annotate static/js/tiny_mce/plugins/layer/editor_plugin_src.js @ 442:6c182ceb7147

Fixing #217; upgrade TinyMCE to 3.4.2 and enable the paste plugin.
author Brian Neal <bgneal@gmail.com>
date Thu, 26 May 2011 00:43:49 +0000
parents 88b2b9cb8c1f
children
rev   line source
bgneal@312 1 /**
bgneal@312 2 * editor_plugin_src.js
bgneal@312 3 *
bgneal@312 4 * Copyright 2009, Moxiecode Systems AB
bgneal@312 5 * Released under LGPL License.
bgneal@312 6 *
bgneal@312 7 * License: http://tinymce.moxiecode.com/license
bgneal@312 8 * Contributing: http://tinymce.moxiecode.com/contributing
bgneal@312 9 */
bgneal@312 10
bgneal@312 11 (function() {
bgneal@312 12 tinymce.create('tinymce.plugins.Layer', {
bgneal@312 13 init : function(ed, url) {
bgneal@312 14 var t = this;
bgneal@312 15
bgneal@312 16 t.editor = ed;
bgneal@312 17
bgneal@312 18 // Register commands
bgneal@312 19 ed.addCommand('mceInsertLayer', t._insertLayer, t);
bgneal@312 20
bgneal@312 21 ed.addCommand('mceMoveForward', function() {
bgneal@312 22 t._move(1);
bgneal@312 23 });
bgneal@312 24
bgneal@312 25 ed.addCommand('mceMoveBackward', function() {
bgneal@312 26 t._move(-1);
bgneal@312 27 });
bgneal@312 28
bgneal@312 29 ed.addCommand('mceMakeAbsolute', function() {
bgneal@312 30 t._toggleAbsolute();
bgneal@312 31 });
bgneal@312 32
bgneal@312 33 // Register buttons
bgneal@312 34 ed.addButton('moveforward', {title : 'layer.forward_desc', cmd : 'mceMoveForward'});
bgneal@312 35 ed.addButton('movebackward', {title : 'layer.backward_desc', cmd : 'mceMoveBackward'});
bgneal@312 36 ed.addButton('absolute', {title : 'layer.absolute_desc', cmd : 'mceMakeAbsolute'});
bgneal@312 37 ed.addButton('insertlayer', {title : 'layer.insertlayer_desc', cmd : 'mceInsertLayer'});
bgneal@312 38
bgneal@312 39 ed.onInit.add(function() {
bgneal@312 40 if (tinymce.isIE)
bgneal@312 41 ed.getDoc().execCommand('2D-Position', false, true);
bgneal@312 42 });
bgneal@312 43
bgneal@312 44 ed.onNodeChange.add(t._nodeChange, t);
bgneal@312 45 ed.onVisualAid.add(t._visualAid, t);
bgneal@312 46 },
bgneal@312 47
bgneal@312 48 getInfo : function() {
bgneal@312 49 return {
bgneal@312 50 longname : 'Layer',
bgneal@312 51 author : 'Moxiecode Systems AB',
bgneal@312 52 authorurl : 'http://tinymce.moxiecode.com',
bgneal@312 53 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/layer',
bgneal@312 54 version : tinymce.majorVersion + "." + tinymce.minorVersion
bgneal@312 55 };
bgneal@312 56 },
bgneal@312 57
bgneal@312 58 // Private methods
bgneal@312 59
bgneal@312 60 _nodeChange : function(ed, cm, n) {
bgneal@312 61 var le, p;
bgneal@312 62
bgneal@312 63 le = this._getParentLayer(n);
bgneal@312 64 p = ed.dom.getParent(n, 'DIV,P,IMG');
bgneal@312 65
bgneal@312 66 if (!p) {
bgneal@312 67 cm.setDisabled('absolute', 1);
bgneal@312 68 cm.setDisabled('moveforward', 1);
bgneal@312 69 cm.setDisabled('movebackward', 1);
bgneal@312 70 } else {
bgneal@312 71 cm.setDisabled('absolute', 0);
bgneal@312 72 cm.setDisabled('moveforward', !le);
bgneal@312 73 cm.setDisabled('movebackward', !le);
bgneal@312 74 cm.setActive('absolute', le && le.style.position.toLowerCase() == "absolute");
bgneal@312 75 }
bgneal@312 76 },
bgneal@312 77
bgneal@312 78 // Private methods
bgneal@312 79
bgneal@312 80 _visualAid : function(ed, e, s) {
bgneal@312 81 var dom = ed.dom;
bgneal@312 82
bgneal@312 83 tinymce.each(dom.select('div,p', e), function(e) {
bgneal@312 84 if (/^(absolute|relative|static)$/i.test(e.style.position)) {
bgneal@312 85 if (s)
bgneal@312 86 dom.addClass(e, 'mceItemVisualAid');
bgneal@312 87 else
bgneal@312 88 dom.removeClass(e, 'mceItemVisualAid');
bgneal@312 89 }
bgneal@312 90 });
bgneal@312 91 },
bgneal@312 92
bgneal@312 93 _move : function(d) {
bgneal@312 94 var ed = this.editor, i, z = [], le = this._getParentLayer(ed.selection.getNode()), ci = -1, fi = -1, nl;
bgneal@312 95
bgneal@312 96 nl = [];
bgneal@312 97 tinymce.walk(ed.getBody(), function(n) {
bgneal@312 98 if (n.nodeType == 1 && /^(absolute|relative|static)$/i.test(n.style.position))
bgneal@312 99 nl.push(n);
bgneal@312 100 }, 'childNodes');
bgneal@312 101
bgneal@312 102 // Find z-indexes
bgneal@312 103 for (i=0; i<nl.length; i++) {
bgneal@312 104 z[i] = nl[i].style.zIndex ? parseInt(nl[i].style.zIndex) : 0;
bgneal@312 105
bgneal@312 106 if (ci < 0 && nl[i] == le)
bgneal@312 107 ci = i;
bgneal@312 108 }
bgneal@312 109
bgneal@312 110 if (d < 0) {
bgneal@312 111 // Move back
bgneal@312 112
bgneal@312 113 // Try find a lower one
bgneal@312 114 for (i=0; i<z.length; i++) {
bgneal@312 115 if (z[i] < z[ci]) {
bgneal@312 116 fi = i;
bgneal@312 117 break;
bgneal@312 118 }
bgneal@312 119 }
bgneal@312 120
bgneal@312 121 if (fi > -1) {
bgneal@312 122 nl[ci].style.zIndex = z[fi];
bgneal@312 123 nl[fi].style.zIndex = z[ci];
bgneal@312 124 } else {
bgneal@312 125 if (z[ci] > 0)
bgneal@312 126 nl[ci].style.zIndex = z[ci] - 1;
bgneal@312 127 }
bgneal@312 128 } else {
bgneal@312 129 // Move forward
bgneal@312 130
bgneal@312 131 // Try find a higher one
bgneal@312 132 for (i=0; i<z.length; i++) {
bgneal@312 133 if (z[i] > z[ci]) {
bgneal@312 134 fi = i;
bgneal@312 135 break;
bgneal@312 136 }
bgneal@312 137 }
bgneal@312 138
bgneal@312 139 if (fi > -1) {
bgneal@312 140 nl[ci].style.zIndex = z[fi];
bgneal@312 141 nl[fi].style.zIndex = z[ci];
bgneal@312 142 } else
bgneal@312 143 nl[ci].style.zIndex = z[ci] + 1;
bgneal@312 144 }
bgneal@312 145
bgneal@312 146 ed.execCommand('mceRepaint');
bgneal@312 147 },
bgneal@312 148
bgneal@312 149 _getParentLayer : function(n) {
bgneal@312 150 return this.editor.dom.getParent(n, function(n) {
bgneal@312 151 return n.nodeType == 1 && /^(absolute|relative|static)$/i.test(n.style.position);
bgneal@312 152 });
bgneal@312 153 },
bgneal@312 154
bgneal@312 155 _insertLayer : function() {
bgneal@312 156 var ed = this.editor, p = ed.dom.getPos(ed.dom.getParent(ed.selection.getNode(), '*'));
bgneal@312 157
bgneal@312 158 ed.dom.add(ed.getBody(), 'div', {
bgneal@312 159 style : {
bgneal@312 160 position : 'absolute',
bgneal@312 161 left : p.x,
bgneal@312 162 top : (p.y > 20 ? p.y : 20),
bgneal@312 163 width : 100,
bgneal@312 164 height : 100
bgneal@312 165 },
bgneal@312 166 'class' : 'mceItemVisualAid'
bgneal@312 167 }, ed.selection.getContent() || ed.getLang('layer.content'));
bgneal@312 168 },
bgneal@312 169
bgneal@312 170 _toggleAbsolute : function() {
bgneal@312 171 var ed = this.editor, le = this._getParentLayer(ed.selection.getNode());
bgneal@312 172
bgneal@312 173 if (!le)
bgneal@312 174 le = ed.dom.getParent(ed.selection.getNode(), 'DIV,P,IMG');
bgneal@312 175
bgneal@312 176 if (le) {
bgneal@312 177 if (le.style.position.toLowerCase() == "absolute") {
bgneal@312 178 ed.dom.setStyles(le, {
bgneal@312 179 position : '',
bgneal@312 180 left : '',
bgneal@312 181 top : '',
bgneal@312 182 width : '',
bgneal@312 183 height : ''
bgneal@312 184 });
bgneal@312 185
bgneal@312 186 ed.dom.removeClass(le, 'mceItemVisualAid');
bgneal@312 187 } else {
bgneal@312 188 if (le.style.left == "")
bgneal@312 189 le.style.left = 20 + 'px';
bgneal@312 190
bgneal@312 191 if (le.style.top == "")
bgneal@312 192 le.style.top = 20 + 'px';
bgneal@312 193
bgneal@312 194 if (le.style.width == "")
bgneal@312 195 le.style.width = le.width ? (le.width + 'px') : '100px';
bgneal@312 196
bgneal@312 197 if (le.style.height == "")
bgneal@312 198 le.style.height = le.height ? (le.height + 'px') : '100px';
bgneal@312 199
bgneal@312 200 le.style.position = "absolute";
bgneal@442 201
bgneal@442 202 ed.dom.setAttrib(le, 'data-mce-style', '');
bgneal@312 203 ed.addVisual(ed.getBody());
bgneal@312 204 }
bgneal@312 205
bgneal@312 206 ed.execCommand('mceRepaint');
bgneal@312 207 ed.nodeChanged();
bgneal@312 208 }
bgneal@312 209 }
bgneal@312 210 });
bgneal@312 211
bgneal@312 212 // Register plugin
bgneal@312 213 tinymce.PluginManager.add('layer', tinymce.plugins.Layer);
bgneal@312 214 })();