CARVIEW |
Select Language
HTTP/2 301
location: https://raw.githubusercontent.com/nbubna/store/master/src/store.on.js
accept-ranges: bytes
age: 0
date: Mon, 21 Jul 2025 08:41:37 GMT
via: 1.1 varnish
x-served-by: cache-bom4724-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753087297.918528,VS0,VE1015
vary: Accept-Encoding
x-fastly-request-id: d8f39fb3e6c387ed0ffed145b9849f864f8460c0
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: 2608:11B1B4:2BEBC2:81B05C:687DFD41
content-encoding: gzip
accept-ranges: bytes
date: Mon, 21 Jul 2025 08:41:38 GMT
via: 1.1 varnish
x-served-by: cache-bom4727-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753087298.984533,VS0,VE248
vary: Authorization,Accept-Encoding
access-control-allow-origin: *
cross-origin-resource-policy: cross-origin
x-fastly-request-id: 4e334c28c7c0f49f1d166c211ef2e9d392485bec
expires: Mon, 21 Jul 2025 08:46:38 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._);