Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | 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
 
11
dojo.provide("dojo.widget.Editor2Plugin.AlwaysShowToolbar");
12
dojo.event.topic.subscribe("dojo.widget.Editor2::onLoad", function (editor) {
13
	if (editor.toolbarAlwaysVisible) {
14
		var p = new dojo.widget.Editor2Plugin.AlwaysShowToolbar(editor);
15
	}
16
});
17
dojo.declare("dojo.widget.Editor2Plugin.AlwaysShowToolbar", null, function (editor) {
18
	this.editor = editor;
19
	this.editor.registerLoadedPlugin(this);
20
	this.setup();
21
}, {_scrollSetUp:false, _fixEnabled:false, _scrollThreshold:false, _handleScroll:true, setup:function () {
22
	var tdn = this.editor.toolbarWidget;
23
	if (!tdn.tbBgIframe) {
24
		tdn.tbBgIframe = new dojo.html.BackgroundIframe(tdn.domNode);
25
		tdn.tbBgIframe.onResized();
26
	}
27
	this.scrollInterval = setInterval(dojo.lang.hitch(this, "globalOnScrollHandler"), 100);
28
	dojo.event.connect("before", this.editor.toolbarWidget, "destroy", this, "destroy");
29
}, globalOnScrollHandler:function () {
30
	var isIE = dojo.render.html.ie;
31
	if (!this._handleScroll) {
32
		return;
33
	}
34
	var dh = dojo.html;
35
	var tdn = this.editor.toolbarWidget.domNode;
36
	var db = dojo.body();
37
	if (!this._scrollSetUp) {
38
		this._scrollSetUp = true;
39
		var editorWidth = dh.getMarginBox(this.editor.domNode).width;
40
		this._scrollThreshold = dh.abs(tdn, true).y;
41
		if ((isIE) && (db) && (dh.getStyle(db, "background-image") == "none")) {
42
			with (db.style) {
43
				backgroundImage = "url(" + dojo.uri.moduleUri("dojo.widget", "templates/images/blank.gif") + ")";
44
				backgroundAttachment = "fixed";
45
			}
46
		}
47
	}
48
	var scrollPos = (window["pageYOffset"]) ? window["pageYOffset"] : (document["documentElement"] || document["body"]).scrollTop;
49
	if (scrollPos > this._scrollThreshold) {
50
		if (!this._fixEnabled) {
51
			var tdnbox = dojo.html.getMarginBox(tdn);
52
			this.editor.editorObject.style.marginTop = tdnbox.height + "px";
53
			if (isIE) {
54
				tdn.style.left = dojo.html.abs(tdn, dojo.html.boxSizing.MARGIN_BOX).x;
55
				if (tdn.previousSibling) {
56
					this._IEOriginalPos = ["after", tdn.previousSibling];
57
				} else {
58
					if (tdn.nextSibling) {
59
						this._IEOriginalPos = ["before", tdn.nextSibling];
60
					} else {
61
						this._IEOriginalPos = ["", tdn.parentNode];
62
					}
63
				}
64
				dojo.body().appendChild(tdn);
65
				dojo.html.addClass(tdn, "IEFixedToolbar");
66
			} else {
67
				with (tdn.style) {
68
					position = "fixed";
69
					top = "0px";
70
				}
71
			}
72
			tdn.style.width = tdnbox.width + "px";
73
			tdn.style.zIndex = 1000;
74
			this._fixEnabled = true;
75
		}
76
		if (!dojo.render.html.safari) {
77
			var eHeight = (this.height) ? parseInt(this.editor.height) : this.editor._lastHeight;
78
			if (scrollPos > (this._scrollThreshold + eHeight)) {
79
				tdn.style.display = "none";
80
			} else {
81
				tdn.style.display = "";
82
			}
83
		}
84
	} else {
85
		if (this._fixEnabled) {
86
			(this.editor.object || this.editor.iframe).style.marginTop = null;
87
			with (tdn.style) {
88
				position = "";
89
				top = "";
90
				zIndex = "";
91
				display = "";
92
			}
93
			if (isIE) {
94
				tdn.style.left = "";
95
				dojo.html.removeClass(tdn, "IEFixedToolbar");
96
				if (this._IEOriginalPos) {
97
					dojo.html.insertAtPosition(tdn, this._IEOriginalPos[1], this._IEOriginalPos[0]);
98
					this._IEOriginalPos = null;
99
				} else {
100
					dojo.html.insertBefore(tdn, this.editor.object || this.editor.iframe);
101
				}
102
			}
103
			tdn.style.width = "";
104
			this._fixEnabled = false;
105
		}
106
	}
107
}, destroy:function () {
108
	this._IEOriginalPos = null;
109
	this._handleScroll = false;
110
	clearInterval(this.scrollInterval);
111
	this.editor.unregisterLoadedPlugin(this);
112
	if (dojo.render.html.ie) {
113
		dojo.html.removeClass(this.editor.toolbarWidget.domNode, "IEFixedToolbar");
114
	}
115
}});
116