diff options
author | Mark Otto <otto@github.com> | 2012-12-20 12:02:52 +0400 |
---|---|---|
committer | Mark Otto <otto@github.com> | 2012-12-20 12:02:52 +0400 |
commit | 72f13e2870c431f132b9f63cc9d7e87bc6810425 (patch) | |
tree | ca5e4d8cbbcd3f3ef57ac04fad009d39fbf7b89a /docs/assets/js/bootstrap.js | |
parent | 14844db862a61c92be982921e14a526484f3b8a9 (diff) | |
parent | 9726fded1c587c14b57a61a92b88ac74fe21d320 (diff) |
Merge branch '2.2.3' into 3.0.0-wip
Conflicts:
Makefile
README.md
component.json
docs/assets/css/bootstrap-responsive.css
docs/assets/css/bootstrap.css
docs/assets/js/bootstrap-affix.js
docs/assets/js/bootstrap-alert.js
docs/assets/js/bootstrap-button.js
docs/assets/js/bootstrap-carousel.js
docs/assets/js/bootstrap-collapse.js
docs/assets/js/bootstrap-dropdown.js
docs/assets/js/bootstrap-modal.js
docs/assets/js/bootstrap-popover.js
docs/assets/js/bootstrap-scrollspy.js
docs/assets/js/bootstrap-tab.js
docs/assets/js/bootstrap-tooltip.js
docs/assets/js/bootstrap-transition.js
docs/assets/js/bootstrap-typeahead.js
docs/assets/js/bootstrap.js
docs/assets/js/bootstrap.min.js
docs/index.html
docs/templates/pages/base-css.mustache
docs/templates/pages/index.mustache
docs/templates/pages/javascript.mustache
js/bootstrap-affix.js
js/bootstrap-alert.js
js/bootstrap-button.js
js/bootstrap-carousel.js
js/bootstrap-collapse.js
js/bootstrap-dropdown.js
js/bootstrap-modal.js
js/bootstrap-popover.js
js/bootstrap-scrollspy.js
js/bootstrap-tab.js
js/bootstrap-tooltip.js
js/bootstrap-transition.js
js/bootstrap-typeahead.js
less/bootstrap.less
less/responsive.less
less/type.less
package.json
Diffstat (limited to 'docs/assets/js/bootstrap.js')
-rw-r--r-- | docs/assets/js/bootstrap.js | 67 |
1 files changed, 45 insertions, 22 deletions
diff --git a/docs/assets/js/bootstrap.js b/docs/assets/js/bootstrap.js index 9479fcf84e..59c3534a63 100644 --- a/docs/assets/js/bootstrap.js +++ b/docs/assets/js/bootstrap.js @@ -289,6 +289,7 @@ var Carousel = function (element, options) { this.$element = $(element) + this.$indicators = this.$element.find('.carousel-indicators') this.options = options this.options.pause == 'hover' && this.$element .on('mouseenter', $.proxy(this.pause, this)) @@ -305,13 +306,17 @@ return this } + , getActiveIndex: function () { + this.$active = this.$element.find('.item.active') + this.$items = this.$active.parent().children() + return this.$items.index(this.$active) + } + , to: function (pos) { - var $active = this.$element.find('.item.active') - , children = $active.parent().children() - , activePos = children.index($active) + var activeIndex = this.getActiveIndex() , that = this - if (pos > (children.length - 1) || pos < 0) return + if (pos > (this.$items.length - 1) || pos < 0) return if (this.sliding) { return this.$element.one('slid', function () { @@ -319,11 +324,11 @@ }) } - if (activePos == pos) { + if (activeIndex == pos) { return this.pause().cycle() } - return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos])) + return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos])) } , pause: function (e) { @@ -368,6 +373,14 @@ if ($next.hasClass('active')) return + if (this.$indicators.length) { + this.$indicators.find('.active').removeClass('active') + this.$element.one('slid', function () { + var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()]) + $nextIndicator && $nextIndicator.addClass('active') + }) + } + if ($.support.transition && this.$element.hasClass('slide')) { this.$element.trigger(e) if (e.isDefaultPrevented()) return @@ -726,8 +739,9 @@ selector = selector && /#/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 } - $parent = $(selector) - $parent.length || ($parent = $this.parent()) + $parent = selector && $(selector) + + if (!$parent || !$parent.length) $parent = $this.parent() return $parent } @@ -831,8 +845,7 @@ that.$element.appendTo(document.body) //don't move modals dom position } - that.$element - .show() + that.$element.show() if (transition) { that.$element[0].offsetWidth // force reflow @@ -1113,7 +1126,6 @@ , show: function () { var $tip - , inside , pos , actualWidth , actualHeight @@ -1132,19 +1144,17 @@ this.options.placement.call(this, $tip[0], this.$element[0]) : this.options.placement - inside = /in/.test(placement) - $tip .detach() .css({ top: 0, left: 0, display: 'block' }) .insertAfter(this.$element) - pos = this.getPosition(inside) + pos = this.getPosition() actualWidth = $tip[0].offsetWidth actualHeight = $tip[0].offsetHeight - switch (inside ? placement.split(' ')[1] : placement) { + switch (placement) { case 'bottom': tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2} break @@ -1209,11 +1219,12 @@ return this.getTitle() } - , getPosition: function (inside) { - return $.extend({}, (inside ? {top: 0, left: 0} : this.$element.offset()), { - width: this.$element[0].offsetWidth - , height: this.$element[0].offsetHeight - }) + , getPosition: function () { + var el = this.$element[0] + return $.extend({}, el.getBoundingClientRect ? el.getBoundingClientRect() : { + width: el.offsetWidth + , height: el.offsetHeight + }, this.$element.offset()) } , getTitle: function () { @@ -1892,6 +1903,7 @@ , listen: function () { this.$element + .on('focus', $.proxy(this.focus, this)) .on('blur', $.proxy(this.blur, this)) .on('keypress', $.proxy(this.keypress, this)) .on('keyup', $.proxy(this.keyup, this)) @@ -1903,6 +1915,7 @@ this.$menu .on('click', $.proxy(this.click, this)) .on('mouseenter', 'li', $.proxy(this.mouseenter, this)) + .on('mouseleave', 'li', $.proxy(this.mouseleave, this)) } , eventSupported: function(eventName) { @@ -1976,9 +1989,13 @@ e.preventDefault() } + , focus: function (e) { + this.focused = true + } + , blur: function (e) { - var that = this - setTimeout(function () { that.hide() }, 150) + this.focused = false + if (!this.mousedover && this.shown) this.hide() } , click: function (e) { @@ -1988,10 +2005,16 @@ } , mouseenter: function (e) { + this.mousedover = true this.$menu.find('.active').removeClass('active') $(e.currentTarget).addClass('active') } + , mouseleave: function (e) { + this.mousedover = false + if (!this.focused && this.shown) this.hide() + } + } |