]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dijit/_editor/plugins/AlwaysShowToolbar.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dijit / _editor / plugins / AlwaysShowToolbar.js
1 if(!dojo._hasResource["dijit._editor.plugins.AlwaysShowToolbar"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dijit._editor.plugins.AlwaysShowToolbar"] = true;
3 dojo.provide("dijit._editor.plugins.AlwaysShowToolbar");
4
5 dojo.declare("dijit._editor.plugins.AlwaysShowToolbar", dijit._editor._Plugin,
6         {
7         _handleScroll: true,
8         setEditor: function(e){
9                 this.editor = e;
10 //              setTimeout(dojo.hitch(this,this.enable), 10000);
11                 e.onLoadDeferred.addCallback(dojo.hitch(this, this.enable));
12 //              this.scrollInterval = setInterval(dojo.hitch(this, "globalOnScrollHandler"), 100);
13         },
14         enable: function(d){
15                 this._updateHeight();
16                 this.connect(window, 'onscroll', "globalOnScrollHandler");
17                 this.connect(this.editor, 'onNormalizedDisplayChanged', "_updateHeight");
18                 return d;
19         },
20         _updateHeight: function(){
21                 // summary:
22                 //              Updates the height of the editor area to fit the contents.
23                 var e = this.editor;
24                 if(!e.isLoaded){ return; }
25                 if(e.height){ return; }
26
27                 var height = dojo.marginBox(e.editNode).h;
28                 if(dojo.isOpera){
29                         height = e.editNode.scrollHeight;
30                 }
31                 // console.debug('height',height);
32                 // alert(this.editNode);
33
34                 //height maybe zero in some cases even though the content is not empty,
35                 //we try the height of body instead
36                 if(!height){
37                         height = dojo.marginBox(e.document.body).h;
38                 }
39
40                 if(height == 0){
41                         console.debug("Can not figure out the height of the editing area!");
42                         return; //prevent setting height to 0
43                 }
44                 if(height != this._lastHeight){
45                         this._lastHeight = height;
46                         // this.editorObject.style.height = this._lastHeight + "px";
47                         dojo.marginBox(e.iframe, { h: this._lastHeight });
48 //                      this.iframe.height=this._lastHeight+10+'px';
49 //                      this.iframe.style.height=this._lastHeight+'px';
50                 }
51         },
52         _lastHeight: 0,
53         globalOnScrollHandler: function(){
54                 var isIE = dojo.isIE && dojo.isIE<7;
55                 if(!this._handleScroll){ return; }
56                 var tdn = this.editor.toolbar.domNode;
57                 var db = dojo.body;
58
59                 if(!this._scrollSetUp){
60                         this._scrollSetUp = true;
61                         this._scrollThreshold = dojo._abs(tdn, true).y;
62 //                      console.log("threshold:", this._scrollThreshold);
63                         //what's this for?? comment out for now
64 //                      if((isIE)&&(db)&&(dojo.style(db, "backgroundIimage")=="none")){
65 //                              db.style.backgroundImage = "url(" + dojo.uri.moduleUri("dijit", "templates/blank.gif") + ")";
66 //                              db.style.backgroundAttachment = "fixed";
67 //                      }
68                 }
69
70                 var scrollPos = dojo._docScroll().y;
71                 var s = tdn.style;
72
73                 if(scrollPos > this._scrollThreshold && scrollPos < this._scrollThreshold+this._lastHeight){
74                         // dojo.debug(scrollPos);
75                         if(!this._fixEnabled){
76                                 var tdnbox = dojo.marginBox(tdn);
77                                 this.editor.iframe.style.marginTop = tdnbox.h+"px";
78
79                                 if(isIE){
80                                         s.left = dojo._abs(tdn).x;
81                                         if(tdn.previousSibling){
82                                                 this._IEOriginalPos = ['after',tdn.previousSibling];
83                                         }else if(tdn.nextSibling){
84                                                 this._IEOriginalPos = ['before',tdn.nextSibling];
85                                         }else{
86                                                 this._IEOriginalPos = ['last',tdn.parentNode];
87                                         }
88                                         dojo.body().appendChild(tdn);
89                                         dojo.addClass(tdn,'dijitIEFixedToolbar');
90                                 }else{
91                                         s.position = "fixed";
92                                         s.top = "0px";
93                                 }
94
95                                 dojo.marginBox(tdn, { w: tdnbox.w });
96                                 s.zIndex = 2000;
97                                 this._fixEnabled = true;
98                         }
99                         // if we're showing the floating toolbar, make sure that if
100                         // we've scrolled past the bottom of the editor that we hide
101                         // the toolbar for this instance of the editor.
102
103                         // TODO: when we get multiple editor toolbar support working
104                         // correctly, ensure that we check this against the scroll
105                         // position of the bottom-most editor instance.
106                         var eHeight = (this.height) ? parseInt(this.editor.height) : this.editor._lastHeight;
107                         s.display = (scrollPos > this._scrollThreshold+eHeight) ? "none" : "";
108                 }else if(this._fixEnabled){
109                         this.editor.iframe.style.marginTop = '';
110                         s.position = "";
111                         s.top = "";
112                         s.zIndex = "";
113                         s.display = "";
114                         if(isIE){
115                                 s.left = "";
116                                 dojo.removeClass(tdn,'dijitIEFixedToolbar');
117                                 if(this._IEOriginalPos){
118                                         dojo.place(tdn, this._IEOriginalPos[1], this._IEOriginalPos[0]);
119                                         this._IEOriginalPos = null;
120                                 }else{
121                                         dojo.place(tdn, this.editor.iframe, 'before');
122                                 }
123                         }
124                         s.width = "";
125                         this._fixEnabled = false;
126                 }
127         },
128         destroy: function(){
129                 this._IEOriginalPos = null;
130                 this._handleScroll = false;
131                 dojo.forEach(this._connects, dojo.disconnect);
132 //              clearInterval(this.scrollInterval);
133
134                 if(dojo.isIE && dojo.isIE<7){
135                         dojo.removeClass(this.editor.toolbar.domNode, 'dijitIEFixedToolbar');
136                 }
137         }
138 });
139
140 }