vendor/assets/javascripts/bootstrap-modal.js in bootstrap-modal-rails-2.0 vs vendor/assets/javascripts/bootstrap-modal.js in bootstrap-modal-rails-2.1
- old
+ new
@@ -1,7 +1,7 @@
/* ===========================================================
- * bootstrap-modal.js v2.0
+ * bootstrap-modal.js v2.1
* ===========================================================
* Copyright 2012 Jordan Schroter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,83 +18,59 @@
!function ($) {
"use strict"; // jshint ;_;
-
+
/* MODAL CLASS DEFINITION
* ====================== */
var Modal = function (element, options) {
this.init(element, options);
- }
+ };
Modal.prototype = {
- constructor: Modal,
-
+ constructor: Modal,
+
init: function (element, options) {
this.options = options;
-
+
this.$element = $(element)
.delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this));
-
+
this.options.remote && this.$element.find('.modal-body').load(this.options.remote);
-
- var manager = typeof this.options.manager === 'function' ?
+
+ var manager = typeof this.options.manager === 'function' ?
this.options.manager.call(this) : this.options.manager;
- manager = manager.appendModal ?
+ manager = manager.appendModal ?
manager : $(manager).modalmanager().data('modalmanager');
manager.appendModal(this);
- },
-
+ },
+
toggle: function () {
return this[!this.isShown ? 'show' : 'hide']();
- },
-
+ },
+
show: function () {
- var that = this,
- e = $.Event('show');
-
+ var e = $.Event('show');
+
if (this.isShown) return;
this.$element.triggerHandler(e);
if (e.isDefaultPrevented()) return;
-
- if (this.options.width){
- this.$element.css('width', this.options.width);
-
- var that = this;
- this.$element.css('margin-left', function () {
- if (/%/ig.test(that.options.width)){
- return -(parseInt(that.options.width) / 2) + '%';
- } else {
- return -($(this).width() / 2) + 'px';
- }
- });
- }
-
- var prop = this.options.height ? 'height' : 'max-height';
- var value = this.options.height || this.options.maxHeight;
-
- if (value){
- this.$element.find('.modal-body')
- .css('overflow', 'auto')
- .css(prop, value);
- }
-
this.escape();
this.tab();
-
+
this.options.loading && this.loading();
- },
-
+ },
+
hide: function (e) {
e && e.preventDefault();
e = $.Event('hide');
@@ -105,11 +81,11 @@
this.isShown = false;
this.escape();
this.tab();
-
+
this.isLoading && this.loading();
$(document).off('focusin.modal');
this.$element
@@ -120,112 +96,153 @@
.attr('aria-hidden', true);
$.support.transition && this.$element.hasClass('fade') ?
this.hideWithTransition() :
this.hideModal();
- },
+ },
+ layout: function () {
+ var prop = this.options.height ? 'height' : 'max-height',
+ value = this.options.height || this.options.maxHeight;
+
+ if (this.options.width){
+ this.$element.css('width', this.options.width);
+
+ var that = this;
+ this.$element.css('margin-left', function () {
+ if (/%/ig.test(that.options.width)){
+ return -(parseInt(that.options.width) / 2) + '%';
+ } else {
+ return -($(this).width() / 2) + 'px';
+ }
+ });
+ } else {
+ this.$element.css('width', '');
+ this.$element.css('margin-left', '');
+ }
+
+ this.$element.find('.modal-body')
+ .css('overflow', '')
+ .css(prop, '');
+
+ var modalOverflow = $(window).height() - 10 < this.$element.height();
+
+ if (value){
+ this.$element.find('.modal-body')
+ .css('overflow', 'auto')
+ .css(prop, value);
+ }
+
+ if (modalOverflow || this.options.modalOverflow) {
+ this.$element
+ .css('margin-top', 0)
+ .addClass('modal-overflow');
+ } else {
+ this.$element
+ .css('margin-top', 0 - this.$element.height() / 2)
+ .removeClass('modal-overflow');
+ }
+ },
+
tab: function () {
var that = this;
- if (this.isShown && this.options.consumeTab) {
- this.$element.on('keydown.tabindex.modal', '[data-tabindex]', function (e) {
- if (e.keyCode && e.keyCode == 9){
- var $next = $(this),
- $rollover = $(this);
-
- that.$element.find('[data-tabindex]:enabled:not([readonly])').each(function (e) {
- if (!e.shiftKey){
- $next = $next.data('tabindex') < $(this).data('tabindex') ?
- $next = $(this) :
- $rollover = $(this);
- } else {
- $next = $next.data('tabindex') > $(this).data('tabindex') ?
- $next = $(this) :
- $rollover = $(this);
- }
- });
+ if (this.isShown && this.options.consumeTab) {
+ this.$element.on('keydown.tabindex.modal', '[data-tabindex]', function (e) {
+ if (e.keyCode && e.keyCode == 9){
+ var $next = $(this),
+ $rollover = $(this);
- $next[0] !== $(this)[0] ?
- $next.focus() : $rollover.focus();
+ that.$element.find('[data-tabindex]:enabled:not([readonly])').each(function (e) {
+ if (!e.shiftKey){
+ $next = $next.data('tabindex') < $(this).data('tabindex') ?
+ $next = $(this) :
+ $rollover = $(this);
+ } else {
+ $next = $next.data('tabindex') > $(this).data('tabindex') ?
+ $next = $(this) :
+ $rollover = $(this);
+ }
+ });
- e.preventDefault();
+ $next[0] !== $(this)[0] ?
+ $next.focus() : $rollover.focus();
- }
- });
+ e.preventDefault();
+ }
+ });
} else if (!this.isShown) {
this.$element.off('keydown.tabindex.modal');
}
- },
-
+ },
+
escape: function () {
var that = this;
if (this.isShown && this.options.keyboard) {
if (!this.$element.attr('tabindex')) this.$element.attr('tabindex', -1);
-
+
this.$element.on('keyup.dismiss.modal', function (e) {
e.which == 27 && that.hide();
});
} else if (!this.isShown) {
this.$element.off('keyup.dismiss.modal')
}
- },
-
+ },
+
hideWithTransition: function () {
var that = this
, timeout = setTimeout(function () {
- that.$element.off($.support.transition.end)
- that.hideModal()
+ that.$element.off($.support.transition.end);
+ that.hideModal();
}, 500);
this.$element.one($.support.transition.end, function () {
- clearTimeout(timeout)
- that.hideModal()
+ clearTimeout(timeout);
+ that.hideModal();
});
- },
-
+ },
+
hideModal: function () {
this.$element
.hide()
.triggerHandler('hidden');
-
var prop = this.options.height ? 'height' : 'max-height';
var value = this.options.height || this.options.maxHeight;
-
+
if (value){
this.$element.find('.modal-body')
.css('overflow', '')
.css(prop, '');
}
- },
+ },
removeLoading: function () {
this.$loading.remove();
this.$loading = null;
this.isLoading = false;
},
-
+
loading: function (callback) {
callback = callback || function () {};
-
+
var animate = this.$element.hasClass('fade') ? 'fade' : '';
-
+
if (!this.isLoading) {
var doAnimate = $.support.transition && animate;
-
+
this.$loading = $('<div class="loading-mask ' + animate + '">')
.append(this.options.spinner)
.appendTo(this.$element);
- if (doAnimate) this.$loading[0].offsetWidth // force reflow
-
- this.$loading.addClass('in')
+ if (doAnimate) this.$loading[0].offsetWidth; // force reflow
+ this.$loading.addClass('in');
+
this.isLoading = true;
-
+
doAnimate ?
this.$loading.one($.support.transition.end, callback) :
callback();
} else if (this.isLoading && this.$loading) {
@@ -238,11 +255,11 @@
} else if (callback) {
callback(this.isLoading);
}
},
-
+
focus: function () {
var $focusElem = this.$element.find(this.options.focusOn);
$focusElem = $focusElem.length ? $focusElem : this.$element;
@@ -267,21 +284,21 @@
}
this.focus();
},
-
+
destroy: function () {
var e = $.Event('destroy');
this.$element.triggerHandler(e);
if (e.isDefaultPrevented()) return;
-
+
this.teardown();
},
-
- teardown: function () {
+
+ teardown: function () {
if (!this.$parent.length){
this.$element.remove();
this.$element = null;
return;
}
@@ -294,55 +311,57 @@
this.$element.removeData('modal');
this.$element
.removeClass('in')
.attr('aria-hidden', true);
}
- }
+ };
/* MODAL PLUGIN DEFINITION
* ======================= */
- $.fn.modal = function (option) {
+ $.fn.modal = function (option, args) {
return this.each(function () {
- var $this = $(this),
- data = $this.data('modal'),
+ var $this = $(this),
+ data = $this.data('modal'),
options = $.extend({}, $.fn.modal.defaults, $this.data(), typeof option == 'object' && option);
- if (!data) $this.data('modal', (data = new Modal(this, options)))
- if (typeof option == 'string') data[option]()
+ if (!data) $this.data('modal', (data = new Modal(this, options)));
+ if (typeof option == 'string') data[option].apply(data, [].concat(args));
else if (options.show) data.show()
})
- }
+ };
$.fn.modal.defaults = {
- keyboard: true,
+ keyboard: true,
backdrop: true,
loading: false,
show: true,
width: null,
height: null,
maxHeight: null,
modalOverflow: false,
consumeTab: true,
focusOn: null,
+ replace: false,
+ resize: false,
attentionAnimation: 'shake',
manager: 'body',
spinner: '<div class="loading-spinner" style="width: 200px; margin-left: -100px;"><div class="progress progress-striped active"><div class="bar" style="width: 100%;"></div></div></div>'
- }
+ };
- $.fn.modal.Constructor = Modal
+ $.fn.modal.Constructor = Modal;
/* MODAL DATA-API
* ============== */
-
+
$(function () {
$(document).off('.modal').on('click.modal.data-api', '[data-toggle="modal"]', function ( e ) {
- var $this = $(this),
- href = $this.attr('href'),
- $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))), //strip for ie7
+ var $this = $(this),
+ href = $this.attr('href'),
+ $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))), //strip for ie7
option = $target.data('modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data());
e.preventDefault();
$target
.modal(option)
@@ -350,6 +369,6 @@
$this.focus();
})
});
});
-}(window.jQuery);
\ No newline at end of file
+}(window.jQuery);