Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.widget.Editor2Plugin.AlwaysShowToolbar");
14
dojo.event.topic.subscribe("dojo.widget.Editor2::onLoad", function (editor) {
15
	if (editor.toolbarAlwaysVisible) {
16
		var p = new dojo.widget.Editor2Plugin.AlwaysShowToolbar(editor);
17
	}
18
});
19
dojo.declare("dojo.widget.Editor2Plugin.AlwaysShowToolbar", null, function (editor) {
20
	this.editor = editor;
21
	this.editor.registerLoadedPlugin(this);
22
	this.setup();
23
}, {_scrollSetUp:false, _fixEnabled:false, _scrollThreshold:false, _handleScroll:true, setup:function () {
24
	var tdn = this.editor.toolbarWidget;
25
	if (!tdn.tbBgIframe) {
26
		tdn.tbBgIframe = new dojo.html.BackgroundIframe(tdn.domNode);
27
		tdn.tbBgIframe.onResized();
28
	}
29
	this.scrollInterval = setInterval(dojo.lang.hitch(this, "globalOnScrollHandler"), 100);
30
	dojo.event.connect("before", this.editor.toolbarWidget, "destroy", this, "destroy");
31
}, globalOnScrollHandler:function () {
32
	var isIE = dojo.render.html.ie;
33
	if (!this._handleScroll) {
34
		return;
35
	}
36
	var dh = dojo.html;
37
	var tdn = this.editor.toolbarWidget.domNode;
38
	var db = dojo.body();
39
	if (!this._scrollSetUp) {
40
		this._scrollSetUp = true;
41
		var editorWidth = dh.getMarginBox(this.editor.domNode).width;
42
		this._scrollThreshold = dh.abs(tdn, true).y;
43
		if ((isIE) && (db) && (dh.getStyle(db, "background-image") == "none")) {
44
			with (db.style) {
45
				backgroundImage = "url(" + dojo.uri.moduleUri("dojo.widget", "templates/images/blank.gif") + ")";
46
				backgroundAttachment = "fixed";
47
			}
48
		}
49
	}
50
	var scrollPos = (window["pageYOffset"]) ? window["pageYOffset"] : (document["documentElement"] || document["body"]).scrollTop;
51
	if (scrollPos > this._scrollThreshold) {
52
		if (!this._fixEnabled) {
53
			var tdnbox = dojo.html.getMarginBox(tdn);
54
			this.editor.editorObject.style.marginTop = tdnbox.height + "px";
55
			if (isIE) {
56
				tdn.style.left = dojo.html.abs(tdn, dojo.html.boxSizing.MARGIN_BOX).x;
57
				if (tdn.previousSibling) {
58
					this._IEOriginalPos = ["after", tdn.previousSibling];
59
				} else {
60
					if (tdn.nextSibling) {
61
						this._IEOriginalPos = ["before", tdn.nextSibling];
62
					} else {
63
						this._IEOriginalPos = ["", tdn.parentNode];
64
					}
65
				}
66
				dojo.body().appendChild(tdn);
67
				dojo.html.addClass(tdn, "IEFixedToolbar");
68
			} else {
69
				with (tdn.style) {
70
					position = "fixed";
71
					top = "0px";
72
				}
73
			}
74
			tdn.style.width = tdnbox.width + "px";
75
			tdn.style.zIndex = 1000;
76
			this._fixEnabled = true;
77
		}
78
		if (!dojo.render.html.safari) {
79
			var eHeight = (this.height) ? parseInt(this.editor.height) : this.editor._lastHeight;
80
			if (scrollPos > (this._scrollThreshold + eHeight)) {
81
				tdn.style.display = "none";
82
			} else {
83
				tdn.style.display = "";
84
			}
85
		}
86
	} else {
87
		if (this._fixEnabled) {
88
			(this.editor.object || this.editor.iframe).style.marginTop = null;
89
			with (tdn.style) {
90
				position = "";
91
				top = "";
92
				zIndex = "";
93
				display = "";
94
			}
95
			if (isIE) {
96
				tdn.style.left = "";
97
				dojo.html.removeClass(tdn, "IEFixedToolbar");
98
				if (this._IEOriginalPos) {
99
					dojo.html.insertAtPosition(tdn, this._IEOriginalPos[1], this._IEOriginalPos[0]);
100
					this._IEOriginalPos = null;
101
				} else {
102
					dojo.html.insertBefore(tdn, this.editor.object || this.editor.iframe);
103
				}
104
			}
105
			tdn.style.width = "";
106
			this._fixEnabled = false;
107
		}
108
	}
109
}, destroy:function () {
110
	this._IEOriginalPos = null;
111
	this._handleScroll = false;
112
	clearInterval(this.scrollInterval);
113
	this.editor.unregisterLoadedPlugin(this);
114
	if (dojo.render.html.ie) {
115
		dojo.html.removeClass(this.editor.toolbarWidget.domNode, "IEFixedToolbar");
116
	}
117
}});
118