Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cto
g1
Commits
9b21a1ff
Commit
9b21a1ff
authored
Jan 17, 2018
by
S Anand
Browse files
BUG: urlfilter should allow deleting multiple keys
parent
3b9ec81a
Pipeline
#39914
passed with stage
in 1 minute and 22 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/jquery.urlfilter.js
View file @
9b21a1ff
...
...
@@ -33,18 +33,20 @@ export function urlfilter(options) {
remove
=
hasdata
(
$this
,
'
remove
'
,
default_remove
),
href
=
$this
.
attr
(
attr
),
url
=
parse
(
href
),
q
=
url
.
searchKey
if
(
remove
)
for
(
var
key
in
q
)
if
(
q
[
key
]
===
''
)
q
[
key
]
=
null
q
=
url
.
searchList
function
target_url
(
url
)
{
return
parse
(
url
)
var
result
=
parse
(
url
)
.
join
(
href
,
{
query
:
false
,
hash
:
false
})
.
update
(
q
,
mode
)
.
toString
()
if
(
remove
)
{
var
missing_keys
=
{}
for
(
var
key
in
result
.
searchKey
)
if
(
result
.
searchKey
[
key
]
===
''
)
missing_keys
[
key
]
=
null
result
.
update
(
missing_keys
)
}
return
result
.
toString
()
}
/*
...
...
test/test-urlfilter.html
View file @
9b21a1ff
...
...
@@ -28,14 +28,14 @@
var loc = proxylog({href: '', hash: ''}, events)
var hist = {pushState: function(obj, name, href) { loc.href = href }}
// Check if clicking
"
selector
"
sets location.href / location.hash
"
attr
"
.
// The search key in location should initially be
"
init
"
and should become
"
search
"
// The search key in location should initially be
"
init
"
and should become
"
result
"
// A
"
urlfilter
"
event is triggered on the
"
selector
"
function check(t, selector, attr, init,
search
) {
t.test('clicking ' + selector + ' sets location.' + attr + ' from ' + init + ' to ' +
search
, function(st) {
function check(t, selector, attr, init,
result
) {
t.test('clicking ' + selector + ' sets location.' + attr + ' from ' + init + ' to ' +
result
, function(st) {
st.plan(3)
loc[attr] = init
events.once(attr + '.set', function (val) {
st.equal(g1.url.parse(val).search,
search
, 'check.' + attr + '.set')
st.equal(g1.url.parse(val).search,
result
, 'check.' + attr + '.set')
})
$(selector)
.one('urlfilter', function(e) {
...
...
@@ -96,7 +96,8 @@
<a
class=
"urlfilter def x2"
href=
"?x=2"
data-mode=
""
>
set ?x=2
</a>
<a
class=
"urlfilter add x2"
href=
"?x=2"
data-mode=
"add"
>
add ?x=2
</a>
<a
class=
"urlfilter tog x2"
href=
"?x=2"
data-mode=
"toggle"
>
toggle ?x=2
</a>
<a
class=
"urlfilter del x2"
href=
"?x=2"
data-mode=
"del"
>
toggle ?x=2
</a>
<a
class=
"urlfilter del x2"
href=
"?x=2"
data-mode=
"del"
>
del ?x=2
</a>
<a
class=
"urlfilter del x12"
href=
"?x=1&x=2"
data-mode=
"del"
>
del ?x=1
&
x=2
</a>
<script>
tape
(
'
setting data-mode as a child attribute works
'
,
function
(
t
)
{
check
(
t
,
'
.def.x1
'
,
'
href
'
,
''
,
'
x=1
'
)
...
...
@@ -118,6 +119,10 @@
check
(
t
,
'
.add.x2
'
,
'
href
'
,
'
?x=1
'
,
'
x=1&x=2
'
)
check
(
t
,
'
.tog.x2
'
,
'
href
'
,
'
?x=1
'
,
'
x=1&x=2
'
)
check
(
t
,
'
.del.x2
'
,
'
href
'
,
'
?x=1
'
,
'
x=1
'
)
check
(
t
,
'
.del.x1
'
,
'
href
'
,
'
?x=1&x=2&y=3
'
,
'
x=2&y=3
'
)
check
(
t
,
'
.del.x12
'
,
'
href
'
,
'
?x=1&x=2
'
,
''
)
check
(
t
,
'
.del.x12
'
,
'
href
'
,
'
?x=1&x=2&x=3&y=4
'
,
'
x=3&y=4
'
)
})
</script>
...
...
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