issue27, on gallery export use links which will guide back the user into phpfspot...
[phpfspot.git] / phpfspot.js
1 function showImage(id)
2 {
3    var image_div = document.getElementById("content");
4    image_div.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=showphoto&id=' + id));
5 }
6
7 function showCredits()
8 {
9    var credits = document.getElementById("content");
10    credits.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=showcredits'));
11 }
12
13 function Tags(mode, id)
14 {
15    if(mode == "add") {
16       // add the tag to users session
17       HTML_AJAX.grab(encodeURI('rpc.php?action=addtag&id=' + id));
18    }
19    else if(mode == "del") {
20       // del the tag from users session
21       HTML_AJAX.grab(encodeURI('rpc.php?action=deltag&id=' + id));
22    }
23    else if(mode == "reset") {
24       HTML_AJAX.grab(encodeURI('rpc.php?action=reset'));
25       clearSearch();
26    }
27    else if(mode == "condition") {
28       setCheckedValue(id, id.value);
29       HTML_AJAX.grab(encodeURI('rpc.php?action=tagcondition&mode=' + id.value));
30    }
31    
32    refreshAvailableTags();
33    refreshSelectedTags();
34    refreshPhotoIndex();
35
36 }
37
38 function refreshAvailableTags()
39 {
40    // update available tags
41    var avail_tags = document.getElementById('available_tags');
42    avail_tags.innerHTML = "Loading...";
43    avail_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_available_tags'));
44 }
45
46 function refreshSelectedTags()
47 {
48    // update selected tags
49    var selected_tags = document.getElementById("selected_tags");
50    selected_tags.innerHTML = "Loading...";
51    selected_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_selected_tags'));
52
53    // if no tags are currently selected, return false from here
54    if(selected_tags.innerHTML == "")
55       return false;
56    
57    return true;
58
59 }
60
61 function showPhotoIndex(begin_with)
62 {
63    if(begin_with == undefined)
64       HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index'));
65    else
66       HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index&begin_with=' + begin_with));
67 }
68
69 function showBubbleDetails(object, id, direction)
70 {
71    HTML_AJAX.replace(object, encodeURI('rpc.php?action=showbubbledetails&id=' + id + '&direction=" + direction'));
72 }
73
74 // if photo index is currently shown, refresh it
75 function refreshPhotoIndex()
76 {
77    if(document.getElementById("matrix") != undefined || startup == 1) {
78       showPhotoIndex();
79       startup = 0;
80    }
81 }
82
83 function click(object)
84 {
85    if(object.blur)
86       object.blur();
87
88 }
89
90 // set the radio button with the given value as being checked
91 // do nothing if there are no radio buttons
92 // if the given value does not exist, all the radio buttons
93 // are reset to unchecked
94 function setCheckedValue(condition, value) {
95
96    var count = condition.length;
97    if(count == undefined) {
98       condition.checked = (condition.value == value.toString());
99       return;
100    }
101    for(var i = 0; i < count; i++) {
102       condition[i].checked = false;
103       if(condition[i].value == value.toString()) {
104          condition[i].checked = true;
105       }
106    }
107 }
108
109 function startTagSearch(searchfor)
110 {
111    HTML_AJAX.grab(encodeURI('rpc.php?action=tag_search&for=' + searchfor));
112    refreshAvailableTags();
113    refreshSelectedTags();
114    showPhotoIndex();
115
116 }
117
118 function setViewMode(mode)
119 {
120    var exprt = document.getElementById('output');
121    exprt.innerHTML = "Loading...";
122    exprt.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_export&mode=' + mode));
123 }
124
125 function clearSearch()
126 {
127    document.getElementsByName('searchfor')[0].value = '';
128 }
129
130 function init_phpfspot()
131 {
132    refreshAvailableTags();
133
134    if(photo = getPhotoToShow()) {
135       showImage(photo)
136       refreshSelectedTags();
137    }
138    else {
139       if(refreshSelectedTags()) {
140          showPhotoIndex();
141       }
142    }
143 }
144
145 function setBackGrdColor(item, color)
146 {
147    if(color == 'mouseover')
148       item.style.backgroundColor='#c6e9ff';
149    if(color == 'mouseout')
150       item.style.backgroundColor='#eeeeee';
151    if(color == 'mouseclick')
152       item.style.backgroundColor='#93A8CA';
153 }
154
155 function getPhotoToShow()
156 {
157    // update selected tags
158    var photo_to_show = HTML_AJAX.grab(encodeURI('rpc.php?action=get_photo_to_show'));
159
160    // if no image needs to be shown, return false from here
161    if(photo_to_show == "")
162       return false;
163    
164    return photo_to_show;
165 }
166
167
168
169 var startup = 1;
170