2 * editor_plugin_src.js
\r
4 * Copyright 2009, Moxiecode Systems AB
\r
5 * Released under LGPL License.
\r
7 * License: http://tinymce.moxiecode.com/license
\r
8 * Contributing: http://tinymce.moxiecode.com/contributing
\r
12 tinymce.create('tinymce.plugins.Layer', {
\r
13 init : function(ed, url) {
\r
18 // Register commands
\r
19 ed.addCommand('mceInsertLayer', t._insertLayer, t);
\r
21 ed.addCommand('mceMoveForward', function() {
\r
25 ed.addCommand('mceMoveBackward', function() {
\r
29 ed.addCommand('mceMakeAbsolute', function() {
\r
30 t._toggleAbsolute();
\r
34 ed.addButton('moveforward', {title : 'layer.forward_desc', cmd : 'mceMoveForward'});
\r
35 ed.addButton('movebackward', {title : 'layer.backward_desc', cmd : 'mceMoveBackward'});
\r
36 ed.addButton('absolute', {title : 'layer.absolute_desc', cmd : 'mceMakeAbsolute'});
\r
37 ed.addButton('insertlayer', {title : 'layer.insertlayer_desc', cmd : 'mceInsertLayer'});
\r
39 ed.onInit.add(function() {
\r
41 ed.getDoc().execCommand('2D-Position', false, true);
\r
44 ed.onNodeChange.add(t._nodeChange, t);
\r
45 ed.onVisualAid.add(t._visualAid, t);
\r
48 getInfo : function() {
\r
51 author : 'Moxiecode Systems AB',
\r
52 authorurl : 'http://tinymce.moxiecode.com',
\r
53 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/layer',
\r
54 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
60 _nodeChange : function(ed, cm, n) {
\r
63 le = this._getParentLayer(n);
\r
64 p = ed.dom.getParent(n, 'DIV,P,IMG');
\r
67 cm.setDisabled('absolute', 1);
\r
68 cm.setDisabled('moveforward', 1);
\r
69 cm.setDisabled('movebackward', 1);
\r
71 cm.setDisabled('absolute', 0);
\r
72 cm.setDisabled('moveforward', !le);
\r
73 cm.setDisabled('movebackward', !le);
\r
74 cm.setActive('absolute', le && le.style.position.toLowerCase() == "absolute");
\r
80 _visualAid : function(ed, e, s) {
\r
83 tinymce.each(dom.select('div,p', e), function(e) {
\r
84 if (/^(absolute|relative|static)$/i.test(e.style.position)) {
\r
86 dom.addClass(e, 'mceItemVisualAid');
\r
88 dom.removeClass(e, 'mceItemVisualAid');
\r
93 _move : function(d) {
\r
94 var ed = this.editor, i, z = [], le = this._getParentLayer(ed.selection.getNode()), ci = -1, fi = -1, nl;
\r
97 tinymce.walk(ed.getBody(), function(n) {
\r
98 if (n.nodeType == 1 && /^(absolute|relative|static)$/i.test(n.style.position))
\r
103 for (i=0; i<nl.length; i++) {
\r
104 z[i] = nl[i].style.zIndex ? parseInt(nl[i].style.zIndex) : 0;
\r
106 if (ci < 0 && nl[i] == le)
\r
113 // Try find a lower one
\r
114 for (i=0; i<z.length; i++) {
\r
115 if (z[i] < z[ci]) {
\r
122 nl[ci].style.zIndex = z[fi];
\r
123 nl[fi].style.zIndex = z[ci];
\r
126 nl[ci].style.zIndex = z[ci] - 1;
\r
131 // Try find a higher one
\r
132 for (i=0; i<z.length; i++) {
\r
133 if (z[i] > z[ci]) {
\r
140 nl[ci].style.zIndex = z[fi];
\r
141 nl[fi].style.zIndex = z[ci];
\r
143 nl[ci].style.zIndex = z[ci] + 1;
\r
146 ed.execCommand('mceRepaint');
\r
149 _getParentLayer : function(n) {
\r
150 return this.editor.dom.getParent(n, function(n) {
\r
151 return n.nodeType == 1 && /^(absolute|relative|static)$/i.test(n.style.position);
\r
155 _insertLayer : function() {
\r
156 var ed = this.editor, p = ed.dom.getPos(ed.dom.getParent(ed.selection.getNode(), '*'));
\r
158 ed.dom.add(ed.getBody(), 'div', {
\r
160 position : 'absolute',
\r
162 top : (p.y > 20 ? p.y : 20),
\r
166 'class' : 'mceItemVisualAid'
\r
167 }, ed.selection.getContent() || ed.getLang('layer.content'));
\r
170 _toggleAbsolute : function() {
\r
171 var ed = this.editor, le = this._getParentLayer(ed.selection.getNode());
\r
174 le = ed.dom.getParent(ed.selection.getNode(), 'DIV,P,IMG');
\r
177 if (le.style.position.toLowerCase() == "absolute") {
\r
178 ed.dom.setStyles(le, {
\r
186 ed.dom.removeClass(le, 'mceItemVisualAid');
\r
188 if (le.style.left == "")
\r
189 le.style.left = 20 + 'px';
\r
191 if (le.style.top == "")
\r
192 le.style.top = 20 + 'px';
\r
194 if (le.style.width == "")
\r
195 le.style.width = le.width ? (le.width + 'px') : '100px';
\r
197 if (le.style.height == "")
\r
198 le.style.height = le.height ? (le.height + 'px') : '100px';
\r
200 le.style.position = "absolute";
\r
201 ed.addVisual(ed.getBody());
\r
204 ed.execCommand('mceRepaint');
\r
211 tinymce.PluginManager.add('layer', tinymce.plugins.Layer);
\r