diff options
| author | Ailin Nemui | 2016-04-18 14:21:46 +0200 | 
|---|---|---|
| committer | Ailin Nemui | 2016-04-18 14:21:59 +0200 | 
| commit | 33b0332ceefc5deb239fa53a0b2db1edbfa3560c (patch) | |
| tree | b9bf13e24417ad6d7d0442da4ecd037c3290452d /assets | |
| parent | 726b046a3c616a0d50a220aad72e3459bef334f1 (diff) | |
| download | scripts.irssi.org-33b0332ceefc5deb239fa53a0b2db1edbfa3560c.tar.bz2 | |
support filling the javascript filter from url hash
[skip ci]
Diffstat (limited to 'assets')
| -rw-r--r-- | assets/js/hashfill.js | 32 | 
1 files changed, 32 insertions, 0 deletions
| diff --git a/assets/js/hashfill.js b/assets/js/hashfill.js new file mode 100644 index 0000000..a831703 --- /dev/null +++ b/assets/js/hashfill.js @@ -0,0 +1,32 @@ +(function(document, $) { +    'use strict'; + +    function readhash() { +	var kv = window.location.hash.substr(1).split('&'); +	for(var i = 0; i < kv.length; i++) { +	    var p = kv[i].split('='); +	    var e = $(':input').filter(function(i, e) { +		return (e.dataset||{}).name === p[0]; +	    }); +	    if (e && e[0]) { +		e[0].value = decodeURIComponent(p[1].replace(/[+]/g, '%20')); +		if ('createEvent' in document) { +		    var ev = document.createEvent('HTMLEvents'); +		    ev.initEvent('input', true, false); +		    e[0].dispatchEvent(ev); +		} +	    } +	} +    } + +    if ('onhashchange' in window) { +	$(window).bind('hashchange', readhash); +    } + +    document.addEventListener('readystatechange', function() { +	if (document.readyState === 'complete') { +	    readhash(); +	} +    }); + +})(document, $); | 
