forked from devalot/jquery-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
behavior.js
49 lines (42 loc) · 1007 Bytes
/
behavior.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function ExampleBehavior () {
this.initialize();
}
ExampleBehavior.prototype = {
initialize: function () {
var self = this;
this.sayHello();
$("#bands li").click(function () {
self.removeArtist(this);
});
$("#add-band").submit(function () {
self.addArtistFromForm();
return false;
});
},
sayHello: function () {
console.log("Here I am, come find me.");
},
removeArtist: function (li) {
var e = $(li);
e.addClass("deleted");
e.fadeOut();
},
addArtistFromForm: function () {
var self = this;
var artist = $("#add-band input[name='band']").val();
console.log("new artist is:" + artist);
var li = $(document.createElement('li'));
li.text(artist);
li.addClass("new");
$("#bands").append(li);
li.click(function () {
self.removeArtist(this)
});
window.setTimeout(function () {
li.removeClass("new")
}, 2000);
}
};
$(document).ready(function () {
new ExampleBehavior();
});