source: [view]
var vp = dojo.window.getBox();
//Alias this for shorter code.
var ed = this.editor;
var body = dojo.body();
var editorParent = ed.domNode.parentNode;
this.isFullscreen = full;
if(full){
//Parent classes can royally screw up this plugin, so we
//have to set eveything to position static.
while(editorParent && editorParent !== dojo.body()){
dojo.addClass(editorParent, "dijitForceStatic");
editorParent = editorParent.parentNode;
}
// Save off the resize function. We want to kill its behavior.
this._editorResizeHolder = this.editor.resize;
ed.resize = function() {} ;
// Try to constrain focus control.
ed._fullscreen_oldOnKeyDown = ed.onKeyDown;
ed.onKeyDown = dojo.hitch(this, this._containFocus);
this._origState = {};
this._origiFrameState = {};
// Store the basic editor state we have to restore later.
// Not using dojo.style here, had problems, didn't
// give me stuff like 100%, gave me pixel calculated values.
// Need the exact original values.
var domNode = ed.domNode,
domStyle = domNode && domNode.style || {};
this._origState = {
width: domStyle.width || "",
height: domStyle.height || "",
top: dojo.style(domNode, "top") || "",
left: dojo.style(domNode, "left") || "",
position: dojo.style(domNode, "position") || "static",
marginBox: dojo.marginBox(ed.domNode)
};
// Store the iframe state we have to restore later.
// Not using dojo.style here, had problems, didn't
// give me stuff like 100%, gave me pixel calculated values.
// Need the exact original values.
var iframe = ed.iframe,
iframeStyle = iframe && iframe.style || {};
var bc = dojo.style(ed.iframe, "backgroundColor");
this._origiFrameState = {
backgroundColor: bc || "transparent",
width: iframeStyle.width || "auto",
height: iframeStyle.height || "auto",
zIndex: iframeStyle.zIndex || ""
};
// Okay, size everything.
dojo.style(ed.domNode, {
position: "absolute",
top: "0px",
left: "0px",
zIndex: this.zIndex,
width: vp.w + "px",
height: vp.h + "px"
});
dojo.style(ed.iframe, {
height: "100%",
width: "100%",
zIndex: this.zIndex,
backgroundColor: bc !== "transparent" &&
bc !== "rgba(0, 0, 0, 0)"?bc:"white"
});
dojo.style(ed.iframe.parentNode, {
height: "95%",
width: "100%"
});
// Store the overflow state we have to restore later.
// IE had issues, so have to check that it's defined. Ugh.
if(body.style && body.style.overflow){
this._oldOverflow = dojo.style(body, "overflow");
}else{
this._oldOverflow = "";
}
if(dojo.isIE && !dojo.isQuirks){
// IE will put scrollbars in anyway, html (parent of body)
// also controls them in standards mode, so we have to
// remove them, argh.
if(body.parentNode &&
body.parentNode.style &&
body.parentNode.style.overflow){
this._oldBodyParentOverflow = body.parentNode.style.overflow;
}else{
try{
this._oldBodyParentOverflow = dojo.style(body.parentNode, "overflow");
}catch(e){
this._oldBodyParentOverflow = "scroll";
}
}
dojo.style(body.parentNode, "overflow", "hidden");
}
dojo.style(body, "overflow", "hidden");
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;
}
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._resizeEditor();
}), 10);
};
this._resizeHandle = dojo.connect(window, "onresize", this, resizer);
// Also monitor for direct calls to resize and adapt editor.
this._resizeHandle2 = dojo.connect(ed, "resize", dojo.hitch(this, function(){
if(this._resizer){
clearTimeout(this._resizer);
delete this._resizer;
}
this._resizer = setTimeout(dojo.hitch(this, function(){
delete this._resizer;
this._resizeEditor();
}), 10);
}));
// Call it once to work around IE glitchiness. Safe for other browsers too.
this._resizeEditor();
var dn = this.editor.toolbar.domNode;
setTimeout(function(){dojo.window.scrollIntoView(dn);}, 250);
}else{
if(this._resizeHandle){
// Cleanup resizing listeners
dojo.disconnect(this._resizeHandle);
this._resizeHandle = null;
}
if(this._resizeHandle2){
// Cleanup resizing listeners
dojo.disconnect(this._resizeHandle2);
this._resizeHandle2 = null;
}
if(this._rst){
clearTimeout(this._rst);
this._rst = null;
}
//Remove all position static class assigns.
while(editorParent && editorParent !== dojo.body()){
dojo.removeClass(editorParent, "dijitForceStatic");
editorParent = editorParent.parentNode;
}
// Restore resize function
if(this._editorResizeHolder){
this.editor.resize = this._editorResizeHolder;
}
if(!this._origState && !this._origiFrameState){
// If we actually didn't toggle, then don't do anything.
return;
}
if(ed._fullscreen_oldOnKeyDown){
ed.onKeyDown = ed._fullscreen_oldOnKeyDown;
delete ed._fullscreen_oldOnKeyDown;
}
// Add a timeout to make sure we don't have a resize firing in the
// background at the time of minimize.
var self = this;
setTimeout(function(){
// Restore all the editor state.
var mb = self._origState.marginBox;
var oh = self._origState.height;
if(dojo.isIE && !dojo.isQuirks){
body.parentNode.style.overflow = self._oldBodyParentOverflow;
delete self._oldBodyParentOverflow;
}
dojo.style(body, "overflow", self._oldOverflow);
delete self._oldOverflow;
dojo.style(ed.domNode, self._origState);
dojo.style(ed.iframe.parentNode, {
height: "",
width: ""
});
dojo.style(ed.iframe, self._origiFrameState);
delete self._origState;
delete self._origiFrameState;
// In case it is contained in a layout and the layout changed size,
// go ahead and call resize.
var pWidget = dijit.getEnclosingWidget(ed.domNode.parentNode);
if(pWidget && pWidget.resize){
pWidget.resize();
}else{
if(!oh || oh.indexOf("%") < 0){
// Resize if the original size wasn't set
// or wasn't in percent. Timeout is to avoid
// an IE crash in unit testing.
setTimeout(dojo.hitch(this, function(){ed.resize({h: mb.h});}), 0);
}
}
dojo.window.scrollIntoView(self.editor.toolbar.domNode);
}, 100);
}