source: main/trunk/greenstone3/web/interfaces/default/js/document_scripts.js@ 32774

Last change on this file since 32774 was 32774, checked in by ak19, 5 years ago

Kathy's style of char replacement reads simpler.

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