[24520] | 1 | var inProgress = new Array();
|
---|
| 2 | var openClassifiers = new Array();
|
---|
| 3 | var busy = false;
|
---|
| 4 |
|
---|
| 5 | function isExpanded(sectionID)
|
---|
| 6 | {
|
---|
[26396] | 7 | var divElem = gs.jqGet("div" + sectionID);
|
---|
| 8 | if(!divElem.css("display") || divElem.css("display") != "none")
|
---|
[24520] | 9 | {
|
---|
| 10 | return true;
|
---|
| 11 | }
|
---|
| 12 | return false;
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 | function toggleSection(sectionID)
|
---|
| 16 | {
|
---|
[26396] | 17 | var section = gs.jqGet("div" + sectionID);
|
---|
| 18 | var sectionToggle = gs.jqGet("toggle" + sectionID);
|
---|
[24520] | 19 |
|
---|
| 20 | if(sectionToggle == undefined)
|
---|
| 21 | {
|
---|
| 22 | return;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
[26396] | 25 | //If the div exists
|
---|
[33145] | 26 | // Test if 'section' exists.
|
---|
| 27 | // ==> Because we're using jQuery to do this we need to test the length of the object returned
|
---|
| 28 | // http://stackoverflow.com/questions/920236/how-can-i-detect-if-a-selector-returns-null
|
---|
| 29 | if(section.length !== 0)
|
---|
[24520] | 30 | {
|
---|
[33289] | 31 | var expanding = false;
|
---|
[24520] | 32 | if(isExpanded(sectionID))
|
---|
| 33 | {
|
---|
[33289] | 34 | expanding = false;
|
---|
[26396] | 35 | section.css("display", "none");
|
---|
| 36 | sectionToggle.attr("src", gs.imageURLs.expand);
|
---|
| 37 |
|
---|
[33145] | 38 | if(openClassifiers[sectionID].length !== 0) //if(openClassifiers[sectionID] != undefined)
|
---|
[24520] | 39 | {
|
---|
| 40 | delete openClassifiers[sectionID];
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 | else
|
---|
| 44 | {
|
---|
[33289] | 45 | expanding = true;
|
---|
[26396] | 46 | section.css("display", "block");
|
---|
| 47 | sectionToggle.attr("src", gs.imageURLs.collapse);
|
---|
[24520] | 48 | openClassifiers[sectionID] = true;
|
---|
| 49 | }
|
---|
| 50 | updateOpenClassifiers();
|
---|
[33289] | 51 | if(typeof mapEnabled !== 'undefined' /*&& mapEnabled*/){
|
---|
[33168] | 52 | //console.log("Classifier scripts -> updateMap()");
|
---|
[33289] | 53 | toggleMapSection({"expand": expanding, "nodeID": sectionID});
|
---|
[33146] | 54 | updateMap();
|
---|
| 55 | }
|
---|
[24520] | 56 | }
|
---|
| 57 | else
|
---|
| 58 | {
|
---|
[33217] | 59 | httpBrowseRequest(sectionID);
|
---|
[24520] | 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | function updateOpenClassifiers()
|
---|
| 64 | {
|
---|
| 65 | var oc = "";
|
---|
| 66 | var first = true;
|
---|
| 67 | for(var key in openClassifiers)
|
---|
| 68 | {
|
---|
| 69 | if(first)
|
---|
| 70 | {
|
---|
| 71 | first = false;
|
---|
| 72 | }
|
---|
| 73 | else
|
---|
| 74 | {
|
---|
| 75 | oc += ",";
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | oc += key;
|
---|
| 79 | }
|
---|
[33153] | 80 |
|
---|
| 81 | if(oc != undefined && oc != "")
|
---|
[24520] | 82 | {
|
---|
| 83 | window.location.hash = oc;
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | function openStoredClassifiers()
|
---|
| 88 | {
|
---|
| 89 | if(window.location.hash != undefined && window.location.hash.length > 1)
|
---|
| 90 | {
|
---|
| 91 | var toOpen = window.location.hash.substring(1,window.location.hash.length).split(",");
|
---|
| 92 | var loopFunction = function(sectionArray, index)
|
---|
| 93 | {
|
---|
| 94 | if(!busy && index < sectionArray.length)
|
---|
| 95 | {
|
---|
| 96 | busy = true;
|
---|
| 97 | toggleSection(sectionArray[index]);
|
---|
| 98 | setTimeout(function()
|
---|
| 99 | {
|
---|
| 100 | loopFunction(sectionArray, index + 1);
|
---|
[24555] | 101 | }, 25);
|
---|
[24520] | 102 |
|
---|
[24555] | 103 | return true;
|
---|
[24520] | 104 | }
|
---|
| 105 |
|
---|
| 106 | setTimeout(function()
|
---|
| 107 | {
|
---|
| 108 | loopFunction(sectionArray, index);
|
---|
[24555] | 109 | }, 25);
|
---|
[24520] | 110 | return false;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | if(toOpen.length > 0)
|
---|
| 114 | {
|
---|
| 115 | loopFunction(toOpen, 0);
|
---|
| 116 | }
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[33217] | 120 | function httpBrowseRequest(sectionID)
|
---|
[24520] | 121 | {
|
---|
| 122 | if(!inProgress[sectionID])
|
---|
| 123 | {
|
---|
[33128] | 124 | inProgress[sectionID] = true;
|
---|
[24520] | 125 |
|
---|
[26396] | 126 | var sectionToggle = gs.jqGet("toggle" + sectionID);
|
---|
| 127 | sectionToggle.attr("src", gs.imageURLs.loading);
|
---|
[25442] | 128 |
|
---|
| 129 | var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + sectionID.replace(/\./g, "/") + "?excerptid=div" + sectionID;
|
---|
[24520] | 130 |
|
---|
[29277] | 131 | if(gs.cgiParams.berrybasket == "on")
|
---|
[24520] | 132 | {
|
---|
| 133 | url = url + "&berrybasket=on";
|
---|
[29277] | 134 | }
|
---|
[33286] | 135 | if(gs.cgiParams.favouritebasket == "on")
|
---|
[33259] | 136 | {
|
---|
[33286] | 137 | url = url + "&favouritebasket=on";
|
---|
[33259] | 138 | }
|
---|
[24520] | 139 |
|
---|
[24521] | 140 | if(url.indexOf("#") != -1)
|
---|
| 141 | {
|
---|
| 142 | url = url.substring(0, url.indexOf("#"));
|
---|
| 143 | }
|
---|
[26396] | 144 |
|
---|
| 145 | $.ajax(url)
|
---|
[36027] | 146 | .done(function(data)
|
---|
[24520] | 147 | {
|
---|
[26396] | 148 | var newDiv = $("<div>");
|
---|
| 149 | var sibling = gs.jqGet("title" + sectionID);
|
---|
| 150 | sibling.after(newDiv);
|
---|
| 151 |
|
---|
| 152 | newDiv.html(data);
|
---|
| 153 | sectionToggle.attr("src", gs.imageURLs.collapse);
|
---|
| 154 | openClassifiers[sectionID] = true;
|
---|
| 155 |
|
---|
[29277] | 156 | if(gs.cgiParams.berrybasket == "on")
|
---|
[24520] | 157 | {
|
---|
[33259] | 158 | berryCheckout();
|
---|
[24520] | 159 | }
|
---|
[33286] | 160 | if(gs.cgiParams.favouritebasket == "on")
|
---|
[26396] | 161 | {
|
---|
[33259] | 162 | favouritesCheckout();
|
---|
| 163 | }
|
---|
| 164 | if(gs.cgiParams.documentbasket == "on")
|
---|
| 165 | {
|
---|
[26396] | 166 | dmcheckout();
|
---|
| 167 | }
|
---|
[33146] | 168 | updateOpenClassifiers();
|
---|
[33187] | 169 | if(typeof mapEnabled !== 'undefined'){
|
---|
[33217] | 170 | httpMapBrowseRequest(sectionID);
|
---|
[33146] | 171 | }
|
---|
[26396] | 172 | })
|
---|
[36027] | 173 | .fail(function()
|
---|
[26396] | 174 | {
|
---|
| 175 | sectionToggle.attr("src", gs.imageURLs.expand);
|
---|
| 176 | })
|
---|
[36027] | 177 | .always(function()
|
---|
[26396] | 178 | {
|
---|
| 179 | inProgress[sectionID] = false;
|
---|
| 180 | busy = false;
|
---|
| 181 | });
|
---|
[24520] | 182 | }
|
---|
[33153] | 183 | }
|
---|