Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bootstrap
bootstrap
Commits
6e490628
Commit
6e490628
authored
13 years ago
by
Jacob Thornton
Browse files
Options
Download
Email Patches
Plain Diff
more efficient matcher + bold matched query in item
parent
4fe11342
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
js/bootstrap-typeahead.js
+30
-20
js/bootstrap-typeahead.js
with
30 additions
and
20 deletions
+30
-20
js/bootstrap-typeahead.js
+
30
-
20
View file @
6e490628
...
@@ -36,7 +36,7 @@
...
@@ -36,7 +36,7 @@
,
matcher
:
function
(
item
,
query
)
{
,
matcher
:
function
(
item
,
query
)
{
// ;_; http://jsperf.com/asdfdfasdfa
// ;_; http://jsperf.com/asdfdfasdfa
return
~
item
.
toLowerCase
().
indexOf
(
query
.
toLowerCase
()
)
return
~
item
.
toLowerCase
().
indexOf
(
query
)
}
}
,
select
:
function
()
{
,
select
:
function
()
{
...
@@ -67,16 +67,20 @@
...
@@ -67,16 +67,20 @@
}
}
,
lookup
:
function
(
event
)
{
,
lookup
:
function
(
event
)
{
var
query
=
this
.
$element
.
val
()
var
that
=
this
,
that
=
this
,
items
,
items
,
q
this
.
query
=
this
.
$element
.
val
()
if
(
!
query
)
{
if
(
!
this
.
query
)
{
return
this
.
shown
?
this
.
hide
()
:
this
return
this
.
shown
?
this
.
hide
()
:
this
}
}
q
=
this
.
query
.
toLowerCase
()
items
=
this
.
data
.
filter
(
function
(
item
)
{
items
=
this
.
data
.
filter
(
function
(
item
)
{
if
(
that
.
matcher
(
item
,
q
uery
))
return
item
if
(
that
.
matcher
(
item
,
q
))
return
item
})
})
if
(
!
items
.
length
)
{
if
(
!
items
.
length
)
{
...
@@ -88,10 +92,15 @@
...
@@ -88,10 +92,15 @@
,
render
:
function
(
items
)
{
,
render
:
function
(
items
)
{
var
that
=
this
var
that
=
this
,
QUERY
=
new
RegExp
(
'
(
'
+
this
.
query
+
'
)
'
,
'
ig
'
)
items
=
$
(
items
).
map
(
function
(
i
,
item
)
{
items
=
$
(
items
).
map
(
function
(
i
,
item
)
{
i
=
$
(
that
.
options
.
item
).
attr
(
'
data-value
'
,
item
)
i
=
$
(
that
.
options
.
item
).
attr
(
'
data-value
'
,
item
)
i
.
find
(
'
a
'
).
text
(
item
)
i
.
find
(
'
a
'
).
html
(
item
.
replace
(
QUERY
,
function
(
$1
,
match
)
{
return
'
<strong>
'
+
match
+
'
</strong>
'
}))
return
i
[
0
]
return
i
[
0
]
})
})
...
@@ -122,6 +131,21 @@
...
@@ -122,6 +131,21 @@
prev
.
addClass
(
'
active
'
)
prev
.
addClass
(
'
active
'
)
}
}
,
listen
:
function
()
{
this
.
$element
.
on
(
'
blur
'
,
$
.
proxy
(
this
.
blur
,
this
))
.
on
(
'
keypress
'
,
$
.
proxy
(
this
.
keypress
,
this
))
.
on
(
'
keyup
'
,
$
.
proxy
(
this
.
keyup
,
this
))
if
(
$
.
browser
.
webkit
||
$
.
browser
.
msie
)
{
this
.
$element
.
on
(
'
keydown
'
,
$
.
proxy
(
this
.
keypress
,
this
))
}
this
.
$menu
.
on
(
'
click
'
,
$
.
proxy
(
this
.
click
,
this
))
.
on
(
'
mouseenter
'
,
'
li
'
,
$
.
proxy
(
this
.
mouseenter
,
this
))
}
,
keyup
:
function
(
e
)
{
,
keyup
:
function
(
e
)
{
e
.
stopPropagation
()
e
.
stopPropagation
()
e
.
preventDefault
()
e
.
preventDefault
()
...
@@ -188,20 +212,6 @@
...
@@ -188,20 +212,6 @@
$
(
e
.
currentTarget
).
addClass
(
'
active
'
)
$
(
e
.
currentTarget
).
addClass
(
'
active
'
)
}
}
,
listen
:
function
()
{
this
.
$element
.
on
(
'
blur
'
,
$
.
proxy
(
this
.
blur
,
this
))
.
on
(
'
keypress
'
,
$
.
proxy
(
this
.
keypress
,
this
))
.
on
(
'
keyup
'
,
$
.
proxy
(
this
.
keyup
,
this
))
if
(
$
.
browser
.
webkit
||
$
.
browser
.
msie
)
{
this
.
$element
.
on
(
'
keydown
'
,
$
.
proxy
(
this
.
keypress
,
this
))
}
this
.
$menu
.
on
(
'
click
'
,
$
.
proxy
(
this
.
click
,
this
))
.
on
(
'
mouseenter
'
,
'
li
'
,
$
.
proxy
(
this
.
mouseenter
,
this
))
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment