|
|
/* Copyright (C) NAVER corp. Licensed under LGPL v2. @see https://github.com/naver/smarteditor2/blob/master/LICENSE.md */ if(typeof window.nhn=="undefined"){window.nhn={}}if(!nhn.husky){nhn.husky={}}(function(){var b=/^\$(LOCAL|BEFORE|ON|AFTER)_/,c=/^\$(BEFORE|ON|AFTER)_MSG_APP_READY$/,a=[],d={};nhn.husky.HuskyCore=jindo.$Class({name:"HuskyCore",aCallerStack:null,bMobile:jindo.$Agent().navigator().mobile||jindo.$Agent().navigator().msafari,$init:function(e){this.htOptions=e||{};a.push(this);if(this.htOptions.oDebugger){nhn.husky.HuskyCore.getCore=function(){return a};this.htOptions.oDebugger.setApp(this)}this.messageQueue=[];this.oMessageMap={};this.oDisabledMessage={};this.oLazyMessage={};this.aPlugins=[];this.appStatus=nhn.husky.APP_STATUS.NOT_READY;this.aCallerStack=[];this._fnWaitForPluginReady=jindo.$Fn(this._waitForPluginReady,this).bind();this.registerPlugin(this)},setDebugger:function(e){this.htOptions.oDebugger=e;e.setApp(this)},exec:function(g,f,e){if(this.appStatus==nhn.husky.APP_STATUS.NOT_READY){this.messageQueue[this.messageQueue.length]={msg:g,args:f,event:e};return true}this.exec=this._exec;this.exec(g,f,e)},delayedExec:function(j,g,e,f){var h=jindo.$Fn(this.exec,this).bind(j,g,f);setTimeout(h,e)},_exec:function(g,f,e){return(this._exec=this.htOptions.oDebugger?this._execWithDebugger:this._execWithoutDebugger).call(this,g,f,e)},_execWithDebugger:function(h,g,f){this.htOptions.oDebugger.log_MessageStart(h,g);var e=this._doExec(h,g,f);this.htOptions.oDebugger.log_MessageEnd(h,g);return e},_execWithoutDebugger:function(g,f,e){return this._doExec(g,f,e)},_doExec:function(m,j,h){var f=false;if(this.oLazyMessage[m]){var l=this.oLazyMessage[m];this._loadLazyFiles(m,j,h,l.aFilenames,0);return false}if(!this.oDisabledMessage[m]){var g=[];if(j&&j.length){var e=j.length;for(var k=0;k<e;k++){g[k]=j[k]}}if(h){g[g.length]=h}f=this._execMsgStep("BEFORE",m,g);if(f){f=this._execMsgStep("ON",m,g)}if(f){f=this._execMsgStep("AFTER",m,g)}}return f},registerPlugin:function(f){if(!f){throw ("An error occured in registerPlugin(): invalid plug-in")}f.nIdx=this.aPlugins.length;f.oApp=this;this.aPlugins[f.nIdx]=f;if(f.status!=nhn.husky.PLUGIN_STATUS.NOT_READY){f.status=nhn.husky.PLUGIN_STATUS.READY}if(this.appStatus!=nhn.husky.APP_STATUS.NOT_READY){for(var e in f){if(b.test(e)){this.addToMessageMap(e,f)}}}this.exec("MSG_PLUGIN_REGISTERED",[f]);return f.nIdx},disableMessage:function(e,f){this.oDisabledMessage[e]=f},registerBrowserEvent:function(j,k,f,h,e){h=h||[];var g=(e)?jindo.$Fn(this.delayedExec,this).bind(f,h,e):jindo.$Fn(this.exec,this).bind(f,h);return jindo.$Fn(g,this).attach(j,k)},run:function(h){this.htRunOptions=h||{};this._changeAppStatus(nhn.husky.APP_STATUS.WAITING_FOR_PLUGINS_READY);var g=this.messageQueue.length;for(var f=0;f<g;f++){var e=this.messageQueue[f];this.exec(e.msg,e.args,e.event)}this._fnWaitForPluginReady()},acceptLocalBeforeFirstAgain:function(f,e){f._husky_bRun=!e},createMessageMap:function(e){this.oMessageMap[e]=[];var g=this.aPlugins.length;for(var f=0;f<g;f++){this._doAddToMessageMap(e,this.aPlugins[f])}},addToMessageMap:function(e,f){if(!this.oMessageMap[e]){return}this._doAddToMessageMap(e,f)},_changeAppStatus:function(e){this.appStatus=e;if(this.appStatus==nhn.husky.APP_STATUS.READY){this.exec("MSG_APP_READY")}},_execMsgStep:function(e,f,g){return(this._execMsgStep=this.htOptions.oDebugger?this._execMsgStepWithDebugger:this._execMsgStepWithoutDebugger).call(this,e,f,g)},_execMsgStepWithDebugger:function(e,g,h){this.htOptions.oDebugger.log_MessageStepStart(e,g,h);var f=this._execMsgHandler("$"+e+"_"+g,h);this.htOptions.oDebugger.log_MessageStepEnd(e,g,h);return f},_execMsgStepWithoutDebugger:function(e,f,g){return this._execMsgHandler("$"+e+"_"+f,g)},_execMsgHandler:function(f,g){var h;if(!this.oMessageMap[f]){this.createMessageMap(f)}var k=this.oMessageMap[f];var j=k.length;if(j===0){return true}var e=true;if(c.test(f)){for(h=0;h<j;h++){if(this._execHandler(k[h],f,g)===false){e=false;break}}}else{for(h=0;h<j;h++){if(!k[h]._husky_bRun){k[h]._husky_bRun=true;if(typeof k[h].$LOCAL_BEFORE_FIRST=="function"&&this._execHandler(k[h],"$LOCAL_BEFORE_FIRST",[f,g])===false){continue}}if(typeof k[h].$LOCAL_BEFORE_ALL=="function
|