-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackbone.bootstrap-modal.js
69 lines (62 loc) · 1.45 KB
/
backbone.bootstrap-modal.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
(c) 2013 Karl Mikkelsen.
Backbone.BootstrapModal may be freely distributed under the MIT license.
For all details and documentation:
https://github.com/KingKarl85/Backbone.BootstrapModal
*/
(function(_, Backbone){
Backbone.BootstrapModal = Backbone.View.extend({
modalTemplate:"<div class='modal'></div>",
modal:function(options){
this.$modal = Backbone.$(this.modalTemplate);
this.$modal.html(this.el);
this.options = _.extend({
backdrop: 'static',
hidden: function(){
this.remove();
}
}, this.options, opts);
options = this.options;
var self = this;
this.$modal.modal(options).on('shown', function(){
if(options.shown && options.shown.call){
options.shown.call(self);
}
}).on("hidden", function(){
if(options.hidden && options.hidden.call){
options.hidden.call(self);
}
}).on("show", function(){
if(options.show && options.show.call){
options.show.call(self);
}
}).on("hide", function(){
if(options.hide && options.hide.call){
options.hide.call(self);
}
});
return this.$modal;
},
hide:function(){
if(this.$modal){
this.$modal.modal('hide');
}
},
show:function(){
if(!this.$modal){
this.modal({show:false});
}
this.$modal.modal("show");
},
toggle:function(){
if(this.$modal){
this.$modal.modal('toggle');
}
},
remove:function(){
if(this.$modal){
this.$modal.remove();
}
}
});
})(_, Backbone);