1 | /** Javascript file for viewing documents */
|
---|
2 |
|
---|
3 | /** NOTE, this file uses inline templates which look for httpPath, assocfilepath, Source, Thumb, Title metadata. These need to be added into any xsl file that uses this javascript (using <gsf:metadata name="xx" hidden="true"/> if they are not already being collected. */
|
---|
4 |
|
---|
5 | var _imageZoomEnabled = false;
|
---|
6 | // Choose which types of filtering you want: sectionnum, or sectiontitle or both
|
---|
7 | var _filter_on_types = ["sectiontitle", "sectionnum"];
|
---|
8 |
|
---|
9 | // are titles numeric match?
|
---|
10 | var _filter_title_numeric = false;
|
---|
11 |
|
---|
12 | var _linkCellMap = new Array();
|
---|
13 | var _onCells = new Array();
|
---|
14 |
|
---|
15 | var curHLNum = null;
|
---|
16 |
|
---|
17 | /*Array to store init states of metadata fields and text*/
|
---|
18 | var editableInitStates = new Array();
|
---|
19 | /*Array to store last states of metadata fields and text*/
|
---|
20 | var editableLastStates = new Array();
|
---|
21 |
|
---|
22 |
|
---|
23 | /********************
|
---|
24 | * EXPANSION SCRIPTS *
|
---|
25 | ********************/
|
---|
26 |
|
---|
27 | /*
|
---|
28 | Given a string consisting of a single character, returns the %hex (%XX)
|
---|
29 | https://www.w3resource.com/javascript-exercises/javascript-string-exercise-27.php
|
---|
30 | https://stackoverflow.com/questions/40100096/what-is-equivalent-php-chr-and-ord-functions-in-javascript
|
---|
31 | https://www.w3resource.com/javascript-exercises/javascript-string-exercise-27.php
|
---|
32 | */
|
---|
33 | function urlEncodeChar(single_char_string) {
|
---|
34 | /*var hex = Number(single_char_string.charCodeAt(0)).toString(16);
|
---|
35 | var str = "" + hex;
|
---|
36 | str = "%" + str.toUpperCase();
|
---|
37 | return str;
|
---|
38 | */
|
---|
39 |
|
---|
40 | var hex = "%" + Number(single_char_string.charCodeAt(0)).toString(16).toUpperCase();
|
---|
41 | return hex;
|
---|
42 | }
|
---|
43 |
|
---|
44 | /*
|
---|
45 | Tomcat 8 appears to be stricter in requiring unsafe and reserved chars
|
---|
46 | in URLs to be escaped with URL encoding
|
---|
47 | See section "Character Encoding Chart of
|
---|
48 | https://perishablepress.com/stop-using-unsafe-characters-in-urls/
|
---|
49 | Reserved chars:
|
---|
50 | ; / ? : @ = &
|
---|
51 | -----> %3B %2F %3F %3A %40 %3D %26
|
---|
52 | Unsafe chars:
|
---|
53 | " < > # % { } | \ ^ ~ [ ] ` and SPACE/BLANK
|
---|
54 | ----> %22 %3C %3E %23 %25 %7B %7D %7C %5C %5E ~ %5B %5D %60 and %20
|
---|
55 | But the above conflicts with the reserved vs unreserved listings at
|
---|
56 | https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI
|
---|
57 | Possibly more info: https://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid
|
---|
58 |
|
---|
59 | Javascript already provides functions encodeURI() and encodeURIComponent(), see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI
|
---|
60 | However, the set of chars they deal with only partially overlap with the set of chars that need encoding as per the RFC3986 for URIs and RFC1738 for URLs discussed at
|
---|
61 | https://perishablepress.com/stop-using-unsafe-characters-in-urls/
|
---|
62 | We want to handle all the characters listed as unsafe and reserved at https://perishablepress.com/stop-using-unsafe-characters-in-urls/
|
---|
63 | so we define and use our own conceptually equivalent methods for both existing JavaScript methods:
|
---|
64 | - makeSafeURL() for Javascript's encodeURI() to make sure all unsafe characters in URLs are escaped by being URL encoded
|
---|
65 | - and makeSafeURLComponent() for JavaScript's encodeURIComponent to additionally make sure all reserved characters in a URL portion are escaped by being URL encoded too
|
---|
66 |
|
---|
67 | Function makeSafeURL() is passed a string that represents a URL and therefore only deals with characters that are unsafe in a URL and which therefore require escaping.
|
---|
68 | Function makeSafeURLComponent() deals with portions of a URL that when decoded need not represent a URL at all, for example data like inline templates passed in as a
|
---|
69 | URL query string's parameter values. As such makeSafeURLComponent() should escape both unsafe URL characters and characters that are reserved in URLs since reserved
|
---|
70 | characters in the query string part (as query param values representing data) may take on a different meaning from their reserved meaning in a URL context.
|
---|
71 | */
|
---|
72 |
|
---|
73 | /* URL encodes both
|
---|
74 | - UNSAFE characters to make URL safe, by calling makeSafeURL()
|
---|
75 | - and RESERVED characters (characters that have reserved meanings within a URL) to make URL valid, since the url component parameter could use reserved characters
|
---|
76 | in a non-URL sense. For example, the inline template (ilt) parameter value of a URL could use '=' and '&' signs where these would have XSLT rather than URL meanings.
|
---|
77 |
|
---|
78 | See end of https://www.w3schools.com/jsref/jsref_replace.asp to use a callback passing each captured element of a regex in str.replace()
|
---|
79 | */
|
---|
80 | function makeURLComponentSafe(url_part, encode_percentages) {
|
---|
81 | // https://stackoverflow.com/questions/12797118/how-can-i-declare-optional-function-parameters-in-javascript
|
---|
82 | encode_percentages = encode_percentages || 1; // this method forces the URL-encoding of any % in url_part, e.g. do this for inline-templates that haven't ever been encoded
|
---|
83 |
|
---|
84 | var url_encoded = makeURLSafe(url_part, encode_percentages);
|
---|
85 | //return url_encoded.replace(/;/g, "%3B").replace(/\//g, "%2F").replace(/\?/g, "%3F").replace(/\:/g, "%3A").replace(/\@/g, "%40").replace(/=/g, "%3D").replace(/\&/g,"%26");
|
---|
86 | url_encoded = url_encoded.replace(/[\;\/\?\:\@\=\&]/g, function(s) {
|
---|
87 | return urlEncodeChar(s);
|
---|
88 | });
|
---|
89 | return url_encoded;
|
---|
90 | }
|
---|
91 |
|
---|
92 | /*
|
---|
93 | URL encode UNSAFE characters to make URL passed in safe.
|
---|
94 | Set encode_percentages to 1 (true) if you don't want % signs encoded: you'd do so if the url is already partly URL encoded.
|
---|
95 | */
|
---|
96 | function makeURLSafe(url, encode_percentages) {
|
---|
97 | encode_percentages = encode_percentages || 0; // https://stackoverflow.com/questions/12797118/how-can-i-declare-optional-function-parameters-in-javascript
|
---|
98 |
|
---|
99 | var url_encoded = url;
|
---|
100 | if(encode_percentages) { url_encoded = url_encoded.replace(/\%/g,"%25"); } // encode % first
|
---|
101 | //url_encoded = url_encoded.replace(/ /g, "%20").replace(/\"/g,"%22").replace(/\</g,"%3C").replace(/\>/g,"%3E").replace(/\#/g,"%23").replace(/\{/g,"%7B").replace(/\}/g,"%7D");
|
---|
102 | //url_encoded = url_encoded.replace(/\|/g,"%7C").replace(/\\/g,"%5C").replace(/\^/g,"%5E").replace(/\[/g,"%5B").replace(/\]/g,"%5D").replace(/\`/g,"%60");
|
---|
103 | // Should we handle ~, but then what is its URL encoded value? Because https://meyerweb.com/eric/tools/dencoder/ URLencodes ~ to ~.
|
---|
104 | //return url_encoded;
|
---|
105 | url_encoded = url_encoded.replace(/[\ \"\<\>\#\{\}\|\\^\~\[\]\`]/g, function(s) {
|
---|
106 | return urlEncodeChar(s);
|
---|
107 | });
|
---|
108 | return url_encoded;
|
---|
109 | }
|
---|
110 |
|
---|
111 | function getTextForSection(sectionID, callback)
|
---|
112 | {
|
---|
113 | if(!callback)
|
---|
114 | {
|
---|
115 | console.log("Cannot get text as the callback function is not defined");
|
---|
116 | }
|
---|
117 |
|
---|
118 | var template = "";
|
---|
119 | template += '<xsl:template match="/">';
|
---|
120 | template += '<text>';
|
---|
121 | template += '<xsl:for-each select="/page/pageResponse/document//documentNode[@nodeID = \'' + sectionID + '\']">';
|
---|
122 | template += '<xsl:call-template name="sectionContent"/>';
|
---|
123 | template += '</xsl:for-each>';
|
---|
124 | template += '</text>';
|
---|
125 | template += '</xsl:template>';
|
---|
126 |
|
---|
127 | template = makeURLComponentSafe(template);
|
---|
128 |
|
---|
129 | var hlCheckBox = document.getElementById("highlightOption");
|
---|
130 |
|
---|
131 | var hl = "";
|
---|
132 | if(hlCheckBox)
|
---|
133 | {
|
---|
134 | if(hlCheckBox.checked)
|
---|
135 | {
|
---|
136 | hl = "on";
|
---|
137 | }
|
---|
138 | else
|
---|
139 | {
|
---|
140 | hl = "off";
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + sectionID + "?ed=1&hl=" + hl + "&ilt=" + template;
|
---|
145 | if (gs.cgiParams.p_s && gs.cgiParams.p_s.length > 0) {
|
---|
146 | url += "&p.s=" + gs.cgiParams.p_s;
|
---|
147 | }
|
---|
148 | if (gs.cgiParams.ck && gs.cgiParams.ck.length > 0) {
|
---|
149 | url += "&ck=" + gs.cgiParams.ck;
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 |
|
---|
154 | $.ajax(url)
|
---|
155 | .success(function(response)
|
---|
156 | {
|
---|
157 | if(response)
|
---|
158 | {
|
---|
159 | var textStart = response.indexOf(">", response.indexOf(">") + 1) + 1;
|
---|
160 | var textEnd = response.lastIndexOf("<");
|
---|
161 |
|
---|
162 | if(textStart == 0 || textEnd == -1 || textEnd <= textStart)
|
---|
163 | {
|
---|
164 | callback("");
|
---|
165 | }
|
---|
166 |
|
---|
167 | var text = response.substring(textStart, textEnd);
|
---|
168 | callback(text);
|
---|
169 | }
|
---|
170 | else
|
---|
171 | {
|
---|
172 | callback(null);
|
---|
173 | }
|
---|
174 | })
|
---|
175 | .error(function()
|
---|
176 | {
|
---|
177 | callback(null);
|
---|
178 | });
|
---|
179 | }
|
---|
180 |
|
---|
181 | function getSubSectionsForSection(sectionID, callback)
|
---|
182 | {
|
---|
183 | if(!callback)
|
---|
184 | {
|
---|
185 | console.log("Cannot get sub sections as the callback function is not defined");
|
---|
186 | }
|
---|
187 |
|
---|
188 | var template = "";
|
---|
189 | template += '<xsl:template match="/">';
|
---|
190 | template += '<sections>';
|
---|
191 | template += '<xsl:for-each select="/page/pageResponse/document//documentNode[@nodeID = \'' + sectionID + '\']/documentNode">';
|
---|
192 | template += '<xsl:call-template name="wrapDocumentNodes"/>';
|
---|
193 | template += '</xsl:for-each>';
|
---|
194 | template += '</sections>';
|
---|
195 | template += '</xsl:template>';
|
---|
196 |
|
---|
197 | template = makeURLComponentSafe(template);
|
---|
198 | var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + sectionID + "?ilt=" + template;
|
---|
199 |
|
---|
200 | if(gs.documentMetadata.docType == "paged")
|
---|
201 | {
|
---|
202 | url += "&dt=hierarchy";
|
---|
203 | }
|
---|
204 |
|
---|
205 | $.ajax(url)
|
---|
206 | .success(function(response)
|
---|
207 | {
|
---|
208 | if(response)
|
---|
209 | {
|
---|
210 | var sectionsStart = response.indexOf(">", response.indexOf(">") + 1) + 1;
|
---|
211 | var sectionsEnd = response.lastIndexOf("<");
|
---|
212 |
|
---|
213 | if(sectionsStart == 0 || sectionsEnd == -1 || sectionsEnd <= sectionsStart)
|
---|
214 | {
|
---|
215 | callback(" ");
|
---|
216 | return;
|
---|
217 | }
|
---|
218 |
|
---|
219 | var sections = response.substring(sectionsStart, sectionsEnd);
|
---|
220 | callback(sections);
|
---|
221 | }
|
---|
222 | else
|
---|
223 | {
|
---|
224 | callback(null);
|
---|
225 | }
|
---|
226 | })
|
---|
227 | .error(function()
|
---|
228 | {
|
---|
229 | callback(null);
|
---|
230 | });
|
---|
231 | }
|
---|
232 |
|
---|
233 | function toggleSection(sectionID, callback, tocDisabled)
|
---|
234 | {
|
---|
235 | var docElem = gs.jqGet("doc" + sectionID);
|
---|
236 | var tocElem = gs.jqGet("toc" + sectionID);
|
---|
237 |
|
---|
238 | var tocToggleElem = gs.jqGet("ttoggle" + sectionID);
|
---|
239 | var docToggleElem = gs.jqGet("dtoggle" + sectionID);
|
---|
240 |
|
---|
241 | if(docElem.css("display") == "none")
|
---|
242 | {
|
---|
243 | if(tocToggleElem.length && !tocDisabled)
|
---|
244 | {
|
---|
245 | tocToggleElem.attr("src", gs.imageURLs.collapse);
|
---|
246 | }
|
---|
247 |
|
---|
248 | if(tocElem.length && !tocDisabled)
|
---|
249 | {
|
---|
250 | tocElem.css("display", "block");
|
---|
251 | }
|
---|
252 |
|
---|
253 | if(docElem.hasClass("noText"))
|
---|
254 | {
|
---|
255 | getTextForSection(sectionID, function(text)
|
---|
256 | {
|
---|
257 | if(text)
|
---|
258 | {
|
---|
259 | var nodeID = sectionID.replace(/\./g, "_");
|
---|
260 | if(text.search("wrap" + nodeID) != -1)
|
---|
261 | {
|
---|
262 | $("#zoomOptions").css("display", "");
|
---|
263 | $("#pagedImageOptions").css("display", "");
|
---|
264 | }
|
---|
265 | getSubSectionsForSection(sectionID, function(sections)
|
---|
266 | {
|
---|
267 | if(sections)
|
---|
268 | {
|
---|
269 | var textElem = gs.jqGet("doc" + sectionID);
|
---|
270 | textElem.html(text + sections);
|
---|
271 |
|
---|
272 | docElem.removeClass("noText");
|
---|
273 | docElem.css("display", "block");
|
---|
274 | docToggleElem.attr("src", gs.imageURLs.collapse);
|
---|
275 |
|
---|
276 | if(callback)
|
---|
277 | {
|
---|
278 | callback(true);
|
---|
279 | }
|
---|
280 |
|
---|
281 | if(gs.jqGet("viewSelection").length)
|
---|
282 | {
|
---|
283 | changeView();
|
---|
284 | }
|
---|
285 | }
|
---|
286 | else
|
---|
287 | {
|
---|
288 | docToggleElem.attr("src", gs.imageURLs.expand);
|
---|
289 | if(callback)
|
---|
290 | {
|
---|
291 | callback(false);
|
---|
292 | }
|
---|
293 | }
|
---|
294 | });
|
---|
295 | }
|
---|
296 | else
|
---|
297 | {
|
---|
298 | docToggleElem.attr("src", gs.imageURLs.expand);
|
---|
299 | if(callback)
|
---|
300 | {
|
---|
301 | callback(false);
|
---|
302 | }
|
---|
303 | }
|
---|
304 | });
|
---|
305 |
|
---|
306 | docToggleElem.attr("src", gs.imageURLs.loading);
|
---|
307 | }
|
---|
308 | else
|
---|
309 | {
|
---|
310 | docToggleElem.attr("src", gs.imageURLs.collapse);
|
---|
311 | docElem.css("display", "block");
|
---|
312 |
|
---|
313 | if(callback)
|
---|
314 | {
|
---|
315 | callback(true);
|
---|
316 | }
|
---|
317 | }
|
---|
318 | }
|
---|
319 | else
|
---|
320 | {
|
---|
321 | docElem.css("display", "none");
|
---|
322 |
|
---|
323 | //Use the page image if this is a leaf node and the chapter image if it not
|
---|
324 | docToggleElem.attr("src", gs.imageURLs.expand);
|
---|
325 |
|
---|
326 | if(tocToggleElem.length)
|
---|
327 | {
|
---|
328 | tocToggleElem.attr("src", gs.imageURLs.expand);
|
---|
329 | }
|
---|
330 |
|
---|
331 | if(tocElem.length)
|
---|
332 | {
|
---|
333 | tocElem.css("display", "none");
|
---|
334 | }
|
---|
335 |
|
---|
336 | if(callback)
|
---|
337 | {
|
---|
338 | callback(true);
|
---|
339 | }
|
---|
340 | }
|
---|
341 | }
|
---|
342 |
|
---|
343 | function scrollToTop()
|
---|
344 | {
|
---|
345 | $('html, body').stop().animate({scrollTop: 0}, 1000);
|
---|
346 | }
|
---|
347 |
|
---|
348 | function scrollNextHightlight()
|
---|
349 | {
|
---|
350 | if (curHLNum == null)
|
---|
351 | {
|
---|
352 | curHLNum = 0;
|
---|
353 | } else
|
---|
354 | {
|
---|
355 | curHLNum++;
|
---|
356 | }
|
---|
357 | var hlNode = $("span[class$='ermHighlight']:eq(" + curHLNum + ")");
|
---|
358 | if (hlNode.length == 0)
|
---|
359 | {
|
---|
360 | curHLNum = 0;
|
---|
361 | hlNode = $("span[class$='ermHighlight']:eq(" + curHLNum + ")");
|
---|
362 | }
|
---|
363 | if (hlNode.length != 0)
|
---|
364 | {
|
---|
365 | var topVal = $(hlNode).offset().top - 50;
|
---|
366 | $('html, body').stop().animate({scrollTop: topVal}, 1000);
|
---|
367 | }
|
---|
368 | }
|
---|
369 |
|
---|
370 | function scrollPrevHightlight()
|
---|
371 | {
|
---|
372 | if (curHLNum == null)
|
---|
373 | {
|
---|
374 | curHLNum = $("span[class$='ermHighlight']").length - 1;
|
---|
375 | } else
|
---|
376 | {
|
---|
377 | curHLNum--;
|
---|
378 | }
|
---|
379 | var hlNode = $("span[class$='ermHighlight']:eq(" + curHLNum + ")");
|
---|
380 | if (hlNode.length == 0)
|
---|
381 | {
|
---|
382 | curHLNum = $("span[class$='ermHighlight']").length - 1;
|
---|
383 | hlNode = $("span[class$='ermHighlight']:eq(" + curHLNum + ")");
|
---|
384 | }
|
---|
385 | if (hlNode.length != 0)
|
---|
386 | {
|
---|
387 | var topVal = $(hlNode).offset().top - 50;
|
---|
388 | $('html, body').stop().animate({scrollTop: topVal}, 1000);
|
---|
389 | }
|
---|
390 | }
|
---|
391 |
|
---|
392 | function focusSection(sectionID, level, tocDisabled)
|
---|
393 | {
|
---|
394 | expandAndExecute(sectionID, level, tocDisabled, function()
|
---|
395 | {
|
---|
396 | var topVal = $(document.getElementById("doc" + sectionID)).offset().top - 50;
|
---|
397 | $('html, body').stop().animate({scrollTop: topVal}, 1000);
|
---|
398 | });
|
---|
399 | }
|
---|
400 | function focusAnchor(sectionID, level, tocDisabled, anchor)
|
---|
401 | {
|
---|
402 | expandAndExecute(sectionID, level, tocDisabled, function()
|
---|
403 | {
|
---|
404 | var target = document.getElementById(anchor);
|
---|
405 | if (!target){
|
---|
406 | target = document.getElementsByName(anchor)[0];
|
---|
407 | }
|
---|
408 | var topVal = $(target).offset().top - 50;
|
---|
409 | $('html, body').stop().animate({scrollTop: topVal}, 1000);
|
---|
410 | window.location.hash = anchor;
|
---|
411 | });
|
---|
412 | }
|
---|
413 | function expandAndExecute(sectionID, level, tocDisabled, executeAfter)
|
---|
414 | {
|
---|
415 | if(!level)
|
---|
416 | {
|
---|
417 | level = 0;
|
---|
418 | }
|
---|
419 | var parts = sectionID.split(".");
|
---|
420 | if(level >= parts.length)
|
---|
421 | {
|
---|
422 | if (executeAfter) {
|
---|
423 | executeAfter();
|
---|
424 | }
|
---|
425 | document.getElementById("gs_content").style.cursor = "default";
|
---|
426 | return;
|
---|
427 | }
|
---|
428 |
|
---|
429 | var idToExpand = "";
|
---|
430 | for(var i = 0; i < level + 1; i++)
|
---|
431 | {
|
---|
432 | if(i > 0)
|
---|
433 | {
|
---|
434 | idToExpand += ".";
|
---|
435 | }
|
---|
436 |
|
---|
437 | idToExpand += parts[i];
|
---|
438 | }
|
---|
439 |
|
---|
440 | if(!isSectionExpanded(idToExpand))
|
---|
441 | {
|
---|
442 | document.getElementById("gs_content").style.cursor = "progress";
|
---|
443 | toggleSection(idToExpand, function(success)
|
---|
444 | {
|
---|
445 | if(success)
|
---|
446 | {
|
---|
447 | expandAndExecute(sectionID, level + 1, tocDisabled, executeAfter);
|
---|
448 | }
|
---|
449 | }, tocDisabled);
|
---|
450 | }
|
---|
451 | else
|
---|
452 | {
|
---|
453 | expandAndExecute(sectionID, level + 1, tocDisabled, executeAfter);
|
---|
454 | }
|
---|
455 | }
|
---|
456 | function expandOrCollapseAll(expand)
|
---|
457 | {
|
---|
458 | var divs = $("div");
|
---|
459 | var startCounter = 0;
|
---|
460 | var endCounter = 0;
|
---|
461 |
|
---|
462 | for(var i = 0; i < divs.length; i++)
|
---|
463 | {
|
---|
464 | if($(divs[i]).attr("id") && $(divs[i]).attr("id").search(/^doc/) != -1)
|
---|
465 | {
|
---|
466 | var id = $(divs[i]).attr("id").replace(/^doc(.*)/, "$1");
|
---|
467 | if(isSectionExpanded(id) != expand)
|
---|
468 | {
|
---|
469 | //Don't collapse the top level
|
---|
470 | if(!expand && id.indexOf(".") == -1)
|
---|
471 | {
|
---|
472 | continue;
|
---|
473 | }
|
---|
474 | startCounter++;
|
---|
475 |
|
---|
476 | var toggleFunction = function(tid)
|
---|
477 | {
|
---|
478 | toggleSection(tid, function(success)
|
---|
479 | {
|
---|
480 | if(success)
|
---|
481 | {
|
---|
482 | endCounter++;
|
---|
483 | }
|
---|
484 | else
|
---|
485 | {
|
---|
486 | setTimeout(function(){toggleFunction(tid)}, 500);
|
---|
487 | }
|
---|
488 | });
|
---|
489 | }
|
---|
490 | toggleFunction(id);
|
---|
491 | }
|
---|
492 | }
|
---|
493 | }
|
---|
494 |
|
---|
495 | if(startCounter != 0)
|
---|
496 | {
|
---|
497 | var checkFunction = function()
|
---|
498 | {
|
---|
499 | if(startCounter == endCounter)
|
---|
500 | {
|
---|
501 | expandOrCollapseAll(expand);
|
---|
502 | }
|
---|
503 | else
|
---|
504 | {
|
---|
505 | setTimeout(checkFunction, 500);
|
---|
506 | }
|
---|
507 | }
|
---|
508 | checkFunction();
|
---|
509 | }
|
---|
510 | }
|
---|
511 |
|
---|
512 | function loadTopLevelPage(callbackFunction, customURL)
|
---|
513 | {
|
---|
514 | var url;
|
---|
515 | if(customURL)
|
---|
516 | {
|
---|
517 | url = customURL;
|
---|
518 | }
|
---|
519 | else
|
---|
520 | {
|
---|
521 | url = gs.xsltParams.library_name + "?a=d&c=" + gs.cgiParams.c + "&excerptid=gs-document";
|
---|
522 | if(gs.cgiParams.d && gs.cgiParams.d.length > 0)
|
---|
523 | {
|
---|
524 | url += "&d=" + gs.cgiParams.d.replace(/([^.]*)\..*/, "$1");
|
---|
525 | }
|
---|
526 | else if(gs.cgiParams.href && gs.cgiParams.href.length > 0)
|
---|
527 | {
|
---|
528 | url += "&d=&alb=1&rl=1&href=" + gs.cgiParams.href;
|
---|
529 | }
|
---|
530 | }
|
---|
531 |
|
---|
532 | $.ajax(url)
|
---|
533 | .success(function(response)
|
---|
534 | {
|
---|
535 | if(response)
|
---|
536 | {
|
---|
537 | var targetElem = $("#gs-document");
|
---|
538 | var docStart = response.indexOf(">") + 1;
|
---|
539 | var docEnd = response.lastIndexOf("<");
|
---|
540 | var doc = response.substring(docStart, docEnd);
|
---|
541 |
|
---|
542 | targetElem.html(doc);
|
---|
543 |
|
---|
544 | if(callbackFunction)
|
---|
545 | {
|
---|
546 | callbackFunction();
|
---|
547 | }
|
---|
548 | }
|
---|
549 | })
|
---|
550 | .error(function()
|
---|
551 | {
|
---|
552 | setTimeout(function(){loadTopLevelPage(callbackFunction, customURL);}, 1000);
|
---|
553 | });
|
---|
554 | }
|
---|
555 |
|
---|
556 | function retrieveFullTableOfContentsSuccess(newTOCElem)
|
---|
557 | {
|
---|
558 | var tocStart = newTOCElem.indexOf(">") + 1;
|
---|
559 | var tocEnd = newTOCElem.lastIndexOf("<");
|
---|
560 |
|
---|
561 | var newTOC = newTOCElem.substring(tocStart, tocEnd);
|
---|
562 |
|
---|
563 | //Add the "Expand document"/"Collapse document" links
|
---|
564 | //newTOC = "<table style=\"width:100%; text-align:center;\"><tr><td><a href=\"javascript:expandOrCollapseAll(true);\">"+gs.text.doc.expand_doc+"</a></td><td><a href=\"javascript:expandOrCollapseAll(false);\">"+gs.text.doc.collapse_doc+"</a></td></tr></table>" + newTOC;
|
---|
565 | //newTOC = "<table style=\"width:100%; text-align:center;\"><tr><td><a href=\""+window.location.href+"?ed=1\">"+gs.text.doc.expand_doc+"</a></td><td><a href=\""+window.location.href+"?ed=0\">"+gs.text.doc.collapse_doc+"</a></td></tr></table>" + newTOC;
|
---|
566 |
|
---|
567 | //Collapse the TOC
|
---|
568 | newTOC = newTOC.replace(/display:block/g, "display:none");
|
---|
569 | newTOC = newTOC.replace(/display:none/, "display:block");
|
---|
570 | newTOC = newTOC.replace(/images\/collapse/g, "images/expand");
|
---|
571 |
|
---|
572 | var tocElem = $("#tableOfContents");
|
---|
573 | tocElem.html(newTOC);
|
---|
574 |
|
---|
575 | gs.variables.tocLoaded = true;
|
---|
576 | }
|
---|
577 |
|
---|
578 | function retrieveFullTableOfContentsSuccessClientSideXSLT(newTOCElem)
|
---|
579 | {
|
---|
580 | $('#client-side-xslt-ajax').remove();
|
---|
581 | retrieveFullTableOfContentsSuccess(newTOCElem)
|
---|
582 | }
|
---|
583 |
|
---|
584 | function retrieveFullTableOfContents()
|
---|
585 | {
|
---|
586 | var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "?excerptid=tableOfContents&ec=1";
|
---|
587 | if(gs.cgiParams.d && gs.cgiParams.d.length > 0)
|
---|
588 | {
|
---|
589 | url += "&a=d&d=" + gs.cgiParams.d;
|
---|
590 | }
|
---|
591 | else if(gs.cgiParams.href && gs.cgiParams.href.length > 0)
|
---|
592 | {
|
---|
593 | url += "&a=d&d=&alb=1&rl=1&href=" + gs.cgiParams.href;
|
---|
594 | }
|
---|
595 | // later on we want this arg p.s so we can keep search term highlighting for expand document link
|
---|
596 | if (gs.cgiParams.p_s && gs.cgiParams.p_s.length > 0) {
|
---|
597 | url += "&p.s=" + gs.cgiParams.p_s;
|
---|
598 | }
|
---|
599 | if (gs.cgiParams.ck && gs.cgiParams.ck.length > 0) {
|
---|
600 | url += "&ck=" + gs.cgiParams.ck;
|
---|
601 | }
|
---|
602 |
|
---|
603 | if (gs.xsltParams.use_client_side_xslt == "true") { // note xsltParams are of type string, so test needs to be in quotes
|
---|
604 | url += "&callback=retrieveFullTableOfContentsSuccessClientSideXSLT"; // used in client-side-xslt.js, in combination with 'excerptid'
|
---|
605 | $('<iframe src="'+url+'" id="client-side-xslt-ajax" tabindex="-1" style="position: absolute; width: 0px; height: 0px; border: none;"></iframe>').appendTo('body');
|
---|
606 | }
|
---|
607 | else {
|
---|
608 | $.ajax(url)
|
---|
609 | .success(retrieveFullTableOfContentsSuccess)
|
---|
610 | .error(function() {
|
---|
611 | setTimeout(retrieveFullTableOfContents, 1000);
|
---|
612 | });
|
---|
613 | }
|
---|
614 | }
|
---|
615 |
|
---|
616 | function isSectionExpanded(sectionID)
|
---|
617 | {
|
---|
618 | var docElem = gs.jqGet("doc" + sectionID);
|
---|
619 | if(docElem.css("display") == "block")
|
---|
620 | {
|
---|
621 | return true;
|
---|
622 | }
|
---|
623 | return false;
|
---|
624 | }
|
---|
625 |
|
---|
626 | function minimizeSidebar()
|
---|
627 | {
|
---|
628 | var toc = $("#contentsArea");
|
---|
629 | var maxLink = $("#sidebarMaximizeButton");
|
---|
630 | var minLink = $("#sidebarMinimizeButton");
|
---|
631 |
|
---|
632 | if(toc.length)
|
---|
633 | {
|
---|
634 | toc.css("display", "none");
|
---|
635 | }
|
---|
636 |
|
---|
637 | maxLink.css("display", "block");
|
---|
638 | minLink.css("display", "none");
|
---|
639 | }
|
---|
640 |
|
---|
641 | function maximizeSidebar()
|
---|
642 | {
|
---|
643 | var coverImage = $("#coverImage");
|
---|
644 | var toc = $("#contentsArea");
|
---|
645 | var maxLink = $("#sidebarMaximizeButton");
|
---|
646 | var minLink = $("#sidebarMinimizeButton");
|
---|
647 |
|
---|
648 | if(coverImage.length)
|
---|
649 | {
|
---|
650 | coverImage.css("display", "block");
|
---|
651 | }
|
---|
652 |
|
---|
653 | if(toc.length)
|
---|
654 | {
|
---|
655 | toc.css("display", "block");
|
---|
656 | }
|
---|
657 |
|
---|
658 | maxLink.css("display", "none");
|
---|
659 | minLink.css("display", "block");
|
---|
660 | }
|
---|
661 |
|
---|
662 | function extractFilteredPagesToOwnDocument()
|
---|
663 | {
|
---|
664 | var oids = new Array();
|
---|
665 | var filtered = $(".pageSliderCol:visible a").each(function()
|
---|
666 | {
|
---|
667 | var hrefString = $(this).attr("href");
|
---|
668 | var oidStart = hrefString.indexOf(".") + 1;
|
---|
669 | var oidFinish = hrefString.indexOf("'", oidStart + 1);
|
---|
670 |
|
---|
671 | oids.push(hrefString.substring(oidStart, oidFinish));
|
---|
672 | });
|
---|
673 |
|
---|
674 | var sectionString = "[";
|
---|
675 | for(var i = 0; i < oids.length; i++)
|
---|
676 | {
|
---|
677 | sectionString += "\"" + oids[i] + "\"";
|
---|
678 | if(i < oids.length - 1)
|
---|
679 | {
|
---|
680 | sectionString += ",";
|
---|
681 | }
|
---|
682 | }
|
---|
683 | sectionString += "]";
|
---|
684 |
|
---|
685 | var url = "cgi-bin/document-extract.pl?a=extract-archives-doc&c=" + gs.cgiParams.c + "&d=" + gs.cgiParams.d + "&json-sections=" + sectionString + "&site=" + gs.xsltParams.site_name;// + "&json-metadata=[{"metaname":"dc.Title","metavalue":"All Black Rugy Success","metamode":"accumulate"]"
|
---|
686 | $("#extractDocButton").attr("disabled", "disabled").html("Extracting document...");
|
---|
687 | $.ajax(url)
|
---|
688 | .success(function(response)
|
---|
689 | {
|
---|
690 | $("#extractDocButton").html("Building collection...");
|
---|
691 | gs.functions.buildCollections([gs.cgiParams.c], function()
|
---|
692 | {
|
---|
693 | $("#extractDocButton").removeAttr("disabled").html("Extract these pages to document");
|
---|
694 | });
|
---|
695 | })
|
---|
696 | .error(function()
|
---|
697 | {
|
---|
698 | $("#extractDocButton").removeAttr("disabled").html("Extract these pages to document");
|
---|
699 | });
|
---|
700 | }
|
---|
701 |
|
---|
702 | /**********************
|
---|
703 | * PAGED-IMAGE SCRIPTS *
|
---|
704 | **********************/
|
---|
705 |
|
---|
706 | function changeView()
|
---|
707 | {
|
---|
708 | var viewList = $("#viewSelection");
|
---|
709 | var currentVal = viewList.val();
|
---|
710 |
|
---|
711 | var view;
|
---|
712 | if(currentVal == "Image view")
|
---|
713 | {
|
---|
714 | setImageVisible(true);
|
---|
715 | setTextVisible(false);
|
---|
716 | view = "image";
|
---|
717 | }
|
---|
718 | else if(currentVal == "Text view")
|
---|
719 | {
|
---|
720 | setImageVisible(false);
|
---|
721 | setTextVisible(true);
|
---|
722 | view = "text";
|
---|
723 | }
|
---|
724 | else
|
---|
725 | {
|
---|
726 | setImageVisible(true);
|
---|
727 | setTextVisible(true);
|
---|
728 | view = "";
|
---|
729 | }
|
---|
730 |
|
---|
731 | var url = gs.xsltParams.library_name + "?a=d&view=" + view + "&c=" + gs.cgiParams.c;
|
---|
732 | $.ajax(url);
|
---|
733 | }
|
---|
734 |
|
---|
735 | function setImageVisible(visible)
|
---|
736 | {
|
---|
737 | $("div").each(function()
|
---|
738 | {
|
---|
739 | if($(this).attr("id") && $(this).attr("id").search(/^image/) != -1)
|
---|
740 | {
|
---|
741 | $(this).css("display", (visible ? "block" : "none"));
|
---|
742 | }
|
---|
743 | });
|
---|
744 | }
|
---|
745 |
|
---|
746 | function setTextVisible(visible)
|
---|
747 | {
|
---|
748 | $("div").each(function()
|
---|
749 | {
|
---|
750 | if($(this).attr("id") && $(this).attr("id").search(/^text/) != -1)
|
---|
751 | {
|
---|
752 | $(this).css("display", (visible ? "block" : "none"));
|
---|
753 | }
|
---|
754 | });
|
---|
755 | }
|
---|
756 |
|
---|
757 | function retrieveTableOfContentsAndTitles()
|
---|
758 | {
|
---|
759 | var ilt = "";
|
---|
760 | ilt += '<xsl:template match="/">';
|
---|
761 | ilt += '<xsl:for-each select="/page/pageResponse/document/documentNode">';
|
---|
762 | ilt += '<xsl:call-template name="documentNodeTOC"/>';
|
---|
763 | ilt += '</xsl:for-each>';
|
---|
764 | ilt += '</xsl:template>';
|
---|
765 |
|
---|
766 | ilt = makeURLComponentSafe(ilt);
|
---|
767 |
|
---|
768 |
|
---|
769 | var url = gs.xsltParams.library_name + "?a=d&ec=1&c=" + gs.cgiParams.c + "&d=" + gs.cgiParams.d + "&ilt=" + ilt;
|
---|
770 |
|
---|
771 | $.ajax(url)
|
---|
772 | .success(function(response)
|
---|
773 | {
|
---|
774 | var tableOfContents = $("#tableOfContents");
|
---|
775 | tableOfContents.append(response);
|
---|
776 | replaceLinksWithSlider();
|
---|
777 |
|
---|
778 | var loading = $("#tocLoadingImage");
|
---|
779 | loading.remove();
|
---|
780 | })
|
---|
781 | .error(function()
|
---|
782 | {
|
---|
783 | setTimeout(function(){retrieveTableOfContentsAndTitles();}, 1000);
|
---|
784 | });
|
---|
785 | }
|
---|
786 |
|
---|
787 |
|
---|
788 | function replaceLinksWithSlider()
|
---|
789 | {
|
---|
790 | var tableOfContents = $("#tableOfContents");
|
---|
791 | var leafSections = new Array();
|
---|
792 | var liElems = tableOfContents.find("li").each(function()
|
---|
793 | {
|
---|
794 | var section = $(this);
|
---|
795 | var add = true;
|
---|
796 | for(var j = 0; j < leafSections.length; j++)
|
---|
797 | {
|
---|
798 | if(leafSections[j] == undefined){continue;}
|
---|
799 |
|
---|
800 | var leaf = $(leafSections[j]);
|
---|
801 | if(leaf.attr("id").search(section.attr("id")) != -1)
|
---|
802 | {
|
---|
803 | add = false;
|
---|
804 | }
|
---|
805 |
|
---|
806 | if(section.attr("id").search(leaf.attr("id")) != -1)
|
---|
807 | {
|
---|
808 | delete leafSections[j];
|
---|
809 | }
|
---|
810 | }
|
---|
811 |
|
---|
812 | if(add)
|
---|
813 | {
|
---|
814 | leafSections.push(section);
|
---|
815 | }
|
---|
816 | });
|
---|
817 |
|
---|
818 | for(var i = 0 ; i < leafSections.length; i++)
|
---|
819 | {
|
---|
820 | if(leafSections[i] == undefined){continue;}
|
---|
821 |
|
---|
822 | leafSections[i].css("display", "none");
|
---|
823 | var links = leafSections[i].find("a");
|
---|
824 |
|
---|
825 | var widget = new SliderWidget(links);
|
---|
826 | leafSections[i].before(widget.getElem());
|
---|
827 | }
|
---|
828 |
|
---|
829 | //Disable all TOC toggles
|
---|
830 | var imgs = $("img").each(function()
|
---|
831 | {
|
---|
832 | var currentImage = $(this);
|
---|
833 | if(currentImage.attr("id") && currentImage.attr("id").search(/^ttoggle/) != -1)
|
---|
834 | {
|
---|
835 | currentImage.attr("onclick", "");
|
---|
836 | currentImage.click(function()
|
---|
837 | {
|
---|
838 | var sliderDiv = currentImage.parents("table").first().next();
|
---|
839 | if(sliderDiv.is(":visible"))
|
---|
840 | {
|
---|
841 | sliderDiv.hide();
|
---|
842 | }
|
---|
843 | else
|
---|
844 | {
|
---|
845 | sliderDiv.show();
|
---|
846 | }
|
---|
847 | });
|
---|
848 | }
|
---|
849 | else if(currentImage.attr("id") && currentImage.attr("id").search(/^dtoggle/) != -1)
|
---|
850 | {
|
---|
851 | currentImage.attr("onclick", currentImage.attr("onclick").replace(/\)/, ", null, true)"));
|
---|
852 | }
|
---|
853 | });
|
---|
854 | }
|
---|
855 |
|
---|
856 |
|
---|
857 | function SliderWidget(_links)
|
---|
858 | {
|
---|
859 | //****************
|
---|
860 | //MEMBER VARIABLES
|
---|
861 | //****************
|
---|
862 |
|
---|
863 | //The container for the widget
|
---|
864 | var _mainDiv = $("<div>");
|
---|
865 | _mainDiv.attr("class", "ui-widget-content pageSlider");
|
---|
866 |
|
---|
867 | //The table of images
|
---|
868 | var _linkTable = $("<table>");
|
---|
869 | _mainDiv.append(_linkTable);
|
---|
870 |
|
---|
871 | //The image row of the table
|
---|
872 | var _linkRow = $("<tr>");
|
---|
873 | _linkTable.append(_linkRow);
|
---|
874 |
|
---|
875 | //The list of titles we can search through
|
---|
876 | var _titles = new Array();
|
---|
877 |
|
---|
878 | //Keep track of the slider position
|
---|
879 | var _prevScroll = 0;
|
---|
880 |
|
---|
881 | //****************
|
---|
882 | //PUBLIC FUNCTIONS
|
---|
883 | //****************
|
---|
884 |
|
---|
885 | //Function that returns the widget element
|
---|
886 | this.getElem = function()
|
---|
887 | {
|
---|
888 | return _mainDiv;
|
---|
889 | }
|
---|
890 |
|
---|
891 | //*****************
|
---|
892 | //PRIVATE FUNCTIONS
|
---|
893 | //*****************
|
---|
894 |
|
---|
895 | // _filter_on_types can be "sectionnum", "sectiontitle"
|
---|
896 | var setUpFilterButtons = function() {
|
---|
897 |
|
---|
898 | var button_div = $("#filterOnButtons");
|
---|
899 | button_div.onclick = doFiltering;
|
---|
900 | button_div.html("radio");
|
---|
901 | if (_filter_on_types.length == 0) {
|
---|
902 | _filter_on_types = ["sectionnum", "sectiontitle"];
|
---|
903 | }
|
---|
904 | else if (_filter_on_types.length == 1) {
|
---|
905 | if (_filter_on_types[0] == "sectionnum") {
|
---|
906 | button_div.html("(<input type='radio' name='filterOn' value='num' checked>"+gs.text.doc.filter.pagenum+"</input>)");
|
---|
907 | } else {
|
---|
908 | button_div.html("(<input type='radio' name='filterOn' value='title' checked>"+gs.text.doc.filter.title+"</input>)");
|
---|
909 | }
|
---|
910 | } else {
|
---|
911 | // should be both options
|
---|
912 | button_div.html("<input type='radio' name='filterOn' value='num' checked>"+gs.text.doc.filter.pagenum+"</input><input type='radio' name='filterOn' value='title'>"+gs.text.doc.filter.title+"</input>");
|
---|
913 | }
|
---|
914 | }
|
---|
915 |
|
---|
916 | var doFiltering = function () {
|
---|
917 | if (typeof _titles == "undefined") {
|
---|
918 | return;
|
---|
919 | }
|
---|
920 |
|
---|
921 | var filter_string = $("#filterText").val();
|
---|
922 | var filter_type = $('input[name="filterOn"]:checked').val();
|
---|
923 |
|
---|
924 | var index = 2; // section num
|
---|
925 | var numeric_match = true;
|
---|
926 | if (filter_type == "title") {
|
---|
927 | index = 3;
|
---|
928 | if (_filter_title_numeric != true) {
|
---|
929 | numeric_match = false;
|
---|
930 | }
|
---|
931 |
|
---|
932 | }
|
---|
933 | var values = filter_string.split(",");
|
---|
934 |
|
---|
935 | var matchingTitles = new Array();
|
---|
936 |
|
---|
937 | for (var l = 0; l < values.length; l++)
|
---|
938 | {
|
---|
939 | var currentValue = values[l].replace(/^ +/g, "").replace(/ +$/g, "");
|
---|
940 | if (numeric_match) {
|
---|
941 | var isRange = (currentValue.search(/^\d+-\d+$/) != -1);
|
---|
942 | if (isRange) {
|
---|
943 | var firstNumber = Number(currentValue.replace(/(\d+)-\d+/, "$1"));
|
---|
944 | var secondNumber = Number(currentValue.replace(/\d+-(\d+)/, "$1"));
|
---|
945 | if(firstNumber <= secondNumber)
|
---|
946 | {
|
---|
947 | for(var i = firstNumber; i <= secondNumber; i++)
|
---|
948 | {
|
---|
949 | var numString = i + "";
|
---|
950 | for(var j = 0; j < _titles.length; j++) {
|
---|
951 | var currentTitle = _titles[j];
|
---|
952 | if(currentTitle[index] == numString) {
|
---|
953 | matchingTitles.push(currentTitle);
|
---|
954 | break; // assume no titles are the same
|
---|
955 | }
|
---|
956 | }
|
---|
957 | }
|
---|
958 | }
|
---|
959 | } // if isRange
|
---|
960 | else {
|
---|
961 | for(var j = 0; j < _titles.length; j++) {
|
---|
962 | if (_titles[j][index]==currentValue) {
|
---|
963 | matchingTitles.push(_titles[j]);
|
---|
964 | break; // assume no titles are the same
|
---|
965 | }
|
---|
966 | }
|
---|
967 |
|
---|
968 | }
|
---|
969 |
|
---|
970 | } else { // not numeric match.
|
---|
971 | // need to do a search
|
---|
972 | for(var i = 0; i < _titles.length; i++)
|
---|
973 | {
|
---|
974 | var currentTitle = _titles[i];
|
---|
975 | if(currentTitle[index].toLowerCase().search(currentValue.toLowerCase().replace(/\./g, "\\.")) != -1)
|
---|
976 | {
|
---|
977 | matchingTitles.push(currentTitle);
|
---|
978 | }
|
---|
979 | }
|
---|
980 | }
|
---|
981 | } // for each value from filter string
|
---|
982 |
|
---|
983 | // set all to hide...
|
---|
984 | for(var i = 0; i < _titles.length; i++)
|
---|
985 | {
|
---|
986 | $(_titles[i][1].cell).css("display", "none");
|
---|
987 | }
|
---|
988 |
|
---|
989 | // .. then display the matching ones
|
---|
990 | for(var i = 0; i < matchingTitles.length; i++)
|
---|
991 | {
|
---|
992 | $(matchingTitles[i][1].cell).css("display", "table-cell");
|
---|
993 | }
|
---|
994 | } // end doFiltering() function
|
---|
995 |
|
---|
996 | var setUpFilterBox = function()
|
---|
997 | {
|
---|
998 | var filter = $("#filterText");
|
---|
999 |
|
---|
1000 | filter.keyup(function()
|
---|
1001 | {
|
---|
1002 | doFiltering();
|
---|
1003 | });
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | var getImage = function(page, attemptNumber)
|
---|
1007 | {
|
---|
1008 | var href = page.getAttribute("href");
|
---|
1009 | var startHREF = href.indexOf("'") + 1;
|
---|
1010 | var endHREF = href.indexOf("'", startHREF);
|
---|
1011 | var nodeID = href.substring(startHREF, endHREF);
|
---|
1012 | href = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + nodeID;
|
---|
1013 |
|
---|
1014 | var template = '';
|
---|
1015 | template += '<xsl:template match="/">';
|
---|
1016 | template += '<html>';
|
---|
1017 | template += '<img>';
|
---|
1018 | template += '<xsl:attribute name="src">';
|
---|
1019 | template += "<xsl:value-of disable-output-escaping=\"yes\" select=\"/page/pageResponse/collection/metadataList/metadata[@name = 'httpPath']\"/>";
|
---|
1020 | template += '<xsl:text>/index/assoc/</xsl:text>';
|
---|
1021 | template += "<xsl:value-of disable-output-escaping=\"yes\" select=\"/page/pageResponse/document/metadataList/metadata[@name = 'assocfilepath']\"/>";
|
---|
1022 | template += '<xsl:text>/</xsl:text>';
|
---|
1023 | template += "<xsl:value-of disable-output-escaping=\"yes\" select=\"/page/pageResponse/document//documentNode[@nodeID = '" + nodeID + "']/metadataList/metadata[@name = 'Thumb']\"/>";
|
---|
1024 | template += '</xsl:attribute>';
|
---|
1025 | template += '</img>';
|
---|
1026 | template += '<p>';
|
---|
1027 | template += "<xsl:value-of disable-output-escaping=\"yes\" select=\"/page/pageResponse/document/documentNode/metadataList/metadata[@name = 'Title']\"/>";
|
---|
1028 | template += '</p>';
|
---|
1029 | template += '</html>';
|
---|
1030 | template += '</xsl:template>';
|
---|
1031 | template = makeURLComponentSafe(template);
|
---|
1032 | var url = href + "?noText=1&ilt=" + template;
|
---|
1033 |
|
---|
1034 | $.ajax(url)
|
---|
1035 | .success(function(text)
|
---|
1036 | {
|
---|
1037 | var hrefStart = text.indexOf("src=\"") + 5;
|
---|
1038 | if(hrefStart == -1)
|
---|
1039 | {
|
---|
1040 | page.isLoading = false;
|
---|
1041 | page.noImage = true;
|
---|
1042 | $(page.image).attr("src", gs.imageURLs.blank);
|
---|
1043 | return;
|
---|
1044 | }
|
---|
1045 | var hrefEnd = text.indexOf("\"", hrefStart);
|
---|
1046 | var href = text.substring(hrefStart, hrefEnd);
|
---|
1047 |
|
---|
1048 | var image = $("<img>");
|
---|
1049 | image.load(function()
|
---|
1050 | {
|
---|
1051 | $(page.link).html("");
|
---|
1052 | $(page.link).append(image);
|
---|
1053 | page.isLoading = false;
|
---|
1054 | page.imageLoaded = true;
|
---|
1055 | });
|
---|
1056 | image.error(function()
|
---|
1057 | {
|
---|
1058 | if(!attemptNumber || attemptNumber < 3)
|
---|
1059 | {
|
---|
1060 | setTimeout(function(){getImage(page, ((!attemptNumber) ? 1 : attemptNumber + 1));}, 500);
|
---|
1061 | }
|
---|
1062 | else
|
---|
1063 | {
|
---|
1064 | page.isLoading = false;
|
---|
1065 | page.noImage = true;
|
---|
1066 | image.attr("src", gs.imageURLs.blank);
|
---|
1067 | }
|
---|
1068 | });
|
---|
1069 | image.attr("src", href);
|
---|
1070 |
|
---|
1071 | var titleStart = text.indexOf("<p>") + 3;
|
---|
1072 | var titleEnd = text.indexOf("</p>");
|
---|
1073 | var title = text.substring(titleStart, titleEnd);
|
---|
1074 | })
|
---|
1075 | .error(function()
|
---|
1076 | {
|
---|
1077 | page.failed = true;
|
---|
1078 | if(!attemptNumber || attemptNumber < 3)
|
---|
1079 | {
|
---|
1080 | setTimeout(function(){getImage(page, ((!attemptNumber) ? 1 : attemptNumber + 1));}, 500);
|
---|
1081 | }
|
---|
1082 | else
|
---|
1083 | {
|
---|
1084 | var image = $("<img>", {"src": gs.imageURLs.blank});
|
---|
1085 | $(page.link).html("");
|
---|
1086 | $(page.link).append(image);
|
---|
1087 | page.isLoading = false;
|
---|
1088 | page.noImage = true;
|
---|
1089 | }
|
---|
1090 | });
|
---|
1091 | }
|
---|
1092 |
|
---|
1093 | var startCheckFunction = function()
|
---|
1094 | {
|
---|
1095 | var checkFunction = function(forced)
|
---|
1096 | {
|
---|
1097 | //Don't bother checking if we haven't scrolled very far
|
---|
1098 | if(Math.abs(_mainDiv.scrollLeft() - _prevScroll) > 100 || forced)
|
---|
1099 | {
|
---|
1100 | _prevScroll = _mainDiv.scrollLeft();
|
---|
1101 | _checking = true;
|
---|
1102 | var widgetLeft = _mainDiv.offset().left;
|
---|
1103 | var widgetRight = widgetLeft + _mainDiv.width();
|
---|
1104 |
|
---|
1105 | var visiblePages = new Array();
|
---|
1106 | for(var i = 0; i < _links.length; i++)
|
---|
1107 | {
|
---|
1108 | var current = _links[i].cell;
|
---|
1109 | var currentLeft = current.offset().left;
|
---|
1110 | var currentRight = currentLeft + current.width();
|
---|
1111 |
|
---|
1112 | if(currentRight > widgetLeft && currentLeft < widgetRight)
|
---|
1113 | {
|
---|
1114 | visiblePages.push(_links[i]);
|
---|
1115 | }
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | for(var i = 0; i < visiblePages.length; i++)
|
---|
1119 | {
|
---|
1120 | var page = visiblePages[i];
|
---|
1121 | if(!page || page.imageLoaded || page.noImage || page.isLoading)
|
---|
1122 | {
|
---|
1123 | continue;
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 | page.isLoading = true;
|
---|
1127 | getImage(page);
|
---|
1128 | }
|
---|
1129 | _checking = false;
|
---|
1130 | }
|
---|
1131 | }
|
---|
1132 |
|
---|
1133 | setTimeout(checkFunction, 250);
|
---|
1134 | setInterval(function(){checkFunction(true)}, 2000);
|
---|
1135 | _mainDiv.scroll(checkFunction);
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 | //***********
|
---|
1139 | //CONSTRUCTOR
|
---|
1140 | //***********
|
---|
1141 |
|
---|
1142 | for(var i = 0; i < _links.length; i++)
|
---|
1143 | {
|
---|
1144 | var col = $("<td>");
|
---|
1145 | _linkRow.append(col);
|
---|
1146 | col.addClass("pageSliderCol");
|
---|
1147 | _links[i].cell = col;
|
---|
1148 |
|
---|
1149 | var link = $("<a>");
|
---|
1150 | col.append(link);
|
---|
1151 | _links[i].link = link;
|
---|
1152 | var href = $(_links[i]).attr("href");
|
---|
1153 | link.attr("href", href.replace(/\)/, ", 0, true)"));
|
---|
1154 |
|
---|
1155 | if(!_linkCellMap[href])
|
---|
1156 | {
|
---|
1157 | _linkCellMap[href] = new Array();
|
---|
1158 | }
|
---|
1159 | _linkCellMap[href].push(_links[i]);
|
---|
1160 |
|
---|
1161 | var loadingText = $("<p>Loading image</p>");
|
---|
1162 | link.append(loadingText);
|
---|
1163 |
|
---|
1164 | var image = $("<img>");
|
---|
1165 | link.append(image);
|
---|
1166 | image.attr("src", gs.imageURLs.loading);
|
---|
1167 | _links[i].image = image;
|
---|
1168 |
|
---|
1169 | var title = $(_links[i]).html();
|
---|
1170 | var t_section = "";
|
---|
1171 | var t_title = "";
|
---|
1172 | if (title.search(/tocSectionNumber/) != -1)
|
---|
1173 | {
|
---|
1174 | var matching_regex = /<span class=\"tocSectionNumber\">([0-9]+)<\/span>[\s\S]*<span class=\"tocSectionTitle\">(.+)<\/span>$/mg;
|
---|
1175 | var matches_array = matching_regex.exec(title);
|
---|
1176 | if (matches_array != null && matches_array.length == 3) {
|
---|
1177 | t_section = matches_array[1];
|
---|
1178 | t_title = matches_array[2];
|
---|
1179 | }
|
---|
1180 | }
|
---|
1181 |
|
---|
1182 | _titles.push([title, _links[i], t_section, t_title]);
|
---|
1183 |
|
---|
1184 | col.append($("<br>"));
|
---|
1185 | col.append(title);
|
---|
1186 | }
|
---|
1187 |
|
---|
1188 | setUpFilterBox();
|
---|
1189 | setUpFilterButtons();
|
---|
1190 | startCheckFunction();
|
---|
1191 | }
|
---|
1192 |
|
---|
1193 | /***********************
|
---|
1194 | * HIGHLIGHTING SCRIPTS *
|
---|
1195 | ***********************/
|
---|
1196 | function swapHighlight(imageClicked)
|
---|
1197 | {
|
---|
1198 | var hlCheckbox = $("#highlightOption");
|
---|
1199 | if(imageClicked)
|
---|
1200 | {
|
---|
1201 | // toggle the state of the checkbox
|
---|
1202 | $(hlCheckbox).prop("checked", !$(hlCheckbox).prop("checked"));
|
---|
1203 | }
|
---|
1204 | var from;
|
---|
1205 | var to;
|
---|
1206 | if(hlCheckbox.prop("checked"))
|
---|
1207 | {
|
---|
1208 | from = "noTermHighlight";
|
---|
1209 | to = "termHighlight";
|
---|
1210 | }
|
---|
1211 | else
|
---|
1212 | {
|
---|
1213 | from = "termHighlight";
|
---|
1214 | to = "noTermHighlight";
|
---|
1215 | }
|
---|
1216 |
|
---|
1217 | var spans = $("span").each(function()
|
---|
1218 | {
|
---|
1219 | if($(this).hasClass(from))
|
---|
1220 | {
|
---|
1221 | $(this).removeClass(from);
|
---|
1222 | $(this).addClass(to);
|
---|
1223 | }
|
---|
1224 | });
|
---|
1225 | }
|
---|
1226 |
|
---|
1227 | /**************************
|
---|
1228 | * REALISTIC BOOKS SCRIPTS *
|
---|
1229 | **************************/
|
---|
1230 |
|
---|
1231 | function bookInit()
|
---|
1232 | {
|
---|
1233 | loadBook();
|
---|
1234 | hideText();
|
---|
1235 | showBook();
|
---|
1236 | swapLinkJavascript(false);
|
---|
1237 | }
|
---|
1238 |
|
---|
1239 | function hideText()
|
---|
1240 | {
|
---|
1241 | $("#gs-document-text").css("visibility", "hidden");
|
---|
1242 | }
|
---|
1243 |
|
---|
1244 | function showText()
|
---|
1245 | {
|
---|
1246 | $("#gs-document-text").css("visibility", "visible");
|
---|
1247 | }
|
---|
1248 |
|
---|
1249 | function hideBook()
|
---|
1250 | {
|
---|
1251 | $("#bookDiv, #bookObject, #bookEmbed").css({"visibility": "hidden", "height": "0px"});
|
---|
1252 | }
|
---|
1253 |
|
---|
1254 | function showBook()
|
---|
1255 | {
|
---|
1256 | $("#bookDiv, #bookObject, #bookEmbed").css({"visibility": "visible", "height": "600px"});
|
---|
1257 | }
|
---|
1258 |
|
---|
1259 | function swapLinkJavascript(rbOn)
|
---|
1260 | {
|
---|
1261 | var option = $("#rbOption");
|
---|
1262 | var optionImage = $("#rbOptionImage");
|
---|
1263 |
|
---|
1264 | if(rbOn)
|
---|
1265 | {
|
---|
1266 | option.attr("onclick", "hideText(); showBook(); swapLinkJavascript(false);");
|
---|
1267 | optionImage.attr("onclick", "hideText(); showBook(); swapLinkJavascript(false);");
|
---|
1268 | $(option).prop("checked", false);
|
---|
1269 | }
|
---|
1270 | else
|
---|
1271 | {
|
---|
1272 | option.attr("onclick", "hideBook(); showText(); swapLinkJavascript(true);");
|
---|
1273 | optionImage.attr("onclick", "hideBook(); showText(); swapLinkJavascript(true);");
|
---|
1274 | $(option).prop("checked", true);
|
---|
1275 | }
|
---|
1276 | }
|
---|
1277 |
|
---|
1278 | function loadBook()
|
---|
1279 | {
|
---|
1280 | var doc_url = document.URL;
|
---|
1281 | doc_url = doc_url.replace(/(&|\?)book=[a-z]+/gi,'');
|
---|
1282 | doc_url += '&book=flashxml';
|
---|
1283 |
|
---|
1284 | var img_cover = gs.collectionMetadata.httpPath + '/index/assoc/' + gs.documentMetadata.assocfilepath + '/cover.jpg';
|
---|
1285 |
|
---|
1286 | var flash_plug_html = ""
|
---|
1287 | flash_plug_html += '<OBJECT align="middle" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" \n';
|
---|
1288 | flash_plug_html += ' height="600px" id="bookObject" swLiveConnect="true" \n';
|
---|
1289 | flash_plug_html += ' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" \n';
|
---|
1290 | flash_plug_html += ' width="70%">\n';
|
---|
1291 | flash_plug_html += ' <PARAM name="allowScriptAccess" value="always" />\n';
|
---|
1292 | flash_plug_html += ' <PARAM name="movie" value="Book.swf';
|
---|
1293 | flash_plug_html += '?src_image=' + escape(img_cover);
|
---|
1294 | flash_plug_html += '&doc_url=' + escape(doc_url);
|
---|
1295 | flash_plug_html += '" />\n';
|
---|
1296 | flash_plug_html += ' <PARAM name="quality" value="high" />\n';
|
---|
1297 | flash_plug_html += ' <PARAM name="bgcolor" value="#FFFFFF" />\n';
|
---|
1298 | flash_plug_html += ' <EMBED align="middle" \n';
|
---|
1299 | flash_plug_html += ' allowScriptAccess="always" swLiveConnect="true" \n';
|
---|
1300 | flash_plug_html += ' bgcolor="#FFFFFF" height="600px" name="Book" \n';
|
---|
1301 | flash_plug_html += ' pluginspage="http://www.macromedia.com/go/getflashplayer" \n';
|
---|
1302 | flash_plug_html += ' quality="high" id="bookEmbed"\n';
|
---|
1303 | flash_plug_html += ' src="Book.swf';
|
---|
1304 | flash_plug_html += '?src_image=' + escape(img_cover);
|
---|
1305 | flash_plug_html += '&doc_url=' + escape(doc_url);
|
---|
1306 | flash_plug_html += '"\n';
|
---|
1307 | flash_plug_html += ' type="application/x-shockwave-flash" width="70%" />\n';
|
---|
1308 | flash_plug_html += '</OBJECT>\n';
|
---|
1309 | $("#bookdiv").html(flash_plug_html);
|
---|
1310 | }
|
---|
1311 |
|
---|
1312 |
|
---|
1313 |
|
---|
1314 | /***************
|
---|
1315 | * MENU SCRIPTS *
|
---|
1316 | ***************/
|
---|
1317 | function moveScroller() {
|
---|
1318 | var move = function() {
|
---|
1319 | var editbar = $("#editBar");
|
---|
1320 | var st = $(window).scrollTop();
|
---|
1321 | var fa = $("#float-anchor").offset().top;
|
---|
1322 | if(st > fa) {
|
---|
1323 |
|
---|
1324 | editbar.css({
|
---|
1325 | position: "fixed",
|
---|
1326 | top: "0px",
|
---|
1327 | width: editbar.data("width"),
|
---|
1328 | //width: "30%"
|
---|
1329 | });
|
---|
1330 | } else {
|
---|
1331 | editbar.data("width", editbar.css("width"));
|
---|
1332 | editbar.css({
|
---|
1333 | position: "relative",
|
---|
1334 | top: "",
|
---|
1335 | width: ""
|
---|
1336 | });
|
---|
1337 | }
|
---|
1338 | };
|
---|
1339 | $(window).scroll(move);
|
---|
1340 | move();
|
---|
1341 | }
|
---|
1342 |
|
---|
1343 |
|
---|
1344 | function floatMenu(enabled)
|
---|
1345 | {
|
---|
1346 | var menu = $(".tableOfContentsContainer");
|
---|
1347 | if(enabled)
|
---|
1348 | {
|
---|
1349 | menu.data("position", menu.css("position"));
|
---|
1350 | menu.data("width", menu.css("width"));
|
---|
1351 | menu.data("right", menu.css("right"));
|
---|
1352 | menu.data("top", menu.css("top"));
|
---|
1353 | menu.data("max-height", menu.css("max-height"));
|
---|
1354 | menu.data("overflow", menu.css("overflow"));
|
---|
1355 | menu.data("z-index", menu.css("z-index"));
|
---|
1356 |
|
---|
1357 | menu.css("position", "fixed");
|
---|
1358 | menu.css("width", "300px");
|
---|
1359 | menu.css("right", "0px");
|
---|
1360 | menu.css("top", "100px");
|
---|
1361 | menu.css("max-height", "600px");
|
---|
1362 | menu.css("overflow", "auto");
|
---|
1363 | menu.css("z-index", "200");
|
---|
1364 |
|
---|
1365 | $("#unfloatTOCButton").show();
|
---|
1366 | }
|
---|
1367 | else
|
---|
1368 | {
|
---|
1369 | menu.css("position", menu.data("position"));
|
---|
1370 | menu.css("width", menu.data("width"));
|
---|
1371 | menu.css("right", menu.data("right"));
|
---|
1372 | menu.css("top", menu.data("top"));
|
---|
1373 | menu.css("max-height", menu.data("max-height"));
|
---|
1374 | menu.css("overflow", menu.data("overflow"));
|
---|
1375 | menu.css("z-index", menu.data("z-index"));
|
---|
1376 |
|
---|
1377 | $("#unfloatTOCButton").hide();
|
---|
1378 | $("#floatTOCToggle").prop("checked", false);
|
---|
1379 | }
|
---|
1380 |
|
---|
1381 | var url = gs.xsltParams.library_name + "?a=d&ftoc=" + (enabled ? "1" : "0") + "&c=" + gs.cgiParams.c;
|
---|
1382 |
|
---|
1383 | $.ajax(url);
|
---|
1384 | }
|
---|
1385 |
|
---|
1386 | /********************
|
---|
1387 | * SLIDESHOW SCRIPTS *
|
---|
1388 | ********************/
|
---|
1389 |
|
---|
1390 | function showSlideShow()
|
---|
1391 | {
|
---|
1392 | if(!($("#gs-slideshow").length))
|
---|
1393 | {
|
---|
1394 | var slideshowDiv = $("<div>", {id:"gs-slideshow", style:"height:100%;"});
|
---|
1395 | var loadingImage = $("<img>", {src:gs.imageURLs.loading});
|
---|
1396 | slideshowDiv.append(loadingImage);
|
---|
1397 |
|
---|
1398 | $.blockUI({message: $(slideshowDiv), css:{top: "5%", left: "5%", width: "90%", height: "90%", overflow: "auto", cursor: "auto"}});
|
---|
1399 |
|
---|
1400 | retrieveImagesForSlideShow(function(imageIDArray)
|
---|
1401 | {
|
---|
1402 | loadingImage.hide();
|
---|
1403 | if(imageIDArray && imageIDArray.length > 0)
|
---|
1404 | {
|
---|
1405 | var imageURLs = new Array();
|
---|
1406 | for(var i = 0; i < imageIDArray.length; i++)
|
---|
1407 | {
|
---|
1408 | if(imageIDArray[i].source && imageIDArray[i].source.search(/.*\.(gif|jpg|jpeg|png)$/) != -1)
|
---|
1409 | {
|
---|
1410 | imageURLs.push(gs.collectionMetadata.httpPath + "/index/assoc/" + gs.documentMetadata.assocfilepath + "/" + imageIDArray[i].source);
|
---|
1411 | }
|
---|
1412 | }
|
---|
1413 | new SlideShowWidget(slideshowDiv, imageURLs, imageIDArray);
|
---|
1414 | }
|
---|
1415 | });
|
---|
1416 | }
|
---|
1417 | else
|
---|
1418 | {
|
---|
1419 | $("#gs-slideshow").show();
|
---|
1420 | }
|
---|
1421 | }
|
---|
1422 |
|
---|
1423 | function retrieveImagesForSlideShow(callback)
|
---|
1424 | {
|
---|
1425 | var template = "";
|
---|
1426 | template += '<xsl:template match="/">';
|
---|
1427 | template += '<images>[';
|
---|
1428 | template += '<xsl:for-each select="//documentNode">';
|
---|
1429 | template += '<xsl:text disable-output-escaping="yes">{"source":"</xsl:text><gsf:metadata name="Source"/><xsl:text disable-output-escaping="yes">",</xsl:text>';
|
---|
1430 | template += '<xsl:text disable-output-escaping="yes">"id":"</xsl:text><xsl:value-of select="@nodeID"/><xsl:text disable-output-escaping="yes">"}</xsl:text>';
|
---|
1431 | template += '<xsl:if test="position() != count(//documentNode)">,</xsl:if>';
|
---|
1432 | template += '</xsl:for-each>';
|
---|
1433 | template += ']</images>';
|
---|
1434 | template += '</xsl:template>';
|
---|
1435 | template = makeURLComponentSafe(template);
|
---|
1436 | var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + gs.cgiParams.d + "?ed=1&ilt=" + template;
|
---|
1437 |
|
---|
1438 | $.ajax(
|
---|
1439 | {
|
---|
1440 | url:url,
|
---|
1441 | success: function(data)
|
---|
1442 | {
|
---|
1443 | var startIndex = data.indexOf(">", data.indexOf(">") + 1) + 1;
|
---|
1444 | var endIndex = data.lastIndexOf("<");
|
---|
1445 | var arrayString = data.substring(startIndex, endIndex);
|
---|
1446 | var imageIDArray = eval(arrayString);
|
---|
1447 |
|
---|
1448 | callback(imageIDArray);
|
---|
1449 | }
|
---|
1450 | });
|
---|
1451 | }
|
---|
1452 |
|
---|
1453 | function SlideShowWidget(mainDiv, images, idArray)
|
---|
1454 | {
|
---|
1455 | var _inTransition = false;
|
---|
1456 | var _images = new Array();
|
---|
1457 | var _mainDiv = mainDiv;
|
---|
1458 | var _imageDiv = $("<div>", {id:"ssImageDiv", style:"height:95%; overflow:auto;"});
|
---|
1459 | var _navDiv = $("<div>", {style:"height:5%;"});
|
---|
1460 | var _nextButton = $("<img>", {src:gs.imageURLs.next, style:"float:right; cursor:pointer;"});
|
---|
1461 | var _prevButton = $("<img>", {src:gs.imageURLs.prev, style:"float:left; cursor:pointer; display:none;"});
|
---|
1462 | var _closeLink = $("<a href=\"javascript:$.unblockUI()\">Close Slideshow</a>");
|
---|
1463 | var _clearDiv = $("<div>", {style:"clear:both;"});
|
---|
1464 | var _currentIndex = 0;
|
---|
1465 |
|
---|
1466 | _navDiv.append(_nextButton);
|
---|
1467 | _navDiv.append(_closeLink);
|
---|
1468 | _navDiv.append(_prevButton);
|
---|
1469 | _navDiv.append(_clearDiv);
|
---|
1470 | _mainDiv.append(_navDiv);
|
---|
1471 | _mainDiv.append(_imageDiv);
|
---|
1472 |
|
---|
1473 | for(var i = 0; i < images.length; i++)
|
---|
1474 | {
|
---|
1475 | _images.push($("<img>", {src:images[i], "class":"slideshowImage"}));
|
---|
1476 | }
|
---|
1477 |
|
---|
1478 | if(_images.length < 2)
|
---|
1479 | {
|
---|
1480 | _nextButton.css("display", "none");
|
---|
1481 | }
|
---|
1482 |
|
---|
1483 | _imageDiv.append(_images[0]);
|
---|
1484 |
|
---|
1485 | this.nextImage = function()
|
---|
1486 | {
|
---|
1487 | if(!_inTransition)
|
---|
1488 | {
|
---|
1489 | _inTransition = true;
|
---|
1490 | if((_currentIndex + 1) < _images.length)
|
---|
1491 | {
|
---|
1492 | _prevButton.css("display", "");
|
---|
1493 | if(_currentIndex + 1 == _images.length - 1)
|
---|
1494 | {
|
---|
1495 | _nextButton.css("display", "none");
|
---|
1496 | }
|
---|
1497 |
|
---|
1498 | _imageDiv.fadeOut(500, function()
|
---|
1499 | {
|
---|
1500 | _imageDiv.empty();
|
---|
1501 | _imageDiv.append(_images[_currentIndex + 1]);
|
---|
1502 | _currentIndex++;
|
---|
1503 | _imageDiv.fadeIn(500, function()
|
---|
1504 | {
|
---|
1505 | _inTransition = false;
|
---|
1506 | });
|
---|
1507 | });
|
---|
1508 | }
|
---|
1509 | else
|
---|
1510 | {
|
---|
1511 | _inTransition = false;
|
---|
1512 | }
|
---|
1513 | }
|
---|
1514 | }
|
---|
1515 |
|
---|
1516 | this.prevImage = function()
|
---|
1517 | {
|
---|
1518 | if(!_inTransition)
|
---|
1519 | {
|
---|
1520 | _inTransition = true;
|
---|
1521 | if((_currentIndex - 1) >= 0)
|
---|
1522 | {
|
---|
1523 | _nextButton.css("display", "");
|
---|
1524 | if(_currentIndex - 1 == 0)
|
---|
1525 | {
|
---|
1526 | _prevButton.css("display", "none");
|
---|
1527 | }
|
---|
1528 |
|
---|
1529 | _imageDiv.fadeOut(500, function()
|
---|
1530 | {
|
---|
1531 | _imageDiv.empty();
|
---|
1532 | _imageDiv.append(_images[_currentIndex - 1]);
|
---|
1533 | _currentIndex--;
|
---|
1534 | _imageDiv.fadeIn(500, function()
|
---|
1535 | {
|
---|
1536 | _inTransition = false;
|
---|
1537 | });
|
---|
1538 | });
|
---|
1539 | }
|
---|
1540 | else
|
---|
1541 | {
|
---|
1542 | _inTransition = false;
|
---|
1543 | }
|
---|
1544 | }
|
---|
1545 | }
|
---|
1546 |
|
---|
1547 | var getRootFilenameFromURL = function(url)
|
---|
1548 | {
|
---|
1549 | var urlSegments = url.split("/");
|
---|
1550 | var filename = urlSegments[urlSegments.length - 1];
|
---|
1551 | return filename.replace(/_thumb\..*$/, "");
|
---|
1552 | }
|
---|
1553 |
|
---|
1554 | var setLink = function(currentLink, index)
|
---|
1555 | {
|
---|
1556 | $(currentLink).click(function()
|
---|
1557 | {
|
---|
1558 | _inTransition = true;
|
---|
1559 | _currentIndex = index;
|
---|
1560 | _imageDiv.fadeOut(500, function()
|
---|
1561 | {
|
---|
1562 | _imageDiv.empty();
|
---|
1563 | _imageDiv.append(_images[_currentIndex]);
|
---|
1564 | _imageDiv.fadeIn(500, function()
|
---|
1565 | {
|
---|
1566 | _inTransition = false;
|
---|
1567 | });
|
---|
1568 | });
|
---|
1569 | });
|
---|
1570 | }
|
---|
1571 |
|
---|
1572 | var sliderLinks = $(".pageSliderCol a");
|
---|
1573 | for(var i = 0; i < sliderLinks.length; i++)
|
---|
1574 | {
|
---|
1575 | var currentLink = sliderLinks[i];
|
---|
1576 | var id = $(currentLink).attr("href").split("'")[1];
|
---|
1577 |
|
---|
1578 | for(var j = 0; j < idArray.length; j++)
|
---|
1579 | {
|
---|
1580 | if(idArray[j].id == id)
|
---|
1581 | {
|
---|
1582 | var image = idArray[j].source;
|
---|
1583 |
|
---|
1584 | for(var l = 0; l < images.length; l++)
|
---|
1585 | {
|
---|
1586 | var filename = getRootFilenameFromURL(images[l]);
|
---|
1587 | if (filename == image)
|
---|
1588 | {
|
---|
1589 | setLink(currentLink, l);
|
---|
1590 | break;
|
---|
1591 | }
|
---|
1592 | }
|
---|
1593 |
|
---|
1594 | break;
|
---|
1595 | }
|
---|
1596 | }
|
---|
1597 | }
|
---|
1598 |
|
---|
1599 | _nextButton.click(this.nextImage);
|
---|
1600 | _prevButton.click(this.prevImage);
|
---|
1601 | }
|
---|