Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 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", null,
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._connects=[dojo.connect(window,'onscroll',this,"globalOnScrollHandler"),
17
		dojo.connect(this.editor,'onNormalizedDisplayChanged',this,"_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
 
72
		if(scrollPos > this._scrollThreshold && scrollPos < this._scrollThreshold+this._lastHeight){
73
			// dojo.debug(scrollPos);
74
			if(!this._fixEnabled){
75
				var tdnbox = dojo.marginBox(tdn);
76
				this.editor.iframe.style.marginTop = tdnbox.h+"px";
77
 
78
				if(isIE){
79
					tdn.style.left = dojo._abs(tdn).x;
80
					if(tdn.previousSibling){
81
						this._IEOriginalPos = ['after',tdn.previousSibling];
82
					}else if(tdn.nextSibling){
83
						this._IEOriginalPos = ['before',tdn.nextSibling];
84
					}else{
85
						this._IEOriginalPos = ['last',tdn.parentNode];
86
					}
87
					dojo.body().appendChild(tdn);
88
					dojo.addClass(tdn,'IEFixedToolbar');
89
				}else{
90
					with(tdn.style){
91
						position = "fixed";
92
						top = "0px";
93
					}
94
				}
95
 
96
				dojo.marginBox(tdn, { w: tdnbox.w });
97
				tdn.style.zIndex = 2000;
98
				this._fixEnabled = true;
99
			}
100
			// if we're showing the floating toolbar, make sure that if
101
			// we've scrolled past the bottom of the editor that we hide
102
			// the toolbar for this instance of the editor.
103
 
104
			// TODO: when we get multiple editor toolbar support working
105
			// correctly, ensure that we check this against the scroll
106
			// position of the bottom-most editor instance.
107
			var eHeight = (this.height) ? parseInt(this.editor.height) : this.editor._lastHeight;
108
			if(scrollPos > (this._scrollThreshold+eHeight)){
109
				tdn.style.display = "none";
110
			}else{
111
				tdn.style.display = "";
112
			}
113
		}else if(this._fixEnabled){
114
			this.editor.iframe.style.marginTop = '';
115
			with(tdn.style){
116
				position = "";
117
				top = "";
118
				zIndex = "";
119
				display = "";
120
			}
121
			if(isIE){
122
				tdn.style.left = "";
123
				dojo.removeClass(tdn,'IEFixedToolbar');
124
				if(this._IEOriginalPos){
125
					dojo.place(tdn, this._IEOriginalPos[1], this._IEOriginalPos[0]);
126
					this._IEOriginalPos = null;
127
				}else{
128
					dojo.place(tdn, this.editor.iframe,'before');
129
				}
130
			}
131
			tdn.style.width = "";
132
			this._fixEnabled = false;
133
		}
134
	},
135
	destroy: function(){
136
		this._IEOriginalPos = null;
137
		this._handleScroll = false;
138
		dojo.forEach(this._connects,dojo.disconnect);
139
//		clearInterval(this.scrollInterval);
140
 
141
		if(dojo.isIE && dojo.isIE<7){
142
			dojo.removeClass(this.editor.toolbar.domNode,'IEFixedToolbar');
143
		}
144
	}
145
});
146
 
147
}