source: trunk/www.guidonia.net/wp/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.dev.js@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 7.2 KB
Line 
1
2(function() {
3 tinymce.create('tinymce.plugins.wpEditImage', {
4
5 init : function(ed, url) {
6 var t = this;
7
8 t.url = url;
9 t._createButtons();
10
11 // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
12 ed.addCommand('WP_EditImage', function() {
13 var el = ed.selection.getNode(), vp = tinymce.DOM.getViewPort(), H = vp.h, W = ( 720 < vp.w ) ? 720 : vp.w, cls = ed.dom.getAttrib(el, 'class');
14
15 if ( cls.indexOf('mceItem') != -1 || cls.indexOf('wpGallery') != -1 || el.nodeName != 'IMG' )
16 return;
17
18 tb_show('', url + '/editimage.html?ver=321&TB_iframe=true');
19 tinymce.DOM.setStyles('TB_window', {
20 'width':( W - 50 )+'px',
21 'height':( H - 45 )+'px',
22 'margin-left':'-'+parseInt((( W - 50 ) / 2),10) + 'px'
23 });
24
25 if ( ! tinymce.isIE6 ) {
26 tinymce.DOM.setStyles('TB_window', {
27 'top':'20px',
28 'marginTop':'0'
29 });
30 }
31
32 tinymce.DOM.setStyles('TB_iframeContent', {
33 'width':( W - 50 )+'px',
34 'height':( H - 75 )+'px'
35 });
36 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
37 });
38
39 ed.onInit.add(function(ed) {
40 tinymce.dom.Event.add(ed.getWin(), 'scroll', function(e) {
41 ed.plugins.wpeditimage.hideButtons();
42 });
43 });
44
45 ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
46 ed.plugins.wpeditimage.hideButtons();
47 });
48
49 ed.onSaveContent.add(function(ed, o) {
50 ed.plugins.wpeditimage.hideButtons();
51 });
52
53 ed.onMouseUp.add(function(ed, e) {
54 var n, DL;
55
56 if ( tinymce.isOpera ) {
57 if ( e.target.nodeName == 'IMG' )
58 ed.plugins.wpeditimage.showButtons(e.target);
59 } else if ( ! tinymce.isWebKit ) {
60 n = ed.selection.getNode();
61
62 if ( n.nodeName == 'IMG' && (DL = ed.dom.getParent(n, 'DL')) ) {
63 window.setTimeout(function(){
64 var ed = tinyMCE.activeEditor, n = ed.selection.getNode(), DL = ed.dom.getParent(n, 'DL');
65
66 if ( n.width != (parseInt(ed.dom.getStyle(DL, 'width')) - 10) ) {
67 ed.dom.setStyle(DL, 'width', parseInt(n.width)+10);
68 ed.execCommand('mceRepaint');
69 }
70 }, 100);
71 }
72 }
73 });
74
75 ed.onMouseDown.add(function(ed, e) {
76 if ( tinymce.isOpera || e.target.nodeName != 'IMG' ) {
77 t.hideButtons();
78 return;
79 }
80 ed.plugins.wpeditimage.showButtons(e.target);
81 });
82
83 ed.onKeyPress.add(function(ed, e) {
84 var DL, DIV, P;
85
86 if ( e.keyCode == 13 && (DL = ed.dom.getParent(ed.selection.getNode(), 'DL')) ) {
87 P = ed.dom.create('p', {}, '&nbsp;');
88 if ( (DIV = DL.parentNode) && DIV.nodeName == 'DIV' )
89 ed.dom.insertAfter( P, DIV );
90 else ed.dom.insertAfter( P, DL );
91
92 tinymce.dom.Event.cancel(e);
93 ed.selection.select(P);
94 return false;
95 }
96 });
97
98 ed.onBeforeSetContent.add(function(ed, o) {
99 o.content = t._do_shcode(o.content);
100 });
101
102 ed.onPostProcess.add(function(ed, o) {
103 if (o.get)
104 o.content = t._get_shcode(o.content);
105 });
106 },
107
108 _do_shcode : function(co) {
109 return co.replace(/\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\][\s\u00a0]*/g, function(a,b,c){
110 var id, cls, w, cap, div_cls;
111
112 b = b.replace(/\\'|\\&#39;|\\&#039;/g, '&#39;').replace(/\\"|\\&quot;/g, '&quot;');
113 c = c.replace(/\\&#39;|\\&#039;/g, '&#39;').replace(/\\&quot;/g, '&quot;');
114 id = b.match(/id=['"]([^'"]+)/i);
115 cls = b.match(/align=['"]([^'"]+)/i);
116 w = b.match(/width=['"]([0-9]+)/);
117 cap = b.match(/caption=['"]([^'"]+)/i);
118
119 id = ( id && id[1] ) ? id[1] : '';
120 cls = ( cls && cls[1] ) ? cls[1] : 'alignnone';
121 w = ( w && w[1] ) ? w[1] : '';
122 cap = ( cap && cap[1] ) ? cap[1] : '';
123 if ( ! w || ! cap ) return c;
124
125 div_cls = (cls == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
126
127 return '<div class="'+div_cls+'"><dl id="'+id+'" class="wp-caption '+cls+'" style="width: '+(10+parseInt(w))+
128 'px"><dt class="wp-caption-dt">'+c+'</dt><dd class="wp-caption-dd">'+cap+'</dd></dl></div>';
129 });
130 },
131
132 _get_shcode : function(co) {
133 return co.replace(/<div class="mceTemp[^"]*">\s*<dl([^>]+)>\s*<dt[^>]+>([\s\S]+?)<\/dt>\s*<dd[^>]+>(.+?)<\/dd>\s*<\/dl>\s*<\/div>\s*/gi, function(a,b,c,cap){
134 var id, cls, w;
135
136 id = b.match(/id=['"]([^'"]+)/i);
137 cls = b.match(/class=['"]([^'"]+)/i);
138 w = c.match(/width=['"]([0-9]+)/);
139
140 id = ( id && id[1] ) ? id[1] : '';
141 cls = ( cls && cls[1] ) ? cls[1] : 'alignnone';
142 w = ( w && w[1] ) ? w[1] : '';
143
144 if ( ! w || ! cap ) return c;
145 cls = cls.match(/align[^ '"]+/) || 'alignnone';
146 cap = cap.replace(/<\S[^<>]*>/gi, '').replace(/'/g, '&#39;').replace(/"/g, '&quot;');
147
148 return '[caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/caption]';
149 });
150 },
151
152 showButtons : function(n) {
153 var t = this, ed = tinyMCE.activeEditor, p1, p2, vp, DOM = tinymce.DOM, X, Y, cls = ed.dom.getAttrib(n, 'class');
154
155 if ( cls.indexOf('mceItem') != -1 || cls.indexOf('wpGallery') != -1 )
156 return;
157
158 vp = ed.dom.getViewPort(ed.getWin());
159 p1 = DOM.getPos(ed.getContentAreaContainer());
160 p2 = ed.dom.getPos(n);
161
162 X = Math.max(p2.x - vp.x, 0) + p1.x;
163 Y = Math.max(p2.y - vp.y, 0) + p1.y;
164
165 DOM.setStyles('wp_editbtns', {
166 'top' : Y+5+'px',
167 'left' : X+5+'px',
168 'display' : 'block'
169 });
170
171 t.btnsTout = window.setTimeout( function(){ed.plugins.wpeditimage.hideButtons();}, 5000 );
172 },
173
174 hideButtons : function() {
175 if ( tinymce.DOM.isHidden('wp_editbtns') ) return;
176
177 tinymce.DOM.hide('wp_editbtns');
178 window.clearTimeout(this.btnsTout);
179 },
180
181 _createButtons : function() {
182 var t = this, ed = tinyMCE.activeEditor, DOM = tinymce.DOM, wp_editbtns, wp_editimgbtn, wp_delimgbtn;
183
184 DOM.remove('wp_editbtns');
185
186 wp_editbtns = DOM.add(document.body, 'div', {
187 id : 'wp_editbtns',
188 style : 'display:none;'
189 });
190
191 wp_editimgbtn = DOM.add('wp_editbtns', 'img', {
192 src : t.url+'/img/image.png',
193 id : 'wp_editimgbtn',
194 width : '24',
195 height : '24',
196 title : ed.getLang('wpeditimage.edit_img')
197 });
198
199 wp_editimgbtn.onmousedown = function(e) {
200 var ed = tinyMCE.activeEditor;
201 ed.windowManager.bookmark = ed.selection.getBookmark('simple');
202 ed.execCommand("WP_EditImage");
203 this.parentNode.style.display = 'none';
204 };
205
206 wp_delimgbtn = DOM.add('wp_editbtns', 'img', {
207 src : t.url+'/img/delete.png',
208 id : 'wp_delimgbtn',
209 width : '24',
210 height : '24',
211 title : ed.getLang('wpeditimage.del_img')
212 });
213
214 wp_delimgbtn.onmousedown = function(e) {
215 var ed = tinyMCE.activeEditor, el = ed.selection.getNode(), p;
216
217 if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('mceItem') == -1 ) {
218 if ( (p = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(p, 'mceTemp') )
219 ed.dom.remove(p);
220 else if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1 )
221 ed.dom.remove(p);
222 else ed.dom.remove(el);
223
224 this.parentNode.style.display = 'none';
225 ed.execCommand('mceRepaint');
226 return false;
227 }
228 };
229 },
230
231 getInfo : function() {
232 return {
233 longname : 'Edit Image',
234 author : 'WordPress',
235 authorurl : 'http://wordpress.org',
236 infourl : '',
237 version : "1.0"
238 };
239 }
240 });
241
242 tinymce.PluginManager.add('wpeditimage', tinymce.plugins.wpEditImage);
243})();
Note: See TracBrowser for help on using the repository browser.