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