" + 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;
}
function retrieveFullTableOfContentsSuccessClientSideXSLT(newTOCElem)
{
$('#client-side-xslt-ajax').remove();
retrieveFullTableOfContentsSuccess(newTOCElem)
}
function retrieveFullTableOfContents()
{
var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "?excerptid=tableOfContents&ec=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;
}
// later on we want this arg p.s so we can keep search term highlighting for expand document link
if (gs.cgiParams.p_s && gs.cgiParams.p_s.length > 0) {
url += "&p.s=" + gs.cgiParams.p_s;
}
if (gs.xsltParams.use_client_side_xslt == "true") { // note xsltParams are of type string, so test needs to be in quotes
url += "&callback=retrieveFullTableOfContentsSuccessClientSideXSLT"; // used in client-side-xslt.js, in combination with 'excerptid'
$('').appendTo('body');
}
else {
$.ajax(url)
.success(retrieveFullTableOfContentsSuccess)
.error(function() {
setTimeout(retrieveFullTableOfContents, 1000);
});
}
}
function isSectionExpanded(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");
}
function extractFilteredPagesToOwnDocument()
{
var oids = new Array();
var filtered = $(".pageSliderCol:visible a").each(function()
{
var hrefString = $(this).attr("href");
var oidStart = hrefString.indexOf(".") + 1;
var oidFinish = hrefString.indexOf("'", oidStart + 1);
oids.push(hrefString.substring(oidStart, oidFinish));
});
var sectionString = "[";
for(var i = 0; i < oids.length; i++)
{
sectionString += "\"" + oids[i] + "\"";
if(i < oids.length - 1)
{
sectionString += ",";
}
}
sectionString += "]";
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"]"
$("#extractDocButton").attr("disabled", "disabled").html("Extracting document...");
$.ajax(url)
.success(function(response)
{
$("#extractDocButton").html("Building collection...");
gs.functions.buildCollections([gs.cgiParams.c], function()
{
$("#extractDocButton").removeAttr("disabled").html("Extract these pages to document");
});
})
.error(function()
{
$("#extractDocButton").removeAttr("disabled").html("Extract these pages to document");
});
}
/**********************
* 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&ec=1&c=" + gs.cgiParams.c + "&d=" + gs.cgiParams.d + "&ilt=" + ilt.replace(/ /g, "%20");
$.ajax(url)
.success(function(response)
{
var tableOfContents = $("#tableOfContents");
tableOfContents.append(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", "");
currentImage.click(function()
{
var sliderDiv = currentImage.parents("table").first().next();
if(sliderDiv.is(":visible"))
{
sliderDiv.hide();
}
else
{
sliderDiv.show();
}
});
}
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
//*****************
// _filter_on_types can be "sectionnum", "sectiontitle"
var setUpFilterButtons = function() {
var button_div = $("#filterOnButtons");
button_div.onclick = doFiltering;
button_div.html("radio");
if (_filter_on_types.length == 0) {
_filter_on_types = ["sectionnum", "sectiontitle"];
}
else if (_filter_on_types.length == 1) {
if (_filter_on_types[0] == "sectionnum") {
button_div.html("("+gs.text.doc.filter.pagenum+")");
} else {
button_div.html("("+gs.text.doc.filter.title+")");
}
} else {
// should be both options
button_div.html(""+gs.text.doc.filter.pagenum+""+gs.text.doc.filter.title+"");
}
}
var doFiltering = function () {
if (typeof _titles == "undefined") {
return;
}
var filter_string = $("#filterText").val();
var filter_type = $('input[name="filterOn"]:checked').val();
var index = 2; // section num
var numeric_match = true;
if (filter_type == "title") {
index = 3;
if (_filter_title_numeric != true) {
numeric_match = false;
}
}
var values = filter_string.split(",");
var matchingTitles = new Array();
for (var l = 0; l < values.length; l++)
{
var currentValue = values[l].replace(/^ +/g, "").replace(/ +$/g, "");
if (numeric_match) {
var isRange = (currentValue.search(/^\d+-\d+$/) != -1);
if (isRange) {
var firstNumber = Number(currentValue.replace(/(\d+)-\d+/, "$1"));
var secondNumber = Number(currentValue.replace(/\d+-(\d+)/, "$1"));
if(firstNumber <= secondNumber)
{
for(var i = firstNumber; i <= secondNumber; i++)
{
var numString = i + "";
for(var j = 0; j < _titles.length; j++) {
var currentTitle = _titles[j];
if(currentTitle[index] == numString) {
matchingTitles.push(currentTitle);
break; // assume no titles are the same
}
}
}
}
} // if isRange
else {
for(var j = 0; j < _titles.length; j++) {
if (_titles[j][index]==currentValue) {
matchingTitles.push(_titles[j]);
break; // assume no titles are the same
}
}
}
} else { // not numeric match.
// need to do a search
for(var i = 0; i < _titles.length; i++)
{
var currentTitle = _titles[i];
if(currentTitle[index].toLowerCase().search(currentValue.toLowerCase().replace(/\./g, "\\.")) != -1)
{
matchingTitles.push(currentTitle);
}
}
}
} // for each value from filter string
// set all to hide...
for(var i = 0; i < _titles.length; i++)
{
$(_titles[i][1].cell).css("display", "none");
}
// .. then display the matching ones
for(var i = 0; i < matchingTitles.length; i++)
{
$(matchingTitles[i][1].cell).css("display", "table-cell");
}
} // end doFiltering() function
var setUpFilterBox = function()
{
var filter = $("#filterText");
filter.keyup(function()
{
doFiltering();
});
}
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 += '/index/assoc/';
template += "";
template += '/';
template += "";
template += '';
template += '';
template += '