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 window.alert(whattodo);
378 if(whattodo == 'showpi' || whattodo == 'showpi_date') {
381 if(whattodo == 'showpi_tags') {
382 refreshSelectedTags();
385 if(whattodo == 'show_photo') {
386 if(photo = getPhotoToShow()) {
388 refreshSelectedTags();
395 * change background-color on mouse-over
397 function setBackGrdColor(item, color)
399 if(color == 'mouseover')
400 item.style.backgroundColor='#c6e9ff';
401 if(color == 'mouseout')
402 item.style.backgroundColor='#eeeeee';
403 if(color == 'mouseclick')
404 item.style.backgroundColor='#93A8CA';
406 } // setBackGrdColor()
409 * ask server, which photo needs to be shown
411 * when user press the refresh-button in a single-photo
412 * view or maybe enters the link via an external URL, the
413 * client does not know, what photo will be shown (dimensions...).
414 * But the server can tell this the browser.
416 function getPhotoToShow()
418 var photo_to_show = HTML_AJAX.grab(encodeURI('rpc.php?action=get_photo_to_show'));
420 // if no image needs to be shown, return false from here
421 if(photo_to_show == "")
424 return photo_to_show;
426 } // getPhotoToShow()
429 * a fake-zoom for photo
431 * a quick to let the browser do some zooming on
441 /* internet explorer */
442 if(document.images['photo'].width)
443 photo = document.images['photo'];
446 if(photo == undefined && document.getElementById('photo').width)
447 photo = document.getElementById('photo');
449 if(photo != undefined) {
451 if(origWidth == undefined)
452 origWidth = photo.width;
453 if(origHeight == undefined)
454 origHeight = photo.height;
457 new_w = photo.width * (1 + mod/100);
458 new_h = photo.height * (1 + mod/100);
460 photo.height = new_h;
462 if(photo_details_pos == undefined) {
463 photo_details_pos = findPos(document.getElementById('photo_details'),'left');
466 if((photo.offsetLeft + new_w) >= photo_details_pos-20) {
467 hidePhotoDetails('true');
470 hidePhotoDetails('false');
474 photo.width = origWidth;
475 photo.height = origHeight;
476 hidePhotoDetails('false');
483 * hides the photo details layin
485 * if the photo is getting zoomed quiet large, this will
486 * auto-hide (and also restore) the photo-details-box.
488 function hidePhotoDetails(mode)
492 if(photo_details = document.getElementById('photo_details')) {
494 photo_details.style.visibility = 'hidden';
495 photo_details.style.display = 'none';
498 photo_details.style.visibility = 'visible';
499 photo_details.style.display = '';
502 } // hidePhotoDetails()
507 function showCalendar(date_box, click_obj)
509 var calendar = document.getElementById('calendar');
510 var year = document.getElementById(date_box+'year').value;
511 var month = document.getElementById(date_box+'month').value;
512 if(date_box == 'from') {
513 var xpos = document.getElementById('frompic').offsetLeft;
514 var ypos = document.getElementById('frompic').offsetTop;
515 calendar_mode = 'from';
517 if(date_box == 'to') {
518 var xpos = document.getElementById('topic').offsetLeft;
519 var ypos = document.getElementById('topic').offsetTop;
520 calendar_mode = 'to';
522 calendar.style.left = xpos + 100 + 'px';
523 calendar.style.top = ypos + 80 + 'px';
525 if(calendar.style.visibility == "" || calendar.style.visibility == 'hidden') {
526 calendar.style.visibility = 'visible';
527 calendar.innerHTML = "Loading...";
528 calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix&year=' + year + '&month=' + month));
540 function hideCalendar()
542 var calendar = document.getElementById('calendar');
543 if(calendar.style.visibility != 'hidden') {
544 calendar.style.visibility = 'hidden';
550 * switch month in calendar
552 function setMonth(year, month, day)
554 var calendar = document.getElementById('calendar');
555 calendar.innerHTML = "Loading...";
556 calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix&year='+ year +'&month='+ month +'&day='+ day));
560 * get the user-selected date from the calendar and
561 * put it into the date-search boxes
563 function setCalendarDate(year, month, day)
565 document.getElementById(calendar_mode+'year').value = year;
566 document.getElementById(calendar_mode+'month').value = month;
567 document.getElementById(calendar_mode+'day').value = day;
570 } // setCalendarDate()
573 * reset phpfspot complelely and move to the begining
577 HTML_AJAX.grab(encodeURI('rpc.php?action=reset'));
579 refreshAvailableTags();
580 refreshSelectedTags();
586 * find objects with their class-name
588 function WSR_getElementsByClassName(oElm, strTagName, oClassNames){
589 var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
590 var arrReturnElements = new Array();
591 var arrRegExpClassNames = new Array();
592 if(typeof oClassNames == "object"){
593 for(var i=0; i<oClassNames.length; i++){
594 arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames[i].replace(/-/g, "\-") + "(\s|$)"));
598 arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames.replace(/-/g, "\-") + "(\s|$)"));
602 for(var j=0; j<arrElements.length; j++){
603 oElement = arrElements[j];
605 for(var k=0; k<arrRegExpClassNames.length; k++){
606 if(!arrRegExpClassNames[k].test(oElement.className)){
612 arrReturnElements.push(oElement);
615 return (arrReturnElements)
617 } // WSR_getElementsByClassName()
620 * javascript based photo preloading
622 function preloadPhotos(image_url) {
629 lbImg=WSR_getElementsByClassName(document,"img","thumb");
630 for(i=0;i<lbImg.length;i++){
631 lbImg[i].src=image_url[i];
632 // to not bomb the server with requests, give the page some time
633 // to load the images one by one. if a image exceeds the timeout,
634 // the next image will be loaded.
635 if(lbImg[i].complete != undefined && lbImg[i].complete != true) {
637 while(lbImg[i].complete != true && counting < timeout) {
638 window.setTimeout("noop()", waiting);
646 /* a function that does nothing */
652 function startSlideShow()
655 HTML_AJAX.grab(encodeURI('rpc.php?action=reset_slideshow'));
657 sliding = setInterval("nextSlide()", sliding_time*1000);
658 document.getElementById('stop_ico').src = "resources/32_stop.png";
661 clearInterval(sliding);
663 document.getElementById('stop_ico').src = "resources/32_play.png";
666 } // startSlideShow()
669 * switch to next slide
673 var next_img = HTML_AJAX.grab(encodeURI('rpc.php?action=get_next_slideshow_img'));
674 document.getElementById('slide_img').src = next_img;
679 * switch to previous slide
683 var prev_img = HTML_AJAX.grab(encodeURI('rpc.php?action=get_prev_slideshow_img'));
684 document.getElementById('slide_img').src = prev_img;
689 * interrupt slide show
691 function pauseSlideShow()
693 if(!sliding_paused) {
695 clearInterval(sliding);
696 document.getElementById('pause_ico').src = "resources/32_play.png";
700 sliding = setInterval("nextSlide()", sliding_time*1000);
701 document.getElementById('pause_ico').src = "resources/32_pause.png";
704 } // pauseSlideShow()
709 function startAutoBrowse()
713 autobrowse = setInterval("autoBrowse()", 5000);
716 clearInterval(autobrowse);
718 document.getElementById('autobrowse_ico').src = "resources/32_play.png";
721 } // startAutoBrowser()
726 function autoBrowse()
728 if(document.getElementById('next_link')) {
729 var next_link = document.getElementById('next_link').href;
730 window.location.href = next_link;
731 document.getElementById('autobrowse_ico').src = "resources/32_pause.png";
733 /* we have reached the last photo */
735 if(ab_ico = document.getElementById('autobrowse_ico'))
736 ab_ico.src = "resources/32_play.png";
737 clearInterval(autobrowse);
743 * initiate slider to modify slide-switching-speed
745 function initSlider()
747 var sliderEl = document.getElementById ? document.getElementById("slider-1") : null;
748 var inputEl = document.forms[0]["slider-input-1"];
749 var s = new Slider(sliderEl, inputEl);
752 s.setValue(sliding_time);
753 document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
754 s.onchange = function () {
755 sliding_time = s.getValue();
756 document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
757 if(!sliding_paused && sliding) {
758 clearInterval(sliding);
759 sliding = setInterval("nextSlide()", sliding_time*1000);
762 window.onresize = function () {
769 * if the sort-order (photo-name, date, ...) has been
770 * changed, update the photo-index view.
772 function update_sort_order(obj)
774 var objTemp = new Object();
775 objTemp['value'] = obj.options[obj.selectedIndex].value;
777 var retr = HTML_AJAX.post('rpc.php?action=update_sort_order', objTemp);
783 window.alert("Server message: "+ retr);
786 } // update_sort_order()
791 function keyDown(e) {
792 var evt = (e) ? e:(window.event) ? window.event:null;
795 var key = (evt.charCode) ? evt.charCode :
796 ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
799 if(key == 37) /* left curosr */ {
800 if(document.getElementById('prev_link')) {
801 var prev_link = document.getElementById('prev_link').href;
802 window.location.href = prev_link;
806 if(key == 38) /* up cursor */ {
808 if(key == 39) /* right curosr */ {
809 if(document.getElementById('next_link')) {
810 var next_link = document.getElementById('next_link').href;
811 window.location.href = next_link;
815 if(key == 73 && evt.altKey && evt.ctrlKey) /* ctrl+alt+i */ {
819 if(key == 82 && evt.altKey && evt.ctrlKey) /* ctrl+alt+r */ {
826 document.onkeydown=keyDown;
827 if(document.layers) {
828 document.captureEvents(Event.KEYDOWN);
831 // will be reseted by first viewing photo-index
834 var calendar_shown = 0;
835 var calendar_mode = '';
836 // auto-browsing & sliding
839 var sliding_paused = 0;
840 var sliding_time = 3;
844 // position of the last shown photo in photo-index
845 var photo_details_pos;