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 | // TODO: Is there a better solution
|
---|
16 | function _basicToggleSection(sectionID) {
|
---|
17 | // Leave this function here, even though it's empty.
|
---|
18 | // This function is here because:
|
---|
19 | // - it mirrors the identically named version in document_scripts
|
---|
20 | // - and this allows map_scripts to override it without knowing whether it's
|
---|
21 | // overriding classifier_scripts::toggleSection() or document_scripts::toggleSection().
|
---|
22 |
|
---|
23 | // This method is not meant to call toggleSection. If anything it would be the other way around
|
---|
24 | // (as occurs in doc_scripts.js). But this method has to remain empty for classifier_scripts.js
|
---|
25 | // since map_scripts largely repeats classifier_scripts.js::toggleSection() code.
|
---|
26 | }
|
---|
27 |
|
---|
28 | function toggleSection(sectionID)
|
---|
29 | {
|
---|
30 | var section = gs.jqGet("div" + sectionID);
|
---|
31 | var sectionToggle = gs.jqGet("toggle" + sectionID);
|
---|
32 |
|
---|
33 | if(sectionToggle == undefined)
|
---|
34 | {
|
---|
35 | return;
|
---|
36 | }
|
---|
37 |
|
---|
38 | //If the div exists
|
---|
39 | if(section.length)
|
---|
40 | {
|
---|
41 | if(isExpanded(sectionID))
|
---|
42 | {
|
---|
43 | section.css("display", "none");
|
---|
44 | sectionToggle.attr("src", gs.imageURLs.expand);
|
---|
45 |
|
---|
46 | if(openClassifiers[sectionID] != undefined)
|
---|
47 | {
|
---|
48 | delete openClassifiers[sectionID];
|
---|
49 | }
|
---|
50 | }
|
---|
51 | else
|
---|
52 | {
|
---|
53 | section.css("display", "block");
|
---|
54 | sectionToggle.attr("src", gs.imageURLs.collapse);
|
---|
55 | openClassifiers[sectionID] = true;
|
---|
56 | }
|
---|
57 | updateOpenClassifiers();
|
---|
58 | }
|
---|
59 | else
|
---|
60 | {
|
---|
61 | httpRequest(sectionID);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | function updateOpenClassifiers()
|
---|
66 | {
|
---|
67 | var oc = "";
|
---|
68 | var first = true;
|
---|
69 | for(var key in openClassifiers)
|
---|
70 | {
|
---|
71 | if(first)
|
---|
72 | {
|
---|
73 | first = false;
|
---|
74 | }
|
---|
75 | else
|
---|
76 | {
|
---|
77 | oc += ",";
|
---|
78 | }
|
---|
79 |
|
---|
80 | oc += key;
|
---|
81 | }
|
---|
82 |
|
---|
83 | if(oc != undefined)
|
---|
84 | {
|
---|
85 | window.location.hash = oc;
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | function openStoredClassifiers()
|
---|
90 | {
|
---|
91 | if(window.location.hash != undefined && window.location.hash.length > 1)
|
---|
92 | {
|
---|
93 | var toOpen = window.location.hash.substring(1,window.location.hash.length).split(",");
|
---|
94 | var loopFunction = function(sectionArray, index)
|
---|
95 | {
|
---|
96 | if(!busy && index < sectionArray.length)
|
---|
97 | {
|
---|
98 | busy = true;
|
---|
99 | toggleSection(sectionArray[index]);
|
---|
100 | setTimeout(function()
|
---|
101 | {
|
---|
102 | loopFunction(sectionArray, index + 1);
|
---|
103 | }, 25);
|
---|
104 |
|
---|
105 | return true;
|
---|
106 | }
|
---|
107 |
|
---|
108 | setTimeout(function()
|
---|
109 | {
|
---|
110 | loopFunction(sectionArray, index);
|
---|
111 | }, 25);
|
---|
112 | return false;
|
---|
113 | }
|
---|
114 |
|
---|
115 | if(toOpen.length > 0)
|
---|
116 | {
|
---|
117 | loopFunction(toOpen, 0);
|
---|
118 | }
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | function httpRequest(sectionID)
|
---|
123 | {
|
---|
124 | if(!inProgress[sectionID])
|
---|
125 | {
|
---|
126 | inProgress[sectionID] = true;
|
---|
127 |
|
---|
128 | var sectionToggle = gs.jqGet("toggle" + sectionID);
|
---|
129 | sectionToggle.attr("src", gs.imageURLs.loading);
|
---|
130 |
|
---|
131 | var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + sectionID.replace(/\./g, "/") + "?excerptid=div" + sectionID;
|
---|
132 |
|
---|
133 | if(gs.cgiParams.berrybasket == "on")
|
---|
134 | {
|
---|
135 | url = url + "&berrybasket=on";
|
---|
136 | }
|
---|
137 |
|
---|
138 | if(url.indexOf("#") != -1)
|
---|
139 | {
|
---|
140 | url = url.substring(0, url.indexOf("#"));
|
---|
141 | }
|
---|
142 |
|
---|
143 | $.ajax(url)
|
---|
144 | .success(function(data)
|
---|
145 | {
|
---|
146 | var newDiv = $("<div>");
|
---|
147 | var sibling = gs.jqGet("title" + sectionID);
|
---|
148 | sibling.after(newDiv);
|
---|
149 |
|
---|
150 | newDiv.html(data);
|
---|
151 | sectionToggle.attr("src", gs.imageURLs.collapse);
|
---|
152 | openClassifiers[sectionID] = true;
|
---|
153 |
|
---|
154 | if(gs.cgiParams.berrybasket == "on")
|
---|
155 | {
|
---|
156 | checkout();
|
---|
157 | }
|
---|
158 | else if(gs.cgiParams.documentbasket == "on")
|
---|
159 | {
|
---|
160 | dmcheckout();
|
---|
161 | }
|
---|
162 | updateOpenClassifiers();
|
---|
163 | })
|
---|
164 | .error(function()
|
---|
165 | {
|
---|
166 | sectionToggle.attr("src", gs.imageURLs.expand);
|
---|
167 | })
|
---|
168 | .complete(function()
|
---|
169 | {
|
---|
170 | inProgress[sectionID] = false;
|
---|
171 | busy = false;
|
---|
172 | });
|
---|
173 | }
|
---|
174 | } |
---|