-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
54 lines (47 loc) · 1.27 KB
/
app.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
49
50
51
52
53
54
// Put this in a common javscript file just before app.js
jQueryView = Backbone.View.extend({
initialize : function() {
this.el = $(this.el);
this.tmpl = $(this.tmpl);
}
});
App.HelloW = function($) {
// private stuffs
var HelloWorldView;
// Creating a Backbone.View that supports jQuery
HelloWorldView = jQueryView.extend({
el : '#hello-world',
tmpl : '#hello-world-tmpl',
events : {
'click #btnSay' : 'render'
},
initialize : function(params) {
// call super initializer
jQueryView.prototype.initialize.call(this);
this.name = params.name || ''; // empty string by defualt
this.bold = params.bold || true; // bold by default
// initializing a button
$.tmpl('<button id="btnSay">${text}</button>', {text : params.btn}).appendTo(this.el);
},
render : function() {
var content = this.tmpl.tmpl({name : this.name});
// manipulating view a.k.a rendering view
this.el.html(content)
.css({'font-weight' : this.bold ? 'bold' : 'normal'});
}
});
// public stuffs
return {
start : function() {
// instatiating a view
new HelloWorldView({
name : 'GeekZy',
btn : 'Say it',
tagName : 'span',
id : 'foo',
className : 'title',
});
}
}
}(jQuery);
jQuery(function() { App.HelloW.start(); });