/* ======================================================================== * bootstrap: modal.js v3.2.0 * http://getbootstrap.com/javascript/#modals * ======================================================================== * copyright 2011-2014 twitter, inc. * licensed under mit (https://github.com/twbs/bootstrap/blob/master/license) * ======================================================================== */ +function ($) { 'use strict'; // modal class definition // ====================== var modal = function (element, options) { this.options = options this.$body = $(document.body) this.$element = $(element) this.$backdrop = this.isshown = null this.scrollbarwidth = 0 if (this.options.remote) { this.$element .find('.modal-content') .load(this.options.remote, $.proxy(function () { this.$element.trigger('loaded.bs.modal') }, this)) } } modal.version = '3.2.0' modal.defaults = { backdrop: true, keyboard: true, show: true } modal.prototype.toggle = function (_relatedtarget) { return this.isshown ? this.hide() : this.show(_relatedtarget) } modal.prototype.show = function (_relatedtarget) { var that = this var e = $.event('show.bs.modal', { relatedtarget: _relatedtarget }) this.$element.trigger(e) if (this.isshown || e.isdefaultprevented()) return this.isshown = true this.checkscrollbar() this.$body.addclass('modal-open') this.setscrollbar() this.escape() this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this)) this.backdrop(function () { var transition = $.support.transition && that.$element.hasclass('fade') if (!that.$element.parent().length) { that.$element.appendto(that.$body) // don't move modals dom position } that.$element .show() .scrolltop(0) if (transition) { that.$element[0].offsetwidth // force reflow } that.$element .addclass('in') .attr('aria-hidden', false) that.enforcefocus() var e = $.event('shown.bs.modal', { relatedtarget: _relatedtarget }) transition ? that.$element.find('.modal-dialog') // wait for modal to slide in .one('bstransitionend', function () { that.$element.trigger('focus').trigger(e) }) .emulatetransitionend(300) : that.$element.trigger('focus').trigger(e) }) } modal.prototype.hide = function (e) { if (e) e.preventdefault() e = $.event('hide.bs.modal') this.$element.trigger(e) if (!this.isshown || e.isdefaultprevented()) return this.isshown = false this.$body.removeclass('modal-open') this.resetscrollbar() this.escape() $(document).off('focusin.bs.modal') this.$element .removeclass('in') .attr('aria-hidden', true) .off('click.dismiss.bs.modal') $.support.transition && this.$element.hasclass('fade') ? this.$element .one('bstransitionend', $.proxy(this.hidemodal, this)) .emulatetransitionend(300) : this.hidemodal() } modal.prototype.enforcefocus = function () { $(document) .off('focusin.bs.modal') // guard against infinite focus loop .on('focusin.bs.modal', $.proxy(function (e) { if (this.$element[0] !== e.target && !this.$element.has(e.target).length) { this.$element.trigger('focus') } }, this)) } modal.prototype.escape = function () { if (this.isshown && this.options.keyboard) { this.$element.on('keyup.dismiss.bs.modal', $.proxy(function (e) { e.which == 27 && this.hide() }, this)) } else if (!this.isshown) { this.$element.off('keyup.dismiss.bs.modal') } } modal.prototype.hidemodal = function () { var that = this this.$element.hide() this.backdrop(function () { that.$element.trigger('hidden.bs.modal') }) } modal.prototype.removebackdrop = function () { this.$backdrop && this.$backdrop.remove() this.$backdrop = null } modal.prototype.backdrop = function (callback) { var that = this var animate = this.$element.hasclass('fade') ? 'fade' : '' if (this.isshown && this.options.backdrop) { var doanimate = $.support.transition && animate this.$backdrop = $('
') .appendto(this.$body) this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) { if (e.target !== e.currenttarget) return this.options.backdrop == 'static' ? this.$element[0].focus.call(this.$element[0]) : this.hide.call(this) }, this)) if (doanimate) this.$backdrop[0].offsetwidth // force reflow this.$backdrop.addclass('in') if (!callback) return doanimate ? this.$backdrop .one('bstransitionend', callback) .emulatetransitionend(150) : callback() } else if (!this.isshown && this.$backdrop) { this.$backdrop.removeclass('in') var callbackremove = function () { that.removebackdrop() callback && callback() } $.support.transition && this.$element.hasclass('fade') ? this.$backdrop .one('bstransitionend', callbackremove) .emulatetransitionend(150) : callbackremove() } else if (callback) { callback() } } modal.prototype.checkscrollbar = function () { if (document.body.clientwidth >= window.innerwidth) return this.scrollbarwidth = this.scrollbarwidth || this.measurescrollbar() } modal.prototype.setscrollbar = function () { var bodypad = parseint((this.$body.css('padding-right') || 0), 10) if (this.scrollbarwidth) this.$body.css('padding-right', bodypad + this.scrollbarwidth) } modal.prototype.resetscrollbar = function () { this.$body.css('padding-right', '') } modal.prototype.measurescrollbar = function () { // thx walsh var scrolldiv = document.createelement('div') scrolldiv.classname = 'modal-scrollbar-measure' this.$body.append(scrolldiv) var scrollbarwidth = scrolldiv.offsetwidth - scrolldiv.clientwidth this.$body[0].removechild(scrolldiv) return scrollbarwidth } // modal plugin definition // ======================= function plugin(option, _relatedtarget) { return this.each(function () { var $this = $(this) var data = $this.data('bs.modal') var options = $.extend({}, modal.defaults, $this.data(), typeof option == 'object' && option) if (!data) $this.data('bs.modal', (data = new modal(this, options))) if (typeof option == 'string') data[option](_relatedtarget) else if (options.show) data.show(_relatedtarget) }) } var old = $.fn.modal $.fn.modal = plugin $.fn.modal.constructor = modal // modal no conflict // ================= $.fn.modal.noconflict = function () { $.fn.modal = old return this } // modal data-api // ============== $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) { var $this = $(this) var href = $this.attr('href') var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7 var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data()) if ($this.is('a')) e.preventdefault() $target.one('show.bs.modal', function (showevent) { if (showevent.isdefaultprevented()) return // only register focus restorer if modal will actually get shown $target.one('hidden.bs.modal', function () { $this.is(':visible') && $this.trigger('focus') }) }) plugin.call($target, option, this) }) }(jquery);