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 from_year = document.getElementById('fromyear').value;
269 from_month = document.getElementById('frommonth').value;
270 from_day = document.getElementById('fromday').value;
271 from = from_year +"-"+ from_month +"-"+ from_day;
272 to_year = document.getElementById('toyear').value;
273 to_month = document.getElementById('tomonth').value;
274 to_day = document.getElementById('today').value;
275 to = to_year +"-"+ to_month +"-"+ to_day;
277 var objTemp = new Object();
278 objTemp['action'] = 'search';
280 if(document.getElementsByName('searchfor_tag')[0] != undefined &&
281 document.getElementsByName('searchfor_tag')[0].value != "") {
282 objTemp['for_tag'] = document.getElementsByName('searchfor_tag')[0].value;
284 if(document.getElementsByName('searchfor_name')[0] != undefined &&
285 document.getElementsByName('searchfor_name')[0].value != "") {
286 objTemp['for_name'] = document.getElementsByName('searchfor_name')[0].value;
288 if(document.getElementsByName('consider_date')[0] != undefined &&
289 document.getElementsByName('consider_date')[0].checked == true) {
290 objTemp['from'] = from;
293 if(document.getElementsByName('consider_rate')[0] != undefined &&
294 document.getElementsByName('consider_rate')[0].checked == true) {
295 objTemp['rate_from'] = rate_search['from'];
296 objTemp['rate_to'] = rate_search['to'];
299 var retr = HTML_AJAX.post(web_path + '/rpc.php', objTemp);
301 refreshAvailableTags();
302 refreshSelectedTags();
306 window.alert("Server message: "+ retr);
312 * enable/disable date search
314 * this function will either enable or disable the
315 * input fields for the date-search
317 function datesearch()
321 if(document.getElementsByName('consider_date')[0].checked == true) {
325 document.getElementById('fromyear').disabled = mode;
326 document.getElementById('frommonth').disabled = mode;
327 document.getElementById('fromday').disabled = mode;
328 document.getElementById('toyear').disabled = mode;
329 document.getElementById('tomonth').disabled = mode;
330 document.getElementById('today').disabled = mode;
337 * called for photo-index export. will return the
338 * selected mode via AJAX from the server.
340 function setViewMode(mode)
342 var exprt = document.getElementById('output');
343 exprt.innerHTML = "Loading...";
344 exprt.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_export&mode=' + mode));
349 * reset all search-fields
351 function clearSearch()
353 if(document.getElementsByName('searchfor_tag')[0] != undefined)
354 document.getElementsByName('searchfor_tag')[0].value = '';
355 if(document.getElementsByName('searchfor_name')[0] != undefined)
356 document.getElementsByName('searchfor_name')[0].value = '';
358 if(document.getElementsByName('consider_date')[0] != undefined &&
359 document.getElementsByName('consider_date')[0].checked == true) {
360 document.getElementsByName('consider_date')[0].checked = false;
363 if(document.getElementsByName('consider_rate')[0] != undefined &&
364 document.getElementsByName('consider_rate')[0].checked == true) {
365 document.getElementsByName('consider_rate')[0].checked = false;
371 * if the client is planless, ask the server what to do
374 function AskServerWhatToDo()
376 return HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=what_to_do'));
378 } // AskServerWhatToDo()
383 * this function will be called when the browser opens phpfspot
384 * the first time. It will fetch the tag-lists and will then
385 * switch to the right view, which the browser got told from
386 * the server (maybe someone hit the refresh button...).
388 * as parameter the server can set the correct webpath.
389 * espacialley when using user-friendly url's, the browser
390 * does not know the correct URLs to address images, stylesheets,
393 function init_phpfspot(srv_webpath)
395 if(srv_webpath != undefined)
396 web_path = srv_webpath;
400 /* always load list of available tags */
401 //this should not be more necessary since 4.5.08
402 //refreshAvailableTags();
404 /* ask the server what we are currently displaying */
405 whattodo = AskServerWhatToDo();
407 if(whattodo == 'showpi' || whattodo == 'showpi_date') {
410 if(whattodo == 'showpi_tags') {
411 refreshSelectedTags();
414 if(whattodo == 'show_photo') {
415 if(photo = getPhotoToShow()) {
417 refreshSelectedTags();
424 * change background-color on mouse-over
426 function setBackGrdColor(item, color)
428 if(color == 'mouseover')
429 item.style.backgroundColor='#c6e9ff';
430 if(color == 'mouseout')
431 item.style.backgroundColor='#eeeeee';
432 if(color == 'mouseclick')
433 item.style.backgroundColor='#93A8CA';
435 } // setBackGrdColor()
438 * ask server, which photo needs to be shown
440 * when user press the refresh-button in a single-photo
441 * view or maybe enters the link via an external URL, the
442 * client does not know, what photo will be shown (dimensions...).
443 * But the server can tell this the browser.
445 function getPhotoToShow()
447 var photo_to_show = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_photo_to_show'));
449 // if no image needs to be shown, return false from here
450 if(photo_to_show == "")
453 return photo_to_show;
455 } // getPhotoToShow()
458 * a fake-zoom for photo
460 * a quick to let the browser do some zooming on
470 /* internet explorer */
471 if(document.images['photo'].width)
472 photo = document.images['photo'];
475 if(photo == undefined && document.getElementById('photo').width)
476 photo = document.getElementById('photo');
478 if(photo != undefined) {
480 if(origWidth == undefined)
481 origWidth = photo.width;
482 if(origHeight == undefined)
483 origHeight = photo.height;
486 new_w = photo.width * (1 + mod/100);
487 new_h = photo.height * (1 + mod/100);
489 photo.height = new_h;
491 if(photo_details_pos == undefined) {
492 photo_details_pos = findPos(document.getElementById('photo_details'),'left');
495 if((photo.offsetLeft + new_w) >= photo_details_pos-20) {
496 hidePhotoDetails('true');
499 hidePhotoDetails('false');
503 photo.width = origWidth;
504 photo.height = origHeight;
505 hidePhotoDetails('false');
512 * hides the photo details layin
514 * if the photo is getting zoomed quiet large, this will
515 * auto-hide (and also restore) the photo-details-box.
517 function hidePhotoDetails(mode)
521 if(photo_details = document.getElementById('photo_details')) {
523 photo_details.style.visibility = 'hidden';
524 photo_details.style.display = 'none';
527 photo_details.style.visibility = 'visible';
528 photo_details.style.display = '';
531 } // hidePhotoDetails()
536 function showCalendar(date_box, click_obj)
538 var calendar = document.getElementById('calendar');
539 var year = document.getElementById(date_box+'year').value;
540 var month = document.getElementById(date_box+'month').value;
541 if(date_box == 'from') {
542 var xpos = document.getElementById('frompic').offsetLeft;
543 var ypos = document.getElementById('frompic').offsetTop;
544 calendar_mode = 'from';
546 if(date_box == 'to') {
547 var xpos = document.getElementById('topic').offsetLeft;
548 var ypos = document.getElementById('topic').offsetTop;
549 calendar_mode = 'to';
551 calendar.style.left = xpos + 100 + 'px';
552 calendar.style.top = ypos + 80 + 'px';
554 if(calendar.style.visibility == "" || calendar.style.visibility == 'hidden') {
555 calendar.style.visibility = 'visible';
556 calendar.innerHTML = "Loading...";
557 calendar.innerHTML = HTML_AJAX.grab(encodeURI(web_path +'/rpc.php?action=get_calendar_matrix&year=' + year + '&month=' + month));
569 function hideCalendar()
571 var calendar = document.getElementById('calendar');
572 if(calendar.style.visibility != 'hidden') {
573 calendar.style.visibility = 'hidden';
579 * switch month in calendar
581 function setMonth(year, month, day)
583 var calendar = document.getElementById('calendar');
584 calendar.innerHTML = "Loading...";
585 calendar.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_calendar_matrix&year='+ year +'&month='+ month +'&day='+ day));
589 * get the user-selected date from the calendar and
590 * put it into the date-search boxes
592 function setCalendarDate(year, month, day)
594 document.getElementById(calendar_mode+'year').value = year;
595 document.getElementById(calendar_mode+'month').value = month;
596 document.getElementById(calendar_mode+'day').value = day;
599 } // setCalendarDate()
602 * reset phpfspot complelely and move to the begining
606 HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=reset'));
608 refreshAvailableTags();
609 refreshSelectedTags();
615 * find objects with their class-name
617 function WSR_getElementsByClassName(oElm, strTagName, oClassNames){
618 var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
619 var arrReturnElements = new Array();
620 var arrRegExpClassNames = new Array();
621 if(typeof oClassNames == "object"){
622 for(var i=0; i<oClassNames.length; i++){
623 arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames[i].replace(/-/g, "\-") + "(\s|$)"));
627 arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames.replace(/-/g, "\-") + "(\s|$)"));
631 for(var j=0; j<arrElements.length; j++){
632 oElement = arrElements[j];
634 for(var k=0; k<arrRegExpClassNames.length; k++){
635 if(!arrRegExpClassNames[k].test(oElement.className)){
641 arrReturnElements.push(oElement);
644 return (arrReturnElements)
646 } // WSR_getElementsByClassName()
649 * javascript based photo preloading
651 function preloadPhotos(image_url) {
658 lbImg=WSR_getElementsByClassName(document,"img","thumb");
659 for(i=0;i<lbImg.length;i++){
660 lbImg[i].src=image_url[i];
661 // to not bomb the server with requests, give the page some time
662 // to load the images one by one. if a image exceeds the timeout,
663 // the next image will be loaded.
664 if(lbImg[i].complete != undefined && lbImg[i].complete != true) {
666 while(lbImg[i].complete != true && counting < timeout) {
667 window.setTimeout("noop()", waiting);
675 /* a function that does nothing */
681 function startSlideShow()
684 HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=reset_slideshow'));
686 sliding = setInterval("nextSlide()", sliding_time*1000);
687 document.getElementById('stop_ico').src = web_path + "/resources/32_stop.png";
690 clearInterval(sliding);
692 document.getElementById('stop_ico').src = web_path + "/resources/32_play.png";
695 } // startSlideShow()
698 * switch to next slide
702 var next_img = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_next_slideshow_img'));
703 document.getElementById('slide_img').src = next_img;
708 * switch to previous slide
712 var prev_img = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_prev_slideshow_img'));
713 document.getElementById('slide_img').src = prev_img;
718 * interrupt slide show
720 function pauseSlideShow()
722 if(!sliding_paused) {
724 clearInterval(sliding);
725 document.getElementById('pause_ico').src = web_path + "/resources/32_play.png";
729 sliding = setInterval("nextSlide()", sliding_time*1000);
730 document.getElementById('pause_ico').src = web_path + "/resources/32_pause.png";
733 } // pauseSlideShow()
738 function startAutoBrowse()
742 autobrowse = setInterval("autoBrowse()", 5000);
745 clearInterval(autobrowse);
747 document.getElementById('autobrowse_ico').src = web_path + "/resources/32_play.png";
750 } // startAutoBrowser()
755 function autoBrowse()
757 if(document.getElementById('next_link')) {
758 var next_link = document.getElementById('next_link').href;
759 window.location.href = next_link;
760 document.getElementById('autobrowse_ico').src = web_path + "/resources/32_pause.png";
762 /* we have reached the last photo */
764 if(ab_ico = document.getElementById('autobrowse_ico'))
765 ab_ico.src = web_path + "/resources/32_play.png";
766 clearInterval(autobrowse);
772 * initiate slider to modify slide-switching-speed
774 function initSlider()
776 var sliderEl = document.getElementById ? document.getElementById("slider-1") : null;
777 var inputEl = document.forms[0]["slider-input-1"];
778 var s = new Slider(sliderEl, inputEl);
781 s.setValue(sliding_time);
782 document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
783 s.onchange = function () {
784 sliding_time = s.getValue();
785 document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
786 if(!sliding_paused && sliding) {
787 clearInterval(sliding);
788 sliding = setInterval("nextSlide()", sliding_time*1000);
791 window.onresize = function () {
798 * if the sort-order (photo-name, date, ...) has been
799 * changed, update the photo-index view.
801 function update_sort_order(obj)
803 var objTemp = new Object();
804 objTemp['value'] = obj.options[obj.selectedIndex].value;
806 var retr = HTML_AJAX.post(web_path + '/rpc.php?action=update_sort_order', objTemp);
812 window.alert("Server message: "+ retr);
815 } // update_sort_order()
820 * this function will show the requested amount of
826 function show_rate(mode, level)
830 for(i = 1; i <= 5; i++) {
832 document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/star.png';
835 document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/empty_rate.png';
845 * this function will set the requested rate-stars-amount into a global
846 * variable (which will then later be used on form-submit) and will also
847 * update the display.
852 function set_rate(mode, level)
854 rate_search[mode] = level;
855 show_rate(mode, level);
862 * this function will reset the rate-star to their initial value.
866 function reset_rate(mode)
868 if(rate_search[mode] == undefined)
869 rate_search[mode] = 0;
871 show_rate(mode, rate_search[mode]);
878 function keyDown(e) {
879 var evt = (e) ? e:(window.event) ? window.event:null;
882 var key = (evt.charCode) ? evt.charCode :
883 ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
886 if(key == 37) /* left curosr */ {
887 if(document.getElementById('prev_link')) {
888 var prev_link = document.getElementById('prev_link').href;
889 window.location.href = prev_link;
893 if(key == 38) /* up cursor */ {
895 if(key == 39) /* right curosr */ {
896 if(document.getElementById('next_link')) {
897 var next_link = document.getElementById('next_link').href;
898 window.location.href = next_link;
902 if(key == 73 && evt.altKey && evt.ctrlKey) /* ctrl+alt+i */ {
906 if(key == 82 && evt.altKey && evt.ctrlKey) /* ctrl+alt+r */ {
913 document.onkeydown=keyDown;
914 if(document.layers) {
915 document.captureEvents(Event.KEYDOWN);
918 // will be reseted by first viewing photo-index
921 var calendar_shown = 0;
922 var calendar_mode = '';
923 // auto-browsing & sliding
926 var sliding_paused = 0;
927 var sliding_time = 3;
931 // position of the last shown photo in photo-index
932 var photo_details_pos;
934 var rate_search = new Array();