source: [view]
var ed = this.editor;
var edPlugins = ed._plugins;
var html;
this._sourceShown = source;
var self = this;
try{
if(!this.sourceArea){
this._createSourceView();
}
if(source){
// Update the QueryCommandEnabled function to disable everything but
// the source view mode. Have to over-ride a function, then kick all
// plugins to check their state.
ed._sourceQueryCommandEnabled = ed.queryCommandEnabled;
ed.queryCommandEnabled = function(cmd){
var lcmd = cmd.toLowerCase();
if(lcmd === "viewsource"){
return true;
}else{
return false;
}
};
this.editor.onDisplayChanged();
html = ed.get("value");
html = this._filter(html);
ed.set("value", html);
this._pluginList = [];
dojo.forEach(edPlugins, function(p){
// Turn off any plugins not controlled by queryCommandenabled.
if(!(p instanceof dijit._editor.plugins.ViewSource)){
p.set("disabled", true)
}
});
// We actually do need to trap this plugin and adjust how we
// display the textarea.
if(this._fsPlugin){
this._fsPlugin._getAltViewNode = function(){
return self.sourceArea;
};
}
this.sourceArea.value = html;
var is = dojo._getMarginSize(ed.iframe.parentNode);
dojo.marginBox(this.sourceArea, {
w: is.w,
h: is.h
});
dojo.style(ed.iframe, "display", "none");
dojo.style(this.sourceArea, {
display: "block"
});
var resizer = function(){
// function to handle resize events.
// Will check current VP and only resize if
// different.
var vp = dojo.window.getBox();
if("_prevW" in this && "_prevH" in this){
// No actual size change, ignore.
if(vp.w === this._prevW && vp.h === this._prevH){
return;
}else{
this._prevW = vp.w;
this._prevH = vp.h;
}
}else{
this._prevW = vp.w;
this._prevH = vp.h;
}
if(this._resizer){
clearTimeout(this._resizer);
delete this._resizer;
}
// Timeout it to help avoid spamming resize on IE.
// Works for all browsers.
this._resizer = setTimeout(dojo.hitch(this, function(){
delete this._resizer;
this._resize();
}), 10);
};
this._resizeHandle = dojo.connect(window, "onresize", this, resizer);
//Call this on a delay once to deal with IE glitchiness on initial size.
setTimeout(dojo.hitch(this, this._resize), 100);
//Trigger a check for command enablement/disablement.
this.editor.onNormalizedDisplayChanged();
this.editor.__oldGetValue = this.editor.getValue;
this.editor.getValue = dojo.hitch(this, function() {
var txt = this.sourceArea.value;
txt = this._filter(txt);
return txt;
});
}else{
// First check that we were in source view before doing anything.
// corner case for being called with a value of false and we hadn't
// actually been in source display mode.
if(!ed._sourceQueryCommandEnabled){
return;
}
dojo.disconnect(this._resizeHandle);
delete this._resizeHandle;
if(this.editor.__oldGetValue){
this.editor.getValue = this.editor.__oldGetValue;
delete this.editor.__oldGetValue;
}
// Restore all the plugin buttons state.
ed.queryCommandEnabled = ed._sourceQueryCommandEnabled;
if(!this._readOnly){
html = this.sourceArea.value;
html = this._filter(html);
ed.beginEditing();
ed.set("value", html);
ed.endEditing();
}
dojo.forEach(edPlugins, function(p){
// Turn back on any plugins we turned off.
p.set("disabled", false);
});
dojo.style(this.sourceArea, "display", "none");
dojo.style(ed.iframe, "display", "block");
delete ed._sourceQueryCommandEnabled;
//Trigger a check for command enablement/disablement.
this.editor.onDisplayChanged();
}
// Call a delayed resize to wait for some things to display in header/footer.
setTimeout(dojo.hitch(this, function(){
// Make resize calls.
var parent = ed.domNode.parentNode;
if(parent){
var container = dijit.getEnclosingWidget(parent);
if(container && container.resize){
container.resize();
}
}
ed.resize();
}), 300);
}catch(e){
console.log(e);
}