CARVIEW |
Select Language
HTTP/2 301
location: https://raw.githubusercontent.com/nbubna/store/master/src/store.bind.js
accept-ranges: bytes
age: 0
date: Wed, 23 Jul 2025 20:59:09 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210088-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753304349.799024,VS0,VE239
vary: Accept-Encoding
x-fastly-request-id: 262654d21c319a630764d0b75744031b7218531e
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/"9e421012da462f1d506edee567e2f14d3502ce5f9337b0b5def59027a06415b8"
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: 16AC:2FAC39:1BBCE3:4009BE:68814D0E
content-encoding: gzip
accept-ranges: bytes
date: Wed, 23 Jul 2025 20:59:09 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210069-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753304349.087356,VS0,VE266
vary: Authorization,Accept-Encoding
access-control-allow-origin: *
cross-origin-resource-policy: cross-origin
x-fastly-request-id: 200066ef8410ebba9fcecb43ef619424dcc710bf
expires: Wed, 23 Jul 2025 21:04:09 GMT
source-age: 0
content-length: 1008
/**
* 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
* store.on(function storageEvent(e){ console.log('web storage:', e); });
* store.off(storageEvent);
*
* Status: ALPHA - useful, if you don't mind incomplete browser support for events
*/
;(function(window, document, _) {
_.fn('on', function(key, fn) {
if (!fn) { fn = key; key = ''; }// shift args when needed
var s = this,
bound,
id = _.id(this._area);
if (window.addEventListener) {
window.addEventListener("storage", bound = function(e) {
var k = s._out(e.key);
if (k && (!key || k === key)) {// must match key if listener has one
var eid = _.id(e.storageArea);
if (!eid || id === eid) {// must match area, if event has a known one
return fn.call(s, _.event(k, s, e));
}
}
}, false);
} else {
document.attachEvent("onstorage", bound = function() {
return fn.call(s, window.event);
});
}
fn['_'+key+'listener'] = bound;
return s;
});
_.fn('off', function(key, fn) {
if (!fn) { fn = key; key = ''; }// shift args when needed
var bound = fn['_'+key+'listener'];
if (window.removeEventListener) {
window.removeEventListener("storage", bound);
} else {
document.detachEvent("onstorage", bound);
}
return this;
});
_.event = function(k, s, e) {
var event = {
key: k,
namespace: s.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;
};
_.id = function(area) {
for (var id in _.areas) {
if (area === _.areas[id]) {
return id;
}
}
};
})(window, document, window.store._);