//>>built
define("dijit/_editor/plugins/ViewSource","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(p,m,y,q,r,k,e,z,t,c,u,v,w,x,f,A,B,C){var n=y("dijit._editor.plugins.ViewSource",f,{stripScripts:!0,stripComments:!0,stripIFrames:!0,stripEventHandlers:!0,readOnly:!1,
_fsPlugin:null,toggle:function(){v("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:c.hitch(this,"_showSource")});this.button.set("readOnly",!1)},setEditor:function(a){this.editor=
a;this._initButton();this.removeValueFilterHandles();this._setValueFilterHandle=m.before(this.editor,"setValue",c.hitch(this,function(a){return[this._filter(a)]}));this._getValueFilterHandle=m.after(this.editor,"getValue",c.hitch(this,function(a){return this._filter(a)}));this.editor.addKeyHandler(t.F12,!0,!0,c.hitch(this,function(a){this.button.focus();this.toggle();a.stopPropagation();a.preventDefault();setTimeout(c.hitch(this,function(){this.editor.focused&&this.editor.focus()}),100)}))},_showSource:function(a){var b=
this.editor,g=b._plugins,d;this._sourceShown=a;var h=this;try{this.sourceArea||this._createSourceView();if(a)b._sourceQueryCommandEnabled=b.queryCommandEnabled,b.queryCommandEnabled=function(a){return"viewsource"===a.toLowerCase()},this.editor.onDisplayChanged(),p.forEach(g,function(a){!a||a instanceof n||!a.isInstanceOf(f)||a.set("disabled",!0)}),this._fsPlugin&&(this._fsPlugin._getAltViewNode=function(){return h.sourceArea}),this.sourceArea.value=b.get("value"),this.sourceArea.style.height=b.iframe.style.height,
this.sourceArea.style.width=b.iframe.style.width,b.iframe.parentNode.style.position="relative",e.set(b.iframe,{position:"absolute",top:0,visibility:"hidden"}),e.set(this.sourceArea,{display:"block"}),this._resizeHandle=u(window,"resize",c.hitch(this,function(){var a=w.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(c.hitch(this,
function(){delete this._resizer;this._resize()}),10))})),setTimeout(c.hitch(this,this._resize),100),this.editor.onNormalizedDisplayChanged(),this.editor.__oldGetValue=this.editor.getValue,this.editor.getValue=c.hitch(this,function(){var a=this.sourceArea.value;return a=this._filter(a)}),this._setListener=m.after(this.editor,"setValue",c.hitch(this,function(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||(d=this.sourceArea.value,b.beginEditing(),b.set("value",d),b.endEditing());p.forEach(g,function(a){a&&a.isInstanceOf(f)&&a.set("disabled",!1)});e.set(this.sourceArea,"display","none");e.set(b.iframe,{position:"relative",visibility:"visible"});delete b._sourceQueryCommandEnabled;this.editor.onDisplayChanged()}setTimeout(c.hitch(this,
function(){var a=b.domNode.parentNode;a&&(a=C.getEnclosingWidget(a))&&a.resize&&a.resize();b.resize()}),300)}catch(l){}},updateState:function(){this.button.set("disabled",this.get("disabled"))},_resize:function(){var a=this.editor,b=a.getHeaderHeight(),g=a.getFooterHeight(),d=k.position(a.domNode),c=k.getPadBorderExtents(a.iframe.parentNode),l=k.getMarginExtents(a.iframe.parentNode),e=k.getPadBorderExtents(a.domNode),f=d.w-e.w,d=d.h-(b+e.h+g);this._fsPlugin&&this._fsPlugin.isFullscreen&&(a=w.getBox(a.ownerDocument),
f=a.w-e.w,d=a.h-(b+e.h+g));k.setMarginBox(this.sourceArea,{w:Math.round(f-(c.w+l.w)),h:Math.round(d-(c.h+l.h))})},_createSourceView:function(){var a=this.editor,b=a._plugins;this.sourceArea=r.create("textarea");this.readOnly&&(q.set(this.sourceArea,"readOnly",!0),this._readOnly=!0);e.set(this.sourceArea,{padding:"0px",margin:"0px",borderWidth:"0px",borderStyle:"none"});q.set(this.sourceArea,"aria-label",this.editor.id);r.place(this.sourceArea,a.iframe,"before");v("ie")&&a.iframe.parentNode.lastChild!==
a.iframe&&e.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,x.focus(a.editNode)):a._viewsource_oldFocus()}catch(l){}};var d,h;for(d=0;d<b.length;d++)if((h=b[d])&&("dijit._editor.plugins.FullScreen"===h.declaredClass||h.declaredClass===B._scopeName+"._editor.plugins.FullScreen")){this._fsPlugin=
h;break}this._fsPlugin&&(this._fsPlugin._viewsource_getAltViewNode=this._fsPlugin._getAltViewNode,this._fsPlugin._getAltViewNode=function(){return g._sourceShown?g.sourceArea:this._viewsource_getAltViewNode()});this.own(u(this.sourceArea,"keydown",c.hitch(this,function(b){this._sourceShown&&b.keyCode==t.F12&&b.ctrlKey&&b.shiftKey&&(this.button.focus(),this.button.set("checked",!1),setTimeout(c.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 c=
0,d=b.length;c<d;c++){var e=b[c],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},removeValueFilterHandles:function(){this._setValueFilterHandle&&(this._setValueFilterHandle.remove(),delete this._setValueFilterHandle);this._getValueFilterHandle&&
(this._getValueFilterHandle.remove(),delete this._getValueFilterHandle)},setSourceAreaCaret:function(){var a=this.sourceArea;x.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.removeValueFilterHandles();this.inherited(arguments)}});f.registry.viewSource=f.registry.viewsource=function(a){return new n({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 n});
//# sourceMappingURL=ViewSource.js.map