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 showImage(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('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('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('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 avail_tags.innerHTML = "Loading...";
163 avail_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_available_tags'));
165 } // refreshAvailableTags()
168 * update selected-tags list
170 * this function queries an actual version of the tag-list
171 * for the selected tags from the server via AJAX.
173 function refreshSelectedTags()
175 // update selected tags
176 var selected_tags = document.getElementById("selected_tags");
177 selected_tags.innerHTML = "Loading...";
178 selected_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_selected_tags'));
180 } // refreshSelectedTags()
185 * this function will fetch the photo-index view from
186 * the server via AJAX. It's also used to browse through
187 * the photo-index pages
189 function showPhotoIndex(begin_with, last_photo)
191 var url = "rpc.php?action=show_photo_index";
192 if(begin_with != undefined)
193 url = url + '&begin_with=' + begin_with;
194 if(last_photo != undefined)
195 url = url + '&last_photo=' + last_photo;
197 HTML_AJAX.replace(document.getElementById("content"), encodeURI(url));
199 } // showPhotoIndex()
204 * this function will be called, to request a refresh of the
205 * photo index. this, for example, can be caused, when changing
208 function refreshPhotoIndex()
210 /* only invoke showPhotoIndex(), if photo-index is really shown */
211 if(document.getElementById("index") != undefined || startup == 1) {
216 } // refreshPhotoIndex()
221 * this function removes the focus-rectangle which may appear
222 * when click on a link. Not always beautiful.
224 function click(object)
232 * change current radio-button setting
234 * This function will check the radio-button with the given value.
235 * If no radio-button is currently displayed, this function will do
237 * If the given value does not exist, the existing radio buttons will
240 function setCheckedValue(condition, value) {
242 var count = condition.length;
243 if(count == undefined) {
244 condition.checked = (condition.value == value.toString());
247 for(var i = 0; i < count; i++) {
248 condition[i].checked = false;
249 if(condition[i].value == value.toString()) {
250 condition[i].checked = true;
254 } // setCheckedValue()
259 * This function will be invoked by starting
260 * any kind of search (tag-name, photo-name, date, ...).
262 function startSearch()
264 from_year = document.getElementById('fromyear').value;
265 from_month = document.getElementById('frommonth').value;
266 from_day = document.getElementById('fromday').value;
267 from = from_year +"-"+ from_month +"-"+ from_day;
268 to_year = document.getElementById('toyear').value;
269 to_month = document.getElementById('tomonth').value;
270 to_day = document.getElementById('today').value;
271 to = to_year +"-"+ to_month +"-"+ to_day;
273 var objTemp = new Object();
274 objTemp['action'] = 'search';
276 if(document.getElementsByName('searchfor_tag')[0].value != "") {
277 objTemp['for_tag'] = document.getElementsByName('searchfor_tag')[0].value;
279 if(document.getElementsByName('searchfor_name')[0].value != "") {
280 objTemp['for_name'] = document.getElementsByName('searchfor_name')[0].value;
282 if(document.getElementsByName('consider_date')[0].checked == true) {
283 objTemp['from'] = from;
287 var retr = HTML_AJAX.post('rpc.php', objTemp);
289 refreshAvailableTags();
290 refreshSelectedTags();
294 window.alert("Server message: "+ retr);
300 * enable/disable date search
302 * this function will either enable or disable the
303 * input fields for the date-search
305 function datesearch()
309 if(document.getElementsByName('consider_date')[0].checked == true) {
313 document.getElementById('fromyear').disabled = mode;
314 document.getElementById('frommonth').disabled = mode;
315 document.getElementById('fromday').disabled = mode;
316 document.getElementById('toyear').disabled = mode;
317 document.getElementById('tomonth').disabled = mode;
318 document.getElementById('today').disabled = mode;
325 * called for photo-index export. will return the
326 * selected mode via AJAX from the server.
328 function setViewMode(mode)
330 var exprt = document.getElementById('output');
331 exprt.innerHTML = "Loading...";
332 exprt.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_export&mode=' + mode));
337 * reset all search-fields
339 function clearSearch()
341 document.getElementsByName('searchfor_tag')[0].value = '';
342 document.getElementsByName('searchfor_name')[0].value = '';
344 if(document.getElementsByName('consider_date')[0].checked == true) {
345 document.getElementsByName('consider_date')[0].checked = false;
352 * if the client is planless, ask the server what to do
355 function AskServerWhatToDo()
357 return HTML_AJAX.grab(encodeURI('rpc.php?action=what_to_do'));
358 } // AskServerWhatToDo()
363 * this function will be called when the browser opens phpfspot
364 * the first time. It will fetch the tag-lists and will then
365 * switch to the right view, which the browser got told from
366 * the server (maybe someone hit the refresh button...).
368 function init_phpfspot(mode)
370 /* always load list of available tags */
371 refreshAvailableTags();
373 /* ask the server what we are currently displaying */
374 whattodo = AskServerWhatToDo();
376 if(whattodo == 'showpi' || whattodo == 'showpi_date') {
379 if(whattodo == 'showpi_tags') {
380 refreshSelectedTags();
383 if(whattodo == 'show_photo') {
384 if(photo = getPhotoToShow()) {
386 refreshSelectedTags();
393 * change background-color on mouse-over
395 function setBackGrdColor(item, color)
397 if(color == 'mouseover')
398 item.style.backgroundColor='#c6e9ff';
399 if(color == 'mouseout')
400 item.style.backgroundColor='#eeeeee';
401 if(color == 'mouseclick')
402 item.style.backgroundColor='#93A8CA';
404 } // setBackGrdColor()
407 * ask server, which photo needs to be shown
409 * when user press the refresh-button in a single-photo
410 * view or maybe enters the link via an external URL, the
411 * client does not know, what photo will be shown (dimensions...).
412 * But the server can tell this the browser.
414 function getPhotoToShow()
416 var photo_to_show = HTML_AJAX.grab(encodeURI('rpc.php?action=get_photo_to_show'));
418 // if no image needs to be shown, return false from here
419 if(photo_to_show == "")
422 return photo_to_show;
424 } // getPhotoToShow()
427 * a fake-zoom for photo
429 * a quick to let the browser do some zooming on
439 /* internet explorer */
440 if(document.images['photo'].width)
441 photo = document.images['photo'];
444 if(photo == undefined && document.getElementById('photo').width)
445 photo = document.getElementById('photo');
447 if(photo != undefined) {
449 if(origWidth == undefined)
450 origWidth = photo.width;
451 if(origHeight == undefined)
452 origHeight = photo.height;
455 new_w = photo.width * (1 + mod/100);
456 new_h = photo.height * (1 + mod/100);
458 photo.height = new_h;
460 if(photo_details_pos == undefined) {
461 photo_details_pos = findPos(document.getElementById('photo_details'),'left');
464 if((photo.offsetLeft + new_w) >= photo_details_pos-20) {
465 hidePhotoDetails('true');
468 hidePhotoDetails('false');
472 photo.width = origWidth;
473 photo.height = origHeight;
474 hidePhotoDetails('false');
481 * hides the photo details layin
483 * if the photo is getting zoomed quiet large, this will
484 * auto-hide (and also restore) the photo-details-box.
486 function hidePhotoDetails(mode)
490 if(photo_details = document.getElementById('photo_details')) {
492 photo_details.style.visibility = 'hidden';
493 photo_details.style.display = 'none';
496 photo_details.style.visibility = 'visible';
497 photo_details.style.display = '';
500 } // hidePhotoDetails()
505 function showCalendar(date_box, click_obj)
507 var calendar = document.getElementById('calendar');
508 var year = document.getElementById(date_box+'year').value;
509 var month = document.getElementById(date_box+'month').value;
510 if(date_box == 'from') {
511 var xpos = document.getElementById('frompic').offsetLeft;
512 var ypos = document.getElementById('frompic').offsetTop;
513 calendar_mode = 'from';
515 if(date_box == 'to') {
516 var xpos = document.getElementById('topic').offsetLeft;
517 var ypos = document.getElementById('topic').offsetTop;
518 calendar_mode = 'to';
520 calendar.style.left = xpos + 100 + 'px';
521 calendar.style.top = ypos + 80 + 'px';
523 if(calendar.style.visibility == "" || calendar.style.visibility == 'hidden') {
524 calendar.style.visibility = 'visible';
525 calendar.innerHTML = "Loading...";
526 calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix&year=' + year + '&month=' + month));
538 function hideCalendar()
540 var calendar = document.getElementById('calendar');
541 if(calendar.style.visibility != 'hidden') {
542 calendar.style.visibility = 'hidden';
548 * switch month in calendar
550 function setMonth(year, month, day)
552 var calendar = document.getElementById('calendar');
553 calendar.innerHTML = "Loading...";
554 calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix&year='+ year +'&month='+ month +'&day='+ day));
558 * get the user-selected date from the calendar and
559 * put it into the date-search boxes
561 function setCalendarDate(year, month, day)
563 document.getElementById(calendar_mode+'year').value = year;
564 document.getElementById(calendar_mode+'month').value = month;
565 document.getElementById(calendar_mode+'day').value = day;
568 } // setCalendarDate()
571 * reset phpfspot complelely and move to the begining
575 HTML_AJAX.grab(encodeURI('rpc.php?action=reset'));
577 refreshAvailableTags();
578 refreshSelectedTags();
584 * find objects with their class-name
586 function WSR_getElementsByClassName(oElm, strTagName, oClassNames){
587 var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
588 var arrReturnElements = new Array();
589 var arrRegExpClassNames = new Array();
590 if(typeof oClassNames == "object"){
591 for(var i=0; i<oClassNames.length; i++){
592 arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames[i].replace(/-/g, "\-") + "(\s|$)"));
596 arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames.replace(/-/g, "\-") + "(\s|$)"));
600 for(var j=0; j<arrElements.length; j++){
601 oElement = arrElements[j];
603 for(var k=0; k<arrRegExpClassNames.length; k++){
604 if(!arrRegExpClassNames[k].test(oElement.className)){
610 arrReturnElements.push(oElement);
613 return (arrReturnElements)
615 } // WSR_getElementsByClassName()
618 * javascript based photo preloading
620 function preloadPhotos(image_url) {
627 lbImg=WSR_getElementsByClassName(document,"img","thumb");
628 for(i=0;i<lbImg.length;i++){
629 lbImg[i].src=image_url[i];
630 // to not bomb the server with requests, give the page some time
631 // to load the images one by one. if a image exceeds the timeout,
632 // the next image will be loaded.
633 if(lbImg[i].complete != undefined && lbImg[i].complete != true) {
635 while(lbImg[i].complete != true && counting < timeout) {
636 window.setTimeout("noop()", waiting);
644 /* a function that does nothing */
650 function startSlideShow()
653 HTML_AJAX.grab(encodeURI('rpc.php?action=reset_slideshow'));
655 sliding = setInterval("nextSlide()", sliding_time*1000);
656 document.getElementById('stop_ico').src = "resources/32_stop.png";
659 clearInterval(sliding);
661 document.getElementById('stop_ico').src = "resources/32_play.png";
664 } // startSlideShow()
667 * switch to next slide
671 var next_img = HTML_AJAX.grab(encodeURI('rpc.php?action=get_next_slideshow_img'));
672 document.getElementById('slide_img').src = next_img;
677 * switch to previous slide
681 var prev_img = HTML_AJAX.grab(encodeURI('rpc.php?action=get_prev_slideshow_img'));
682 document.getElementById('slide_img').src = prev_img;
687 * interrupt slide show
689 function pauseSlideShow()
691 if(!sliding_paused) {
693 clearInterval(sliding);
694 document.getElementById('pause_ico').src = "resources/32_play.png";
698 sliding = setInterval("nextSlide()", sliding_time*1000);
699 document.getElementById('pause_ico').src = "resources/32_pause.png";
702 } // pauseSlideShow()
707 function startAutoBrowse()
711 autobrowse = setInterval("autoBrowse()", 5000);
714 clearInterval(autobrowse);
716 document.getElementById('autobrowse_ico').src = "resources/32_play.png";
719 } // startAutoBrowser()
724 function autoBrowse()
726 if(document.getElementById('next_link')) {
727 var next_link = document.getElementById('next_link').href;
728 window.location.href = next_link;
729 document.getElementById('autobrowse_ico').src = "resources/32_pause.png";
731 /* we have reached the last photo */
733 if(ab_ico = document.getElementById('autobrowse_ico'))
734 ab_ico.src = "resources/32_play.png";
735 clearInterval(autobrowse);
741 * initiate slider to modify slide-switching-speed
743 function initSlider()
745 var sliderEl = document.getElementById ? document.getElementById("slider-1") : null;
746 var inputEl = document.forms[0]["slider-input-1"];
747 var s = new Slider(sliderEl, inputEl);
750 s.setValue(sliding_time);
751 document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
752 s.onchange = function () {
753 sliding_time = s.getValue();
754 document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
755 if(!sliding_paused && sliding) {
756 clearInterval(sliding);
757 sliding = setInterval("nextSlide()", sliding_time*1000);
760 window.onresize = function () {
767 * if the sort-order (photo-name, date, ...) has been
768 * changed, update the photo-index view.
770 function update_sort_order(obj)
772 var objTemp = new Object();
773 objTemp['value'] = obj.options[obj.selectedIndex].value;
775 var retr = HTML_AJAX.post('rpc.php?action=update_sort_order', objTemp);
781 window.alert("Server message: "+ retr);
784 } // update_sort_order()
789 function keyDown(e) {
790 var evt = (e) ? e:(window.event) ? window.event:null;
793 var key = (evt.charCode) ? evt.charCode :
794 ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
797 if(key == 37) /* left curosr */ {
798 if(document.getElementById('prev_link')) {
799 var prev_link = document.getElementById('prev_link').href;
800 window.location.href = prev_link;
804 if(key == 38) /* up cursor */ {
806 if(key == 39) /* right curosr */ {
807 if(document.getElementById('next_link')) {
808 var next_link = document.getElementById('next_link').href;
809 window.location.href = next_link;
813 if(key == 73 && evt.altKey && evt.ctrlKey) /* ctrl+alt+i */ {
817 if(key == 82 && evt.altKey && evt.ctrlKey) /* ctrl+alt+r */ {
824 document.onkeydown=keyDown;
825 if(document.layers) {
826 document.captureEvents(Event.KEYDOWN);
829 // will be reseted by first viewing photo-index
832 var calendar_shown = 0;
833 var calendar_mode = '';
834 // auto-browsing & sliding
837 var sliding_paused = 0;
838 var sliding_time = 3;
842 // position of the last shown photo in photo-index
843 var photo_details_pos;