-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgallery.js
318 lines (268 loc) · 8.52 KB
/
gallery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
// Global variables:
var gThumbWidth;
if (gThumbWidth == undefined)
gThumbWidth = 24;
var gThumbHeight;
if (gThumbHeight == undefined)
gThumbHeight = 24;
var gSlideShowInterval;
if (gSlideShowInterval == undefined)
gSlideShowInterval = 3000; // lags between images.
var gAutoStartSlideShow;
if (gAutoStartSlideShow == undefined)
gAutoStartSlideShow = false;
var gBehaviorsArray = [];
var gSlideShowOn = false;
var gSlideShowTimer = null;
var gImageLoader = null;
var curActiveURL=null;
// Register a callback turn
// off the slide show before it attempts to load new data.
dsPhotos.addObserver(function(nType, notifier, data) {
if (nType == "onPreLoad")
StopSlideShow();
});
// Register a callback on the thumbnails region so we can show the first
// image in the data set after all the thumbnails have loaded.
Spry.Data.Region.addObserver("thumbnails", function(nType, notifier, data) {
if (nType == "onPostUpdate")
{
ShowCurrentImage();
if (gAutoStartSlideShow)
StartSlideShow(true);
}
});
// Sets the image info area
function SetInfoArea(imgPath, width, height,tnID){
var index=imgPath.lastIndexOf('/')+1;
var fileName=imgPath.toString().substring(index);
var imgID=tnID.toString().substring(2);
var imgInfo = dsPhotos.data[imgID];
var rating=imgInfo["@rating"];
var cat=imgInfo["@categories"];
document.getElementById("image_info").innerHTML=
"<p>File name: "+fileName+"<br />"+"Width: "+width+"<br />"+"Height: "+height+"<br />"+
"Rating: "+rating+"<br />"+"Categories: "+cat+"<br />"+"</p>";
curActiveURL=imgPath;
document.cookie="activeImage="+"/Applications/XAMPP/xamppfiles/htdocs/cs242_final/"+ curActiveURL;
}
// Trigger the transition animation from the current image
// being displayed to the image at imgPath.
function SetMainImage(imgPath, width, height, tnID)
{
var img = document.getElementById("mainImage");
if (!img)
return;
CancelBehavior("mainImage");
Spry.Utils.SelectionManager.clearSelection("thumbnailSelection");
if (tnID)
Spry.Utils.SelectionManager.select("thumbnailSelection", document.getElementById(tnID), "selectedThumbnail");
if (gImageLoader)
{
gImageLoader.onload = function() {};
gImageLoader = null;
}
gBehaviorsArray["mainImage"] = new Spry.Effect.Opacity(img, Spry.Effect.getOpacity(img), 0, {
duration: 400,
finish: function()
{
gBehaviorsArray["mainImage"] = new Spry.Effect.Size(img.parentNode, Spry.Effect.getDimensions(img.parentNode), {
width: width,
height: height,
units:"px"
}, {
duration: 400,
finish: function()
{
gImageLoader = new Image();
gImageLoader.onload = function()
{
img.src = gImageLoader.src;
gImageLoader = null;
gBehaviorsArray["mainImage"] = new Spry.Effect.Opacity(img, 0, 1, {
duration: 400,
finish: function()
{
gBehaviorsArray["mainImage"] = null;
img.style.opacity = "";
img.style.filter = "";
// If the slide show is on, fire off the timer for the next image.
if (gSlideShowOn)
SetSlideShowTimer();
}
});
gBehaviorsArray["mainImage"].start();
};
gImageLoader.src = imgPath;
}
});
gBehaviorsArray["mainImage"].start();
}
});
SetInfoArea(imgPath, width, height, tnID);
gBehaviorsArray["mainImage"].start();
}
// Cancel the animation
function CancelBehavior(id)
{
if (gBehaviorsArray[id])
{
gBehaviorsArray[id].cancel();
gBehaviorsArray[id] = null;
}
}
function SizeAndPosition(id, toX, toY, toWidth, toHeight, callback)
{
CancelBehavior(id);
var effectCluster = new Spry.Effect.Cluster( {
finish: callback
} );
var ele = Spry.Effect.getElement(id);
var moveEffect = new Spry.Effect.Move(ele, Spry.Effect.getPosition(ele), {
x: toX,
y: toY,
units: "px"
}, {
duration: 400
});
var sizeEffect = new Spry.Effect.Size(ele, Spry.Effect.getDimensions(ele), {
width: toWidth,
height: toHeight,
units: "px"
}, {
duration: 400
});
effectCluster.addParallelEffect(moveEffect);
effectCluster.addParallelEffect(sizeEffect);
//effectCluster.finish = callback;
gBehaviorsArray[id] = effectCluster;
gBehaviorsArray[id].start();
}
// Animation mouseover.
function GrowThumbnail(img, width, height)
{
Spry.Utils.addClassName(img, "inFocus");
img.style.zIndex = 150;
var id = img.getAttribute("id");
var twidth = Math.floor(width * .75);
var theight = Math.floor(height * .75);
var tx = (gThumbWidth - twidth) / 2;
var ty = (gThumbHeight - theight) / 2;
SizeAndPosition(id, tx, ty, twidth, theight, function(b){
gBehaviorsArray[id] = null;
});
}
// Trigger the animation of the thumbnail shrinking.
function ShrinkThumbnail(img)
{
Spry.Utils.addClassName(img, "inFocus");
img.style.zIndex = 1;
var id = img.getAttribute("id");
SizeAndPosition(id, 0, 0, gThumbWidth, gThumbHeight, function(b){
gBehaviorsArray[id] = null;
Spry.Utils.removeClassName(img, "inFocus");
});
}
// Show the image of the current selected row inside the dsPhotos data set.
function ShowCurrentImage()
{
var curRow = dsPhotos.getCurrentRow();
SetMainImage("galleries/" + dsGalleries.getCurrentRow()["@base"] + "images/" + curRow["@path"], curRow["@width"], curRow["@height"], "tn" + curRow["ds_RowID"]);
}
// Utility function to advance (forwards or backwards) the current selected row
// in dsPhotos. This has the side effect of "selecting" the thumbnail and image
// of the new current row.
function AdvanceToNextImage(moveBackwards)
{
var rows = dsPhotos.getData();
var curRow = dsPhotos.getCurrentRow();
if (rows.length < 1)
return;
for (var i = 0; i < rows.length; i++)
{
if (rows[i] == curRow)
{
if (moveBackwards)
--i;
else
++i;
break;
}
}
if (!moveBackwards && i >= rows.length)
i = 0;
else if (moveBackwards && i < 0)
i = rows.length - 1;
curRow = rows[i];
dsPhotos.setCurrentRow(curRow["ds_RowID"]);
ShowCurrentImage();
}
function SetSlideShowTimer()
{
KillSlideShowTimer();
gSlideShowTimer = setTimeout(function(){
gSlideShowTimer = null;
AdvanceToNextImage(false);
}, gSlideShowInterval);
}
function KillSlideShowTimer()
{
if (gSlideShowTimer)
clearTimeout(gSlideShowTimer);
gSlideShowTimer = null;
}
// Start the slide show that runs forwards through all
// the rows in dsPhotos.
function StartSlideShow(skipTimer)
{
gSlideShowOn = true;
if (!skipTimer)
SetSlideShowTimer();
var playLabel = document.getElementById("playLabel");
if (playLabel)
playLabel.firstChild.data = "Pause";
}
// Kill any slide show that is currently running.
function StopSlideShow()
{
gSlideShowOn = false;
KillSlideShowTimer();
var playLabel = document.getElementById("playLabel");
if (playLabel)
playLabel.firstChild.data = "Play";
}
function HandleThumbnailClick(id)
{
StopSlideShow();
dsPhotos.setCurrentRow(id);
ShowCurrentImage();
}
//Editing
// hands the image with url=src to aviary to edit
function launchEditor(id, src) {
featherEditor.launch({
image: id,
url: src
});
return false;
}
//calls launchEditor
function PhotoEdit(){
var url="http://wang248.projects.cs.illinois.edu/"+curActiveURL;
return launchEditor('mainImage', url);
}
/**********************
* not used
******************
*/
function SetCookieActiveImage(){
document.cookie="activeImage=" +"/Applications/XAMPP/xamppfiles/htdocs/cs242_final/"+ curActiveURL;
return false;
}
function DisplayComments(){
document.getElementById('comment').innerHTML=
"<p>+<?getComments();?>+</p>";
}
function getActiveImage(){
return curActiveURL;
}