]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/_editor/plugins/AlwaysShowToolbar.js.uncompressed.js
1 define("dijit/_editor/plugins/AlwaysShowToolbar", [
2 "dojo/_base/declare", // declare
3 "dojo/dom-class", // domClass.add domClass.remove
4 "dojo/dom-construct", // domConstruct.place
6 "dojo/_base/lang", // lang.hitch
7 "dojo/_base/sniff", // has("ie") has("opera")
8 "dojo/_base/window", // win.body
10 ], function(declare
, domClass
, domConstruct
, domGeometry
, lang
, has
, win
, _Plugin
){
13 var _Plugin = dijit._editor._Plugin;
17 // dijit/_editor/plugins/AlwaysShowToolbar
19 // This plugin is required for Editors in auto-expand mode.
20 // It handles the auto-expansion as the user adds/deletes text,
21 // and keeps the editor's toolbar visible even when the top of the editor
22 // has scrolled off the top of the viewport (usually when editing a long
26 return declare("dijit._editor.plugins.AlwaysShowToolbar", _Plugin
, {
28 // This plugin is required for Editors in auto-expand mode.
29 // It handles the auto-expansion as the user adds/deletes text,
30 // and keeps the editor's toolbar visible even when the top of the editor
31 // has scrolled off the top of the viewport (usually when editing a long
34 // Specify this in extraPlugins (or plugins) parameter and also set
37 // | <div data-dojo-type="dijit.Editor" height=""
38 // | data-dojo-props="extraPlugins: [dijit._editor.plugins.AlwaysShowToolbar]">
40 // _handleScroll: Boolean
41 // Enables/disables the handler for scroll events
44 setEditor: function(e
){
45 // Overrides _Plugin.setEditor().
47 console
.log('Port AlwaysShowToolbar plugin to work with Editor without iframe');
53 e
.onLoadDeferred
.addCallback(lang
.hitch(this, this.enable
));
58 // Enable plugin. Called when Editor has finished initializing.
63 this.connect(window
, 'onscroll', "globalOnScrollHandler");
64 this.connect(this.editor
, 'onNormalizedDisplayChanged', "_updateHeight");
68 _updateHeight: function(){
70 // Updates the height of the editor area to fit the contents.
72 if(!e
.isLoaded
){ return; }
73 if(e
.height
){ return; }
75 var height
= domGeometry
.getMarginSize(e
.editNode
).h
;
77 height
= e
.editNode
.scrollHeight
;
79 // console.debug('height',height);
80 // alert(this.editNode);
82 //height maybe zero in some cases even though the content is not empty,
83 //we try the height of body instead
85 height
= domGeometry
.getMarginSize(e
.document
.body
).h
;
89 console
.debug("Can not figure out the height of the editing area!");
90 return; //prevent setting height to 0
92 if(has("ie") <= 7 && this.editor
.minHeight
){
93 var min
= parseInt(this.editor
.minHeight
);
94 if(height
< min
){ height
= min
; }
96 if(height
!= this._lastHeight
){
97 this._lastHeight
= height
;
98 // this.editorObject.style.height = this._lastHeight + "px";
99 domGeometry
.setMarginBox(e
.iframe
, { h
: this._lastHeight
});
103 // _lastHeight: Integer
104 // Height in px of the editor at the last time we did sizing
107 globalOnScrollHandler: function(){
109 // Handler for scroll events that bubbled up to <html>
113 var isIE6
= has("ie") < 7;
114 if(!this._handleScroll
){ return; }
115 var tdn
= this.editor
.header
;
116 if(!this._scrollSetUp
){
117 this._scrollSetUp
= true;
118 this._scrollThreshold
= domGeometry
.position(tdn
, true).y
;
119 // var db = win.body;
120 // console.log("threshold:", this._scrollThreshold);
121 //what's this for?? comment out for now
122 // if((isIE6)&&(db)&&(domStyle.set or get TODO(db, "backgroundIimage")=="none")){
123 // db.style.backgroundImage = "url(" + dojo.uri.moduleUri("dijit", "templates/blank.gif") + ")";
124 // db.style.backgroundAttachment = "fixed";
128 var scrollPos
= domGeometry
.docScroll().y
;
131 if(scrollPos
> this._scrollThreshold
&& scrollPos
< this._scrollThreshold
+this._lastHeight
){
132 // dojo.debug(scrollPos);
133 if(!this._fixEnabled
){
134 var tdnbox
= domGeometry
.getMarginSize(tdn
);
135 this.editor
.iframe
.style
.marginTop
= tdnbox
.h
+"px";
138 s
.left
= domGeometry
.position(tdn
).x
;
139 if(tdn
.previousSibling
){
140 this._IEOriginalPos
= ['after',tdn
.previousSibling
];
141 }else if(tdn
.nextSibling
){
142 this._IEOriginalPos
= ['before',tdn
.nextSibling
];
144 this._IEOriginalPos
= ['last',tdn
.parentNode
];
146 win
.body().appendChild(tdn
);
147 domClass
.add(tdn
,'dijitIEFixedToolbar');
149 s
.position
= "fixed";
153 domGeometry
.setMarginBox(tdn
, { w
: tdnbox
.w
});
155 this._fixEnabled
= true;
157 // if we're showing the floating toolbar, make sure that if
158 // we've scrolled past the bottom of the editor that we hide
159 // the toolbar for this instance of the editor.
161 // TODO: when we get multiple editor toolbar support working
162 // correctly, ensure that we check this against the scroll
163 // position of the bottom-most editor instance.
164 var eHeight
= (this.height
) ? parseInt(this.editor
.height
) : this.editor
._lastHeight
;
165 s
.display
= (scrollPos
> this._scrollThreshold
+eHeight
) ? "none" : "";
166 }else if(this._fixEnabled
){
167 this.editor
.iframe
.style
.marginTop
= '';
174 domClass
.remove(tdn
,'dijitIEFixedToolbar');
175 if(this._IEOriginalPos
){
176 domConstruct
.place(tdn
, this._IEOriginalPos
[1], this._IEOriginalPos
[0]);
177 this._IEOriginalPos
= null;
179 domConstruct
.place(tdn
, this.editor
.iframe
, 'before');
183 this._fixEnabled
= false;
188 // Overrides _Plugin.destroy(). TODO: call this.inherited() rather than repeating code.
189 this._IEOriginalPos
= null;
190 this._handleScroll
= false;
191 this.inherited(arguments
);
194 domClass
.remove(this.editor
.header
, 'dijitIEFixedToolbar');