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

Last change on this file since 33127 was 33127, checked in by wy59, 5 years ago

2 single changes before major commit. 1. map-scripts.js: Bugfix, no longer referencing a var that does not exist. 2. classifier_scripts.js: Removing unused variable.

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