1 /***************************************************************************
3 * Copyright (c) by Andreas Unterkircher, unki@netshadow.at
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 ***************************************************************************/
25 * this function will be called by client and fetches
26 * the single-photo view via AJAX from the server.
27 * Furthermore it will scrollup the browser to the top
28 * position so the image become visibile immediatley.
30 function showImage(id, scrollup)
32 /* is phpfspot skeleton really displayed? */
33 if(!document.getElementById('content'))
36 var content = document.getElementById('content');
38 /* blank the screen */
39 if(scrollup != undefined) {
40 content.innerHTML = "";
43 /* fetch single-photo view from server */
44 HTML_AJAX.replace(content, encodeURI('rpc.php?action=showphoto&id=' + id));
46 /* scroll the window up to the top */
47 if(scrollup != undefined) {
51 /* delete some global vars */
52 delete(origHeight); origHeight = undefined;
53 delete(origWidth); origWidth = undefined;
54 delete(photo_details_pos); photo_details_pos = undefined;
59 * scroll browser to the last shown photo
61 * this function will be called when user returns from single-photo
62 * to the photo index. It will scroll down the window (if possible)
63 * to the position of the last shown photo.
65 function moveToThumb(thumb_id)
67 if(thumb_id == undefined)
70 if(thumbimg = document.getElementById('thumbimg' + thumb_id)) {
71 window.scrollTo(0, findPos(thumbimg,'top')-100);
77 * return position of object
79 * this function returns the position of an object.
80 * depending on the parameter 'direction' it will either
81 * return the X or Y position.
83 function findPos(obj, direction) {
85 if (obj.offsetParent) {
87 if(direction == 'left')
88 cur += obj.offsetLeft;
89 if(direction == 'top')
91 } while (obj = obj.offsetParent);
98 * opens the credits page
100 function showCredits()
102 var credits = document.getElementById("content");
103 credits.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=showcredits'));
108 * tag-selection handling
110 * this function is getting called by client to either
113 * - modify tag-match condition
115 * It will then fetch the result from the server via AJAX
116 * and updates the tag-selection.
118 function Tags(mode, id)
120 var objTemp = new Object();
123 // add tag to users session
124 objTemp['action'] = 'addtag';
127 else if(mode == "del") {
128 // del tag from users session
129 objTemp['action'] = 'deltag';
132 else if(mode == "condition") {
133 setCheckedValue(id, id.value);
134 objTemp['action'] = 'tagcondition';
135 objTemp['mode'] = id.value;
138 var retr = HTML_AJAX.post('rpc.php', objTemp);
140 refreshAvailableTags();
141 refreshSelectedTags();
145 window.alert("Server message: "+ retr);
151 * update available-tags tag-cloud
153 * this function queries an actual version of the tag-cloud
154 * for the available (not-selected) tags from the server via
157 function refreshAvailableTags()
159 // update available tags
160 var avail_tags = document.getElementById('available_tags');
161 avail_tags.innerHTML = "Loading...";
162 avail_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_available_tags'));
164 } // refreshAvailableTags()
167 * update selected-tags list
169 * this function queries an actual version of the tag-list
170 * for the selected tags from the server via AJAX.
172 function refreshSelectedTags()
174 // update selected tags
175 var selected_tags = document.getElementById("selected_tags");
176 selected_tags.innerHTML = "Loading...";
177 selected_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_selected_tags'));
179 } // refreshSelectedTags()
184 * this function will fetch the photo-index view from
185 * the server via AJAX. It's also used to browse through
186 * the photo-index pages
188 function showPhotoIndex(begin_with, last_photo)
190 var url = "rpc.php?action=show_photo_index";
191 if(begin_with != undefined)
192 url = url + '&begin_with=' + begin_with;
193 if(last_photo != undefined)
194 url = url + '&last_photo=' + last_photo;
196 HTML_AJAX.replace(document.getElementById("content"), encodeURI(url));
198 } // showPhotoIndex()
203 * this function will be called, to request a refresh of the
204 * photo index. this, for example, can be caused, when changing
207 function refreshPhotoIndex()
209 /* only invoke showPhotoIndex(), if photo-index is really shown */
210 if(document.getElementById("index") != undefined || startup == 1) {
215 } // refreshPhotoIndex()
220 * this function removes the focus-rectangle which may appear
221 * when click on a link. Not always beautiful.
223 function click(object)
231 * change current radio-button setting
233 * This function will check the radio-button with the given value.
234 * If no radio-button is currently displayed, this function will do
236 * If the given value does not exist, the existing radio buttons will
239 function setCheckedValue(condition, value) {
241 var count = condition.length;
242 if(count == undefined) {
243 condition.checked = (condition.value == value.toString());
246 for(var i = 0; i < count; i++) {
247 condition[i].checked = false;
248 if(condition[i].value == value.toString()) {
249 condition[i].checked = true;
253 } // setCheckedValue()
258 * This function will be invoked by starting
259 * any kind of search (tag-name, photo-name, date, ...).
261 function startSearch()
263 from_year = document.getElementById('fromyear').value;
264 from_month = document.getElementById('frommonth').value;
265 from_day = document.getElementById('fromday').value;
266 from = from_year +"-"+ from_month +"-"+ from_day;
267 to_year = document.getElementById('toyear').value;
268 to_month = document.getElementById('tomonth').value;
269 to_day = document.getElementById('today').value;
270 to = to_year +"-"+ to_month +"-"+ to_day;
272 var objTemp = new Object();
273 objTemp['action'] = 'search';
275 if(document.getElementsByName('searchfor_tag')[0].value != "") {
276 objTemp['for_tag'] = document.getElementsByName('searchfor_tag')[0].value;
278 if(document.getElementsByName('searchfor_name')[0].value != "") {
279 objTemp['for_name'] = document.getElementsByName('searchfor_name')[0].value;
281 if(document.getElementsByName('consider_date')[0].checked == true) {
282 objTemp['from'] = from;
286 var retr = HTML_AJAX.post('rpc.php', objTemp);
288 refreshAvailableTags();
289 refreshSelectedTags();
293 window.alert("Server message: "+ retr);
299 * enable/disable date search
301 * this function will either enable or disable the
302 * input fields for the date-search
304 function datesearch()
308 if(document.getElementsByName('consider_date')[0].checked == true) {
312 document.getElementById('fromyear').disabled = mode;
313 document.getElementById('frommonth').disabled = mode;
314 document.getElementById('fromday').disabled = mode;
315 document.getElementById('toyear').disabled = mode;
316 document.getElementById('tomonth').disabled = mode;
317 document.getElementById('today').disabled = mode;
324 * called for photo-index export. will return the
325 * selected mode via AJAX from the server.
327 function setViewMode(mode)
329 var exprt = document.getElementById('output');
330 exprt.innerHTML = "Loading...";
331 exprt.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_export&mode=' + mode));
336 * reset all search-fields
338 function clearSearch()
340 document.getElementsByName('searchfor_tag')[0].value = '';
341 document.getElementsByName('searchfor_name')[0].value = '';
343 if(document.getElementsByName('consider_date')[0].checked == true) {
344 document.getElementsByName('consider_date')[0].checked = false;
351 * if the client is planless, ask the server what to do
354 function AskServerWhatToDo()
356 return HTML_AJAX.grab(encodeURI('rpc.php?action=what_to_do'));
357 } // AskServerWhatToDo()
362 * this function will be called when the browser opens phpfspot
363 * the first time. It will fetch the tag-lists and will then
364 * switch to the right view, which the browser got told from
365 * the server (maybe someone hit the refresh button...).
367 function init_phpfspot(mode)
369 /* always load list of available tags */
370 refreshAvailableTags();
372 /* ask the server what we are currently displaying */
373 whattodo = AskServerWhatToDo();
375 if(whattodo == 'showpi' || whattodo == 'showpi_date') {
378 if(whattodo == 'showpi_tags') {
379 refreshSelectedTags();
382 if(whattodo == 'show_photo') {
383 if(photo = getPhotoToShow()) {
385 refreshSelectedTags();
392 * change background-color on mouse-over
394 function setBackGrdColor(item, color)
396 if(color == 'mouseover')
397 item.style.backgroundColor='#c6e9ff';
398 if(color == 'mouseout')
399 item.style.backgroundColor='#eeeeee';
400 if(color == 'mouseclick')
401 item.style.backgroundColor='#93A8CA';
403 } // setBackGrdColor()
406 * ask server, which photo needs to be shown
408 * when user press the refresh-button in a single-photo
409 * view or maybe enters the link via an external URL, the
410 * client does not know, what photo will be shown (dimensions...).
411 * But the server can tell this the browser.
413 function getPhotoToShow()
415 var photo_to_show = HTML_AJAX.grab(encodeURI('rpc.php?action=get_photo_to_show'));
417 // if no image needs to be shown, return false from here
418 if(photo_to_show == "")
421 return photo_to_show;
423 } // getPhotoToShow()
426 * a fake-zoom for photo
428 * a quick to let the browser do some zooming on
438 /* internet explorer */
439 if(document.images['photo'].width)
440 photo = document.images['photo'];
443 if(photo == undefined && document.getElementById('photo').width)
444 photo = document.getElementById('photo');
446 if(photo != undefined) {
448 if(origWidth == undefined)
449 origWidth = photo.width;
450 if(origHeight == undefined)
451 origHeight = photo.height;
454 new_w = photo.width * (1 + mod/100);
455 new_h = photo.height * (1 + mod/100);
457 photo.height = new_h;
459 if(photo_details_pos == undefined) {
460 photo_details_pos = findPos(document.getElementById('photo_details'),'left');
463 if((photo.offsetLeft + new_w) >= photo_details_pos-20) {
464 hidePhotoDetails('true');
467 hidePhotoDetails('false');
471 photo.width = origWidth;
472 photo.height = origHeight;
473 hidePhotoDetails('false');
480 * hides the photo details layin
482 * if the photo is getting zoomed quiet large, this will
483 * auto-hide (and also restore) the photo-details-box.
485 function hidePhotoDetails(mode)
489 if(photo_details = document.getElementById('photo_details')) {
491 photo_details.style.visibility = 'hidden';
492 photo_details.style.display = 'none';
495 photo_details.style.visibility = 'visible';
496 photo_details.style.display = '';
499 } // hidePhotoDetails()
504 function showCalendar(date_box, click_obj)
506 var calendar = document.getElementById('calendar');
507 var year = document.getElementById(date_box+'year').value;
508 var month = document.getElementById(date_box+'month').value;
509 if(date_box == 'from') {
510 var xpos = document.getElementById('frompic').offsetLeft;
511 var ypos = document.getElementById('frompic').offsetTop;
512 calendar_mode = 'from';
514 if(date_box == 'to') {
515 var xpos = document.getElementById('topic').offsetLeft;
516 var ypos = document.getElementById('topic').offsetTop;
517 calendar_mode = 'to';
519 calendar.style.left = xpos + 100 + 'px';
520 calendar.style.top = ypos + 80 + 'px';
522 if(calendar.style.visibility == "" || calendar.style.visibility == 'hidden') {
523 calendar.style.visibility = 'visible';
524 calendar.innerHTML = "Loading...";
525 calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix&year=' + year + '&month=' + month));
537 function hideCalendar()
539 var calendar = document.getElementById('calendar');
540 if(calendar.style.visibility != 'hidden') {
541 calendar.style.visibility = 'hidden';
547 * switch month in calendar
549 function setMonth(year, month, day)
551 var calendar = document.getElementById('calendar');
552 calendar.innerHTML = "Loading...";
553 calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix&year='+ year +'&month='+ month +'&day='+ day));
557 * get the user-selected date from the calendar and
558 * put it into the date-search boxes
560 function setCalendarDate(year, month, day)
562 document.getElementById(calendar_mode+'year').value = year;
563 document.getElementById(calendar_mode+'month').value = month;
564 document.getElementById(calendar_mode+'day').value = day;
567 } // setCalendarDate()
570 * reset phpfspot complelely and move to the begining
574 HTML_AJAX.grab(encodeURI('rpc.php?action=reset'));
576 refreshAvailableTags();
577 refreshSelectedTags();
583 * find objects with their class-name
585 function WSR_getElementsByClassName(oElm, strTagName, oClassNames){
586 var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
587 var arrReturnElements = new Array();
588 var arrRegExpClassNames = new Array();
589 if(typeof oClassNames == "object"){
590 for(var i=0; i<oClassNames.length; i++){
591 arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames[i].replace(/-/g, "\-") + "(\s|$)"));
595 arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames.replace(/-/g, "\-") + "(\s|$)"));
599 for(var j=0; j<arrElements.length; j++){
600 oElement = arrElements[j];
602 for(var k=0; k<arrRegExpClassNames.length; k++){
603 if(!arrRegExpClassNames[k].test(oElement.className)){
609 arrReturnElements.push(oElement);
612 return (arrReturnElements)
614 } // WSR_getElementsByClassName()
617 * javascript based photo preloading
619 function preloadPhotos(image_url) {
626 lbImg=WSR_getElementsByClassName(document,"img","thumb");
627 for(i=0;i<lbImg.length;i++){
628 lbImg[i].src=image_url[i];
629 // to not bomb the server with requests, give the page some time
630 // to load the images one by one. if a image exceeds the timeout,
631 // the next image will be loaded.
632 if(lbImg[i].complete != undefined && lbImg[i].complete != true) {
634 while(lbImg[i].complete != true && counting < timeout) {
635 window.setTimeout("noop()", waiting);
643 /* a function that does nothing */
649 function startSlideShow()
652 HTML_AJAX.grab(encodeURI('rpc.php?action=reset_slideshow'));
654 sliding = setInterval("nextSlide()", sliding_time*1000);
655 document.getElementById('stop_ico').src = "resources/32_stop.png";
658 clearInterval(sliding);
660 document.getElementById('stop_ico').src = "resources/32_play.png";
663 } // startSlideShow()
666 * switch to next slide
670 var next_img = HTML_AJAX.grab(encodeURI('rpc.php?action=get_next_slideshow_img'));
671 document.getElementById('slide_img').src = next_img;
676 * switch to previous slide
680 var prev_img = HTML_AJAX.grab(encodeURI('rpc.php?action=get_prev_slideshow_img'));
681 document.getElementById('slide_img').src = prev_img;
686 * interrupt slide show
688 function pauseSlideShow()
690 if(!sliding_paused) {
692 clearInterval(sliding);
693 document.getElementById('pause_ico').src = "resources/32_play.png";
697 sliding = setInterval("nextSlide()", sliding_time*1000);
698 document.getElementById('pause_ico').src = "resources/32_pause.png";
701 } // pauseSlideShow()
706 function startAutoBrowse()
710 autobrowse = setInterval("autoBrowse()", 5000);
713 clearInterval(autobrowse);
715 document.getElementById('autobrowse_ico').src = "resources/32_play.png";
718 } // startAutoBrowser()
723 function autoBrowse()
725 if(document.getElementById('next_link')) {
726 var next_link = document.getElementById('next_link').href;
727 window.location.href = next_link;
728 document.getElementById('autobrowse_ico').src = "resources/32_pause.png";
730 /* we have reached the last photo */
732 if(ab_ico = document.getElementById('autobrowse_ico'))
733 ab_ico.src = "resources/32_play.png";
734 clearInterval(autobrowse);
740 * initiate slider to modify slide-switching-speed
742 function initSlider()
744 var sliderEl = document.getElementById ? document.getElementById("slider-1") : null;
745 var inputEl = document.forms[0]["slider-input-1"];
746 var s = new Slider(sliderEl, inputEl);
749 s.setValue(sliding_time);
750 document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
751 s.onchange = function () {
752 sliding_time = s.getValue();
753 document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
754 if(!sliding_paused && sliding) {
755 clearInterval(sliding);
756 sliding = setInterval("nextSlide()", sliding_time*1000);
759 window.onresize = function () {
766 * if the sort-order (photo-name, date, ...) has been
767 * changed, update the photo-index view.
769 function update_sort_order(obj)
771 var objTemp = new Object();
772 objTemp['value'] = obj.options[obj.selectedIndex].value;
774 var retr = HTML_AJAX.post('rpc.php?action=update_sort_order', objTemp);
780 window.alert("Server message: "+ retr);
783 } // update_sort_order()
788 function keyDown(e) {
789 var evt = (e) ? e:(window.event) ? window.event:null;
792 var key = (evt.charCode) ? evt.charCode :
793 ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
796 if(key == 37) /* left curosr */ {
797 if(document.getElementById('prev_link')) {
798 var prev_link = document.getElementById('prev_link').href;
799 window.location.href = prev_link;
803 if(key == 38) /* up cursor */ {
805 if(key == 39) /* right curosr */ {
806 if(document.getElementById('next_link')) {
807 var next_link = document.getElementById('next_link').href;
808 window.location.href = next_link;
812 if(key == 73 && evt.altKey && evt.ctrlKey) /* ctrl+alt+i */ {
816 if(key == 82 && evt.altKey && evt.ctrlKey) /* ctrl+alt+r */ {
823 document.onkeydown=keyDown;
824 if(document.layers) {
825 document.captureEvents(Event.KEYDOWN);
828 // will be reseted by first viewing photo-index
831 var calendar_shown = 0;
832 var calendar_mode = '';
833 // auto-browsing & sliding
836 var sliding_paused = 0;
837 var sliding_time = 3;
841 // position of the last shown photo in photo-index
842 var photo_details_pos;