var _imageZoomEnabled = false; var _linkCellMap = new Array(); var _onCells = new Array(); /******************** * EXPANSION SCRIPTS * ********************/ function getTextForSection(sectionID, callback) { if(!callback) { console.log("Cannot get text as the callback function is not defined"); } var template = ""; template += ''; template += ''; template += ''; template += ''; template += ''; template += ''; template += ''; var hlCheckBox = document.getElementById("highlightOption"); var hl = ""; if(hlCheckBox) { if(hlCheckBox.checked) { hl = "on"; } else { hl = "off"; } } var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + sectionID + "?hl=" + hl + "&p.s=TextQuery&ilt=" + template.replace(" ", "%20"); $.ajax(url) .success(function(response) { if(response) { var textStart = response.indexOf(">", response.indexOf(">") + 1) + 1; var textEnd = response.lastIndexOf("<"); if(textStart == 0 || textEnd == -1 || textEnd <= textStart) { callback(""); } var text = response.substring(textStart, textEnd); callback(text); } else { callback(null); } }) .error(function() { callback(null); }); } function getSubSectionsForSection(sectionID, callback) { if(!callback) { console.log("Cannot get sub sections as the callback function is not defined"); } var template = ""; template += ''; template += ''; template += ''; template += ''; template += ''; template += ''; template += ''; var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + sectionID + "?ilt=" + template.replace(" ", "%20"); if(gs.documentMetadata.docType == "paged") { url += "&dt=hierarchy"; } $.ajax(url) .success(function(response) { if(response) { var sectionsStart = response.indexOf(">", response.indexOf(">") + 1) + 1; var sectionsEnd = response.lastIndexOf("<"); if(sectionsStart == 0 || sectionsEnd == -1 || sectionsEnd <= sectionsStart) { callback(" "); return; } var sections = response.substring(sectionsStart, sectionsEnd); callback(sections); } else { callback(null); } }) .error(function() { callback(null); }); } function toggleSection(sectionID, callback, tocDisabled) { var docElem = gs.jqGet("doc" + sectionID); var tocElem = gs.jqGet("toc" + sectionID); var tocToggleElem = gs.jqGet("ttoggle" + sectionID); var docToggleElem = gs.jqGet("dtoggle" + sectionID); if(docElem.css("display") == "none") { if(tocToggleElem.length && !tocDisabled) { tocToggleElem.attr("src", gs.imageURLs.collapse); } if(tocElem.length && !tocDisabled) { tocElem.css("display", "block"); } if(docElem.hasClass("noText")) { getTextForSection(sectionID, function(text) { if(text) { var nodeID = sectionID.replace(/\./g, "_"); if(text.search("wrap" + nodeID) != -1) { $("#zoomOptions").css("display", ""); $("#pagedImageOptions").css("display", ""); } getSubSectionsForSection(sectionID, function(sections) { if(sections) { var textElem = gs.jqGet("doc" + sectionID); textElem.html(text + sections); docElem.removeClass("noText"); docElem.css("display", "block"); docToggleElem.attr("src", gs.imageURLs.collapse); if(callback) { callback(true); } if(gs.jqGet("viewSelection").length) { changeView(); } } else { docToggleElem.attr("src", gs.imageURLs.expand); if(callback) { callback(false); } } }); } else { docToggleElem.attr("src", gs.imageURLs.expand); if(callback) { callback(false); } } }); docToggleElem.attr("src", gs.imageURLs.loading); } else { docToggleElem.attr("src", gs.imageURLs.collapse); docElem.css("display", "block"); if(callback) { callback(true); } } } else { docElem.css("display", "none"); //Use the page image if this is a leaf node and the chapter image if it not docToggleElem.attr("src", gs.imageURLs.expand); if(tocToggleElem.length) { tocToggleElem.attr("src", gs.imageURLs.expand); } if(tocElem.length) { tocElem.css("display", "none"); } if(callback) { callback(true); } } } function scrollToTop() { $('html, body').stop().animate({scrollTop: 0}, 1000); } function focusSection(sectionID, level, tocDisabled) { if(!level) { level = 0; } var parts = sectionID.split("."); if(level >= parts.length) { var topVal = $(document.getElementById("doc" + sectionID)).offset().top - 50; $('html, body').stop().animate({scrollTop: topVal}, 1000); return; } var idToExpand = ""; for(var i = 0; i < level + 1; i++) { if(i > 0) { idToExpand += "."; } idToExpand += parts[i]; } if(!isExpanded(idToExpand)) { toggleSection(idToExpand, function(success) { if(success) { focusSection(sectionID, level + 1, tocDisabled); } }, tocDisabled); } else { focusSection(sectionID, level + 1, tocDisabled); } } function expandOrCollapseAll(expand) { var divs = $("div"); var startCounter = 0; var endCounter = 0; for(var i = 0; i < divs.length; i++) { if($(divs[i]).attr("id") && $(divs[i]).attr("id").search(/^doc/) != -1) { var id = $(divs[i]).attr("id").replace(/^doc(.*)/, "$1"); if(isExpanded(id) != expand) { //Don't collapse the top level if(!expand && id.indexOf(".") == -1) { continue; } startCounter++; var toggleFunction = function(tid) { toggleSection(tid, function(success) { if(success) { endCounter++; } else { setTimeout(function(){toggleFunction(tid)}, 500); } }); } toggleFunction(id); } } } if(startCounter != 0) { var checkFunction = function() { if(startCounter == endCounter) { expandOrCollapseAll(expand); } else { setTimeout(checkFunction, 500); } } checkFunction(); } } function loadTopLevelPage(callbackFunction, customURL) { var url; if(customURL) { url = customURL; } else { url = gs.xsltParams.library_name + "?a=d&c=" + gs.cgiParams.c + "&excerptid=gs-document"; if(gs.cgiParams.d && gs.cgiParams.d.length > 0) { url += "&d=" + gs.cgiParams.d.replace(/([^.]*)\..*/, "$1"); } else if(gs.cgiParams.href && gs.cgiParams.href.length > 0) { url += "&d=&alb=1&rl=1&href=" + gs.cgiParams.href; } } $.ajax(url) .success(function(response) { if(response) { var targetElem = $("#gs-document"); var docStart = response.indexOf(">") + 1; var docEnd = response.lastIndexOf("<"); var doc = response.substring(docStart, docEnd); targetElem.html(doc); if(callbackFunction) { callbackFunction(); } } }) .error(function() { setTimeout(function(){loadTopLevelPage(callbackFunction, customURL);}, 1000); }); } function retrieveFullTableOfContents() { var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "?excerptid=tableOfContents&ed=1"; if(gs.cgiParams.d && gs.cgiParams.d.length > 0) { url += "&a=d&d=" + gs.cgiParams.d; } else if(gs.cgiParams.href && gs.cgiParams.href.length > 0) { url += "&a=d&d=&alb=1&rl=1&href=" + gs.cgiParams.href; } $.ajax(url) .success(function(newTOCElem) { var tocStart = newTOCElem.indexOf(">") + 1; var tocEnd = newTOCElem.lastIndexOf("<"); var newTOC = newTOCElem.substring(tocStart, tocEnd); //Add the "Expand document"/"Collapse document" links newTOC = "
Expand documentCollapse document
" + newTOC; //Collapse the TOC newTOC = newTOC.replace(/display:block/g, "display:none"); newTOC = newTOC.replace(/display:none/, "display:block"); newTOC = newTOC.replace(/images\/collapse/g, "images/expand"); var tocElem = $("#tableOfContents"); tocElem.html(newTOC); gs.variables.tocLoaded = true; }) .error(function() { setTimeout(retrieveFullTableOfContents, 1000); }); } function isExpanded(sectionID) { var docElem = gs.jqGet("doc" + sectionID); if(docElem.css("display") == "block") { return true; } return false; } function minimizeSidebar() { var toc = $("#contentsArea"); var maxLink = $("#sidebarMaximizeButton"); var minLink = $("#sidebarMinimizeButton"); if(toc.length) { toc.css("display", "none"); } maxLink.css("display", "block"); minLink.css("display", "none"); } function maximizeSidebar() { var coverImage = $("#coverImage"); var toc = $("#contentsArea"); var maxLink = $("#sidebarMaximizeButton"); var minLink = $("#sidebarMinimizeButton"); if(coverImage.length) { coverImage.css("display", "block"); } if(toc.length) { toc.css("display", "block"); } maxLink.css("display", "none"); minLink.css("display", "block"); } /********************** * PAGED-IMAGE SCRIPTS * **********************/ function changeView() { var viewList = $("#viewSelection"); var currentVal = viewList.val(); var view; if(currentVal == "Image view") { setImageVisible(true); setTextVisible(false); view = "image"; } else if(currentVal == "Text view") { setImageVisible(false); setTextVisible(true); view = "text"; } else { setImageVisible(true); setTextVisible(true); view = ""; } var url = gs.xsltParams.library_name + "?a=d&view=" + view + "&c=" + gs.cgiParams.c; $.ajax(url); } function setImageVisible(visible) { $("div").each(function() { if($(this).attr("id") && $(this).attr("id").search(/^image/) != -1) { $(this).css("display", (visible ? "block" : "none")); } }); } function setTextVisible(visible) { $("div").each(function() { if($(this).attr("id") && $(this).attr("id").search(/^text/) != -1) { $(this).css("display", (visible ? "block" : "none")); } }); } function retrieveTableOfContentsAndTitles() { var ilt = ""; ilt += ''; ilt += ''; ilt += ''; ilt += ''; ilt += ''; var url = gs.xsltParams.library_name + "?a=d&ed=1&c=" + gs.cgiParams.c + "&d=" + gs.cgiParams.d + "&ilt=" + ilt.replace(/ /g, "%20"); $.ajax(url) .success(function(response) { $("#tableOfContents").html(response); replaceLinksWithSlider(); var loading = $("#tocLoadingImage"); loading.remove(); }) .error(function() { setTimeout(function(){retrieveTableOfContentsAndTitles();}, 1000); }); } function replaceLinksWithSlider() { var tableOfContents = $("#tableOfContents"); var leafSections = new Array(); var liElems = tableOfContents.find("li").each(function() { var section = $(this); var add = true; for(var j = 0; j < leafSections.length; j++) { if(leafSections[j] == undefined){continue;} var leaf = $(leafSections[j]); if(leaf.attr("id").search(section.attr("id")) != -1) { add = false; } if(section.attr("id").search(leaf.attr("id")) != -1) { delete leafSections[j]; } } if(add) { leafSections.push(section); } }); for(var i = 0 ; i < leafSections.length; i++) { if(leafSections[i] == undefined){continue;} leafSections[i].css("display", "none"); var links = leafSections[i].find("a"); var widget = new SliderWidget(links); leafSections[i].before(widget.getElem()); } //Disable all TOC toggles var imgs = $("img").each(function() { var currentImage = $(this); if(currentImage.attr("id") && currentImage.attr("id").search(/^ttoggle/) != -1) { currentImage.attr("onclick", ""); } else if(currentImage.attr("id") && currentImage.attr("id").search(/^dtoggle/) != -1) { currentImage.attr("onclick", currentImage.attr("onclick").replace(/\)/, ", null, true)")); } }); } function SliderWidget(_links) { //**************** //MEMBER VARIABLES //**************** //The container for the widget var _mainDiv = $("
"); _mainDiv.attr("class", "ui-widget-content pageSlider"); //The table of images var _linkTable = $(""); _mainDiv.append(_linkTable); //The image row of the table var _linkRow = $(""); _linkTable.append(_linkRow); //The list of titles we can search through var _titles = new Array(); //Keep track of the slider position var _prevScroll = 0; //**************** //PUBLIC FUNCTIONS //**************** //Function that returns the widget element this.getElem = function() { return _mainDiv; } //***************** //PRIVATE FUNCTIONS //***************** var setUpFilterBox = function() { var filter = $("#filterText"); filter.keyup(function() { var currentValue = filter.val(); var isRange = (currentValue.search(/\d+-\d+/) != -1) var found = false; for(var i = 0; i < _titles.length; i++) { if(_titles[i][0] == currentValue) { found = true; } } if(!found && isRange) { var firstNumber = currentValue.replace(/^(\d+)-\d+$/, "$1"); var secondNumber = currentValue.replace(/^\d+-(\d+)$/, "$1"); if(firstNumber <= secondNumber) { var matchingTitles = new Array(); for(var i = firstNumber; i <= secondNumber; i++) { var numString = i + ""; for(var j = 0; j < _titles.length; j++) { var currentTitle = _titles[j]; if(currentTitle[0].search(numString) != -1) { matchingTitles.push(currentTitle); } } } for(var i = 0; i < _titles.length; i++) { $(_titles[i][1].cell).css("display", "none"); } for(var i = 0; i < matchingTitles.length; i++) { $(matchingTitles[i][1].cell).css("display", "table-cell"); } } } else { for(var i = 0; i < _titles.length; i++) { var currentTitle = _titles[i]; if(currentTitle[0].search(currentValue.replace(/\./g, "\\.")) != -1) { $(currentTitle[1].cell).css("display", "table-cell"); } else { $(currentTitle[1].cell).css("display", "none"); } } } }); } var getImage = function(page, attemptNumber) { var href = page.getAttribute("href"); var startHREF = href.indexOf("'") + 1; var endHREF = href.indexOf("'", startHREF); var nodeID = href.substring(startHREF, endHREF); href = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + nodeID; var template = ''; template += ''; template += ''; template += ''; template += ''; template += ''; template += ""; template += '/index/assoc/'; template += ""; template += '/'; template += ""; template += ''; template += ''; template += '

'; template += ""; template += '

'; template += ''; template += '
'; var url = href + "?ilt=" + template.replace(" ", "%20"); $.ajax(url) .success(function(text) { var hrefStart = text.indexOf("src=\"") + 5; if(hrefStart == -1) { page.isLoading = false; page.noImage = true; $(page.image).attr("src", gs.imageURLs.blank); return; } var hrefEnd = text.indexOf("\"", hrefStart); var href = text.substring(hrefStart, hrefEnd); var image = $(""); image.load(function() { $(page.link).html(""); $(page.link).append(image); page.isLoading = false; page.imageLoaded = true; }); image.error(function() { if(!attemptNumber || attemptNumber < 3) { setTimeout(function(){getImage(page, ((!attemptNumber) ? 1 : attemptNumber + 1));}, 500); } else { page.isLoading = false; page.noImage = true; image.attr("src", gs.imageURLs.blank); } }); image.attr("src", href); var titleStart = text.indexOf("

") + 3; var titleEnd = text.indexOf("

"); var title = text.substring(titleStart, titleEnd); }) .error(function() { page.failed = true; if(!attemptNumber || attemptNumber < 3) { setTimeout(function(){getImage(page, ((!attemptNumber) ? 1 : attemptNumber + 1));}, 500); } else { var image = $("", {"src": gs.imageURLs.blank}); $(page.link).html(""); $(page.link).append(image); page.isLoading = false; page.noImage = true; } }); } var startCheckFunction = function() { var checkFunction = function(forced) { //Don't bother checking if we haven't scrolled very far if(Math.abs(_mainDiv.scrollLeft() - _prevScroll) > 100 || forced) { _prevScroll = _mainDiv.scrollLeft(); _checking = true; var widgetLeft = _mainDiv.offset().left; var widgetRight = widgetLeft + _mainDiv.width(); var visiblePages = new Array(); for(var i = 0; i < _links.length; i++) { var current = _links[i].cell; var currentLeft = current.offset().left; var currentRight = currentLeft + current.width(); if(currentRight > widgetLeft && currentLeft < widgetRight) { visiblePages.push(_links[i]); } } for(var i = 0; i < visiblePages.length; i++) { var page = visiblePages[i]; if(!page || page.imageLoaded || page.noImage || page.isLoading) { continue; } page.isLoading = true; getImage(page); } _checking = false; } } setTimeout(checkFunction, 250); setInterval(function(){checkFunction(true)}, 2000); _mainDiv.scroll(checkFunction); } //*********** //CONSTRUCTOR //*********** for(var i = 0; i < _links.length; i++) { var col = $("
"); _linkRow.append(col); col.addClass("pageSliderCol"); _links[i].cell = col; var link = $(""); col.append(link); _links[i].link = link; var href = $(_links[i]).attr("href"); link.attr("href", href.replace(/\)/, ", 0, true)")); if(!_linkCellMap[href]) { _linkCellMap[href] = new Array(); } _linkCellMap[href].push(_links[i]); var loadingText = $("

Loading image

"); link.append(loadingText); var image = $(""); link.append(image); image.attr("src", gs.imageURLs.loading); _links[i].image = image; var title = $(_links[i]).html(); if(title.search(/^[^ ]+ [^ ]+$/) != -1) { var section = title.replace(/^([^ ]+) [^ ]+$/, "$1"); var page = title.replace(/^[^ ]+ ([^ ]+)$/, "$1"); if(page.search(/^[0-9]+$/) != -1) { title = page; } } _titles.push([title, _links[i]]); col.append($("
")); col.append(title); } setUpFilterBox(); startCheckFunction(); } /*********************** * HIGHLIGHTING SCRIPTS * ***********************/ function swapHighlight(imageClicked) { var hlCheckbox = $("#highlightOption"); if(imageClicked) { $(hlCheckbox).attr("checked", !$(hlCheckbox).attr("checked")); } var from; var to; if(hlCheckbox.attr("checked")) { from = "noTermHighlight"; to = "termHighlight"; } else { from = "termHighlight"; to = "noTermHighlight"; } var spans = $("span").each(function() { if($(this).hasClass(from)) { $(this).removeClass(from); $(this).addClass(to); } }); } /************************** * REALISTIC BOOKS SCRIPTS * **************************/ function bookInit() { loadBook(); hideText(); showBook(); swapLinkJavascript(false); } function hideText() { $("#gs-document-text").css("visibility", "hidden"); } function showText() { $("#gs-document-text").css("visibility", "visible"); } function hideBook() { $("#bookDiv, #bookObject, #bookEmbed").css({"visibility": "hidden", "height": "0px"}); } function showBook() { $("#bookDiv, #bookObject, #bookEmbed").css({"visibility": "visible", "height": "600px"}); } function swapLinkJavascript(rbOn) { var option = $("#rbOption"); var optionImage = $("#rbOptionImage"); if(rbOn) { option.attr("onclick", "hideText(); showBook(); swapLinkJavascript(false);"); optionImage.attr("onclick", "hideText(); showBook(); swapLinkJavascript(false);"); $(option).attr("checked", false); } else { option.attr("onclick", "hideBook(); showText(); swapLinkJavascript(true);"); optionImage.attr("onclick", "hideBook(); showText(); swapLinkJavascript(true);"); $(option).attr("checked", true); } } function loadBook() { var doc_url = document.URL; doc_url = doc_url.replace(/(&|\?)book=[a-z]+/gi,''); doc_url += '&book=flashxml'; var img_cover = gs.collectionMetadata.httpPath + '/index/assoc/' + gs.documentMetadata.assocfilepath + '/cover.jpg'; var flash_plug_html = "" flash_plug_html += '", {"style": "font-size:0.7em; padding:0px 10px", "class": "editMetadataButton"}); var linkSpan = $("", {"class": "ui-state-default ui-corner-all", "style": "padding: 2px; float:left;"}); var linkLabel = $("edit metadata"); var linkIcon = $("", {"class": "ui-icon ui-icon-folder-collapsed"}); newCell.linkIcon = linkIcon; newCell.linkLabel = linkLabel; var uList = $("