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(),
14 H = vp.h - 80, W = ( 640 < vp.w ) ? 640 : vp.w;
16 if ( el.nodeName != 'IMG' ) return;
17 if ( ed.dom.getAttrib(el, 'class').indexOf('wpGallery') == -1 ) return;
19 post_id = tinymce.DOM.get('post_ID').value;
20 tb_show('', tinymce.documentBaseURL + '/media-upload.php?post_id='+post_id+'&tab=gallery&TB_iframe=true&width='+W+'&height='+H);
22 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
25 ed.onMouseDown.add(function(ed, e) {
26 if ( e.target.nodeName == 'IMG' && ed.dom.hasClass(e.target, 'wpGallery') )
27 ed.plugins.wordpress._showButtons(e.target, 'wp_gallerybtns');
30 ed.onBeforeSetContent.add(function(ed, o) {
31 o.content = t._do_gallery(o.content);
34 ed.onPostProcess.add(function(ed, o) {
36 o.content = t._get_gallery(o.content);
40 _do_gallery : function(co) {
41 return co.replace(/\[gallery([^\]]*)\]/g, function(a,b){
42 return '<img src="'+tinymce.baseURL+'/plugins/wpgallery/img/t.gif" class="wpGallery mceItem" title="gallery'+tinymce.DOM.encode(b)+'" />';
46 _get_gallery : function(co) {
48 function getAttr(s, n) {
49 n = new RegExp(n + '=\"([^\"]+)\"', 'g').exec(s);
50 return n ? tinymce.DOM.decode(n[1]) : '';
53 return co.replace(/(?:<p[^>]*>)*(<img[^>]+>)(?:<\/p>)*/g, function(a,im) {
54 var cls = getAttr(im, 'class');
56 if ( cls.indexOf('wpGallery') != -1 )
57 return '<p>['+tinymce.trim(getAttr(im, 'title'))+']</p>';
63 _createButtons : function() {
64 var t = this, ed = tinyMCE.activeEditor, DOM = tinymce.DOM, editButton, dellButton;
66 DOM.remove('wp_gallerybtns');
68 DOM.add(document.body, 'div', {
69 id : 'wp_gallerybtns',
70 style : 'display:none;'
73 editButton = DOM.add('wp_gallerybtns', 'img', {
74 src : t.url+'/img/edit.png',
75 id : 'wp_editgallery',
78 title : ed.getLang('wordpress.editgallery')
81 tinymce.dom.Event.add(editButton, 'mousedown', function(e) {
82 var ed = tinyMCE.activeEditor;
83 ed.windowManager.bookmark = ed.selection.getBookmark('simple');
84 ed.execCommand("WP_Gallery");
87 dellButton = DOM.add('wp_gallerybtns', 'img', {
88 src : t.url+'/img/delete.png',
92 title : ed.getLang('wordpress.delgallery')
95 tinymce.dom.Event.add(dellButton, 'mousedown', function(e) {
96 var ed = tinyMCE.activeEditor, el = ed.selection.getNode();
98 if ( el.nodeName == 'IMG' && ed.dom.hasClass(el, 'wpGallery') ) {
101 ed.execCommand('mceRepaint');
107 getInfo : function() {
109 longname : 'Gallery Settings',
110 author : 'WordPress',
111 authorurl : 'http://wordpress.org',
118 tinymce.PluginManager.add('wpgallery', tinymce.plugins.wpGallery);