UNPKG

@arnellebalane/master-tab

Version:

Controls which tab should be the master tab when opening a page in multiple browser tabs

3 lines (2 loc) 1.28 kB
var t=new(function(t,e){return t(e={exports:{}},e.exports),e.exports}(function(t){var e=function(){this.$listeners={}};e.prototype.on=function(t,e){this.$listeners[t]||(this.$listeners[t]=[]),this.$listeners[t].push(e)},e.prototype.off=function(t,e){if(this.$listeners[t]){if(e instanceof Function){var n=this.$listeners[t].indexOf(e);this.$listeners[t].splice(n,1)}this.$listeners[t].length&&e||delete this.$listeners[t]}},e.prototype.emit=function(t,e){this.$listeners[t]&&this.$listeners[t].forEach(function(t){return t(e)})},t.exports=e})),e=t.STORAGE_KEY||"mastertab",n=t.INSTANCE_ID||Math.floor(65536*Math.random()).toString(16),i=0,s=1,o=2,r=function(){var t=localStorage.getItem(e);return t?t.split(";"):[]},c=function(t){localStorage.setItem(e,t.join(";"))},a=function(e){t.emit("change",e[0]===n)};["pageshow","focus","visibilitychange"].forEach(function(t){window.addEventListener(t,function(t){if(("hidden"===document.visibilityState?o:document.hasFocus()?i:s)!==o){var e=r(),f=e.indexOf(n);f<0&&(f=e.length),e.splice(f,1),e.unshift(n),c(e),a(e)}})}),window.addEventListener("unload",function(){var t=r(),e=t.indexOf(n);t.splice(e,1),c(t),a(t)}),window.addEventListener("storage",function(t){t.key===e&&a(r())}),module.exports=t; //# sourceMappingURL=master-tab.js.map