fix the bookmark problem thanks to the hash trick learnt at http://www.contentwithsty...
authorgc <gc>
Tue, 21 Jun 2005 19:55:59 +0000 (19:55 +0000)
committergc <gc>
Tue, 21 Jun 2005 19:55:59 +0000 (19:55 +0000)
bin/booh-backend
lib/booh/html-merges.rb

index 32581c4e586c05c449883a8afc9d9bb178c76859..9ed093a938f64978e863587d468997d69bbfe16b 100755 (executable)
@@ -687,7 +687,7 @@ def walk_source_dir
                 html = $html_thumbnails.collect { |l| l.clone }
                 iterations = {}
                 for i in html
-                    i.sub!(/~~run_slideshow~~/, images.size <= 1 ? '' : '<a href="image-' + size2js(sizeobj['name']) + '.html?run_slideshow">' + utf8(_('Run slideshow!'))+'</a>')
+                    i.sub!(/~~run_slideshow~~/, images.size <= 1 ? '' : '<a href="image-' + size2js(sizeobj['name']) + '.html#run_slideshow=1">' + utf8(_('Run slideshow!'))+'</a>')
                     i.sub!(/~~title~~/, xmldir.attributes['thumbnails-caption'] || utf8(File.basename(dir)))
                     substitute_html_sizes(i, sizeobj, 'thumbnails')
                     discover_iterations(iterations, i)
@@ -701,7 +701,7 @@ def walk_source_dir
                         if type == 'image'
                             index = images.index(file)
                             html_thumbnails.gsub!(/~~image_iteration~~/,
-                                                  '<a href="image-' + size2js(sizeobj['name']) + '.html?current=' + fullscreen_images[sizeobj['name']][index] +
+                                                  '<a href="image-' + size2js(sizeobj['name']) + '.html#current=' + fullscreen_images[sizeobj['name']][index] +
                                                       '" name="' + fullscreen_images[sizeobj['name']][index] + '">' +
                                                       img_element("#{dest_dir}/#{thumbnail_images[sizeobj['name']][index]}") + '</a>')
                             html_thumbnails.gsub!(/~~caption_iteration~~/,
index 8e5c8dfe65281a3aff182b40c616255351414406..63ed1bde4f67375b59f6011876c1bdb05b452654 100644 (file)
@@ -69,6 +69,43 @@ function load(i) {
     return 1;
 }
 
+function getparam(key) {
+    all_params = location.href.split("#")
+    if (all_params.length > 1) {
+        params = all_params[1].split("&");
+        for (i = 0; i < params.length; i++) {
+            keyvalue = params[i].split("=");
+            if (keyvalue[0] == key) {
+                return keyvalue[1];
+            }
+        }
+    }
+    return null;
+}
+
+function loadcurrent(img) {
+    for (i = 0; i < images.length; i++) {
+        if (images[i] == img) {
+            current = i;
+            display_current();
+            return;
+        }
+    }
+    current = 0;
+    display_current();
+}
+
+/* check URL for changes; allows the URL to reflect currently showed image */
+var currentURL = '';
+function checkURL() {
+    if (window.location.href != currentURL) {
+        currentURL = window.location.href;
+        img = getparam('current');
+        loadcurrent(img);
+    }
+    setTimeout("checkURL()", 100);
+}
+
 function preload() { 
 
     /* favor current image, if user clicked on `last' or something */
@@ -78,13 +115,22 @@ function preload() {
      * but rather load them one by one, in order to get
      * next ones faster, beginning with next to current
      */
-    for (i = current + 1; i < images.length && i <= current + 5; i++) { 
+    if (current + 1 < images.length && load(current + 1) == 0) {
+        setTimeout("preload()", 500);
+        return;
+    }
+    if (current - 1 >= 0 && load(current - 1) == 0) {
+        setTimeout("preload()", 500);
+        return;
+    }
+
+    for (i = current + 2; i < images.length && i <= current + 5; i++) { 
         if (load(i) == 0) {
             setTimeout("preload()", 500);
             return;
         }
     }
-    for (i = current - 1; i >= current - 3; i--) { 
+    for (i = current - 2; i >= current - 3; i--) { 
         if (i >= 0) {
             if (load(i) == 0) {
                 setTimeout("preload()", 500);
@@ -122,28 +168,13 @@ function init() {
 
     add_cookie('booh-preferred-size-~~theme~~=~~current_size~~')
 
-    /* retrieve GET parameters */
-    all_params = location.href.split("?")
-    if (all_params.length > 1) {
-        params = all_params[1].split("&");
-        for (i = 0; i < params.length; i++) {
-            keyvalue = params[i].split("=");
-            if (keyvalue[0] == "run_slideshow") {
-                toggle_slideshow();
-            }
-            if (keyvalue[0] == "current") {
-                for (i = 0; i < images.length; i++) {
-                    if (images[i] == keyvalue[1]) {
-                        current = i;
-                        break;
-                    }
-                }
-            }
-        }
+    if (getparam('run_slideshow')) {
+        toggle_slideshow();
     }
 
+    checkURL();
+
     preload();
-    display_current();
     if (images.length == 1) {
         document.getElementById("b_slideshow").disabled = true;
     }
@@ -192,6 +223,10 @@ function set_cursor_(value, element) {
 
 function set_cursor(value) {
     set_cursor_(value, document.getElementById('body'));
+    set_cursor_(value, document.getElementById('b_first'));
+    set_cursor_(value, document.getElementById('b_previous'));
+    set_cursor_(value, document.getElementById('b_next'));
+    set_cursor_(value, document.getElementById('b_last'));
 }
 
 function show_current_text() {
@@ -204,7 +239,7 @@ function show_current_text() {
             if (other_sizes[i] == "original") {
                 document.getElementById('link' + other_sizes[i]).href = eval("images_" + other_sizes[i] + "[current]");
             } else {
-                document.getElementById('link' + other_sizes[i]).href = 'image-' + other_sizes[i] + '.html?current=' + eval("images_" + other_sizes[i] + "[current]");
+                document.getElementById('link' + other_sizes[i]).href = 'image-' + other_sizes[i] + '.html#current=' + eval("images_" + other_sizes[i] + "[current]");
             }
         }
         document.getElementById('thumbnails').href = 'thumbnails-~~current_size~~.html#' + images[current];
@@ -216,7 +251,8 @@ function show_current_text() {
 }
 
 function display_current() {
-    eval("document.main_img.src = images[" + current + "]");
+    document.main_img.src = images[current];
+    window.location.href = 'image-~~current_size~~.html#current=' + images[current];
     show_current_text();
     update_sensibilities();
 }