auto-browse needs to use the 16x16 icons instead of 32x32 which are used in slideshow
[phpfspot.git] / phpfspot.js
index ae202a0c004f69d0e7eb792c19f62711d787b571..3421583e0c630e6a57cc1e461caf38bb8866c4b5 100644 (file)
  ***************************************************************************/
 
 /**
- * display image
+ * show photo
  *
  * this function will be called by client and fetches
  * the single-photo view via AJAX from the server.
  * Furthermore it will scrollup the browser to the top
  * position so the image become visibile immediatley.
  */
-function showImage(id, scrollup)
+function showPhoto(id, scrollup)
 {
    /* is phpfspot skeleton really displayed? */
    if(!document.getElementById('content'))
@@ -54,7 +54,7 @@ function showImage(id, scrollup)
    delete(origWidth); origWidth = undefined;
    delete(photo_details_pos); photo_details_pos = undefined;
 
-} // showImage()
+} // showPhoto()
 
 /**
  * scroll browser to the last shown photo
@@ -277,16 +277,24 @@ function startSearch()
    var objTemp = new Object();
    objTemp['action'] = 'search';
 
-   if(document.getElementsByName('searchfor_tag')[0].value != "") {
+   if(document.getElementsByName('searchfor_tag')[0] != undefined &&
+      document.getElementsByName('searchfor_tag')[0].value != "") {
       objTemp['for_tag'] = document.getElementsByName('searchfor_tag')[0].value;
    }
-   if(document.getElementsByName('searchfor_name')[0].value != "") {
+   if(document.getElementsByName('searchfor_name')[0] != undefined &&
+      document.getElementsByName('searchfor_name')[0].value != "") {
       objTemp['for_name'] = document.getElementsByName('searchfor_name')[0].value;
    }
-   if(document.getElementsByName('consider_date')[0].checked == true) {
+   if(document.getElementsByName('consider_date')[0] != undefined &&
+      document.getElementsByName('consider_date')[0].checked == true) {
       objTemp['from'] = from;
       objTemp['to'] = to;
    }
+   if(document.getElementsByName('consider_rate')[0] != undefined &&
+      document.getElementsByName('consider_rate')[0].checked == true) {
+      objTemp['rate_from'] = rate_search['from'];
+      objTemp['rate_to'] = rate_search['to'];
+   }
 
    var retr = HTML_AJAX.post(web_path + '/rpc.php', objTemp);
    if(retr == "ok") {
@@ -329,8 +337,13 @@ function datesearch()
  * called for photo-index export. will return the
  * selected mode via AJAX from the server.
  */
-function setViewMode(mode)
+function setViewMode(srv_webpath, mode)
 {
+   if(srv_webpath != undefined)
+      web_path = srv_webpath;
+   else
+      web_path = '';
+
    var exprt = document.getElementById('output');
    exprt.innerHTML = "Loading...";
    exprt.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_export&mode=' + mode));
@@ -342,13 +355,20 @@ function setViewMode(mode)
  */
 function clearSearch()
 {
-   document.getElementsByName('searchfor_tag')[0].value = '';
-   document.getElementsByName('searchfor_name')[0].value = '';
+   if(document.getElementsByName('searchfor_tag')[0] != undefined)
+      document.getElementsByName('searchfor_tag')[0].value = '';
+   if(document.getElementsByName('searchfor_name')[0] != undefined)
+      document.getElementsByName('searchfor_name')[0].value = '';
 
-   if(document.getElementsByName('consider_date')[0].checked == true) {
+   if(document.getElementsByName('consider_date')[0] != undefined &&
+      document.getElementsByName('consider_date')[0].checked == true) {
       document.getElementsByName('consider_date')[0].checked = false;
       datesearch();
-   }  
+   }
+   if(document.getElementsByName('consider_rate')[0] != undefined &&
+      document.getElementsByName('consider_rate')[0].checked == true) {
+      document.getElementsByName('consider_rate')[0].checked = false;
+   }
 
 } // clearSearch()
 
@@ -398,7 +418,7 @@ function init_phpfspot(srv_webpath)
    }
    if(whattodo == 'show_photo') {
       if(photo = getPhotoToShow()) {
-         showImage(photo);
+         showPhoto(photo);
          refreshSelectedTags();
       }
    }
@@ -640,17 +660,19 @@ function preloadPhotos(image_url) {
    var waiting = 100;
    var counting;
 
-   lbImg=WSR_getElementsByClassName(document,"img","thumb");
-   for(i=0;i<lbImg.length;i++){
-      lbImg[i].src=image_url[i];
-      // to not bomb the server with requests, give the page some time
-      // to load the images one by one. if a image exceeds the timeout,
-      // the next image will be loaded.
-      if(lbImg[i].complete != undefined && lbImg[i].complete != true) {
-         counting = 0;
-         while(lbImg[i].complete != true && counting < timeout) {
-            window.setTimeout("noop()", waiting);
-            counting+=waiting;
+   lbImg = WSR_getElementsByClassName(document,"img","thumb");
+   if(lbImg != undefined) {
+      for(i=0;i<lbImg.length;i++){
+         lbImg[i].src=image_url[i];
+         // to not bomb the server with requests, give the page some time
+         // to load the images one by one. if a image exceeds the timeout,
+         // the next image will be loaded.
+         if(lbImg[i].complete != undefined && lbImg[i].complete != true) {
+            counting = 0;
+            while(lbImg[i].complete != true && counting < timeout) {
+               window.setTimeout("noop()", waiting);
+               counting+=waiting;
+            }
          }
       }
    }
@@ -663,8 +685,13 @@ function noop() {}
 /**
  * start slideshow
  */
-function startSlideShow()
+function startSlideShow(srv_webpath)
 {
+   if(srv_webpath != undefined)
+      web_path = srv_webpath;
+   else
+      web_path = '';
+
    if(!sliding) {
       HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=reset_slideshow'));
       nextSlide();
@@ -742,12 +769,12 @@ function autoBrowse()
    if(document.getElementById('next_link')) {
       var next_link = document.getElementById('next_link').href;
       window.location.href = next_link;
-      document.getElementById('autobrowse_ico').src = web_path + "/resources/32_pause.png";
+      document.getElementById('autobrowse_ico').src = web_path + "/resources/16_pause.png";
    }
    /* we have reached the last photo */
    else {
       if(ab_ico = document.getElementById('autobrowse_ico'))
-         ab_ico.src = web_path + "/resources/32_play.png";
+         ab_ico.src = web_path + "/resources/16_play.png";
       clearInterval(autobrowse);
    }
 
@@ -799,6 +826,64 @@ function update_sort_order(obj)
 
 } // update_sort_order()
 
+/**
+ * show rate stars
+ *
+ * this function will show the requested amount of
+ * rate-stars.
+ *
+ * @param string mode
+ * @param int level
+ */
+function show_rate(mode, level)
+{
+   var i;
+
+   for(i = 1; i <= 5; i++) {
+      if(i <= level) {
+         document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/star.png';
+      }
+      else {
+         document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/empty_rate.png';
+      }
+   }
+
+} // show_rate()
+
+/**
+ * set rate stars
+ *
+ *
+ * this function will set the requested rate-stars-amount into a global
+ * variable (which will then later be used on form-submit) and will also
+ * update the display.
+ *
+ * @param string mode
+ * @param int level
+ */
+function set_rate(mode, level)
+{
+   rate_search[mode] = level;
+   show_rate(mode, level);
+
+} // set_rate()
+
+/**
+ * reset rate stars
+ *
+ * this function will reset the rate-star to their initial value.
+ *
+ * @param string mode
+ */
+function reset_rate(mode)
+{
+   if(rate_search[mode] == undefined)
+      rate_search[mode] = 0;
+
+   show_rate(mode, rate_search[mode]);
+
+} // reset_rate()
+
 /**
  * handle key events
  */
@@ -858,3 +943,4 @@ var origWidth;
 // position of the last shown photo in photo-index
 var photo_details_pos;
 var web_path;
+var rate_search = new Array();