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

Last change on this file since 31520 was 31520, checked in by kjdon, 7 years ago

a couple of small but significant changes. when getting the table of contents and using excerptid, just use ec=1 (expand contents) rather than ed=1 (expand document). the prevents us having to retrieve all the text sections of the document just to get the table of contents out. add the expand document and collapse document links into the toc when ed=1 or ec=1. they weren't there before. So then we don't need to add them to toc after retrieving toc, as they are already present. Lastly, changed the expand and collapse doc links to be standard html links - a full reload of the document - rather than javascript. HOpefully this will mean that google can follow these links and index the pages. need to test this out as the toc is not part of the original page source.

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