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

Last change on this file since 32838 was 29277, checked in by kjdon, 10 years ago

berrybasket cgi param is all lower case.

  • 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 var httpRequest = new gs.functions.ajaxRequest();
115
116 var sectionToggle = gs.jqGet("toggle" + sectionID);
117 sectionToggle.attr("src", gs.imageURLs.loading);
118
119 var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + sectionID.replace(/\./g, "/") + "?excerptid=div" + sectionID;
120
121 if(gs.cgiParams.berrybasket == "on")
122 {
123 url = url + "&berrybasket=on";
124 }
125
126 if(url.indexOf("#") != -1)
127 {
128 url = url.substring(0, url.indexOf("#"));
129 }
130
131 $.ajax(url)
132 .success(function(data)
133 {
134 var newDiv = $("<div>");
135 var sibling = gs.jqGet("title" + sectionID);
136 sibling.after(newDiv);
137
138 newDiv.html(data);
139 sectionToggle.attr("src", gs.imageURLs.collapse);
140 openClassifiers[sectionID] = true;
141
142 if(gs.cgiParams.berrybasket == "on")
143 {
144 checkout();
145 }
146 else if(gs.cgiParams.documentbasket == "on")
147 {
148 dmcheckout();
149 }
150 updateOpenClassifiers();
151 })
152 .error(function()
153 {
154 sectionToggle.attr("src", gs.imageURLs.expand);
155 })
156 .complete(function()
157 {
158 inProgress[sectionID] = false;
159 busy = false;
160 });
161 }
162}
Note: See TracBrowser for help on using the repository browser.