Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
4618141b
Commit
4618141b
authored
Sep 03, 2014
by
Randall Leeds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Isolate the search directive
parent
a7a5aaec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
21 deletions
+27
-21
simple-search.coffee
h/static/scripts/directives/simple-search.coffee
+16
-12
simple-search-test.coffee
tests/js/directives/simple-search-test.coffee
+11
-9
No files found.
h/static/scripts/directives/simple-search.coffee
View file @
4618141b
simpleSearch
=
[
'$parse'
,
(
$parse
)
->
uuid
=
0
link
:
(
scope
,
elem
,
attr
,
ctrl
)
->
_search
=
$parse
(
attr
.
onsearch
)
_clear
=
$parse
(
attr
.
onclear
)
scope
.
viewId
=
uuid
++
scope
.
dosearch
=
->
_search
(
scope
,
{
"this"
:
scope
.
searchtext
})
scope
.
reset
=
(
event
)
->
event
.
preventDefault
()
scope
.
searchtext
=
''
_clear
(
scope
)
if
attr
.
onclear
scope
.
query
=
''
scope
.
onClear
?
()
scope
.
search
=
(
event
)
->
event
.
preventDefault
()
scope
.
query
=
scope
.
searchtext
scope
.
$watch
attr
.
query
,
(
query
)
->
if
query
?
scope
.
searchtext
=
query
_search
(
scope
,
{
"this"
:
scope
.
searchtext
})
scope
.
$watch
'query'
,
(
query
,
old
)
->
return
if
query
is
old
scope
.
searchtext
=
query
if
query
scope
.
onSearch
?
(
query
:
scope
.
searchtext
)
restrict
:
'C'
scope
:
query
:
'='
onSearch
:
'&'
onClear
:
'&'
template
:
'''
<form class="simple-search-form" ng-class="!searchtext && 'simple-search-inactive'" name="searchBox" ng-submit="
dosearch(
)">
<form class="simple-search-form" ng-class="!searchtext && 'simple-search-inactive'" name="searchBox" ng-submit="
search($event
)">
<input id="simple-search-{{viewId}}" class="simple-search-input" type="text" ng-model="searchtext" name="searchText" placeholder="Search…" />
<label for="simple-search-{{viewId}}" class="simple-search-icon icon-search"></label>
<button class="simple-search-clear" type="reset" ng-hide="!searchtext" ng-click="reset($event)">
...
...
tests/js/directives/simple-search-test.coffee
View file @
4618141b
...
...
@@ -4,6 +4,7 @@ describe 'h.directives', ->
$scope
=
null
$compile
=
null
fakeWindow
=
null
isolate
=
null
beforeEach
module
(
'h.directives'
)
...
...
@@ -20,23 +21,24 @@ describe 'h.directives', ->
template
=
'''
<div class="simpleSearch"
query="query"
on
search="update(this
)"
onclear="clear()">
on
-search="update(query
)"
on
-
clear="clear()">
</div>
'''
$element
=
$compile
(
angular
.
element
(
template
))(
$scope
)
$scope
.
$digest
()
isolate
=
$element
.
isolateScope
()
it
'updates the search-bar'
,
->
$scope
.
query
=
"Test query"
$scope
.
$digest
()
assert
.
equal
(
$scop
e
.
searchtext
,
$scope
.
query
)
assert
.
equal
(
isolat
e
.
searchtext
,
$scope
.
query
)
it
'calls the given search function'
,
->
$scope
.
query
=
"Test query"
$scop
e
.
$digest
()
$element
.
triggerHandler
(
'submit'
)
isolate
.
searchtext
=
"Test query"
isolat
e
.
$digest
()
$element
.
find
(
'form'
).
triggerHandler
(
'submit'
)
sinon
.
assert
.
calledWith
(
$scope
.
update
,
"Test query"
)
it
'calls the given clear function'
,
->
...
...
@@ -44,10 +46,10 @@ describe 'h.directives', ->
assert
(
$scope
.
clear
.
called
)
it
'clears the search-bar'
,
->
$scope
.
query
=
"Test query"
$scop
e
.
$digest
()
isolate
.
searchtext
=
"Test query"
isolat
e
.
$digest
()
$element
.
find
(
'.simple-search-clear'
).
click
()
assert
.
equal
(
$scop
e
.
searchtext
,
''
)
assert
.
equal
(
isolat
e
.
searchtext
,
''
)
it
'adds a class to the form when there is no input value'
,
->
$form
=
$element
.
find
(
'.simple-search-form'
)
...
...
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