2 * $Id: editor_plugin_src.js 652 2008-02-29 13:09:46Z spocke $
\r
5 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
\r
9 tinymce.create('tinymce.plugins.Layer', {
\r
10 init : function(ed, url) {
\r
15 // Register commands
\r
16 ed.addCommand('mceInsertLayer', t._insertLayer, t);
\r
18 ed.addCommand('mceMoveForward', function() {
\r
22 ed.addCommand('mceMoveBackward', function() {
\r
26 ed.addCommand('mceMakeAbsolute', function() {
\r
27 t._toggleAbsolute();
\r
31 ed.addButton('moveforward', {title : 'layer.forward_desc', cmd : 'mceMoveForward'});
\r
32 ed.addButton('movebackward', {title : 'layer.backward_desc', cmd : 'mceMoveBackward'});
\r
33 ed.addButton('absolute', {title : 'layer.absolute_desc', cmd : 'mceMakeAbsolute'});
\r
34 ed.addButton('insertlayer', {title : 'layer.insertlayer_desc', cmd : 'mceInsertLayer'});
\r
36 ed.onInit.add(function() {
\r
38 ed.getDoc().execCommand('2D-Position', false, true);
\r
41 ed.onNodeChange.add(t._nodeChange, t);
\r
42 ed.onVisualAid.add(t._visualAid, t);
\r
45 getInfo : function() {
\r
48 author : 'Moxiecode Systems AB',
\r
49 authorurl : 'http://tinymce.moxiecode.com',
\r
50 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/layer',
\r
51 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
57 _nodeChange : function(ed, cm, n) {
\r
60 le = this._getParentLayer(n);
\r
61 p = ed.dom.getParent(n, 'DIV,P,IMG');
\r
64 cm.setDisabled('absolute', 1);
\r
65 cm.setDisabled('moveforward', 1);
\r
66 cm.setDisabled('movebackward', 1);
\r
68 cm.setDisabled('absolute', 0);
\r
69 cm.setDisabled('moveforward', !le);
\r
70 cm.setDisabled('movebackward', !le);
\r
71 cm.setActive('absolute', le && le.style.position.toLowerCase() == "absolute");
\r
77 _visualAid : function(ed, e, s) {
\r
80 tinymce.each(dom.select('div,p', e), function(e) {
\r
81 if (/^(absolute|relative|static)$/i.test(e.style.position)) {
\r
83 dom.addClass(e, 'mceItemVisualAid');
\r
85 dom.removeClass(e, 'mceItemVisualAid');
\r
90 _move : function(d) {
\r
91 var ed = this.editor, i, z = [], le = this._getParentLayer(ed.selection.getNode()), ci = -1, fi = -1, nl;
\r
94 tinymce.walk(ed.getBody(), function(n) {
\r
95 if (n.nodeType == 1 && /^(absolute|relative|static)$/i.test(n.style.position))
\r
100 for (i=0; i<nl.length; i++) {
\r
101 z[i] = nl[i].style.zIndex ? parseInt(nl[i].style.zIndex) : 0;
\r
103 if (ci < 0 && nl[i] == le)
\r
110 // Try find a lower one
\r
111 for (i=0; i<z.length; i++) {
\r
112 if (z[i] < z[ci]) {
\r
119 nl[ci].style.zIndex = z[fi];
\r
120 nl[fi].style.zIndex = z[ci];
\r
123 nl[ci].style.zIndex = z[ci] - 1;
\r
128 // Try find a higher one
\r
129 for (i=0; i<z.length; i++) {
\r
130 if (z[i] > z[ci]) {
\r
137 nl[ci].style.zIndex = z[fi];
\r
138 nl[fi].style.zIndex = z[ci];
\r
140 nl[ci].style.zIndex = z[ci] + 1;
\r
143 ed.execCommand('mceRepaint');
\r
146 _getParentLayer : function(n) {
\r
147 return this.editor.dom.getParent(n, function(n) {
\r
148 return n.nodeType == 1 && /^(absolute|relative|static)$/i.test(n.style.position);
\r
152 _insertLayer : function() {
\r
153 var ed = this.editor, p = ed.dom.getPos(ed.dom.getParent(ed.selection.getNode(), '*'));
\r
155 ed.dom.add(ed.getBody(), 'div', {
\r
157 position : 'absolute',
\r
159 top : (p.y > 20 ? p.y : 20),
\r
163 'class' : 'mceItemVisualAid'
\r
164 }, ed.selection.getContent() || ed.getLang('layer.content'));
\r
167 _toggleAbsolute : function() {
\r
168 var ed = this.editor, le = this._getParentLayer(ed.selection.getNode());
\r
171 le = ed.dom.getParent(ed.selection.getNode(), 'DIV,P,IMG');
\r
174 if (le.style.position.toLowerCase() == "absolute") {
\r
175 ed.dom.setStyles(le, {
\r
183 ed.dom.removeClass(le, 'mceItemVisualAid');
\r
185 if (le.style.left == "")
\r
186 le.style.left = 20 + 'px';
\r
188 if (le.style.top == "")
\r
189 le.style.top = 20 + 'px';
\r
191 if (le.style.width == "")
\r
192 le.style.width = le.width ? (le.width + 'px') : '100px';
\r
194 if (le.style.height == "")
\r
195 le.style.height = le.height ? (le.height + 'px') : '100px';
\r
197 le.style.position = "absolute";
\r
198 ed.addVisual(ed.getBody());
\r
201 ed.execCommand('mceRepaint');
\r
208 tinymce.PluginManager.add('layer', tinymce.plugins.Layer);
\r