| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/dom-class", |
| 4 |
"dojo/dom-construct", |
| 5 |
"dojo/dom-geometry", |
| 6 |
"dojo/_base/lang", |
| 7 |
"dojo/on", |
| 8 |
"dojo/sniff", |
| 9 |
"dojo/_base/window", |
| 10 |
"../_Plugin" |
| 11 |
], function(declare, domClass, domConstruct, domGeometry, lang, on, has, win, _Plugin){ |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
return declare("dijit._editor.plugins.AlwaysShowToolbar", _Plugin, { |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
_handleScroll: true, |
| 36 |
|
| 37 |
setEditor: function(e){ |
| 38 |
|
| 39 |
if(!e.iframe){ |
| 40 |
console.log('Port AlwaysShowToolbar plugin to work with Editor without iframe'); |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
this.editor = e; |
| 45 |
|
| 46 |
e.onLoadDeferred.then(lang.hitch(this, this.enable)); |
| 47 |
}, |
| 48 |
|
| 49 |
enable: function(d){ |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
this._updateHeight(); |
| 56 |
this.own( |
| 57 |
on(window, 'scroll', lang.hitch(this, "globalOnScrollHandler")), |
| 58 |
this.editor.on('NormalizedDisplayChanged', lang.hitch(this, "_updateHeight")) |
| 59 |
); |
| 60 |
return d; |
| 61 |
}, |
| 62 |
|
| 63 |
_updateHeight: function(){ |
| 64 |
|
| 65 |
|
| 66 |
var e = this.editor; |
| 67 |
if(!e.isLoaded){ |
| 68 |
return; |
| 69 |
} |
| 70 |
if(e.height){ |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
var height = domGeometry.getMarginSize(e.editNode).h; |
| 75 |
if(has("opera")){ |
| 76 |
height = e.editNode.scrollHeight; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
if(!height){ |
| 84 |
height = domGeometry.getMarginSize(e.document.body).h; |
| 85 |
} |
| 86 |
|
| 87 |
if(this._fixEnabled){ |
| 88 |
|
| 89 |
|
| 90 |
height += domGeometry.getMarginSize(this.editor.header).h; |
| 91 |
} |
| 92 |
|
| 93 |
if(height == 0){ |
| 94 |
console.debug("Can not figure out the height of the editing area!"); |
| 95 |
return; |
| 96 |
} |
| 97 |
if(has("ie") <= 7 && this.editor.minHeight){ |
| 98 |
var min = parseInt(this.editor.minHeight); |
| 99 |
if(height < min){ |
| 100 |
height = min; |
| 101 |
} |
| 102 |
} |
| 103 |
if(height != this._lastHeight){ |
| 104 |
this._lastHeight = height; |
| 105 |
|
| 106 |
domGeometry.setMarginBox(e.iframe, { h: this._lastHeight }); |
| 107 |
} |
| 108 |
}, |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
_lastHeight: 0, |
| 113 |
|
| 114 |
globalOnScrollHandler: function(){ |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
var isIE6 = has("ie") < 7; |
| 121 |
if(!this._handleScroll){ |
| 122 |
return; |
| 123 |
} |
| 124 |
var tdn = this.editor.header; |
| 125 |
if(!this._scrollSetUp){ |
| 126 |
this._scrollSetUp = true; |
| 127 |
this._scrollThreshold = domGeometry.position(tdn, true).y; |
| 128 |
} |
| 129 |
|
| 130 |
var scrollPos = domGeometry.docScroll(this.editor.ownerDocument).y; |
| 131 |
var s = tdn.style; |
| 132 |
|
| 133 |
if(scrollPos > this._scrollThreshold && scrollPos < this._scrollThreshold + this._lastHeight){ |
| 134 |
|
| 135 |
if(!this._fixEnabled){ |
| 136 |
var tdnbox = domGeometry.getMarginSize(tdn); |
| 137 |
this.editor.iframe.style.marginTop = tdnbox.h + "px"; |
| 138 |
|
| 139 |
if(isIE6){ |
| 140 |
s.left = domGeometry.position(tdn).x; |
| 141 |
if(tdn.previousSibling){ |
| 142 |
this._IEOriginalPos = ['after', tdn.previousSibling]; |
| 143 |
}else if(tdn.nextSibling){ |
| 144 |
this._IEOriginalPos = ['before', tdn.nextSibling]; |
| 145 |
}else{ |
| 146 |
this._IEOriginalPos = ['last', tdn.parentNode]; |
| 147 |
} |
| 148 |
this.editor.ownerDocumentBody.appendChild(tdn); |
| 149 |
domClass.add(tdn, 'dijitIEFixedToolbar'); |
| 150 |
}else{ |
| 151 |
s.position = "fixed"; |
| 152 |
s.top = "0px"; |
| 153 |
} |
| 154 |
|
| 155 |
domGeometry.setMarginBox(tdn, { w: tdnbox.w }); |
| 156 |
s.zIndex = 2000; |
| 157 |
this._fixEnabled = true; |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
var eHeight = (this.height) ? parseInt(this.editor.height) : this.editor._lastHeight; |
| 167 |
s.display = (scrollPos > this._scrollThreshold + eHeight) ? "none" : ""; |
| 168 |
}else if(this._fixEnabled){ |
| 169 |
this.editor.iframe.style.marginTop = ''; |
| 170 |
s.position = ""; |
| 171 |
s.top = ""; |
| 172 |
s.zIndex = ""; |
| 173 |
s.display = ""; |
| 174 |
if(isIE6){ |
| 175 |
s.left = ""; |
| 176 |
domClass.remove(tdn, 'dijitIEFixedToolbar'); |
| 177 |
if(this._IEOriginalPos){ |
| 178 |
domConstruct.place(tdn, this._IEOriginalPos[1], this._IEOriginalPos[0]); |
| 179 |
this._IEOriginalPos = null; |
| 180 |
}else{ |
| 181 |
domConstruct.place(tdn, this.editor.iframe, 'before'); |
| 182 |
} |
| 183 |
} |
| 184 |
s.width = ""; |
| 185 |
this._fixEnabled = false; |
| 186 |
} |
| 187 |
}, |
| 188 |
|
| 189 |
destroy: function(){ |
| 190 |
|
| 191 |
this._IEOriginalPos = null; |
| 192 |
this._handleScroll = false; |
| 193 |
this.inherited(arguments); |
| 194 |
|
| 195 |
if(has("ie") < 7){ |
| 196 |
domClass.remove(this.editor.header, 'dijitIEFixedToolbar'); |
| 197 |
} |
| 198 |
} |
| 199 |
}); |
| 200 |
|
| 201 |
}); |