1 |
|
---|
2 | var mouseX = 0;
|
---|
3 | var mouseY = 0;
|
---|
4 |
|
---|
5 | function 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 |
|
---|
54 | function 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 |
|
---|
92 | var annotateResize = false;
|
---|
93 | var annotateResizeElem = null;
|
---|
94 |
|
---|
95 | function 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 |
|
---|
115 | function 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 |
|
---|
133 | var annotateMove = false;
|
---|
134 | var annotateMoveElem = null;
|
---|
135 |
|
---|
136 | var moveXOffset = 0;
|
---|
137 | var moveYOffset = 0;
|
---|
138 |
|
---|
139 | function 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 |
|
---|
156 | function annotateMouseUp(elem,event)
|
---|
157 | {
|
---|
158 | event = event || window.event;
|
---|
159 |
|
---|
160 | annotateMove = false;
|
---|
161 | annotateMoveElem = null;
|
---|
162 |
|
---|
163 | return true;
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 | function 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 |
|
---|
184 | function annotateLoseFocus(elem)
|
---|
185 | {
|
---|
186 | //de.cursor.setCursorAtXY(mouseX,mouseY);
|
---|
187 | setCursorAtXY(mouseX,mouseY);
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | function annotateGainFocus(elem)
|
---|
192 | {
|
---|
193 | //de.cursor.setCursorAtXY(mouseX,mouseY);
|
---|
194 | setCursorAtXY(mouseX,mouseY);
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 | var annotate_width = 0;
|
---|
199 | var max_annotate_width = 9;
|
---|
200 | var annotate_height = 1;
|
---|
201 |
|
---|
202 |
|
---|
203 |
|
---|
204 |
|
---|
205 | function 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 |
|
---|