liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//>>built
define("dojo/_base/array dojo/aspect dojo/_base/declare dojo/dom-attr dojo/dom-construct dojo/dom-geometry dojo/dom-style dojo/i18n dojo/keys dojo/_base/lang dojo/on dojo/sniff dojo/window ../../focus ../_Plugin ../../form/ToggleButton ../.. ../../registry dojo/i18n!../nls/commands".split(" "),function(n,x,y,p,q,k,f,z,r,d,t,u,v,w,l,A,B,C){var m=y("dijit._editor.plugins.ViewSource",l,{stripScripts:!0,stripComments:!0,stripIFrames:!0,stripEventHandlers:!0,readOnly:!1,_fsPlugin:null,toggle:function(){u("webkit")&&
(this._vsFocused=!0);this.button.set("checked",!this.button.get("checked"))},_initButton:function(){var a=z.getLocalization("dijit._editor","commands"),b=this.editor;this.button=new A({label:a.viewSource,ownerDocument:b.ownerDocument,dir:b.dir,lang:b.lang,showLabel:!1,iconClass:this.iconClassPrefix+" "+this.iconClassPrefix+"ViewSource",tabIndex:"-1",onChange:d.hitch(this,"_showSource")});this.button.set("readOnly",!1)},setEditor:function(a){this.editor=a;this._initButton();this.editor.addKeyHandler(r.F12,
!0,!0,d.hitch(this,function(a){this.button.focus();this.toggle();a.stopPropagation();a.preventDefault();setTimeout(d.hitch(this,function(){this.editor.focused&&this.editor.focus()}),100)}))},_showSource:function(a){var b=this.editor,g=b._plugins,c;this._sourceShown=a;var e=this;try{this.sourceArea||this._createSourceView();if(a)b._sourceQueryCommandEnabled=b.queryCommandEnabled,b.queryCommandEnabled=function(a){return"viewsource"===a.toLowerCase()},this.editor.onDisplayChanged(),c=b.get("value"),
c=this._filter(c),b.set("value",c),n.forEach(g,function(a){!a||a instanceof m||!a.isInstanceOf(l)||a.set("disabled",!0)}),this._fsPlugin&&(this._fsPlugin._getAltViewNode=function(){return e.sourceArea}),this.sourceArea.value=c,this.sourceArea.style.height=b.iframe.style.height,this.sourceArea.style.width=b.iframe.style.width,b.iframe.parentNode.style.position="relative",f.set(b.iframe,{position:"absolute",top:0,visibility:"hidden"}),f.set(this.sourceArea,{display:"block"}),this._resizeHandle=t(window,
"resize",d.hitch(this,function(){var a=v.getBox(b.ownerDocument);"_prevW"in this&&"_prevH"in this&&a.w===this._prevW&&a.h===this._prevH||(this._prevW=a.w,this._prevH=a.h,this._resizer&&(clearTimeout(this._resizer),delete this._resizer),this._resizer=setTimeout(d.hitch(this,function(){delete this._resizer;this._resize()}),10))})),setTimeout(d.hitch(this,this._resize),100),this.editor.onNormalizedDisplayChanged(),this.editor.__oldGetValue=this.editor.getValue,this.editor.getValue=d.hitch(this,function(){var a=
this.sourceArea.value;return a=this._filter(a)}),this._setListener=x.after(this.editor,"setValue",d.hitch(this,function(a){a=this._filter(a||"");this.sourceArea.value=a}),!0);else{if(!b._sourceQueryCommandEnabled)return;this._setListener.remove();delete this._setListener;this._resizeHandle.remove();delete this._resizeHandle;this.editor.__oldGetValue&&(this.editor.getValue=this.editor.__oldGetValue,delete this.editor.__oldGetValue);b.queryCommandEnabled=b._sourceQueryCommandEnabled;this._readOnly||
(c=this.sourceArea.value,c=this._filter(c),b.beginEditing(),b.set("value",c),b.endEditing());n.forEach(g,function(a){a&&a.isInstanceOf(l)&&a.set("disabled",!1)});f.set(this.sourceArea,"display","none");f.set(b.iframe,{position:"relative",visibility:"visible"});delete b._sourceQueryCommandEnabled;this.editor.onDisplayChanged()}setTimeout(d.hitch(this,function(){var a=b.domNode.parentNode;a&&(a=C.getEnclosingWidget(a))&&a.resize&&a.resize();b.resize()}),300)}catch(h){console.log(h)}},updateState:function(){this.button.set("disabled",
this.get("disabled"))},_resize:function(){var a=this.editor,b=a.getHeaderHeight(),g=a.getFooterHeight(),c=k.position(a.domNode),e=k.getPadBorderExtents(a.iframe.parentNode),h=k.getMarginExtents(a.iframe.parentNode),d=k.getPadBorderExtents(a.domNode),f=c.w-d.w,c=c.h-(b+d.h+g);this._fsPlugin&&this._fsPlugin.isFullscreen&&(a=v.getBox(a.ownerDocument),f=a.w-d.w,c=a.h-(b+d.h+g));k.setMarginBox(this.sourceArea,{w:Math.round(f-(e.w+h.w)),h:Math.round(c-(e.h+h.h))})},_createSourceView:function(){var a=this.editor,
b=a._plugins;this.sourceArea=q.create("textarea");this.readOnly&&(p.set(this.sourceArea,"readOnly",!0),this._readOnly=!0);f.set(this.sourceArea,{padding:"0px",margin:"0px",borderWidth:"0px",borderStyle:"none"});p.set(this.sourceArea,"aria-label",this.editor.id);q.place(this.sourceArea,a.iframe,"before");u("ie")&&a.iframe.parentNode.lastChild!==a.iframe&&f.set(a.iframe.parentNode.lastChild,{width:"0px",height:"0px",padding:"0px",margin:"0px",borderWidth:"0px",borderStyle:"none"});a._viewsource_oldFocus=
a.focus;var g=this;a.focus=function(){if(g._sourceShown)g.setSourceAreaCaret();else try{this._vsFocused?(delete this._vsFocused,w.focus(a.editNode)):a._viewsource_oldFocus()}catch(h){console.log("ViewSource focus code error: "+h)}};var c,e;for(c=0;c<b.length;c++)if((e=b[c])&&("dijit._editor.plugins.FullScreen"===e.declaredClass||e.declaredClass===B._scopeName+"._editor.plugins.FullScreen")){this._fsPlugin=e;break}this._fsPlugin&&(this._fsPlugin._viewsource_getAltViewNode=this._fsPlugin._getAltViewNode,
this._fsPlugin._getAltViewNode=function(){return g._sourceShown?g.sourceArea:this._viewsource_getAltViewNode()});this.own(t(this.sourceArea,"keydown",d.hitch(this,function(b){this._sourceShown&&b.keyCode==r.F12&&b.ctrlKey&&b.shiftKey&&(this.button.focus(),this.button.set("checked",!1),setTimeout(d.hitch(this,function(){a.focus()}),100),b.stopPropagation(),b.preventDefault())})))},_stripScripts:function(a){a&&(a=a.replace(/<\s*script[^>]*>((.|\s)*?)<\\?\/\s*script\s*>/ig,""),a=a.replace(/<\s*script\b([^<>]|\s)*>?/ig,
""),a=a.replace(/<[^>]*=(\s|)*[("|')]javascript:[^$1][(\s|.)]*[$1][^>]*>/ig,""));return a},_stripComments:function(a){a&&(a=a.replace(/\x3c!--(.|\s){1,}?--\x3e/g,""));return a},_stripIFrames:function(a){a&&(a=a.replace(/<\s*iframe[^>]*>((.|\s)*?)<\\?\/\s*iframe\s*>/ig,""));return a},_stripEventHandlers:function(a){if(a){var b=a.match(/<[a-z]+?\b(.*?on.*?(['"]).*?\2.*?)+>/gim);if(b)for(var d=0,c=b.length;d<c;d++){var e=b[d],f=e.replace(/\s+on[a-z]*\s*=\s*(['"])(.*?)\1/igm,"");a=a.replace(e,f)}}return a},
_filter:function(a){a&&(this.stripScripts&&(a=this._stripScripts(a)),this.stripComments&&(a=this._stripComments(a)),this.stripIFrames&&(a=this._stripIFrames(a)),this.stripEventHandlers&&(a=this._stripEventHandlers(a)));return a},setSourceAreaCaret:function(){var a=this.sourceArea;w.focus(a);this._sourceShown&&!this.readOnly&&(a.setSelectionRange?a.setSelectionRange(0,0):this.sourceArea.createTextRange&&(a=a.createTextRange(),a.collapse(!0),a.moveStart("character",-99999),a.moveStart("character",0),
a.moveEnd("character",0),a.select()))},destroy:function(){this._resizer&&(clearTimeout(this._resizer),delete this._resizer);this._resizeHandle&&(this._resizeHandle.remove(),delete this._resizeHandle);this._setListener&&(this._setListener.remove(),delete this._setListener);this.inherited(arguments)}});l.registry.viewSource=l.registry.viewsource=function(a){return new m({readOnly:"readOnly"in a?a.readOnly:!1,stripComments:"stripComments"in a?a.stripComments:!0,stripScripts:"stripScripts"in a?a.stripScripts:
!0,stripIFrames:"stripIFrames"in a?a.stripIFrames:!0,stripEventHandlers:"stripEventHandlers"in a?a.stripEventHandlers:!0})};return m});