diff options
Diffstat (limited to 'js')
| -rw-r--r-- | js/.jscs.json | 26 | ||||
| -rw-r--r-- | js/.jshintrc | 1 | ||||
| -rw-r--r-- | js/affix.js | 39 | ||||
| -rw-r--r-- | js/alert.js | 2 | ||||
| -rw-r--r-- | js/button.js | 32 | ||||
| -rw-r--r-- | js/carousel.js | 16 | ||||
| -rw-r--r-- | js/collapse.js | 4 | ||||
| -rw-r--r-- | js/dropdown.js | 2 | ||||
| -rw-r--r-- | js/modal.js | 10 | ||||
| -rw-r--r-- | js/popover.js | 3 | ||||
| -rw-r--r-- | js/scrollspy.js | 6 | ||||
| -rw-r--r-- | js/tab.js | 2 | ||||
| -rw-r--r-- | js/tests/unit/affix.js | 25 | ||||
| -rw-r--r-- | js/tests/unit/carousel.js | 25 | ||||
| -rw-r--r-- | js/tooltip.js | 39 | ||||
| -rw-r--r-- | js/transition.js | 4 |
16 files changed, 166 insertions, 70 deletions
diff --git a/js/.jscs.json b/js/.jscs.json index e8210ccde..096da217d 100644 --- a/js/.jscs.json +++ b/js/.jscs.json @@ -1,15 +1,15 @@ { - "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"], - "requireSpacesInFunctionExpression": { "beforeOpeningCurlyBrace": true }, - "requireLeftStickedOperators": [","], - "disallowLeftStickedOperators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], - "requireRightStickedOperators": ["!"], - "disallowRightStickedOperators": ["?", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], - "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"], - "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], - "requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], - "requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], - "disallowKeywords": ["with"], - "validateLineBreaks": "LF", - "requireLineFeedAtFileEnd": true + "disallowKeywords": ["with"], + "requireLeftStickedOperators": [","], + "disallowLeftStickedOperators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], + "disallowRightStickedOperators": ["?", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], + "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"], + "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], + "requireLineFeedAtFileEnd": true, + "requireRightStickedOperators": ["!"], + "requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], + "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"], + "requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], + "requireSpacesInFunctionExpression": { "beforeOpeningCurlyBrace": true }, + "validateLineBreaks": "LF" } diff --git a/js/.jshintrc b/js/.jshintrc index c8cccda37..ab4dfdfc9 100644 --- a/js/.jshintrc +++ b/js/.jshintrc @@ -9,7 +9,6 @@ "eqnull" : true, "expr" : true, "laxbreak" : true, - "laxcomma" : true, "quotmark" : "single", "validthis": true }
\ No newline at end of file diff --git a/js/affix.js b/js/affix.js index 34ee091fb..bc11feaa8 100644 --- a/js/affix.js +++ b/js/affix.js @@ -1,5 +1,5 @@ /* ======================================================================== - * Bootstrap: affix.js v3.1.0 + * Bootstrap: affix.js v3.0.3 * http://getbootstrap.com/javascript/#affix * ======================================================================== * Copyright 2013 Twitter, Inc. @@ -18,9 +18,10 @@ .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.$element = $(element) + this.affixed = + this.unpin = + this.pinnedOffset = null this.checkPosition() } @@ -31,6 +32,14 @@ offset: 0 } + Affix.prototype.getPinnedOffset = function () { + if (this.pinnedOffset) return this.pinnedOffset + this.$element.removeClass(Affix.RESET).addClass('affix') + var scrollTop = this.$window.scrollTop() + var position = this.$element.offset() + return (this.pinnedOffset = position.top - scrollTop) + } + Affix.prototype.checkPositionWithEventLoop = function () { setTimeout($.proxy(this.checkPosition, this), 1) } @@ -45,9 +54,11 @@ var offsetTop = offset.top var offsetBottom = offset.bottom + if (this.affixed == 'top') position.top += scrollTop + if (typeof offset != 'object') offsetBottom = offsetTop = offset - if (typeof offsetTop == 'function') offsetTop = offset.top() - if (typeof offsetBottom == 'function') offsetBottom = offset.bottom() + if (typeof offsetTop == 'function') offsetTop = offset.top(this.$element) + if (typeof offsetBottom == 'function') offsetBottom = offset.bottom(this.$element) var affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ? false : offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ? 'bottom' : @@ -56,13 +67,23 @@ if (this.affixed === affix) return if (this.unpin) this.$element.css('top', '') + var affixType = 'affix' + (affix ? '-' + affix : '') + var e = $.Event(affixType + '.bs.affix') + + this.$element.trigger(e) + + if (e.isDefaultPrevented()) return + this.affixed = affix - this.unpin = affix == 'bottom' ? position.top - scrollTop : null + this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null - this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : '')) + this.$element + .removeClass(Affix.RESET) + .addClass(affixType) + .trigger($.Event(affixType.replace('affix', 'affixed'))) if (affix == 'bottom') { - this.$element.offset({ top: document.body.offsetHeight - offsetBottom - this.$element.height() }) + this.$element.offset({ top: scrollHeight - offsetBottom - this.$element.height() }) } } diff --git a/js/alert.js b/js/alert.js index d7bbc5656..e15658492 100644 --- a/js/alert.js +++ b/js/alert.js @@ -1,5 +1,5 @@ /* ======================================================================== - * Bootstrap: alert.js v3.1.0 + * Bootstrap: alert.js v3.0.3 * http://getbootstrap.com/javascript/#alerts * ======================================================================== * Copyright 2013 Twitter, Inc. diff --git a/js/button.js b/js/button.js index 2cf67f6ad..34a61f58a 100644 --- a/js/button.js +++ b/js/button.js @@ -1,5 +1,5 @@ /* ======================================================================== - * Bootstrap: button.js v3.1.0 + * Bootstrap: button.js v3.0.3 * http://getbootstrap.com/javascript/#buttons * ======================================================================== * Copyright 2013 Twitter, Inc. @@ -13,8 +13,9 @@ // ============================== var Button = function (element, options) { - this.$element = $(element) - this.options = $.extend({}, Button.DEFAULTS, options) + this.$element = $(element) + this.options = $.extend({}, Button.DEFAULTS, options) + this.isLoading = false } Button.DEFAULTS = { @@ -34,25 +35,26 @@ $el[val](data[state] || this.options[state]) // push to event loop to allow forms to submit - setTimeout(function () { - state == 'loadingText' ? - $el.addClass(d).attr(d, d) : - $el.removeClass(d).removeAttr(d); - }, 0) + setTimeout($.proxy(function () { + if (state == 'loadingText') { + this.isLoading = true + $el.addClass(d).attr(d, d) + } else if (this.isLoading) { + this.isLoading = false + $el.removeClass(d).removeAttr(d) + } + }, this), 0) } Button.prototype.toggle = function () { - var $parent = this.$element.closest('[data-toggle="buttons"]') var changed = true + var $parent = this.$element.closest('[data-toggle="buttons"]') if ($parent.length) { var $input = this.$element.find('input') - if ($input.prop('type') === 'radio') { - // see if clicking on current one - if ($input.prop('checked') && this.$element.hasClass('active')) - changed = false - else - $parent.find('.active').removeClass('active') + if ($input.prop('type') == 'radio') { + if ($input.prop('checked') && this.$element.hasClass('active')) changed = false + else $parent.find('.active').removeClass('active') } if (changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change') } diff --git a/js/carousel.js b/js/carousel.js index 9ac7c6a2c..fbd055116 100644 --- a/js/carousel.js +++ b/js/carousel.js @@ -1,5 +1,5 @@ /* ======================================================================== - * Bootstrap: carousel.js v3.1.0 + * Bootstrap: carousel.js v3.0.3 * http://getbootstrap.com/javascript/#carousel * ======================================================================== * Copyright 2013 Twitter, Inc. @@ -100,13 +100,15 @@ $next = this.$element.find('.item')[fallback]() } - this.sliding = true - - isCycling && this.pause() + if ($next.hasClass('active')) return var e = $.Event('slide.bs.carousel', { relatedTarget: $next[0], direction: direction }) + this.$element.trigger(e) + if (e.isDefaultPrevented()) return - if ($next.hasClass('active')) return + this.sliding = true + + isCycling && this.pause() if (this.$indicators.length) { this.$indicators.find('.active').removeClass('active') @@ -117,8 +119,6 @@ } if ($.support.transition && this.$element.hasClass('slide')) { - this.$element.trigger(e) - if (e.isDefaultPrevented()) return $next.addClass(type) $next[0].offsetWidth // force reflow $active.addClass(direction) @@ -132,8 +132,6 @@ }) .emulateTransitionEnd($active.css('transition-duration').slice(0, -1) * 1000) } else { - this.$element.trigger(e) - if (e.isDefaultPrevented()) return $active.removeClass('active') $next.addClass('active') this.sliding = false diff --git a/js/collapse.js b/js/collapse.js index e87ecb526..cd8f38439 100644 --- a/js/collapse.js +++ b/js/collapse.js @@ -1,5 +1,5 @@ /* ======================================================================== - * Bootstrap: collapse.js v3.1.0 + * Bootstrap: collapse.js v3.0.3 * http://getbootstrap.com/javascript/#collapse * ======================================================================== * Copyright 2013 Twitter, Inc. @@ -58,7 +58,7 @@ var complete = function () { this.$element .removeClass('collapsing') - .addClass('in') + .addClass('collapse in') [dimension]('auto') this.transitioning = 0 this.$element.trigger('shown.bs.collapse') diff --git a/js/dropdown.js b/js/dropdown.js index 1788b0195..48752fda5 100644 --- a/js/dropdown.js +++ b/js/dropdown.js @@ -1,5 +1,5 @@ /* ======================================================================== - * Bootstrap: dropdown.js v3.1.0 + * Bootstrap: dropdown.js v3.0.3 * http://getbootstrap.com/javascript/#dropdowns * ======================================================================== * Copyright 2013 Twitter, Inc. diff --git a/js/modal.js b/js/modal.js index 794cbad80..5fd53b849 100644 --- a/js/modal.js +++ b/js/modal.js @@ -1,5 +1,5 @@ /* ======================================================================== - * Bootstrap: modal.js v3.1.0 + * Bootstrap: modal.js v3.0.3 * http://getbootstrap.com/javascript/#modals * ======================================================================== * Copyright 2013 Twitter, Inc. @@ -18,7 +18,9 @@ this.$backdrop = this.isShown = null - if (this.options.remote) this.$element.load(this.options.remote) + if (this.options.remote) this.$element.find('.modal-content').load(this.options.remote, $.proxy(function () { + this.$element.trigger('loaded.bs.modal') + }, this)) } Modal.DEFAULTS = { @@ -216,9 +218,9 @@ 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('modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data()) + var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data()) - e.preventDefault() + if ($this.is('a')) e.preventDefault() $target .modal(option, this) diff --git a/js/popover.js b/js/popover.js index adbb17ff5..1e8104c4f 100644 --- a/js/popover.js +++ b/js/popover.js @@ -1,5 +1,5 @@ /* ======================================================================== - * Bootstrap: popover.js v3.1.0 + * Bootstrap: popover.js v3.0.3 * http://getbootstrap.com/javascript/#popovers * ======================================================================== * Copyright 2013 Twitter, Inc. @@ -87,6 +87,7 @@ var data = $this.data('bs.popover') var options = typeof option == 'object' && option + if (!data && option == 'destroy') return if (!data) $this.data('bs.popover', (data = new Popover(this, options))) if (typeof option == 'string') data[option]() }) diff --git a/js/scrollspy.js b/js/scrollspy.js index 3393572b7..571dafbde 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -1,5 +1,5 @@ /* ======================================================================== - * Bootstrap: scrollspy.js v3.1.0 + * Bootstrap: scrollspy.js v3.0.3 * http://getbootstrap.com/javascript/#scrollspy * ======================================================================== * Copyright 2013 Twitter, Inc. @@ -47,7 +47,7 @@ .map(function () { var $el = $(this) var href = $el.data('target') || $el.attr('href') - var $href = /^#\w/.test(href) && $(href) + var $href = /^#./.test(href) && $(href) return ($href && $href.length @@ -85,7 +85,7 @@ this.activeTarget = target $(this.selector) - .parents('.active') + .parentsUntil(this.options.target, '.active') .removeClass('active') var selector = this.selector + @@ -1,5 +1,5 @@ /* ======================================================================== - * Bootstrap: tab.js v3.1.0 + * Bootstrap: tab.js v3.0.3 * http://getbootstrap.com/javascript/#tabs * ======================================================================== * Copyright 2013 Twitter, Inc. diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index 6085a141e..3c8105bce 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -22,4 +22,29 @@ $(function () { ok(!$affix.hasClass('affix'), 'affix class was not added') }) + test('should trigger affixed event after affix', function () { + stop() + + var template = $('<div id="affixTarget"><ul><li>Please affix</li><li>And unaffix</li></ul></div><div id="affixAfter" style="height: 20000px; display:block;"></div>') + template.appendTo('body') + + var affixer = $('#affixTarget').affix({ + offset: $('#affixTarget ul').position() + }) + + $('#affixTarget') + .on('affix.bs.affix', function (e) { + ok(true, 'affix event triggered') + }).on('affixed.bs.affix', function (e) { + ok(true,'affixed event triggered') + $('#affixTarget').remove() + $('#affixAfter').remove() + start() + }) + + setTimeout(function () { + window.scrollTo(0, document.body.scrollHeight) + setTimeout(function () { window.scroll(0,0) }, 0) + },0) + }) }) diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 8d1726b71..5edec68ad 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -16,7 +16,7 @@ $(function () { ok($(document.body).carousel()[0] == document.body, 'document.body returned') }) - test('should not fire sliden when slide is prevented', function () { + test('should not fire slide when slide is prevented', function () { $.support.transition = false stop() $('<div class="carousel"/>') @@ -31,6 +31,29 @@ $(function () { .carousel('next') }) + test('should reset when slide is prevented', function () { + var template = '<div id="carousel-example-generic" class="carousel slide"><ol class="carousel-indicators"><li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li><li data-target="#carousel-example-generic" data-slide-to="1"></li><li data-target="#carousel-example-generic" data-slide-to="2"></li></ol><div class="carousel-inner"><div class="item active"><div class="carousel-caption"></div></div><div class="item"><div class="carousel-caption"></div></div><div class="item"><div class="carousel-caption"></div></div></div><a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"></a><a class="right carousel-control" href="#carousel-example-generic" data-slide="next"></a></div>' + var $carousel = $(template) + $.support.transition = false + stop() + $carousel.one('slide.bs.carousel', function (e) { + e.preventDefault() + setTimeout(function () { + ok($carousel.find('.item:eq(0)').is('.active')) + ok($carousel.find('.carousel-indicators li:eq(0)').is('.active')) + $carousel.carousel('next') + }, 1); + }) + $carousel.one('slid.bs.carousel', function () { + setTimeout(function () { + ok($carousel.find('.item:eq(1)').is('.active')) + ok($carousel.find('.carousel-indicators li:eq(1)').is('.active')) + start() + }, 1); + }) + $carousel.carousel('next') + }) + test('should fire slide event with direction', function () { var template = '<div id="myCarousel" class="carousel slide"><div class="carousel-inner"><div class="item active"><img alt=""><div class="carousel-caption"><h4>{{_i}}First Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div><div class="item"><img alt=""><div class="carousel-caption"><h4>{{_i}}Second Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div><div class="item"><img alt=""><div class="carousel-caption"><h4>{{_i}}Third Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div></div><a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a><a class="right carousel-control" href="#myCarousel" data-slide="next">›</a></div>' $.support.transition = false diff --git a/js/tooltip.js b/js/tooltip.js index 38d06bc52..d491fea0e 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -1,5 +1,5 @@ /* ======================================================================== - * Bootstrap: tooltip.js v3.1.0 + * Bootstrap: tooltip.js v3.0.3 * http://getbootstrap.com/javascript/#tooltip * Inspired by the original jQuery.tipsy by Jason Frame * ======================================================================== @@ -50,8 +50,8 @@ 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' + var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin' + var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout' 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)) @@ -128,6 +128,7 @@ this.$element.trigger(e) if (e.isDefaultPrevented()) return + var that = this; var $tip = this.tip() @@ -177,7 +178,17 @@ var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight) this.applyPlacement(calculatedOffset, placement) - this.$element.trigger('shown.bs.' + this.type) + this.hoverState = null + + var complete = function() { + that.$element.trigger('shown.bs.' + that.type) + } + + $.support.transition && this.$tip.hasClass('fade') ? + $tip + .one($.support.transition.end, complete) + .emulateTransitionEnd(150) : + complete() } } @@ -198,9 +209,18 @@ offset.top = offset.top + marginTop offset.left = offset.left + marginLeft - $tip - .offset(offset) - .addClass('in') + // $.fn.offset doesn't round pixel values + // so we use setOffset directly with our own function B-0 + jQuery.offset.setOffset($tip[0], $.extend({ + using: function (props) { + $tip.css({ + top: Math.round(props.top), + left: Math.round(props.left) + }) + } + }, offset), 0) + + $tip.addClass('in') // check to see if placing tip in new offset caused the tip to resize itself var actualWidth = $tip[0].offsetWidth @@ -251,6 +271,7 @@ function complete() { if (that.hoverState != 'in') $tip.detach() + that.$element.trigger('hidden.bs.' + that.type) } this.$element.trigger(e) @@ -265,7 +286,7 @@ .emulateTransitionEnd(150) : complete() - this.$element.trigger('hidden.bs.' + this.type) + this.hoverState = null return this } @@ -341,6 +362,7 @@ } Tooltip.prototype.destroy = function () { + clearTimeout(this.timeout) this.hide().$element.off('.' + this.type).removeData('bs.' + this.type) } @@ -356,6 +378,7 @@ var data = $this.data('bs.tooltip') var options = typeof option == 'object' && option + if (!data && option == 'destroy') return if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options))) if (typeof option == 'string') data[option]() }) diff --git a/js/transition.js b/js/transition.js index 26c77a860..fac318af9 100644 --- a/js/transition.js +++ b/js/transition.js @@ -1,5 +1,5 @@ /* ======================================================================== - * Bootstrap: transition.js v3.1.0 + * Bootstrap: transition.js v3.0.3 * http://getbootstrap.com/javascript/#transitions * ======================================================================== * Copyright 2013 Twitter, Inc. @@ -27,6 +27,8 @@ return { end: transEndEventNames[name] } } } + + return false // explicit for ie8 ( ._.) } // http://blog.alexmaccaw.com/css-transitions |
