root / trunk / web / dojo / dijit / _editor / plugins / AlwaysShowToolbar.js
History | View | Annotate | Download (2.78 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dijit._editor.plugins.AlwaysShowToolbar"]){ |
||
9 | dojo._hasResource["dijit._editor.plugins.AlwaysShowToolbar"]=true; |
||
10 | dojo.provide("dijit._editor.plugins.AlwaysShowToolbar");
|
||
11 | dojo.declare("dijit._editor.plugins.AlwaysShowToolbar",dijit._editor._Plugin,{_handleScroll:true,setEditor:function(e){ |
||
12 | if(!e.iframe){
|
||
13 | return;
|
||
14 | } |
||
15 | this.editor=e;
|
||
16 | e.onLoadDeferred.addCallback(dojo.hitch(this,this.enable)); |
||
17 | },enable:function(d){ |
||
18 | this._updateHeight();
|
||
19 | this.connect(window,"onscroll","globalOnScrollHandler"); |
||
20 | this.connect(this.editor,"onNormalizedDisplayChanged","_updateHeight"); |
||
21 | return d;
|
||
22 | },_updateHeight:function(){ |
||
23 | var e=this.editor; |
||
24 | if(!e.isLoaded){
|
||
25 | return;
|
||
26 | } |
||
27 | if(e.height){
|
||
28 | return;
|
||
29 | } |
||
30 | var _1=dojo.marginBox(e.editNode).h;
|
||
31 | if(dojo.isOpera){
|
||
32 | _1=e.editNode.scrollHeight; |
||
33 | } |
||
34 | if(!_1){
|
||
35 | _1=dojo.marginBox(e.document.body).h; |
||
36 | } |
||
37 | if(_1==0){ |
||
38 | return;
|
||
39 | } |
||
40 | if(dojo.isIE<=7&&this.editor.minHeight){ |
||
41 | var _2=parseInt(this.editor.minHeight); |
||
42 | if(_1<_2){
|
||
43 | _1=_2; |
||
44 | } |
||
45 | } |
||
46 | if(_1!=this._lastHeight){ |
||
47 | this._lastHeight=_1;
|
||
48 | dojo.marginBox(e.iframe,{h:this._lastHeight}); |
||
49 | } |
||
50 | },_lastHeight:0,globalOnScrollHandler:function(){ |
||
51 | var _3=dojo.isIE<7; |
||
52 | if(!this._handleScroll){ |
||
53 | return;
|
||
54 | } |
||
55 | var _4=this.editor.header; |
||
56 | var db=dojo.body;
|
||
57 | if(!this._scrollSetUp){ |
||
58 | this._scrollSetUp=true; |
||
59 | this._scrollThreshold=dojo.position(_4,true).y; |
||
60 | } |
||
61 | var _5=dojo._docScroll().y;
|
||
62 | var s=_4.style;
|
||
63 | if(_5>this._scrollThreshold&&_5<this._scrollThreshold+this._lastHeight){ |
||
64 | if(!this._fixEnabled){ |
||
65 | var _6=dojo.marginBox(_4);
|
||
66 | this.editor.iframe.style.marginTop=_6.h+"px"; |
||
67 | if(_3){
|
||
68 | s.left=dojo.position(_4).x; |
||
69 | if(_4.previousSibling){
|
||
70 | this._IEOriginalPos=["after",_4.previousSibling]; |
||
71 | }else{
|
||
72 | if(_4.nextSibling){
|
||
73 | this._IEOriginalPos=["before",_4.nextSibling]; |
||
74 | }else{
|
||
75 | this._IEOriginalPos=["last",_4.parentNode]; |
||
76 | } |
||
77 | } |
||
78 | dojo.body().appendChild(_4); |
||
79 | dojo.addClass(_4,"dijitIEFixedToolbar");
|
||
80 | }else{
|
||
81 | s.position="fixed";
|
||
82 | s.top="0px";
|
||
83 | } |
||
84 | dojo.marginBox(_4,{w:_6.w});
|
||
85 | s.zIndex=2000;
|
||
86 | this._fixEnabled=true; |
||
87 | } |
||
88 | var _7=(this.height)?parseInt(this.editor.height):this.editor._lastHeight; |
||
89 | s.display=(_5>this._scrollThreshold+_7)?"none":""; |
||
90 | }else{
|
||
91 | if(this._fixEnabled){ |
||
92 | this.editor.iframe.style.marginTop=""; |
||
93 | s.position="";
|
||
94 | s.top="";
|
||
95 | s.zIndex="";
|
||
96 | s.display="";
|
||
97 | if(_3){
|
||
98 | s.left="";
|
||
99 | dojo.removeClass(_4,"dijitIEFixedToolbar");
|
||
100 | if(this._IEOriginalPos){ |
||
101 | dojo.place(_4,this._IEOriginalPos[1],this._IEOriginalPos[0]); |
||
102 | this._IEOriginalPos=null; |
||
103 | }else{
|
||
104 | dojo.place(_4,this.editor.iframe,"before"); |
||
105 | } |
||
106 | } |
||
107 | s.width="";
|
||
108 | this._fixEnabled=false; |
||
109 | } |
||
110 | } |
||
111 | },destroy:function(){ |
||
112 | this._IEOriginalPos=null; |
||
113 | this._handleScroll=false; |
||
114 | dojo.forEach(this._connects,dojo.disconnect);
|
||
115 | if(dojo.isIE<7){ |
||
116 | dojo.removeClass(this.editor.header,"dijitIEFixedToolbar"); |
||
117 | } |
||
118 | }}); |
||
119 | } |