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

Last change on this file since 28279 was 28279, checked in by sjm84, 11 years ago

Added some status information when extracting a document

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