3 tinymce.create('tinymce.plugins.wpGallery', {
5 init : function(ed, url) {
11 // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
12 ed.addCommand('WP_Gallery', function() {
13 var el = ed.selection.getNode(), post_id, vp = tinymce.DOM.getViewPort(), H = vp.h - 80, W = ( 640 < vp.w ) ? 640 : vp.w;
15 if ( el.nodeName != 'IMG' ) return;
16 if ( ed.dom.getAttrib(el, 'class').indexOf('wpGallery') == -1 ) return;
18 post_id = tinymce.DOM.get('post_ID').value;
19 tb_show('', tinymce.documentBaseURL + '/media-upload.php?post_id='+post_id+'&tab=gallery&TB_iframe=true&width='+W+'&height='+H);
21 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
24 ed.onInit.add(function(ed) {
25 tinymce.dom.Event.add(ed.getWin(), 'scroll', function(e) {
26 ed.plugins.wpgallery.hideButtons();
30 ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
31 ed.plugins.wpgallery.hideButtons();
34 ed.onSaveContent.add(function(ed, o) {
35 ed.plugins.wpgallery.hideButtons();
38 ed.onMouseUp.add(function(ed, e) {
39 if ( tinymce.isOpera ) {
40 if ( e.target.nodeName == 'IMG' )
41 ed.plugins.wpgallery.showButtons(e.target);
46 ed.onMouseDown.add(function(ed, e) {
47 if ( tinymce.isOpera || e.target.nodeName != 'IMG' ) {
51 ed.plugins.wpgallery.showButtons(e.target);
54 ed.onBeforeSetContent.add(function(ed, o) {
55 o.content = t._do_gallery(o.content);
58 ed.onPostProcess.add(function(ed, o) {
60 o.content = t._get_gallery(o.content);
64 _do_gallery : function(co) {
65 return co.replace(/\[gallery([^\]]*)\]/g, function(a,b){
66 return '<img src="'+tinymce.baseURL+'/plugins/wpgallery/img/t.gif" class="wpGallery mceItem" title="gallery'+tinymce.DOM.encode(b)+'" />';
70 _get_gallery : function(co) {
72 function getAttr(s, n) {
73 n = new RegExp(n + '=\"([^\"]+)\"', 'g').exec(s);
74 return n ? tinymce.DOM.decode(n[1]) : '';
77 return co.replace(/(?:<p[^>]*>)*(<img[^>]+>)(?:<\/p>)*/g, function(a,im) {
78 var cls = getAttr(im, 'class');
80 if ( cls.indexOf('wpGallery') != -1 )
81 return '<p>['+tinymce.trim(getAttr(im, 'title'))+']</p>';
87 showButtons : function(n) {
88 var t = this, ed = tinyMCE.activeEditor, p1, p2, vp, DOM = tinymce.DOM, X, Y;
90 if (ed.dom.getAttrib(n, 'class').indexOf('wpGallery') == -1)
93 vp = ed.dom.getViewPort(ed.getWin());
94 p1 = DOM.getPos(ed.getContentAreaContainer());
95 p2 = ed.dom.getPos(n);
97 X = Math.max(p2.x - vp.x, 0) + p1.x;
98 Y = Math.max(p2.y - vp.y, 0) + p1.y;
100 DOM.setStyles('wp_gallerybtns', {
106 t.btnsTout = window.setTimeout( function(){ed.plugins.wpgallery.hideButtons();}, 5000 );
109 hideButtons : function() {
110 if ( tinymce.DOM.isHidden('wp_gallerybtns') ) return;
112 tinymce.DOM.hide('wp_gallerybtns');
113 window.clearTimeout(this.btnsTout);
116 _createButtons : function() {
117 var t = this, ed = tinyMCE.activeEditor, DOM = tinymce.DOM, wp_gallerybtns, wp_editgallery, wp_delgallery;
119 DOM.remove('wp_gallerybtns');
121 wp_gallerybtns = DOM.add(document.body, 'div', {
122 id : 'wp_gallerybtns',
123 style : 'display:none;'
126 wp_editgallery = DOM.add('wp_gallerybtns', 'img', {
127 src : t.url+'/img/edit.png',
128 id : 'wp_editgallery',
131 title : ed.getLang('wordpress.editgallery')
134 wp_editgallery.onmousedown = function(e) {
135 var ed = tinyMCE.activeEditor;
136 ed.windowManager.bookmark = ed.selection.getBookmark('simple');
137 ed.execCommand("WP_Gallery");
138 this.parentNode.style.display = 'none';
141 wp_delgallery = DOM.add('wp_gallerybtns', 'img', {
142 src : t.url+'/img/delete.png',
143 id : 'wp_delgallery',
146 title : ed.getLang('wordpress.delgallery')
149 wp_delgallery.onmousedown = function(e) {
150 var ed = tinyMCE.activeEditor, el = ed.selection.getNode();
152 if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('wpGallery') != -1 ) {
155 this.parentNode.style.display = 'none';
156 ed.execCommand('mceRepaint');
162 getInfo : function() {
164 longname : 'Gallery Settings',
165 author : 'WordPress',
166 authorurl : 'http://wordpress.org',
173 tinymce.PluginManager.add('wpgallery', tinymce.plugins.wpGallery);