source: main/trunk/model-sites-dev/mozarts-laptop/collect/digital-music-stand/script/annotate-main.js@ 30456

Last change on this file since 30456 was 30456, checked in by davidb, 8 years ago

Changes to work with the newer direct-edit JS script that was put into Greenstone3

  • Property svn:executable set to *
File size: 7.4 KB
Line 
1
2var mouseX = 0;
3var mouseY = 0;
4
5function trackMouse(e)
6{
7
8 //0,0 point is the top left corner of the container,
9 //minus its padding:
10 var containerX = YAHOO.util.Dom.getX("thispage");
11 var containerY = YAHOO.util.Dom.getY("thispage");
12 var clickX = YAHOO.util.Event.getPageX(e);
13 var clickY = YAHOO.util.Event.getPageY(e);
14
15 mouseX = clickX;
16 mouseY = clickY;
17
18 var coord_div = getElement("coord");
19 coord_div.innerHTML = mouseX + ", " + mouseY;
20
21
22 //get container padding using Dom's getStyle():
23 var containerPaddingX = parseInt(YAHOO.util.Dom.getStyle("thispage","padding-left"), 10);
24 var containerPaddingY = parseInt(YAHOO.util.Dom.getStyle("thispage","padding-top"), 10);
25 var newWidth = clickX - containerX - containerPaddingX;
26 var newHeight = clickY - containerY - containerPaddingY;
27
28
29 if (annotateMoveElem != null) {
30 annotateMoveElem.style.left = (mouseX - moveXOffset) + "px";
31 annotateMoveElem.style.top = (mouseY - moveYOffset) + "px";
32 }
33
34
35 if (annotateResizeElem != null) {
36 var ax_org = parseInt(annotateResizeElem.style.left);
37 var ay_org = parseInt(annotateResizeElem.style.top);
38 var ax_dim = mouseX - ax_org +1;
39 var ay_dim = mouseY - ay_org +1;
40
41 if ((ax_dim>16) && (ay_dim>16)) {
42 annotateResizeElem.style.width = ax_dim + "px";
43 annotateResizeElem.style.height = ay_dim + "px";
44 }
45 }
46
47
48}
49
50
51function closeAnnotation(elem,evt)
52{
53 // 'elem' not currently used, but passed in to be similar to other event handlers
54 // 'elem' could be used to simplify working 'closeElem' ??
55
56 evt = evt || window.event;
57
58 var mousePos = getMouseCoords(evt);
59
60 var closeElem = de.cursor.getNonCursorNodeAtXY(mousePos.x, mousePos.y);
61
62 var currElem = closeElem.parentNode;
63 var prevElem = closeElem;
64
65 while (currElem!=null) {
66 prevElem = currElem;
67 currElem = currElem.parentNode;
68
69 if (prevElem.getAttribute("class") == "annotationNote") {
70 break;
71 }
72 }
73
74 var annotateCanvas = currElem;
75 var annotateDiv = prevElem;
76
77 var editableElems = getElementsByClass("editable-",annotateDiv);
78 var editableElem = editableElems[0];
79
80 var removeMetapos = editableElem.getAttribute("metapos");
81 console.log("closeAnnotation: metapos = " + removeMetapos);
82
83 annotate.removeAnnotation(annotateCanvas,removeMetapos);
84
85 return false;
86}
87
88
89var annotateResize = false;
90var annotateResizeElem = null;
91
92function startResizeAnnotation(elem,event)
93{
94 event = event || window.event;
95
96 var rightclick = false;
97 if (event.which) rightclick = (event.which == 3);
98 else if (event.button) rightclick = (event.button == 2);
99 // stop things early (allow for right-click to close annotation, on mouseup)
100 if (rightclick) return false;
101
102 annotateResize = true;
103 annotateResizeElem = elem.parentNode.parentNode.parentNode.parentNode;
104
105 console.log("*** clearing selection and setting cursor to null!");
106 de.selection.clear(); // clear selection
107 de.cursor.setCursor(null); // clear focus
108
109 return false; // stop drag and drop of image
110}
111
112function stopResizeAnnotation(elem,event)
113{
114 event = event || window.event;
115
116 var rightclick = false;
117 if (event.which) rightclick = (event.which == 3);
118 else if (event.button) rightclick = (event.button == 2);
119 // stop things early (allow for right-click to close annotation, on mouseup)
120 if (rightclick) return closeAnnotation(elem,event);
121
122 annotateResize = false;
123 annotateResizeElem = null;
124
125 return true;
126
127}
128
129
130var annotateMove = false;
131var annotateMoveElem = null;
132
133var moveXOffset = 0;
134var moveYOffset = 0;
135
136function annotateMouseDown(elem,event)
137{
138 event = event || window.event;
139
140 annotateMove = true;
141 annotateMoveElem = elem.parentNode.parentNode.parentNode;
142
143 moveXOffset = mouseX - parseInt(annotateMoveElem.style.left);
144 moveYOffset = mouseY - parseInt(annotateMoveElem.style.top);
145
146 return false; // stop selection of page Image
147}
148
149function annotateMouseUp(elem,event)
150{
151 event = event || window.event;
152
153 annotateMove = false;
154 annotateMoveElem = null;
155
156 return true;
157}
158
159
160function setCursorAtXY(x,y)
161{
162 // Filter out non editable node first... so that can
163 // quickely avoid searching
164 var cInfo;
165 var targetEl = de.getElementAtXY(x, y);
166
167 if (targetEl) {
168 if (de.doc.isNodeEditable(targetEl)) {
169 //cInfo = de.cursor.getCursorInfoAtXY(x, y, targetEl);
170 cInfo = de.cursor.getCursorDescAtXY(x,y,targetEl);
171 }
172 }
173
174 de.cursor.setCursor(cInfo);
175}
176
177function annotateLoseFocus(elem)
178{
179 //de.cursor.setCursorAtXY(mouseX,mouseY);
180 setCursorAtXY(mouseX,mouseY);
181}
182
183
184function annotateGainFocus(elem)
185{
186 //de.cursor.setCursorAtXY(mouseX,mouseY);
187 setCursorAtXY(mouseX,mouseY);
188}
189
190
191var annotate_width = 0;
192var max_annotate_width = 9;
193var annotate_height = 1;
194
195
196
197
198function keyPress(e)
199{
200 if (e.keyID == "Escape") {
201 musicStand.cancelPageAnim();
202 }
203
204 //var cursorInfo = de.cursor.getCurrentCursorInfo();
205 var cursorInfo = de.cursor.getCurrentCursorDesc();
206
207 var newAnnotation = false;
208
209 if (cursorInfo==null) {
210 newAnnotation = true;
211 }
212 else if (expeditee) {
213 var overTextElem = de.cursor.getNonCursorNodeAtXY(mouseX,mouseY);
214 var overElem = de.doc.getEditableRootNode(overTextElem);
215
216 if (overElem==null) {
217 // mouse in white space, but missed an onmouseout event
218 de.cursor.setCursor(null);
219
220 newAnnotation = true;
221 }
222 else {
223 var editableElem = de.doc.getEditableRootNode(cursorInfo.textNode);
224
225 if (editableElem.getAttribute("id") != overElem.getAttribute("id")) {
226 // cursor is over another editable element (but must have
227 // missed onmouseover event)
228 // => need to switch cursor location
229 var startCursor = de.cursor.createCursor(overElem.firstChild,0,false);
230 de.cursor.setCursor(startCursor);
231 }
232 }
233
234 }
235
236 if (newAnnotation) {
237 // control/shift being down marks beginning key accelerators such
238 // as ctrl-r or similar
239 // => ignore here, but let it bubble up further
240
241 var isAccelDown = de.events.Keyboard.isAcceleratorDown(e);
242 var isShiftDown = e.shiftKey;
243 console.log("**** is accel down: " + isAccelDown);
244 console.log("**** is shift down: " + isShiftDown);
245 //if (e.isAccelDown() || e.isShiftDown()) { return true; }
246 if (isAccelDown || isShiftDown) { return true; }
247
248 if (e.keyID == "Escape") {
249 // deactivate cursor !!!???????
250 de.cursor.setCursor(null);
251 return true;
252 }
253
254 console.log("*** mouse: ("+mouseX+","+mouseY+")");
255
256 var newAI = annotate.createAnnotation(mouseX-8,mouseY-14,null,"20"," ");
257
258 var annotateCanvasElem = document.getElementById("annotateCanvas");
259 annotateCanvasElem.appendChild(newAI);
260
261 var editableElems = getElementsByClass("editable-",newAI);
262 var editableElem = editableElems[0];
263
264 //var startCursor = de.cursor.createCursor(editableElem.firstChild,0,false);
265 var startCursor = de.cursor.createCursorDesc(editableElem.firstChild,0,false);
266 de.cursor.setCursor(startCursor);
267
268 }
269
270
271}
272
273
274
275
Note: See TracBrowser for help on using the repository browser.