/** * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $ * * @author Moxiecode * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved. */ /* Import plugin specific language pack */ tinyMCE.importPluginLanguagePack('layer'); var TinyMCE_LayerPlugin = { getInfo : function() { return { longname : 'Layer', author : 'Moxiecode Systems AB', authorurl : 'http://tinymce.moxiecode.com', infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/layer', version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion }; }, initInstance : function(inst) { if (tinyMCE.isMSIE && !tinyMCE.isOpera) inst.getDoc().execCommand('2D-Position'); }, handleEvent : function(e) { var inst = tinyMCE.selectedInstance; var w = inst.getWin(), le = inst._lastStyleElm, e; if (tinyMCE.isGecko) { e = this._getParentLayer(inst.getFocusElement()); if (e) { if (!inst._lastStyleElm) { e.style.overflow = 'auto'; inst._lastStyleElm = e; } } else if (le) { le = inst._lastStyleElm; le.style.width = le.scrollWidth + 'px'; le.style.height = le.scrollHeight + 'px'; le.style.overflow = ''; inst._lastStyleElm = null; } } return true; }, handleVisualAid : function(el, deep, state, inst) { var nl = inst.getDoc().getElementsByTagName("div"), i; for (i=0; i -1) { nl[ci].style.zIndex = z[fi]; nl[fi].style.zIndex = z[ci]; } else { if (z[ci] > 0) nl[ci].style.zIndex = z[ci] - 1; } } else { // Move forward // Try find a higher one for (i=0; i z[ci]) { fi = i; break; } } if (fi > -1) { nl[ci].style.zIndex = z[fi]; nl[fi].style.zIndex = z[ci]; } else nl[ci].style.zIndex = z[ci] + 1; } inst.repaint(); }, _getParentLayer : function(n) { return tinyMCE.getParentNode(n, function(n) { return n.nodeType == 1 && new RegExp('absolute|relative|static', 'gi').test(n.style.position); }); }, _insertLayer : function() { var inst = tinyMCE.selectedInstance; var e = tinyMCE.getParentElement(inst.getFocusElement()); var p = tinyMCE.getAbsPosition(e); var d = inst.getDoc(); var ne = d.createElement('div'); var h = inst.selection.getSelectedHTML(); // Move div ne.style.position = 'absolute'; ne.style.left = p.absLeft + 'px'; ne.style.top = (p.absTop > 20 ? p.absTop : 20) + 'px'; ne.style.width = '100px'; ne.style.height = '100px'; ne.className = 'mceVisualAid'; if (!h) h = tinyMCE.getLang('lang_layer_content'); ne.innerHTML = h; // Add it d.body.appendChild(ne); }, _toggleAbsolute : function() { var inst = tinyMCE.selectedInstance; var le = this._getParentLayer(inst.getFocusElement()); if (le == null) le = tinyMCE.getParentElement(inst.getFocusElement(), 'div,p,img'); if (le) { if (le.style.position.toLowerCase() == "absolute") { le.style.position = ""; le.style.left = ""; le.style.top = ""; } else { le.style.position = "absolute"; if (le.style.left == "") le.style.left = 20 + 'px'; if (le.style.top == "") le.style.top = 20 + 'px'; if (le.style.width == "") le.style.width = le.width ? (le.width + 'px') : '100px'; if (le.style.height == "") le.style.height = le.height ? (le.height + 'px') : '100px'; tinyMCE.handleVisualAid(inst.getBody(), true, inst.visualAid, inst); } inst.repaint(); tinyMCE.triggerNodeChange(); } } }; tinyMCE.addPlugin("layer", TinyMCE_LayerPlugin);