diff options
author | Mark Otto <otto@github.com> | 2012-12-09 05:40:42 +0400 |
---|---|---|
committer | Mark Otto <otto@github.com> | 2012-12-09 05:40:42 +0400 |
commit | bc0b94a3fdc8fe480c74f4494073e2c0addb265e (patch) | |
tree | e13fec2ed829b4586fa4044fffc8dbfadddae54e /js | |
parent | be5f31480b53555c492e0077c8bb9f419fc48f62 (diff) | |
parent | 9376a7c221a64c2bf508d02ea2ccd85748d10fcc (diff) |
Merge branch 'master' into 3.0.0-wip
Conflicts:
docs/assets/css/bootstrap.css
docs/assets/js/bootstrap.js
docs/css.html
docs/templates/pages/base-css.mustache
docs/templates/pages/components.mustache
docs/templates/pages/javascript.mustache
less/breadcrumbs.less
less/tables.less
less/tests/css-tests.html
Diffstat (limited to 'js')
-rw-r--r-- | js/bootstrap-affix.js | 11 | ||||
-rw-r--r-- | js/bootstrap-alert.js | 11 | ||||
-rw-r--r-- | js/bootstrap-button.js | 11 | ||||
-rw-r--r-- | js/bootstrap-carousel.js | 11 | ||||
-rw-r--r-- | js/bootstrap-collapse.js | 17 | ||||
-rw-r--r-- | js/bootstrap-dropdown.js | 16 | ||||
-rw-r--r-- | js/bootstrap-modal.js | 11 | ||||
-rw-r--r-- | js/bootstrap-popover.js | 11 | ||||
-rw-r--r-- | js/bootstrap-scrollspy.js | 13 | ||||
-rw-r--r-- | js/bootstrap-tab.js | 11 | ||||
-rw-r--r-- | js/bootstrap-tooltip.js | 11 | ||||
-rw-r--r-- | js/bootstrap-typeahead.js | 31 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-affix.js | 6 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-alert.js | 6 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-button.js | 6 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-carousel.js | 6 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-collapse.js | 6 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-dropdown.js | 10 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-modal.js | 6 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-popover.js | 12 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-scrollspy.js | 6 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-tab.js | 6 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-tooltip.js | 6 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-typeahead.js | 52 |
24 files changed, 262 insertions, 31 deletions
diff --git a/js/bootstrap-affix.js b/js/bootstrap-affix.js index 0de787e8ca..2b76881c55 100644 --- a/js/bootstrap-affix.js +++ b/js/bootstrap-affix.js @@ -68,6 +68,8 @@ /* AFFIX PLUGIN DEFINITION * ======================= */ + var old = $.fn.affix + $.fn.affix = function (option) { return this.each(function () { var $this = $(this) @@ -85,6 +87,15 @@ } + /* AFFIX NO CONFLICT + * ================= */ + + $.fn.affix.noConflict = function () { + $.fn.affix = old + return this + } + + /* AFFIX DATA-API * ============== */ diff --git a/js/bootstrap-alert.js b/js/bootstrap-alert.js index c957189777..bc45674532 100644 --- a/js/bootstrap-alert.js +++ b/js/bootstrap-alert.js @@ -68,6 +68,8 @@ /* ALERT PLUGIN DEFINITION * ======================= */ + var old = $.fn.alert + $.fn.alert = function (option) { return this.each(function () { var $this = $(this) @@ -80,6 +82,15 @@ $.fn.alert.Constructor = Alert + /* ALERT NO CONFLICT + * ================= */ + + $.fn.alert.noConflict = function () { + $.fn.alert = old + return this + } + + /* ALERT DATA-API * ============== */ diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js index f2e3b77294..6e1aa9c815 100644 --- a/js/bootstrap-button.js +++ b/js/bootstrap-button.js @@ -64,6 +64,8 @@ /* BUTTON PLUGIN DEFINITION * ======================== */ + var old = $.fn.button + $.fn.button = function (option) { return this.each(function () { var $this = $(this) @@ -82,6 +84,15 @@ $.fn.button.Constructor = Button + /* BUTTON NO CONFLICT + * ================== */ + + $.fn.button.noConflict = function () { + $.fn.button = old + return this + } + + /* BUTTON DATA-API * =============== */ diff --git a/js/bootstrap-carousel.js b/js/bootstrap-carousel.js index 875aaca56d..53afac6332 100644 --- a/js/bootstrap-carousel.js +++ b/js/bootstrap-carousel.js @@ -29,7 +29,6 @@ var Carousel = function (element, options) { this.$element = $(element) this.options = options - this.options.slide && this.slide(this.options.slide) this.options.pause == 'hover' && this.$element .on('mouseenter', $.proxy(this.pause, this)) .on('mouseleave', $.proxy(this.cycle, this)) @@ -141,6 +140,8 @@ /* CAROUSEL PLUGIN DEFINITION * ========================== */ + var old = $.fn.carousel + $.fn.carousel = function (option) { return this.each(function () { var $this = $(this) @@ -162,6 +163,14 @@ $.fn.carousel.Constructor = Carousel + /* CAROUSEL NO CONFLICT + * ==================== */ + + $.fn.carousel.noConflict = function () { + $.fn.carousel = old + return this + } + /* CAROUSEL DATA-API * ================= */ diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index d792d850fb..5efdcb1f63 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -120,8 +120,10 @@ } - /* COLLAPSIBLE PLUGIN DEFINITION - * ============================== */ + /* COLLAPSE PLUGIN DEFINITION + * ========================== */ + + var old = $.fn.collapse $.fn.collapse = function (option) { return this.each(function () { @@ -140,9 +142,18 @@ $.fn.collapse.Constructor = Collapse - /* COLLAPSIBLE DATA-API + /* COLLAPSE NO CONFLICT * ==================== */ + $.fn.collapse.noConflict = function () { + $.fn.collapse = old + return this + } + + + /* COLLAPSE DATA-API + * ================= */ + $(document).on('click.collapse.data-api', '[data-toggle=collapse]', function (e) { var $this = $(this), href , target = $this.attr('data-target') diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js index f35b097469..65fc3ea86a 100644 --- a/js/bootstrap-dropdown.js +++ b/js/bootstrap-dropdown.js @@ -53,9 +53,10 @@ if (!isActive) { $parent.toggleClass('open') - $this.focus() } + $this.focus() + return false } @@ -82,7 +83,7 @@ if (!isActive || (isActive && e.keyCode == 27)) return $this.click() - $items = $('[role=menu] li:not(.divider) a', $parent) + $items = $('[role=menu] li:not(.divider):visible a', $parent) if (!$items.length) return @@ -124,6 +125,8 @@ /* DROPDOWN PLUGIN DEFINITION * ========================== */ + var old = $.fn.dropdown + $.fn.dropdown = function (option) { return this.each(function () { var $this = $(this) @@ -136,6 +139,15 @@ $.fn.dropdown.Constructor = Dropdown + /* DROPDOWN NO CONFLICT + * ==================== */ + + $.fn.dropdown.noConflict = function () { + $.fn.dropdown = old + return this + } + + /* APPLY TO STANDARD DROPDOWN ELEMENTS * =================================== */ diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index 9136a7f256..088f814470 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -193,6 +193,8 @@ /* MODAL PLUGIN DEFINITION * ======================= */ + var old = $.fn.modal + $.fn.modal = function (option) { return this.each(function () { var $this = $(this) @@ -213,6 +215,15 @@ $.fn.modal.Constructor = Modal + /* MODAL NO CONFLICT + * ================= */ + + $.fn.modal.noConflict = function () { + $.fn.modal = old + return this + } + + /* MODAL DATA-API * ============== */ diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index 41dcdc010c..dc639a63e2 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -81,6 +81,8 @@ /* POPOVER PLUGIN DEFINITION * ======================= */ + var old = $.fn.popover + $.fn.popover = function (option) { return this.each(function () { var $this = $(this) @@ -100,4 +102,13 @@ , template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"></div></div></div>' }) + + /* POPOVER NO CONFLICT + * =================== */ + + $.fn.popover.noConflict = function () { + $.fn.popover = old + return this + } + }(window.jQuery); diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index c515e31f9c..b61c330067 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -59,7 +59,7 @@ , $href = /^#\w/.test(href) && $(href) return ( $href && $href.length - && [[ $href.position().top, href ]] ) || null + && [[ $href.position().top + self.$scrollElement.scrollTop(), href ]] ) || null }) .sort(function (a, b) { return a[0] - b[0] }) .each(function () { @@ -121,6 +121,8 @@ /* SCROLLSPY PLUGIN DEFINITION * =========================== */ + var old = $.fn.scrollspy + $.fn.scrollspy = function (option) { return this.each(function () { var $this = $(this) @@ -138,6 +140,15 @@ } + /* SCROLLSPY NO CONFLICT + * ===================== */ + + $.fn.scrollspy.noConflict = function () { + $.fn.scrollspy = old + return this + } + + /* SCROLLSPY DATA-API * ================== */ diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js index 49b546ec87..2914cdb170 100644 --- a/js/bootstrap-tab.js +++ b/js/bootstrap-tab.js @@ -110,6 +110,8 @@ /* TAB PLUGIN DEFINITION * ===================== */ + var old = $.fn.tab + $.fn.tab = function ( option ) { return this.each(function () { var $this = $(this) @@ -122,6 +124,15 @@ $.fn.tab.Constructor = Tab + /* TAB NO CONFLICT + * =============== */ + + $.fn.tab.noConflict = function () { + $.fn.tab = old + return this + } + + /* TAB DATA-API * ============ */ diff --git a/js/bootstrap-tooltip.js b/js/bootstrap-tooltip.js index ef6572db76..5a574fcf09 100644 --- a/js/bootstrap-tooltip.js +++ b/js/bootstrap-tooltip.js @@ -250,6 +250,8 @@ /* TOOLTIP PLUGIN DEFINITION * ========================= */ + var old = $.fn.tooltip + $.fn.tooltip = function ( option ) { return this.each(function () { var $this = $(this) @@ -273,4 +275,13 @@ , html: false } + + /* TOOLTIP NO CONFLICT + * =================== */ + + $.fn.tooltip.noConflict = function () { + $.fn.tooltip = old + return this + } + }(window.jQuery);
\ No newline at end of file diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index f1ab231b31..94101db05a 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -33,8 +33,8 @@ 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.$menu = $(this.options.menu) this.shown = false this.listen() } @@ -56,16 +56,18 @@ } , show: function () { - var pos = $.extend({}, this.$element.offset(), { + var pos = $.extend({}, this.$element.position(), { height: this.$element[0].offsetHeight }) - this.$menu.css({ - top: pos.top + pos.height - , left: pos.left - }) + this.$menu + .insertAfter(this.$element) + .css({ + top: pos.top + pos.height + , left: pos.left + }) + .show() - this.$menu.show() this.shown = true return this } @@ -217,7 +219,7 @@ } , keydown: function (e) { - this.suppressKeyPressRepeat = !~$.inArray(e.keyCode, [40,38,9,13,27]) + this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40,38,9,13,27]) this.move(e) } @@ -276,6 +278,8 @@ /* TYPEAHEAD PLUGIN DEFINITION * =========================== */ + var old = $.fn.typeahead + $.fn.typeahead = function (option) { return this.each(function () { var $this = $(this) @@ -297,7 +301,16 @@ $.fn.typeahead.Constructor = Typeahead - /* TYPEAHEAD DATA-API + /* TYPEAHEAD NO CONFLICT + * =================== */ + + $.fn.typeahead.noConflict = function () { + $.fn.typeahead = old + return this + } + + + /* TYPEAHEAD DATA-API * ================== */ $(document).on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) { diff --git a/js/tests/unit/bootstrap-affix.js b/js/tests/unit/bootstrap-affix.js index bc25df9917..c978878903 100644 --- a/js/tests/unit/bootstrap-affix.js +++ b/js/tests/unit/bootstrap-affix.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-affix") + test("should provide no conflict", function () { + var affix = $.fn.affix.noConflict() + ok(!$.fn.affix, 'affix was set back to undefined (org value)') + $.fn.affix = affix + }) + test("should be defined on jquery object", function () { ok($(document.body).affix, 'affix method is defined') }) diff --git a/js/tests/unit/bootstrap-alert.js b/js/tests/unit/bootstrap-alert.js index 7f24e0e6be..9a6b514c47 100644 --- a/js/tests/unit/bootstrap-alert.js +++ b/js/tests/unit/bootstrap-alert.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-alerts") + test("should provide no conflict", function () { + var alert = $.fn.alert.noConflict() + ok(!$.fn.alert, 'alert was set back to undefined (org value)') + $.fn.alert = alert + }) + test("should be defined on jquery object", function () { ok($(document.body).alert, 'alert method is defined') }) diff --git a/js/tests/unit/bootstrap-button.js b/js/tests/unit/bootstrap-button.js index b5d0834999..e23ff9e302 100644 --- a/js/tests/unit/bootstrap-button.js +++ b/js/tests/unit/bootstrap-button.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-buttons") + test("should provide no conflict", function () { + var button = $.fn.button.noConflict() + ok(!$.fn.button, 'button was set back to undefined (org value)') + $.fn.button = button + }) + test("should be defined on jquery object", function () { ok($(document.body).button, 'button method is defined') }) diff --git a/js/tests/unit/bootstrap-carousel.js b/js/tests/unit/bootstrap-carousel.js index 8bd1b62ba0..13b8f721fc 100644 --- a/js/tests/unit/bootstrap-carousel.js +++ b/js/tests/unit/bootstrap-carousel.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-carousel") + test("should provide no conflict", function () { + var carousel = $.fn.carousel.noConflict() + ok(!$.fn.carousel, 'carousel was set back to undefined (org value)') + $.fn.carousel = carousel + }) + test("should be defined on jquery object", function () { ok($(document.body).carousel, 'carousel method is defined') }) diff --git a/js/tests/unit/bootstrap-collapse.js b/js/tests/unit/bootstrap-collapse.js index 6cc7ac7a44..4c5916ecd9 100644 --- a/js/tests/unit/bootstrap-collapse.js +++ b/js/tests/unit/bootstrap-collapse.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-collapse") + test("should provide no conflict", function () { + var collapse = $.fn.collapse.noConflict() + ok(!$.fn.collapse, 'collapse was set back to undefined (org value)') + $.fn.collapse = collapse + }) + test("should be defined on jquery object", function () { ok($(document.body).collapse, 'collapse method is defined') }) diff --git a/js/tests/unit/bootstrap-dropdown.js b/js/tests/unit/bootstrap-dropdown.js index 3788209ecc..2f0d2d29ec 100644 --- a/js/tests/unit/bootstrap-dropdown.js +++ b/js/tests/unit/bootstrap-dropdown.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-dropdowns") + test("should provide no conflict", function () { + var dropdown = $.fn.dropdown.noConflict() + ok(!$.fn.dropdown, 'dropdown was set back to undefined (org value)') + $.fn.dropdown = dropdown + }) + test("should be defined on jquery object", function () { ok($(document.body).dropdown, 'dropdown method is defined') }) @@ -104,7 +110,7 @@ $(function () { }) test("should remove open class if body clicked, with multiple drop downs", function () { - var dropdownHTML = + var dropdownHTML = '<ul class="nav">' + ' <li><a href="#menu1">Menu 1</a></li>' + ' <li class="dropdown" id="testmenu">' @@ -126,7 +132,7 @@ $(function () { , last = dropdowns.last() ok(dropdowns.length == 2, "Should be two dropdowns") - + first.click() ok(first.parents('.open').length == 1, 'open class added on click') ok($('#qunit-fixture .open').length == 1, 'only one object is open') diff --git a/js/tests/unit/bootstrap-modal.js b/js/tests/unit/bootstrap-modal.js index 0851f64a72..98aa990a67 100644 --- a/js/tests/unit/bootstrap-modal.js +++ b/js/tests/unit/bootstrap-modal.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-modal") + test("should provide no conflict", function () { + var modal = $.fn.modal.noConflict() + ok(!$.fn.modal, 'modal was set back to undefined (org value)') + $.fn.modal = modal + }) + test("should be defined on jquery object", function () { var div = $("<div id='modal-test'></div>") ok(div.modal, 'modal method is defined') diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index 6a5f0bdcfe..20234e1476 100644 --- a/js/tests/unit/bootstrap-popover.js +++ b/js/tests/unit/bootstrap-popover.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-popover") + test("should provide no conflict", function () { + var popover = $.fn.popover.noConflict() + ok(!$.fn.popover, 'popover was set back to undefined (org value)') + $.fn.popover = popover + }) + test("should be defined on jquery object", function () { var div = $('<div></div>') ok(div.popover, 'popover method is defined') @@ -70,7 +76,7 @@ $(function () { ok(!$('.popover').length, 'popover was removed') $('#qunit-fixture').empty() }) - + test("should respect custom classes", function() { $.support.transition = false var popover = $('<a href="#">@fat</a>') @@ -80,7 +86,7 @@ $(function () { , content: 'Test' , template: '<div class="popover foobar"><div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div></div>' }) - + popover.popover('show') ok($('.popover').length, 'popover was inserted') @@ -103,5 +109,5 @@ $(function () { ok($._data(popover[0],'events').click[0].namespace == 'foo', 'popover still has click.foo') ok(!$._data(popover[0], 'events').mouseover && !$._data(popover[0], 'events').mouseout, 'popover does not have any events') }) - + })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-scrollspy.js b/js/tests/unit/bootstrap-scrollspy.js index bee46a925e..32bfa71342 100644 --- a/js/tests/unit/bootstrap-scrollspy.js +++ b/js/tests/unit/bootstrap-scrollspy.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-scrollspy") + test("should provide no conflict", function () { + var scrollspy = $.fn.scrollspy.noConflict() + ok(!$.fn.scrollspy, 'scrollspy was set back to undefined (org value)') + $.fn.scrollspy = scrollspy + }) + test("should be defined on jquery object", function () { ok($(document.body).scrollspy, 'scrollspy method is defined') }) diff --git a/js/tests/unit/bootstrap-tab.js b/js/tests/unit/bootstrap-tab.js index 40f9a7406d..ba5910d5e2 100644 --- a/js/tests/unit/bootstrap-tab.js +++ b/js/tests/unit/bootstrap-tab.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-tabs") + test("should provide no conflict", function () { + var tab = $.fn.tab.noConflict() + ok(!$.fn.tab, 'tab was set back to undefined (org value)') + $.fn.tab = tab + }) + test("should be defined on jquery object", function () { ok($(document.body).tab, 'tabs method is defined') }) diff --git a/js/tests/unit/bootstrap-tooltip.js b/js/tests/unit/bootstrap-tooltip.js index bbdf3ce80f..ba51347433 100644 --- a/js/tests/unit/bootstrap-tooltip.js +++ b/js/tests/unit/bootstrap-tooltip.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-tooltip") + test("should provide no conflict", function () { + var tooltip = $.fn.tooltip.noConflict() + ok(!$.fn.tooltip, 'tooltip was set back to undefined (org value)') + $.fn.tooltip = tooltip + }) + test("should be defined on jquery object", function () { var div = $("<div></div>") ok(div.tooltip, 'popover method is defined') diff --git a/js/tests/unit/bootstrap-typeahead.js b/js/tests/unit/bootstrap-typeahead.js index 16bdb91948..4bdbce9709 100644 --- a/js/tests/unit/bootstrap-typeahead.js +++ b/js/tests/unit/bootstrap-typeahead.js @@ -2,6 +2,12 @@ $(function () { module("bootstrap-typeahead") + test("should provide no conflict", function () { + var typeahead = $.fn.typeahead.noConflict() + ok(!$.fn.typeahead, 'typeahead was set back to undefined (org value)') + $.fn.typeahead = typeahead + }) + test("should be defined on jquery object", function () { ok($(document.body).typeahead, 'alert method is defined') }) @@ -32,7 +38,9 @@ $(function () { }) test("should show menu when query entered", function () { - var $input = $('<input />').typeahead({ + var $input = $('<input />') + .appendTo('body') + .typeahead({ source: ['aa', 'ab', 'ac'] }) , typeahead = $input.data('typeahead') @@ -44,6 +52,7 @@ $(function () { equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu') equals(typeahead.$menu.find('.active').length, 1, 'one item is active') + $input.remove() typeahead.$menu.remove() }) @@ -52,7 +61,7 @@ $(function () { source: function () { return ['aa', 'ab', 'ac'] } - }) + }).appendTo('body') , typeahead = $input.data('typeahead') $input.val('a') @@ -62,6 +71,7 @@ $(function () { equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu') equals(typeahead.$menu.find('.active').length, 1, 'one item is active') + $input.remove() typeahead.$menu.remove() }) @@ -70,7 +80,7 @@ $(function () { source: function (query, process) { process(['aa', 'ab', 'ac']) } - }) + }).appendTo('body') , typeahead = $input.data('typeahead') $input.val('a') @@ -80,13 +90,14 @@ $(function () { equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu') equals(typeahead.$menu.find('.active').length, 1, 'one item is active') + $input.remove() typeahead.$menu.remove() }) test("should not explode when regex chars are entered", function () { var $input = $('<input />').typeahead({ source: ['aa', 'ab', 'ac', 'mdo*', 'fat+'] - }) + }).appendTo('body') , typeahead = $input.data('typeahead') $input.val('+') @@ -96,6 +107,7 @@ $(function () { equals(typeahead.$menu.find('li').length, 1, 'has 1 item in menu') equals(typeahead.$menu.find('.active').length, 1, 'one item is active') + $input.remove() typeahead.$menu.remove() }) @@ -103,7 +115,7 @@ $(function () { stop() var $input = $('<input />').typeahead({ source: ['aa', 'ab', 'ac'] - }) + }).appendTo('body') , typeahead = $input.data('typeahead') $input.val('a') @@ -120,13 +132,14 @@ $(function () { start() }, 200) + $input.remove() typeahead.$menu.remove() }) test("should set next item when down arrow is pressed", function () { var $input = $('<input />').typeahead({ source: ['aa', 'ab', 'ac'] - }) + }).appendTo('body') , typeahead = $input.data('typeahead') $input.val('a') @@ -137,21 +150,38 @@ $(function () { equals(typeahead.$menu.find('.active').length, 1, 'one item is active') ok(typeahead.$menu.find('li').first().hasClass('active'), "first item is active") + // simulate entire key pressing event $input.trigger({ type: 'keydown' , keyCode: 40 }) + .trigger({ + type: 'keypress' + , keyCode: 40 + }) + .trigger({ + type: 'keyup' + , keyCode: 40 + }) ok(typeahead.$menu.find('li').first().next().hasClass('active'), "second item is active") - $input.trigger({ type: 'keydown' , keyCode: 38 }) + .trigger({ + type: 'keypress' + , keyCode: 38 + }) + .trigger({ + type: 'keyup' + , keyCode: 38 + }) ok(typeahead.$menu.find('li').first().hasClass('active'), "first item is active") + $input.remove() typeahead.$menu.remove() }) @@ -159,7 +189,7 @@ $(function () { test("should set input value to selected item", function () { var $input = $('<input />').typeahead({ source: ['aa', 'ab', 'ac'] - }) + }).appendTo('body') , typeahead = $input.data('typeahead') , changed = false @@ -174,6 +204,7 @@ $(function () { ok(!typeahead.$menu.is(':visible'), 'the menu was hidden') ok(changed, 'a change event was fired') + $input.remove() typeahead.$menu.remove() }) @@ -181,7 +212,7 @@ $(function () { var $input = $('<input />').typeahead({ source: ['aaaa', 'aaab', 'aaac'], minLength: 3 - }) + }).appendTo('body') , typeahead = $input.data('typeahead') $input.val('aa') @@ -194,6 +225,7 @@ $(function () { equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu') + $input.remove() typeahead.$menu.remove() }) -})
\ No newline at end of file +}) |