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) {
74 /* favor current image, if user clicked on `last' or something */
77 /* don't blindly preload all images at the beginning,
78 * but rather load them one by one, in order to get
79 * next ones faster, beginning with next to current
81 for (i = current + 1; i < images.length && i <= current + 5; i++) {
83 setTimeout("preload()", 500);
87 for (i = current - 1; i >= current - 3; i--) {
90 setTimeout("preload()", 500);
96 setTimeout("preload()", 500);
99 function add_cookie(val) {
100 var expires = new Date(new Date().getTime() + (30 * 86400000)); // 30 days
101 document.cookie = val
102 + '; expires=' + expires.toGMTString()
106 function get_cookie(key) {
107 if (document.cookie) {
108 var index = document.cookie.indexOf(key);
110 var oleft = (document.cookie.indexOf('=', index) + 1);
111 var oright = document.cookie.indexOf(';', index);
113 oright = document.cookie.length;
115 return document.cookie.substring(oleft, oright);
123 add_cookie('booh-preferred-size-~~theme~~=~~current_size~~')
125 /* retrieve GET parameters */
126 all_params = location.href.split("?")
127 if (all_params.length > 1) {
128 params = all_params[1].split("&");
129 for (i = 0; i < params.length; i++) {
130 keyvalue = params[i].split("=");
131 if (keyvalue[0] == "run_slideshow") {
134 if (keyvalue[0] == "current") {
135 for (i = 0; i < images.length; i++) {
136 if (images[i] == keyvalue[1]) {
147 if (images.length == 1) {
148 document.getElementById("b_slideshow").disabled = true;
151 preferred_pause = get_cookie('booh-slideshow-pause-~~theme~~');
152 if (preferred_pause != null) {
153 document.getElementById('secs').value = preferred_pause;
156 if (navigator.userAgent.indexOf('Opera') == -1) {
157 document.onkeydown = keyDownEvent;
161 function update_sensibilities() {
163 document.getElementById("b_first").disabled = true;
164 document.getElementById("b_previous").disabled = true;
166 document.getElementById("b_first").disabled = false;
167 document.getElementById("b_previous").disabled = false;
170 if (current == images.length - 1) {
171 document.getElementById("b_next").disabled = true;
172 document.getElementById("b_last").disabled = true;
174 document.getElementById("b_next").disabled = false;
175 document.getElementById("b_last").disabled = false;
179 function set_cursor_(value, element) {
181 if (!element || !element.style) {
185 element.style.cursor = value;
187 children = element.childNodes;
188 for (i = 0; i < children.length; i++) {
189 set_cursor_(value, children.item[i]);
193 function set_cursor(value) {
194 set_cursor_(value, document.getElementById('body'));
197 function show_current_text() {
198 /* don't show text if image not yet loaded because navigator
199 * won't refresh it during load */
200 if (images_loaded[current] == 2) {
201 document.getElementById('image_counter').innerHTML = ( current + 1 ) + "/" + images.length;
202 document.getElementById('main_text').innerHTML = captions[current];
203 for (i = 0; i < other_sizes.length; i++) {
204 if (other_sizes[i] == "original") {
205 document.getElementById('link' + other_sizes[i]).href = eval("images_" + other_sizes[i] + "[current]");
207 document.getElementById('link' + other_sizes[i]).href = 'image-' + other_sizes[i] + '.html?current=' + eval("images_" + other_sizes[i] + "[current]");
210 document.getElementById('thumbnails').href = 'thumbnails-~~current_size~~.html#' + images[current];
211 set_cursor("default");
213 setTimeout("show_current_text()", 100);
218 function display_current() {
219 eval("document.main_img.src = images[" + current + "]");
221 update_sensibilities();
225 if (slideshow == 1) {
226 toggle_slideshow(true);
234 if (slideshow == 1) {
235 toggle_slideshow(true);
238 if (current < images.length - 1) {
244 function previous() {
245 if (slideshow == 1) {
246 toggle_slideshow(true);
256 if (slideshow == 1) {
257 toggle_slideshow(true);
260 current = images.length - 1;
264 function keyDownEvent(key) {
267 key.which = key.keyCode;
283 for (i = 0; i < 10; i++) {
288 for (i = 0; i < 10; i++) {
295 function toggle_slideshow(now) {
296 if (slideshow == 0) {
297 slideshow_pause = document.getElementById('secs').value;
298 add_cookie('booh-slideshow-pause-~~theme~~=' + slideshow_pause)
299 document.getElementById("b_slideshow").value = "~~stop_slideshow~~";
301 if (current == images.length - 1) {
307 setTimeout("run_slideshow()", slideshow_pause * 1000);
310 clearTimeout(slideshow_timer);
311 document.getElementById("b_slideshow").value = "~~run_slideshow~~";
316 function run_slideshow() {
317 if (slideshow == 0) {
321 if (images_loaded[current + 1] == 2) {
324 slideshow_timer = setTimeout("run_slideshow()", slideshow_pause * 1000);
326 slideshow_timer = setTimeout("run_slideshow()", 500);
329 if (current == images.length - 1) {
330 toggle_slideshow(true);
336 $image_head_code.sub!('~~run_slideshow~~', utf8(_('Run slideshow!')))
337 $image_head_code.sub!('~~stop_slideshow~~', utf8(_('Stop slideshow')))
339 $body_additions = <<'EOF'
340 onload="init()" id="body"
344 <form><input type="button"
346 value="' + utf8(_('<<- First')) + '"
347 id="b_first"/></form>'
350 <form><input type="button"
352 value="' + utf8(_('<- Previous')) + '"
353 id="b_previous"/></form>'
356 <form><input type="button"
358 value="' + utf8(_('Next ->')) + '"
359 id="b_next"/></form>'
362 <form><input type="button"
364 value="' + utf8(_('Last ->>')) + '"
365 id="b_last"/></form>'
367 $button_slideshow = '
369 onclick="toggle_slideshow(true)"
370 value="' + utf8(_('Run slideshow!')) + '"
374 <font size="-2">' + utf8(_('pause:')) + '<input type="text" id="secs" size="1" value="3"/>' + utf8(_('secs')) + '</font>'
378 <img name="main_img">
381 $image_counter_additions = <<'EOF'
385 $caption_additions = <<'EOF'
393 $thumbnails_head_code = <<'EOF'
394 <meta name="generator" content="Generated by Booh! http://zarb.org/~gc/html/booh.html">
396 <script language="JavaScript1.1" type="text/JavaScript">
397 var expires = new Date(new Date().getTime() + (30 * 86400000)); // 30 days
398 document.cookie = 'booh-preferred-size-~~theme~~=~~current_size~~'
399 + '; expires=' + expires.toGMTString()
405 $preferred_size_reloader = <<'EOF'
408 <script language="JavaScript1.1" type="text/JavaScript">
410 function getPreferredSize() {
411 if (document.cookie) {
412 var index = document.cookie.indexOf('booh-preferred-size-~~theme~~');
414 var oleft = (document.cookie.indexOf('=', index) + 1);
415 var oright = document.cookie.indexOf(';', index);
417 oright = document.cookie.length;
419 return 'thumbnails-' + document.cookie.substring(oleft, oright) + '.html';
422 return 'thumbnails-~~default_size~~.html';
425 window.location.href = getPreferredSize();