Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | 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.Show");
14
dojo.require("dojo.widget.*");
15
dojo.require("dojo.widget.HtmlWidget");
16
dojo.require("dojo.uri.Uri");
17
dojo.require("dojo.event.*");
18
dojo.require("dojo.lfx.*");
19
dojo.require("dojo.math.curves");
20
dojo.require("dojo.lang.common");
21
dojo.require("dojo.lang.func");
22
dojo.widget.defineWidget("dojo.widget.Show", dojo.widget.HtmlWidget, function () {
23
	this._slides = [];
24
}, {isContainer:true, _slide:-1, body:null, nav:null, hider:null, select:null, option:null, inNav:false, debugPane:null, noClick:false, templateString:"<div class=\"dojoShow\">\n\t<div dojoAttachPoint=\"contentNode\"></div>\n\t<div class=\"dojoShowNav\" dojoAttachPoint=\"nav\">\n\t\t<div class=\"dojoShowHider\" dojoAttachPoint=\"hider\"></div>\n\t\t<span unselectable=\"on\" style=\"cursor: default;\" dojoAttachEvent=\"onClick:previousSlide\">&lt;</span>\n\t\t<select dojoAttachEvent=\"onClick:gotoSlideByEvent\" dojoAttachPoint=\"select\">\n\t\t\t<option dojoAttachPoint=\"option\">Title</option>\n\t\t</select>\n\t\t<span unselectable=\"on\" style=\"cursor: default;\" dojoAttachEvent=\"onClick:nextSlide\">&gt;</span>\n\t</div>\n</div>\n", templateCssString:"@media screen {\n\thtml, body {\n\t\tmargin: 0px;\n\t\tpadding: 0px;\n\t\twidth: 100%;\n\t}\n\th1 {\n\t\tfont-size: 50px;\n\t}\n\tp, li {\n\t\tfont-size: 30px;\n\t}\n\t.dojoShowNav {\n\t\tbackground: #369;\n\t\toverflow: hidden;\n\t\tposition: absolute;\n\t\theight: 5px;\n\t\tbottom: 0px;\n\t\tleft: 0px;\n\t\twidth: 100%;\n\t\ttext-align: center;\n\t}\n\t.dojoShowNav input {\n\t\tmargin: 0px;\n\t}\n\t.dojoShowHider {\n\t\theight: 5px;\n\t\toverflow: hidden;\n\t\twidth: 100%;\n\t}\n\t.dojoShowPrint {\n\t\tposition: absolute;\n\t\tleft: 5px;\n\t\ttop: 0px;\n\t}\n\t.dojoShow {\n\t\tdisplay: none;\n\t}\n}\n@media print {\n\t.dojoShow {\n\t\tdisplay: none !important;\n\t}\n\t.dojoShowPrint {\n\t\tdisplay: block !important;\n\t}\n\t.dojoShowPrintSlide {\n\t\tborder: 1px solid #aaa;\n\t\tpadding: 10px;\n\t\tmargin-bottom: 15px;\n\t}\n\t.dojoShowPrintSlide, ul {\n\tpage-break-inside: avoid;\n\t}\n\th1 {\n\t\tmargin-top: 0;\n\t\tpage-break-after: avoid;\n\t}\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/Show.css"), fillInTemplate:function (args, frag) {
25
	if (args.debugPane) {
26
		var dp = this.debugPane = dojo.widget.byId(args.debugPane);
27
		dp.hide();
28
		dojo.event.connect(dp, "closeWindow", dojo.lang.hitch(this, function () {
29
			this.debugPane = false;
30
		}));
31
	}
32
	var source = this.getFragNodeRef(frag);
33
	this.sourceNode = dojo.body().appendChild(source.cloneNode(true));
34
	for (var i = 0, child; child = this.sourceNode.childNodes[i]; i++) {
35
		if (child.tagName && child.getAttribute("dojotype").toLowerCase() == "showslide") {
36
			child.className = "dojoShowPrintSlide";
37
			child.innerHTML = "<h1>" + child.title + "</h1>" + child.innerHTML;
38
		}
39
	}
40
	this.sourceNode.className = "dojoShowPrint";
41
	this.sourceNode.style.display = "none";
42
	dojo.event.connect(document, "onclick", this, "gotoSlideByEvent");
43
	if (dojo.render.html.ie) {
44
		dojo.event.connect(document, "onkeydown", this, "gotoSlideByEvent");
45
	} else {
46
		dojo.event.connect(document, "onkeypress", this, "gotoSlideByEvent");
47
	}
48
	dojo.event.connect(window, "onresize", this, "resizeWindow");
49
	dojo.event.connect(this.nav, "onmousemove", this, "popUpNav");
50
}, postCreate:function () {
51
	this._slides = [];
52
	for (var i = 0, child; child = this.children[i]; i++) {
53
		if (child.widgetType == "ShowSlide") {
54
			this._slides.push(child);
55
			this.option.text = child.title + " (" + (i + 1) + ")";
56
			this.option.parentNode.insertBefore(this.option.cloneNode(true), this.option);
57
		}
58
	}
59
	this.option.parentNode.removeChild(this.option);
60
	this.domNode.style.display = "block";
61
	this.resizeWindow();
62
	this.gotoSlide(0, true);
63
	dojo.addOnLoad(dojo.lang.hitch(this, function () {
64
		var th = window.location.hash;
65
		if (th.length) {
66
			var parts = ("" + window.location).split(this.widgetId + "_SlideNo_");
67
			if (parts.length > 1) {
68
				setTimeout(dojo.lang.hitch(this, function () {
69
					this.gotoSlide(parseInt(parts[1]), true);
70
				}), 300);
71
			}
72
		}
73
	}));
74
}, gotoSlide:function (slide, preventSetHash) {
75
	if (slide == this._slide) {
76
		return;
77
	}
78
	if (!this._slides[slide]) {
79
		for (var i = 0, child; child = this._slides[i]; i++) {
80
			if (child.title == slide) {
81
				slide = i;
82
				break;
83
			}
84
		}
85
	}
86
	if (!this._slides[slide]) {
87
		return;
88
	}
89
	if (this.debugPane) {
90
		if (this._slides[slide].debug) {
91
			this.debugPane.show();
92
		} else {
93
			this.debugPane.hide();
94
		}
95
	}
96
	if (this._slide != -1) {
97
		while (this._slides[this._slide].previousAction()) {
98
		}
99
	}
100
	if (!preventSetHash) {
101
		window.location.href = "#" + this.widgetId + "_SlideNo_" + slide;
102
	}
103
	if (this._slides[this._slide]) {
104
		this._slides[this._slide].hide();
105
	}
106
	this._slide = slide;
107
	this.select.selectedIndex = slide;
108
	var cn = this.contentNode;
109
	while (cn.firstChild) {
110
		cn.removeChild(cn.firstChild);
111
	}
112
	cn.appendChild(this._slides[slide].domNode);
113
	this._slides[slide].show();
114
}, gotoSlideByEvent:function (event) {
115
	var node = event.target;
116
	var type = event.type;
117
	if (type == "click") {
118
		if (node.tagName == "OPTION" && node.parentNode == this.select) {
119
			this.gotoSlide(node.index);
120
		} else {
121
			if (node == this.select) {
122
				this.gotoSlide(node.selectedIndex);
123
			} else {
124
				this.nextSlide(event);
125
			}
126
		}
127
	} else {
128
		if (type == "keydown" || type == "keypress") {
129
			var key = event.keyCode;
130
			var ch = event.charCode;
131
			if (key == 63234 || key == 37) {
132
				this.previousSlide(event);
133
			} else {
134
				if (key == 63235 || key == 39 || ch == 32) {
135
					this.nextSlide(event);
136
				}
137
			}
138
		}
139
	}
140
}, nextSlide:function (event) {
141
	if (!this.stopEvent(event)) {
142
		return false;
143
	}
144
	if (!this._slides[this._slide].nextAction(event)) {
145
		if ((this._slide + 1) != this._slides.length) {
146
			this.gotoSlide(this._slide + 1);
147
			return true;
148
		}
149
		return false;
150
	}
151
}, previousSlide:function (event) {
152
	if (!this.stopEvent(event)) {
153
		return false;
154
	}
155
	if (!this._slides[this._slide].previousAction(event)) {
156
		if ((this._slide - 1) != -1) {
157
			this.gotoSlide(this._slide - 1);
158
			return true;
159
		}
160
		return false;
161
	}
162
}, stopEvent:function (ev) {
163
	if (!ev) {
164
		return true;
165
	}
166
	if (ev.type == "click" && (this._slides[this._slide].noClick || this.noClick)) {
167
		return false;
168
	}
169
	var target = ev.target;
170
	while (target != null) {
171
		if (target == this.domNode) {
172
			target = ev.target;
173
			break;
174
		}
175
		target = target.parentNode;
176
	}
177
	if (!dojo.dom.isDescendantOf(target, this.nav)) {
178
		while (target && target != this.domNode) {
179
			if (target.tagName == "A" || target.tagName == "INPUT" || target.tagName == "TEXTAREA" || target.tagName == "SELECT") {
180
				return false;
181
			}
182
			if (typeof target.onclick == "function" || typeof target.onkeypress == "function") {
183
				return false;
184
			}
185
			target = target.parentNode;
186
		}
187
	}
188
	if (window.event) {
189
		ev.returnValue = false;
190
		ev.cancelBubble = true;
191
	} else {
192
		ev.preventDefault();
193
		ev.stopPropagation();
194
	}
195
	return true;
196
}, popUpNav:function () {
197
	if (!this.inNav) {
198
		dojo.lfx.propertyAnimation(this.nav, {"height":{start:5, end:30}}, 250).play();
199
	}
200
	clearTimeout(this.inNav);
201
	this.inNav = setTimeout(dojo.lang.hitch(this, "hideNav"), 2000);
202
}, hideNav:function () {
203
	clearTimeout(this.inNav);
204
	this.inNav = false;
205
	dojo.lfx.propertyAnimation(this.nav, {"height":{start:30, end:5}}, 250).play();
206
}, resizeWindow:function (ev) {
207
	dojo.body().style.height = "auto";
208
	var h = Math.max(document.documentElement.scrollHeight || dojo.body().scrollHeight, dojo.html.getViewport().height);
209
	dojo.body().style.height = h + "px";
210
}});
211