1 /***************************************************************************
3 * phpfspot, presents your F-Spot photo collection in Web browsers.
5 * Copyright (c) by Andreas Unterkircher
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
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 ***************************************************************************/
26 * this function will be called by client and fetches
27 * the single-photo view via AJAX from the server.
28 * Furthermore it will scrollup the browser to the top
29 * position so the image become visibile immediatley.
31 function showPhoto(id, scrollup)
33 /* is phpfspot skeleton really displayed? */
34 if(!document.getElementById('content'))
37 var content = document.getElementById('content');
39 /* blank the screen */
40 if(scrollup != undefined) {
41 content.innerHTML = "";
44 /* fetch single-photo view from server */
45 HTML_AJAX.replace(content, encodeURI(web_path + '/rpc.php?action=showphoto&id=' + id));
47 /* scroll the window up to the top */
48 if(scrollup != undefined) {
52 /* delete some global vars */
53 delete(origHeight); origHeight = undefined;
54 delete(origWidth); origWidth = undefined;
55 delete(photo_details_pos); photo_details_pos = undefined;
60 * scroll browser to the last shown photo
62 * this function will be called when user returns from single-photo
63 * to the photo index. It will scroll down the window (if possible)
64 * to the position of the last shown photo.
66 function moveToThumb(thumb_id)
68 if(thumb_id == undefined)
71 if(thumbimg = document.getElementById('thumbimg' + thumb_id)) {
72 window.scrollTo(0, findPos(thumbimg,'top')-100);
78 * return position of object
80 * this function returns the position of an object.
81 * depending on the parameter 'direction' it will either
82 * return the X or Y position.
84 function findPos(obj, direction) {
86 if (obj.offsetParent) {
88 if(direction == 'left')
89 cur += obj.offsetLeft;
90 if(direction == 'top')
92 } while (obj = obj.offsetParent);
99 * opens the credits page
101 function showCredits()
103 var credits = document.getElementById("content");
104 credits.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=showcredits'));
109 * tag-selection handling
111 * this function is getting called by client to either
114 * - modify tag-match condition
116 * It will then fetch the result from the server via AJAX
117 * and updates the tag-selection.
119 function Tags(mode, id)
121 var objTemp = new Object();
124 // add tag to users session
125 objTemp['action'] = 'addtag';
128 else if(mode == "del") {
129 // del tag from users session
130 objTemp['action'] = 'deltag';
133 else if(mode == "condition") {
134 setCheckedValue(id, id.value);
135 objTemp['action'] = 'tagcondition';
136 objTemp['mode'] = id.value;
139 var retr = HTML_AJAX.post(web_path + '/rpc.php', objTemp);
141 refreshAvailableTags();
142 refreshSelectedTags();
146 window.alert("Server message: "+ retr);
152 * update available-tags tag-cloud
154 * this function queries an actual version of the tag-cloud
155 * for the available (not-selected) tags from the server via
158 function refreshAvailableTags()
160 // update available tags
161 var avail_tags = document.getElementById('available_tags');
162 if(avail_tags != undefined) {
163 avail_tags.innerHTML = "Loading...";
164 avail_tags.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=show_available_tags'));
167 } // refreshAvailableTags()
170 * update selected-tags list
172 * this function queries an actual version of the tag-list
173 * for the selected tags from the server via AJAX.
175 function refreshSelectedTags()
177 // update selected tags
178 var selected_tags = document.getElementById("selected_tags");
179 if(selected_tags != undefined) {
180 selected_tags.innerHTML = "Loading...";
181 selected_tags.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=show_selected_tags'));
184 } // refreshSelectedTags()
189 * this function will fetch the photo-index view from
190 * the server via AJAX. It's also used to browse through
191 * the photo-index pages
193 function showPhotoIndex(begin_with, last_photo)
195 var url = web_path + "/rpc.php?action=show_photo_index";
196 if(begin_with != undefined)
197 url = url + '&begin_with=' + begin_with;
198 if(last_photo != undefined)
199 url = url + '&last_photo=' + last_photo;
201 HTML_AJAX.replace(document.getElementById("content"), encodeURI(url));
203 } // showPhotoIndex()
208 * this function will be called, to request a refresh of the
209 * photo index. this, for example, can be caused, when changing
212 function refreshPhotoIndex()
214 /* only invoke showPhotoIndex(), if photo-index is really shown */
215 if(document.getElementById("index") != undefined || startup == 1) {
220 } // refreshPhotoIndex()
225 * this function removes the focus-rectangle which may appear
226 * when click on a link. Not always beautiful.
228 function click(object)
236 * change current radio-button setting
238 * This function will check the radio-button with the given value.
239 * If no radio-button is currently displayed, this function will do
241 * If the given value does not exist, the existing radio buttons will
244 function setCheckedValue(condition, value) {
246 var count = condition.length;
247 if(count == undefined) {
248 condition.checked = (condition.value == value.toString());
251 for(var i = 0; i < count; i++) {
252 condition[i].checked = false;
253 if(condition[i].value == value.toString()) {
254 condition[i].checked = true;
258 } // setCheckedValue()
263 * This function will be invoked by starting
264 * any kind of search (tag-name, photo-name, date, ...).
266 function startSearch()
268 if(document.getElementById('date_from').value != undefined) {
269 date_from = document.getElementById('date_from').value;
271 if(document.getElementById('date_to').value != undefined) {
272 date_to = document.getElementById('date_to').value;
275 var objTemp = new Object();
276 objTemp['action'] = 'search';
278 if(document.getElementsByName('searchfor_tag')[0] != undefined &&
279 document.getElementsByName('searchfor_tag')[0].value != "") {
280 objTemp['for_tag'] = document.getElementsByName('searchfor_tag')[0].value;
282 if(document.getElementsByName('searchfor_name')[0] != undefined &&
283 document.getElementsByName('searchfor_name')[0].value != "") {
284 objTemp['for_name'] = document.getElementsByName('searchfor_name')[0].value;
286 if(document.getElementsByName('consider_date')[0] != undefined &&
287 document.getElementsByName('consider_date')[0].checked == true) {
288 objTemp['date_from'] = date_from;
289 objTemp['date_to'] = date_to;
291 if(document.getElementsByName('consider_rate')[0] != undefined &&
292 document.getElementsByName('consider_rate')[0].checked == true) {
293 objTemp['rate_from'] = rate_search['from'];
294 objTemp['rate_to'] = rate_search['to'];
297 var retr = HTML_AJAX.post(web_path + '/rpc.php', objTemp);
299 refreshAvailableTags();
300 refreshSelectedTags();
304 window.alert("Server message: "+ retr);
310 * enable/disable date search
312 * this function will either enable or disable the
313 * input fields for the date-search
315 function datesearch()
319 if(document.getElementsByName('consider_date')[0].checked == true) {
323 document.getElementById('date_from').disabled = mode;
324 document.getElementById('date_to').disabled = mode;
331 * called for photo-index export. will return the
332 * selected mode via AJAX from the server.
334 function setViewMode(srv_webpath, mode)
336 if(srv_webpath != undefined)
337 web_path = srv_webpath;
341 var exprt = document.getElementById('output');
342 exprt.innerHTML = "Loading...";
343 exprt.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_export&mode=' + mode));
348 * reset all search-fields
350 function clearSearch()
352 if(document.getElementsByName('searchfor_tag')[0] != undefined)
353 document.getElementsByName('searchfor_tag')[0].value = '';
354 if(document.getElementsByName('searchfor_name')[0] != undefined)
355 document.getElementsByName('searchfor_name')[0].value = '';
357 if(document.getElementsByName('consider_date')[0] != undefined &&
358 document.getElementsByName('consider_date')[0].checked == true) {
359 document.getElementsByName('consider_date')[0].checked = false;
362 if(document.getElementsByName('consider_rate')[0] != undefined &&
363 document.getElementsByName('consider_rate')[0].checked == true) {
364 document.getElementsByName('consider_rate')[0].checked = false;
370 * if the client is planless, ask the server what to do
373 function AskServerWhatToDo()
375 return HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=what_to_do'));
377 } // AskServerWhatToDo()
382 * this function will be called when the browser opens phpfspot
383 * the first time. It will fetch the tag-lists and will then
384 * switch to the right view, which the browser got told from
385 * the server (maybe someone hit the refresh button...).
387 * as parameter the server can set the correct webpath.
388 * espacialley when using user-friendly url's, the browser
389 * does not know the correct URLs to address images, stylesheets,
392 function init_phpfspot(srv_webpath)
394 if(srv_webpath != undefined)
395 web_path = srv_webpath;
399 /* always load list of available tags */
400 //this should not be more necessary since 4.5.08
401 //refreshAvailableTags();
403 /* ask the server what we are currently displaying */
404 whattodo = AskServerWhatToDo();
406 if(whattodo == 'showpi' || whattodo == 'showpi_date') {
409 if(whattodo == 'showpi_tags') {
410 refreshSelectedTags();
413 if(whattodo == 'show_photo') {
414 if(photo = getPhotoToShow()) {
416 refreshSelectedTags();
423 * change background-color on mouse-over
425 function setBackGrdColor(item, color)
427 if(color == 'mouseover')
428 item.style.backgroundColor='#c6e9ff';
429 if(color == 'mouseout')
430 item.style.backgroundColor='#eeeeee';
431 if(color == 'mouseclick')
432 item.style.backgroundColor='#93A8CA';
434 } // setBackGrdColor()
437 * ask server, which photo needs to be shown
439 * when user press the refresh-button in a single-photo
440 * view or maybe enters the link via an external URL, the
441 * client does not know, what photo will be shown (dimensions...).
442 * But the server can tell this the browser.
444 function getPhotoToShow()
446 var photo_to_show = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_photo_to_show'));
448 // if no image needs to be shown, return false from here
449 if(photo_to_show == "")
452 return photo_to_show;
454 } // getPhotoToShow()
457 * a fake-zoom for photo
459 * a quick to let the browser do some zooming on
469 /* internet explorer */
470 if(document.images['photo'].width)
471 photo = document.images['photo'];
474 if(photo == undefined && document.getElementById('photo').width)
475 photo = document.getElementById('photo');
477 if(photo != undefined) {
479 if(origWidth == undefined)
480 origWidth = photo.width;
481 if(origHeight == undefined)
482 origHeight = photo.height;
485 new_w = photo.width * (1 + mod/100);
486 new_h = photo.height * (1 + mod/100);
488 photo.height = new_h;
490 if(photo_details_pos == undefined) {
491 photo_details_pos = findPos(document.getElementById('photo_details'),'left');
494 if((photo.offsetLeft + new_w) >= photo_details_pos-20) {
495 hidePhotoDetails('true');
498 hidePhotoDetails('false');
502 photo.width = origWidth;
503 photo.height = origHeight;
504 hidePhotoDetails('false');
511 * hides the photo details layin
513 * if the photo is getting zoomed quiet large, this will
514 * auto-hide (and also restore) the photo-details-box.
516 function hidePhotoDetails(mode)
520 if(photo_details = document.getElementById('photo_details')) {
522 photo_details.style.visibility = 'hidden';
523 photo_details.style.display = 'none';
526 photo_details.style.visibility = 'visible';
527 photo_details.style.display = '';
530 } // hidePhotoDetails()
535 function showCalendar(date_box, click_obj)
537 var calendar = document.getElementById('calendar');
538 var userdate = document.getElementById('date_' + date_box).value;
540 if(date_box == 'from') {
541 var xpos = document.getElementById('frompic').offsetLeft;
542 var ypos = document.getElementById('frompic').offsetTop;
543 calendar_mode = 'from';
545 if(date_box == 'to') {
546 var xpos = document.getElementById('topic').offsetLeft;
547 var ypos = document.getElementById('topic').offsetTop;
548 calendar_mode = 'to';
550 calendar.style.left = xpos + 100 + 'px';
551 calendar.style.top = ypos + 80 + 'px';
553 if(calendar.style.visibility == "" || calendar.style.visibility == 'hidden') {
554 calendar.style.visibility = 'visible';
555 calendar.innerHTML = "Loading...";
556 calendar.innerHTML = HTML_AJAX.grab(encodeURI(web_path +'/rpc.php?action=get_calendar_matrix&date=' + userdate));
568 function hideCalendar()
570 var calendar = document.getElementById('calendar');
571 if(calendar.style.visibility != 'hidden') {
572 calendar.style.visibility = 'hidden';
578 * switch month in calendar
580 function setMonth(year, month, day)
582 var calendar = document.getElementById('calendar');
583 calendar.innerHTML = "Loading...";
584 calendar.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_calendar_matrix&date='+ year +'-'+ month +'-'+ day));
588 * get the user-selected date from the calendar and
589 * put it into the date-search boxes
591 function setCalendarDate(userdate)
593 document.getElementById('date_'+calendar_mode).value = userdate;
596 } // setCalendarDate()
599 * reset phpfspot complelely and move to the begining
603 HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=reset'));
605 refreshAvailableTags();
606 refreshSelectedTags();
612 * find objects with their class-name
614 function WSR_getElementsByClassName(oElm, strTagName, oClassNames){
615 var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
616 var arrReturnElements = new Array();
617 var arrRegExpClassNames = new Array();
618 if(typeof oClassNames == "object"){
619 for(var i=0; i<oClassNames.length; i++){
620 arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames[i].replace(/-/g, "\-") + "(\s|$)"));
624 arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames.replace(/-/g, "\-") + "(\s|$)"));
628 for(var j=0; j<arrElements.length; j++){
629 oElement = arrElements[j];
631 for(var k=0; k<arrRegExpClassNames.length; k++){
632 if(!arrRegExpClassNames[k].test(oElement.className)){
638 arrReturnElements.push(oElement);
641 return (arrReturnElements)
643 } // WSR_getElementsByClassName()
646 * javascript based photo preloading
648 function preloadPhotos(image_url) {
655 lbImg = WSR_getElementsByClassName(document,"img","thumb");
656 if(lbImg != undefined) {
657 for(i=0;i<lbImg.length;i++){
658 lbImg[i].src=image_url[i];
659 // to not bomb the server with requests, give the page some time
660 // to load the images one by one. if a image exceeds the timeout,
661 // the next image will be loaded.
662 if(lbImg[i].complete != undefined && lbImg[i].complete != true) {
664 while(lbImg[i].complete != true && counting < timeout) {
665 window.setTimeout("noop()", waiting);
674 /* a function that does nothing */
680 function startSlideShow(srv_webpath)
682 if(srv_webpath != undefined)
683 web_path = srv_webpath;
688 HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=reset_slideshow'));
690 sliding = setInterval("nextSlide()", sliding_time*1000);
691 document.getElementById('stop_ico').src = web_path + "/resources/32_stop.png";
694 clearInterval(sliding);
696 document.getElementById('stop_ico').src = web_path + "/resources/32_play.png";
699 } // startSlideShow()
702 * switch to next slide
706 var next_img = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_next_slideshow_img'));
707 document.getElementById('slide_img').src = next_img;
712 * switch to previous slide
716 var prev_img = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_prev_slideshow_img'));
717 document.getElementById('slide_img').src = prev_img;
722 * interrupt slide show
724 function pauseSlideShow()
726 if(!sliding_paused) {
728 clearInterval(sliding);
729 document.getElementById('pause_ico').src = web_path + "/resources/32_play.png";
733 sliding = setInterval("nextSlide()", sliding_time*1000);
734 document.getElementById('pause_ico').src = web_path + "/resources/32_pause.png";
737 } // pauseSlideShow()
742 function startAutoBrowse()
746 autobrowse = setInterval("autoBrowse()", 5000);
749 clearInterval(autobrowse);
751 document.getElementById('autobrowse_ico').src = web_path + "/resources/16_play.png";
754 } // startAutoBrowser()
759 function autoBrowse()
761 if(document.getElementById('next_link')) {
762 var next_link = document.getElementById('next_link').href;
763 window.location.href = next_link;
764 document.getElementById('autobrowse_ico').src = web_path + "/resources/16_pause.png";
766 /* we have reached the last photo */
768 if(ab_ico = document.getElementById('autobrowse_ico'))
769 ab_ico.src = web_path + "/resources/16_play.png";
770 clearInterval(autobrowse);
776 * initiate slider to modify slide-switching-speed
778 function initSlider()
780 var sliderEl = document.getElementById ? document.getElementById("slider-1") : null;
781 var inputEl = document.forms[0]["slider-input-1"];
782 var s = new Slider(sliderEl, inputEl);
785 s.setValue(sliding_time);
786 document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
787 s.onchange = function () {
788 sliding_time = s.getValue();
789 document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
790 if(!sliding_paused && sliding) {
791 clearInterval(sliding);
792 sliding = setInterval("nextSlide()", sliding_time*1000);
795 window.onresize = function () {
802 * if the sort-order (photo-name, date, ...) has been
803 * changed, update the photo-index view.
805 function update_sort_order(obj)
807 var objTemp = new Object();
808 objTemp['value'] = obj.options[obj.selectedIndex].value;
810 var retr = HTML_AJAX.post(web_path + '/rpc.php?action=update_sort_order', objTemp);
816 window.alert("Server message: "+ retr);
819 } // update_sort_order()
822 * if the photo-version ѕelect-box has changed, set the newly
823 * choosen photo version as the to-be-displayed photo version
825 function update_photo_version(obj, current_photo)
827 var objTemp = new Object();
828 objTemp['photo_version'] = obj.options[obj.selectedIndex].value;
829 objTemp['photo_idx'] = current_photo;
831 var retr = HTML_AJAX.post(web_path + '/rpc.php?action=update_photo_version', objTemp);
834 showPhoto(current_photo);
837 window.alert("Server message: "+ retr);
840 } // update_photo_version()
845 * this function will show the requested amount of
851 function show_rate(mode, level)
855 for(i = 1; i <= 5; i++) {
857 document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/star.png';
860 document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/empty_rate.png';
870 * this function will set the requested rate-stars-amount into a global
871 * variable (which will then later be used on form-submit) and will also
872 * update the display.
877 function set_rate(mode, level)
879 rate_search[mode] = level;
880 show_rate(mode, level);
887 * this function will reset the rate-star to their initial value.
891 function reset_rate(mode)
893 if(rate_search[mode] == undefined)
894 rate_search[mode] = 0;
896 show_rate(mode, rate_search[mode]);
903 function keyDown(e) {
904 var evt = (e) ? e:(window.event) ? window.event:null;
907 var key = (evt.charCode) ? evt.charCode :
908 ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
911 if(key == 37) /* left curosr */ {
912 if(document.getElementById('prev_link')) {
913 var prev_link = document.getElementById('prev_link').href;
914 window.location.href = prev_link;
918 if(key == 38) /* up cursor */ {
920 if(key == 39) /* right curosr */ {
921 if(document.getElementById('next_link')) {
922 var next_link = document.getElementById('next_link').href;
923 window.location.href = next_link;
927 if(key == 73 && evt.altKey && evt.ctrlKey) /* ctrl+alt+i */ {
931 if(key == 82 && evt.altKey && evt.ctrlKey) /* ctrl+alt+r */ {
938 document.onkeydown=keyDown;
939 if(document.layers) {
940 document.captureEvents(Event.KEYDOWN);
943 // will be reseted by first viewing photo-index
946 var calendar_shown = 0;
947 var calendar_mode = '';
948 // auto-browsing & sliding
951 var sliding_paused = 0;
952 var sliding_time = 3;
956 // position of the last shown photo in photo-index
957 var photo_details_pos;
959 var rate_search = new Array();