diff options
| author | Jacob Thornton <[email protected]> | 2012-04-24 02:21:45 -0700 |
|---|---|---|
| committer | Jacob Thornton <[email protected]> | 2012-04-24 02:21:45 -0700 |
| commit | e659dc7e1be2e09cec34703dce8c737496e3504e (patch) | |
| tree | be3caed12a3de1218e1fd548f2564302e6c8193a /js | |
| parent | 6506ede6323ee60d4d7f8171937d92141a64e09e (diff) | |
| parent | 839ef3a030b355d0f0c35d6c9e42ecba8b072036 (diff) | |
| download | bootstrap-e659dc7e1be2e09cec34703dce8c737496e3504e.tar.xz bootstrap-e659dc7e1be2e09cec34703dce8c737496e3504e.zip | |
Merge branch '2.0.3-wip'
Conflicts:
Makefile
docs/assets/js/bootstrap.js
docs/assets/js/bootstrap.min.js
Diffstat (limited to 'js')
27 files changed, 686 insertions, 242 deletions
diff --git a/js/.jshintrc b/js/.jshintrc new file mode 100644 index 000000000..bbac349e8 --- /dev/null +++ b/js/.jshintrc @@ -0,0 +1,10 @@ +{ + "validthis": true, + "laxcomma" : true, + "laxbreak" : true, + "browser" : true, + "debug" : true, + "boss" : true, + "expr" : true, + "asi" : true +}
\ No newline at end of file diff --git a/js/README.md b/js/README.md index 1c3ced31f..c7b71e70f 100644 --- a/js/README.md +++ b/js/README.md @@ -5,7 +5,7 @@ These are the high-level design rules which guide the development of Bootstrap's ### DATA-ATTRIBUTE API -We believe you should be able to use all plugins provided by Bootstrap purely through the markup API without writing a single line of javascript. +We believe you should be able to use all plugins provided by Bootstrap purely through the markup API without writing a single line of javascript. This is bootstraps first class api. We acknowledge that this isn't always the most performant and sometimes it may be desirable to turn this functionality off altogether. Therefore, as of 2.0 we provide the ability to disable the data attribute API by unbinding all events on the body namespaced with `'data-api'`. This looks like this: @@ -29,7 +29,7 @@ All methods should accept an optional options object, a string which targets a p $("#myModal").modal() // initialized with defaults $("#myModal").modal({ keyboard: false }) // initialized with no keyboard - $("#myModal").modal('show') // initializes and invokes show immediately afterqwe2 + $("#myModal").modal('show') // initializes and invokes show immediately --- @@ -60,6 +60,12 @@ All events should have an infinitive and past participle form. The infinitive is show | shown hide | hidden +All infinitive events should provide preventDefault functionality. This provides the abililty to stop the execution of an action. + + $('#myModal').on('show', function (e) { + if (!data) return e.preventDefault() // stops modal from being shown + }) + --- ### CONSTRUCTORS diff --git a/js/bootstrap-alert.js b/js/bootstrap-alert.js index d17f44e15..fa0806ea1 100644 --- a/js/bootstrap-alert.js +++ b/js/bootstrap-alert.js @@ -1,5 +1,5 @@ /* ========================================================== - * bootstrap-alert.js v2.0.2 + * bootstrap-alert.js v2.0.3 * http://twitter.github.com/bootstrap/javascript.html#alerts * ========================================================== * Copyright 2012 Twitter, Inc. @@ -18,61 +18,57 @@ * ========================================================== */ -!function( $ ){ +!function ($) { + + "use strict"; // jshint ;_; - "use strict" /* ALERT CLASS DEFINITION * ====================== */ var dismiss = '[data-dismiss="alert"]' - , Alert = function ( el ) { + , Alert = function (el) { $(el).on('click', dismiss, this.close) } - Alert.prototype = { - - constructor: Alert + Alert.prototype.close = function (e) { + var $this = $(this) + , selector = $this.attr('data-target') + , $parent - , close: function ( e ) { - var $this = $(this) - , selector = $this.attr('data-target') - , $parent + if (!selector) { + selector = $this.attr('href') + selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 + } - if (!selector) { - selector = $this.attr('href') - selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 - } + $parent = $(selector) - $parent = $(selector) - $parent.trigger('close') + e && e.preventDefault() - e && e.preventDefault() + $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent()) - $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent()) + $parent.trigger(e = $.Event('close')) - $parent - .trigger('close') - .removeClass('in') + if (e.isDefaultPrevented()) return - function removeElement() { - $parent - .trigger('closed') - .remove() - } + $parent.removeClass('in') - $.support.transition && $parent.hasClass('fade') ? - $parent.on($.support.transition.end, removeElement) : - removeElement() + function removeElement() { + $parent + .trigger('closed') + .remove() } + $.support.transition && $parent.hasClass('fade') ? + $parent.on($.support.transition.end, removeElement) : + removeElement() } /* ALERT PLUGIN DEFINITION * ======================= */ - $.fn.alert = function ( option ) { + $.fn.alert = function (option) { return this.each(function () { var $this = $(this) , data = $this.data('alert') @@ -91,4 +87,4 @@ $('body').on('click.alert.data-api', dismiss, Alert.prototype.close) }) -}( window.jQuery );
\ No newline at end of file +}(window.jQuery);
\ No newline at end of file diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js index 6b36753d8..a9e6ba7b1 100644 --- a/js/bootstrap-button.js +++ b/js/bootstrap-button.js @@ -1,5 +1,5 @@ /* ============================================================ - * bootstrap-button.js v2.0.2 + * bootstrap-button.js v2.0.3 * http://twitter.github.com/bootstrap/javascript.html#buttons * ============================================================ * Copyright 2012 Twitter, Inc. @@ -17,58 +17,54 @@ * limitations under the License. * ============================================================ */ -!function( $ ){ - "use strict" +!function ($) { + + "use strict"; // jshint ;_; + /* BUTTON PUBLIC CLASS DEFINITION * ============================== */ - var Button = function ( element, options ) { + var Button = function (element, options) { this.$element = $(element) this.options = $.extend({}, $.fn.button.defaults, options) } - Button.prototype = { - - constructor: Button + Button.prototype.setState = function (state) { + var d = 'disabled' + , $el = this.$element + , data = $el.data() + , val = $el.is('input') ? 'val' : 'html' - , setState: function ( state ) { - var d = 'disabled' - , $el = this.$element - , data = $el.data() - , val = $el.is('input') ? 'val' : 'html' + state = state + 'Text' + data.resetText || $el.data('resetText', $el[val]()) - state = state + 'Text' - data.resetText || $el.data('resetText', $el[val]()) + $el[val](data[state] || this.options[state]) - $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) - } - - , toggle: function () { - var $parent = this.$element.parent('[data-toggle="buttons-radio"]') + // 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) + } - $parent && $parent - .find('.active') - .removeClass('active') + Button.prototype.toggle = function () { + var $parent = this.$element.parent('[data-toggle="buttons-radio"]') - this.$element.toggleClass('active') - } + $parent && $parent + .find('.active') + .removeClass('active') + this.$element.toggleClass('active') } /* BUTTON PLUGIN DEFINITION * ======================== */ - $.fn.button = function ( option ) { + $.fn.button = function (option) { return this.each(function () { var $this = $(this) , data = $this.data('button') @@ -97,4 +93,4 @@ }) }) -}( window.jQuery );
\ No newline at end of file +}(window.jQuery);
\ No newline at end of file diff --git a/js/bootstrap-carousel.js b/js/bootstrap-carousel.js index 8c0723d28..96e5a8191 100644 --- a/js/bootstrap-carousel.js +++ b/js/bootstrap-carousel.js @@ -1,5 +1,5 @@ /* ========================================================== - * bootstrap-carousel.js v2.0.2 + * bootstrap-carousel.js v2.0.3 * http://twitter.github.com/bootstrap/javascript.html#carousel * ========================================================== * Copyright 2012 Twitter, Inc. @@ -18,16 +18,17 @@ * ========================================================== */ -!function( $ ){ +!function ($) { + + "use strict"; // jshint ;_; - "use strict" /* CAROUSEL CLASS DEFINITION * ========================= */ var Carousel = function (element, options) { this.$element = $(element) - this.options = $.extend({}, $.fn.carousel.defaults, options) + this.options = options this.options.slide && this.slide(this.options.slide) this.options.pause == 'hover' && this.$element .on('mouseenter', $.proxy(this.pause, this)) @@ -36,8 +37,11 @@ Carousel.prototype = { - cycle: function () { - this.interval = setInterval($.proxy(this.next, this), this.options.interval) + cycle: function (e) { + if (!e) this.paused = false + this.options.interval + && !this.paused + && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) return this } @@ -62,7 +66,8 @@ return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos])) } - , pause: function () { + , pause: function (e) { + if (!e) this.paused = true clearInterval(this.interval) this.interval = null return this @@ -85,6 +90,7 @@ , direction = type == 'next' ? 'left' : 'right' , fallback = type == 'next' ? 'first' : 'last' , that = this + , e = $.Event('slide') this.sliding = true @@ -94,24 +100,26 @@ if ($next.hasClass('active')) return - if (!$.support.transition && this.$element.hasClass('slide')) { - this.$element.trigger('slide') - $active.removeClass('active') - $next.addClass('active') - this.sliding = false - this.$element.trigger('slid') - } else { + 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) $next.addClass(direction) - this.$element.trigger('slide') this.$element.one($.support.transition.end, function () { $next.removeClass([type, direction].join(' ')).addClass('active') $active.removeClass(['active', direction].join(' ')) that.sliding = false setTimeout(function () { that.$element.trigger('slid') }, 0) }) + } else { + this.$element.trigger(e) + if (e.isDefaultPrevented()) return + $active.removeClass('active') + $next.addClass('active') + this.sliding = false + this.$element.trigger('slid') } isCycling && this.cycle() @@ -125,15 +133,15 @@ /* CAROUSEL PLUGIN DEFINITION * ========================== */ - $.fn.carousel = function ( option ) { + $.fn.carousel = function (option) { return this.each(function () { var $this = $(this) , data = $this.data('carousel') - , options = typeof option == 'object' && option + , options = $.extend({}, $.fn.carousel.defaults, typeof option == 'object' && option) if (!data) $this.data('carousel', (data = new Carousel(this, options))) if (typeof option == 'number') data.to(option) else if (typeof option == 'string' || (option = options.slide)) data[option]() - else data.cycle() + else if (options.interval) data.cycle() }) } @@ -158,4 +166,4 @@ }) }) -}( window.jQuery );
\ No newline at end of file +}(window.jQuery);
\ No newline at end of file diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index 9a364468b..4cd412c73 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -1,5 +1,5 @@ /* ============================================================= - * bootstrap-collapse.js v2.0.2 + * bootstrap-collapse.js v2.0.3 * http://twitter.github.com/bootstrap/javascript.html#collapse * ============================================================= * Copyright 2012 Twitter, Inc. @@ -17,16 +17,21 @@ * limitations under the License. * ============================================================ */ -!function( $ ){ - "use strict" +!function ($) { - var Collapse = function ( element, options ) { - this.$element = $(element) + "use strict"; // jshint ;_; + + + /* COLLAPSE PUBLIC CLASS DEFINITION + * ================================ */ + + var Collapse = function (element, options) { + this.$element = $(element) this.options = $.extend({}, $.fn.collapse.defaults, options) - if (this.options["parent"]) { - this.$parent = $(this.options["parent"]) + if (this.options.parent) { + this.$parent = $(this.options.parent) } this.options.toggle && this.toggle() @@ -42,31 +47,39 @@ } , show: function () { - var dimension = this.dimension() - , scroll = $.camelCase(['scroll', dimension].join('-')) - , actives = this.$parent && this.$parent.find('.in') + var dimension + , scroll + , actives , hasData + if (this.transitioning) return + + dimension = this.dimension() + scroll = $.camelCase(['scroll', dimension].join('-')) + actives = this.$parent && this.$parent.find('> .accordion-group > .in') + if (actives && actives.length) { hasData = actives.data('collapse') + if (hasData && hasData.transitioning) return actives.collapse('hide') hasData || actives.data('collapse', null) } this.$element[dimension](0) - this.transition('addClass', 'show', 'shown') + this.transition('addClass', $.Event('show'), 'shown') this.$element[dimension](this.$element[0][scroll]) - } , hide: function () { - var dimension = this.dimension() + var dimension + if (this.transitioning) return + dimension = this.dimension() this.reset(this.$element[dimension]()) - this.transition('removeClass', 'hide', 'hidden') + this.transition('removeClass', $.Event('hide'), 'hidden') this.$element[dimension](0) } - , reset: function ( size ) { + , reset: function (size) { var dimension = this.dimension() this.$element @@ -74,37 +87,43 @@ [dimension](size || 'auto') [0].offsetWidth - this.$element[size ? 'addClass' : 'removeClass']('collapse') + this.$element[size !== null ? 'addClass' : 'removeClass']('collapse') return this } - , transition: function ( method, startEvent, completeEvent ) { + , transition: function (method, startEvent, completeEvent) { var that = this , complete = function () { if (startEvent == 'show') that.reset() + that.transitioning = 0 that.$element.trigger(completeEvent) } - this.$element - .trigger(startEvent) - [method]('in') + this.$element.trigger(startEvent) + + if (startEvent.isDefaultPrevented()) return + + this.transitioning = 1 + + this.$element[method]('in') $.support.transition && this.$element.hasClass('collapse') ? this.$element.one($.support.transition.end, complete) : complete() - } + } , toggle: function () { this[this.$element.hasClass('in') ? 'hide' : 'show']() - } + } } - /* COLLAPSIBLE PLUGIN DEFINITION + + /* COLLAPSIBLE PLUGIN DEFINITION * ============================== */ - $.fn.collapse = function ( option ) { + $.fn.collapse = function (option) { return this.each(function () { var $this = $(this) , data = $this.data('collapse') @@ -135,4 +154,4 @@ }) }) -}( window.jQuery );
\ No newline at end of file +}(window.jQuery);
\ No newline at end of file diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js index 54b61c5e9..ec0588dc1 100644 --- a/js/bootstrap-dropdown.js +++ b/js/bootstrap-dropdown.js @@ -1,5 +1,5 @@ /* ============================================================ - * bootstrap-dropdown.js v2.0.2 + * bootstrap-dropdown.js v2.0.3 * http://twitter.github.com/bootstrap/javascript.html#dropdowns * ============================================================ * Copyright 2012 Twitter, Inc. @@ -18,15 +18,16 @@ * ============================================================ */ -!function( $ ){ +!function ($) { + + "use strict"; // jshint ;_; - "use strict" /* DROPDOWN CLASS DEFINITION * ========================= */ var toggle = '[data-toggle="dropdown"]' - , Dropdown = function ( element ) { + , Dropdown = function (element) { var $el = $(element).on('click.dropdown.data-api', this.toggle) $('html').on('click.dropdown.data-api', function () { $el.parent().removeClass('open') @@ -37,12 +38,16 @@ constructor: Dropdown - , toggle: function ( e ) { + , toggle: function (e) { var $this = $(this) - , selector = $this.attr('data-target') , $parent + , selector , isActive + if ($this.is('.disabled, :disabled')) return + + selector = $this.attr('data-target') + if (!selector) { selector = $this.attr('href') selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 @@ -54,7 +59,8 @@ isActive = $parent.hasClass('open') clearMenus() - !isActive && $parent.toggleClass('open') + + if (!isActive) $parent.toggleClass('open') return false } @@ -69,7 +75,7 @@ /* DROPDOWN PLUGIN DEFINITION * ========================== */ - $.fn.dropdown = function ( option ) { + $.fn.dropdown = function (option) { return this.each(function () { var $this = $(this) , data = $this.data('dropdown') @@ -86,7 +92,9 @@ $(function () { $('html').on('click.dropdown.data-api', clearMenus) - $('body').on('click.dropdown.data-api', toggle, Dropdown.prototype.toggle) + $('body') + .on('click.dropdown', '.dropdown form', function (e) { e.stopPropagation() }) + .on('click.dropdown.data-api', toggle, Dropdown.prototype.toggle) }) -}( window.jQuery );
\ No newline at end of file +}(window.jQuery);
\ No newline at end of file diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index e92970627..c831de6b6 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -1,5 +1,5 @@ /* ========================================================= - * bootstrap-modal.js v2.0.2 + * bootstrap-modal.js v2.0.3 * http://twitter.github.com/bootstrap/javascript.html#modals * ========================================================= * Copyright 2012 Twitter, Inc. @@ -18,14 +18,15 @@ * ========================================================= */ -!function( $ ){ +!function ($) { + + "use strict"; // jshint ;_; - "use strict" /* MODAL CLASS DEFINITION * ====================== */ - var Modal = function ( content, options ) { + var Modal = function (content, options) { this.options = options this.$element = $(content) .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this)) @@ -41,19 +42,23 @@ , show: function () { var that = this + , e = $.Event('show') + + this.$element.trigger(e) - if (this.isShown) return + if (this.isShown || e.isDefaultPrevented()) return $('body').addClass('modal-open') this.isShown = true - this.$element.trigger('show') escape.call(this) backdrop.call(this, function () { var transition = $.support.transition && that.$element.hasClass('fade') - !that.$element.parent().length && that.$element.appendTo(document.body) //don't move modals dom position + if (!that.$element.parent().length) { + that.$element.appendTo(document.body) //don't move modals dom position + } that.$element .show() @@ -71,21 +76,24 @@ }) } - , hide: function ( e ) { + , hide: function (e) { e && e.preventDefault() - if (!this.isShown) return - var that = this + + e = $.Event('hide') + + this.$element.trigger(e) + + if (!this.isShown || e.isDefaultPrevented()) return + this.isShown = false $('body').removeClass('modal-open') escape.call(this) - this.$element - .trigger('hide') - .removeClass('in') + this.$element.removeClass('in') $.support.transition && this.$element.hasClass('fade') ? hideWithTransition.call(this) : @@ -111,7 +119,7 @@ }) } - function hideModal( that ) { + function hideModal(that) { this.$element .hide() .trigger('hidden') @@ -119,7 +127,7 @@ backdrop.call(this) } - function backdrop( callback ) { + function backdrop(callback) { var that = this , animate = this.$element.hasClass('fade') ? 'fade' : '' @@ -173,7 +181,7 @@ /* MODAL PLUGIN DEFINITION * ======================= */ - $.fn.modal = function ( option ) { + $.fn.modal = function (option) { return this.each(function () { var $this = $(this) , data = $this.data('modal') @@ -207,4 +215,4 @@ }) }) -}( window.jQuery );
\ No newline at end of file +}(window.jQuery);
\ No newline at end of file diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index e1aa5ac39..d5ecfa920 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -1,5 +1,5 @@ /* =========================================================== - * bootstrap-popover.js v2.0.2 + * bootstrap-popover.js v2.0.3 * http://twitter.github.com/bootstrap/javascript.html#popovers * =========================================================== * Copyright 2012 Twitter, Inc. @@ -18,14 +18,19 @@ * =========================================================== */ -!function( $ ) { +!function ($) { - "use strict" + "use strict"; // jshint ;_; + + + /* POPOVER PUBLIC CLASS DEFINITION + * =============================== */ var Popover = function ( element, options ) { this.init('popover', element, options) } + /* NOTE: POPOVER EXTENDS BOOTSTRAP-TOOLTIP.js ========================================== */ @@ -38,8 +43,8 @@ , title = this.getTitle() , content = this.getContent() - $tip.find('.popover-title')[ $.type(title) == 'object' ? 'append' : 'html' ](title) - $tip.find('.popover-content > *')[ $.type(content) == 'object' ? 'append' : 'html' ](content) + $tip.find('.popover-title')[this.isHTML(title) ? 'html' : 'text'](title) + $tip.find('.popover-content > *')[this.isHTML(content) ? 'html' : 'text'](content) $tip.removeClass('fade top bottom left right in') } @@ -56,12 +61,10 @@ content = $e.attr('data-content') || (typeof o.content == 'function' ? o.content.call($e[0]) : o.content) - content = content.toString().replace(/(^\s*|\s*$)/, "") - return content } - , tip: function() { + , tip: function () { if (!this.$tip) { this.$tip = $(this.options.template) } @@ -74,7 +77,7 @@ /* POPOVER PLUGIN DEFINITION * ======================= */ - $.fn.popover = function ( option ) { + $.fn.popover = function (option) { return this.each(function () { var $this = $(this) , data = $this.data('popover') @@ -92,4 +95,4 @@ , template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>' }) -}( window.jQuery );
\ No newline at end of file +}(window.jQuery);
\ No newline at end of file diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index ea29f2f86..f6a24b003 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -1,5 +1,5 @@ /* ============================================================= - * bootstrap-scrollspy.js v2.0.2 + * bootstrap-scrollspy.js v2.0.3 * http://twitter.github.com/bootstrap/javascript.html#scrollspy * ============================================================= * Copyright 2012 Twitter, Inc. @@ -17,9 +17,11 @@ * limitations under the License. * ============================================================== */ -!function ( $ ) { - "use strict" +!function ($) { + + "use strict"; // jshint ;_; + /* SCROLLSPY CLASS DEFINITION * ========================== */ @@ -43,25 +45,43 @@ constructor: ScrollSpy , refresh: function () { - this.targets = this.$body + var self = this + , $targets + + this.offsets = $([]) + this.targets = $([]) + + $targets = this.$body .find(this.selector) .map(function () { - var href = $(this).attr('href') - return /^#\w/.test(href) && $(href).length ? href : null + var $el = $(this) + , href = $el.data('target') || $el.attr('href') + , $href = /^#\w/.test(href) && $(href) + return ( $href + && href.length + && [[ $href.position().top, href ]] ) || null + }) + .sort(function (a, b) { return a[0] - b[0] }) + .each(function () { + self.offsets.push(this[0]) + self.targets.push(this[1]) }) - - this.offsets = $.map(this.targets, function (id) { - return $(id).position().top - }) } , process: function () { var scrollTop = this.$scrollElement.scrollTop() + this.options.offset + , scrollHeight = this.$scrollElement[0].scrollHeight || this.$body[0].scrollHeight + , maxScroll = scrollHeight - this.$scrollElement.height() , offsets = this.offsets , targets = this.targets , activeTarget = this.activeTarget , i + if (scrollTop >= maxScroll) { + return activeTarget != (i = targets.last()[0]) + && this.activate ( i ) + } + for (i = offsets.length; i--;) { activeTarget != targets[i] && scrollTop >= offsets[i] @@ -72,21 +92,27 @@ , activate: function (target) { var active + , selector this.activeTarget = target - this.$body - .find(this.selector).parent('.active') + $(this.selector) + .parent('.active') .removeClass('active') - active = this.$body - .find(this.selector + '[href="' + target + '"]') + selector = this.selector + + '[data-target="' + target + '"],' + + this.selector + '[href="' + target + '"]' + + active = $(selector) .parent('li') .addClass('active') - if ( active.parent('.dropdown-menu') ) { - active.closest('li.dropdown').addClass('active') + if (active.parent('.dropdown-menu')) { + active = active.closest('li.dropdown').addClass('active') } + + active.trigger('activate') } } @@ -122,4 +148,4 @@ }) }) -}( window.jQuery );
\ No newline at end of file +}(window.jQuery);
\ No newline at end of file diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js index b3938f671..88641de86 100644 --- a/js/bootstrap-tab.js +++ b/js/bootstrap-tab.js @@ -1,5 +1,5 @@ /* ======================================================== - * bootstrap-tab.js v2.0.2 + * bootstrap-tab.js v2.0.3 * http://twitter.github.com/bootstrap/javascript.html#tabs * ======================================================== * Copyright 2012 Twitter, Inc. @@ -18,9 +18,10 @@ * ======================================================== */ -!function( $ ){ +!function ($) { + + "use strict"; // jshint ;_; - "use strict" /* TAB CLASS DEFINITION * ==================== */ @@ -39,6 +40,7 @@ , selector = $this.attr('data-target') , previous , $target + , e if (!selector) { selector = $this.attr('href') @@ -49,11 +51,14 @@ previous = $ul.find('.active a').last()[0] - $this.trigger({ - type: 'show' - , relatedTarget: previous + e = $.Event('show', { + relatedTarget: previous }) + $this.trigger(e) + + if (e.isDefaultPrevented()) return + $target = $(selector) this.activate($this.parent('li'), $ul) @@ -127,4 +132,4 @@ }) }) -}( window.jQuery );
\ No newline at end of file +}(window.jQuery);
\ No newline at end of file diff --git a/js/bootstrap-tooltip.js b/js/bootstrap-tooltip.js index 49b5f7286..577ead48b 100644 --- a/js/bootstrap-tooltip.js +++ b/js/bootstrap-tooltip.js @@ -1,5 +1,5 @@ /* =========================================================== - * bootstrap-tooltip.js v2.0.2 + * bootstrap-tooltip.js v2.0.3 * http://twitter.github.com/bootstrap/javascript.html#tooltips * Inspired by the original jQuery.tipsy by Jason Frame * =========================================================== @@ -18,14 +18,16 @@ * limitations under the License. * ========================================================== */ -!function( $ ) { - "use strict" +!function ($) { + + "use strict"; // jshint ;_; + /* TOOLTIP PUBLIC CLASS DEFINITION * =============================== */ - var Tooltip = function ( element, options ) { + var Tooltip = function (element, options) { this.init('tooltip', element, options) } @@ -33,7 +35,7 @@ constructor: Tooltip - , init: function ( type, element, options ) { + , init: function (type, element, options) { var eventIn , eventOut @@ -54,7 +56,7 @@ this.fixTitle() } - , getOptions: function ( options ) { + , getOptions: function (options) { options = $.extend({}, $.fn[this.type].defaults, options, this.$element.data()) if (options.delay && typeof options.delay == 'number') { @@ -67,34 +69,28 @@ return options } - , enter: function ( e ) { + , enter: function (e) { var self = $(e.currentTarget)[this.type](this._options).data(this.type) - if (!self.options.delay || !self.options.delay.show) { - self.show() - } else { - self.hoverState = 'in' - setTimeout(function() { - if (self.hoverState == 'in') { - self.show() - } - }, self.options.delay.show) - } + if (!self.options.delay || !self.options.delay.show) return self.show() + + clearTimeout(this.timeout) + self.hoverState = 'in' + this.timeout = setTimeout(function() { + if (self.hoverState == 'in') self.show() + }, self.options.delay.show) } - , leave: function ( e ) { + , leave: function (e) { var self = $(e.currentTarget)[this.type](this._options).data(this.type) - if (!self.options.delay || !self.options.delay.hide) { - self.hide() - } else { - self.hoverState = 'out' - setTimeout(function() { - if (self.hoverState == 'out') { - self.hide() - } - }, self.options.delay.hide) - } + if (!self.options.delay || !self.options.delay.hide) return self.hide() + + clearTimeout(this.timeout) + self.hoverState = 'out' + this.timeout = setTimeout(function() { + if (self.hoverState == 'out') self.hide() + }, self.options.delay.hide) } , show: function () { @@ -152,9 +148,20 @@ } } + , isHTML: function(text) { + // html string detection logic adapted from jQuery + return typeof text != 'string' + || ( text.charAt(0) === "<" + && text.charAt( text.length - 1 ) === ">" + && text.length >= 3 + ) || /^(?:[^<]*<[\w\W]+>[^>]*$)/.exec(text) + } + , setContent: function () { var $tip = this.tip() - $tip.find('.tooltip-inner').html(this.getTitle()) + , title = this.getTitle() + + $tip.find('.tooltip-inner')[this.isHTML(title) ? 'html' : 'text'](title) $tip.removeClass('fade in top bottom left right') } @@ -206,8 +213,6 @@ title = $e.attr('data-original-title') || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title) - title = (title || '').toString().replace(/(^\s*|\s*$)/, "") - return title } @@ -259,12 +264,12 @@ $.fn.tooltip.defaults = { animation: true - , delay: 0 - , selector: false , placement: 'top' + , selector: false + , template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' , trigger: 'hover' , title: '' - , template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' + , delay: 0 } -}( window.jQuery );
\ No newline at end of file +}(window.jQuery);
\ No newline at end of file diff --git a/js/bootstrap-transition.js b/js/bootstrap-transition.js index f5226f96d..7e29b2fd0 100644 --- a/js/bootstrap-transition.js +++ b/js/bootstrap-transition.js @@ -1,5 +1,5 @@ /* =================================================== - * bootstrap-transition.js v2.0.2 + * bootstrap-transition.js v2.0.3 * http://twitter.github.com/bootstrap/javascript.html#transitions * =================================================== * Copyright 2012 Twitter, Inc. @@ -17,35 +17,45 @@ * limitations under the License. * ========================================================== */ -!function( $ ) { + +!function ($) { $(function () { - "use strict" + "use strict"; // jshint ;_; + - /* CSS TRANSITION SUPPORT (https://gist.github.com/373874) + /* CSS TRANSITION SUPPORT (http://www.modernizr.com/) * ======================================================= */ $.support.transition = (function () { - var thisBody = document.body || document.documentElement - , thisStyle = thisBody.style - , support = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined - - return support && { - end: (function () { - var transitionEnd = "TransitionEnd" - if ( $.browser.webkit ) { - transitionEnd = "webkitTransitionEnd" - } else if ( $.browser.mozilla ) { - transitionEnd = "transitionend" - } else if ( $.browser.opera ) { - transitionEnd = "oTransitionEnd" + + var transitionEnd = (function () { + + var el = document.createElement('bootstrap') + , transEndEventNames = { + 'WebkitTransition' : 'webkitTransitionEnd' + , 'MozTransition' : 'transitionend' + , 'OTransition' : 'oTransitionEnd' + , 'msTransition' : 'MSTransitionEnd' + , 'transition' : 'transitionend' + } + , name + + for (name in transEndEventNames){ + if (el.style[name] !== undefined) { + return transEndEventNames[name] } - return transitionEnd - }()) + } + + }()) + + return transitionEnd && { + end: transitionEnd } + })() }) -}( window.jQuery );
\ No newline at end of file +}(window.jQuery);
\ No newline at end of file diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index dc2f88221..ada0526f9 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -1,5 +1,5 @@ /* ============================================================= - * bootstrap-typeahead.js v2.0.2 + * bootstrap-typeahead.js v2.0.3 * http://twitter.github.com/bootstrap/javascript.html#typeahead * ============================================================= * Copyright 2012 Twitter, Inc. @@ -17,16 +17,22 @@ * limitations under the License. * ============================================================ */ -!function( $ ){ - "use strict" +!function($){ - var Typeahead = function ( element, options ) { + "use strict"; // jshint ;_; + + + /* TYPEAHEAD PUBLIC CLASS DEFINITION + * ================================= */ + + var Typeahead = function (element, options) { this.$element = $(element) this.options = $.extend({}, $.fn.typeahead.defaults, options) this.matcher = this.options.matcher || this.matcher this.sorter = this.options.sorter || this.sorter this.highlighter = this.options.highlighter || this.highlighter + this.updater = this.options.updater || this.updater this.$menu = $(this.options.menu).appendTo('body') this.source = this.options.source this.shown = false @@ -39,13 +45,18 @@ , select: function () { var val = this.$menu.find('.active').attr('data-value') - this.$element.val(val) - this.$element.change(); + this.$element + .val(this.updater(val)) + .change() return this.hide() } + , updater: function (item) { + return item + } + , show: function () { - var pos = $.extend({}, this.$element.offset(), { + var pos = $.extend({}, this.$element.position(), { height: this.$element[0].offsetHeight }) @@ -77,7 +88,7 @@ } items = $.grep(this.source, function (item) { - if (that.matcher(item)) return item + return that.matcher(item) }) items = this.sorter(items) @@ -109,7 +120,8 @@ } , highlighter: function (item) { - return item.replace(new RegExp('(' + this.query + ')', 'ig'), function ($1, match) { + var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&') + return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) { return '<strong>' + match + '</strong>' }) } @@ -201,11 +213,13 @@ break case 38: // up arrow + if (e.type != 'keydown') break e.preventDefault() this.prev() break case 40: // down arrow + if (e.type != 'keydown') break e.preventDefault() this.next() break @@ -236,7 +250,7 @@ /* TYPEAHEAD PLUGIN DEFINITION * =========================== */ - $.fn.typeahead = function ( option ) { + $.fn.typeahead = function (option) { return this.each(function () { var $this = $(this) , data = $this.data('typeahead') @@ -268,4 +282,4 @@ }) }) -}( window.jQuery );
\ No newline at end of file +}(window.jQuery);
\ No newline at end of file diff --git a/js/tests/index.html b/js/tests/index.html index 8c710de36..2f8f71b12 100644 --- a/js/tests/index.html +++ b/js/tests/index.html @@ -11,10 +11,14 @@ <link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen" /> <script src="vendor/qunit.js"></script> + <!-- phantomjs logging script--> + <script src="unit/bootstrap-phantom.js"></script> + <!-- plugin sources --> <script src="../../js/bootstrap-transition.js"></script> <script src="../../js/bootstrap-alert.js"></script> <script src="../../js/bootstrap-button.js"></script> + <script src="../../js/bootstrap-carousel.js"></script> <script src="../../js/bootstrap-collapse.js"></script> <script src="../../js/bootstrap-dropdown.js"></script> <script src="../../js/bootstrap-modal.js"></script> @@ -28,6 +32,7 @@ <script src="unit/bootstrap-transition.js"></script> <script src="unit/bootstrap-alert.js"></script> <script src="unit/bootstrap-button.js"></script> + <script src="unit/bootstrap-carousel.js"></script> <script src="unit/bootstrap-collapse.js"></script> <script src="unit/bootstrap-dropdown.js"></script> <script src="unit/bootstrap-modal.js"></script> @@ -36,7 +41,7 @@ <script src="unit/bootstrap-tooltip.js"></script> <script src="unit/bootstrap-popover.js"></script> <script src="unit/bootstrap-typeahead.js"></script> - +</head> <body> <div> <h1 id="qunit-header">Bootstrap Plugin Test Suite</h1> diff --git a/js/tests/phantom.js b/js/tests/phantom.js new file mode 100644 index 000000000..4105bf529 --- /dev/null +++ b/js/tests/phantom.js @@ -0,0 +1,63 @@ +// Simple phantom.js integration script +// Adapted from Modernizr + +function waitFor(testFx, onReady, timeOutMillis) { + var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 5001 //< Default Max Timout is 5s + , start = new Date().getTime() + , condition = false + , interval = setInterval(function () { + if ((new Date().getTime() - start < maxtimeOutMillis) && !condition) { + // If not time-out yet and condition not yet fulfilled + condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()) //< defensive code + } else { + if (!condition) { + // If condition still not fulfilled (timeout but condition is 'false') + console.log("'waitFor()' timeout") + phantom.exit(1) + } else { + // Condition fulfilled (timeout and/or condition is 'true') + typeof(onReady) === "string" ? eval(onReady) : onReady() //< Do what it's supposed to do once the condition is fulfilled + clearInterval(interval) //< Stop this interval + } + } + }, 100) //< repeat check every 100ms +} + + +if (phantom.args.length === 0 || phantom.args.length > 2) { + console.log('Usage: phantom.js URL') + phantom.exit() +} + +var page = new WebPage() + +// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this") +page.onConsoleMessage = function(msg) { + console.log(msg) +}; + +page.open(phantom.args[0], function(status){ + if (status !== "success") { + console.log("Unable to access network") + phantom.exit() + } else { + waitFor(function(){ + return page.evaluate(function(){ + var el = document.getElementById('qunit-testresult') + if (el && el.innerText.match('completed')) { + return true + } + return false + }) + }, function(){ + var failedNum = page.evaluate(function(){ + var el = document.getElementById('qunit-testresult') + try { + return el.getElementsByClassName('failed')[0].innerHTML + } catch (e) { } + return 10000 + }); + phantom.exit((parseInt(failedNum, 10) > 0) ? 1 : 0) + }) + } +})
\ No newline at end of file diff --git a/js/tests/server.js b/js/tests/server.js new file mode 100644 index 000000000..7c8445feb --- /dev/null +++ b/js/tests/server.js @@ -0,0 +1,14 @@ +/* + * Simple connect server for phantom.js + * Adapted from Modernizr + */ + +var connect = require('connect') + , http = require('http') + , fs = require('fs') + , app = connect() + .use(connect.static(__dirname + '/../../')); + +http.createServer(app).listen(3000); + +fs.writeFileSync(__dirname + '/pid.txt', process.pid, 'utf-8')
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-alert.js b/js/tests/unit/bootstrap-alert.js index e607f4340..7f24e0e6b 100644 --- a/js/tests/unit/bootstrap-alert.js +++ b/js/tests/unit/bootstrap-alert.js @@ -38,4 +38,19 @@ $(function () { ok(!$('#qunit-fixture').find('.alert-message').length, 'element removed from dom') }) + test("should not fire closed when close is prevented", function () { + $.support.transition = false + stop(); + $('<div class="alert"/>') + .bind('close', function (e) { + e.preventDefault(); + ok(true); + start(); + }) + .bind('closed', function () { + ok(false); + }) + .alert('close') + }) + })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-carousel.js b/js/tests/unit/bootstrap-carousel.js new file mode 100644 index 000000000..92c23e227 --- /dev/null +++ b/js/tests/unit/bootstrap-carousel.js @@ -0,0 +1,28 @@ +$(function () { + + module("bootstrap-carousel") + + test("should be defined on jquery object", function () { + ok($(document.body).carousel, 'carousel method is defined') + }) + + test("should return element", function () { + ok($(document.body).carousel()[0] == document.body, 'document.body returned') + }) + + test("should not fire sliden when slide is prevented", function () { + $.support.transition = false + stop(); + $('<div class="carousel"/>') + .bind('slide', function (e) { + e.preventDefault(); + ok(true); + start(); + }) + .bind('slid', function () { + ok(false); + }) + .carousel('next') + }) + +})
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-collapse.js b/js/tests/unit/bootstrap-collapse.js index 698238d96..8e52898b5 100644 --- a/js/tests/unit/bootstrap-collapse.js +++ b/js/tests/unit/bootstrap-collapse.js @@ -22,4 +22,19 @@ $(function () { ok(/height/.test(el.attr('style')), 'has height set') }) + test("should not fire shown when show is prevented", function () { + $.support.transition = false + stop(); + $('<div class="collapse"/>') + .bind('show', function (e) { + e.preventDefault(); + ok(true); + start(); + }) + .bind('shown', function () { + ok(false); + }) + .collapse('show') + }) + })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-dropdown.js b/js/tests/unit/bootstrap-dropdown.js index 368ced2a5..4e52c8485 100644 --- a/js/tests/unit/bootstrap-dropdown.js +++ b/js/tests/unit/bootstrap-dropdown.js @@ -10,6 +10,40 @@ $(function () { ok($(document.body).dropdown()[0] == document.body, 'document.body returned') }) + test("should not open dropdown if target is disabled", function () { + var dropdownHTML = '<ul class="tabs">' + + '<li class="dropdown">' + + '<button disabled href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>' + + '<ul class="dropdown-menu">' + + '<li><a href="#">Secondary link</a></li>' + + '<li><a href="#">Something else here</a></li>' + + '<li class="divider"></li>' + + '<li><a href="#">Another link</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + , dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click() + + ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') + }) + + test("should not open dropdown if target is disabled", function () { + var dropdownHTML = '<ul class="tabs">' + + '<li class="dropdown">' + + '<button href="#" class="btn dropdown-toggle disabled" data-toggle="dropdown">Dropdown</button>' + + '<ul class="dropdown-menu">' + + '<li><a href="#">Secondary link</a></li>' + + '<li><a href="#">Something else here</a></li>' + + '<li class="divider"></li>' + + '<li><a href="#">Another link</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + , dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click() + + ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') + }) + test("should add class open to menu if clicked", function () { var dropdownHTML = '<ul class="tabs">' + '<li class="dropdown">' diff --git a/js/tests/unit/bootstrap-modal.js b/js/tests/unit/bootstrap-modal.js index 22f5781ea..0851f64a7 100644 --- a/js/tests/unit/bootstrap-modal.js +++ b/js/tests/unit/bootstrap-modal.js @@ -29,6 +29,35 @@ $(function () { .modal("show") }) + test("should fire show event", function () { + stop() + $.support.transition = false + $("<div id='modal-test'></div>") + .bind("show", function () { + ok(true, "show was called") + }) + .bind("shown", function () { + $(this).remove() + start() + }) + .modal("show") + }) + + test("should not fire shown when default prevented", function () { + stop() + $.support.transition = false + $("<div id='modal-test'></div>") + .bind("show", function (e) { + e.preventDefault() + ok(true, "show was called") + start() + }) + .bind("shown", function () { + ok(false, "shown was called") + }) + .modal("show") + }) + test("should hide modal when hide is called", function () { stop() $.support.transition = false diff --git a/js/tests/unit/bootstrap-phantom.js b/js/tests/unit/bootstrap-phantom.js new file mode 100644 index 000000000..a04aeaa87 --- /dev/null +++ b/js/tests/unit/bootstrap-phantom.js @@ -0,0 +1,21 @@ +// Logging setup for phantom integration +// adapted from Modernizr + +QUnit.begin = function () { + console.log("Starting test suite") + console.log("================================================\n") +} + +QUnit.moduleDone = function (opts) { + if (opts.failed === 0) { + console.log("\u2714 All tests passed in '" + opts.name + "' module") + } else { + console.log("\u2716 " + opts.failed + " tests failed in '" + opts.name + "' module") + } +} + +QUnit.done = function (opts) { + console.log("\n================================================") + console.log("Tests completed in " + opts.runtime + " milliseconds") + console.log(opts.passed + " tests of " + opts.total + " passed, " + opts.failed + " failed.") +}
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-tab.js b/js/tests/unit/bootstrap-tab.js index 18f490fa5..987804781 100644 --- a/js/tests/unit/bootstrap-tab.js +++ b/js/tests/unit/bootstrap-tab.js @@ -42,4 +42,20 @@ $(function () { equals($("#qunit-fixture").find('.active').attr('id'), "home") }) + + test("should not fire closed when close is prevented", function () { + $.support.transition = false + stop(); + $('<div class="tab"/>') + .bind('show', function (e) { + e.preventDefault(); + ok(true); + start(); + }) + .bind('shown', function () { + ok(false); + }) + .tab('show') + }) + })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-tooltip.js b/js/tests/unit/bootstrap-tooltip.js index 8543162c6..63f4f0b07 100644 --- a/js/tests/unit/bootstrap-tooltip.js +++ b/js/tests/unit/bootstrap-tooltip.js @@ -59,4 +59,78 @@ $(function () { ok(!$(".tooltip").length, 'tooltip removed') }) + test("should not show tooltip if leave event occurs before delay expires", function () { + var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>') + .appendTo('#qunit-fixture') + .tooltip({ delay: 200 }) + + stop() + + tooltip.trigger('mouseenter') + + setTimeout(function () { + ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in') + tooltip.trigger('mouseout') + setTimeout(function () { + ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in') + start() + }, 200) + }, 100) + }) + + test("should not show tooltip if leave event occurs before delay expires", function () { + var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>') + .appendTo('#qunit-fixture') + .tooltip({ delay: 100 }) + stop() + tooltip.trigger('mouseenter') + setTimeout(function () { + ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in') + tooltip.trigger('mouseout') + setTimeout(function () { + ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in') + start() + }, 100) + }, 50) + }) + + test("should show tooltip if leave event hasn't occured before delay expires", function () { + var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>') + .appendTo('#qunit-fixture') + .tooltip({ delay: 200 }) + stop() + tooltip.trigger('mouseenter') + setTimeout(function () { + ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in') + setTimeout(function () { + ok(!$(".tooltip").hasClass('fade in'), 'tooltip has faded in') + start() + }, 200) + }, 100) + }) + + test("should detect if title string is html or text: foo", function () { + ok(!$.fn.tooltip.Constructor.prototype.isHTML('foo'), 'correctly detected html') + }) + + test("should detect if title string is html or text: &lt;foo&gt;", function () { + ok(!$.fn.tooltip.Constructor.prototype.isHTML('<foo>'), 'correctly detected html') + }) + + test("should detect if title string is html or text: <div>foo</div>", function () { + ok($.fn.tooltip.Constructor.prototype.isHTML('<div>foo</div>'), 'correctly detected html') + }) + + test("should detect if title string is html or text: asdfa<div>foo</div>asdfasdf", function () { + ok($.fn.tooltip.Constructor.prototype.isHTML('asdfa<div>foo</div>asdfasdf'), 'correctly detected html') + }) + + test("should detect if title string is html or text: document.createElement('div')", function () { + ok($.fn.tooltip.Constructor.prototype.isHTML(document.createElement('div')), 'correctly detected html') + }) + + test("should detect if title string is html or text: $('<div />)", function () { + ok($.fn.tooltip.Constructor.prototype.isHTML($('<div></div>')), 'correctly detected html') + }) + })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-transition.js b/js/tests/unit/bootstrap-transition.js index 3f28d2676..086773fa2 100644 --- a/js/tests/unit/bootstrap-transition.js +++ b/js/tests/unit/bootstrap-transition.js @@ -3,7 +3,7 @@ $(function () { module("bootstrap-transition") test("should be defined on jquery support object", function () { - ok($.support.transition != undefined, 'transition object is defined') + ok($.support.transition !== undefined, 'transition object is defined') }) test("should provide an end object", function () { diff --git a/js/tests/unit/bootstrap-typeahead.js b/js/tests/unit/bootstrap-typeahead.js index 96ea7c45f..4e2428d6a 100644 --- a/js/tests/unit/bootstrap-typeahead.js +++ b/js/tests/unit/bootstrap-typeahead.js @@ -52,6 +52,22 @@ $(function () { typeahead.$menu.remove() }) + test("should not explode when regex chars are entered", function () { + var $input = $('<input />').typeahead({ + source: ['aa', 'ab', 'ac', 'mdo*', 'fat+'] + }) + , typeahead = $input.data('typeahead') + + $input.val('+') + typeahead.lookup() + + ok(typeahead.$menu.is(":visible"), 'typeahead is visible') + equals(typeahead.$menu.find('li').length, 1, 'has 1 item in menu') + equals(typeahead.$menu.find('.active').length, 1, 'one item is active') + + typeahead.$menu.remove() + }) + test("should hide menu when query entered", function () { stop() var $input = $('<input />').typeahead({ @@ -91,7 +107,7 @@ $(function () { ok(typeahead.$menu.find('li').first().hasClass('active'), "first item is active") $input.trigger({ - type: 'keypress' + type: 'keydown' , keyCode: 40 }) @@ -99,7 +115,7 @@ $(function () { $input.trigger({ - type: 'keypress' + type: 'keydown' , keyCode: 38 }) |
