2 init : function(option){
6 this.canvas = document.getElementById('canvas');
7 this.content = document.getElementById('content');
8 this.textbox = document.getElementById('textField');
9 this.deck = document.getElementById('deck');
10 this.scroller = document.getElementById('scroller');
12 this.toolbar = document.getElementById('canvasToolbar');
13 this.toolbarHeight = this.toolbar.boxObject.height;
14 this.isToolbarHidden = true;
15 this.toolbar.setAttribute('style', 'margin-top:'+(0-this.toolbarHeight)+'px;margin-bottom:0px;');
18 for(var i in option){this[i] = option[i]}
21 if (this.readParameter()) {
25 document.documentElement.focus();
28 takahashi : function(){
30 document.title = this.data[0].replace(/[\r\n]/g, ' ');
32 if(!this.data[this.offset]){
33 this.offset = this.data.length-1;
35 document.getElementById("current_page").value = this.offset+1;
36 document.getElementById("max_page").value = this.data.length;
38 this.scroller.setAttribute('maxpos', this.data.length-1);
39 this.scroller.setAttribute('curpos', this.offset);
41 var broadcaster = document.getElementById('canBack');
43 broadcaster.setAttribute('disabled', true);
45 broadcaster.removeAttribute('disabled');
47 var broadcaster = document.getElementById('canForward');
48 if (this.offset == this.data.length-1)
49 broadcaster.setAttribute('disabled', true);
51 broadcaster.removeAttribute('disabled');
53 this.canvas.setAttribute('rendering', true);
55 var text = this.data[this.offset].
56 replace(/^[\r\n]+/g,"").replace(/[\r\n]+$/g,"").replace(/(\r\n|[\r\n])/g,"\n")
58 var range = document.createRange();
59 range.selectNodeContents(this.content);
60 range.deleteContents();
67 var image_total_width = 0;
69 var image_total_height = 0;
76 for (var i = 0; i < text.length; i++)
78 this.content.appendChild(document.createElement('hbox'));
79 this.content.lastChild.setAttribute('align', 'center');
80 this.content.lastChild.setAttribute('pack', 'center');
86 if (line.match(/^ /)) {
88 this.content.lastChild.setAttribute('align', 'left');
89 this.content.lastChild.setAttribute('class', 'pre');
90 line = line.substring(1)
93 while (line.match(/^([^\{]+)?(\{\{ima?ge? +src="([^"]+)" +width="([0-9]+)" +height="([0-9]+)"[^\}]*\}\}|\{\{(([^\|]+)?\||)([^\}]+)\}\})(.+)?/))
96 this.content.lastChild.appendChild(document.createElement('description'));
97 this.content.lastChild.lastChild.setAttribute('value', RegExp.$1);
99 newLine = line.substring((RegExp.$1+RegExp.$2).length);
102 if (/^([^\{]+)?\{\{ima?ge? +src="([^"]+)" +width="([0-9]+)" +height="([0-9]+)"[^\}]*\}\}/.test(line)) {
103 this.content.lastChild.appendChild(document.createElement('image'));
104 image_src = RegExp.$2;
105 if (image_src.indexOf('http://') < 0 &&
106 image_src.indexOf('https://') < 0)
107 image_src = this.dataFolder+image_src;
108 this.content.lastChild.lastChild.setAttribute('src', image_src);
109 this.content.lastChild.lastChild.setAttribute('width', parseInt(RegExp.$3 || '0'));
110 this.content.lastChild.lastChild.setAttribute('height', parseInt(RegExp.$4 || '0'));
111 image_width += parseInt(RegExp.$3 || '0');
112 image_height = Math.max(image_height, parseInt(RegExp.$4 || '0'));
116 // else if (/^([^\{]+)?\{\{#([^\|]+)\|([^\}]+)\}\}/.test(line)) {
117 else if (/^([^\{]+)?\{\{(#([^\|]+)?\|)([^\}]+)\}\}/.test(line)) {
119 this.content.lastChild.appendChild(document.createElement('description'));
120 this.content.lastChild.lastChild.setAttribute('value', uri);
121 this.content.lastChild.lastChild.setAttribute('class', RegExp.$3);
125 else if (/^([^\{]+)?\{\{(([^\|]+)?\||)([^\}]+)\}\}/.test(line)) {
127 if (uri.indexOf('://') < 0)
128 uri = this.dataFolder+uri;
129 this.content.lastChild.appendChild(document.createElement('description'));
130 this.content.lastChild.lastChild.setAttribute('value', RegExp.$3 || RegExp.$4);
131 this.content.lastChild.lastChild.setAttribute('href', uri);
132 this.content.lastChild.lastChild.setAttribute('tooltiptext', uri);
133 this.content.lastChild.lastChild.setAttribute('statustext', uri);
134 this.content.lastChild.lastChild.setAttribute('class', 'link-text');
141 this.content.lastChild.appendChild(document.createElement('description'));
142 this.content.lastChild.lastChild.setAttribute('value', line);
145 image_total_width = Math.max(image_total_width, image_width);
146 image_total_height += image_height;
149 this.content.setAttribute('style', 'font-size:10px;');
151 if (this.content.boxObject.width) {
152 var canvas_w = this.canvas.boxObject.width;
153 var canvas_h = this.canvas.boxObject.height-image_total_height;
155 var content_w = this.content.boxObject.width;
156 var new_fs = Math.round((canvas_w/content_w) * this.size);
158 new_fs = new_fs - (new_fs % 32);
159 if (code_listing) { new_fs = 48;}
161 this.content.setAttribute('style', 'top: 0');
162 this.content.setAttribute('style', 'font-size:'+ new_fs + "px");
164 if (this.content.boxObject.width < image_total_width) {
165 content_w = image_total_width;
166 new_fs = Math.round((canvas_w/content_w) * this.size);
167 this.content.setAttribute('style', 'font-size:'+ new_fs + "px");
170 var content_h = this.content.boxObject.height;
171 if(content_h >= canvas_h){
172 content_h = this.content.boxObject.height;
173 new_fs = Math.round((canvas_h/content_h) * new_fs);
174 this.content.setAttribute('style', 'font-size:'+ new_fs + "px");
180 this.canvas.removeAttribute('rendering');
183 reload : function() {
184 if (this.dataPath != location.href) {
185 var path = this.dataPath;
186 if (location.href.match(/^https?:/)) {
187 var request = new XMLHttpRequest();
188 request.open('GET', path);
189 request.onload = function() {
190 Presentation.textbox.value = request.responseText;
191 Presentation.data = Presentation.textbox.value.split('----');
193 Presentation.takahashi();
201 document.getElementById('dataLoader').setAttribute('src', 'about:blank');
202 window.setTimeout(function() {
203 document.getElementById('dataLoader').setAttribute('src', path);
209 window.location.reload();
212 forward : function(){
218 if(this.offset < 0){this.offset = 0}
226 this.offset = this.data.length-1;
229 showPage : function(aPageOffset){
230 this.offset = aPageOffset ? aPageOffset : 0 ;
234 addPage : function() {
235 if (this.textbox.value &&
236 !this.textbox.value.match(/(\r\n|[\r\n])$/))
237 this.textbox.value += '\n';
238 this.textbox.value += '----\n';
242 toggleEditMode : function(){
243 this.deck.selectedIndex = (this.deck.selectedIndex == 0) ? 1 : 0 ;
245 toggleEvaMode : function(){
246 var check = document.getElementById('toggleEva');
247 if (this.canvas.getAttribute('eva') == 'true') {
248 this.canvas.removeAttribute('eva');
249 check.checked = false;
252 this.canvas.setAttribute('eva', true);
253 check.checked = true;
257 onPresentationClick : function(aEvent){
258 if (!this.isToolbarHidden)
259 this.showHideToolbar();
261 switch(aEvent.button)
264 var uri = aEvent.target.getAttribute('href');
269 document.documentElement.focus();
274 document.documentElement.focus();
280 onScrollerDragStart : function(){
281 this.scroller.dragging = true;
283 onScrollerDragMove : function(){
284 if (this.scroller.dragging)
285 this.showPage(parseInt(this.scroller.getAttribute('curpos')));
287 onScrollerDragDrop : function(){
288 if (this.scroller.dragging) {
289 this.showPage(parseInt(this.scroller.getAttribute('curpos')));
291 this.scroller.dragging = false;
293 onEdit : function() {
294 this.data = this.textbox.value.split('----');
298 onKeyPress : function(aEvent) {
299 switch(aEvent.keyCode)
301 case aEvent.DOM_VK_BACK_SPACE:
302 if (this.isPresentationMode) {
303 aEvent.preventBubble();
304 aEvent.preventDefault();
314 onToolbarArea : false,
318 isToolbarHidden : false,
319 onMouseMoveOnCanvas : function(aEvent) {
320 if (this.scroller.dragging) return;
322 this.onToolbarArea = (aEvent.clientY < this.toolbarHeight);
324 if (this.isToolbarHidden == this.onToolbarArea) {
325 if (this.toolbarTimer) window.clearTimeout(this.toolbarTimer);
326 this.toolbarTimer = window.setTimeout('Presentation.onMouseMoveOnCanvasCallback()', this.toolbarDelay);
329 onMouseMoveOnCanvasCallback : function() {
330 if (this.isToolbarHidden == this.onToolbarArea)
331 this.showHideToolbar();
334 toolbarAnimationDelay : 100,
335 toolbarAnimationSteps : 5,
336 toolbarAnimationInfo : null,
337 toolbarAnimationTimer : null,
338 showHideToolbar : function()
340 if (this.toolbarAnimationTimer) window.clearTimeout(this.toolbarAnimationTimer);
342 this.toolbarAnimationInfo = { count : 0 };
343 if (this.isToolbarHidden) {
344 this.toolbarAnimationInfo.start = 0;
345 this.toolbarAnimationInfo.end = this.toolbarHeight;
348 this.toolbarAnimationInfo.start = this.toolbarHeight;
349 this.toolbarAnimationInfo.end = 0;
351 this.toolbarAnimationInfo.current = 0;
353 this.toolbar.setAttribute('style', 'margin-top:'+(0-(this.toolbarHeight-this.toolbarAnimationInfo.start))+'px; margin-bottom:'+(0-this.toolbarAnimationInfo.start)+'px;');
355 this.toolbarAnimationTimer = window.setTimeout('Presentation.animateToolbar()', this.toolbarAnimationDelay/this.toolbarAnimationSteps);
357 animateToolbar : function()
359 this.toolbarAnimationInfo.current += parseInt(this.toolbarHeight/this.toolbarAnimationSteps);
362 if (this.toolbarAnimationInfo.start < this.toolbarAnimationInfo.end) {
363 top = this.toolbarHeight-this.toolbarAnimationInfo.current;
364 bottom = this.toolbarAnimationInfo.current;
367 top = this.toolbarAnimationInfo.current;
368 bottom = this.toolbarHeight-this.toolbarAnimationInfo.current;
371 top = Math.min(Math.max(top, 0), this.toolbarHeight);
372 bottom = Math.min(Math.max(bottom, 0), this.toolbarHeight);
374 this.toolbar.setAttribute('style', 'margin-top:'+(0-top)+'px; margin-bottom:'+(0-bottom)+'px');
376 if (this.toolbarAnimationInfo.count < this.toolbarAnimationSteps) {
377 this.toolbarAnimationInfo.count++;
378 this.toolbarAnimationTimer = window.setTimeout('Presentation.animateToolbar()', this.toolbarAnimationDelay/this.toolbarAnimationSteps);
381 this.isToolbarHidden = !this.isToolbarHidden;
390 this._offset = parseInt(aValue || 0);
391 document.documentElement.setAttribute('lastoffset', this.offset);
397 // Make sure you break the text into parts smaller than 4096
398 // characters, and name them as indicated. Tweak as required.
399 // (What a hack. A JS programmer should find a better way.)
400 // Luc St-Louis, and email is lucs@pobox.com.
402 nodes = document.getElementById('builtinCode').childNodes;
405 if (nodes[i].nodeValue) {
406 content = content + nodes[i].nodeValue;
410 this._data = content.split("----");
421 get isPresentationMode(){
422 return (this.deck.selectedIndex == 0);
428 this.dataPath = location.href;
429 return this._dataPath;
431 set dataPath(aValue){
432 var oldDataPath = this._dataPath;
433 this._dataPath = aValue;
434 if (oldDataPath != aValue) {
435 this._dataFolder = this._dataPath.split('?')[0].replace(/[^\/]+$/, '');
437 return this._dataPath;
441 if (!this._dataFolder)
442 this.dataPath = this.dataPath;
443 return this._dataFolder;
445 set dataFolder(aValue){
446 this._dataFolder = aValue;
447 return this._dataFolder;
450 readParameter : function() {
451 if (location.search) {
452 var param = location.search.replace(/^\?/, '');
454 if (param.match(/page=([0-9]+)/i))
455 this.offset = parseInt(RegExp.$1)-1;
457 if (param.match(/edit=(1|true|yes)/i))
458 this.toggleEditMode();
460 if (param.match(/eva=(1|true|yes)/i))
461 this.toggleEvaMode();
463 if (param.match(/data=([^&;]+)/i)) {
464 var path = unescape(RegExp.$1);
465 this.dataPath = path;
466 if (location.href.match(/^https?:/)) {
467 var request = new XMLHttpRequest();
468 request.open('GET', path);
469 request.onload = function() {
470 Presentation.textbox.value = request.responseText;
471 Presentation.data = Presentation.textbox.value.split('----');
473 Presentation.takahashi();
478 document.getElementById('dataLoader').setAttribute('src', path);
485 onDataLoad : function() {
486 if (!window.frames[0].document.body.hasChildNodes()) return;
487 var data = window.frames[0].document.body.firstChild.innerHTML;
490 this.textbox.value = data;
491 this.data = this.textbox.value.split('----');
499 window.removeEventListener('load', init, false);
503 window.addEventListener('load', init, false);