@zklogic/draw.io
Version:
Draw.IO - Graph Editor integration in Angular-cli
1 lines • 1.78 kB
JavaScript
DrawioClient=function(e,t){mxEventSource.call(this),this.ui=e,this.cookieName=t,this.token=this.getPersistentToken()},mxUtils.extend(DrawioClient,mxEventSource),DrawioClient.prototype.token=null,DrawioClient.prototype.user=null,DrawioClient.prototype.setUser=function(e){this.user=e,this.fireEvent(new mxEventObject("userChanged"))},DrawioClient.prototype.getUser=function(){return this.user},DrawioClient.prototype.clearPersistentToken=function(){if(isLocalStorage)localStorage.removeItem("."+this.cookieName),sessionStorage.removeItem("."+this.cookieName);else if("undefined"!=typeof Storage){var e=new Date;e.setYear(e.getFullYear()-1),document.cookie=this.cookieName+"=; expires="+e.toUTCString()}},DrawioClient.prototype.getPersistentToken=function(e){var t=null;if(isLocalStorage&&null==(t=localStorage.getItem("."+this.cookieName))&&e&&(t=sessionStorage.getItem("."+this.cookieName)),null==t&&"undefined"!=typeof Storage){var o=document.cookie,i=this.cookieName+"=",r=o.indexOf(i);if(r>=0){r+=i.length;var n=o.indexOf(";",r);n<0?n=o.length:postCookie=o.substring(n);var s=o.substring(r,n);if(null!=(t=s.length>0?s:null)&&isLocalStorage){var a=new Date;a.setYear(a.getFullYear()-1),document.cookie=i+"; expires="+a.toUTCString(),localStorage.setItem("."+this.cookieName,t)}}}return t},DrawioClient.prototype.setPersistentToken=function(e,t){try{if(null!=e){if(isLocalStorage)t?sessionStorage.setItem("."+this.cookieName,e):localStorage.setItem("."+this.cookieName,e);else if("undefined"!=typeof Storage){var o=new Date;o.setYear(o.getFullYear()+10);var i=this.cookieName+"="+e+"; path=/"+(t?"":"; expires="+o.toUTCString());"https"==document.location.protocol.toLowerCase()&&(i+=";secure"),document.cookie=i}}else this.clearPersistentToken()}catch(e){this.ui.handleError(e)}};