]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/js/tinymce/plugins/wpgallery/editor_plugin.dev.js
Wordpress 2.8
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / plugins / wpgallery / editor_plugin.dev.js
1
2 (function() {
3         tinymce.create('tinymce.plugins.wpGallery', {
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_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;
14
15                                 if ( el.nodeName != 'IMG' ) return;
16                                 if ( ed.dom.getAttrib(el, 'class').indexOf('wpGallery') == -1 ) return;
17
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);
20
21                                 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
22                         });
23
24                         ed.onInit.add(function(ed) {
25                                 tinymce.dom.Event.add(ed.getWin(), 'scroll', function(e) {
26                                         ed.plugins.wpgallery.hideButtons();
27                                 });
28                         });
29
30                         ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
31                                 ed.plugins.wpgallery.hideButtons();
32                         });
33
34                         ed.onSaveContent.add(function(ed, o) {
35                                 ed.plugins.wpgallery.hideButtons();
36                         });
37
38                         ed.onMouseUp.add(function(ed, e) {
39                                 if ( tinymce.isOpera ) {
40                                         if ( e.target.nodeName == 'IMG' )
41                                                 ed.plugins.wpgallery.showButtons(e.target);
42                                 }
43
44                         });
45
46                         ed.onMouseDown.add(function(ed, e) {
47                                 if ( tinymce.isOpera || e.target.nodeName != 'IMG' ) {
48                                         t.hideButtons();
49                                         return;
50                                 }
51                                 ed.plugins.wpgallery.showButtons(e.target);
52                         });
53
54                         ed.onBeforeSetContent.add(function(ed, o) {
55                                 o.content = t._do_gallery(o.content);
56                         });
57
58                         ed.onPostProcess.add(function(ed, o) {
59                                 if (o.get)
60                                         o.content = t._get_gallery(o.content);
61                         });
62                 },
63
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)+'" />';
67                         });
68                 },
69
70                 _get_gallery : function(co) {
71
72                         function getAttr(s, n) {
73                                 n = new RegExp(n + '=\"([^\"]+)\"', 'g').exec(s);
74                                 return n ? tinymce.DOM.decode(n[1]) : '';
75                         };
76
77                         return co.replace(/(?:<p[^>]*>)*(<img[^>]+>)(?:<\/p>)*/g, function(a,im) {
78                                 var cls = getAttr(im, 'class');
79
80                                 if ( cls.indexOf('wpGallery') != -1 )
81                                         return '<p>['+tinymce.trim(getAttr(im, 'title'))+']</p>';
82
83                                 return a;
84                         });
85                 },
86
87                 showButtons : function(n) {
88                         var t = this, ed = tinyMCE.activeEditor, p1, p2, vp, DOM = tinymce.DOM, X, Y;
89
90                         if (ed.dom.getAttrib(n, 'class').indexOf('wpGallery') == -1)
91                                 return;
92
93                         vp = ed.dom.getViewPort(ed.getWin());
94                         p1 = DOM.getPos(ed.getContentAreaContainer());
95                         p2 = ed.dom.getPos(n);
96
97                         X = Math.max(p2.x - vp.x, 0) + p1.x;
98                         Y = Math.max(p2.y - vp.y, 0) + p1.y;
99
100                         DOM.setStyles('wp_gallerybtns', {
101                                 'top' : Y+5+'px',
102                                 'left' : X+5+'px',
103                                 'display' : 'block'
104                         });
105
106                         t.btnsTout = window.setTimeout( function(){ed.plugins.wpgallery.hideButtons();}, 5000 );
107                 },
108
109                 hideButtons : function() {
110                         if ( tinymce.DOM.isHidden('wp_gallerybtns') ) return;
111
112                         tinymce.DOM.hide('wp_gallerybtns');
113                         window.clearTimeout(this.btnsTout);
114                 },
115
116                 _createButtons : function() {
117                         var t = this, ed = tinyMCE.activeEditor, DOM = tinymce.DOM, wp_gallerybtns, wp_editgallery, wp_delgallery;
118
119                         DOM.remove('wp_gallerybtns');
120
121                         wp_gallerybtns = DOM.add(document.body, 'div', {
122                                 id : 'wp_gallerybtns',
123                                 style : 'display:none;'
124                         });
125
126                         wp_editgallery = DOM.add('wp_gallerybtns', 'img', {
127                                 src : t.url+'/img/edit.png',
128                                 id : 'wp_editgallery',
129                                 width : '24',
130                                 height : '24',
131                                 title : ed.getLang('wordpress.editgallery')
132                         });
133
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';
139                         };
140
141                         wp_delgallery = DOM.add('wp_gallerybtns', 'img', {
142                                 src : t.url+'/img/delete.png',
143                                 id : 'wp_delgallery',
144                                 width : '24',
145                                 height : '24',
146                                 title : ed.getLang('wordpress.delgallery')
147                         });
148
149                         wp_delgallery.onmousedown = function(e) {
150                                 var ed = tinyMCE.activeEditor, el = ed.selection.getNode();
151
152                                 if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('wpGallery') != -1 ) {
153                                         ed.dom.remove(el);
154
155                                         this.parentNode.style.display = 'none';
156                                         ed.execCommand('mceRepaint');
157                                         return false;
158                                 }
159                         };
160                 },
161
162                 getInfo : function() {
163                         return {
164                                 longname : 'Gallery Settings',
165                                 author : 'WordPress',
166                                 authorurl : 'http://wordpress.org',
167                                 infourl : '',
168                                 version : "1.0"
169                         };
170                 }
171         });
172
173         tinymce.PluginManager.add('wpgallery', tinymce.plugins.wpGallery);
174 })();