[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 | {
|
---|
| 31 | if(isExpanded(sectionID))
|
---|
| 32 | {
|
---|
[26396] | 33 | section.css("display", "none");
|
---|
| 34 | sectionToggle.attr("src", gs.imageURLs.expand);
|
---|
| 35 |
|
---|
[33145] | 36 | if(openClassifiers[sectionID].length !== 0) //if(openClassifiers[sectionID] != undefined)
|
---|
[24520] | 37 | {
|
---|
| 38 | delete openClassifiers[sectionID];
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 | else
|
---|
| 42 | {
|
---|
[26396] | 43 | section.css("display", "block");
|
---|
| 44 | sectionToggle.attr("src", gs.imageURLs.collapse);
|
---|
[24520] | 45 | openClassifiers[sectionID] = true;
|
---|
| 46 | }
|
---|
| 47 | updateOpenClassifiers();
|
---|
[33168] | 48 | if(typeof mapEnabled !== 'undefined' && mapEnabled){
|
---|
| 49 | //console.log("Classifier scripts -> updateMap()");
|
---|
[33146] | 50 | updateMap();
|
---|
| 51 | }
|
---|
[24520] | 52 | }
|
---|
| 53 | else
|
---|
| 54 | {
|
---|
| 55 | httpRequest(sectionID);
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | function updateOpenClassifiers()
|
---|
| 60 | {
|
---|
| 61 | var oc = "";
|
---|
| 62 | var first = true;
|
---|
| 63 | for(var key in openClassifiers)
|
---|
| 64 | {
|
---|
| 65 | if(first)
|
---|
| 66 | {
|
---|
| 67 | first = false;
|
---|
| 68 | }
|
---|
| 69 | else
|
---|
| 70 | {
|
---|
| 71 | oc += ",";
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | oc += key;
|
---|
| 75 | }
|
---|
[33153] | 76 |
|
---|
| 77 | if(oc != undefined && oc != "")
|
---|
[24520] | 78 | {
|
---|
| 79 | window.location.hash = oc;
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | function openStoredClassifiers()
|
---|
| 84 | {
|
---|
| 85 | if(window.location.hash != undefined && window.location.hash.length > 1)
|
---|
| 86 | {
|
---|
| 87 | var toOpen = window.location.hash.substring(1,window.location.hash.length).split(",");
|
---|
| 88 | var loopFunction = function(sectionArray, index)
|
---|
| 89 | {
|
---|
| 90 | if(!busy && index < sectionArray.length)
|
---|
| 91 | {
|
---|
| 92 | busy = true;
|
---|
| 93 | toggleSection(sectionArray[index]);
|
---|
| 94 | setTimeout(function()
|
---|
| 95 | {
|
---|
| 96 | loopFunction(sectionArray, index + 1);
|
---|
[24555] | 97 | }, 25);
|
---|
[24520] | 98 |
|
---|
[24555] | 99 | return true;
|
---|
[24520] | 100 | }
|
---|
| 101 |
|
---|
| 102 | setTimeout(function()
|
---|
| 103 | {
|
---|
| 104 | loopFunction(sectionArray, index);
|
---|
[24555] | 105 | }, 25);
|
---|
[24520] | 106 | return false;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | if(toOpen.length > 0)
|
---|
| 110 | {
|
---|
| 111 | loopFunction(toOpen, 0);
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | function httpRequest(sectionID)
|
---|
| 117 | {
|
---|
| 118 | if(!inProgress[sectionID])
|
---|
| 119 | {
|
---|
[33128] | 120 | inProgress[sectionID] = true;
|
---|
[24520] | 121 |
|
---|
[26396] | 122 | var sectionToggle = gs.jqGet("toggle" + sectionID);
|
---|
| 123 | sectionToggle.attr("src", gs.imageURLs.loading);
|
---|
[25442] | 124 |
|
---|
| 125 | var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + sectionID.replace(/\./g, "/") + "?excerptid=div" + sectionID;
|
---|
[24520] | 126 |
|
---|
[29277] | 127 | if(gs.cgiParams.berrybasket == "on")
|
---|
[24520] | 128 | {
|
---|
| 129 | url = url + "&berrybasket=on";
|
---|
[29277] | 130 | }
|
---|
[24520] | 131 |
|
---|
[24521] | 132 | if(url.indexOf("#") != -1)
|
---|
| 133 | {
|
---|
| 134 | url = url.substring(0, url.indexOf("#"));
|
---|
| 135 | }
|
---|
[26396] | 136 |
|
---|
| 137 | $.ajax(url)
|
---|
| 138 | .success(function(data)
|
---|
[24520] | 139 | {
|
---|
[26396] | 140 | var newDiv = $("<div>");
|
---|
| 141 | var sibling = gs.jqGet("title" + sectionID);
|
---|
| 142 | sibling.after(newDiv);
|
---|
| 143 |
|
---|
| 144 | newDiv.html(data);
|
---|
| 145 | sectionToggle.attr("src", gs.imageURLs.collapse);
|
---|
| 146 | openClassifiers[sectionID] = true;
|
---|
| 147 |
|
---|
[29277] | 148 | if(gs.cgiParams.berrybasket == "on")
|
---|
[24520] | 149 | {
|
---|
[26396] | 150 | checkout();
|
---|
[24520] | 151 | }
|
---|
[26396] | 152 | else if(gs.cgiParams.documentbasket == "on")
|
---|
| 153 | {
|
---|
| 154 | dmcheckout();
|
---|
| 155 | }
|
---|
[33146] | 156 | updateOpenClassifiers();
|
---|
[33168] | 157 | if(typeof mapEnabled !== 'undefined' && mapEnabled){
|
---|
[33146] | 158 | getSubClassifier(sectionID);
|
---|
| 159 | }
|
---|
[26396] | 160 | })
|
---|
| 161 | .error(function()
|
---|
| 162 | {
|
---|
| 163 | sectionToggle.attr("src", gs.imageURLs.expand);
|
---|
| 164 | })
|
---|
| 165 | .complete(function()
|
---|
| 166 | {
|
---|
| 167 | inProgress[sectionID] = false;
|
---|
| 168 | busy = false;
|
---|
| 169 | });
|
---|
[24520] | 170 | }
|
---|
[33153] | 171 | }
|
---|