1 /* ===========================================================
2 * bootstrap-modalmanager.min.js v2.2.5
3 * ===========================================================
4 * Copyright 2012 Jordan Schroter
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ========================================================== */
20 var a = function(f, e) {
25 init : function(f, e) {
27 this.options = c.extend({}, c.fn.modalmanager.defaults,
28 this.$element.data(), typeof e == "object" && e);
30 this.backdropCount = 0;
31 if (this.options.resize) {
33 c(window).on("resize.modal", function() {
35 h = setTimeout(function() {
36 for (var j = 0; j < g.stack.length; j++) {
37 g.stack[j].isShown && g.stack[j].layout()
43 createModal : function(f, e) {
48 appendModal : function(f) {
51 f.$element.on("show.modalmanager",
55 var i = c.support.transition
56 && f.$element.hasClass("fade");
57 e.$element.toggleClass("modal-open",
58 e.hasOpenModal()).toggleClass(
60 c(window).height() < e.$element.height());
61 f.$parent = f.$element.parent();
62 f.$container = e.createContainer(f);
63 f.$element.appendTo(f.$container);
64 e.backdrop(f, function() {
67 f.$element[0].offsetWidth
70 f.$element.addClass("in").attr("aria-hidden",
74 f.$element.trigger("shown")
76 i ? f.$element.one(c.support.transition.end, j)
80 f.options.replace ? e.replace(g) : g()
84 "hidden.modalmanager",
87 if (!f.$element.parent().length) {
91 var h = c.support.transition
92 && f.$element.hasClass("fade");
94 f.$element[0].offsetWidth
97 && f.$element.hasClass("fade") ? f.$backdrop
98 .one(c.support.transition.end,
108 f.$element.on("destroyed.modalmanager", b(function(g) {
112 getOpenModals : function() {
114 for (var e = 0; e < this.stack.length; e++) {
115 if (this.stack[e].isShown) {
116 f.push(this.stack[e])
121 hasOpenModal : function() {
122 return this.getOpenModals().length > 0
124 setFocus : function() {
126 for (var e = 0; e < this.stack.length; e++) {
127 if (this.stack[e].isShown) {
136 destroyModal : function(f) {
137 f.$element.off(".modalmanager");
139 this.removeBackdrop(f)
141 this.stack.splice(this.getIndexOfModal(f), 1);
142 var e = this.hasOpenModal();
143 this.$element.toggleClass("modal-open", e);
145 this.$element.removeClass("page-overflow")
147 this.removeContainer(f);
150 getModalAt : function(e) {
153 getIndexOfModal : function(f) {
154 for (var e = 0; e < this.stack.length; e++) {
155 if (f === this.stack[e]) {
160 replace : function(g) {
162 for (var e = 0; e < this.stack.length; e++) {
163 if (this.stack[e].isShown) {
168 this.$backdropHandle = f.$backdrop;
170 g && f.$element.one("hidden", b(c.proxy(g, this)));
178 removeBackdrop : function(e) {
179 e.$backdrop.remove();
182 createBackdrop : function(g, f) {
184 if (!this.$backdropHandle) {
185 e = c(f).addClass(g).appendTo(this.$element)
187 e = this.$backdropHandle;
188 e.off(".modalmanager");
189 this.$backdropHandle = null;
190 this.isLoading && this.removeSpinner()
194 removeContainer : function(e) {
195 e.$container.remove();
198 createContainer : function(e) {
200 f = c('<div class="modal-scrollable">').css("z-index",
201 d("modal", this.getOpenModals().length)).appendTo(
203 if (e && e.options.backdrop != "static") {
204 f.on("click.modal", b(function(g) {
209 f.on("click.modal", b(function(g) {
216 backdrop : function(h, j) {
217 var f = h.$element.hasClass("fade") ? "fade" : "", i = h.options.backdrop
218 && this.backdropCount < this.options.backdropLimit;
219 if (h.isShown && i) {
220 var e = c.support.transition && f && !this.$backdropHandle;
222 .createBackdrop(f, h.options.backdropTemplate);
223 h.$backdrop.css("z-index", d("backdrop",
224 this.getOpenModals().length));
226 h.$backdrop[0].offsetWidth
228 h.$backdrop.addClass("in");
229 this.backdropCount += 1;
230 e ? h.$backdrop.one(c.support.transition.end, j) : j()
232 if (!h.isShown && h.$backdrop) {
233 h.$backdrop.removeClass("in");
234 this.backdropCount -= 1;
236 c.support.transition && h.$element.hasClass("fade") ? h.$backdrop
237 .one(c.support.transition.end, function() {
240 : g.removeBackdrop(h)
248 removeSpinner : function() {
249 this.$spinner && this.$spinner.remove();
250 this.$spinner = null;
251 this.isLoading = false
253 removeLoading : function() {
254 this.$backdropHandle && this.$backdropHandle.remove();
255 this.$backdropHandle = null;
258 loading : function(h) {
259 h = h || function() {
261 this.$element.toggleClass("modal-open",
262 !this.isLoading || this.hasOpenModal()).toggleClass(
264 c(window).height() < this.$element.height());
265 if (!this.isLoading) {
266 this.$backdropHandle = this.createBackdrop("fade",
267 this.options.backdropTemplate);
268 this.$backdropHandle[0].offsetWidth;
269 var e = this.getOpenModals();
271 .css("z-index", d("backdrop", e.length + 1)).addClass(
273 var g = c(this.options.spinner).css("z-index",
274 d("modal", e.length + 1)).appendTo(this.$element)
276 this.$spinner = c(this.createContainer()).append(g).on(
277 "click.modalmanager", c.proxy(this.loading, this));
278 this.isLoading = true;
279 c.support.transition ? this.$backdropHandle.one(
280 c.support.transition.end, h) : h()
282 if (this.isLoading && this.$backdropHandle) {
283 this.$backdropHandle.removeClass("in");
285 c.support.transition ? this.$backdropHandle.one(
286 c.support.transition.end, function() {
288 }) : f.removeLoading()
297 var d = (function() {
299 return function(g, j) {
300 if (typeof f === "undefined") {
301 var i = c('<div class="modal hide" />').appendTo("body"), h = c(
302 '<div class="modal-backdrop hide" />').appendTo("body");
303 e.modal = +i.css("z-index");
304 e.backdrop = +h.css("z-index");
305 f = e.modal - e.backdrop;
310 return e[g] + (f * j)
315 if (f && this === f.target) {
316 return e.apply(this, arguments)
320 c.fn.modalmanager = function(f, e) {
321 return this.each(function() {
322 var h = c(this), g = h.data("modalmanager");
324 h.data("modalmanager", (g = new a(this, f)))
326 if (typeof f === "string") {
327 g[f].apply(g, [].concat(e))
331 c.fn.modalmanager.defaults = {
334 spinner : '<div class="loading-spinner fade" style="width: 200px; margin-left: -100px;"><div class="progress progress-striped active"><div class="bar" style="width: 100%;"></div></div></div>',
335 backdropTemplate : '<div class="modal-backdrop" />'
337 c.fn.modalmanager.Constructor = a;
339 c(document).off("show.bs.modal").off("hidden.bs.modal")