Commit 9b21a1ff authored by S Anand's avatar S Anand
Browse files

BUG: urlfilter should allow deleting multiple keys

parent 3b9ec81a
Pipeline #39914 passed with stage
in 1 minute and 22 seconds
......@@ -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()
}
/*
......
......@@ -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&amp;x=2" data-mode="del">del ?x=1&amp;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>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment