4 # A.k.a `Best web-album Of the world, Or your money back, Humerus'.
6 # The acronyn sucks, however this is a tribute to Dragon Ball by
7 # Akira Toriyama, where the last enemy beaten by heroes of Dragon
8 # Ball is named "Boo". But there was already a free software project
9 # called Boo, so this one will be it "Booh". Or whatever.
12 # Copyright (c) 2004 Guillaume Cottenceau <gc3 at bluewin.ch>
14 # This software may be freely redistributed under the terms of the GNU
15 # public license version 2.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 # holds static data to merge in the html "themes"
24 bindtextdomain("booh")
26 require 'booh/booh-lib'
29 $image_head_code = <<'EOF'
30 <meta name="generator" content="Generated by Booh! http://zarb.org/~gc/html/booh.html">
32 <script language="JavaScript1.1" type="text/JavaScript">
33 var images = new Array(~~images~~);
35 var other_sizes = new Array(~~other_sizes~~);
36 var captions = new Array(~~captions~~);
38 var images_ary = new Array();
39 var images_loaded = new Array();
42 var slideshow_pause = null;
43 var slideshow_timer = null;
45 for (i = 0; i < images.length; i++) {
46 /* this array will contain 0 if image not yet loaded, 1 when loading,
52 document.getElementById('dbg_text').innerHTML += t + "\n";
55 /* load image, return 1 if image is finished loading */
57 if (images_loaded[i] == 0) {
58 images_ary[i] = new Image();
59 images_ary[i].src = images[i];
62 if (images_loaded[i] == 1) {
63 if (images_ary[i].complete) {
72 function getparam(key) {
73 all_params = location.href.split("#")
74 if (all_params.length > 1) {
75 params = all_params[1].split("&");
76 for (i = 0; i < params.length; i++) {
77 keyvalue = params[i].split("=");
78 if (keyvalue[0] == key) {
86 function loadcurrent(img) {
87 for (i = 0; i < images.length; i++) {
88 if (images[i] == img) {
98 function browser_href() {
99 all = location.href.split("/");
100 return all[all.length - 1];
103 /* check URL for changes; allows the URL to reflect currently showed image */
105 function checkURL() {
106 if (currentURL == 'ignore1') {
108 } else if (currentURL == 'ignore2') {
109 currentURL = browser_href();
111 href = browser_href();
112 if (href != currentURL) {
114 img = getparam('current');
118 setTimeout("checkURL()", 100);
123 /* favor current image, if user clicked on `last' or something */
126 /* don't blindly preload all images at the beginning,
127 * but rather load them one by one, in order to get
128 * next ones faster, beginning with next to current
130 if (current + 1 < images.length && load(current + 1) == 0) {
131 setTimeout("preload()", 500);
134 if (current - 1 >= 0 && load(current - 1) == 0) {
135 setTimeout("preload()", 500);
139 for (i = current + 2; i < images.length && i <= current + 5; i++) {
141 setTimeout("preload()", 500);
145 for (i = current - 2; i >= current - 3; i--) {
148 setTimeout("preload()", 500);
154 setTimeout("preload()", 500);
157 function add_cookie(val) {
158 var expires = new Date(new Date().getTime() + (30 * 86400000)); // 30 days
159 document.cookie = val
160 + '; expires=' + expires.toGMTString()
164 function get_cookie(key) {
165 if (document.cookie) {
166 var index = document.cookie.indexOf(key);
168 var oleft = (document.cookie.indexOf('=', index) + 1);
169 var oright = document.cookie.indexOf(';', index);
171 oright = document.cookie.length;
173 return document.cookie.substring(oleft, oright);
181 add_cookie('booh-preferred-size-~~theme~~=~~current_size~~')
183 if (getparam('run_slideshow')) {
190 if (images.length == 1) {
191 document.getElementById("b_slideshow").disabled = true;
194 preferred_pause = get_cookie('booh-slideshow-pause-~~theme~~');
195 if (preferred_pause != null) {
196 document.getElementById('secs').value = preferred_pause;
199 if (navigator.userAgent.indexOf('Opera') == -1) {
200 document.onkeydown = keyDownEvent;
204 function update_sensibilities() {
206 document.getElementById("b_first").disabled = true;
207 document.getElementById("b_previous").disabled = true;
209 document.getElementById("b_first").disabled = false;
210 document.getElementById("b_previous").disabled = false;
213 if (current == images.length - 1) {
214 document.getElementById("b_next").disabled = true;
215 document.getElementById("b_last").disabled = true;
217 document.getElementById("b_next").disabled = false;
218 document.getElementById("b_last").disabled = false;
222 function set_cursor_(value, element) {
224 if (!element || !element.style) {
228 element.style.cursor = value;
230 children = element.childNodes;
231 for (i = 0; i < children.length; i++) {
232 set_cursor_(value, children.item[i]);
236 function set_cursor(value) {
237 set_cursor_(value, document.getElementById('body'));
238 set_cursor_(value, document.getElementById('b_first'));
239 set_cursor_(value, document.getElementById('b_previous'));
240 set_cursor_(value, document.getElementById('b_next'));
241 set_cursor_(value, document.getElementById('b_last'));
244 function show_current_text() {
245 /* don't show text if image not yet loaded because navigator
246 * won't refresh it during load */
247 if (images_loaded[current] == 2) {
248 document.getElementById('image_counter').innerHTML = ( current + 1 ) + "/" + images.length;
249 document.getElementById('main_text').innerHTML = captions[current];
250 for (i = 0; i < other_sizes.length; i++) {
251 if (other_sizes[i] == "original") {
252 document.getElementById('link' + other_sizes[i]).href = eval("images_" + other_sizes[i] + "[current]");
254 document.getElementById('link' + other_sizes[i]).href = 'image-' + other_sizes[i] + '.html#current=' + eval("images_" + other_sizes[i] + "[current]");
257 document.getElementById('thumbnails').href = 'thumbnails-~~current_size~~.html#' + images[current];
258 set_cursor("default");
260 setTimeout("show_current_text()", 100);
265 function display_current() {
266 document.main_img.src = images[current];
267 oldhref = browser_href();
268 newhref = 'image-~~current_size~~.html#current=' + images[current];
269 if (oldhref != newhref) {
270 currentURL = 'ignore1';
271 location.href = newhref;
272 currentURL = 'ignore2';
275 update_sensibilities();
279 if (slideshow == 1) {
280 toggle_slideshow(true);
288 if (slideshow == 1) {
289 toggle_slideshow(true);
292 if (current < images.length - 1) {
299 if (slideshow == 1) {
300 toggle_slideshow(true);
303 if (current < images.length - 11) {
306 current = images.length - 1;
311 function previous() {
312 if (slideshow == 1) {
313 toggle_slideshow(true);
322 function previous10() {
323 if (slideshow == 1) {
324 toggle_slideshow(true);
336 if (slideshow == 1) {
337 toggle_slideshow(true);
340 current = images.length - 1;
344 function keyDownEvent(key) {
347 key.which = key.keyCode;
371 function toggle_slideshow(now) {
372 if (slideshow == 0) {
373 slideshow_pause = document.getElementById('secs').value;
374 add_cookie('booh-slideshow-pause-~~theme~~=' + slideshow_pause)
375 document.getElementById("b_slideshow").value = "~~stop_slideshow~~";
377 if (current == images.length - 1) {
383 setTimeout("run_slideshow()", slideshow_pause * 1000);
386 clearTimeout(slideshow_timer);
387 document.getElementById("b_slideshow").value = "~~run_slideshow~~";
392 function run_slideshow() {
393 if (slideshow == 0) {
397 if (images_loaded[current + 1] == 2) {
400 slideshow_timer = setTimeout("run_slideshow()", slideshow_pause * 1000);
402 slideshow_timer = setTimeout("run_slideshow()", 500);
405 if (current == images.length - 1) {
406 toggle_slideshow(true);
412 $image_head_code.sub!('~~run_slideshow~~', utf8(_('Run slideshow!')))
413 $image_head_code.sub!('~~stop_slideshow~~', utf8(_('Stop slideshow')))
415 $body_additions = <<'EOF'
416 onload="init()" id="body"
420 <form><input type="button"
422 value="' + utf8(_('<<- First')) + '"
423 id="b_first"/></form>'
426 <form><input type="button"
428 value="' + utf8(_('<- Previous')) + '"
429 id="b_previous"/></form>'
432 <form><input type="button"
434 value="' + utf8(_('Next ->')) + '"
435 id="b_next"/></form>'
438 <form><input type="button"
440 value="' + utf8(_('Last ->>')) + '"
441 id="b_last"/></form>'
443 $button_slideshow = '
445 onclick="toggle_slideshow(true)"
446 value="' + utf8(_('Run slideshow!')) + '"
450 <font size="-2">' + utf8(_('pause:')) + '<input type="text" id="secs" size="1" value="3"/>' + utf8(_('secs')) + '</font>'
454 <img name="main_img" class="image">
457 $image_counter_additions = <<'EOF'
461 $caption_additions = <<'EOF'
469 $thumbnails_head_code = <<'EOF'
470 <meta name="generator" content="Generated by Booh! http://zarb.org/~gc/html/booh.html">
472 <script language="JavaScript1.1" type="text/JavaScript">
473 var expires = new Date(new Date().getTime() + (30 * 86400000)); // 30 days
474 document.cookie = 'booh-preferred-size-~~theme~~=~~current_size~~'
475 + '; expires=' + expires.toGMTString()
481 $preferred_size_reloader = <<'EOF'
484 <script language="JavaScript1.1" type="text/JavaScript">
486 var sizes = new Array(~~all_sizes~~);
488 function getPreferredSize() {
489 if (document.cookie) {
490 var index = document.cookie.indexOf('booh-preferred-size-~~theme~~');
492 var oleft = (document.cookie.indexOf('=', index) + 1);
493 var oright = document.cookie.indexOf(';', index);
495 oright = document.cookie.length;
497 size = document.cookie.substring(oleft, oright);
498 for (i = 0; i < sizes.length; i++) {
499 if (sizes[i] == size) {
500 return 'thumbnails-' + size + '.html';
505 return 'thumbnails-~~default_size~~.html';
508 window.location.href = getPreferredSize();