forked from slimjack/IWC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiwc-all.min.js
1 lines (1 loc) · 13.7 KB
/
iwc-all.min.js
1
var SJ=SJ||{};SJ.ns=function(n){var t=n.split("."),i=SJ,r,u;for(t[0]==="SJ"&&(t=t.slice(1)),r=0;r<t.length;r++)u=t[r],typeof i[u]=="undefined"&&(i[u]={}),i=i[u];return i},function(n){var t={},u=0,i={}.toString,r={appName:window.applicationName||"DEFAULT",generateGUID:function(){var n=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var i=(n+Math.random()*16)%16|0;return n=Math.floor(n/16),(t=="x"?i:i&7|8).toString(16)})},callback:function(n){if(SJ.isFunction(n)){var t=Array.prototype.slice.call(arguments,1);n.apply(window,t)}},windowOn:function(n,i){i.handlerId=++u;var r=function(n){n=n||window.event;i(n)};t[i.handlerId]=i;window.addEventListener?window.addEventListener(n,r,!1):window.attachEvent&&window.attachEvent("on"+n,r)},windowUn:function(n,i){window.removeEventListener?window.removeEventListener(n,t[i.handlerId],!1):window.detachEvent&&window.detachEvent("un"+n,t[i.handlerId]);delete t[i.handlerId]},isIE:function(){var t=!window.ActiveXObject&&"ActiveXObject"in window,n;return t?11:(n=navigator.userAgent.toLowerCase(),n.indexOf("msie")!==-1?parseInt(n.split("msie")[1]):!1)},copy:function(n,t){for(var i in t)n[i]=t[i];return n},emptyFn:function(){},isEmpty:function(n){return n==null||n===""||SJ.isArray(n)&&n.length===0},isArray:"isArray"in Array?Array.isArray:function(n){return i.call(n)==="[object Array]"},isDate:function(n){return i.call(n)==="[object Date]"},isObject:function(n){return n!==null&&n!==undefined&&i.call(n)==="[object Object]"},isPrimitive:function(n){var t=typeof n;return t==="number"||t==="string"||t==="boolean"},isFunction:function(n){return!!n&&i.call(n)==="[object Function]"},isNumber:function(n){return typeof n=="number"&&isFinite(n)},isNumeric:function(n){return!isNaN(parseFloat(n))&&isFinite(n)},isString:function(n){return typeof n=="string"},isBoolean:function(n){return typeof n=="boolean"}};r.copy(n,r)}(SJ),function(n){var t={each:function(n,t){for(var i in n)if(n.hasOwnProperty(i)&&t(n[i],i)===!1)break}};SJ.copy(n,t)}(SJ.ns("Object")),function(n){function i(n){function r(n,i){for(var r=0;r<t[n].length;r++)t[n][r]===i&&t[n].splice(r,1)}function i(n,i,r){var f=t[n],u;if(f)for(u=0;u<f.length;u++)if(f[u].fn===i&&f[u].scope===r)return f[u];return null}var t={};return n.on=function(n,r,u){t[n]||(t[n]=[]);i(n,r,u)||t[n].push({fn:r,scope:u})},n.once=function(n,r,u){i(n,r,u)||(t[n]=t[n]||[],t[n].push({fn:r,scope:u,single:!0}))},n.un=function(n,t,u){var f=i(n,t,u);f&&r(n,f)},n.fire=function(n){var i=t[n],f,u;if(i)for(i=[].concat(i),f=Array.prototype.slice.call(arguments,1),u=0;u<i.length;u++)i[u].fn.apply(i[u].scope,f),i[u].single&&r(n,i[u])},n}function t(){i(this)}t.decorate=function(n,r){var u;return r?(u=new t,n.on=u.on,n.un=u.un,n.once=u.once):u=i(n),u};n.Observable=t}(SJ.ns("utils")),function(n){var t=window.localStorage,s,h;typeof t=="undefined"&&(t={getItem:function(){},setItem:function(){},removeItem:function(){}},alert("Local storage is not supported on this browser. Some features will not work."));var i=SJ.isIE()===11,u,f,o=new SJ.utils.Observable,r,e=SJ.isIE()===10||SJ.isIE()===9;e||(r=new SJ.utils.Observable);s=i?function(n){n=n||window.event;u=n.key;f=n.newValue;o.fire("storage",n);r.fire("storage",n)}:e?function(n){n=n||window.event;o.fire("storage",n)}:function(n){n=n||window.event;o.fire("storage",n);r.fire("storage",n)};window.addEventListener?(h=i?window.top:window,h.addEventListener("storage",s,!1),h!=window&&window.addEventListener("unload",function(){h.removeEventListener("storage",s,!1)})):window.attachEvent&&document.attachEvent("onstorage",s);n.localStorage={onChanged:function(n,t,i){if(i&&!e)r.on("storage",n,t);else o.on("storage",n,t)},onceChanged:function(n,t,i){if(i&&!e)r.once("storage",n,t);else o.once("storage",n,t)},unChanged:function(n,t){o.un("storage",n,t);e||r.un("storage",n,t)},getItem:function(n){return i&&u===n?f:t.getItem(n)},setItem:e?function(n,r){i&&u===n&&(f=r);t.setItem(n,r)}:function(n,e){var s=this.getItem(n),o;i&&u===n&&(f=e);t.setItem(n,e);o={key:n,oldValue:s,newValue:e,url:window.location.href.toString()};r.fire("storage",o)},removeItem:e?function(n){i&&u===n&&(f=null);t.removeItem(n)}:function(n){var o=this.getItem(n),e;i&&u===n&&(f=null);t.removeItem(n);e={key:n,oldValue:o,newValue:null,url:window.location.href.toString()};r.fire("storage",e)},forEach:i?function(n){for(var r,e,i=0;i<t.length;i++)if(r=t.key(i),e=r===u?f:t.getItem(r),n(r,e)===!1)break}:function(n){for(var r,u,i=0;i<t.length;i++)if(r=t.key(i),u=t.getItem(r),n(r,u)===!1)break},setVersion:function(n,t){var i=this,u=i.getItem(n),r;u!==t&&(r=[],i.forEach(function(t){t.substr(0,n.length)===n&&r.push(t)}),r.forEach(function(n){i.removeItem(n)}),i.setItem(n,t))}}}(SJ),function(n){var t="IWC_"+SJ.appName;n.getLocalStoragePrefix=function(){return t};n.$version="0.1.3";SJ.localStorage.setVersion(t,n.$version)}(SJ.ns("iwc")),function(n){function c(n){i.on("storagechanged",n)}function l(n){i.un("storagechanged",n)}function f(){i.fire("storagechanged")}function e(t,i){var v=!1,f=!1,y=null,b=n.testingMode?n.lockTimeout||r:r,p=function(){f||(c(e),y=window.setInterval(e,h),f=!0)},w=function(){f&&(l(e),window.clearInterval(y),f=!1)},e=function(){var r,f,e;if(!v){if(r=(new Date).getTime(),f=o(t),f&&r-f.timestamp<b){p();return}v=!0;w();s(t,r);e=window.setTimeout(function(){window.clearTimeout(e);var f=o(t);f&&(f.timestamp!==r||f.lockerId!==u)?(v=!1,p()):(w(),f||s(t,r),i(),n.testingMode||a(t))},10)}};e()}function o(n){var f=t+n,r=SJ.localStorage.getItem(f),u=null,i;return r&&(i=r.split("."),u={timestamp:parseInt(i[0])||0,lockerId:i[1]}),u}function s(n,i){var r=t+n;SJ.localStorage.setItem(r,i+"."+u)}function a(n){var i=t+n;SJ.localStorage.removeItem(i)}function v(n){if(n.key){var i=!n.newValue&&!!n.oldValue;i&&n.key.substr(0,t.length)===t&&f()}else f()}var t=SJ.iwc.getLocalStoragePrefix()+"_TLOCK_",r=3e3,h=50,u=SJ.generateGUID(),i;SJ.localStorage.onChanged(v);i=new SJ.utils.Observable;n.interlockedCall=e;SJ.interlockedCall=e}(SJ.ns("iwc.Lock")),function(n){var t=function(n){var t=this;t._dataId=n;t._observable=new SJ.utils.Observable;t._serializedData=SJ.localStorage.getItem(t._dataId);SJ.localStorage.onChanged(t.onStorageChanged,t,!0)};t.prototype={constructor:t,get:function(){var n=this,t;return n._serializedData=SJ.localStorage.getItem(n._dataId),t=null,n._serializedData&&(t=JSON.parse(n._serializedData)),t},set:function(n,t){var i=this;SJ.iwc.Lock.interlockedCall(i._dataId,function(){i.writeToStorage(n);SJ.callback(t)})},change:function(n){var t=this;SJ.iwc.Lock.interlockedCall(t._dataId,function(){var i=t.get();i=n(i);t.writeToStorage(i)})},onChanged:function(n,t){var i=this;i._observable.on("changed",n,t)},onceChanged:function(n,t){var i=this;i._observable.once("changed",n,t)},unsubscribe:function(n,t){var i=this;i._observable.un("changed",n,t)},writeToStorage:function(n){var t=this,i=n!==null?JSON.stringify(n):"";SJ.localStorage.setItem(t._dataId,i)},onStorageChanged:function(n){var t=this,i,r;n.key&&n.key!==t._dataId||(i=SJ.localStorage.getItem(t._dataId),i!==t._serializedData&&(t._serializedData=i,r=null,i&&(r=JSON.parse(i)),t._observable.fire("changed",r)))}};n.SharedData=t}(SJ.ns("iwc")),function(n){function f(n){if(n.key===u&&n.newValue){var f=JSON.parse(n.newValue);f.senderBusNodeId!==r&&(i.fire.apply(window,f.args),t.fire.apply(window,f.args))}}function e(){var n={senderBusNodeId:r,args:Array.prototype.slice.call(arguments,0)},i=JSON.stringify(n);SJ.localStorage.setItem(u,i);t.fire.apply(window,n.args)}var r=SJ.generateGUID(),i=new SJ.utils.Observable,t=new SJ.utils.Observable,u=SJ.iwc.getLocalStoragePrefix()+"_EBUS";SJ.localStorage.onChanged(f);SJ.copy(n,{on:function(n,r,u,f){if(f)t.on(n,r,u);else i.on(n,r,u)},once:function(n,r,u,f){if(f)t.once(n,r,u);else i.once(n,r,u)},un:function(n,r,u,f){f?t.un(n,r,u):i.un(n,r,u)},fire:e})}(SJ.ns("iwc.EventBus")),function(n){function p(){SJ.localStorage.removeItem(l)}function w(n){n===r&&(h(),SJ.iwc.EventBus.fire("windowisaliveresponce",n))}function b(n){n!==r&&t[n]&&delete t[n]}function k(n){n.key?n.key.substr(0,u.length)===u&&c():c()}function d(){var n={};return SJ.localStorage.forEach(function(t,i){if(i&&t.substr(0,u.length)===u){var r=t.substr(u.length);n[r]=parseInt(i)}}),g(n),n}function h(){c();var n=(new Date).getTime();i[r]=n;SJ.localStorage.setItem(l,n);s||(s=!0,f.fire("windowsmanagerready"))}function g(n){var e=(new Date).getTime(),f;for(var i in n)n.hasOwnProperty(i)&&i!==r&&(f=e-n[i],f>2*o||f>o&&t[i]&&e-t[i]>v?(delete n[i],SJ.localStorage.removeItem(u+i)):f>o?t[i]||(t[i]=e,SJ.iwc.EventBus.fire("windowisaliverequest",i)):t[i]&&delete t[i]);for(i in t)t.hasOwnProperty(i)&&!n.hasOwnProperty(i)&&delete t[i]}function nt(n){return!!i[n]}function c(){var t=d(),u=[],r;for(var n in t)t.hasOwnProperty(n)&&!i[n]&&u.push(n);r=[];for(n in i)i.hasOwnProperty(n)&&!t[n]&&r.push(n);i=t;(u.length||r.length)&&tt(u,r)}function tt(n,t){f.fire("windowschanged",n,t)}function a(n){n===r&&(window.focus(),it())}function it(){var t;if(!e){var i=500,r=document.title,n=!1;e=6;t=function(){document.title=n?r:"******";n=!n;e--;e&&window.setTimeout(t,i)};window.setTimeout(t,i)}}var o=5e3,v=2e3,i={},t={},r=window.name||SJ.generateGUID(),s=!1,f=new SJ.utils.Observable,u=SJ.iwc.getLocalStoragePrefix()+"_WND_",y=o/2,l=u+r,e;SJ.windowOn("unload",p);SJ.localStorage.onChanged(k);SJ.iwc.EventBus.on("windowfocusrequest",a);SJ.iwc.EventBus.on("windowisaliverequest",w);SJ.iwc.EventBus.on("windowisaliveresponce",b);h();window.setInterval(h,y);e=0;SJ.copy(n,{isWindowOpen:nt,getOpenWindowIds:function(){var n=[];for(var t in i)i.hasOwnProperty(t)&&n.push(t);return n},setFocus:function(n){n?a(r):SJ.iwc.EventBus.fire("windowfocusrequest",n)},getThisWindowId:function(){return r},isReady:function(){return s},onReady:function(n,t){if(s)n.call(t);else f.once("windowsmanagerready",n,t)},onWindowsChanged:function(n,t){f.on("windowschanged",n,t)},onceWindowsChanged:function(n,t){f.once("windowschanged",n,t)},unsubscribe:function(n,t){f.un("windowschanged",n,t)}})}(SJ.ns("iwc.WindowMonitor")),function(n){function y(n){i.on("storagechanged",n)}function o(n){i.un("storagechanged",n)}function u(){i.fire("storagechanged")}function p(n){i.once("locksinitialized",n)}function w(){e=!0;i.fire("locksinitialized")}function s(n,t){var i=!1,s=!1,r=!1,c=null,h={lockId:n,release:function(){s=!0;r&&(o(lock),r=!1);i&&(i=!1,g(n))},isCaptured:function(){return i},isReleased:function(){return s}},a=function(){r||(y(u),c=window.setInterval(u,v),r=!0)},w=function(){r&&(o(u),window.clearInterval(c),r=!1)},u=function(){i||s||(f(n)?a():(w(),SJ.iwc.Lock.interlockedCall(n,function(){f(n)?(a(),f(n)||(w(),l(h),i=!0,t())):(l(h),i=!0,t())})))};return e?u():p(u),h}function b(n){if(n.key){var i=!n.newValue&&!!n.oldValue;i&&n.key.substr(0,t.length)===t&&u()}else u()}function h(n){SJ.iwc.WindowMonitor.onReady(function(){SJ.localStorage.forEach(function(n,i){if(i&&n.substr(0,t.length)===t){var r=n.substr(t.length);c(r,i)&&SJ.iwc.Lock.interlockedCall(r,function(){var t=SJ.localStorage.getItem(n);t&&c(r,t)&&(SJ.localStorage.removeItem(n),u())})}});n&&n()})}function c(n,t){var i=JSON.parse(t),r,u;return!i||!i.timestamp||!i.ownerWindowId?!0:(r=i.ownerWindowId===SJ.iwc.WindowMonitor.getThisWindowId(),u=!SJ.iwc.WindowMonitor.isWindowOpen(i.ownerWindowId),u||r&&a(n)===-1)}function k(){for(var t=[].concat(r),n=0;n<t.length;n++)t[n].release()}function d(){k()}function l(n){var i=(new Date).getTime(),u={timestamp:i,ownerWindowId:SJ.iwc.WindowMonitor.getThisWindowId()},f=t+n.lockId;SJ.localStorage.setItem(f,JSON.stringify(u));r.push(n)}function g(n){var e=a(n),i,f,o;e!==-1&&r.splice(e,1);i=t+n;f=SJ.localStorage.getItem(i);f&&(o=JSON.parse(f),SJ.iwc.WindowMonitor.getThisWindowId()===o.ownerWindowId&&SJ.localStorage.removeItem(i));u()}function f(n){var u=t+n,i=SJ.localStorage.getItem(u),r;return i?(r=JSON.parse(i),SJ.iwc.WindowMonitor.isWindowOpen(r.ownerWindowId)):!1}function a(n){for(var t=0;t<r.length;t++)if(r[t].lockId===n)return t;return-1}var t=SJ.iwc.getLocalStoragePrefix()+"_LOCK_",v=500,r=[],e=!1,i;SJ.localStorage.onChanged(b);i=new SJ.utils.Observable;SJ.windowOn("unload",d);h(function(){SJ.iwc.WindowMonitor.onWindowsChanged(function(n,t){t.length&&h()});w()});n.capture=s;SJ.lock=s}(SJ.ns("iwc.Lock")),function(n){var t=function(n,t){var i=this,r;i._serverId=n;i._isReady=!1;i._observable=SJ.utils.Observable.decorate(i,!0);i._serverDescriptionHolder=new SJ.iwc.SharedData(n);r=i._serverDescriptionHolder.get();r&&i.updateContract(r);i._serverDescriptionHolder.onChanged(function(n){i.updateContract(n)});if(t)i.onReady(t)};t.prototype={constructor:t,onReady:function(n,t){var i=this;if(i._isReady)n.call(t);else i._observable.once("ready",n,t)},updateContract:function(n){var t=this,i=n;i.forEach(function(n){t[n]||(t[n]=t.createProxyMethod(n))});t._isReady||(t._isReady=!0,t._observable.fire("ready"))},createProxyMethod:function(n){var t=this;return function(){var r=null,u=null,i=Array.prototype.slice.call(arguments,0),f;if(i.length&&SJ.isFunction(i[i.length-1])&&(r=SJ.generateGUID(),u=i.pop()),f={methodName:n,callId:r,args:i},SJ.iwc.EventBus.fire("servercall_"+t._serverId,f),r)SJ.iwc.EventBus.once("servercallback_"+r,u)}}};n.Client=t}(SJ.ns("iwc")),function(n){var t=function(n,t){var i=this,r;i._serverId=n;i._serverDescriptionHolder=new SJ.iwc.SharedData(i._serverId);SJ.copy(i,t.exposed);r=t.exposed;delete t.exposed;SJ.copy(i,t);SJ.lock(n,function(){i.onInit();i.updateServerDescription(r);SJ.iwc.EventBus.on("servercall_"+i._serverId,i.onServerCall,i)})};t.prototype={constructor:t,onInit:SJ.emptyFn,updateServerDescription:function(n){var i=this,t=[];SJ.Object.each(n,function(n){t.push(n)});i._serverDescriptionHolder.set(t)},onServerCall:function(n){var i=this,t=n.args||[],r;n.callId?(r=function(){var n=Array.prototype.slice.call(arguments,0);n.unshift("servercallback_"+callId);SJ.iwc.EventBus.fire.apply(SJ.iwc.EventBus,n)},t.unshift(r)):t.unshift(SJ.emptyFn);i[n.methodName].apply(i,t)}};n.Server=t}(SJ.ns("iwc"));