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