CARVIEW |
Select Language
HTTP/2 301
location: https://raw.githubusercontent.com/nbubna/store/master/src/store.on.js
accept-ranges: bytes
age: 0
date: Thu, 24 Jul 2025 11:29:15 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210071-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753356555.486282,VS0,VE298
vary: Accept-Encoding
x-fastly-request-id: bdc2d1c9e11eb3c724b863d82cf46f4e4119a5e5
content-length: 0
HTTP/2 200
cache-control: max-age=300
content-security-policy: default-src 'none'; style-src 'unsafe-inline'; sandbox
content-type: text/plain; charset=utf-8
etag: W/"331c30cc69f0b8bf62d3425d1a0a54d07e9352489f8f56f9a95a79465c5599b2"
strict-transport-security: max-age=31536000
x-content-type-options: nosniff
x-frame-options: deny
x-xss-protection: 1; mode=block
x-github-request-id: 5CD2:0903:B72B:1638F:6882190A
content-encoding: gzip
accept-ranges: bytes
date: Thu, 24 Jul 2025 11:29:16 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210051-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753356556.837198,VS0,VE289
vary: Authorization,Accept-Encoding
access-control-allow-origin: *
cross-origin-resource-policy: cross-origin
x-fastly-request-id: 9edf301d20742d851cd9b34771e9cf1fa67264d9
expires: Thu, 24 Jul 2025 11:34:16 GMT
source-age: 0
content-length: 1043
/**
* Copyright (c) 2013 ESHA Research
* Dual licensed under the MIT and GPL licenses:
* https://www.opensource.org/licenses/mit-license.php
* https://www.gnu.org/licenses/gpl.html
*
* Makes it easy to watch for storage events by enhancing the events and
* allowing binding to particular keys and/or namespaces.
*
* // listen to particular key storage events (yes, this is namespace sensitive)
* store.on('foo', function listenToFoo(e){ console.log('foo was changed:', e); });
* store.off('foo', listenToFoo);
*
* // listen to all storage events (also namespace sensitive)
* store.on(function storageEvent(e){ console.log('web storage:', e); });
* store.off(storageEvent);
*
* Status: BETA - useful, if you aren't using IE8 or worse
*/
;(function(window, _) {
_.on = function(key, fn) {
if (!fn) { fn = key; key = ''; }// no key === all keys
var s = this,
listener = function(e) {
var k = s._out(e.key);// undefined if key is not in the namespace
if ((k && (k === key ||// match key if listener has one
(!key && k !== '_-bad-_'))) &&// match catch-all, except internal test
(!e.storageArea || e.storageArea === s._area)) {// match area, if available
return fn.call(s, _.event.call(s, k, e));
}
};
window.addEventListener("storage", fn[key+'-listener']=listener, false);
return this;
};
_.off = function(key, fn) {
if (!fn) { fn = key; key = ''; }// no key === all keys
window.removeEventListener("storage", fn[key+'-listener']);
return this;
};
_.once = function(key, fn) {
if (!fn) { fn = key; key = ''; }
var s = this, listener;
return s.on(key, listener = function() {
s.off(key, listener);
return fn.apply(this, arguments);
});
};
_.event = function(k, e) {
var event = {
key: k,
namespace: this.namespace(),
newValue: _.parse(e.newValue),
oldValue: _.parse(e.oldValue),
url: e.url || e.uri,
storageArea: e.storageArea,
source: e.source,
timeStamp: e.timeStamp,
originalEvent: e
};
if (_.cache) {
var min = _.expires(e.newValue || e.oldValue);
if (min) {
event.expires = _.when(min);
}
}
return event;
};
// store2 policy is to not throw errors on old browsers
var old = !window.addEventListener ? function(){} : null;
_.fn('on', old || _.on);
_.fn('off', old || _.off);
_.fn('once', old || _.once);
})(window, window.store._);