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">
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 = 3;
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').firstChild.data += 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) {
75 /* favor current image, if user clicked on `last' or something */
78 /* don't blindly preload all images at the beginning,
79 * but rather load them one by one, in order to get
80 * next ones faster, beginning with next to current
82 for (i = current + 1; i < images.length && i <= current + 5; i++) {
84 setTimeout("preload()", 500);
88 for (i = current - 1; i >= current - 3; i--) {
91 setTimeout("preload()", 500);
97 setTimeout("preload()", 500);
102 /* retrieve GET parameters */
103 all_params = location.href.split("?")
104 if (all_params.length > 1) {
105 params = all_params[1].split("&");
106 for (i = 0; i < params.length; i++) {
107 keyvalue = params[i].split("=");
108 if (keyvalue[0] == "slideshow_pause") {
109 slideshow_pause = keyvalue[1];
111 if (keyvalue[0] == "run_slideshow") {
114 if (keyvalue[0] == "current") {
115 for (i = 0; i < images.length; i++) {
116 if (images[i] == keyvalue[1]) {
127 if (images.length == 1) {
128 document.getElementById("b_slideshow").disabled = true;
132 function update_sensibilities() {
134 document.getElementById("b_first").disabled = true;
135 document.getElementById("b_previous").disabled = true;
137 document.getElementById("b_first").disabled = false;
138 document.getElementById("b_previous").disabled = false;
141 if (current == images.length - 1) {
142 document.getElementById("b_next").disabled = true;
143 document.getElementById("b_last").disabled = true;
145 document.getElementById("b_next").disabled = false;
146 document.getElementById("b_last").disabled = false;
150 function set_cursor_(value, element) {
152 if (!element || !element.style) {
156 element.style.cursor = value;
158 children = element.childNodes;
159 for (i = 0; i < children.length; i++) {
160 set_cursor_(value, children.item[i]);
164 function set_cursor(value) {
165 set_cursor_(value, document.getElementById('body'));
168 function show_current_text() {
169 /* don't show text if image not yet loaded because navigator
170 * won't refresh it during load */
171 if (images_loaded[current] == 2) {
172 eval("document.getElementById('image_counter')" +
173 ".firstChild.data = '" + ( current + 1 ) + "/" + images.length + "'");
174 eval("document.getElementById('main_text')" +
175 ".firstChild.data = \"" + ( captions[current] || images[current] ) + "\"");
176 for (i = 0; i < other_sizes.length; i++) {
177 eval("linkelems = document.getElementById('link" + other_sizes[i] + "').href.split('?');" +
178 "document.getElementById('link" + other_sizes[i] + "').href = linkelems[0] + '?current=" + eval("images_" + other_sizes[i] + "[current]") + "'");
180 set_cursor("default");
182 setTimeout("show_current_text()", 100);
187 function display_current() {
188 eval("document.main_img.src = images[" + current + "]");
190 update_sensibilities();
194 if (slideshow == 1) {
195 toggle_slideshow(true);
203 if (slideshow == 1) {
204 toggle_slideshow(true);
207 if (current < images.length - 1) {
213 function previous() {
214 if (slideshow == 1) {
215 toggle_slideshow(true);
225 if (slideshow == 1) {
226 toggle_slideshow(true);
229 current = images.length - 1;
233 function toggle_slideshow(now) {
234 if (slideshow == 0) {
235 document.getElementById("b_slideshow").value = "~~stop_slideshow~~";
237 if (current == images.length - 1) {
243 setTimeout("run_slideshow()", slideshow_pause * 1000);
246 clearTimeout(slideshow_timer);
247 document.getElementById("b_slideshow").value = "~~run_slideshow~~";
252 function run_slideshow() {
253 if (slideshow == 0) {
257 if (images_loaded[current + 1] == 2) {
260 slideshow_timer = setTimeout("run_slideshow()", slideshow_pause * 1000);
262 slideshow_timer = setTimeout("run_slideshow()", 500);
265 if (current == images.length - 1) {
266 toggle_slideshow(true);
272 $image_head_code.sub!('~~run_slideshow~~', utf8(_('Run slideshow!')))
273 $image_head_code.sub!('~~stop_slideshow~~', utf8(_('Stop slideshow')))
275 $body_additions = <<'EOF'
276 onload="init()" id="body"
280 <form><input type="button"
282 value="' + utf8(_('<<- First')) + '"
283 id="b_first"></form>';
286 <form><input type="button"
288 value="' + utf8(_('<- Previous')) + '"
289 id="b_previous"></form>';
292 <form><input type="button"
294 value="' + utf8(_('Next ->')) + '"
295 id="b_next"></form>';
298 <form><input type="button"
300 value="' + utf8(_('Last ->>')) + '"
301 id="b_last"></form>';
303 $button_slideshow = '
304 <form><input type="button"
305 onclick="toggle_slideshow(true)"
306 value="' + utf8(_('Run slideshow!')) + '"
311 <img name="main_img">
314 $image_counter_additions = <<'EOF'
318 $caption_additions = <<'EOF'
326 $thumbnails_head_code = <<'EOF'
327 <script language="JavaScript1.1" type="text/JavaScript">
328 var expires = new Date(new Date().getTime() + (30 * 86400000)); // 30 days
329 document.cookie = 'booh-preferred-size-~~theme~~=~~current_size~~'
330 + '; expires=' + expires.toGMTString()
336 $preferred_size_reloader = <<'EOF'
339 <script language="JavaScript1.1" type="text/JavaScript">
341 function getPreferredSize() {
342 if (document.cookie) {
343 var index = document.cookie.indexOf('booh-preferred-size-~~theme~~');
345 var oleft = (document.cookie.indexOf('=', index) + 1);
346 var oright = document.cookie.indexOf(';', index);
348 oright = document.cookie.length;
350 return 'thumbnails-' + document.cookie.substring(oleft, oright) + '.html';
353 return 'thumbnails-~~default_size~~.html';
356 window.location.href = getPreferredSize();