simplyfy modal.js changes

This commit is contained in:
Felix Niklas 2015-01-15 12:01:04 +01:00
parent 3b85bda73d
commit 592b418473

View file

@ -8,8 +8,7 @@
/* /*
modified by Felix Jan-2014 modified by Felix Jan-2014
- change $body to $container - add this.$body = $(options.container || document.body)
- add this.$container = $(options.container || document.body)
*/ */
@ -21,7 +20,7 @@
var Modal = function (element, options) { var Modal = function (element, options) {
this.options = options this.options = options
this.$container = $(options.container || document.body) this.$body = $(options.container || document.body)
this.$element = $(element) this.$element = $(element)
this.$backdrop = this.$backdrop =
this.isShown = null this.isShown = null
@ -64,7 +63,7 @@
this.checkScrollbar() this.checkScrollbar()
this.setScrollbar() this.setScrollbar()
this.$container.addClass('modal-open') this.$body.addClass('modal-open')
this.escape() this.escape()
this.resize() this.resize()
@ -75,7 +74,7 @@
var transition = $.support.transition && that.$element.hasClass('fade') var transition = $.support.transition && that.$element.hasClass('fade')
if (!that.$element.parent().length) { if (!that.$element.parent().length) {
that.$element.appendTo(that.$container) // don't move modals dom position that.$element.appendTo(that.$body) // don't move modals dom position
} }
that.$element that.$element
@ -167,7 +166,7 @@
var that = this var that = this
this.$element.hide() this.$element.hide()
this.backdrop(function () { this.backdrop(function () {
that.$container.removeClass('modal-open') that.$body.removeClass('modal-open')
that.resetAdjustments() that.resetAdjustments()
that.resetScrollbar() that.resetScrollbar()
that.$element.trigger('hidden.bs.modal') that.$element.trigger('hidden.bs.modal')
@ -260,20 +259,20 @@
} }
Modal.prototype.setScrollbar = function () { Modal.prototype.setScrollbar = function () {
var bodyPad = parseInt((this.$container.css('padding-right') || 0), 10) var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10)
if (this.bodyIsOverflowing) this.$container.css('padding-right', bodyPad + this.scrollbarWidth) if (this.bodyIsOverflowing) this.$body.css('padding-right', bodyPad + this.scrollbarWidth)
} }
Modal.prototype.resetScrollbar = function () { Modal.prototype.resetScrollbar = function () {
this.$container.css('padding-right', '') this.$body.css('padding-right', '')
} }
Modal.prototype.measureScrollbar = function () { // thx walsh Modal.prototype.measureScrollbar = function () { // thx walsh
var scrollDiv = document.createElement('div') var scrollDiv = document.createElement('div')
scrollDiv.className = 'modal-scrollbar-measure' scrollDiv.className = 'modal-scrollbar-measure'
this.$container.append(scrollDiv) this.$body.append(scrollDiv)
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
this.$container[0].removeChild(scrollDiv) this.$body[0].removeChild(scrollDiv)
return scrollbarWidth return scrollbarWidth
} }