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

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

Adjustments to make resize and move posits working in new Greenstone3 environment

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