Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bootstrap
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
bootstrap
Commits
6e490628
Commit
6e490628
authored
Jan 21, 2012
by
Jacob Thornton
Browse files
Options
Browse Files
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
with
30 additions
and
20 deletions
+30
-20
js/bootstrap-typeahead.js
js/bootstrap-typeahead.js
+30
-20
No files found.
js/bootstrap-typeahead.js
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
))
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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