Skip to content

Commit 820a3b2

Browse files
committed
get tests passing for typeahead :P
1 parent 1747caf commit 820a3b2

File tree

5 files changed

+43
-28
lines changed

5 files changed

+43
-28
lines changed

docs/assets/js/bootstrap-typeahead.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
this.sorter = this.options.sorter || this.sorter
3434
this.highlighter = this.options.highlighter || this.highlighter
3535
this.updater = this.options.updater || this.updater
36-
this.$menu = $(this.options.menu).insertAfter(this.$element)
3736
this.source = this.options.source
37+
this.$menu = $(this.options.menu)
3838
this.shown = false
3939
this.listen()
4040
}
@@ -60,12 +60,14 @@
6060
height: this.$element[0].offsetHeight
6161
})
6262

63-
this.$menu.css({
64-
top: pos.top + pos.height
65-
, left: pos.left
66-
})
63+
this.$menu
64+
.insertAfter(this.$element)
65+
.css({
66+
top: pos.top + pos.height
67+
, left: pos.left
68+
})
69+
.show()
6770

68-
this.$menu.show()
6971
this.shown = true
7072
return this
7173
}

docs/assets/js/bootstrap.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,8 +1752,8 @@
17521752
this.sorter = this.options.sorter || this.sorter
17531753
this.highlighter = this.options.highlighter || this.highlighter
17541754
this.updater = this.options.updater || this.updater
1755-
this.$menu = $(this.options.menu).insertAfter(this.$element)
17561755
this.source = this.options.source
1756+
this.$menu = $(this.options.menu)
17571757
this.shown = false
17581758
this.listen()
17591759
}
@@ -1779,12 +1779,14 @@
17791779
height: this.$element[0].offsetHeight
17801780
})
17811781

1782-
this.$menu.css({
1783-
top: pos.top + pos.height
1784-
, left: pos.left
1785-
})
1782+
this.$menu
1783+
.insertAfter(this.$element)
1784+
.css({
1785+
top: pos.top + pos.height
1786+
, left: pos.left
1787+
})
1788+
.show()
17861789

1787-
this.$menu.show()
17881790
this.shown = true
17891791
return this
17901792
}

docs/assets/js/bootstrap.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/bootstrap-typeahead.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
this.sorter = this.options.sorter || this.sorter
3434
this.highlighter = this.options.highlighter || this.highlighter
3535
this.updater = this.options.updater || this.updater
36-
this.$menu = $(this.options.menu).insertAfter(this.$element)
3736
this.source = this.options.source
37+
this.$menu = $(this.options.menu)
3838
this.shown = false
3939
this.listen()
4040
}
@@ -60,12 +60,14 @@
6060
height: this.$element[0].offsetHeight
6161
})
6262

63-
this.$menu.css({
64-
top: pos.top + pos.height
65-
, left: pos.left
66-
})
63+
this.$menu
64+
.insertAfter(this.$element)
65+
.css({
66+
top: pos.top + pos.height
67+
, left: pos.left
68+
})
69+
.show()
6770

68-
this.$menu.show()
6971
this.shown = true
7072
return this
7173
}

js/tests/unit/bootstrap-typeahead.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ $(function () {
3838
})
3939

4040
test("should show menu when query entered", function () {
41-
var $input = $('<input />').typeahead({
41+
var $input = $('<input />')
42+
.appendTo('body')
43+
.typeahead({
4244
source: ['aa', 'ab', 'ac']
4345
})
4446
, typeahead = $input.data('typeahead')
@@ -50,6 +52,7 @@ $(function () {
5052
equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu')
5153
equals(typeahead.$menu.find('.active').length, 1, 'one item is active')
5254

55+
$input.remove()
5356
typeahead.$menu.remove()
5457
})
5558

@@ -58,7 +61,7 @@ $(function () {
5861
source: function () {
5962
return ['aa', 'ab', 'ac']
6063
}
61-
})
64+
}).appendTo('body')
6265
, typeahead = $input.data('typeahead')
6366

6467
$input.val('a')
@@ -68,6 +71,7 @@ $(function () {
6871
equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu')
6972
equals(typeahead.$menu.find('.active').length, 1, 'one item is active')
7073

74+
$input.remove()
7175
typeahead.$menu.remove()
7276
})
7377

@@ -76,7 +80,7 @@ $(function () {
7680
source: function (query, process) {
7781
process(['aa', 'ab', 'ac'])
7882
}
79-
})
83+
}).appendTo('body')
8084
, typeahead = $input.data('typeahead')
8185

8286
$input.val('a')
@@ -86,13 +90,14 @@ $(function () {
8690
equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu')
8791
equals(typeahead.$menu.find('.active').length, 1, 'one item is active')
8892

93+
$input.remove()
8994
typeahead.$menu.remove()
9095
})
9196

9297
test("should not explode when regex chars are entered", function () {
9398
var $input = $('<input />').typeahead({
9499
source: ['aa', 'ab', 'ac', 'mdo*', 'fat+']
95-
})
100+
}).appendTo('body')
96101
, typeahead = $input.data('typeahead')
97102

98103
$input.val('+')
@@ -102,14 +107,15 @@ $(function () {
102107
equals(typeahead.$menu.find('li').length, 1, 'has 1 item in menu')
103108
equals(typeahead.$menu.find('.active').length, 1, 'one item is active')
104109

110+
$input.remove()
105111
typeahead.$menu.remove()
106112
})
107113

108114
test("should hide menu when query entered", function () {
109115
stop()
110116
var $input = $('<input />').typeahead({
111117
source: ['aa', 'ab', 'ac']
112-
})
118+
}).appendTo('body')
113119
, typeahead = $input.data('typeahead')
114120

115121
$input.val('a')
@@ -126,13 +132,14 @@ $(function () {
126132
start()
127133
}, 200)
128134

135+
$input.remove()
129136
typeahead.$menu.remove()
130137
})
131138

132139
test("should set next item when down arrow is pressed", function () {
133140
var $input = $('<input />').typeahead({
134141
source: ['aa', 'ab', 'ac']
135-
})
142+
}).appendTo('body')
136143
, typeahead = $input.data('typeahead')
137144

138145
$input.val('a')
@@ -159,7 +166,6 @@ $(function () {
159166

160167
ok(typeahead.$menu.find('li').first().next().hasClass('active'), "second item is active")
161168

162-
163169
$input.trigger({
164170
type: 'keydown'
165171
, keyCode: 38
@@ -175,14 +181,15 @@ $(function () {
175181

176182
ok(typeahead.$menu.find('li').first().hasClass('active'), "first item is active")
177183

184+
$input.remove()
178185
typeahead.$menu.remove()
179186
})
180187

181188

182189
test("should set input value to selected item", function () {
183190
var $input = $('<input />').typeahead({
184191
source: ['aa', 'ab', 'ac']
185-
})
192+
}).appendTo('body')
186193
, typeahead = $input.data('typeahead')
187194
, changed = false
188195

@@ -197,14 +204,15 @@ $(function () {
197204
ok(!typeahead.$menu.is(':visible'), 'the menu was hidden')
198205
ok(changed, 'a change event was fired')
199206

207+
$input.remove()
200208
typeahead.$menu.remove()
201209
})
202210

203211
test("should start querying when minLength is met", function () {
204212
var $input = $('<input />').typeahead({
205213
source: ['aaaa', 'aaab', 'aaac'],
206214
minLength: 3
207-
})
215+
}).appendTo('body')
208216
, typeahead = $input.data('typeahead')
209217

210218
$input.val('aa')
@@ -217,6 +225,7 @@ $(function () {
217225

218226
equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu')
219227

228+
$input.remove()
220229
typeahead.$menu.remove()
221230
})
222231
})

0 commit comments

Comments
 (0)