1 | var inProgress = new Array();
|
---|
2 | var openClassifiers = new Array();
|
---|
3 | var busy = false;
|
---|
4 |
|
---|
5 | function isExpanded(sectionID)
|
---|
6 | {
|
---|
7 | var divElem = gs.jqGet("div" + sectionID);
|
---|
8 | if(!divElem.css("display") || divElem.css("display") != "none")
|
---|
9 | {
|
---|
10 | return true;
|
---|
11 | }
|
---|
12 | return false;
|
---|
13 | }
|
---|
14 |
|
---|
15 | function toggleSection(sectionID)
|
---|
16 | {
|
---|
17 | var section = gs.jqGet("div" + sectionID);
|
---|
18 | var sectionToggle = gs.jqGet("toggle" + sectionID);
|
---|
19 |
|
---|
20 | if(sectionToggle == undefined)
|
---|
21 | {
|
---|
22 | return;
|
---|
23 | }
|
---|
24 |
|
---|
25 | //If the div exists
|
---|
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)
|
---|
30 | {
|
---|
31 | if(isExpanded(sectionID))
|
---|
32 | {
|
---|
33 | section.css("display", "none");
|
---|
34 | sectionToggle.attr("src", gs.imageURLs.expand);
|
---|
35 |
|
---|
36 | if(openClassifiers[sectionID].length !== 0) //if(openClassifiers[sectionID] != undefined)
|
---|
37 | {
|
---|
38 | delete openClassifiers[sectionID];
|
---|
39 | }
|
---|
40 | }
|
---|
41 | else
|
---|
42 | {
|
---|
43 | section.css("display", "block");
|
---|
44 | sectionToggle.attr("src", gs.imageURLs.collapse);
|
---|
45 | openClassifiers[sectionID] = true;
|
---|
46 | }
|
---|
47 | updateOpenClassifiers();
|
---|
48 | if(typeof mapEnabled !== 'undefined' && mapEnabled){
|
---|
49 | //console.log("Classifier scripts -> updateMap()");
|
---|
50 | updateMap();
|
---|
51 | }
|
---|
52 | }
|
---|
53 | else
|
---|
54 | {
|
---|
55 | httpBrowseRequest(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 | }
|
---|
76 |
|
---|
77 | if(oc != undefined && oc != "")
|
---|
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);
|
---|
97 | }, 25);
|
---|
98 |
|
---|
99 | return true;
|
---|
100 | }
|
---|
101 |
|
---|
102 | setTimeout(function()
|
---|
103 | {
|
---|
104 | loopFunction(sectionArray, index);
|
---|
105 | }, 25);
|
---|
106 | return false;
|
---|
107 | }
|
---|
108 |
|
---|
109 | if(toOpen.length > 0)
|
---|
110 | {
|
---|
111 | loopFunction(toOpen, 0);
|
---|
112 | }
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | function httpBrowseRequest(sectionID)
|
---|
117 | {
|
---|
118 | if(!inProgress[sectionID])
|
---|
119 | {
|
---|
120 | inProgress[sectionID] = true;
|
---|
121 |
|
---|
122 | var sectionToggle = gs.jqGet("toggle" + sectionID);
|
---|
123 | sectionToggle.attr("src", gs.imageURLs.loading);
|
---|
124 |
|
---|
125 | var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + sectionID.replace(/\./g, "/") + "?excerptid=div" + sectionID;
|
---|
126 |
|
---|
127 | if(gs.cgiParams.berrybasket == "on")
|
---|
128 | {
|
---|
129 | url = url + "&berrybasket=on";
|
---|
130 | }
|
---|
131 | if(gs.cgiParams.favouritesbasket == "on")
|
---|
132 | {
|
---|
133 | url = url + "&favouritesbasket=on";
|
---|
134 | }
|
---|
135 |
|
---|
136 | if(url.indexOf("#") != -1)
|
---|
137 | {
|
---|
138 | url = url.substring(0, url.indexOf("#"));
|
---|
139 | }
|
---|
140 |
|
---|
141 | $.ajax(url)
|
---|
142 | .success(function(data)
|
---|
143 | {
|
---|
144 | var newDiv = $("<div>");
|
---|
145 | var sibling = gs.jqGet("title" + sectionID);
|
---|
146 | sibling.after(newDiv);
|
---|
147 |
|
---|
148 | newDiv.html(data);
|
---|
149 | sectionToggle.attr("src", gs.imageURLs.collapse);
|
---|
150 | openClassifiers[sectionID] = true;
|
---|
151 |
|
---|
152 | if(gs.cgiParams.berrybasket == "on")
|
---|
153 | {
|
---|
154 | berryCheckout();
|
---|
155 | }
|
---|
156 | if(gs.cgiParams.favouritesbasket == "on")
|
---|
157 | {
|
---|
158 | favouritesCheckout();
|
---|
159 | }
|
---|
160 | if(gs.cgiParams.documentbasket == "on")
|
---|
161 | {
|
---|
162 | dmcheckout();
|
---|
163 | }
|
---|
164 | updateOpenClassifiers();
|
---|
165 | if(typeof mapEnabled !== 'undefined'){
|
---|
166 | httpMapBrowseRequest(sectionID);
|
---|
167 | }
|
---|
168 | })
|
---|
169 | .error(function()
|
---|
170 | {
|
---|
171 | sectionToggle.attr("src", gs.imageURLs.expand);
|
---|
172 | })
|
---|
173 | .complete(function()
|
---|
174 | {
|
---|
175 | inProgress[sectionID] = false;
|
---|
176 | busy = false;
|
---|
177 | });
|
---|
178 | }
|
---|
179 | }
|
---|