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'
27 require 'booh/version.rb'
30 $image_head_code = '<meta name="generator" content="Booh-' + $VERSION + <<'EOF'
31 http://zarb.org/~gc/html/booh.html"/>
33 <script language="JavaScript1.1" type="text/JavaScript">
34 var images = new Array(~~images~~);
36 var other_sizes = new Array(~~other_sizes~~);
37 var captions = new Array(~~captions~~);
39 var images_ary = new Array();
40 var images_loaded = new Array();
43 var slideshow_pause = null;
44 var slideshow_timer = null;
46 for (i = 0; i < images.length; i++) {
47 /* this array will contain 0 if image not yet loaded, 1 when loading,
53 document.getElementById('dbg_text').innerHTML += t + "\n";
56 /* load image, return 1 if image is finished loading */
58 if (images_loaded[i] == 0) {
59 images_ary[i] = new Image();
60 images_ary[i].src = images[i];
63 if (images_loaded[i] == 1) {
64 if (images_ary[i].complete) {
73 function getparam(key) {
74 all_params = location.href.split("#")
75 if (all_params.length > 1) {
76 params = all_params[1].split("&");
77 for (i = 0; i < params.length; i++) {
78 keyvalue = params[i].split("=");
79 if (keyvalue[0] == key) {
87 function loadcurrent(img) {
88 for (i = 0; i < images.length; i++) {
89 if (images[i] == img) {
99 function browser_href() {
100 all = location.href.split("/");
101 return all[all.length - 1];
104 /* check URL for changes; allows the URL to reflect currently showed image */
106 function checkURL() {
107 if (currentURL == 'ignore1') {
109 } else if (currentURL == 'ignore2') {
110 currentURL = browser_href();
112 href = browser_href();
113 if (href != currentURL) {
115 img = getparam('current');
119 setTimeout("checkURL()", 100);
124 /* favor current image, if user clicked on `last' or something */
127 /* don't blindly preload all images at the beginning,
128 * but rather load them one by one, in order to get
129 * next ones faster, beginning with next to current
131 if (current + 1 < images.length && load(current + 1) == 0) {
132 setTimeout("preload()", 500);
135 if (current - 1 >= 0 && load(current - 1) == 0) {
136 setTimeout("preload()", 500);
140 for (i = current + 2; i < images.length && i <= current + 5; i++) {
142 setTimeout("preload()", 500);
146 for (i = current - 2; i >= current - 3; i--) {
149 setTimeout("preload()", 500);
155 setTimeout("preload()", 500);
158 function add_cookie(val) {
159 var expires = new Date(new Date().getTime() + (30 * 86400000)); // 30 days
160 document.cookie = val
161 + '; expires=' + expires.toGMTString()
165 function get_cookie(key) {
166 if (document.cookie) {
167 var index = document.cookie.indexOf(key);
169 var oleft = (document.cookie.indexOf('=', index) + 1);
170 var oright = document.cookie.indexOf(';', index);
172 oright = document.cookie.length;
174 return document.cookie.substring(oleft, oright);
182 preferred_pause = get_cookie('booh-slideshow-pause-~~theme~~');
183 if (preferred_pause != null) {
184 document.getElementById('secs').value = preferred_pause;
187 if (getparam('run_slideshow')) {
194 if (images.length == 1) {
195 document.getElementById("b_slideshow").disabled = true;
196 document.getElementById("b_slideshow").setAttribute("class", "disabled");
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;
208 document.getElementById("b_first").setAttribute("class", "disabled");
209 document.getElementById("b_previous").setAttribute("class", "disabled");
211 document.getElementById("b_first").disabled = false;
212 document.getElementById("b_previous").disabled = false;
213 document.getElementById("b_first").removeAttribute("class");
214 document.getElementById("b_previous").removeAttribute("class");
217 if (current == images.length - 1) {
218 document.getElementById("b_next").disabled = true;
219 document.getElementById("b_last").disabled = true;
220 document.getElementById("b_next").setAttribute("class", "disabled");
221 document.getElementById("b_last").setAttribute("class", "disabled");
223 document.getElementById("b_next").disabled = false;
224 document.getElementById("b_last").disabled = false;
225 document.getElementById("b_next").removeAttribute("class");
226 document.getElementById("b_last").removeAttribute("class");
230 function set_cursor_(value, element) {
232 if (!element || !element.style) {
236 element.style.cursor = value;
238 children = element.childNodes;
239 for (i = 0; i < children.length; i++) {
240 set_cursor_(value, children.item[i]);
244 function set_cursor(value) {
245 set_cursor_(value, document.getElementById('body'));
246 set_cursor_(value, document.getElementById('b_first'));
247 set_cursor_(value, document.getElementById('b_previous'));
248 set_cursor_(value, document.getElementById('b_next'));
249 set_cursor_(value, document.getElementById('b_last'));
252 function show_current_text() {
253 /* don't show text if image not yet loaded because navigator
254 * won't refresh it during load */
255 if (images_loaded[current] == 2) {
256 document.getElementById('image_counter').innerHTML = ( current + 1 ) + "/" + images.length;
257 document.getElementById('main_text').innerHTML = captions[current];
258 for (i = 0; i < other_sizes.length; i++) {
259 if (other_sizes[i] == "original") {
260 document.getElementById('link' + other_sizes[i]).href = eval("images_" + other_sizes[i] + "[current]");
262 document.getElementById('link' + other_sizes[i]).href = 'image-' + other_sizes[i] + '.html#current=' + eval("images_" + other_sizes[i] + "[current]");
265 document.getElementById('thumbnails').href = 'thumbnails-~~current_size~~.html#' + images[current];
266 set_cursor("default");
268 setTimeout("show_current_text()", 100);
273 function display_current() {
274 document.main_img.src = images[current];
275 oldhref = browser_href();
276 newhref = 'image-~~current_size~~.html#current=' + images[current];
277 if (oldhref != newhref) {
278 currentURL = 'ignore1';
279 location.href = newhref;
280 currentURL = 'ignore2';
283 update_sensibilities();
287 if (slideshow == 1) {
288 toggle_slideshow(true);
296 if (slideshow == 1) {
297 toggle_slideshow(true);
300 if (current < images.length - 1) {
307 if (slideshow == 1) {
308 toggle_slideshow(true);
311 if (current < images.length - 11) {
314 current = images.length - 1;
319 function previous() {
320 if (slideshow == 1) {
321 toggle_slideshow(true);
330 function previous10() {
331 if (slideshow == 1) {
332 toggle_slideshow(true);
344 if (slideshow == 1) {
345 toggle_slideshow(true);
348 current = images.length - 1;
352 function keyDownEvent(key) {
355 key.which = key.keyCode;
379 function toggle_slideshow(now) {
380 if (slideshow == 0) {
381 slideshow_pause = document.getElementById('secs').value;
382 add_cookie('booh-slideshow-pause-~~theme~~=' + slideshow_pause)
383 document.getElementById("b_slideshow").value = "~~stop_slideshow~~";
385 if (current == images.length - 1) {
391 setTimeout("run_slideshow()", slideshow_pause * 1000);
394 clearTimeout(slideshow_timer);
395 document.getElementById("b_slideshow").value = "~~run_slideshow~~";
400 function run_slideshow() {
401 if (slideshow == 0) {
405 if (images_loaded[current + 1] == 2) {
408 slideshow_timer = setTimeout("run_slideshow()", slideshow_pause * 1000);
410 slideshow_timer = setTimeout("run_slideshow()", 500);
413 if (current == images.length - 1) {
414 toggle_slideshow(true);
420 $image_head_code.sub!('~~run_slideshow~~', utf8(_('Run slideshow!')))
421 $image_head_code.sub!('~~stop_slideshow~~', utf8(_('Stop slideshow')))
423 $body_additions = <<'EOF'
424 onload="init()" id="body"
428 <form action="fake"><input type="button"
430 value="' + utf8(_('<<- First')) + '"
431 id="b_first"/></form>'
434 <form action="fake"><input type="button"
436 value="' + utf8(_('<- Previous')) + '"
437 id="b_previous"/></form>'
440 <form action="fake"><input type="button"
442 value="' + utf8(_('Next ->')) + '"
443 id="b_next"/></form>'
446 <form action="fake"><input type="button"
448 value="' + utf8(_('Last ->>')) + '"
449 id="b_last"/></form>'
451 $button_slideshow = '
453 onclick="toggle_slideshow(true)"
454 value="' + utf8(_('Run slideshow!')) + '"
458 <font size="-2">' + utf8(_('pause:')) + '<input type="text" id="secs" size="1" value="3"/>' + utf8(_('secs')) + '</font>'
462 <img name="main_img" class="image" src="fake" alt="main image"/>
465 $image_counter_additions = <<'EOF'
469 $caption_additions = <<'EOF'
477 $thumbnails_head_code = '<meta name="generator" content="Booh-' + $VERSION + <<'EOF'
478 http://zarb.org/~gc/html/booh.html"/>
480 <script language="JavaScript1.1" type="text/JavaScript">
481 var expires = new Date(new Date().getTime() + (30 * 86400000)); // 30 days
482 document.cookie = 'booh-preferred-size-~~theme~~=~~current_size_js~~'
483 + '; expires=' + expires.toGMTString()
489 $preferred_size_reloader = <<'EOF'
492 <script language="JavaScript1.1" type="text/JavaScript">
494 var sizes = new Array(~~all_sizes~~);
496 function getPreferredSize() {
497 if (document.cookie) {
498 var index = document.cookie.indexOf('booh-preferred-size-~~theme~~');
500 var oleft = (document.cookie.indexOf('=', index) + 1);
501 var oright = document.cookie.indexOf(';', index);
503 oright = document.cookie.length;
505 size = document.cookie.substring(oleft, oright);
506 for (i = 0; i < sizes.length; i++) {
507 if (sizes[i] == size) {
508 return 'thumbnails-' + size + '.html';
513 return 'thumbnails-~~default_size~~.html';
516 window.location.href = getPreferredSize();
524 $index_head_code = '<meta name="generator" content="Booh-' + $VERSION + ' http://zarb.org/~gc/html/booh.html"/>
525 <script language="JavaScript1.1" type="text/JavaScript">
527 if (!document.cookie || document.cookie.indexOf("booh-not-a-newbie") == -1) {
528 document.getElementById("title").innerHTML += "<br/><br/>' + utf8(_("<i>Hint: you can click on the images to open the albums!</i>")) + '";
530 var expires = new Date(new Date().getTime() + (10 * 86400000)); // 10 days
531 document.cookie = "booh-not-a-newbie=true"
532 + "; expires=" + expires.toGMTString()