1 |
|
---|
2 | function Annotate(httpImagesMacro)
|
---|
3 | {
|
---|
4 | var httpImages = httpImagesMacro;
|
---|
5 |
|
---|
6 | var numAnnotations = 0;
|
---|
7 |
|
---|
8 | var username = null;
|
---|
9 |
|
---|
10 | this.getNumAnnotations = function()
|
---|
11 | {
|
---|
12 | return numAnnotations;
|
---|
13 | }
|
---|
14 |
|
---|
15 | this.setUsername = function(cgiUsername)
|
---|
16 | {
|
---|
17 | username = cgiUsername;
|
---|
18 | }
|
---|
19 |
|
---|
20 | this.getUsername = function()
|
---|
21 | {
|
---|
22 | return username;
|
---|
23 | }
|
---|
24 |
|
---|
25 | this.createAnnotation = function(xleft,ytop,xwidth,yheight,text)
|
---|
26 | {
|
---|
27 | // start new annotation
|
---|
28 | var newAI = document.createElement("div");
|
---|
29 | newAI.setAttribute("class","annotationNote");
|
---|
30 | if (expeditee) {
|
---|
31 | newAI.setAttribute("onmouseout", "javascript:annotateLoseFocus(this)");
|
---|
32 | }
|
---|
33 |
|
---|
34 | //newAI.style.position = "absolute";
|
---|
35 | //newAI.style.visibility = "visible";
|
---|
36 | //newAI.style.zIndex = "2";
|
---|
37 | //newAI.style.background = "rgba(255,200,200,0.7)";
|
---|
38 |
|
---|
39 | if (xwidth) {
|
---|
40 | newAI.style.width = xwidth + "px";
|
---|
41 | }
|
---|
42 |
|
---|
43 | if (yheight) {
|
---|
44 | newAI.style.height = yheight + "px";
|
---|
45 | }
|
---|
46 | else {
|
---|
47 | newAI.style.height = "auto";
|
---|
48 | }
|
---|
49 |
|
---|
50 | //newAI.style.borderStyle = "solid";
|
---|
51 | //newAI.style.borderColor = "black";
|
---|
52 |
|
---|
53 | newAI.style.padding = "1px";
|
---|
54 | newAI.style.paddingRight = "6px";
|
---|
55 |
|
---|
56 |
|
---|
57 | var annotate_x_org = xleft;
|
---|
58 | var annotate_y_org = ytop;
|
---|
59 |
|
---|
60 | if (document.all) {
|
---|
61 | newAI.style.pixelLeft = annotate_x_org
|
---|
62 | newAI.style.pixelTop = annotate_y_org;
|
---|
63 | }
|
---|
64 | else if (document.getElementById) {
|
---|
65 | newAI.style.left = annotate_x_org + 'px';
|
---|
66 | newAI.style.top = annotate_y_org + 'px';
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | var tableElem = document.createElement("table");
|
---|
71 | var trElem = document.createElement("tr");
|
---|
72 |
|
---|
73 | var tdTextElem = document.createElement("td");
|
---|
74 | var tdDecElem = document.createElement("td");
|
---|
75 |
|
---|
76 | var editableElem = document.createElement("span");
|
---|
77 | if (expeditee) {
|
---|
78 | editableElem.setAttribute("onmouseover","javascript:annotateGainFocus(this)");
|
---|
79 | editableElem.setAttribute("onmousemove","javascript:annotateGainFocus(this)");
|
---|
80 | }
|
---|
81 | //else {
|
---|
82 | // tableElem.setAttribute("onmousedown","javascript:return false;");
|
---|
83 | // tableElem.setAttribute("onmouseup", "javascript:return false;");
|
---|
84 | // }
|
---|
85 |
|
---|
86 | var annotation = (username!=null) ? username+"-annotation" : "annotation";
|
---|
87 |
|
---|
88 | editableElem.setAttribute("id","annotateItem" + numAnnotations);
|
---|
89 | editableElem.setAttribute("class","editable-metadata");
|
---|
90 | editableElem.setAttribute("docoid",musicStand.getDocOID());
|
---|
91 | editableElem.setAttribute("metaname",annotation);
|
---|
92 | editableElem.setAttribute("metapos",numAnnotations);
|
---|
93 |
|
---|
94 | //editableElem.setAttribute("style", "cursor:text;");
|
---|
95 |
|
---|
96 | editableElem.style.position = "relative";
|
---|
97 |
|
---|
98 | if (text == "") {
|
---|
99 | text = " "
|
---|
100 | }
|
---|
101 | editableElem.innerHTML = text;
|
---|
102 |
|
---|
103 | tdTextElem.setAttribute("onmousedown","javascript:return annotateMouseDown(this,event);");
|
---|
104 | tdTextElem.setAttribute("onmouseup", "javascript:return annotateMouseUp(this,event);");
|
---|
105 | tdTextElem.setAttribute("style", "cursor:text;");
|
---|
106 |
|
---|
107 | var closeElem = document.createElement("div");
|
---|
108 | //closeElem.onmouseup=closeAnnotation;
|
---|
109 | closeElem.setAttribute("onmouseup","javascript:return closeAnnotation(this,event);");
|
---|
110 | closeElem.setAttribute("style", "cursor:default;");
|
---|
111 |
|
---|
112 | closeElem.style.position = "absolute";
|
---|
113 | closeElem.style.top = "0px";
|
---|
114 | closeElem.style.right = "0px";
|
---|
115 | closeElem.innerHTML = '<img src="'+httpImages+'/window-close.gif">';
|
---|
116 |
|
---|
117 | var resizeElem = document.createElement("div");
|
---|
118 |
|
---|
119 | resizeElem.setAttribute("onmousedown","javascript:return startResizeAnnotation(this,event);");
|
---|
120 | resizeElem.setAttribute("onmouseup", "javascript:return stopResizeAnnotation(this,event);");
|
---|
121 |
|
---|
122 | resizeElem.setAttribute("style", "cursor:se-resize;");
|
---|
123 |
|
---|
124 | resizeElem.style.position = "absolute";
|
---|
125 | resizeElem.style.bottom = "0px";
|
---|
126 | resizeElem.style.right = "0px";
|
---|
127 | resizeElem.innerHTML = '<img src="'+httpImages+'/resizer.gif">';
|
---|
128 |
|
---|
129 | tdTextElem.appendChild(editableElem);
|
---|
130 | tdDecElem.appendChild(closeElem);
|
---|
131 | tdDecElem.appendChild(resizeElem);
|
---|
132 | trElem.appendChild(tdTextElem);
|
---|
133 | trElem.appendChild(tdDecElem);
|
---|
134 | tableElem.appendChild(trElem);
|
---|
135 | newAI.appendChild(tableElem);
|
---|
136 |
|
---|
137 | numAnnotations++;
|
---|
138 |
|
---|
139 | return newAI;
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | this.saveAnnotation = function(annotateWrapper,editedElem)
|
---|
144 | {
|
---|
145 | console.log("**** terminating saveAnnotation() as gsapi not ported");
|
---|
146 | return;
|
---|
147 |
|
---|
148 | var docoid = editedElem.getAttribute("docoid");
|
---|
149 |
|
---|
150 | if (gsdefined(docoid)) {
|
---|
151 | var metaname = editedElem.getAttribute("metaname");
|
---|
152 | var metapos = editedElem.getAttribute("metapos");
|
---|
153 | var metavalue= editedElem.innerHTML;
|
---|
154 |
|
---|
155 | var metavalue = metavalue.replace(/ /g, " ");
|
---|
156 |
|
---|
157 | gsapi.setDocumentMetadata(docoid,metaname,metapos,metavalue);
|
---|
158 | // gsapi.setImportMetadata(docoid,metaname,metapos,metavalue);
|
---|
159 |
|
---|
160 | // Store co-ord + width and height
|
---|
161 | var ax_org = parseInt(annotateWrapper.style.left);
|
---|
162 | var ay_org = parseInt(annotateWrapper.style.top);
|
---|
163 | var ax_dim = parseInt(annotateWrapper.style.width);
|
---|
164 | var ay_dim = parseInt(annotateWrapper.style.height);
|
---|
165 |
|
---|
166 | var scaleFactor = musicStand.getScaleFactor();
|
---|
167 | ax_org /= scaleFactor;
|
---|
168 | ay_org /= scaleFactor;
|
---|
169 |
|
---|
170 | var rectHash = { "left": ax_org, "top": ay_org };
|
---|
171 |
|
---|
172 | if (ay_dim) {
|
---|
173 |
|
---|
174 | if (!ax_dim) {
|
---|
175 | // switch to width and deliberately leave height
|
---|
176 | // underdefined
|
---|
177 | //ax_dim = parseInt(editedElem.offsetWidth) +4;
|
---|
178 | ax_dim = parseInt(annotateWrapper.offsetWidth)-10;
|
---|
179 | }
|
---|
180 | else {
|
---|
181 | rectHash.height = ay_dim;
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | if (ax_dim) {
|
---|
186 | rectHash.width = ax_dim;
|
---|
187 | }
|
---|
188 |
|
---|
189 | var rectHashStr = JSON.stringify(rectHash);
|
---|
190 |
|
---|
191 | //alert("rectHashStr = " + rectHashStr);
|
---|
192 |
|
---|
193 | var metaname = (username!=null) ? username+"-rectpos" : "rectpos";
|
---|
194 |
|
---|
195 | gsapi.setDocumentMetadata(docoid,metaname,metapos,rectHashStr);
|
---|
196 | // gsapi.setImportMetadata(docoid,metaname,metapos,rectHashStr);
|
---|
197 |
|
---|
198 | }
|
---|
199 |
|
---|
200 | return true;
|
---|
201 | }
|
---|
202 |
|
---|
203 | this.clearAnnotations = function()
|
---|
204 | {
|
---|
205 | var annotateCanvasElem = document.getElementById("annotateCanvas");
|
---|
206 | annotateCanvasElem.innerHTML = null;
|
---|
207 | numAnnotations = 0;
|
---|
208 | }
|
---|
209 |
|
---|
210 | this.loadAnnotation = function(docoid,metapos)
|
---|
211 | {
|
---|
212 | console.log("**** terminating loadAnnotation() as gsapi not ported");
|
---|
213 | return;
|
---|
214 |
|
---|
215 | var annotationMetaname = "annotation";
|
---|
216 | var rectposMetaname = "rectpos";
|
---|
217 | if (username!=null) {
|
---|
218 | annotationMetaname = username + "-" + annotationMetaname;
|
---|
219 | rectposMetaname = username + "-" + rectposMetaname;
|
---|
220 | }
|
---|
221 |
|
---|
222 | var annotateText = gsapi.getDocumentMetadata(docoid,annotationMetaname,metapos);
|
---|
223 | var annotateRect = gsapi.getDocumentMetadata(docoid,rectposMetaname,metapos);
|
---|
224 |
|
---|
225 | //alert("annotateRect = " + annotateRect);
|
---|
226 |
|
---|
227 | // Non-existent annotation rectangle has somehow got into the database
|
---|
228 | if (annotateRect == "") { return; }
|
---|
229 |
|
---|
230 | var annotateHash = JSON.parse(annotateRect);
|
---|
231 |
|
---|
232 | var xleft = annotateHash.left;
|
---|
233 | var ytop = annotateHash.top;
|
---|
234 | var xwidth = annotateHash.width;
|
---|
235 | var yheight = annotateHash.height;
|
---|
236 |
|
---|
237 | var scaleFactor = musicStand.getScaleFactor();
|
---|
238 | xleft *= scaleFactor;
|
---|
239 | ytop *= scaleFactor;
|
---|
240 |
|
---|
241 | var newAI = this.createAnnotation(xleft,ytop,xwidth,yheight,annotateText);
|
---|
242 |
|
---|
243 | var annotateCanvasElem = document.getElementById("annotateCanvas");
|
---|
244 | annotateCanvasElem.appendChild(newAI);
|
---|
245 | }
|
---|
246 |
|
---|
247 | this.loadAnnotations = function(docoid)
|
---|
248 | {
|
---|
249 | console.log("*** terminating loadAnnotations() as gsapi not ported");
|
---|
250 | return;
|
---|
251 |
|
---|
252 | numAnnotations = 0;
|
---|
253 |
|
---|
254 | var metaname = (username!=null) ? username+"-numAnnotations" : "numAnnotations";
|
---|
255 |
|
---|
256 | var newNumAnnotations = gsapi.getLiveMetadata(docoid,metaname);
|
---|
257 |
|
---|
258 | //alert("load: newNumAnnotations = " + newNumAnnotations);
|
---|
259 |
|
---|
260 | for (var a=0; a<newNumAnnotations; a++) {
|
---|
261 | this.loadAnnotation(docoid,a);
|
---|
262 | }
|
---|
263 | }
|
---|
264 |
|
---|
265 |
|
---|
266 | this.removeAnnotation = function(annotateCanvas,removeMetapos)
|
---|
267 | {
|
---|
268 | var annotateDivs = annotateCanvas.childNodes;
|
---|
269 | //var numAnnotations = annotateDivs.length;
|
---|
270 |
|
---|
271 | //alert("num annotations = " + numAnnotations + " removeMetapos = " + removeMetapos);
|
---|
272 |
|
---|
273 | for (var a=0; a<numAnnotations; a++) {
|
---|
274 | var annotateDiv = annotateDivs[a];
|
---|
275 |
|
---|
276 | var editableElems = getElementsByClass("editable-",annotateDiv);
|
---|
277 | var editableElem = editableElems[0];
|
---|
278 |
|
---|
279 | var metapos = editableElem.getAttribute("metapos");
|
---|
280 |
|
---|
281 | if (metapos>removeMetapos) {
|
---|
282 | editableElem.setAttribute("metapos",metapos-1);
|
---|
283 | }
|
---|
284 | }
|
---|
285 |
|
---|
286 | if (annotateCanvas != null) {
|
---|
287 | var removeElem = annotateDivs[removeMetapos];
|
---|
288 | annotateCanvas.removeChild(removeElem);
|
---|
289 | }
|
---|
290 |
|
---|
291 |
|
---|
292 | var docoid = musicStand.getDocOID();
|
---|
293 |
|
---|
294 | var annotationMetaname = "annotation";
|
---|
295 | var rectposMetaname = "rectpos";
|
---|
296 | var numAnnotationsMetaname = "numAnnotations";
|
---|
297 |
|
---|
298 | if (username!=null) {
|
---|
299 | annotationMetaname = username + "-" + annotationMetaname;
|
---|
300 | rectposMetaname = username + "-" + rectposMetaname;
|
---|
301 | numAnnotationsMetaname = username + "-" + numAnnotationsMetaname;
|
---|
302 | }
|
---|
303 |
|
---|
304 | console.log("*** removeAnnotation(): supressing removeDocumentMetadata() as gsapi not ported");
|
---|
305 |
|
---|
306 | //gsapi.removeDocumentMetadata(docoid,annotationMetaname,removeMetapos);
|
---|
307 | //gsapi.removeDocumentMetadata(docoid,rectposMetaname,removeMetapos);
|
---|
308 | numAnnotations--;
|
---|
309 | //gsapi.setLiveMetadata(docoid,numAnnotationsMetaname,numAnnotations);
|
---|
310 | }
|
---|
311 | }
|
---|