]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/tinymce/plugins/wpgallery/editor_plugin_src.js
WordPress 3.5-scripts
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / plugins / wpgallery / editor_plugin_src.js
index 9b2d028098e2627460aa1e07f73cb469f08fed2a..99434628e56921cd363238fa5d4fc58764c81db4 100644 (file)
@@ -6,25 +6,55 @@
                        var t = this;
 
                        t.url = url;
+                       t.editor = ed;
                        t._createButtons();
 
                        // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
                        ed.addCommand('WP_Gallery', function() {
-                               var el = ed.selection.getNode(), post_id, vp = tinymce.DOM.getViewPort(),
-                                       H = vp.h - 80, W = ( 640 < vp.w ) ? 640 : vp.w;
+                               if ( tinymce.isIE )
+                                       ed.selection.moveToBookmark( ed.wpGalleryBookmark );
 
-                               if ( el.nodeName != 'IMG' ) return;
-                               if ( ed.dom.getAttrib(el, 'class').indexOf('wpGallery') == -1 ) return;
+                               var el = ed.selection.getNode(),
+                                       gallery = wp.media.gallery,
+                                       frame;
 
-                               post_id = tinymce.DOM.get('post_ID').value;
-                               tb_show('', tinymce.documentBaseURL + 'media-upload.php?post_id='+post_id+'&tab=gallery&TB_iframe=true&width='+W+'&height='+H);
+                               // Check if the `wp.media.gallery` API exists.
+                               if ( typeof wp === 'undefined' || ! wp.media || ! wp.media.gallery )
+                                       return;
 
-                               tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
+                               // Make sure we've selected a gallery node.
+                               if ( el.nodeName != 'IMG' || ed.dom.getAttrib(el, 'class').indexOf('wpGallery') == -1 )
+                                       return;
+
+                               frame = gallery.edit( '[' + ed.dom.getAttrib( el, 'title' ) + ']' );
+
+                               frame.state('gallery-edit').on( 'update', function( selection ) {
+                                       var shortcode = gallery.shortcode( selection ).string().slice( 1, -1 );
+                                       ed.dom.setAttrib( el, 'title', shortcode );
+                               });
+                       });
+
+                       ed.onInit.add(function(ed) {
+                               // iOS6 doesn't show the buttons properly on click, show them on 'touchstart'
+                               if ( 'ontouchstart' in window ) {
+                                       ed.dom.events.add(ed.getBody(), 'touchstart', function(e){
+                                               var target = e.target;
+
+                                               if ( target.nodeName == 'IMG' && ed.dom.hasClass(target, 'wpGallery') ) {
+                                                       ed.selection.select(target);
+                                                       ed.dom.events.cancel(e);
+                                                       ed.plugins.wordpress._hideButtons();
+                                                       ed.plugins.wordpress._showButtons(target, 'wp_gallerybtns');
+                                               }
+                                       });
+                               }
                        });
 
                        ed.onMouseDown.add(function(ed, e) {
-                               if ( e.target.nodeName == 'IMG' && ed.dom.hasClass(e.target, 'wpGallery') )
+                               if ( e.target.nodeName == 'IMG' && ed.dom.hasClass(e.target, 'wpGallery') ) {
+                                       ed.plugins.wordpress._hideButtons();
                                        ed.plugins.wordpress._showButtons(e.target, 'wp_gallerybtns');
+                               }
                        });
 
                        ed.onBeforeSetContent.add(function(ed, o) {
                },
 
                _createButtons : function() {
-                       var t = this, ed = tinyMCE.activeEditor, DOM = tinymce.DOM, editButton, dellButton;
+                       var t = this, ed = tinymce.activeEditor, DOM = tinymce.DOM, editButton, dellButton, isRetina;
 
-                       DOM.remove('wp_gallerybtns');
+                       if ( DOM.get('wp_gallerybtns') )
+                               return;
+
+                       isRetina = ( window.devicePixelRatio && window.devicePixelRatio > 1 ) || // WebKit, Opera
+                               ( window.matchMedia && window.matchMedia('(min-resolution:130dpi)').matches ); // Firefox, IE10, Opera
 
                        DOM.add(document.body, 'div', {
                                id : 'wp_gallerybtns',
                        });
 
                        editButton = DOM.add('wp_gallerybtns', 'img', {
-                               src : t.url+'/img/edit.png',
+                               src : isRetina ? t.url+'/img/edit-2x.png' : t.url+'/img/edit.png',
                                id : 'wp_editgallery',
                                width : '24',
                                height : '24',
                        });
 
                        tinymce.dom.Event.add(editButton, 'mousedown', function(e) {
-                               var ed = tinyMCE.activeEditor;
-                               ed.windowManager.bookmark = ed.selection.getBookmark('simple');
+                               var ed = tinymce.activeEditor;
+                               ed.wpGalleryBookmark = ed.selection.getBookmark('simple');
                                ed.execCommand("WP_Gallery");
+                               ed.plugins.wordpress._hideButtons();
                        });
 
                        dellButton = DOM.add('wp_gallerybtns', 'img', {
-                               src : t.url+'/img/delete.png',
+                               src : isRetina ? t.url+'/img/delete-2x.png' : t.url+'/img/delete.png',
                                id : 'wp_delgallery',
                                width : '24',
                                height : '24',
                        });
 
                        tinymce.dom.Event.add(dellButton, 'mousedown', function(e) {
-                               var ed = tinyMCE.activeEditor, el = ed.selection.getNode();
+                               var ed = tinymce.activeEditor, el = ed.selection.getNode();
 
                                if ( el.nodeName == 'IMG' && ed.dom.hasClass(el, 'wpGallery') ) {
                                        ed.dom.remove(el);
 
                                        ed.execCommand('mceRepaint');
-                                       return false;
+                                       ed.dom.events.cancel(e);
                                }
+
+                               ed.plugins.wordpress._hideButtons();
                        });
                },