$=function(_asId,_oTarget){var _oDom=_oTarget||window.document;return _oDom.getElementById(_asId)};(function(){function QEditorMenuAdaptor(){this._cmds={};this._popupPos={};this._callbacks={};this._oFocusDom=null}QEditorMenuAdaptor.prototype.getBindEditor=function(){return this._moBindEditor};QEditorMenuAdaptor.prototype._setBindEditor=function(_oEditor){this._moBindEditor=_oEditor};QEditorMenuAdaptor.prototype.initMenuAdaptor=function(_oConfig,_oEditor){this._setBindEditor(_oEditor);var _oSelf=this,_oDom=window.document;this._moBindEditor._moEditDoc.oncontextmenu=function(_oEvt){_oSelf._notifyPopupMenu.call(_oSelf,_oEvt)};_oDom.oncontextmenu=function(_oEvt){_oSelf._notifyPopupMenu.call(_oSelf,_oEvt)};this._moMenuCfg=_oConfig;this._oFocusDom=_oEditor._moEditDoc};QEditorMenuAdaptor.prototype._notifyPopupMenu=function(_oEvt){_oEvt.preventDefault();_oEvt.cancelBubble=true;this._popupPos.x=_oEvt.x;this._popupPos.y=_oEvt.y;if(_oEvt.currentTarget!=this._moBindEditor._moEditDoc){var _oTitleDom=$('QMtitle');if(_oEvt.target!=_oTitleDom&&_oEvt.target.tagName&&_oEvt.target.tagName.toLowerCase()=="input"){this._oFocusDom=_oEvt.target}else{_oTitleDom.focus();this._oFocusDom=_oTitleDom}}else{this._moBindEditor._moEditObj.focus();this._oFocusDom=this._moBindEditor._moEditDoc}if(external){var _oMenuCfg={cfg:this._moMenuCfg,pos:{x:_oEvt.screenX,y:_oEvt.screenY}};for(var i in _oMenuCfg.cfg){if(_oMenuCfg.cfg[i].cmd=="cut"){if("false"==this._moBindEditor._moEditBody.contentEditable){_oMenuCfg.cfg[i].enable=false}else{_oMenuCfg.cfg[i].enable=this._hasSelectedArea()}}else if(_oMenuCfg.cfg[i].cmd=="copy"){_oMenuCfg.cfg[i].enable=this._hasSelectedArea()}else if(_oMenuCfg.cfg[i].cmd=="paste"){if("false"==this._moBindEditor._moEditBody.contentEditable){_oMenuCfg.cfg[i].enable=false}else{var _dataFormat=this._getDataFormatInClipboard();_oMenuCfg.cfg[i].enable=!_dataFormat?false:true}}else if(_oMenuCfg.cfg[i].cmd=="pasteastext"){if("false"==this._moBindEditor._moEditBody.contentEditable){_oMenuCfg.cfg[i].enable=false}else{var _dataFormat=this._getDataFormatInClipboard();_oMenuCfg.cfg[i].enable=!_dataFormat?false:true}}else if(_oMenuCfg.cfg[i].cmd=="saveas"){if(this.IsPicObj(_oEvt)){_oMenuCfg.cfg[i].path=decodeURIComponent(_oEvt.srcElement.src);if(_oMenuCfg.cfg[i].path.substr(0,5)!="http:"&&_oMenuCfg.cfg[i].path.substr(0,6)!="https:"){_oMenuCfg.cfg[i].enable=true}}else{_oMenuCfg.cfg[i].enable=false}}else{_oMenuCfg.cfg[i].enable=true}}if(external&&external.RequirePopupMenu)external.RequirePopupMenu(JSON.stringify(_oMenuCfg))}};QEditorMenuAdaptor.prototype.IsPicObj=function(e){var evt=e;var objX=evt.srcElement||evt.target||evt;if(objX.tagName.toLowerCase()=="img"){return true}return false};QEditorMenuAdaptor.prototype._hasSelectedArea=function(){if(this._oFocusDom!=this._moBindEditor._moEditDoc){var nStart=this._oFocusDom.selectionStart,nEnd=this._oFocusDom.selectionEnd;return nStart!=nEnd}var selections=this._moBindEditor._moEditWin.getSelection();return!selections.isCollapsed};QEditorMenuAdaptor.prototype._getDataFormatInClipboard=function(){if(external&&external.RequireGetDataFormatInClipboard){return external.RequireGetDataFormatInClipboard()}return 0};QEditorMenuAdaptor.prototype.execCmd=function(_sCmd){var _sCmdFn=[_sCmd,"Fn"].join("");QEditorMenuAdaptor.cmdFns[_sCmdFn].call(this)};QEditorMenuAdaptor.cmdFns={cutFn:function(_oArgs){if(this._oFocusDom!=this._moBindEditor._moEditDoc){window.document.execCommand("cut")}else{this._moBindEditor._moEditDoc.execCommand("cut")}},copyFn:function(_oArgs){if(this._oFocusDom!=this._moBindEditor._moEditDoc){window.document.execCommand("copy")}else{this._moBindEditor._moEditDoc.execCommand("copy")}},pasteFn:function(_oArgs){if(this._oFocusDom!=this._moBindEditor._moEditDoc){window.document.execCommand("paste")}else{this._moBindEditor.execCmd("paste")}},pasteastextFn:function(_oArgs){if(this._oFocusDom!=this._moBindEditor._moEditDoc){window.document.execCommand("paste")}else{if(external){var text=external.RequireGetDataInClipboard();this._moBindEditor._moEditDoc.execCommand("insertText",false,text)}}},allselFn:function(_oArgs){if(this._oFocusDom!=this._moBindEditor._moEditDoc){var selections=window.getSelection();selections.removeAllRanges();this._oFocusDom.setSelectionRange(0,this._oFocusDom.value.length)}else{var _oBody=this._moBindEditor._moEditDoc.body,rgn=this._moBindEditor._moEditDoc.createRange();rgn.selectNodeContents(_oBody);var selections=this._moBindEditor._moEditWin.getSelection();selections.removeAllRanges();selections.addRange(rgn)}}};window.menuAdaptor=new QEditorMenuAdaptor()})();