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 /* check URL for changes; allows the URL to reflect currently showed image */
100 function checkURL() {
101 if (window.location.href != currentURL) {
102 currentURL = window.location.href;
103 img = getparam('current');
106 setTimeout("checkURL()", 100);
111 /* favor current image, if user clicked on `last' or something */
114 /* don't blindly preload all images at the beginning,
115 * but rather load them one by one, in order to get
116 * next ones faster, beginning with next to current
118 if (current + 1 < images.length && load(current + 1) == 0) {
119 setTimeout("preload()", 500);
122 if (current - 1 >= 0 && load(current - 1) == 0) {
123 setTimeout("preload()", 500);
127 for (i = current + 2; i < images.length && i <= current + 5; i++) {
129 setTimeout("preload()", 500);
133 for (i = current - 2; i >= current - 3; i--) {
136 setTimeout("preload()", 500);
142 setTimeout("preload()", 500);
145 function add_cookie(val) {
146 var expires = new Date(new Date().getTime() + (30 * 86400000)); // 30 days
147 document.cookie = val
148 + '; expires=' + expires.toGMTString()
152 function get_cookie(key) {
153 if (document.cookie) {
154 var index = document.cookie.indexOf(key);
156 var oleft = (document.cookie.indexOf('=', index) + 1);
157 var oright = document.cookie.indexOf(';', index);
159 oright = document.cookie.length;
161 return document.cookie.substring(oleft, oright);
169 add_cookie('booh-preferred-size-~~theme~~=~~current_size~~')
171 if (getparam('run_slideshow')) {
178 if (images.length == 1) {
179 document.getElementById("b_slideshow").disabled = true;
182 preferred_pause = get_cookie('booh-slideshow-pause-~~theme~~');
183 if (preferred_pause != null) {
184 document.getElementById('secs').value = preferred_pause;
187 if (navigator.userAgent.indexOf('Opera') == -1) {
188 document.onkeydown = keyDownEvent;
192 function update_sensibilities() {
194 document.getElementById("b_first").disabled = true;
195 document.getElementById("b_previous").disabled = true;
197 document.getElementById("b_first").disabled = false;
198 document.getElementById("b_previous").disabled = false;
201 if (current == images.length - 1) {
202 document.getElementById("b_next").disabled = true;
203 document.getElementById("b_last").disabled = true;
205 document.getElementById("b_next").disabled = false;
206 document.getElementById("b_last").disabled = false;
210 function set_cursor_(value, element) {
212 if (!element || !element.style) {
216 element.style.cursor = value;
218 children = element.childNodes;
219 for (i = 0; i < children.length; i++) {
220 set_cursor_(value, children.item[i]);
224 function set_cursor(value) {
225 set_cursor_(value, document.getElementById('body'));
226 set_cursor_(value, document.getElementById('b_first'));
227 set_cursor_(value, document.getElementById('b_previous'));
228 set_cursor_(value, document.getElementById('b_next'));
229 set_cursor_(value, document.getElementById('b_last'));
232 function show_current_text() {
233 /* don't show text if image not yet loaded because navigator
234 * won't refresh it during load */
235 if (images_loaded[current] == 2) {
236 document.getElementById('image_counter').innerHTML = ( current + 1 ) + "/" + images.length;
237 document.getElementById('main_text').innerHTML = captions[current];
238 for (i = 0; i < other_sizes.length; i++) {
239 if (other_sizes[i] == "original") {
240 document.getElementById('link' + other_sizes[i]).href = eval("images_" + other_sizes[i] + "[current]");
242 document.getElementById('link' + other_sizes[i]).href = 'image-' + other_sizes[i] + '.html#current=' + eval("images_" + other_sizes[i] + "[current]");
245 document.getElementById('thumbnails').href = 'thumbnails-~~current_size~~.html#' + images[current];
246 set_cursor("default");
248 setTimeout("show_current_text()", 100);
253 function display_current() {
254 document.main_img.src = images[current];
255 window.location.href = 'image-~~current_size~~.html#current=' + images[current];
257 update_sensibilities();
261 if (slideshow == 1) {
262 toggle_slideshow(true);
270 if (slideshow == 1) {
271 toggle_slideshow(true);
274 if (current < images.length - 1) {
280 function previous() {
281 if (slideshow == 1) {
282 toggle_slideshow(true);
292 if (slideshow == 1) {
293 toggle_slideshow(true);
296 current = images.length - 1;
300 function keyDownEvent(key) {
303 key.which = key.keyCode;
319 for (i = 0; i < 10; i++) {
324 for (i = 0; i < 10; i++) {
331 function toggle_slideshow(now) {
332 if (slideshow == 0) {
333 slideshow_pause = document.getElementById('secs').value;
334 add_cookie('booh-slideshow-pause-~~theme~~=' + slideshow_pause)
335 document.getElementById("b_slideshow").value = "~~stop_slideshow~~";
337 if (current == images.length - 1) {
343 setTimeout("run_slideshow()", slideshow_pause * 1000);
346 clearTimeout(slideshow_timer);
347 document.getElementById("b_slideshow").value = "~~run_slideshow~~";
352 function run_slideshow() {
353 if (slideshow == 0) {
357 if (images_loaded[current + 1] == 2) {
360 slideshow_timer = setTimeout("run_slideshow()", slideshow_pause * 1000);
362 slideshow_timer = setTimeout("run_slideshow()", 500);
365 if (current == images.length - 1) {
366 toggle_slideshow(true);
372 $image_head_code.sub!('~~run_slideshow~~', utf8(_('Run slideshow!')))
373 $image_head_code.sub!('~~stop_slideshow~~', utf8(_('Stop slideshow')))
375 $body_additions = <<'EOF'
376 onload="init()" id="body"
380 <form><input type="button"
382 value="' + utf8(_('<<- First')) + '"
383 id="b_first"/></form>'
386 <form><input type="button"
388 value="' + utf8(_('<- Previous')) + '"
389 id="b_previous"/></form>'
392 <form><input type="button"
394 value="' + utf8(_('Next ->')) + '"
395 id="b_next"/></form>'
398 <form><input type="button"
400 value="' + utf8(_('Last ->>')) + '"
401 id="b_last"/></form>'
403 $button_slideshow = '
405 onclick="toggle_slideshow(true)"
406 value="' + utf8(_('Run slideshow!')) + '"
410 <font size="-2">' + utf8(_('pause:')) + '<input type="text" id="secs" size="1" value="3"/>' + utf8(_('secs')) + '</font>'
414 <img name="main_img">
417 $image_counter_additions = <<'EOF'
421 $caption_additions = <<'EOF'
429 $thumbnails_head_code = <<'EOF'
430 <meta name="generator" content="Generated by Booh! http://zarb.org/~gc/html/booh.html">
432 <script language="JavaScript1.1" type="text/JavaScript">
433 var expires = new Date(new Date().getTime() + (30 * 86400000)); // 30 days
434 document.cookie = 'booh-preferred-size-~~theme~~=~~current_size~~'
435 + '; expires=' + expires.toGMTString()
441 $preferred_size_reloader = <<'EOF'
444 <script language="JavaScript1.1" type="text/JavaScript">
446 function getPreferredSize() {
447 if (document.cookie) {
448 var index = document.cookie.indexOf('booh-preferred-size-~~theme~~');
450 var oleft = (document.cookie.indexOf('=', index) + 1);
451 var oright = document.cookie.indexOf(';', index);
453 oright = document.cookie.length;
455 return 'thumbnails-' + document.cookie.substring(oleft, oright) + '.html';
458 return 'thumbnails-~~default_size~~.html';
461 window.location.href = getPreferredSize();