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

Last change on this file since 29213 was 29213, checked in by kjdon, 10 years ago

added a class to metadataSetList to make it the same colour as the other controls. Added a couple of customization vars

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