marionette-modal 1.0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/Gemfile +4 -0
- data/Gruntfile.coffee +111 -0
- data/LICENSE +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/dist/backbone.marionette.modals-min.js +1 -0
- data/dist/backbone.marionette.modals.js +104 -0
- data/dist/backbone.modal-min.js +1 -0
- data/dist/backbone.modal.js +382 -0
- data/dist/marionette.modal-bundled-min.js +1 -0
- data/dist/marionette.modal-bundled.js +858 -0
- data/dist/marionette.modal-min.js +1 -0
- data/dist/marionette.modal.css +24 -0
- data/dist/marionette.modal.js +370 -0
- data/dist/marionette.modal.theme.css +324 -0
- data/examples/1_single_view.html +71 -0
- data/examples/2_tab_based.html +104 -0
- data/examples/3_stacked_modal_with_marionette.html +105 -0
- data/examples/4_wizard.html +132 -0
- data/examples/css/style.css +45 -0
- data/examples/img/tab-icons.png +0 -0
- data/examples/style.css +35 -0
- data/examples/vendor/backbone.js +1591 -0
- data/examples/vendor/backbone.marionette.modals.js +104 -0
- data/examples/vendor/backbone.modal.css +24 -0
- data/examples/vendor/backbone.modal.js +382 -0
- data/examples/vendor/backbone.modal.theme.css +324 -0
- data/examples/vendor/jquery-1.9.1.js +9597 -0
- data/examples/vendor/marionette.js +2466 -0
- data/examples/vendor/marionette.modal.css +24 -0
- data/examples/vendor/marionette.modal.js +370 -0
- data/examples/vendor/marionette.modal.theme.css +324 -0
- data/examples/vendor/underscore.js +1314 -0
- data/lib/marionette-modal/version.rb +3 -0
- data/lib/marionette-modal.rb +22 -0
- data/marionette-modal.gemspec +23 -0
- data/package.json +19 -0
- data/src/backbone.marionette.modals.coffee +67 -0
- data/src/backbone.modal.coffee +253 -0
- data/src/marionette.modal.coffee +248 -0
- data/src/marionette.modal.sass +26 -0
- data/src/marionette.modal.theme.sass +486 -0
- data/src/style.sass +48 -0
- data/test/spec/backbone.marionette.modals.spec.js +120 -0
- data/test/spec/backbone.modal.spec.js +224 -0
- data/test/spec.html +41 -0
- data/test/src/backbone.marionette.modals.spec.coffee +56 -0
- data/test/src/backbone.modal.spec.coffee +139 -0
- metadata +128 -0
@@ -0,0 +1 @@
|
|
1
|
+
(function(){var a=function(a,b){return function(){return a.apply(b,arguments)}},b={}.hasOwnProperty,c=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a};if("undefined"==typeof Marionette||null===Marionette)throw new Error("Marionette is not defined. Please include the latest version from https://github.com/marionettejs/backbone.marionette");Marionette.Modal=function(b){function d(){this.triggerCancel=a(this.triggerCancel,this),this.triggerSubmit=a(this.triggerSubmit,this),this.triggerView=a(this.triggerView,this),this.clickOutside=a(this.clickOutside,this),this.checkKey=a(this.checkKey,this),this.args=Array.prototype.slice.apply(arguments),Marionette.View.prototype.constructor.apply(this,this.args),this.setUIElements(),this.delegateModalEvents()}return c(d,b),d.prototype.prefix="bbm",d.prototype.render=function(a){var b,c,d=this;return null==a&&(a={}),b=this.serializeData(),this.$el.addClass(""+this.prefix+"-wrapper"),this.modalEl=Marionette.$("<div />").addClass(""+this.prefix+"-modal"),this.template&&this.modalEl.html(this.template(b)),this.$el.html(this.modalEl),Marionette.$("body").on("keyup",this.checkKey),Marionette.$("body").on("click",this.clickOutside),this.viewContainer?(this.viewContainerEl=this.modalEl.find(this.viewContainer),this.viewContainerEl.addClass(""+this.prefix+"-modal__views")):this.viewContainerEl=this.modalEl,this.$el.show(),(null!=(c=this.views)?c.length:void 0)>0&&this.openAt(0),"function"==typeof this.onRender&&this.onRender(),this.modalEl.css({opacity:0}),this.$el.fadeIn({duration:100,complete:function(){return d.modalEl.css({opacity:1}).addClass(""+d.prefix+"-modal--open")}}),this},d.prototype.setUIElements=function(){var a;if(this.template=Marionette.getOption(this,"template"),this.views=Marionette.getOption(this,"views"),null!=(a=this.views)&&(a.length=_.size(this.views)),this.viewContainer=Marionette.getOption(this,"viewContainer"),this.$el.hide(),_.isUndefined(this.template)&&_.isUndefined(this.views))throw new Error("No template or views defined for Backbone.Modal");if(this.template&&this.views&&_.isUndefined(this.viewContainer))throw new Error("No viewContainer defined for Backbone.Modal")},d.prototype.serializeData=function(){var a;return a={},this.model&&(a=_.extend(a,this.model.toJSON())),this.collection&&(a=_.extend(a,{items:this.collection.toJSON()})),a},d.prototype.delegateModalEvents=function(){var a,b,c,d,e,f,g;this.active=!0,a=Marionette.getOption(this,"cancelEl"),e=Marionette.getOption(this,"submitEl"),e&&this.$el.on("click",e,this.triggerSubmit),a&&this.$el.on("click",a,this.triggerCancel),g=[];for(b in this.views)"length"!==b?(c=b.match(/^(\S+)\s*(.*)$/),f=c[1],d=c[2],g.push(this.$el.on(f,d,this.views[b],this.triggerView))):g.push(void 0);return g},d.prototype.undelegateModalEvents=function(){var a,b,c,d,e,f,g;this.active=!1,a=this.getOption("cancelEl"),e=this.getOption("submitEl"),e&&this.$el.off("click",e,this.triggerSubmit),a&&this.$el.off("click",a,this.triggerCancel),g=[];for(b in this.views)"length"!==b?(c=b.match(/^(\S+)\s*(.*)$/),f=c[1],d=c[2],g.push(this.$el.off(f,d,this.views[b],this.triggerView))):g.push(void 0);return g},d.prototype.checkKey=function(a){if(this.active)switch(a.keyCode){case 27:return this.triggerCancel();case 13:return this.triggerSubmit()}},d.prototype.clickOutside=function(a){return Marionette.$(a.target).hasClass(""+this.prefix+"-wrapper")&&this.active?this.triggerCancel(null,!0):void 0},d.prototype.buildView=function(a){var b;if(a)return _.isFunction(a)?(b=new a(this.args[0]),b instanceof Backbone.View?{el:b.render().$el,view:b}:{el:a(this.args[0])}):{view:a,el:a.$el}},d.prototype.triggerView=function(a){var b,c,d,e;null!=a&&"function"==typeof a.preventDefault&&a.preventDefault(),e=a.data,c=this.buildView(e.view),this.currentView&&(this.previousView=this.currentView),this.currentView=c.view||c.el,b=0;for(d in this.views)e.view===this.views[d].view&&(this.currentIndex=b),b++;return e.onActive&&(_.isFunction(e.onActive)?e.onActive(this):_.isString(e.onActive)&&this[e.onActive].call(this,e)),this.shouldAnimate?this.animateToView(c.el):(this.shouldAnimate=!0,this.$(this.viewContainerEl).html(c.el))},d.prototype.animateToView=function(a){var b,c,d,e,f,g,h=this;return e={position:"relative",top:-9999,left:-9999},f=Marionette.$("<tester/>").css(e),f.html(this.$el.clone().css(e)),0!==Marionette.$("tester").length?Marionette.$("tester").replaceWith(f):Marionette.$("body").append(f),b=this.viewContainer?f.find(this.viewContainer):f.find("."+this.prefix+"-modal"),b.removeAttr("style"),d=b.outerHeight(),b.html(a),c=b.outerHeight(),d===c?(this.$(this.viewContainerEl).html(a),null!=(g=this.previousView)?"function"==typeof g.close?g.close():void 0:void 0):(this.$(this.viewContainerEl).css({opacity:0}),this.$(this.viewContainerEl).animate({height:c},100,function(){var b;return h.$(h.viewContainerEl).css({opacity:1}).removeAttr("style"),h.$(h.viewContainerEl).html(a),null!=(b=h.previousView)?"function"==typeof b.close?b.close():void 0:void 0}))},d.prototype.triggerSubmit=function(a){return a&&(null!=a&&a.preventDefault(),!this.beforeSubmit||this.beforeSubmit()!==!1)?("function"==typeof this.submit&&this.submit(),this.regionEnabled?this.trigger("modal:close"):this.close()):void 0},d.prototype.triggerCancel=function(a){return null!=a&&a.preventDefault(),this.beforeCancel&&this.beforeCancel()===!1?void 0:("function"==typeof this.cancel&&this.cancel(),this.regionEnabled?this.triggerMethod("modal:close"):this.close())},d.prototype.close=function(){var a=this;return Marionette.$("body").off("keyup",this.checkKey),Marionette.$("body").off("click",this.clickOutside),"function"==typeof this.onClose&&this.onClose(),this.shouldAnimate=!1,this.modalEl.addClass(""+this.prefix+"-modal--close"),this.$el.fadeOut({duration:200}),_.delay(function(){var b;return null!=(b=a.currentView)&&"function"==typeof b.remove&&b.remove(),a.remove()},200)},d.prototype.openAt=function(a){var b,c,d;b=0;for(c in this.views)"length"!==c&&(b===a&&(d=this.views[c]),b++);return d&&(this.currentIndex=a,this.triggerView({data:d})),this},d.prototype.next=function(){return this.currentIndex+1<this.views.length?this.openAt(this.currentIndex+1):void 0},d.prototype.previous=function(){return this.currentIndex-1<this.views.length-1?this.openAt(this.currentIndex-1):void 0},d}(Marionette.View)}).call(this);
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/* Modal positioning */
|
2
|
+
.bbm-wrapper {
|
3
|
+
box-sizing: border-box;
|
4
|
+
position: absolute;
|
5
|
+
left: 0;
|
6
|
+
top: 0;
|
7
|
+
width: 100%;
|
8
|
+
height: 100%;
|
9
|
+
z-index: 100;
|
10
|
+
padding: 50px 10px;
|
11
|
+
overflow-x: auto;
|
12
|
+
overflow-y: scroll; }
|
13
|
+
.bbm-wrapper * {
|
14
|
+
box-sizing: border-box; }
|
15
|
+
|
16
|
+
.bbm-modal {
|
17
|
+
border-radius: 3px;
|
18
|
+
margin: auto;
|
19
|
+
width: auto;
|
20
|
+
max-width: 550px; }
|
21
|
+
|
22
|
+
.bbm-views {
|
23
|
+
width: 100%;
|
24
|
+
box-sizing: border-box; }
|
@@ -0,0 +1,370 @@
|
|
1
|
+
(function() {
|
2
|
+
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
3
|
+
__hasProp = {}.hasOwnProperty,
|
4
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
5
|
+
|
6
|
+
if (typeof Marionette === "undefined" || Marionette === null) {
|
7
|
+
throw new Error("Marionette is not defined. Please include the latest version from https://github.com/marionettejs/backbone.marionette");
|
8
|
+
}
|
9
|
+
|
10
|
+
Marionette.Modal = (function(_super) {
|
11
|
+
__extends(Modal, _super);
|
12
|
+
|
13
|
+
Modal.prototype.prefix = 'bbm';
|
14
|
+
|
15
|
+
function Modal() {
|
16
|
+
this.triggerCancel = __bind(this.triggerCancel, this);
|
17
|
+
this.triggerSubmit = __bind(this.triggerSubmit, this);
|
18
|
+
this.triggerView = __bind(this.triggerView, this);
|
19
|
+
this.clickOutside = __bind(this.clickOutside, this);
|
20
|
+
this.checkKey = __bind(this.checkKey, this);
|
21
|
+
this.args = Array.prototype.slice.apply(arguments);
|
22
|
+
Marionette.View.prototype.constructor.apply(this, this.args);
|
23
|
+
this.setUIElements();
|
24
|
+
this.delegateModalEvents();
|
25
|
+
}
|
26
|
+
|
27
|
+
Modal.prototype.render = function(options) {
|
28
|
+
var data, _ref,
|
29
|
+
_this = this;
|
30
|
+
if (options == null) {
|
31
|
+
options = {};
|
32
|
+
}
|
33
|
+
data = this.serializeData();
|
34
|
+
this.$el.addClass("" + this.prefix + "-wrapper");
|
35
|
+
this.modalEl = Marionette.$('<div />').addClass("" + this.prefix + "-modal");
|
36
|
+
if (this.template) {
|
37
|
+
this.modalEl.html(this.template(data));
|
38
|
+
}
|
39
|
+
this.$el.html(this.modalEl);
|
40
|
+
Marionette.$('body').on('keyup', this.checkKey);
|
41
|
+
Marionette.$('body').on('click', this.clickOutside);
|
42
|
+
if (this.viewContainer) {
|
43
|
+
this.viewContainerEl = this.modalEl.find(this.viewContainer);
|
44
|
+
this.viewContainerEl.addClass("" + this.prefix + "-modal__views");
|
45
|
+
} else {
|
46
|
+
this.viewContainerEl = this.modalEl;
|
47
|
+
}
|
48
|
+
this.$el.show();
|
49
|
+
if (((_ref = this.views) != null ? _ref.length : void 0) > 0) {
|
50
|
+
this.openAt(0);
|
51
|
+
}
|
52
|
+
if (typeof this.onRender === "function") {
|
53
|
+
this.onRender();
|
54
|
+
}
|
55
|
+
this.modalEl.css({
|
56
|
+
opacity: 0
|
57
|
+
});
|
58
|
+
this.$el.fadeIn({
|
59
|
+
duration: 100,
|
60
|
+
complete: function() {
|
61
|
+
return _this.modalEl.css({
|
62
|
+
opacity: 1
|
63
|
+
}).addClass("" + _this.prefix + "-modal--open");
|
64
|
+
}
|
65
|
+
});
|
66
|
+
return this;
|
67
|
+
};
|
68
|
+
|
69
|
+
Modal.prototype.setUIElements = function() {
|
70
|
+
var _ref;
|
71
|
+
this.template = Marionette.getOption(this, 'template');
|
72
|
+
this.views = Marionette.getOption(this, 'views');
|
73
|
+
if ((_ref = this.views) != null) {
|
74
|
+
_ref.length = _.size(this.views);
|
75
|
+
}
|
76
|
+
this.viewContainer = Marionette.getOption(this, 'viewContainer');
|
77
|
+
this.$el.hide();
|
78
|
+
if (_.isUndefined(this.template) && _.isUndefined(this.views)) {
|
79
|
+
throw new Error('No template or views defined for Backbone.Modal');
|
80
|
+
}
|
81
|
+
if (this.template && this.views && _.isUndefined(this.viewContainer)) {
|
82
|
+
throw new Error('No viewContainer defined for Backbone.Modal');
|
83
|
+
}
|
84
|
+
};
|
85
|
+
|
86
|
+
Modal.prototype.serializeData = function() {
|
87
|
+
var data;
|
88
|
+
data = {};
|
89
|
+
if (this.model) {
|
90
|
+
data = _.extend(data, this.model.toJSON());
|
91
|
+
}
|
92
|
+
if (this.collection) {
|
93
|
+
data = _.extend(data, {
|
94
|
+
items: this.collection.toJSON()
|
95
|
+
});
|
96
|
+
}
|
97
|
+
return data;
|
98
|
+
};
|
99
|
+
|
100
|
+
Modal.prototype.delegateModalEvents = function() {
|
101
|
+
var cancelEl, key, match, selector, submitEl, trigger, _results;
|
102
|
+
this.active = true;
|
103
|
+
cancelEl = Marionette.getOption(this, 'cancelEl');
|
104
|
+
submitEl = Marionette.getOption(this, 'submitEl');
|
105
|
+
if (submitEl) {
|
106
|
+
this.$el.on('click', submitEl, this.triggerSubmit);
|
107
|
+
}
|
108
|
+
if (cancelEl) {
|
109
|
+
this.$el.on('click', cancelEl, this.triggerCancel);
|
110
|
+
}
|
111
|
+
_results = [];
|
112
|
+
for (key in this.views) {
|
113
|
+
if (key !== 'length') {
|
114
|
+
match = key.match(/^(\S+)\s*(.*)$/);
|
115
|
+
trigger = match[1];
|
116
|
+
selector = match[2];
|
117
|
+
_results.push(this.$el.on(trigger, selector, this.views[key], this.triggerView));
|
118
|
+
} else {
|
119
|
+
_results.push(void 0);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
return _results;
|
123
|
+
};
|
124
|
+
|
125
|
+
Modal.prototype.undelegateModalEvents = function() {
|
126
|
+
var cancelEl, key, match, selector, submitEl, trigger, _results;
|
127
|
+
this.active = false;
|
128
|
+
cancelEl = this.getOption('cancelEl');
|
129
|
+
submitEl = this.getOption('submitEl');
|
130
|
+
if (submitEl) {
|
131
|
+
this.$el.off('click', submitEl, this.triggerSubmit);
|
132
|
+
}
|
133
|
+
if (cancelEl) {
|
134
|
+
this.$el.off('click', cancelEl, this.triggerCancel);
|
135
|
+
}
|
136
|
+
_results = [];
|
137
|
+
for (key in this.views) {
|
138
|
+
if (key !== 'length') {
|
139
|
+
match = key.match(/^(\S+)\s*(.*)$/);
|
140
|
+
trigger = match[1];
|
141
|
+
selector = match[2];
|
142
|
+
_results.push(this.$el.off(trigger, selector, this.views[key], this.triggerView));
|
143
|
+
} else {
|
144
|
+
_results.push(void 0);
|
145
|
+
}
|
146
|
+
}
|
147
|
+
return _results;
|
148
|
+
};
|
149
|
+
|
150
|
+
Modal.prototype.checkKey = function(e) {
|
151
|
+
if (this.active) {
|
152
|
+
switch (e.keyCode) {
|
153
|
+
case 27:
|
154
|
+
return this.triggerCancel();
|
155
|
+
case 13:
|
156
|
+
return this.triggerSubmit();
|
157
|
+
}
|
158
|
+
}
|
159
|
+
};
|
160
|
+
|
161
|
+
Modal.prototype.clickOutside = function(e) {
|
162
|
+
if (Marionette.$(e.target).hasClass("" + this.prefix + "-wrapper") && this.active) {
|
163
|
+
return this.triggerCancel(null, true);
|
164
|
+
}
|
165
|
+
};
|
166
|
+
|
167
|
+
Modal.prototype.buildView = function(viewType) {
|
168
|
+
var view;
|
169
|
+
if (!viewType) {
|
170
|
+
return;
|
171
|
+
}
|
172
|
+
if (_.isFunction(viewType)) {
|
173
|
+
view = new viewType(this.args[0]);
|
174
|
+
if (view instanceof Backbone.View) {
|
175
|
+
return {
|
176
|
+
el: view.render().$el,
|
177
|
+
view: view
|
178
|
+
};
|
179
|
+
} else {
|
180
|
+
return {
|
181
|
+
el: viewType(this.args[0])
|
182
|
+
};
|
183
|
+
}
|
184
|
+
}
|
185
|
+
return {
|
186
|
+
view: viewType,
|
187
|
+
el: viewType.$el
|
188
|
+
};
|
189
|
+
};
|
190
|
+
|
191
|
+
Modal.prototype.triggerView = function(e) {
|
192
|
+
var index, instance, key, options;
|
193
|
+
if (e != null) {
|
194
|
+
if (typeof e.preventDefault === "function") {
|
195
|
+
e.preventDefault();
|
196
|
+
}
|
197
|
+
}
|
198
|
+
options = e.data;
|
199
|
+
instance = this.buildView(options.view);
|
200
|
+
if (this.currentView) {
|
201
|
+
this.previousView = this.currentView;
|
202
|
+
}
|
203
|
+
this.currentView = instance.view || instance.el;
|
204
|
+
index = 0;
|
205
|
+
for (key in this.views) {
|
206
|
+
if (options.view === this.views[key].view) {
|
207
|
+
this.currentIndex = index;
|
208
|
+
}
|
209
|
+
index++;
|
210
|
+
}
|
211
|
+
if (options.onActive) {
|
212
|
+
if (_.isFunction(options.onActive)) {
|
213
|
+
options.onActive(this);
|
214
|
+
} else if (_.isString(options.onActive)) {
|
215
|
+
this[options.onActive].call(this, options);
|
216
|
+
}
|
217
|
+
}
|
218
|
+
if (this.shouldAnimate) {
|
219
|
+
return this.animateToView(instance.el);
|
220
|
+
} else {
|
221
|
+
this.shouldAnimate = true;
|
222
|
+
return this.$(this.viewContainerEl).html(instance.el);
|
223
|
+
}
|
224
|
+
};
|
225
|
+
|
226
|
+
Modal.prototype.animateToView = function(view) {
|
227
|
+
var container, newHeight, previousHeight, style, tester, _ref,
|
228
|
+
_this = this;
|
229
|
+
style = {
|
230
|
+
position: 'relative',
|
231
|
+
top: -9999,
|
232
|
+
left: -9999
|
233
|
+
};
|
234
|
+
tester = Marionette.$('<tester/>').css(style);
|
235
|
+
tester.html(this.$el.clone().css(style));
|
236
|
+
if (Marionette.$('tester').length !== 0) {
|
237
|
+
Marionette.$('tester').replaceWith(tester);
|
238
|
+
} else {
|
239
|
+
Marionette.$('body').append(tester);
|
240
|
+
}
|
241
|
+
if (this.viewContainer) {
|
242
|
+
container = tester.find(this.viewContainer);
|
243
|
+
} else {
|
244
|
+
container = tester.find("." + this.prefix + "-modal");
|
245
|
+
}
|
246
|
+
container.removeAttr('style');
|
247
|
+
previousHeight = container.outerHeight();
|
248
|
+
container.html(view);
|
249
|
+
newHeight = container.outerHeight();
|
250
|
+
if (previousHeight === newHeight) {
|
251
|
+
this.$(this.viewContainerEl).html(view);
|
252
|
+
return (_ref = this.previousView) != null ? typeof _ref.close === "function" ? _ref.close() : void 0 : void 0;
|
253
|
+
} else {
|
254
|
+
this.$(this.viewContainerEl).css({
|
255
|
+
opacity: 0
|
256
|
+
});
|
257
|
+
return this.$(this.viewContainerEl).animate({
|
258
|
+
height: newHeight
|
259
|
+
}, 100, function() {
|
260
|
+
var _ref1;
|
261
|
+
_this.$(_this.viewContainerEl).css({
|
262
|
+
opacity: 1
|
263
|
+
}).removeAttr('style');
|
264
|
+
_this.$(_this.viewContainerEl).html(view);
|
265
|
+
return (_ref1 = _this.previousView) != null ? typeof _ref1.close === "function" ? _ref1.close() : void 0 : void 0;
|
266
|
+
});
|
267
|
+
}
|
268
|
+
};
|
269
|
+
|
270
|
+
Modal.prototype.triggerSubmit = function(e) {
|
271
|
+
if (!e) {
|
272
|
+
return;
|
273
|
+
}
|
274
|
+
if (e != null) {
|
275
|
+
e.preventDefault();
|
276
|
+
}
|
277
|
+
if (this.beforeSubmit) {
|
278
|
+
if (this.beforeSubmit() === false) {
|
279
|
+
return;
|
280
|
+
}
|
281
|
+
}
|
282
|
+
if (typeof this.submit === "function") {
|
283
|
+
this.submit();
|
284
|
+
}
|
285
|
+
if (this.regionEnabled) {
|
286
|
+
return this.trigger('modal:close');
|
287
|
+
} else {
|
288
|
+
return this.close();
|
289
|
+
}
|
290
|
+
};
|
291
|
+
|
292
|
+
Modal.prototype.triggerCancel = function(e) {
|
293
|
+
if (e != null) {
|
294
|
+
e.preventDefault();
|
295
|
+
}
|
296
|
+
if (this.beforeCancel) {
|
297
|
+
if (this.beforeCancel() === false) {
|
298
|
+
return;
|
299
|
+
}
|
300
|
+
}
|
301
|
+
if (typeof this.cancel === "function") {
|
302
|
+
this.cancel();
|
303
|
+
}
|
304
|
+
if (this.regionEnabled) {
|
305
|
+
return this.triggerMethod('modal:close');
|
306
|
+
} else {
|
307
|
+
return this.close();
|
308
|
+
}
|
309
|
+
};
|
310
|
+
|
311
|
+
Modal.prototype.close = function() {
|
312
|
+
var _this = this;
|
313
|
+
Marionette.$('body').off('keyup', this.checkKey);
|
314
|
+
Marionette.$('body').off('click', this.clickOutside);
|
315
|
+
if (typeof this.onClose === "function") {
|
316
|
+
this.onClose();
|
317
|
+
}
|
318
|
+
this.shouldAnimate = false;
|
319
|
+
this.modalEl.addClass("" + this.prefix + "-modal--close");
|
320
|
+
this.$el.fadeOut({
|
321
|
+
duration: 200
|
322
|
+
});
|
323
|
+
return _.delay(function() {
|
324
|
+
var _ref;
|
325
|
+
if ((_ref = _this.currentView) != null) {
|
326
|
+
if (typeof _ref.remove === "function") {
|
327
|
+
_ref.remove();
|
328
|
+
}
|
329
|
+
}
|
330
|
+
return _this.remove();
|
331
|
+
}, 200);
|
332
|
+
};
|
333
|
+
|
334
|
+
Modal.prototype.openAt = function(index) {
|
335
|
+
var i, key, view;
|
336
|
+
i = 0;
|
337
|
+
for (key in this.views) {
|
338
|
+
if (key !== 'length') {
|
339
|
+
if (i === index) {
|
340
|
+
view = this.views[key];
|
341
|
+
}
|
342
|
+
i++;
|
343
|
+
}
|
344
|
+
}
|
345
|
+
if (view) {
|
346
|
+
this.currentIndex = index;
|
347
|
+
this.triggerView({
|
348
|
+
data: view
|
349
|
+
});
|
350
|
+
}
|
351
|
+
return this;
|
352
|
+
};
|
353
|
+
|
354
|
+
Modal.prototype.next = function() {
|
355
|
+
if (this.currentIndex + 1 < this.views.length) {
|
356
|
+
return this.openAt(this.currentIndex + 1);
|
357
|
+
}
|
358
|
+
};
|
359
|
+
|
360
|
+
Modal.prototype.previous = function() {
|
361
|
+
if (this.currentIndex - 1 < this.views.length - 1) {
|
362
|
+
return this.openAt(this.currentIndex - 1);
|
363
|
+
}
|
364
|
+
};
|
365
|
+
|
366
|
+
return Modal;
|
367
|
+
|
368
|
+
})(Marionette.View);
|
369
|
+
|
370
|
+
}).call(this);
|