From fc6ffd2a83ad0f4aecf13211e5ea006dc3049f6c Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 26 Feb 2015 00:30:35 +0000 Subject: [PATCH] TinyMCE: wpView improvements: remove the (obsolete) get/setViewText methods. Update stopping/pausing of multiple ME media players. Props iseulde. See #31412. git-svn-id: https://develop.svn.wordpress.org/trunk@31548 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/mce-view.js | 20 +++++----- .../js/tinymce/plugins/wpview/plugin.js | 37 +------------------ 2 files changed, 11 insertions(+), 46 deletions(-) diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index d7775ea4b8..fc6284fd3e 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/wp-includes/js/mce-view.js @@ -651,7 +651,7 @@ window.wp = window.wp || {}; var media = wp.media[ this.type ], frame = media.edit( text ); - this.stopPlayers && this.stopPlayers(); + this.pausePlayers && this.pausePlayers(); _.each( this.state, function( state ) { frame.state( state ).on( 'update', function( selection ) { @@ -728,7 +728,7 @@ window.wp = window.wp || {}; self.render(); } ) .fail( function( response ) { - if ( self.type === 'embedURL' ) { + if ( self.url ) { self.removeMarkers(); } else { self.setError( response.message || response.statusText, 'admin-media' ); @@ -737,19 +737,19 @@ window.wp = window.wp || {}; this.getEditors( function( editor ) { editor.on( 'wpview-selected', function() { - self.stopPlayers(); + self.pausePlayers(); } ); } ); }, - stopPlayers: function( remove ) { + pausePlayers: function() { this.getNodes( function( editor, node, content ) { var win = $( 'iframe.wpview-sandbox', content ).get( 0 ); if ( win && ( win = win.contentWindow ) && win.mejs ) { _.each( win.mejs.players, function( player ) { try { - player[ remove ? 'remove' : 'pause' ](); + player.pause(); } catch ( e ) {} } ); } @@ -762,10 +762,10 @@ window.wp = window.wp || {}; edit: function( text, update ) { var media = wp.media.embed, - isURL = 'embedURL' === this.type, - frame = media.edit( text, isURL ); + frame = media.edit( text, !! this.url ), + self = this; - this.stopPlayers(); + this.pausePlayers(); frame.state( 'embed' ).props.on( 'change:url', function( model, url ) { if ( url ) { @@ -774,7 +774,7 @@ window.wp = window.wp || {}; } ); frame.state( 'embed' ).on( 'select', function() { - if ( isURL ) { + if ( self.url ) { update( frame.state( 'embed' ).metadata.url ); } else { update( media.shortcode( frame.state( 'embed' ).metadata ).string() ); @@ -808,7 +808,7 @@ window.wp = window.wp || {}; views.register( 'embedURL', _.extend( {}, embed, { match: function( content ) { var re = /(^|

)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi, - match = re.exec( tinymce.trim( content ) ); + match = re.exec( content ); if ( match ) { return { diff --git a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js index 2810a52be6..78b52cb19b 100644 --- a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -34,37 +34,6 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { return false; } - /** - * Get the text/shortcode string for a view. - * - * @param view The view wrapper's node - * @returns string The text/shoercode string of the view - */ - function getViewText( view ) { - if ( view = getView( view ) ) { - return window.decodeURIComponent( editor.dom.getAttrib( view, 'data-wpview-text' ) || '' ); - } - - return ''; - } - - /** - * Set the view's original text/shortcode string - * - * @param view The view wrapper's HTML id or node - * @param text The text string to be set - */ - function setViewText( view, text ) { - view = getView( view ); - - if ( view ) { - editor.dom.setAttrib( view, 'data-wpview-text', window.encodeURIComponent( text || '' ) ); - return true; - } - - return false; - } - function _stop( event ) { event.stopPropagation(); } @@ -138,7 +107,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { clipboard = dom.create( 'div', { 'class': 'wpview-clipboard', 'contenteditable': 'true' - }, getViewText( viewNode ) ); + }, decodeURIComponent( editor.dom.getAttrib( viewNode, 'data-wpview-text' ) ) ); editor.dom.select( '.wpview-body', viewNode )[0].appendChild( clipboard ); @@ -197,8 +166,6 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { // Check if the `wp.mce` API exists. if ( typeof wp === 'undefined' || ! wp.mce ) { return { - getViewText: _noop, - setViewText: _noop, getView: _noop }; } @@ -721,8 +688,6 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { }); return { - getViewText: getViewText, - setViewText: setViewText, getView: getView }; });