diff options
author | Gleb Mazovetskiy <glex.spb@gmail.com> | 2014-11-12 18:29:47 +0300 |
---|---|---|
committer | Gleb Mazovetskiy <glex.spb@gmail.com> | 2014-11-12 18:29:47 +0300 |
commit | f0fc412cf352ccace36012c0ef72f176ba16c8a2 (patch) | |
tree | d13a551e442d4264d785dac2318454d5550ab36c /assets/javascripts/bootstrap | |
parent | 5f1800ab526266469217ed7bcfd05bdce6eb0c92 (diff) |
rake convert
Diffstat (limited to 'assets/javascripts/bootstrap')
-rw-r--r-- | assets/javascripts/bootstrap/button.js | 2 | ||||
-rw-r--r-- | assets/javascripts/bootstrap/carousel.js | 1 | ||||
-rw-r--r-- | assets/javascripts/bootstrap/dropdown.js | 2 | ||||
-rw-r--r-- | assets/javascripts/bootstrap/modal.js | 49 |
4 files changed, 49 insertions, 5 deletions
diff --git a/assets/javascripts/bootstrap/button.js b/assets/javascripts/bootstrap/button.js index 2be02341..40382949 100644 --- a/assets/javascripts/bootstrap/button.js +++ b/assets/javascripts/bootstrap/button.js @@ -110,7 +110,7 @@ e.preventDefault() }) .on('focus.bs.button.data-api blur.bs.button.data-api', '[data-toggle^="button"]', function (e) { - $(e.target).closest('.btn').toggleClass('focus', e.type == 'focus') + $(e.target).closest('.btn').toggleClass('focus', /^focus(in)?$/.test(e.type)) }) }(jQuery); diff --git a/assets/javascripts/bootstrap/carousel.js b/assets/javascripts/bootstrap/carousel.js index 4e4e4779..82106d27 100644 --- a/assets/javascripts/bootstrap/carousel.js +++ b/assets/javascripts/bootstrap/carousel.js @@ -42,6 +42,7 @@ } Carousel.prototype.keydown = function (e) { + if (/input|textarea/i.test(e.target.tagName)) return switch (e.which) { case 37: this.prev(); break case 39: this.next(); break diff --git a/assets/javascripts/bootstrap/dropdown.js b/assets/javascripts/bootstrap/dropdown.js index ae192e57..64ec34d5 100644 --- a/assets/javascripts/bootstrap/dropdown.js +++ b/assets/javascripts/bootstrap/dropdown.js @@ -55,7 +55,7 @@ } Dropdown.prototype.keydown = function (e) { - if (!/(38|40|27|32)/.test(e.which)) return + if (!/(38|40|27|32)/.test(e.which) || /input|textarea/i.test(e.target.tagName)) return var $this = $(this) diff --git a/assets/javascripts/bootstrap/modal.js b/assets/javascripts/bootstrap/modal.js index 8b0e269b..ed3f0293 100644 --- a/assets/javascripts/bootstrap/modal.js +++ b/assets/javascripts/bootstrap/modal.js @@ -56,10 +56,11 @@ this.isShown = true this.checkScrollbar() + this.setScrollbar() this.$body.addClass('modal-open') - this.setScrollbar() this.escape() + this.resize() this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this)) @@ -74,6 +75,9 @@ .show() .scrollTop(0) + if (that.options.backdrop) that.adjustBackdrop() + that.adjustDialog() + if (transition) { that.$element[0].offsetWidth // force reflow } @@ -108,6 +112,7 @@ this.isShown = false this.escape() + this.resize() $(document).off('focusin.bs.modal') @@ -143,11 +148,20 @@ } } + Modal.prototype.resize = function () { + if (this.isShown) { + $(window).on('resize.bs.modal', $.proxy(this.handleUpdate, this)) + } else { + $(window).off('resize.bs.modal') + } + } + Modal.prototype.hideModal = function () { var that = this this.$element.hide() this.backdrop(function () { that.$body.removeClass('modal-open') + that.resetAdjustments() that.resetScrollbar() that.$element.trigger('hidden.bs.modal') }) @@ -204,13 +218,43 @@ } } + // these following methods are used to handle overflowing modals + + Modal.prototype.handleUpdate = function () { + if (this.options.backdrop) this.adjustBackdrop() + this.adjustDialog() + } + + Modal.prototype.adjustBackdrop = function () { + this.$backdrop + .css('height', 0) + .css('height', this.$element[0].scrollHeight) + } + + Modal.prototype.adjustDialog = function () { + var modalIsOverflowing = this.$element[0].scrollHeight > document.documentElement.clientHeight + + this.$element.css({ + paddingLeft: !this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : '', + paddingRight: this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : '' + }) + } + + Modal.prototype.resetAdjustments = function () { + this.$element.css({ + paddingLeft: '', + paddingRight: '' + }) + } + Modal.prototype.checkScrollbar = function () { + this.bodyIsOverflowing = document.body.scrollHeight > document.documentElement.clientHeight 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) + if (this.bodyIsOverflowing) this.$body.css('padding-right', bodyPad + this.scrollbarWidth) } Modal.prototype.resetScrollbar = function () { @@ -218,7 +262,6 @@ } Modal.prototype.measureScrollbar = function () { // thx walsh - if (document.body.clientWidth >= window.innerWidth) return 0 var scrollDiv = document.createElement('div') scrollDiv.className = 'modal-scrollbar-measure' this.$body.append(scrollDiv) |