source: main/trunk/greenstone3/web/interfaces/default/js/classifier_scripts.js@ 36027

Last change on this file since 36027 was 36027, checked in by cstephen, 2 years ago

Migrate to using jQuery3 and jQuery-UI-1.13.2; and integrate cookie consent manager

  • Property svn:executable set to *
File size: 3.9 KB
Line 
1var inProgress = new Array();
2var openClassifiers = new Array();
3var busy = false;
4
5function 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
15function 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 var expanding = false;
32 if(isExpanded(sectionID))
33 {
34 expanding = false;
35 section.css("display", "none");
36 sectionToggle.attr("src", gs.imageURLs.expand);
37
38 if(openClassifiers[sectionID].length !== 0) //if(openClassifiers[sectionID] != undefined)
39 {
40 delete openClassifiers[sectionID];
41 }
42 }
43 else
44 {
45 expanding = true;
46 section.css("display", "block");
47 sectionToggle.attr("src", gs.imageURLs.collapse);
48 openClassifiers[sectionID] = true;
49 }
50 updateOpenClassifiers();
51 if(typeof mapEnabled !== 'undefined' /*&& mapEnabled*/){
52 //console.log("Classifier scripts -> updateMap()");
53 toggleMapSection({"expand": expanding, "nodeID": sectionID});
54 updateMap();
55 }
56 }
57 else
58 {
59 httpBrowseRequest(sectionID);
60 }
61}
62
63function 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 }
80
81 if(oc != undefined && oc != "")
82 {
83 window.location.hash = oc;
84 }
85}
86
87function 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);
101 }, 25);
102
103 return true;
104 }
105
106 setTimeout(function()
107 {
108 loopFunction(sectionArray, index);
109 }, 25);
110 return false;
111 }
112
113 if(toOpen.length > 0)
114 {
115 loopFunction(toOpen, 0);
116 }
117 }
118}
119
120function httpBrowseRequest(sectionID)
121{
122 if(!inProgress[sectionID])
123 {
124 inProgress[sectionID] = true;
125
126 var sectionToggle = gs.jqGet("toggle" + sectionID);
127 sectionToggle.attr("src", gs.imageURLs.loading);
128
129 var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + sectionID.replace(/\./g, "/") + "?excerptid=div" + sectionID;
130
131 if(gs.cgiParams.berrybasket == "on")
132 {
133 url = url + "&berrybasket=on";
134 }
135 if(gs.cgiParams.favouritebasket == "on")
136 {
137 url = url + "&favouritebasket=on";
138 }
139
140 if(url.indexOf("#") != -1)
141 {
142 url = url.substring(0, url.indexOf("#"));
143 }
144
145 $.ajax(url)
146 .done(function(data)
147 {
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
156 if(gs.cgiParams.berrybasket == "on")
157 {
158 berryCheckout();
159 }
160 if(gs.cgiParams.favouritebasket == "on")
161 {
162 favouritesCheckout();
163 }
164 if(gs.cgiParams.documentbasket == "on")
165 {
166 dmcheckout();
167 }
168 updateOpenClassifiers();
169 if(typeof mapEnabled !== 'undefined'){
170 httpMapBrowseRequest(sectionID);
171 }
172 })
173 .fail(function()
174 {
175 sectionToggle.attr("src", gs.imageURLs.expand);
176 })
177 .always(function()
178 {
179 inProgress[sectionID] = false;
180 busy = false;
181 });
182 }
183}
Note: See TracBrowser for help on using the repository browser.