Commit 30c3e9e7 authored by S Anand's avatar S Anand

DOC: urlchange clearing, multi-listening. Fixes #119 @karmanya.aggarwal

parent 6e93b42f
Pipeline #77012 passed with stage
in 2 minutes and 13 seconds
......@@ -52,6 +52,10 @@ Examples:
- When the URL changes from `#a` to `#b`, it triggers 2 events on `window`:
- `.on('#', function(e) { e.hash.pathname == 'b' }`
- `.on('#/', function(e, val) { val == 'b' && e.old == 'a' }`
- Combinations of keys can be listened to simultaneously
- `.on('#?x #?y', function(e){})` will only be triggered if both x and y change
- When the hashkey is reset, `location.hash=''`
- `.on('#', function(e){})` as the location.hash is now `{}`
## $.urlchange events
......
......@@ -89,6 +89,27 @@
window.location.hash = '#?x=1&y=2'
})
tape('clearing x should still trigger an event', function(t) {
reset('#?x=1')
t.plan(2) // One less than no. of tests. #?x.test should not be fired
$(window).one('#?x', function (e, val) {
t.deepEqual(e.hash.searchList, {})
t.deepEqual(e.old.searchList, {'x': ['1']})
})
window.location.hash = ''
})
tape('Adding #?abc=1&xyz=2 triggers on both abc and xyz events', function(t) {
reset('#?abc=1&xyz=1')
t.plan(3) // One less than no. of tests. #?x.test should not be fired
$(window).one('#?abc #?xyz', function (e, val) {
t.equal(val, '2')
t.deepEqual(e.hash.searchList, { 'abc': ['1'], 'xyz': ['2'] })
t.deepEqual(e.old.searchList, { 'abc': ['1'], 'xyz': ['1'] })
})
window.location.hash = '#?abc=1&xyz=2'
})
tape('#a?x=1&y=2&z=3 -> #b?x=1&x=2&y=3', function(t) {
reset('#a?x=1&y=2&z=3')
t.plan(18)
......
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