| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,357 @@ |
| 1 |
+/** |
|
| 2 |
+ * $Id$ |
|
| 3 |
+ * |
|
| 4 |
+ * @author Moxiecode |
|
| 5 |
+ * @copyright Copyright � 2004-2007, Moxiecode Systems AB, All rights reserved. |
|
| 6 |
+ * |
|
| 7 |
+ * The contents of this file will be wrapped in a class later on. |
|
| 8 |
+ */ |
|
| 9 |
+ |
|
| 10 |
+/**#@+ |
|
| 11 |
+ * @member TinyMCE_Engine |
|
| 12 |
+ * @method |
|
| 13 |
+ */ |
|
| 14 |
+tinyMCE.add(TinyMCE_Engine, {
|
|
| 15 |
+ /** |
|
| 16 |
+ * Sets the enabled/disabled state of build in events on the specific node. |
|
| 17 |
+ * This function is needed since some events gets executed in WYSIWYG mode. |
|
| 18 |
+ * |
|
| 19 |
+ * @param {HTMLNode} node HTML node to enable/disable events on.
|
|
| 20 |
+ * @param {boolean} state true/false state if the events should be disabled or enabled.
|
|
| 21 |
+ * @private |
|
| 22 |
+ */ |
|
| 23 |
+ _setEventsEnabled : function(node, state) {
|
|
| 24 |
+ var evs, x, y, elms, i, event; |
|
| 25 |
+ var events = ['onfocus','onblur','onclick','ondblclick', |
|
| 26 |
+ 'onmousedown','onmouseup','onmouseover','onmousemove', |
|
| 27 |
+ 'onmouseout','onkeypress','onkeydown','onkeydown','onkeyup']; |
|
| 28 |
+ |
|
| 29 |
+ evs = tinyMCE.settings.event_elements.split(',');
|
|
| 30 |
+ for (y=0; y<evs.length; y++){
|
|
| 31 |
+ elms = node.getElementsByTagName(evs[y]); |
|
| 32 |
+ for (i=0; i<elms.length; i++) {
|
|
| 33 |
+ event = ""; |
|
| 34 |
+ |
|
| 35 |
+ for (x=0; x<events.length; x++) {
|
|
| 36 |
+ if ((event = tinyMCE.getAttrib(elms[i], events[x])) !== '') {
|
|
| 37 |
+ event = tinyMCE.cleanupEventStr("" + event);
|
|
| 38 |
+ |
|
| 39 |
+ if (!state) |
|
| 40 |
+ event = "return true;" + event; |
|
| 41 |
+ else |
|
| 42 |
+ event = event.replace(/^return true;/gi, ''); |
|
| 43 |
+ |
|
| 44 |
+ elms[i].removeAttribute(events[x]); |
|
| 45 |
+ elms[i].setAttribute(events[x], event); |
|
| 46 |
+ } |
|
| 47 |
+ } |
|
| 48 |
+ } |
|
| 49 |
+ } |
|
| 50 |
+ }, |
|
| 51 |
+ |
|
| 52 |
+ /** |
|
| 53 |
+ * Patch function for MSIE specific events, this one simply grabs the window.event object and |
|
| 54 |
+ * passes it as a argument to the handleEvent function of the TinyMCE_Engine class. |
|
| 55 |
+ * |
|
| 56 |
+ * @param {string} editor_id Editor id to patch.
|
|
| 57 |
+ * @private |
|
| 58 |
+ */ |
|
| 59 |
+ _eventPatch : function(editor_id) {
|
|
| 60 |
+ var n, inst, win, e; |
|
| 61 |
+ |
|
| 62 |
+ // Remove odd, error |
|
| 63 |
+ if (typeof(tinyMCE) == "undefined") |
|
| 64 |
+ return true; |
|
| 65 |
+ |
|
| 66 |
+ try {
|
|
| 67 |
+ // Try selected instance first |
|
| 68 |
+ if (tinyMCE.selectedInstance) {
|
|
| 69 |
+ win = tinyMCE.selectedInstance.getWin(); |
|
| 70 |
+ |
|
| 71 |
+ if (win && win.event) {
|
|
| 72 |
+ e = win.event; |
|
| 73 |
+ |
|
| 74 |
+ if (!e.target) |
|
| 75 |
+ e.target = e.srcElement; |
|
| 76 |
+ |
|
| 77 |
+ TinyMCE_Engine.prototype.handleEvent(e); |
|
| 78 |
+ return; |
|
| 79 |
+ } |
|
| 80 |
+ } |
|
| 81 |
+ |
|
| 82 |
+ // Search for it |
|
| 83 |
+ for (n in tinyMCE.instances) {
|
|
| 84 |
+ inst = tinyMCE.instances[n]; |
|
| 85 |
+ |
|
| 86 |
+ if (!tinyMCE.isInstance(inst)) |
|
| 87 |
+ continue; |
|
| 88 |
+ |
|
| 89 |
+ inst.select(); |
|
| 90 |
+ win = inst.getWin(); |
|
| 91 |
+ |
|
| 92 |
+ if (win && win.event) {
|
|
| 93 |
+ e = win.event; |
|
| 94 |
+ |
|
| 95 |
+ if (!e.target) |
|
| 96 |
+ e.target = e.srcElement; |
|
| 97 |
+ |
|
| 98 |
+ TinyMCE_Engine.prototype.handleEvent(e); |
|
| 99 |
+ return; |
|
| 100 |
+ } |
|
| 101 |
+ } |
|
| 102 |
+ } catch (ex) {
|
|
| 103 |
+ // Ignore error if iframe is pointing to external URL |
|
| 104 |
+ } |
|
| 105 |
+ }, |
|
| 106 |
+ |
|
| 107 |
+ findEvent : function(e) {
|
|
| 108 |
+ var n, inst; |
|
| 109 |
+ |
|
| 110 |
+ if (e) |
|
| 111 |
+ return e; |
|
| 112 |
+ |
|
| 113 |
+ for (n in tinyMCE.instances) {
|
|
| 114 |
+ inst = tinyMCE.instances[n]; |
|
| 115 |
+ |
|
| 116 |
+ if (tinyMCE.isInstance(inst) && inst.getWin().event) |
|
| 117 |
+ return inst.getWin().event; |
|
| 118 |
+ } |
|
| 119 |
+ |
|
| 120 |
+ return null; |
|
| 121 |
+ }, |
|
| 122 |
+ |
|
| 123 |
+ /** |
|
| 124 |
+ * Unload document event handler function. This function will be executed when the |
|
| 125 |
+ * page is unloaded, this will automaticly move the current editor contents to the textarea element this enables |
|
| 126 |
+ * the editor to restore it's state when the user presses the back button in the browser. |
|
| 127 |
+ * This will execute the triggerSave function. |
|
| 128 |
+ */ |
|
| 129 |
+ unloadHandler : function() {
|
|
| 130 |
+ tinyMCE.triggerSave(true, true); |
|
| 131 |
+ }, |
|
| 132 |
+ |
|
| 133 |
+ /** |
|
| 134 |
+ * Adds the handleEvent function to the specified editor instance. |
|
| 135 |
+ * |
|
| 136 |
+ * @param {inst} inst Editor control instance to add event handler to.
|
|
| 137 |
+ */ |
|
| 138 |
+ addEventHandlers : function(inst) {
|
|
| 139 |
+ this.setEventHandlers(inst, 1); |
|
| 140 |
+ }, |
|
| 141 |
+ |
|
| 142 |
+ /** |
|
| 143 |
+ * Sets or removes event handles form the specified instance. |
|
| 144 |
+ * |
|
| 145 |
+ * @param {bool} s True/false state if to add or remove event handlers.
|
|
| 146 |
+ */ |
|
| 147 |
+ setEventHandlers : function(inst, s) {
|
|
| 148 |
+ var doc = inst.getDoc(), ie, ot, i, f = s ? tinyMCE.addEvent : tinyMCE.removeEvent; |
|
| 149 |
+ |
|
| 150 |
+ ie = ['keypress', 'keyup', 'keydown', 'click', 'mouseup', 'mousedown', 'controlselect', 'dblclick']; |
|
| 151 |
+ ot = ['keypress', 'keyup', 'keydown', 'click', 'mouseup', 'mousedown', 'focus', 'blur', 'dragdrop']; |
|
| 152 |
+ |
|
| 153 |
+ inst.switchSettings(); |
|
| 154 |
+ |
|
| 155 |
+ if (tinyMCE.isIE) {
|
|
| 156 |
+ for (i=0; i<ie.length; i++) |
|
| 157 |
+ f(doc, ie[i], TinyMCE_Engine.prototype._eventPatch); |
|
| 158 |
+ } else {
|
|
| 159 |
+ for (i=0; i<ot.length; i++) |
|
| 160 |
+ f(doc, ot[i], tinyMCE.handleEvent); |
|
| 161 |
+ |
|
| 162 |
+ // Force designmode |
|
| 163 |
+ try {
|
|
| 164 |
+ doc.designMode = "On"; |
|
| 165 |
+ } catch (e) {
|
|
| 166 |
+ // Ignore |
|
| 167 |
+ } |
|
| 168 |
+ } |
|
| 169 |
+ }, |
|
| 170 |
+ |
|
| 171 |
+ /** |
|
| 172 |
+ * Mouse move handler function, this will be executed each time |
|
| 173 |
+ * the mouse is moved within a editor instance. This function stores away the current selection in MSIE |
|
| 174 |
+ * this will then be used when a undo/redo level is added. |
|
| 175 |
+ */ |
|
| 176 |
+ onMouseMove : function() {
|
|
| 177 |
+ var inst, lh; |
|
| 178 |
+ |
|
| 179 |
+ // Fix for IE7 bug where it's not restoring hover on anchors correctly |
|
| 180 |
+ if (tinyMCE.lastHover) {
|
|
| 181 |
+ lh = tinyMCE.lastHover; |
|
| 182 |
+ |
|
| 183 |
+ // Call out on menus and refresh class on normal buttons |
|
| 184 |
+ if (lh.className.indexOf('mceMenu') != -1)
|
|
| 185 |
+ tinyMCE._menuButtonEvent('out', lh);
|
|
| 186 |
+ else |
|
| 187 |
+ lh.className = lh.className; |
|
| 188 |
+ |
|
| 189 |
+ tinyMCE.lastHover = null; |
|
| 190 |
+ } |
|
| 191 |
+ |
|
| 192 |
+ if (!tinyMCE.hasMouseMoved) {
|
|
| 193 |
+ inst = tinyMCE.selectedInstance; |
|
| 194 |
+ |
|
| 195 |
+ // Workaround for bug #1437457 (Odd MSIE bug) |
|
| 196 |
+ if (inst.isFocused) {
|
|
| 197 |
+ inst.undoBookmark = inst.selection.getBookmark(); |
|
| 198 |
+ tinyMCE.hasMouseMoved = true; |
|
| 199 |
+ } |
|
| 200 |
+ } |
|
| 201 |
+ |
|
| 202 |
+ // tinyMCE.cancelEvent(inst.getWin().event); |
|
| 203 |
+ // return false; |
|
| 204 |
+ }, |
|
| 205 |
+ |
|
| 206 |
+ /** |
|
| 207 |
+ * Cancels the specified event, this will disable the event from be passed to other listeners in event chain. |
|
| 208 |
+ * |
|
| 209 |
+ * @param {DOMEvent} e Event to cancel.
|
|
| 210 |
+ * @return Returns false. |
|
| 211 |
+ * @type bool |
|
| 212 |
+ */ |
|
| 213 |
+ cancelEvent : function(e) {
|
|
| 214 |
+ if (!e) |
|
| 215 |
+ return false; |
|
| 216 |
+ |
|
| 217 |
+ if (tinyMCE.isIE) {
|
|
| 218 |
+ e.returnValue = false; |
|
| 219 |
+ e.cancelBubble = true; |
|
| 220 |
+ } else {
|
|
| 221 |
+ e.preventDefault(); |
|
| 222 |
+ e.stopPropagation && e.stopPropagation(); |
|
| 223 |
+ } |
|
| 224 |
+ |
|
| 225 |
+ return false; |
|
| 226 |
+ }, |
|
| 227 |
+ |
|
| 228 |
+ /** |
|
| 229 |
+ * Adds a event handler function to the specified object. |
|
| 230 |
+ * |
|
| 231 |
+ * @param {HTMLElement} o Object to add event handler to.
|
|
| 232 |
+ * @param {string} n Event name to listen to for example "click".
|
|
| 233 |
+ * @param {function} h Function handler to execute when event occurs.
|
|
| 234 |
+ */ |
|
| 235 |
+ addEvent : function(o, n, h) {
|
|
| 236 |
+ // Add cleanup for all non unload events |
|
| 237 |
+ if (n != 'unload') {
|
|
| 238 |
+ function clean() {
|
|
| 239 |
+ var ex; |
|
| 240 |
+ |
|
| 241 |
+ try {
|
|
| 242 |
+ tinyMCE.removeEvent(o, n, h); |
|
| 243 |
+ tinyMCE.removeEvent(window, 'unload', clean); |
|
| 244 |
+ o = n = h = null; |
|
| 245 |
+ } catch (ex) {
|
|
| 246 |
+ // IE may produce access denied exception on unload |
|
| 247 |
+ } |
|
| 248 |
+ } |
|
| 249 |
+ |
|
| 250 |
+ // Add memory cleaner |
|
| 251 |
+ tinyMCE.addEvent(window, 'unload', clean); |
|
| 252 |
+ } |
|
| 253 |
+ |
|
| 254 |
+ if (o.attachEvent) |
|
| 255 |
+ o.attachEvent("on" + n, h);
|
|
| 256 |
+ else |
|
| 257 |
+ o.addEventListener(n, h, false); |
|
| 258 |
+ }, |
|
| 259 |
+ |
|
| 260 |
+ /** |
|
| 261 |
+ * Removes a event handler function from the specified object. |
|
| 262 |
+ * |
|
| 263 |
+ * @param {HTMLElement} o Object to remove event handler from.
|
|
| 264 |
+ * @param {string} n Event name to stop listening for. Example "click".
|
|
| 265 |
+ * @param {function} h Function handler to detach from the event.
|
|
| 266 |
+ */ |
|
| 267 |
+ removeEvent : function(o, n, h) {
|
|
| 268 |
+ if (o.detachEvent) |
|
| 269 |
+ o.detachEvent("on" + n, h);
|
|
| 270 |
+ else |
|
| 271 |
+ o.removeEventListener(n, h, false); |
|
| 272 |
+ }, |
|
| 273 |
+ |
|
| 274 |
+ /** |
|
| 275 |
+ * Adds accessibility keydown handler to the specified select element. |
|
| 276 |
+ * |
|
| 277 |
+ * @param {DOMEvent} e Event that gets passed when the element is focused.
|
|
| 278 |
+ * @param {HTMLElement} s Select element that the keydown handler gets added to.
|
|
| 279 |
+ * @param {DOMWindow} w DOM window reference to add.
|
|
| 280 |
+ */ |
|
| 281 |
+ addSelectAccessibility : function(e, s, w) {
|
|
| 282 |
+ // Add event handlers |
|
| 283 |
+ if (!s._isAccessible) {
|
|
| 284 |
+ s.onkeydown = tinyMCE.accessibleEventHandler; |
|
| 285 |
+ s.onblur = tinyMCE.accessibleEventHandler; |
|
| 286 |
+ s._isAccessible = true; |
|
| 287 |
+ s._win = w; |
|
| 288 |
+ } |
|
| 289 |
+ |
|
| 290 |
+ return false; |
|
| 291 |
+ }, |
|
| 292 |
+ |
|
| 293 |
+ /** |
|
| 294 |
+ * Accessibility handler that gets executed when the user hits a key in a select element. |
|
| 295 |
+ * This handler trams the enter/return or space key and then executes the onchange event handler. |
|
| 296 |
+ * |
|
| 297 |
+ * @param {DOMEvent} e DOM event object instance.
|
|
| 298 |
+ */ |
|
| 299 |
+ accessibleEventHandler : function(e) {
|
|
| 300 |
+ var elm, win = this._win; |
|
| 301 |
+ |
|
| 302 |
+ e = tinyMCE.isIE ? win.event : e; |
|
| 303 |
+ elm = tinyMCE.isIE ? e.srcElement : e.target; |
|
| 304 |
+ |
|
| 305 |
+ // Unpiggyback onchange on blur |
|
| 306 |
+ if (e.type == "blur") {
|
|
| 307 |
+ if (elm.oldonchange) {
|
|
| 308 |
+ elm.onchange = elm.oldonchange; |
|
| 309 |
+ elm.oldonchange = null; |
|
| 310 |
+ } |
|
| 311 |
+ |
|
| 312 |
+ return true; |
|
| 313 |
+ } |
|
| 314 |
+ |
|
| 315 |
+ // Piggyback onchange |
|
| 316 |
+ if (elm.nodeName == "SELECT" && !elm.oldonchange) {
|
|
| 317 |
+ elm.oldonchange = elm.onchange; |
|
| 318 |
+ elm.onchange = null; |
|
| 319 |
+ } |
|
| 320 |
+ |
|
| 321 |
+ // Execute onchange and remove piggyback |
|
| 322 |
+ if (e.keyCode == 13 || e.keyCode == 32) {
|
|
| 323 |
+ elm.onchange = elm.oldonchange; |
|
| 324 |
+ elm.onchange(); |
|
| 325 |
+ elm.oldonchange = null; |
|
| 326 |
+ |
|
| 327 |
+ tinyMCE.cancelEvent(e); |
|
| 328 |
+ return false; |
|
| 329 |
+ } |
|
| 330 |
+ |
|
| 331 |
+ return true; |
|
| 332 |
+ }, |
|
| 333 |
+ |
|
| 334 |
+ /** |
|
| 335 |
+ * Resets the iframe width and height to it's old values before a drag/drop operation occured. |
|
| 336 |
+ * This function is used in a workaround for a MSIE bug where drag/drop fails in iframes with width/height in %. |
|
| 337 |
+ */ |
|
| 338 |
+ _resetIframeHeight : function() {
|
|
| 339 |
+ var ife; |
|
| 340 |
+ |
|
| 341 |
+ if (tinyMCE.isRealIE) {
|
|
| 342 |
+ ife = tinyMCE.selectedInstance.iframeElement; |
|
| 343 |
+ |
|
| 344 |
+ /* if (ife._oldWidth) {
|
|
| 345 |
+ ife.style.width = ife._oldWidth; |
|
| 346 |
+ ife.width = ife._oldWidth; |
|
| 347 |
+ }*/ |
|
| 348 |
+ |
|
| 349 |
+ if (ife._oldHeight) {
|
|
| 350 |
+ ife.style.height = ife._oldHeight; |
|
| 351 |
+ ife.height = ife._oldHeight; |
|
| 352 |
+ } |
|
| 353 |
+ } |
|
| 354 |
+ } |
|
| 355 |
+ |
|
| 356 |
+ /**#@-*/ |
|
| 357 |
+}); |