From 0d33455ef486d0cf06cb29d427efda57f42f7ea9 Mon Sep 17 00:00:00 2001 From: John-Philip Johansson Date: Sat, 4 May 2013 16:55:52 +0200 Subject: Replace Makefile with GruntJS A rebase (against soon-to-be 3.0.0-rc.1) & squash of https://github.com/twbs/bootstrap/pull/7786 AKA https://github.com/twitter/bootstrap/pull/7786 originally by @seriema @mokkabonna @jojohess Rebased by @cvrebert --- dist/js/bootstrap.js | 1315 +++++++++++++++++++++++++------------------------- 1 file changed, 664 insertions(+), 651 deletions(-) (limited to 'dist/js/bootstrap.js') diff --git a/dist/js/bootstrap.js b/dist/js/bootstrap.js index 0295d98fb..1bb1212ce 100644 --- a/dist/js/bootstrap.js +++ b/dist/js/bootstrap.js @@ -1,11 +1,13 @@ -if (!jQuery) { throw new Error("Bootstrap requires jQuery") } - - +/** +* bootstrap.js v3.0.0 by @fat and @mdo +* Copyright 2013 Twitter Inc. +* http://www.apache.org/licenses/LICENSE-2.0 +*/ /* ======================================================================== - * Bootstrap: transition.js v3.0.0 - * http://twbs.github.com/bootstrap/javascript.html#transitions + * Bootstrap: affix.js v3.0.0 + * http://twbs.github.com/bootstrap/javascript.html#affix * ======================================================================== - * Copyright 2013 Twitter, Inc. + * Copyright 2012 Twitter, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,39 +25,111 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } +function ($) { "use strict"; - // CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/) - // ============================================================ + // AFFIX CLASS DEFINITION + // ====================== - function transitionEnd() { - var el = document.createElement('bootstrap') + var Affix = function (element, options) { + this.options = $.extend({}, Affix.DEFAULTS, options) + this.$window = $(window) + .on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this)) + .on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this)) - var transEndEventNames = { - 'WebkitTransition' : 'webkitTransitionEnd' - , 'MozTransition' : 'transitionend' - , 'OTransition' : 'oTransitionEnd otransitionend' - , 'transition' : 'transitionend' - } + this.$element = $(element) + this.affixed = + this.unpin = null - for (var name in transEndEventNames) { - if (el.style[name] !== undefined) { - return { end: transEndEventNames[name] } - } + this.checkPosition() + } + + Affix.RESET = 'affix affix-top affix-bottom' + + Affix.DEFAULTS = { + offset: 0 + } + + Affix.prototype.checkPositionWithEventLoop = function () { + setTimeout($.proxy(this.checkPosition, this), 1) + } + + Affix.prototype.checkPosition = function () { + if (!this.$element.is(':visible')) return + + var scrollHeight = $(document).height() + var scrollTop = this.$window.scrollTop() + var position = this.$element.offset() + var offset = this.options.offset + var offsetTop = offset.top + var offsetBottom = offset.bottom + + if (typeof offset != 'object') offsetBottom = offsetTop = offset + if (typeof offsetTop == 'function') offsetTop = offset.top() + if (typeof offsetBottom == 'function') offsetBottom = offset.bottom() + + var affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ? false : + offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ? 'bottom' : + offsetTop != null && (scrollTop <= offsetTop) ? 'top' : false + + if (this.affixed === affix) return + if (this.unpin) this.$element.css('top', '') + + this.affixed = affix + this.unpin = affix == 'bottom' ? position.top - scrollTop : null + + this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : '')) + + if (affix == 'bottom') { + this.$element.offset({ top: document.body.offsetHeight - offsetBottom - this.$element.height() }) } } - // http://blog.alexmaccaw.com/css-transitions - $.fn.emulateTransitionEnd = function (duration) { - var called = false, $el = this - $(this).one('webkitTransitionEnd', function () { called = true }) - var callback = function () { if (!called) $($el).trigger('webkitTransitionEnd') } - setTimeout(callback, duration) + + // AFFIX PLUGIN DEFINITION + // ======================= + + var old = $.fn.affix + + $.fn.affix = function (option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.affix') + var options = typeof option == 'object' && option + + if (!data) $this.data('bs.affix', (data = new Affix(this, options))) + if (typeof option == 'string') data[option]() + }) } - $(function () { - $.support.transition = transitionEnd() + $.fn.affix.Constructor = Affix + + + // AFFIX NO CONFLICT + // ================= + + $.fn.affix.noConflict = function () { + $.fn.affix = old + return this + } + + + // AFFIX DATA-API + // ============== + + $(window).on('load', function () { + $('[data-spy="affix"]').each(function () { + var $spy = $(this) + var data = $spy.data() + + data.offset = data.offset || {} + + if (data.offsetBottom) data.offset.bottom = data.offsetBottom + if (data.offsetTop) data.offset.top = data.offsetTop + + $spy.affix(data) + }) }) }(window.jQuery); + /* ======================================================================== * Bootstrap: alert.js v3.0.0 * http://twbs.github.com/bootstrap/javascript.html#alerts @@ -154,6 +228,7 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } $(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close) }(window.jQuery); + /* ======================================================================== * Bootstrap: button.js v3.0.0 * http://twbs.github.com/bootstrap/javascript.html#buttons @@ -261,6 +336,7 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } }) }(window.jQuery); + /* ======================================================================== * Bootstrap: carousel.js v3.0.0 * http://twbs.github.com/bootstrap/javascript.html#carousel @@ -474,6 +550,7 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } }) }(window.jQuery); + /* ======================================================================== * Bootstrap: collapse.js v3.0.0 * http://twbs.github.com/bootstrap/javascript.html#collapse @@ -642,6 +719,7 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } }) }(window.jQuery); + /* ======================================================================== * Bootstrap: dropdown.js v3.0.0 * http://twbs.github.com/bootstrap/javascript.html#dropdowns @@ -796,6 +874,7 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } .on('keydown.bs.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown) }(window.jQuery); + /* ======================================================================== * Bootstrap: modal.js v3.0.0 * http://twbs.github.com/bootstrap/javascript.html#modals @@ -1037,10 +1116,10 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } .on('hidden.bs.modal', '.modal', function () { $body.removeClass('modal-open') }) }(window.jQuery); + /* ======================================================================== - * Bootstrap: tooltip.js v3.0.0 - * http://twbs.github.com/bootstrap/javascript.html#affix - * Inspired by the original jQuery.tipsy by Jason Frame + * Bootstrap: popover.js v3.0.0 + * http://twbs.github.com/bootstrap/javascript.html#popovers * ======================================================================== * Copyright 2012 Twitter, Inc. * @@ -1060,350 +1139,258 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } +function ($) { "use strict"; - // TOOLTIP PUBLIC CLASS DEFINITION + // POPOVER PUBLIC CLASS DEFINITION // =============================== - var Tooltip = function (element, options) { - this.type = - this.options = - this.enabled = - this.timeout = - this.hoverState = - this.$element = null - - this.init('tooltip', element, options) - } - - Tooltip.DEFAULTS = { - animation: true - , placement: 'top' - , selector: false - , template: '
' - , trigger: 'hover focus' - , title: '' - , delay: 0 - , html: false - , container: false + var Popover = function (element, options) { + this.init('popover', element, options) } - Tooltip.prototype.init = function (type, element, options) { - this.enabled = true - this.type = type - this.$element = $(element) - this.options = this.getOptions(options) + Popover.DEFAULTS = $.extend({} , $.fn.tooltip.Constructor.DEFAULTS, { + placement: 'right' + , trigger: 'click' + , content: '' + , template: '

' + }) - var triggers = this.options.trigger.split(' ') - for (var i = triggers.length; i--;) { - var trigger = triggers[i] + // NOTE: POPOVER EXTENDS tooltip.js + // ================================ - if (trigger == 'click') { - this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) - } else if (trigger != 'manual') { - var eventIn = trigger == 'hover' ? 'mouseenter' : 'focus' - var eventOut = trigger == 'hover' ? 'mouseleave' : 'blur' + Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype) - this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) - this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) - } - } + Popover.prototype.constructor = Popover - this.options.selector ? - (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : - this.fixTitle() + Popover.prototype.getDefaults = function () { + return Popover.DEFAULTS } - Tooltip.prototype.getDefaults = function () { - return Tooltip.DEFAULTS - } + Popover.prototype.setContent = function () { + var $tip = this.tip() + var title = this.getTitle() + var content = this.getContent() - Tooltip.prototype.getOptions = function (options) { - options = $.extend({}, this.getDefaults(), this.$element.data(), options) + $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title) + $tip.find('.popover-content')[this.options.html ? 'html' : 'text'](content) - if (options.delay && typeof options.delay == 'number') { - options.delay = { - show: options.delay - , hide: options.delay - } - } + $tip.removeClass('fade top bottom left right in') - return options + $tip.find('.popover-title:empty').hide() } - Tooltip.prototype.enter = function (obj) { - var defaults = this.getDefaults() - var options = {} - - this._options && $.each(this._options, function (key, value) { - if (defaults[key] != value) options[key] = value - }) + Popover.prototype.hasContent = function () { + return this.getTitle() || this.getContent() + } - var self = obj instanceof this.constructor ? - obj : $(obj.currentTarget)[this.type](options).data('bs.' + this.type) + Popover.prototype.getContent = function () { + var $e = this.$element + var o = this.options - clearTimeout(self.timeout) + return $e.attr('data-content') + || (typeof o.content == 'function' ? + o.content.call($e[0]) : + o.content) + } - if (!self.options.delay || !self.options.delay.show) return self.show() + Popover.prototype.tip = function () { + if (!this.$tip) this.$tip = $(this.options.template) + return this.$tip + } - self.hoverState = 'in' - self.timeout = setTimeout(function () { - if (self.hoverState == 'in') self.show() - }, self.options.delay.show) + Popover.prototype.destroy = function () { + this.hide().$element.off('.' + this.type).removeData(this.type) } - Tooltip.prototype.leave = function (obj) { - var self = obj instanceof this.constructor ? - obj : $(obj.currentTarget)[this.type](this._options).data('bs.' + this.type) - clearTimeout(self.timeout) + // POPOVER PLUGIN DEFINITION + // ========================= - if (!self.options.delay || !self.options.delay.hide) return self.hide() + var old = $.fn.popover - self.hoverState = 'out' - self.timeout = setTimeout(function () { - if (self.hoverState == 'out') self.hide() - }, self.options.delay.hide) - } + $.fn.popover = function (option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.popover') + var options = typeof option == 'object' && option - Tooltip.prototype.show = function () { - var e = $.Event('show.bs.'+ this.type) + if (!data) $this.data('bs.popover', (data = new Popover(this, options))) + if (typeof option == 'string') data[option]() + }) + } - if (this.hasContent() && this.enabled) { - this.$element.trigger(e) + $.fn.popover.Constructor = Popover - if (e.isDefaultPrevented()) return - var $tip = this.tip() + // POPOVER NO CONFLICT + // =================== - this.setContent() + $.fn.popover.noConflict = function () { + $.fn.popover = old + return this + } - if (this.options.animation) $tip.addClass('fade') +}(window.jQuery); - var placement = typeof this.options.placement == 'function' ? - this.options.placement.call(this, $tip[0], this.$element[0]) : - this.options.placement +/* ======================================================================== + * Bootstrap: scrollspy.js v3.0.0 + * http://twbs.github.com/bootstrap/javascript.html#scrollspy + * ======================================================================== + * Copyright 2012 Twitter, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ======================================================================== */ - var autoToken = /\s?auto?\s?/i - var autoPlace = autoToken.test(placement) - if (autoPlace) placement = placement.replace(autoToken, '') || 'top' - $tip - .detach() - .css({ top: 0, left: 0, display: 'block' }) - .addClass(placement) ++function ($) { "use strict"; - this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element) + // SCROLLSPY CLASS DEFINITION + // ========================== - var pos = this.getPosition() - var actualWidth = $tip[0].offsetWidth - var actualHeight = $tip[0].offsetHeight + function ScrollSpy(element, options) { + var href + var process = $.proxy(this.process, this) + var $element = $(element).is('body') ? $(window) : $(element) - if (autoPlace) { - var $parent = this.$element.parent() + this.$body = $('body') + this.$scrollElement = $element.on('scroll.bs.scroll-spy.data-api', process) + this.options = $.extend({}, ScrollSpy.DEFAULTS, options) + this.selector = (this.options.target + || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 + || '') + ' .nav li > a' + this.offsets = $([]) + this.targets = $([]) + this.activeTarget = null - var orgPlacement = placement - var docScroll = document.documentElement.scrollTop || document.body.scrollTop - var parentWidth = this.options.container == 'body' ? window.innerWidth : $parent.outerWidth() - var parentHeight = this.options.container == 'body' ? window.innerHeight : $parent.outerHeight() - var parentLeft = this.options.container == 'body' ? 0 : $parent.offset().left + this.refresh() + this.process() + } - placement = placement == 'bottom' && pos.top + pos.height + actualHeight - docScroll > parentHeight ? 'top' : - placement == 'top' && pos.top - docScroll - actualHeight < 0 ? 'bottom' : - placement == 'right' && pos.right + actualWidth > parentWidth ? 'left' : - placement == 'left' && pos.left - actualWidth < parentLeft ? 'right' : - placement + ScrollSpy.DEFAULTS = { + offset: 10 + } - $tip - .removeClass(orgPlacement) - .addClass(placement) - } + ScrollSpy.prototype.refresh = function () { + this.offsets = $([]) + this.targets = $([]) - var tp = placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } : - placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } : - placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } : - /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width } + var self = this + var $targets = this.$body + .find(this.selector) + .map(function () { + var $el = $(this) + var href = $el.data('target') || $el.attr('href') + var $href = /^#\w/.test(href) && $(href) - this.applyPlacement(tp, placement) - this.$element.trigger('shown.bs.' + this.type) - } + return ($href + && $href.length + && [[ $href.offset().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]]) || null + }) + .sort(function (a, b) { return a[0] - b[0] }) + .each(function () { + self.offsets.push(this[0]) + self.targets.push(this[1]) + }) } - Tooltip.prototype.applyPlacement = function(offset, placement) { - var replace - var $tip = this.tip() - var width = $tip[0].offsetWidth - var height = $tip[0].offsetHeight - - // manually read margins because getBoundingClientRect includes difference - offset.top = offset.top + parseInt($tip.css('margin-top'), 10) - offset.left = offset.left + parseInt($tip.css('margin-left'), 10) - - $tip - .offset(offset) - .addClass('in') + ScrollSpy.prototype.process = function () { + var scrollTop = this.$scrollElement.scrollTop() + this.options.offset + var scrollHeight = this.$scrollElement[0].scrollHeight || this.$body[0].scrollHeight + var maxScroll = scrollHeight - this.$scrollElement.height() + var offsets = this.offsets + var targets = this.targets + var activeTarget = this.activeTarget + var i - var actualWidth = $tip[0].offsetWidth - var actualHeight = $tip[0].offsetHeight + if (scrollTop >= maxScroll) { + return activeTarget != (i = targets.last()[0]) && this.activate(i) + } - if (placement == 'top' && actualHeight != height) { - replace = true - offset.top = offset.top + height - actualHeight + for (i = offsets.length; i--;) { + activeTarget != targets[i] + && scrollTop >= offsets[i] + && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) + && this.activate( targets[i] ) } + } - if (placement == 'bottom' || placement == 'top') { - var delta = 0 + ScrollSpy.prototype.activate = function (target) { + this.activeTarget = target - if (offset.left < 0){ - delta = offset.left * -2 - offset.left = 0 + $(this.selector) + .parents('.active') + .removeClass('active') - $tip.offset(offset) + var selector = this.selector + + '[data-target="' + target + '"],' + + this.selector + '[href="' + target + '"]' - actualWidth = $tip[0].offsetWidth - actualHeight = $tip[0].offsetHeight - } + var active = $(selector) + .parents('li') + .addClass('active') - this.replaceArrow(delta - width + actualWidth, actualWidth, 'left') - } else { - this.replaceArrow(actualHeight - height, actualHeight, 'top') + if (active.parent('.dropdown-menu').length) { + active = active + .closest('li.dropdown') + .addClass('active') } - if (replace) $tip.offset(offset) - } - - Tooltip.prototype.replaceArrow = function(delta, dimension, position) { - this.arrow().css(position, delta ? (50 * (1 - delta / dimension) + "%") : '') + active.trigger('activate') } - Tooltip.prototype.setContent = function () { - var $tip = this.tip() - var title = this.getTitle() - $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title) - $tip.removeClass('fade in top bottom left right') - } + // SCROLLSPY PLUGIN DEFINITION + // =========================== - Tooltip.prototype.hide = function () { - var that = this - var $tip = this.tip() - var e = $.Event('hide.bs.' + this.type) + var old = $.fn.scrollspy - this.$element.trigger(e) + $.fn.scrollspy = function (option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.scrollspy') + var options = typeof option == 'object' && option - if (e.isDefaultPrevented()) return + if (!data) $this.data('bs.scrollspy', (data = new ScrollSpy(this, options))) + if (typeof option == 'string') data[option]() + }) + } - $tip.removeClass('in') + $.fn.scrollspy.Constructor = ScrollSpy - $.support.transition && this.$tip.hasClass('fade') ? - $tip - .one($.support.transition.end, $tip.detach) - .emulateTransitionEnd(150) : - $tip.detach() - this.$element.trigger('hidden.bs.' + this.type) + // SCROLLSPY NO CONFLICT + // ===================== + $.fn.scrollspy.noConflict = function () { + $.fn.scrollspy = old return this } - Tooltip.prototype.fixTitle = function () { - var $e = this.$element - if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') { - $e.attr('data-original-title', $e.attr('title') || '').attr('title', '') - } - } - Tooltip.prototype.hasContent = function () { - return this.getTitle() - } + // SCROLLSPY DATA-API + // ================== - Tooltip.prototype.getPosition = function () { - var el = this.$element[0] - return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : { - width: el.offsetWidth - , height: el.offsetHeight - }, this.$element.offset()) - } + $(window).on('load', function () { + $('[data-spy="scroll"]').each(function () { + var $spy = $(this) + $spy.scrollspy($spy.data()) + }) + }) - Tooltip.prototype.getTitle = function () { - var title - var $e = this.$element - var o = this.options +}(window.jQuery); - title = $e.attr('data-original-title') - || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title) - - return title - } - - Tooltip.prototype.tip = function () { - return this.$tip = this.$tip || $(this.options.template) - } - - Tooltip.prototype.arrow =function(){ - return this.$arrow = this.$arrow || this.tip().find(".tooltip-arrow") - } - - Tooltip.prototype.validate = function () { - if (!this.$element[0].parentNode) { - this.hide() - this.$element = null - this.options = null - } - } - - Tooltip.prototype.enable = function () { - this.enabled = true - } - - Tooltip.prototype.disable = function () { - this.enabled = false - } - - Tooltip.prototype.toggleEnabled = function () { - this.enabled = !this.enabled - } - - Tooltip.prototype.toggle = function (e) { - var self = e ? $(e.currentTarget)[this.type](this._options).data('bs.' + this.type) : this - self.tip().hasClass('in') ? self.leave(self) : self.enter(self) - } - - Tooltip.prototype.destroy = function () { - this.hide().$element.off('.' + this.type).removeData('bs.' + this.type) - } - - - // TOOLTIP PLUGIN DEFINITION - // ========================= - - var old = $.fn.tooltip - - $.fn.tooltip = function (option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.tooltip') - var options = typeof option == 'object' && option - - if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options))) - if (typeof option == 'string') data[option]() - }) - } - - $.fn.tooltip.Constructor = Tooltip - - - // TOOLTIP NO CONFLICT - // =================== - - $.fn.tooltip.noConflict = function () { - $.fn.tooltip = old - return this - } - -}(window.jQuery); /* ======================================================================== - * Bootstrap: popover.js v3.0.0 - * http://twbs.github.com/bootstrap/javascript.html#popovers + * Bootstrap: tab.js v3.0.0 + * http://twbs.github.com/bootstrap/javascript.html#tabs * ======================================================================== * Copyright 2012 Twitter, Inc. * @@ -1423,100 +1410,124 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } +function ($) { "use strict"; - // POPOVER PUBLIC CLASS DEFINITION - // =============================== + // TAB CLASS DEFINITION + // ==================== - var Popover = function (element, options) { - this.init('popover', element, options) + var Tab = function (element) { + this.element = $(element) } - Popover.DEFAULTS = $.extend({} , $.fn.tooltip.Constructor.DEFAULTS, { - placement: 'right' - , trigger: 'click' - , content: '' - , template: '

' - }) + Tab.prototype.show = function () { + var $this = this.element + var $ul = $this.closest('ul:not(.dropdown-menu)') + var selector = $this.attr('data-target') + if (!selector) { + selector = $this.attr('href') + selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 + } - // NOTE: POPOVER EXTENDS tooltip.js - // ================================ + if ($this.parent('li').hasClass('active')) return - Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype) + var previous = $ul.find('.active:last a')[0] + var e = $.Event('show.bs.tab', { + relatedTarget: previous + }) - Popover.prototype.constructor = Popover + $this.trigger(e) - Popover.prototype.getDefaults = function () { - return Popover.DEFAULTS - } + if (e.isDefaultPrevented()) return - Popover.prototype.setContent = function () { - var $tip = this.tip() - var title = this.getTitle() - var content = this.getContent() + var $target = $(selector) - $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title) - $tip.find('.popover-content')[this.options.html ? 'html' : 'text'](content) + this.activate($this.parent('li'), $ul) + this.activate($target, $target.parent(), function () { + $this.trigger({ + type: 'shown.bs.tab' + , relatedTarget: previous + }) + }) + } - $tip.removeClass('fade top bottom left right in') + Tab.prototype.activate = function (element, container, callback) { + var $active = container.find('> .active') + var transition = callback + && $.support.transition + && $active.hasClass('fade') - $tip.find('.popover-title:empty').hide() - } + function next() { + $active + .removeClass('active') + .find('> .dropdown-menu > .active') + .removeClass('active') - Popover.prototype.hasContent = function () { - return this.getTitle() || this.getContent() - } + element.addClass('active') - Popover.prototype.getContent = function () { - var $e = this.$element - var o = this.options + if (transition) { + element[0].offsetWidth // reflow for transition + element.addClass('in') + } else { + element.removeClass('fade') + } - return $e.attr('data-content') - || (typeof o.content == 'function' ? - o.content.call($e[0]) : - o.content) - } + if (element.parent('.dropdown-menu')) { + element.closest('li.dropdown').addClass('active') + } - Popover.prototype.tip = function () { - if (!this.$tip) this.$tip = $(this.options.template) - return this.$tip - } + callback && callback() + } - Popover.prototype.destroy = function () { - this.hide().$element.off('.' + this.type).removeData(this.type) + transition ? + $active + .one($.support.transition.end, next) + .emulateTransitionEnd(150) : + next() + + $active.removeClass('in') } - // POPOVER PLUGIN DEFINITION - // ========================= + // TAB PLUGIN DEFINITION + // ===================== - var old = $.fn.popover + var old = $.fn.tab - $.fn.popover = function (option) { + $.fn.tab = function ( option ) { return this.each(function () { - var $this = $(this) - var data = $this.data('bs.popover') - var options = typeof option == 'object' && option + var $this = $(this) + var data = $this.data('bs.tab') - if (!data) $this.data('bs.popover', (data = new Popover(this, options))) + if (!data) $this.data('bs.tab', (data = new Tab(this))) if (typeof option == 'string') data[option]() }) } - $.fn.popover.Constructor = Popover + $.fn.tab.Constructor = Tab - // POPOVER NO CONFLICT - // =================== + // TAB NO CONFLICT + // =============== - $.fn.popover.noConflict = function () { - $.fn.popover = old + $.fn.tab.noConflict = function () { + $.fn.tab = old return this } + + // TAB DATA-API + // ============ + + $(document).on('click.bs.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) { + e.preventDefault() + $(this).tab('show') + }) + }(window.jQuery); + /* ======================================================================== - * Bootstrap: scrollspy.js v3.0.0 - * http://twbs.github.com/bootstrap/javascript.html#scrollspy + * Bootstrap: tooltip.js v3.0.0 + * http://twbs.github.com/bootstrap/javascript.html#affix + * Inspired by the original jQuery.tipsy by Jason Frame * ======================================================================== * Copyright 2012 Twitter, Inc. * @@ -1536,280 +1547,353 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } +function ($) { "use strict"; - // SCROLLSPY CLASS DEFINITION - // ========================== - - function ScrollSpy(element, options) { - var href - var process = $.proxy(this.process, this) - var $element = $(element).is('body') ? $(window) : $(element) + // TOOLTIP PUBLIC CLASS DEFINITION + // =============================== - this.$body = $('body') - this.$scrollElement = $element.on('scroll.bs.scroll-spy.data-api', process) - this.options = $.extend({}, ScrollSpy.DEFAULTS, options) - this.selector = (this.options.target - || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 - || '') + ' .nav li > a' - this.offsets = $([]) - this.targets = $([]) - this.activeTarget = null + var Tooltip = function (element, options) { + this.type = + this.options = + this.enabled = + this.timeout = + this.hoverState = + this.$element = null - this.refresh() - this.process() + this.init('tooltip', element, options) } - ScrollSpy.DEFAULTS = { - offset: 10 + Tooltip.DEFAULTS = { + animation: true + , placement: 'top' + , selector: false + , template: '
' + , trigger: 'hover focus' + , title: '' + , delay: 0 + , html: false + , container: false } - ScrollSpy.prototype.refresh = function () { - this.offsets = $([]) - this.targets = $([]) + Tooltip.prototype.init = function (type, element, options) { + this.enabled = true + this.type = type + this.$element = $(element) + this.options = this.getOptions(options) - var self = this - var $targets = this.$body - .find(this.selector) - .map(function () { - var $el = $(this) - var href = $el.data('target') || $el.attr('href') - var $href = /^#\w/.test(href) && $(href) + var triggers = this.options.trigger.split(' ') - return ($href - && $href.length - && [[ $href.offset().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]]) || null - }) - .sort(function (a, b) { return a[0] - b[0] }) - .each(function () { - self.offsets.push(this[0]) - self.targets.push(this[1]) - }) - } + for (var i = triggers.length; i--;) { + var trigger = triggers[i] - ScrollSpy.prototype.process = function () { - var scrollTop = this.$scrollElement.scrollTop() + this.options.offset - var scrollHeight = this.$scrollElement[0].scrollHeight || this.$body[0].scrollHeight - var maxScroll = scrollHeight - this.$scrollElement.height() - var offsets = this.offsets - var targets = this.targets - var activeTarget = this.activeTarget - var i + if (trigger == 'click') { + this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) + } else if (trigger != 'manual') { + var eventIn = trigger == 'hover' ? 'mouseenter' : 'focus' + var eventOut = trigger == 'hover' ? 'mouseleave' : 'blur' - if (scrollTop >= maxScroll) { - return activeTarget != (i = targets.last()[0]) && this.activate(i) + this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) + this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) + } } - for (i = offsets.length; i--;) { - activeTarget != targets[i] - && scrollTop >= offsets[i] - && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) - && this.activate( targets[i] ) + this.options.selector ? + (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : + this.fixTitle() + } + + Tooltip.prototype.getDefaults = function () { + return Tooltip.DEFAULTS + } + + Tooltip.prototype.getOptions = function (options) { + options = $.extend({}, this.getDefaults(), this.$element.data(), options) + + if (options.delay && typeof options.delay == 'number') { + options.delay = { + show: options.delay + , hide: options.delay + } } + + return options } - ScrollSpy.prototype.activate = function (target) { - this.activeTarget = target + Tooltip.prototype.enter = function (obj) { + var defaults = this.getDefaults() + var options = {} - $(this.selector) - .parents('.active') - .removeClass('active') + this._options && $.each(this._options, function (key, value) { + if (defaults[key] != value) options[key] = value + }) - var selector = this.selector - + '[data-target="' + target + '"],' - + this.selector + '[href="' + target + '"]' + var self = obj instanceof this.constructor ? + obj : $(obj.currentTarget)[this.type](options).data('bs.' + this.type) - var active = $(selector) - .parents('li') - .addClass('active') + clearTimeout(self.timeout) - if (active.parent('.dropdown-menu').length) { - active = active - .closest('li.dropdown') - .addClass('active') - } + if (!self.options.delay || !self.options.delay.show) return self.show() - active.trigger('activate') + self.hoverState = 'in' + self.timeout = setTimeout(function () { + if (self.hoverState == 'in') self.show() + }, self.options.delay.show) } + Tooltip.prototype.leave = function (obj) { + var self = obj instanceof this.constructor ? + obj : $(obj.currentTarget)[this.type](this._options).data('bs.' + this.type) - // SCROLLSPY PLUGIN DEFINITION - // =========================== - - var old = $.fn.scrollspy + clearTimeout(self.timeout) - $.fn.scrollspy = function (option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.scrollspy') - var options = typeof option == 'object' && option + if (!self.options.delay || !self.options.delay.hide) return self.hide() - if (!data) $this.data('bs.scrollspy', (data = new ScrollSpy(this, options))) - if (typeof option == 'string') data[option]() - }) + self.hoverState = 'out' + self.timeout = setTimeout(function () { + if (self.hoverState == 'out') self.hide() + }, self.options.delay.hide) } - $.fn.scrollspy.Constructor = ScrollSpy + Tooltip.prototype.show = function () { + var e = $.Event('show.bs.'+ this.type) + if (this.hasContent() && this.enabled) { + this.$element.trigger(e) - // SCROLLSPY NO CONFLICT - // ===================== + if (e.isDefaultPrevented()) return - $.fn.scrollspy.noConflict = function () { - $.fn.scrollspy = old - return this + var $tip = this.tip() + + this.setContent() + + if (this.options.animation) $tip.addClass('fade') + + var placement = typeof this.options.placement == 'function' ? + this.options.placement.call(this, $tip[0], this.$element[0]) : + this.options.placement + + var autoToken = /\s?auto?\s?/i + var autoPlace = autoToken.test(placement) + if (autoPlace) placement = placement.replace(autoToken, '') || 'top' + + $tip + .detach() + .css({ top: 0, left: 0, display: 'block' }) + .addClass(placement) + + this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element) + + var pos = this.getPosition() + var actualWidth = $tip[0].offsetWidth + var actualHeight = $tip[0].offsetHeight + + if (autoPlace) { + var $parent = this.$element.parent() + + var orgPlacement = placement + var docScroll = document.documentElement.scrollTop || document.body.scrollTop + var parentWidth = this.options.container == 'body' ? window.innerWidth : $parent.outerWidth() + var parentHeight = this.options.container == 'body' ? window.innerHeight : $parent.outerHeight() + var parentLeft = this.options.container == 'body' ? 0 : $parent.offset().left + + placement = placement == 'bottom' && pos.top + pos.height + actualHeight - docScroll > parentHeight ? 'top' : + placement == 'top' && pos.top - docScroll - actualHeight < 0 ? 'bottom' : + placement == 'right' && pos.right + actualWidth > parentWidth ? 'left' : + placement == 'left' && pos.left - actualWidth < parentLeft ? 'right' : + placement + + $tip + .removeClass(orgPlacement) + .addClass(placement) + } + + var tp = placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } : + placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } : + placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } : + /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width } + + this.applyPlacement(tp, placement) + this.$element.trigger('shown.bs.' + this.type) + } } + Tooltip.prototype.applyPlacement = function(offset, placement) { + var replace + var $tip = this.tip() + var width = $tip[0].offsetWidth + var height = $tip[0].offsetHeight - // SCROLLSPY DATA-API - // ================== + // manually read margins because getBoundingClientRect includes difference + offset.top = offset.top + parseInt($tip.css('margin-top'), 10) + offset.left = offset.left + parseInt($tip.css('margin-left'), 10) - $(window).on('load', function () { - $('[data-spy="scroll"]').each(function () { - var $spy = $(this) - $spy.scrollspy($spy.data()) - }) - }) + $tip + .offset(offset) + .addClass('in') -}(window.jQuery); -/* ======================================================================== - * Bootstrap: tab.js v3.0.0 - * http://twbs.github.com/bootstrap/javascript.html#tabs - * ======================================================================== - * Copyright 2012 Twitter, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ======================================================================== */ + var actualWidth = $tip[0].offsetWidth + var actualHeight = $tip[0].offsetHeight + if (placement == 'top' && actualHeight != height) { + replace = true + offset.top = offset.top + height - actualHeight + } -+function ($) { "use strict"; + if (placement == 'bottom' || placement == 'top') { + var delta = 0 - // TAB CLASS DEFINITION - // ==================== + if (offset.left < 0){ + delta = offset.left * -2 + offset.left = 0 - var Tab = function (element) { - this.element = $(element) + $tip.offset(offset) + + actualWidth = $tip[0].offsetWidth + actualHeight = $tip[0].offsetHeight + } + + this.replaceArrow(delta - width + actualWidth, actualWidth, 'left') + } else { + this.replaceArrow(actualHeight - height, actualHeight, 'top') + } + + if (replace) $tip.offset(offset) } - Tab.prototype.show = function () { - var $this = this.element - var $ul = $this.closest('ul:not(.dropdown-menu)') - var selector = $this.attr('data-target') + Tooltip.prototype.replaceArrow = function(delta, dimension, position) { + this.arrow().css(position, delta ? (50 * (1 - delta / dimension) + "%") : '') + } + + Tooltip.prototype.setContent = function () { + var $tip = this.tip() + var title = this.getTitle() + + $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title) + $tip.removeClass('fade in top bottom left right') + } + + Tooltip.prototype.hide = function () { + var that = this + var $tip = this.tip() + var e = $.Event('hide.bs.' + this.type) + + this.$element.trigger(e) + + if (e.isDefaultPrevented()) return + + $tip.removeClass('in') + + $.support.transition && this.$tip.hasClass('fade') ? + $tip + .one($.support.transition.end, $tip.detach) + .emulateTransitionEnd(150) : + $tip.detach() + + this.$element.trigger('hidden.bs.' + this.type) - if (!selector) { - selector = $this.attr('href') - selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 - } + return this + } - if ($this.parent('li').hasClass('active')) return + Tooltip.prototype.fixTitle = function () { + var $e = this.$element + if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') { + $e.attr('data-original-title', $e.attr('title') || '').attr('title', '') + } + } - var previous = $ul.find('.active:last a')[0] - var e = $.Event('show.bs.tab', { - relatedTarget: previous - }) + Tooltip.prototype.hasContent = function () { + return this.getTitle() + } - $this.trigger(e) + Tooltip.prototype.getPosition = function () { + var el = this.$element[0] + return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : { + width: el.offsetWidth + , height: el.offsetHeight + }, this.$element.offset()) + } - if (e.isDefaultPrevented()) return + Tooltip.prototype.getTitle = function () { + var title + var $e = this.$element + var o = this.options - var $target = $(selector) + title = $e.attr('data-original-title') + || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title) - this.activate($this.parent('li'), $ul) - this.activate($target, $target.parent(), function () { - $this.trigger({ - type: 'shown.bs.tab' - , relatedTarget: previous - }) - }) + return title } - Tab.prototype.activate = function (element, container, callback) { - var $active = container.find('> .active') - var transition = callback - && $.support.transition - && $active.hasClass('fade') + Tooltip.prototype.tip = function () { + return this.$tip = this.$tip || $(this.options.template) + } - function next() { - $active - .removeClass('active') - .find('> .dropdown-menu > .active') - .removeClass('active') + Tooltip.prototype.arrow =function(){ + return this.$arrow = this.$arrow || this.tip().find(".tooltip-arrow") + } - element.addClass('active') + Tooltip.prototype.validate = function () { + if (!this.$element[0].parentNode) { + this.hide() + this.$element = null + this.options = null + } + } - if (transition) { - element[0].offsetWidth // reflow for transition - element.addClass('in') - } else { - element.removeClass('fade') - } + Tooltip.prototype.enable = function () { + this.enabled = true + } - if (element.parent('.dropdown-menu')) { - element.closest('li.dropdown').addClass('active') - } + Tooltip.prototype.disable = function () { + this.enabled = false + } - callback && callback() - } + Tooltip.prototype.toggleEnabled = function () { + this.enabled = !this.enabled + } - transition ? - $active - .one($.support.transition.end, next) - .emulateTransitionEnd(150) : - next() + Tooltip.prototype.toggle = function (e) { + var self = e ? $(e.currentTarget)[this.type](this._options).data('bs.' + this.type) : this + self.tip().hasClass('in') ? self.leave(self) : self.enter(self) + } - $active.removeClass('in') + Tooltip.prototype.destroy = function () { + this.hide().$element.off('.' + this.type).removeData('bs.' + this.type) } - // TAB PLUGIN DEFINITION - // ===================== + // TOOLTIP PLUGIN DEFINITION + // ========================= - var old = $.fn.tab + var old = $.fn.tooltip - $.fn.tab = function ( option ) { + $.fn.tooltip = function (option) { return this.each(function () { - var $this = $(this) - var data = $this.data('bs.tab') + var $this = $(this) + var data = $this.data('bs.tooltip') + var options = typeof option == 'object' && option - if (!data) $this.data('bs.tab', (data = new Tab(this))) + if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options))) if (typeof option == 'string') data[option]() }) } - $.fn.tab.Constructor = Tab + $.fn.tooltip.Constructor = Tooltip - // TAB NO CONFLICT - // =============== + // TOOLTIP NO CONFLICT + // =================== - $.fn.tab.noConflict = function () { - $.fn.tab = old + $.fn.tooltip.noConflict = function () { + $.fn.tooltip = old return this } - - // TAB DATA-API - // ============ - - $(document).on('click.bs.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) { - e.preventDefault() - $(this).tab('show') - }) - }(window.jQuery); + /* ======================================================================== - * Bootstrap: affix.js v3.0.0 - * http://twbs.github.com/bootstrap/javascript.html#affix + * Bootstrap: transition.js v3.0.0 + * http://twbs.github.com/bootstrap/javascript.html#transitions * ======================================================================== - * Copyright 2012 Twitter, Inc. + * Copyright 2013 Twitter, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1827,107 +1911,36 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } +function ($) { "use strict"; - // AFFIX CLASS DEFINITION - // ====================== - - var Affix = function (element, options) { - this.options = $.extend({}, Affix.DEFAULTS, options) - this.$window = $(window) - .on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this)) - .on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this)) - - this.$element = $(element) - this.affixed = - this.unpin = null - - this.checkPosition() - } - - Affix.RESET = 'affix affix-top affix-bottom' - - Affix.DEFAULTS = { - offset: 0 - } - - Affix.prototype.checkPositionWithEventLoop = function () { - setTimeout($.proxy(this.checkPosition, this), 1) - } - - Affix.prototype.checkPosition = function () { - if (!this.$element.is(':visible')) return - - var scrollHeight = $(document).height() - var scrollTop = this.$window.scrollTop() - var position = this.$element.offset() - var offset = this.options.offset - var offsetTop = offset.top - var offsetBottom = offset.bottom - - if (typeof offset != 'object') offsetBottom = offsetTop = offset - if (typeof offsetTop == 'function') offsetTop = offset.top() - if (typeof offsetBottom == 'function') offsetBottom = offset.bottom() - - var affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ? false : - offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ? 'bottom' : - offsetTop != null && (scrollTop <= offsetTop) ? 'top' : false - - if (this.affixed === affix) return - if (this.unpin) this.$element.css('top', '') - - this.affixed = affix - this.unpin = affix == 'bottom' ? position.top - scrollTop : null + // CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/) + // ============================================================ - this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : '')) + function transitionEnd() { + var el = document.createElement('bootstrap') - if (affix == 'bottom') { - this.$element.offset({ top: document.body.offsetHeight - offsetBottom - this.$element.height() }) + var transEndEventNames = { + 'WebkitTransition' : 'webkitTransitionEnd' + , 'MozTransition' : 'transitionend' + , 'OTransition' : 'oTransitionEnd otransitionend' + , 'transition' : 'transitionend' } - } - - - // AFFIX PLUGIN DEFINITION - // ======================= - - var old = $.fn.affix - - $.fn.affix = function (option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.affix') - var options = typeof option == 'object' && option - if (!data) $this.data('bs.affix', (data = new Affix(this, options))) - if (typeof option == 'string') data[option]() - }) + for (var name in transEndEventNames) { + if (el.style[name] !== undefined) { + return { end: transEndEventNames[name] } + } + } } - $.fn.affix.Constructor = Affix - - - // AFFIX NO CONFLICT - // ================= - - $.fn.affix.noConflict = function () { - $.fn.affix = old - return this + // http://blog.alexmaccaw.com/css-transitions + $.fn.emulateTransitionEnd = function (duration) { + var called = false, $el = this + $(this).one('webkitTransitionEnd', function () { called = true }) + var callback = function () { if (!called) $($el).trigger('webkitTransitionEnd') } + setTimeout(callback, duration) } - - // AFFIX DATA-API - // ============== - - $(window).on('load', function () { - $('[data-spy="affix"]').each(function () { - var $spy = $(this) - var data = $spy.data() - - data.offset = data.offset || {} - - if (data.offsetBottom) data.offset.bottom = data.offsetBottom - if (data.offsetTop) data.offset.top = data.offsetTop - - $spy.affix(data) - }) + $(function () { + $.support.transition = transitionEnd() }) }(window.jQuery); -- cgit v1.2.3