From b799bd8e3385373a823df72f472a23a501f694e2 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Wed, 25 Feb 2015 23:13:25 +0000 Subject: [PATCH] TinyMCE: wpView improvements: - Better structure, simpler "view" registration, better extensibility. - Better inline documentation. - Don't show a placeholder for pasted link until we know the link is "embeddable'. And many more improvements. Props iseulde. See #31412. Built from https://develop.svn.wordpress.org/trunk@31546 git-svn-id: http://core.svn.wordpress.org/trunk@31527 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/mce-view.js | 1465 ++++++++--------- wp-includes/js/mce-view.min.js | 2 +- .../js/tinymce/plugins/wpview/plugin.js | 4 +- .../js/tinymce/plugins/wpview/plugin.min.js | 2 +- wp-includes/js/tinymce/wp-tinymce.js.gz | Bin 136243 -> 136250 bytes wp-includes/media-template.php | 2 +- wp-includes/version.php | 4 +- 7 files changed, 703 insertions(+), 776 deletions(-) diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index 3a21e01fa7..d7775ea4b8 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -1,278 +1,37 @@ /* global tinymce */ -/** + +window.wp = window.wp || {}; + +/* + * The TinyMCE view API. + * * Note: this API is "experimental" meaning that it will probably change * in the next few releases based on feedback from 3.9.0. * If you decide to use it, please follow the development closely. + * + * Diagram + * + * |- registered view constructor (type) + * | |- view instance (unique text) + * | | |- editor 1 + * | | | |- view node + * | | | |- view node + * | | | |- ... + * | | |- editor 2 + * | | | |- ... + * | |- view instance + * | | |- ... + * |- registered view + * | |- ... */ - -// Ensure the global `wp` object exists. -window.wp = window.wp || {}; - -( function( $ ) { +( function( window, wp, $ ) { 'use strict'; var views = {}, - instances = {}, - media = wp.media, - mediaWindows = [], - windowIdx = 0, - waitInterval = 50, - viewOptions = ['encodedText']; + instances = {}; - // Create the `wp.mce` object if necessary. wp.mce = wp.mce || {}; - /** - * wp.mce.View - * - * A Backbone-like View constructor intended for use when rendering a TinyMCE View. The main difference is - * that the TinyMCE View is not tied to a particular DOM node. - * - * @param {Object} [options={}] - */ - wp.mce.View = function( options ) { - options = options || {}; - this.type = options.type; - _.extend( this, _.pick( options, viewOptions ) ); - this.initialize.apply( this, arguments ); - }; - - _.extend( wp.mce.View.prototype, { - initialize: function() {}, - getHtml: function() { - return ''; - }, - loadingPlaceholder: function() { - return '' + - '
' + - '
' + - '
' + - '
'; - }, - render: function( force ) { - if ( force || ! this.rendered() ) { - this.unbind(); - - this.setContent( - '

\u00a0

' + - '
' + - '
' + - ( _.isFunction( views[ this.type ].edit ) ? '
' : '' ) + - '
' + - '
' + - '
' + - ( this.getHtml() || this.loadingPlaceholder() ) + - '
' + - ( this.overlay ? '
' : '' ) + - '
' + - '

\u00a0

', - 'wrap' - ); - - $( this ).trigger( 'ready' ); - - this.rendered( true ); - } - }, - unbind: function() {}, - getEditors: function( callback ) { - var editors = []; - - _.each( tinymce.editors, function( editor ) { - if ( editor.plugins.wpview ) { - if ( callback ) { - callback( editor ); - } - - editors.push( editor ); - } - }, this ); - - return editors; - }, - getNodes: function( callback ) { - var nodes = [], - self = this; - - this.getEditors( function( editor ) { - $( editor.getBody() ) - .find( '[data-wpview-text="' + self.encodedText + '"]' ) - .each( function ( i, node ) { - if ( callback ) { - callback( editor, node, $( node ).find( '.wpview-content' ).get( 0 ) ); - } - - nodes.push( node ); - } ); - } ); - - return nodes; - }, - setContent: function( html, option ) { - this.getNodes( function ( editor, node, content ) { - var el = ( option === 'wrap' || option === 'replace' ) ? node : content, - insert = html; - - if ( _.isString( insert ) ) { - insert = editor.dom.createFragment( insert ); - } - - if ( option === 'replace' ) { - editor.dom.replace( insert, el ); - } else { - el.innerHTML = ''; - el.appendChild( insert ); - } - } ); - }, - /* jshint scripturl: true */ - setIframes: function ( head, body ) { - var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver, - importStyles = this.type === 'video' || this.type === 'audio' || this.type === 'playlist'; - - if ( head || body.indexOf( ' Visual. - setTimeout( function() { - iframe = dom.add( content, 'iframe', { - src: tinymce.Env.ie ? 'javascript:""' : '', - frameBorder: '0', - allowTransparency: 'true', - scrolling: 'no', - 'class': 'wpview-sandbox', - style: { - width: '100%', - display: 'block' - } - } ); - - iframeDoc = iframe.contentWindow.document; - - iframeDoc.open(); - iframeDoc.write( - '' + - '' + - '' + - '' + - head + - styles + - '' + - '' + - '' + - body + - '' + - '' - ); - iframeDoc.close(); - - resize = function() { - var $iframe, iframeDocHeight; - - // Make sure the iframe still exists. - if ( iframe.contentWindow ) { - $iframe = $( iframe ); - iframeDocHeight = $( iframeDoc.body ).height(); - - if ( $iframe.height() !== iframeDocHeight ) { - $iframe.height( iframeDocHeight ); - editor.nodeChanged(); - } - } - }; - - if ( MutationObserver ) { - new MutationObserver( _.debounce( function() { - resize(); - }, 100 ) ) - .observe( iframeDoc.body, { - attributes: true, - childList: true, - subtree: true - } ); - } else { - for ( i = 1; i < 6; i++ ) { - setTimeout( resize, i * 700 ); - } - } - - if ( importStyles ) { - editor.on( 'wp-body-class-change', function() { - iframeDoc.body.className = editor.getBody().className; - }); - } - }, waitInterval ); - }); - } else { - this.setContent( body ); - } - }, - setError: function( message, dashicon ) { - this.setContent( - '
' + - '
' + - '

' + message + '

' + - '
' - ); - }, - rendered: function( value ) { - var notRendered; - - this.getNodes( function( editor, node ) { - if ( value != null ) { - $( node ).data( 'rendered', value === true ); - } else { - notRendered = notRendered || ! $( node ).data( 'rendered' ); - } - } ); - - return ! notRendered; - } - } ); - - // take advantage of the Backbone extend method - wp.mce.View.extend = Backbone.View.extend; - /** * wp.mce.views * @@ -283,67 +42,36 @@ window.wp = window.wp || {}; wp.mce.views = { /** - * wp.mce.views.register( type, view ) - * - * Registers a new TinyMCE view. - * - * @param type - * @param constructor + * Registers a new view type. * + * @param {String} type The view type. + * @param {Object} extend An object to extend wp.mce.View.prototype with. */ - register: function( type, constructor ) { - var defaultConstructor = { - type: type, - View: {}, - toView: function( content ) { - var match = wp.shortcode.next( this.type, content ); - - if ( ! match ) { - return; - } - - return { - index: match.index, - content: match.content, - options: { - shortcode: match.shortcode - } - }; - } - }; - - constructor = _.defaults( constructor, defaultConstructor ); - constructor.View = wp.mce.View.extend( constructor.View ); - - views[ type ] = constructor; + register: function( type, extend ) { + views[ type ] = wp.mce.View.extend( _.extend( extend, { type: type } ) ); }, /** - * wp.mce.views.get( id ) + * Unregisters a view type. * - * Returns a TinyMCE view constructor. - * - * @param type - */ - get: function( type ) { - return views[ type ]; - }, - - /** - * wp.mce.views.unregister( type ) - * - * Unregisters a TinyMCE view. - * - * @param type + * @param {String} type The view type. */ unregister: function( type ) { delete views[ type ]; }, /** - * wp.mce.views.unbind( editor ) + * Returns the settings of a view type. * - * The editor DOM is being rebuilt, run cleanup. + * @param {String} type The view type. + */ + get: function( type ) { + return views[ type ]; + }, + + /** + * Unbinds all view nodes. + * Runs before removing all view nodes from the DOM. */ unbind: function() { _.each( instances, function( instance ) { @@ -352,18 +80,18 @@ window.wp = window.wp || {}; }, /** - * toViews( content ) - * Scans a `content` string for each view's pattern, replacing any - * matches with wrapper elements, and creates a new instance for - * every match, which triggers the related data to be fetched. + * Scans a given string for each view's pattern, + * replacing any matches with markers, + * and creates a new instance for every match. * - * @param content + * @param {String} content The string to scan. */ - toViews: function( content ) { + setMarkers: function( content ) { var pieces = [ { content: content } ], + self = this, current; - _.each( views, function( view, viewType ) { + _.each( views, function( view, type ) { current = pieces.slice(); pieces = []; @@ -379,110 +107,72 @@ window.wp = window.wp || {}; // Iterate through the string progressively matching views // and slicing the string as we go. - while ( remaining && (result = view.toView( remaining )) ) { + while ( remaining && ( result = view.prototype.match( remaining ) ) ) { // Any text before the match becomes an unprocessed piece. if ( result.index ) { - pieces.push({ content: remaining.substring( 0, result.index ) }); + pieces.push( { content: remaining.substring( 0, result.index ) } ); } + self.createInstance( type, result.content, result.options ); + // Add the processed piece for the match. - pieces.push({ - content: wp.mce.views.toView( viewType, result.content, result.options ), + pieces.push( { + content: '

' + result.content + '

', processed: true - }); + } ); // Update the remaining content. remaining = remaining.slice( result.index + result.content.length ); } - // There are no additional matches. If any content remains, - // add it as an unprocessed piece. + // There are no additional matches. + // If any content remains, add it as an unprocessed piece. if ( remaining ) { - pieces.push({ content: remaining }); + pieces.push( { content: remaining } ); } - }); - }); + } ); + } ); - return _.pluck( pieces, 'content' ).join(''); + return _.pluck( pieces, 'content' ).join( '' ); }, /** - * Create a placeholder for a particular view type - * - * @param viewType - * @param text - * @param options + * Create a view instance. * + * @param {String} type The view type. + * @param {String} text The textual representation of the view. + * @param {Object} options Options. */ - toView: function( viewType, text, options ) { - var view = wp.mce.views.get( viewType ), - encodedText = window.encodeURIComponent( text ), - instance, viewOptions; + createInstance: function( type, text, options ) { + var View = this.get( type ), + encodedText = encodeURIComponent( text ), + instance = this.getInstance( encodedText ); - - if ( ! view ) { - return text; + if ( instance ) { + return instance; } - if ( ! wp.mce.views.getInstance( encodedText ) ) { - viewOptions = options; - viewOptions.type = viewType; - viewOptions.encodedText = encodedText; - instance = new view.View( viewOptions ); - instances[ encodedText ] = instance; - } + options = _.extend( options || {}, { + text: text, + encodedText: encodedText + } ); - return wp.html.string({ - tag: 'div', - - attrs: { - 'class': 'wpview-wrap', - 'data-wpview-text': encodedText, - 'data-wpview-type': viewType - }, - - content: '\u00a0' - }); + return instances[ encodedText ] = new View( options ); }, /** - * Refresh views after an update is made + * Get a view instance. * - * @param view {object} being refreshed - * @param text {string} textual representation of the view - * @param force {Boolean} whether to force rendering + * @param {String} text The textual representation of the view. */ - refreshView: function( view, text, force ) { - var encodedText = window.encodeURIComponent( text ), - viewOptions, - result, instance; - - instance = wp.mce.views.getInstance( encodedText ); - - if ( ! instance ) { - result = view.toView( text ); - viewOptions = result.options; - viewOptions.type = view.type; - viewOptions.encodedText = encodedText; - instance = new view.View( viewOptions ); - instances[ encodedText ] = instance; - } - - instance.render( force ); - }, - - getInstance: function( encodedText ) { - return instances[ encodedText ]; + getInstance: function( text ) { + return instances[ encodeURIComponent( text ) ]; }, /** - * render( scope ) + * Renders all view nodes that are not yet rendered. * - * Renders any view instances inside a DOM node `scope`. - * - * View instances are detected by the presence of wrapper elements. - * To generate wrapper elements, pass your content through - * `wp.mce.view.toViews( content )`. + * @param {Boolean} force Rerender all view nodes. */ render: function( force ) { _.each( instances, function( instance ) { @@ -490,408 +180,645 @@ window.wp = window.wp || {}; } ); }, - edit: function( node ) { - var viewType = $( node ).data('wpview-type'), - view = wp.mce.views.get( viewType ); + /** + * Update the text of a given view node. + * + * @param {String} text The new text. + * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in. + * @param {HTMLElement} node The view node to update. + */ + update: function( text, editor, node ) { + var oldText = decodeURIComponent( $( node ).data( 'wpview-text' ) ), + instance = this.getInstance( oldText ); - if ( view ) { - view.edit( node ); - } - } - }; - - wp.mce.views.register( 'gallery', { - View: { - template: media.template( 'editor-gallery' ), - - // The fallback post ID to use as a parent for galleries that don't - // specify the `ids` or `include` parameters. - // - // Uses the hidden input on the edit posts page by default. - postID: $('#post_ID').val(), - - initialize: function( options ) { - this.shortcode = options.shortcode; - this.fetch(); - }, - - fetch: function() { - var self = this; - - this.attachments = wp.media.gallery.attachments( this.shortcode, this.postID ); - this.dfd = this.attachments.more().done( function() { - self.render( true ); - } ); - }, - - getHtml: function() { - var attrs = this.shortcode.attrs.named, - attachments = false, - options; - - // Don't render errors while still fetching attachments - if ( this.dfd && 'pending' === this.dfd.state() && ! this.attachments.length ) { - return ''; - } - - if ( this.attachments.length ) { - attachments = this.attachments.toJSON(); - - _.each( attachments, function( attachment ) { - if ( attachment.sizes ) { - if ( attrs.size && attachment.sizes[ attrs.size ] ) { - attachment.thumbnail = attachment.sizes[ attrs.size ]; - } else if ( attachment.sizes.thumbnail ) { - attachment.thumbnail = attachment.sizes.thumbnail; - } else if ( attachment.sizes.full ) { - attachment.thumbnail = attachment.sizes.full; - } - } - } ); - } - - options = { - attachments: attachments, - columns: attrs.columns ? parseInt( attrs.columns, 10 ) : wp.media.galleryDefaults.columns - }; - - return this.template( options ); - } - }, - - edit: function( node ) { - var gallery = wp.media.gallery, - self = this, - frame, data; - - data = window.decodeURIComponent( $( node ).attr('data-wpview-text') ); - frame = gallery.edit( data ); - - frame.state('gallery-edit').on( 'update', function( selection ) { - var shortcode = gallery.shortcode( selection ).string(); - $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) ); - wp.mce.views.refreshView( self, shortcode, true ); - }); - - frame.on( 'close', function() { - frame.detach(); - }); - } - } ); - - /** - * These are base methods that are shared by the audio and video shortcode's MCE controller. - * - * @mixin - */ - wp.mce.av = { - View: { - overlay: true, - - action: 'parse-media-shortcode', - - initialize: function( options ) { - var self = this; - - this.shortcode = options.shortcode; - - _.bindAll( this, 'setIframes', 'setNodes', 'fetch', 'stopPlayers' ); - $( this ).on( 'ready', this.setNodes ); - - $( document ).on( 'media:edit', this.stopPlayers ); - - this.fetch(); - - this.getEditors( function( editor ) { - editor.on( 'hide', function () { - mediaWindows = []; - windowIdx = 0; - self.stopPlayers(); - } ); - }); - }, - - pauseOtherWindows: function ( win ) { - _.each( mediaWindows, function ( mediaWindow ) { - if ( mediaWindow.sandboxId !== win.sandboxId ) { - _.each( mediaWindow.mejs.players, function ( player ) { - player.pause(); - } ); - } - } ); - }, - - iframeLoaded: function (win) { - return _.bind( function () { - var callback; - if ( ! win.mejs || _.isEmpty( win.mejs.players ) ) { - return; - } - - win.sandboxId = windowIdx; - windowIdx++; - mediaWindows.push( win ); - - callback = _.bind( function () { - this.pauseOtherWindows( win ); - }, this ); - - if ( ! _.isEmpty( win.mejs.MediaPluginBridge.pluginMediaElements ) ) { - _.each( win.mejs.MediaPluginBridge.pluginMediaElements, function ( mediaElement ) { - mediaElement.addEventListener( 'play', callback ); - } ); - } - - _.each( win.mejs.players, function ( player ) { - $( player.node ).on( 'play', callback ); - }, this ); - }, this ); - }, - - listenToSandboxes: function () { - _.each( this.getNodes(), function ( node ) { - var win, iframe = $( '.wpview-sandbox', node ).get( 0 ); - if ( iframe && ( win = iframe.contentWindow ) ) { - $( win ).load( _.bind( this.iframeLoaded( win ), this ) ); - } - }, this ); - }, - - deferredListen: function () { - window.setTimeout( _.bind( this.listenToSandboxes, this ), this.getNodes().length * waitInterval ); - }, - - setNodes: function () { - if ( this.parsed ) { - this.setIframes( this.parsed.head, this.parsed.body ); - this.deferredListen(); - } else { - this.fail(); - } - }, - - fetch: function () { - var self = this; - - wp.ajax.send( this.action, { - data: { - post_ID: $( '#post_ID' ).val() || 0, - type: this.shortcode.tag, - shortcode: this.shortcode.string() - } - } ) - .done( function( response ) { - if ( response ) { - self.parsed = response; - self.setIframes( response.head, response.body ); - self.deferredListen(); - } else { - self.fail( true ); - } - } ) - .fail( function( response ) { - self.fail( response || true ); - } ); - }, - - fail: function( error ) { - if ( ! this.error ) { - if ( error ) { - this.error = error; - } else { - return; - } - } - - if ( this.error.message ) { - if ( ( this.error.type === 'not-embeddable' && this.type === 'embed' ) || this.error.type === 'not-ssl' || - this.error.type === 'no-items' ) { - - this.setError( this.error.message, 'admin-media' ); - } else { - this.setContent( '

' + this.original + '

', 'replace' ); - } - } else if ( this.error.statusText ) { - this.setError( this.error.statusText, 'admin-media' ); - } else if ( this.original ) { - this.setContent( '

' + this.original + '

', 'replace' ); - } - }, - - stopPlayers: function( remove ) { - var rem = remove === 'remove'; - - this.getNodes( function( editor, node, content ) { - var p, win, - iframe = $( 'iframe.wpview-sandbox', content ).get(0); - - if ( iframe && ( win = iframe.contentWindow ) && win.mejs ) { - // Sometimes ME.js may show a "Download File" placeholder and player.remove() doesn't exist there. - try { - for ( p in win.mejs.players ) { - win.mejs.players[p].pause(); - - if ( rem ) { - win.mejs.players[p].remove(); - } - } - } catch( er ) {} - } - }); - }, - - unbind: function() { - this.stopPlayers( 'remove' ); + if ( instance ) { + instance.update( text, editor, node ); } }, /** - * Called when a TinyMCE view is clicked for editing. - * - Parses the shortcode out of the element's data attribute - * - Calls the `edit` method on the shortcode model - * - Launches the model window - * - Bind's an `update` callback which updates the element's data attribute - * re-renders the view + * Renders any editing interface based on the view type. * - * @param {HTMLElement} node + * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in. + * @param {HTMLElement} node The view node to edit. */ - edit: function( node ) { - var media = wp.media[ this.type ], - self = this, - frame, data, callback; + edit: function( editor, node ) { + var text = decodeURIComponent( $( node ).data( 'wpview-text' ) ), + instance = this.getInstance( text ); - $( document ).trigger( 'media:edit' ); - - data = window.decodeURIComponent( $( node ).attr('data-wpview-text') ); - frame = media.edit( data ); - frame.on( 'close', function() { - frame.detach(); - } ); - - callback = function( selection ) { - var shortcode = wp.media[ self.type ].shortcode( selection ).string(); - $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) ); - wp.mce.views.refreshView( self, shortcode ); - frame.detach(); - }; - if ( _.isArray( self.state ) ) { - _.each( self.state, function (state) { - frame.state( state ).on( 'update', callback ); + if ( instance && instance.edit ) { + instance.edit( text, function( text ) { + instance.update( text, editor, node ); } ); - } else { - frame.state( self.state ).on( 'update', callback ); } - frame.open(); } }; /** - * TinyMCE handler for the video shortcode + * A Backbone-like View constructor intended for use when rendering a TinyMCE View. + * The main difference is that the TinyMCE View is not tied to a particular DOM node. * - * @mixes wp.mce.av + * @param {Object} Options. */ - wp.mce.views.register( 'video', _.extend( {}, wp.mce.av, { - state: 'video-details' - } ) ); - - /** - * TinyMCE handler for the audio shortcode - * - * @mixes wp.mce.av - */ - wp.mce.views.register( 'audio', _.extend( {}, wp.mce.av, { - state: 'audio-details' - } ) ); - - /** - * TinyMCE handler for the playlist shortcode - * - * @mixes wp.mce.av - */ - wp.mce.views.register( 'playlist', _.extend( {}, wp.mce.av, { - state: [ 'playlist-edit', 'video-playlist-edit' ] - } ) ); - - /** - * TinyMCE handler for the embed shortcode - */ - wp.mce.embedMixin = { - View: _.extend( {}, wp.mce.av.View, { - overlay: true, - action: 'parse-embed', - initialize: function( options ) { - this.content = options.content; - this.original = options.url || options.shortcode.string(); - - if ( options.url ) { - this.shortcode = media.embed.shortcode( { - url: options.url - } ); - } else { - this.shortcode = options.shortcode; - } - - _.bindAll( this, 'setIframes', 'setNodes', 'fetch' ); - $( this ).on( 'ready', this.setNodes ); - - this.fetch(); - } - } ), - edit: function( node ) { - var embed = media.embed, - self = this, - frame, - data, - isURL = 'embedURL' === this.type; - - $( document ).trigger( 'media:edit' ); - - data = window.decodeURIComponent( $( node ).attr('data-wpview-text') ); - frame = embed.edit( data, isURL ); - frame.on( 'close', function() { - frame.detach(); - } ); - frame.state( 'embed' ).props.on( 'change:url', function (model, url) { - if ( ! url ) { - return; - } - frame.state( 'embed' ).metadata = model.toJSON(); - } ); - frame.state( 'embed' ).on( 'select', function() { - var shortcode; - - if ( isURL ) { - shortcode = frame.state( 'embed' ).metadata.url; - } else { - shortcode = embed.shortcode( frame.state( 'embed' ).metadata ).string(); - } - $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) ); - wp.mce.views.refreshView( self, shortcode ); - frame.detach(); - } ); - frame.open(); - } + wp.mce.View = function( options ) { + _.extend( this, options ); + this.initialize(); }; - wp.mce.views.register( 'embed', _.extend( {}, wp.mce.embedMixin ) ); + wp.mce.View.extend = Backbone.View.extend; - wp.mce.views.register( 'embedURL', _.extend( {}, wp.mce.embedMixin, { - toView: function( content ) { - var re = /(^|

)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi, - match = re.exec( tinymce.trim( content ) ); + _.extend( wp.mce.View.prototype, { - if ( ! match ) { + /** + * The content. + * + * @type {*} + */ + content: null, + + /** + * Whether or not to display a loader. + * + * @type {Boolean} + */ + loader: true, + + /** + * Runs after the view instance is created. + */ + initialize: function() {}, + + /** + * Retuns the content to render in the view node. + * + * @return {*} + */ + getContent: function() { + return this.content; + }, + + /** + * Renders all view nodes tied to this view instance that are not yet rendered. + * + * @param {Boolean} force Rerender all view nodes tied to this view instance. + */ + render: function( force ) { + // If there's nothing to render an no loader needs to be shown, stop. + if ( ! this.loader && ! this.getContent() ) { return; } - return { - index: match.index + match[1].length, - content: match[2], - options: { - url: match[2] + // We're about to rerender all views of this instance, so unbind rendered views. + force && this.unbind(); + + // Replace any left over markers. + this.replaceMarkers(); + + if ( this.getContent() ) { + this.setContent( this.getContent(), function( editor, node ) { + $( node ).data( 'rendered', true ); + this.bindNodes.apply( this, arguments ); + }, force ? null : false ); + } else { + this.setLoader(); + } + }, + + /** + * Binds a given rendered view node. + * Runs after a view node's content is added to the DOM. + * + * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in. + * @param {HTMLElement} node The view node. + * @param {HTMLElement} contentNode The view's content node. + */ + bindNodes: function( /* editor, node, contentNode */ ) {}, + + /** + * Unbinds all view nodes tied to this view instance. + * Runs before their content is removed from the DOM. + */ + unbind: function() { + this.getNodes( function() { + this.unbindNodes.apply( this, arguments ); + }, true ); + }, + + /** + * Unbinds a given view node. + * Runs before the view node's content is removed from the DOM. + * + * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in. + * @param {HTMLElement} node The view node. + * @param {HTMLElement} contentNode The view's content node. + */ + unbindNodes: function( /* editor, node, contentNode */ ) {}, + + /** + * Gets all the TinyMCE editor instances that support views. + * + * @param {Function} callback A callback. + */ + getEditors: function( callback ) { + _.each( tinymce.editors, function( editor ) { + if ( editor.plugins.wpview ) { + callback.call( this, editor ); } - }; + }, this ); + }, + + /** + * Gets all view nodes tied to this view instance. + * + * @param {Function} callback A callback. + * @param {Boolean} rendered Get (un)rendered view nodes. Optional. + */ + getNodes: function( callback, rendered ) { + this.getEditors( function( editor ) { + var self = this; + + $( editor.getBody() ) + .find( '[data-wpview-text="' + self.encodedText + '"]' ) + .filter( function() { + var data; + + if ( rendered == null ) { + return true; + } + + data = $( this ).data( 'rendered' ) === true; + + return rendered ? data : ! data; + } ) + .each( function() { + callback.call( self, editor, this, $( this ).find( '.wpview-content' ).get( 0 ) ); + } ); + } ); + }, + + /** + * Gets all marker nodes tied to this view instance. + * + * @param {Function} callback A callback. + */ + getMarkers: function( callback ) { + this.getEditors( function( editor ) { + var self = this; + + $( editor.getBody() ) + .find( '[data-wpview-marker="' + this.encodedText + '"]' ) + .each( function() { + callback.call( self, editor, this ); + } ); + } ); + }, + + /** + * Replaces all marker nodes tied to this view instance. + */ + replaceMarkers: function() { + this.getMarkers( function( editor, node ) { + if ( $( node ).text() !== this.text ) { + editor.dom.setAttrib( node, 'data-wpview-marker', null ); + return; + } + + editor.dom.replace( + editor.dom.createFragment( + '

' + + '

\u00a0

' + + '
' + + '
' + + ( this.edit ? '
' : '' ) + + '
' + + '
' + + '
' + + '
' + + '

\u00a0

' + + '
' + ), + node + ); + } ); + }, + + /** + * Removes all marker nodes tied to this view instance. + */ + removeMarkers: function() { + this.getMarkers( function( editor, node ) { + editor.dom.setAttrib( node, 'data-wpview-marker', null ); + } ); + }, + + /** + * Sets the content for all view nodes tied to this view instance. + * + * @param {*} content The content to set. + * @param {Function} callback A callback. Optional. + * @param {Boolean} rendered Only set for (un)rendered nodes. Optional. + */ + setContent: function( content, callback, rendered ) { + if ( _.isObject( content ) && content.body.indexOf( ' Visual. + setTimeout( function() { + iframe = dom.add( content, 'iframe', { + /* jshint scripturl: true */ + src: tinymce.Env.ie ? 'javascript:""' : '', + frameBorder: '0', + allowTransparency: 'true', + scrolling: 'no', + 'class': 'wpview-sandbox', + style: { + width: '100%', + display: 'block' + } + } ); + + dom.add( content, 'div', { 'class': 'wpview-overlay' } ); + + iframeDoc = iframe.contentWindow.document; + + iframeDoc.open(); + + iframeDoc.write( + '' + + '' + + '' + + '' + + head + + styles + + '' + + '' + + '' + + body + + '' + + '' + ); + + iframeDoc.close(); + + resize = function() { + var $iframe, iframeDocHeight; + + // Make sure the iframe still exists. + if ( iframe.contentWindow ) { + $iframe = $( iframe ); + iframeDocHeight = $( iframeDoc.body ).height(); + + if ( $iframe.height() !== iframeDocHeight ) { + $iframe.height( iframeDocHeight ); + editor.nodeChanged(); + } + } + }; + + if ( MutationObserver ) { + new MutationObserver( _.debounce( function() { + resize(); + }, 100 ) ) + .observe( iframeDoc.body, { + attributes: true, + childList: true, + subtree: true + } ); + } else { + for ( i = 1; i < 6; i++ ) { + setTimeout( resize, i * 700 ); + } + } + + if ( importStyles ) { + editor.on( 'wp-body-class-change', function() { + iframeDoc.body.className = editor.getBody().className; + } ); + } + }, 50 ); + + callback && callback.apply( this, arguments ); + }, rendered ); + }, + + /** + * Sets a loader for all view nodes tied to this view instance. + */ + setLoader: function() { + this.setContent( + '
' + + '
' + + '
' + + '
' + ); + }, + + /** + * Sets an error for all view nodes tied to this view instance. + * + * @param {String} message The error message to set. + * @param {String} dashicon A dashicon ID (optional). {@link https://developer.wordpress.org/resource/dashicons/} + */ + setError: function( message, dashicon ) { + this.setContent( + '
' + + '
' + + '

' + message + '

' + + '
' + ); + }, + + /** + * Tries to find a text match in a given string. + * + * @param {String} content The string to scan. + * + * @return {Object} + */ + match: function( content ) { + var match = wp.shortcode.next( this.type, content ); + + if ( match ) { + return { + index: match.index, + content: match.content, + options: { + shortcode: match.shortcode + } + }; + } + }, + + /** + * Update the text of a given view node. + * + * @param {String} text The new text. + * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in. + * @param {HTMLElement} node The view node to update. + */ + update: function( text, editor, node ) { + $( node ).data( 'rendered', false ); + editor.dom.setAttrib( node, 'data-wpview-text', encodeURIComponent( text ) ); + wp.mce.views.createInstance( this.type, text, this.match( text ).options ).render(); } + } ); +} )( window, window.wp, window.jQuery ); + +/* + * The WordPress core TinyMCE views. + * Views for the gallery, audio, video, playlist and embed shortcodes, + * and a view for embeddable URLs. + */ +( function( window, views, $ ) { + var postID = $( '#post_ID' ).val() || 0, + media, gallery, av, embed; + + media = { + state: [], + + edit: function( text, update ) { + var media = wp.media[ this.type ], + frame = media.edit( text ); + + this.stopPlayers && this.stopPlayers(); + + _.each( this.state, function( state ) { + frame.state( state ).on( 'update', function( selection ) { + update( media.shortcode( selection ).string() ); + } ); + } ); + + frame.on( 'close', function() { + frame.detach(); + } ); + } + }; + + gallery = _.extend( {}, media, { + state: [ 'gallery-edit' ], + template: wp.media.template( 'editor-gallery' ), + + initialize: function() { + var attachments = wp.media.gallery.attachments( this.shortcode, postID ), + attrs = this.shortcode.attrs.named, + self = this; + + attachments.more() + .done( function() { + attachments = attachments.toJSON(); + + _.each( attachments, function( attachment ) { + if ( attachment.sizes ) { + if ( attrs.size && attachment.sizes[ attrs.size ] ) { + attachment.thumbnail = attachment.sizes[ attrs.size ]; + } else if ( attachment.sizes.thumbnail ) { + attachment.thumbnail = attachment.sizes.thumbnail; + } else if ( attachment.sizes.full ) { + attachment.thumbnail = attachment.sizes.full; + } + } + } ); + + self.content = self.template( { + attachments: attachments, + columns: attrs.columns ? parseInt( attrs.columns, 10 ) : wp.media.galleryDefaults.columns + } ); + + self.render(); + } ) + .fail( function( jqXHR, textStatus ) { + self.setError( textStatus ); + } ); + } + } ); + + av = _.extend( {}, media, { + action: 'parse-media-shortcode', + + initialize: function() { + var self = this; + + if ( this.url ) { + this.loader = false; + this.shortcode = wp.media.embed.shortcode( { + url: this.url + } ); + } + + wp.ajax.send( this.action, { + data: { + post_ID: postID, + type: this.shortcode.tag, + shortcode: this.shortcode.string() + } + } ) + .done( function( response ) { + self.content = response; + self.render(); + } ) + .fail( function( response ) { + if ( self.type === 'embedURL' ) { + self.removeMarkers(); + } else { + self.setError( response.message || response.statusText, 'admin-media' ); + } + } ); + + this.getEditors( function( editor ) { + editor.on( 'wpview-selected', function() { + self.stopPlayers(); + } ); + } ); + }, + + stopPlayers: function( remove ) { + 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' ](); + } catch ( e ) {} + } ); + } + } ); + } + } ); + + embed = _.extend( {}, av, { + action: 'parse-embed', + + edit: function( text, update ) { + var media = wp.media.embed, + isURL = 'embedURL' === this.type, + frame = media.edit( text, isURL ); + + this.stopPlayers(); + + frame.state( 'embed' ).props.on( 'change:url', function( model, url ) { + if ( url ) { + frame.state( 'embed' ).metadata = model.toJSON(); + } + } ); + + frame.state( 'embed' ).on( 'select', function() { + if ( isURL ) { + update( frame.state( 'embed' ).metadata.url ); + } else { + update( media.shortcode( frame.state( 'embed' ).metadata ).string() ); + } + } ); + + frame.on( 'close', function() { + frame.detach(); + } ); + + frame.open(); + } + } ); + + views.register( 'gallery', _.extend( {}, gallery ) ); + + views.register( 'audio', _.extend( {}, av, { + state: [ 'audio-details' ] } ) ); -}(jQuery)); + views.register( 'video', _.extend( {}, av, { + state: [ 'video-details' ] + } ) ); + + views.register( 'playlist', _.extend( {}, av, { + state: [ 'playlist-edit', 'video-playlist-edit' ] + } ) ); + + views.register( 'embed', _.extend( {}, embed ) ); + + views.register( 'embedURL', _.extend( {}, embed, { + match: function( content ) { + var re = /(^|

)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi, + match = re.exec( tinymce.trim( content ) ); + + if ( match ) { + return { + index: match.index + match[1].length, + content: match[2], + options: { + url: match[2] + } + }; + } + } + } ) ); +} )( window, window.wp.mce.views, window.jQuery ); diff --git a/wp-includes/js/mce-view.min.js b/wp-includes/js/mce-view.min.js index 6914452ef8..94f7655a75 100644 --- a/wp-includes/js/mce-view.min.js +++ b/wp-includes/js/mce-view.min.js @@ -1 +1 @@ -window.wp=window.wp||{},function(a){"use strict";var b={},c={},d=wp.media,e=[],f=0,g=50,h=["encodedText"];wp.mce=wp.mce||{},wp.mce.View=function(a){a=a||{},this.type=a.type,_.extend(this,_.pick(a,h)),this.initialize.apply(this,arguments)},_.extend(wp.mce.View.prototype,{initialize:function(){},getHtml:function(){return""},loadingPlaceholder:function(){return'

'},render:function(c){(c||!this.rendered())&&(this.unbind(),this.setContent('

 

'+(_.isFunction(b[this.type].edit)?'
':"")+'
'+(this.getHtml()||this.loadingPlaceholder())+"
"+(this.overlay?'
':"")+'

 

',"wrap"),a(this).trigger("ready"),this.rendered(!0))},unbind:function(){},getEditors:function(a){var b=[];return _.each(tinymce.editors,function(c){c.plugins.wpview&&(a&&a(c),b.push(c))},this),b},getNodes:function(b){var c=[],d=this;return this.getEditors(function(e){a(e.getBody()).find('[data-wpview-text="'+d.encodedText+'"]').each(function(d,f){b&&b(e,f,a(f).find(".wpview-content").get(0)),c.push(f)})}),c},setContent:function(a,b){this.getNodes(function(c,d,e){var f="wrap"===b||"replace"===b?d:e,g=a;_.isString(g)&&(g=c.dom.createFragment(g)),"replace"===b?c.dom.replace(g,f):(f.innerHTML="",f.appendChild(g))})},setIframes:function(b,c){var d=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver,e="video"===this.type||"audio"===this.type||"playlist"===this.type;b||-1!==c.indexOf("'+b+o+''+c+""),k.close(),m=function(){var b,c;j.contentWindow&&(b=a(j),c=a(k.body).height(),b.height()!==c&&(b.height(c),f.nodeChanged()))},d)new d(_.debounce(function(){m()},100)).observe(k.body,{attributes:!0,childList:!0,subtree:!0});else for(l=1;6>l;l++)setTimeout(m,700*l);e&&f.on("wp-body-class-change",function(){k.body.className=f.getBody().className})},g)}):this.setContent(c)},setError:function(a,b){this.setContent('

'+a+"

")},rendered:function(b){var c;return this.getNodes(function(d,e){null!=b?a(e).data("rendered",b===!0):c=c||!a(e).data("rendered")}),!c}}),wp.mce.View.extend=Backbone.View.extend,wp.mce.views={register:function(a,c){var d={type:a,View:{},toView:function(a){var b=wp.shortcode.next(this.type,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}}};c=_.defaults(c,d),c.View=wp.mce.View.extend(c.View),b[a]=c},get:function(a){return b[a]},unregister:function(a){delete b[a]},unbind:function(){_.each(c,function(a){a.unbind()})},toViews:function(a){var c,d=[{content:a}];return _.each(b,function(a,b){c=d.slice(),d=[],_.each(c,function(c){var e,f=c.content;if(c.processed)return void d.push(c);for(;f&&(e=a.toView(f));)e.index&&d.push({content:f.substring(0,e.index)}),d.push({content:wp.mce.views.toView(b,e.content,e.options),processed:!0}),f=f.slice(e.index+e.content.length);f&&d.push({content:f})})}),_.pluck(d,"content").join("")},toView:function(a,b,d){var e,f,g=wp.mce.views.get(a),h=window.encodeURIComponent(b);return g?(wp.mce.views.getInstance(h)||(f=d,f.type=a,f.encodedText=h,e=new g.View(f),c[h]=e),wp.html.string({tag:"div",attrs:{"class":"wpview-wrap","data-wpview-text":h,"data-wpview-type":a},content:" "})):b},refreshView:function(a,b,d){var e,f,g,h=window.encodeURIComponent(b);g=wp.mce.views.getInstance(h),g||(f=a.toView(b),e=f.options,e.type=a.type,e.encodedText=h,g=new a.View(e),c[h]=g),g.render(d)},getInstance:function(a){return c[a]},render:function(a){_.each(c,function(b){b.render(a)})},edit:function(b){var c=a(b).data("wpview-type"),d=wp.mce.views.get(c);d&&d.edit(b)}},wp.mce.views.register("gallery",{View:{template:d.template("editor-gallery"),postID:a("#post_ID").val(),initialize:function(a){this.shortcode=a.shortcode,this.fetch()},fetch:function(){var a=this;this.attachments=wp.media.gallery.attachments(this.shortcode,this.postID),this.dfd=this.attachments.more().done(function(){a.render(!0)})},getHtml:function(){var a,b=this.shortcode.attrs.named,c=!1;return this.dfd&&"pending"===this.dfd.state()&&!this.attachments.length?"":(this.attachments.length&&(c=this.attachments.toJSON(),_.each(c,function(a){a.sizes&&(b.size&&a.sizes[b.size]?a.thumbnail=a.sizes[b.size]:a.sizes.thumbnail?a.thumbnail=a.sizes.thumbnail:a.sizes.full&&(a.thumbnail=a.sizes.full))})),a={attachments:c,columns:b.columns?parseInt(b.columns,10):wp.media.galleryDefaults.columns},this.template(a))}},edit:function(b){var c,d,e=wp.media.gallery,f=this;d=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=e.edit(d),c.state("gallery-edit").on("update",function(c){var d=e.shortcode(c).string();a(b).attr("data-wpview-text",window.encodeURIComponent(d)),wp.mce.views.refreshView(f,d,!0)}),c.on("close",function(){c.detach()})}}),wp.mce.av={View:{overlay:!0,action:"parse-media-shortcode",initialize:function(b){var c=this;this.shortcode=b.shortcode,_.bindAll(this,"setIframes","setNodes","fetch","stopPlayers"),a(this).on("ready",this.setNodes),a(document).on("media:edit",this.stopPlayers),this.fetch(),this.getEditors(function(a){a.on("hide",function(){e=[],f=0,c.stopPlayers()})})},pauseOtherWindows:function(a){_.each(e,function(b){b.sandboxId!==a.sandboxId&&_.each(b.mejs.players,function(a){a.pause()})})},iframeLoaded:function(b){return _.bind(function(){var c;b.mejs&&!_.isEmpty(b.mejs.players)&&(b.sandboxId=f,f++,e.push(b),c=_.bind(function(){this.pauseOtherWindows(b)},this),_.isEmpty(b.mejs.MediaPluginBridge.pluginMediaElements)||_.each(b.mejs.MediaPluginBridge.pluginMediaElements,function(a){a.addEventListener("play",c)}),_.each(b.mejs.players,function(b){a(b.node).on("play",c)},this))},this)},listenToSandboxes:function(){_.each(this.getNodes(),function(b){var c,d=a(".wpview-sandbox",b).get(0);d&&(c=d.contentWindow)&&a(c).load(_.bind(this.iframeLoaded(c),this))},this)},deferredListen:function(){window.setTimeout(_.bind(this.listenToSandboxes,this),this.getNodes().length*g)},setNodes:function(){this.parsed?(this.setIframes(this.parsed.head,this.parsed.body),this.deferredListen()):this.fail()},fetch:function(){var b=this;wp.ajax.send(this.action,{data:{post_ID:a("#post_ID").val()||0,type:this.shortcode.tag,shortcode:this.shortcode.string()}}).done(function(a){a?(b.parsed=a,b.setIframes(a.head,a.body),b.deferredListen()):b.fail(!0)}).fail(function(a){b.fail(a||!0)})},fail:function(a){if(!this.error){if(!a)return;this.error=a}this.error.message?"not-embeddable"===this.error.type&&"embed"===this.type||"not-ssl"===this.error.type||"no-items"===this.error.type?this.setError(this.error.message,"admin-media"):this.setContent("

"+this.original+"

","replace"):this.error.statusText?this.setError(this.error.statusText,"admin-media"):this.original&&this.setContent("

"+this.original+"

","replace")},stopPlayers:function(b){var c="remove"===b;this.getNodes(function(b,d,e){var f,g,h=a("iframe.wpview-sandbox",e).get(0);if(h&&(g=h.contentWindow)&&g.mejs)try{for(f in g.mejs.players)g.mejs.players[f].pause(),c&&g.mejs.players[f].remove()}catch(i){}})},unbind:function(){this.stopPlayers("remove")}},edit:function(b){var c,d,e,f=wp.media[this.type],g=this;a(document).trigger("media:edit"),d=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=f.edit(d),c.on("close",function(){c.detach()}),e=function(d){var e=wp.media[g.type].shortcode(d).string();a(b).attr("data-wpview-text",window.encodeURIComponent(e)),wp.mce.views.refreshView(g,e),c.detach()},_.isArray(g.state)?_.each(g.state,function(a){c.state(a).on("update",e)}):c.state(g.state).on("update",e),c.open()}},wp.mce.views.register("video",_.extend({},wp.mce.av,{state:"video-details"})),wp.mce.views.register("audio",_.extend({},wp.mce.av,{state:"audio-details"})),wp.mce.views.register("playlist",_.extend({},wp.mce.av,{state:["playlist-edit","video-playlist-edit"]})),wp.mce.embedMixin={View:_.extend({},wp.mce.av.View,{overlay:!0,action:"parse-embed",initialize:function(b){this.content=b.content,this.original=b.url||b.shortcode.string(),this.shortcode=b.url?d.embed.shortcode({url:b.url}):b.shortcode,_.bindAll(this,"setIframes","setNodes","fetch"),a(this).on("ready",this.setNodes),this.fetch()}}),edit:function(b){var c,e,f=d.embed,g=this,h="embedURL"===this.type;a(document).trigger("media:edit"),e=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=f.edit(e,h),c.on("close",function(){c.detach()}),c.state("embed").props.on("change:url",function(a,b){b&&(c.state("embed").metadata=a.toJSON())}),c.state("embed").on("select",function(){var d;d=h?c.state("embed").metadata.url:f.shortcode(c.state("embed").metadata).string(),a(b).attr("data-wpview-text",window.encodeURIComponent(d)),wp.mce.views.refreshView(g,d),c.detach()}),c.open()}},wp.mce.views.register("embed",_.extend({},wp.mce.embedMixin)),wp.mce.views.register("embedURL",_.extend({},wp.mce.embedMixin,{toView:function(a){var b=/(^|

)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi,c=b.exec(tinymce.trim(a));if(c)return{index:c.index+c[1].length,content:c[2],options:{url:c[2]}}}}))}(jQuery); \ No newline at end of file +window.wp=window.wp||{},function(a,b,c){"use strict";var d={},e={};b.mce=b.mce||{},b.mce.views={register:function(a,c){d[a]=b.mce.View.extend(_.extend(c,{type:a}))},unregister:function(a){delete d[a]},get:function(a){return d[a]},unbind:function(){_.each(e,function(a){a.unbind()})},setMarkers:function(a){var b,c=[{content:a}],e=this;return _.each(d,function(a,d){b=c.slice(),c=[],_.each(b,function(b){var f,g=b.content;if(b.processed)return void c.push(b);for(;g&&(f=a.prototype.match(g));)f.index&&c.push({content:g.substring(0,f.index)}),e.createInstance(d,f.content,f.options),c.push({content:'

'+f.content+"

",processed:!0}),g=g.slice(f.index+f.content.length);g&&c.push({content:g})})}),_.pluck(c,"content").join("")},createInstance:function(a,b,c){var d=this.get(a),f=encodeURIComponent(b),g=this.getInstance(f);return g?g:(c=_.extend(c||{},{text:b,encodedText:f}),e[f]=new d(c))},getInstance:function(a){return e[encodeURIComponent(a)]},render:function(a){_.each(e,function(b){b.render(a)})},update:function(a,b,d){var e=decodeURIComponent(c(d).data("wpview-text")),f=this.getInstance(e);f&&f.update(a,b,d)},edit:function(a,b){var d=decodeURIComponent(c(b).data("wpview-text")),e=this.getInstance(d);e&&e.edit&&e.edit(d,function(c){e.update(c,a,b)})}},b.mce.View=function(a){_.extend(this,a),this.initialize()},b.mce.View.extend=Backbone.View.extend,_.extend(b.mce.View.prototype,{content:null,loader:!0,initialize:function(){},getContent:function(){return this.content},render:function(a){(this.loader||this.getContent())&&(a&&this.unbind(),this.replaceMarkers(),this.getContent()?this.setContent(this.getContent(),function(a,b){c(b).data("rendered",!0),this.bindNodes.apply(this,arguments)},a?null:!1):this.setLoader())},bindNodes:function(){},unbind:function(){this.getNodes(function(){this.unbindNodes.apply(this,arguments)},!0)},unbindNodes:function(){},getEditors:function(a){_.each(tinymce.editors,function(b){b.plugins.wpview&&a.call(this,b)},this)},getNodes:function(a,b){this.getEditors(function(d){var e=this;c(d.getBody()).find('[data-wpview-text="'+e.encodedText+'"]').filter(function(){var a;return null==b?!0:(a=c(this).data("rendered")===!0,b?a:!a)}).each(function(){a.call(e,d,this,c(this).find(".wpview-content").get(0))})})},getMarkers:function(a){this.getEditors(function(b){var d=this;c(b.getBody()).find('[data-wpview-marker="'+this.encodedText+'"]').each(function(){a.call(d,b,this)})})},replaceMarkers:function(){this.getMarkers(function(a,b){return c(b).text()!==this.text?void a.dom.setAttrib(b,"data-wpview-marker",null):void a.dom.replace(a.dom.createFragment('

 

'+(this.edit?'
':"")+'

 

'),b)})},removeMarkers:function(){this.getMarkers(function(a,b){a.dom.setAttrib(b,"data-wpview-marker",null)})},setContent:function(a,b,c){_.isObject(a)&&-1!==a.body.indexOf("'),e.innerHTML="",e.appendChild(_.isString(a)?c.dom.createFragment(a):a),b&&b.apply(this,arguments)},c)},setIframes:function(d,e,f,g){var h=a.MutationObserver||a.WebKitMutationObserver||a.MozMutationObserver,i="video"===this.type||"audio"===this.type||"playlist"===this.type;this.getNodes(function(a,g,j){var k,l,m,n,o=a.dom,p="",q=a.getBody().className||"";j.innerHTML="",d=d||"",i&&(b.mce.views.sandboxStyles?p=b.mce.views.sandboxStyles:(tinymce.each(o.$('link[rel="stylesheet"]',a.getDoc().head),function(a){a.href&&-1===a.href.indexOf("skins/lightgray/content.min.css")&&-1===a.href.indexOf("skins/wordpress/wp-content.css")&&(p+=o.getOuterHTML(a)+"\n")}),b.mce.views.sandboxStyles=p)),setTimeout(function(){if(k=o.add(j,"iframe",{src:tinymce.Env.ie?'javascript:""':"",frameBorder:"0",allowTransparency:"true",scrolling:"no","class":"wpview-sandbox",style:{width:"100%",display:"block"}}),o.add(j,"div",{"class":"wpview-overlay"}),l=k.contentWindow.document,l.open(),l.write(''+d+p+''+e+""),l.close(),n=function(){var b,d;k.contentWindow&&(b=c(k),d=c(l.body).height(),b.height()!==d&&(b.height(d),a.nodeChanged()))},h)new h(_.debounce(function(){n()},100)).observe(l.body,{attributes:!0,childList:!0,subtree:!0});else for(m=1;6>m;m++)setTimeout(n,700*m);i&&a.on("wp-body-class-change",function(){l.body.className=a.getBody().className})},50),f&&f.apply(this,arguments)},g)},setLoader:function(){this.setContent('
')},setError:function(a,b){this.setContent('

'+a+"

")},match:function(a){var c=b.shortcode.next(this.type,a);return c?{index:c.index,content:c.content,options:{shortcode:c.shortcode}}:void 0},update:function(a,d,e){c(e).data("rendered",!1),d.dom.setAttrib(e,"data-wpview-text",encodeURIComponent(a)),b.mce.views.createInstance(this.type,a,this.match(a).options).render()}})}(window,window.wp,window.jQuery),function(a,b,c){var d,e,f,g,h=c("#post_ID").val()||0;d={state:[],edit:function(a,b){var c=wp.media[this.type],d=c.edit(a);this.stopPlayers&&this.stopPlayers(),_.each(this.state,function(a){d.state(a).on("update",function(a){b(c.shortcode(a).string())})}),d.on("close",function(){d.detach()})}},e=_.extend({},d,{state:["gallery-edit"],template:wp.media.template("editor-gallery"),initialize:function(){var a=wp.media.gallery.attachments(this.shortcode,h),b=this.shortcode.attrs.named,c=this;a.more().done(function(){a=a.toJSON(),_.each(a,function(a){a.sizes&&(b.size&&a.sizes[b.size]?a.thumbnail=a.sizes[b.size]:a.sizes.thumbnail?a.thumbnail=a.sizes.thumbnail:a.sizes.full&&(a.thumbnail=a.sizes.full))}),c.content=c.template({attachments:a,columns:b.columns?parseInt(b.columns,10):wp.media.galleryDefaults.columns}),c.render()}).fail(function(a,b){c.setError(b)})}}),f=_.extend({},d,{action:"parse-media-shortcode",initialize:function(){var a=this;this.url&&(this.loader=!1,this.shortcode=wp.media.embed.shortcode({url:this.url})),wp.ajax.send(this.action,{data:{post_ID:h,type:this.shortcode.tag,shortcode:this.shortcode.string()}}).done(function(b){a.content=b,a.render()}).fail(function(b){"embedURL"===a.type?a.removeMarkers():a.setError(b.message||b.statusText,"admin-media")}),this.getEditors(function(b){b.on("wpview-selected",function(){a.stopPlayers()})})},stopPlayers:function(a){this.getNodes(function(b,d,e){var f=c("iframe.wpview-sandbox",e).get(0);f&&(f=f.contentWindow)&&f.mejs&&_.each(f.mejs.players,function(b){try{b[a?"remove":"pause"]()}catch(c){}})})}}),g=_.extend({},f,{action:"parse-embed",edit:function(a,b){var c=wp.media.embed,d="embedURL"===this.type,e=c.edit(a,d);this.stopPlayers(),e.state("embed").props.on("change:url",function(a,b){b&&(e.state("embed").metadata=a.toJSON())}),e.state("embed").on("select",function(){b(d?e.state("embed").metadata.url:c.shortcode(e.state("embed").metadata).string())}),e.on("close",function(){e.detach()}),e.open()}}),b.register("gallery",_.extend({},e)),b.register("audio",_.extend({},f,{state:["audio-details"]})),b.register("video",_.extend({},f,{state:["video-details"]})),b.register("playlist",_.extend({},f,{state:["playlist-edit","video-playlist-edit"]})),b.register("embed",_.extend({},g)),b.register("embedURL",_.extend({},g,{match:function(a){var b=/(^|

)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi,c=b.exec(tinymce.trim(a));return c?{index:c.index+c[1].length,content:c[2],options:{url:c[2]}}:void 0}}))}(window,window.wp.mce.views,window.jQuery); \ No newline at end of file diff --git a/wp-includes/js/tinymce/plugins/wpview/plugin.js b/wp-includes/js/tinymce/plugins/wpview/plugin.js index 2a9d496df0..2810a52be6 100644 --- a/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -237,7 +237,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { return; } - event.content = wp.mce.views.toViews( event.content ); + event.content = wp.mce.views.setMarkers( event.content ); }); // When the editor's content has been updated and the DOM has been @@ -341,7 +341,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { editor.focus(); } - wp.mce.views.edit( view ); + wp.mce.views.edit( editor, view ); return false; } else if ( editor.dom.hasClass( event.target, 'remove' ) ) { removeView( view ); diff --git a/wp-includes/js/tinymce/plugins/wpview/plugin.min.js b/wp-includes/js/tinymce/plugins/wpview/plugin.min.js index 6c6ebb340b..459db66c9a 100644 --- a/wp-includes/js/tinymce/plugins/wpview/plugin.min.js +++ b/wp-includes/js/tinymce/plugins/wpview/plugin.min.js @@ -1 +1 @@ -tinymce.PluginManager.add("wpview",function(a){function b(a){return c(a,"wpview-wrap")}function c(a,b){for(;a&&a.parentNode;){if(a.className&&-1!==(" "+a.className+" ").indexOf(" "+b+" "))return a;a=a.parentNode}return!1}function d(c){return(c=b(c))?window.decodeURIComponent(a.dom.getAttrib(c,"data-wpview-text")||""):""}function e(c,d){return c=b(c),c?(a.dom.setAttrib(c,"data-wpview-text",window.encodeURIComponent(d||"")),!0):!1}function f(a){a.stopPropagation()}function g(b,c){var d=b?"before":"after",e=b?0:1;l(),a.selection.setCursorLocation(a.dom.select(".wpview-selection-"+d,c)[0],e),a.nodeChanged()}function h(b,c,d){var e=a.dom,f=e.create("p");v.ie&&v.ie<11||(f.innerHTML='
'),c?b.parentNode.insertBefore(f,b):e.insertAfter(f,b),l(),c&&d===w.ENTER?g(c,b):a.selection.setCursorLocation(f,0),a.nodeChanged()}function i(b){a.undoManager.transact(function(){h(b),a.dom.remove(b)})}function j(b){var c,e=a.dom;if(b){if(b===o)return void k(b);a.getBody().focus(),l(),o=b,e.setAttrib(b,"data-mce-selected",1),k(b),c=e.create("div",{"class":"wpview-clipboard",contenteditable:"true"},d(b)),a.dom.select(".wpview-body",b)[0].appendChild(c),e.bind(c,"beforedeactivate focusin focusout",f),e.bind(o,"beforedeactivate focusin focusout",f),B?a.selection.select(c):a.selection.select(c,!0),a.nodeChanged(),a.fire("wpview-selected",b)}}function k(b){var c=0,d=a.$(b).find(".toolbar"),e=tinymce.$(a.editorContainer).find(".mce-toolbar-grp")[0],f=e&&e.getBoundingClientRect().bottom||0;d.length&&a.iframeElement&&(c=b.getBoundingClientRect().top+a.iframeElement.getBoundingClientRect().top-f-48),0>c?d.removeClass("mce-arrow-down").css({top:-43+-1*c}):c>0&&!d.hasClass("mce-arrow-down")&&d.addClass("mce-arrow-down").css({top:""})}function l(){var b,c=a.dom;o&&(b=a.dom.select(".wpview-clipboard",o)[0],c.unbind(b),c.remove(b),c.unbind(o,"beforedeactivate focusin focusout click mouseup",f),c.setAttrib(o,"data-mce-selected",null)),o=null}function m(a){return a.replace(/]+data-wpview-text=\"([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>(?: |\u00a0)*<\/p><\/div>/g,"$1")}function n(a){return 47>=a&&a!==w.SPACEBAR&&a!==w.ENTER&&a!==w.DELETE&&a!==w.BACKSPACE&&(37>a||a>40)||a>=224||a>=144&&150>=a||a>=91&&93>=a||a>=112&&135>=a}var o,p,q,r,s,t,u,v=tinymce.Env,w=tinymce.util.VK,x=tinymce.dom.TreeWalker,y=!1,z=!0,A=function(){return!1},B=/iPad|iPod|iPhone/.test(navigator.userAgent);return"undefined"!=typeof wp&&wp.mce?(a.on("BeforeAddUndo",function(a){a.lastLevel&&m(a.level.content)===m(a.lastLevel.content)&&a.preventDefault()}),a.on("BeforeSetContent",function(b){var c;b.content&&(o&&i(o),c=a.selection.getNode(),(!b.content.match(/^\s*(https?:\/\/[^\s"]+)\s*$/i)||"P"===c.nodeName&&c.parentNode===a.getBody()&&a.dom.isEmpty(c))&&(b.content=wp.mce.views.toViews(b.content)))}),a.on("SetContent",function(){wp.mce.views.render()}),a.on("click",function(c){var d,e=c.clientX,f=c.clientY,h=a.getBody(),i=h.getBoundingClientRect(),j=h.firstChild,k=j.getBoundingClientRect(),l=h.lastChild,m=l.getBoundingClientRect();fm.bottom&&(d=b(l))?(g(!1,d),c.preventDefault()):(ei.right)&&tinymce.each(a.dom.select(".wpview-wrap"),function(a){var b=a.getBoundingClientRect();return f=b.top&&f<=b.bottom?(ei.right&&(g(!1,a),c.preventDefault()),!1):void 0})}),a.on("init",function(){var c=!1,d=a.selection,e=window.MutationObserver||window.WebKitMutationObserver;a.on("BeforeSetContent",function(){var c,e,f=b(d.getNode());f&&(!f.nextSibling||b(f.nextSibling)?(e=a.getDoc().createTextNode(""),a.dom.insertAfter(e,f)):(c=new x(f.nextSibling,f.nextSibling),e=c.next()),d.select(e),d.collapse(!0))}),a.dom.bind(a.getDoc(),"touchmove",function(){c=!0}),a.on("mousedown mouseup click touchend",function(d){var e=b(d.target);if(z=!1,e){if(d.stopImmediatePropagation(),d.preventDefault(),!("touchend"!==d.type&&"mousedown"!==d.type||d.metaKey||d.ctrlKey)){if(a.dom.hasClass(d.target,"edit"))return v.ie&&a.focus(),wp.mce.views.edit(e),!1;if(a.dom.hasClass(d.target,"remove"))return i(e),!1}return"touchend"===d.type&&c?c=!1:j(e),!1}("touchend"===d.type||"mousedown"===d.type)&&l(),"touchend"===d.type&&c&&(c=!1)},!0),e&&new e(function(){a.fire("wp-body-class-change")}).observe(a.getBody(),{attributes:!0,attributeFilter:["class"]})}),a.on("PreProcess",function(b){tinymce.each(a.dom.select("div[data-wpview-text]",b.node),function(a){a.textContent=a.innerText=" "})}),a.on("PostProcess",function(a){a.content&&(a.content=a.content.replace(/

]*?data-wpview-text="([^"]*)"[^>]*>[\s\S]*?<\/div>/g,function(a,b){return b?"

"+window.decodeURIComponent(b)+"

":""}))}),a.on("keydown",function(c){var d,e,f,k,m,p,r,s=c.keyCode,t=a.dom,u=a.selection;if(o){if((c.metaKey||c.ctrlKey)&&s!==w.BACKSPACE&&86!==s||s>=112&&123>=s)return void((c.metaKey||c.ctrlKey)&&88===s&&(y=o));if(e=b(u.getNode()),e!==o)return void l();s===w.LEFT?(g(!0,e),c.preventDefault()):s===w.UP?(e.previousSibling?b(e.previousSibling)?g(!0,e.previousSibling):(l(),u.select(e.previousSibling,!0),u.collapse()):g(!0,e),c.preventDefault()):s===w.RIGHT?(g(!1,e),c.preventDefault()):s===w.DOWN?(e.nextSibling?b(e.nextSibling)?g(!1,e.nextSibling):(l(),u.setCursorLocation(e.nextSibling,0)):g(!1,e),c.preventDefault()):n(s)||(i(o),(s===w.ENTER||s===w.DELETE||s===w.BACKSPACE)&&c.preventDefault())}else{if(c.metaKey||c.ctrlKey||s>=112&&123>=s)return;if(d=u.getNode(),q=d,e=b(d),u.isCollapsed()||(m=u.getRng(),(e=b(m.endContainer))?(p=m.cloneRange(),u.select(e.previousSibling,!0),u.collapse(),r=u.getRng(),p.setEnd(r.endContainer,r.endOffset),u.setRng(p)):(e=b(m.startContainer))&&(p=m.cloneRange(),p.setStart(e.nextSibling,0),u.setRng(p))),!e)return void(c.keyCode===w.BACKSPACE&&(a.dom.isEmpty(d)?(e=b(d.previousSibling))&&(g(!1,e),a.dom.remove(d),c.preventDefault()):(m=u.getRng())&&0===m.startOffset&&0===m.endOffset&&(e=b(d.previousSibling))&&(g(!1,e),c.preventDefault())));if(!(f=t.hasClass(e,"wpview-selection-before"))&&!(k=t.hasClass(e,"wpview-selection-after")))return;if(n(s))return;k&&s===w.UP||f&&s===w.BACKSPACE?(e.previousSibling?b(e.previousSibling)?g(!1,e.previousSibling):t.isEmpty(e.previousSibling)&&s===w.BACKSPACE?t.remove(e.previousSibling):(u.select(e.previousSibling,!0),u.collapse()):g(!0,e),c.preventDefault()):!k||s!==w.DOWN&&s!==w.RIGHT?!f||s!==w.UP&&s!==w.LEFT?f&&s===w.DOWN?(e.nextSibling?b(e.nextSibling)?g(!0,e.nextSibling):u.setCursorLocation(e.nextSibling,0):g(!1,e),c.preventDefault()):k&&s===w.LEFT||f&&s===w.RIGHT?(j(e),c.preventDefault()):k&&s===w.BACKSPACE?(i(e),c.preventDefault()):k?h(e):f&&h(e,!0,s):(e.previousSibling&&(b(e.previousSibling)?g(s===w.UP,e.previousSibling):(u.select(e.previousSibling,!0),u.collapse())),c.preventDefault()):(e.nextSibling&&(b(e.nextSibling)?g(s===w.RIGHT,e.nextSibling):u.setCursorLocation(e.nextSibling,0)),c.preventDefault()),s===w.ENTER&&c.preventDefault()}}),a.on("keyup",function(){y&&(i(y),y=!1)}),a.on("focus",function(){var c;s=!0,a.dom.addClass(a.getBody(),"has-focus"),z&&(c=b(a.getBody().firstChild))&&g(!0,c),z=!1}),a.on("blur",function(){s=!1,a.dom.removeClass(a.getBody(),"has-focus")}),a.on("NodeChange",function(d){var e=a.dom,f=a.dom.select(".wpview-wrap"),h=d.element.className,i=b(d.element),j=q;if(q=!1,clearInterval(p),tinymce.each(f,function(a){a.className&&(a.className=a.className.replace(/ ?\bwpview-(?:selection-before|selection-after|cursor-hide)\b/g,""))}),s&&i)if("wpview-selection-before"!==h&&"wpview-selection-after"!==h||!a.selection.isCollapsed())c(d.element,"wpview-clipboard")||r||(l(),r++,g(!0,i));else{if(r=0,l(),j===i.previousSibling)return void g(!0,i);if(j===i.nextSibling)return void g(!1,i);e.addClass(i,h),p=setInterval(function(){e.hasClass(i,"wpview-cursor-hide")?e.removeClass(i,"wpview-cursor-hide"):e.addClass(i,"wpview-cursor-hide")},500)}}),a.on("BeforeExecCommand",function(){var c,d=a.selection.getNode();d&&((u="wpview-selection-before"===d.className)||"wpview-selection-after"===d.className)&&(c=b(d))&&(h(c,u),t=c)}),a.on("ExecCommand",function(){var b,c;o&&(b=o,l(),j(b)),t&&(c=t[u?"previousSibling":"nextSibling"],c&&"P"===c.nodeName&&a.dom.isEmpty(c)&&(a.dom.remove(c),g(u,t)),t=!1)}),a.on("ResolveName",function(c){a.dom.hasClass(c.target,"wpview-wrap")?(c.name=a.dom.getAttrib(c.target,"data-wpview-type")||"wpview",c.stopPropagation()):b(c.target)&&(c.preventDefault(),c.stopPropagation())}),{getViewText:d,setViewText:e,getView:b}):{getViewText:A,setViewText:A,getView:A}}); \ No newline at end of file +tinymce.PluginManager.add("wpview",function(a){function b(a){return c(a,"wpview-wrap")}function c(a,b){for(;a&&a.parentNode;){if(a.className&&-1!==(" "+a.className+" ").indexOf(" "+b+" "))return a;a=a.parentNode}return!1}function d(c){return(c=b(c))?window.decodeURIComponent(a.dom.getAttrib(c,"data-wpview-text")||""):""}function e(c,d){return c=b(c),c?(a.dom.setAttrib(c,"data-wpview-text",window.encodeURIComponent(d||"")),!0):!1}function f(a){a.stopPropagation()}function g(b,c){var d=b?"before":"after",e=b?0:1;l(),a.selection.setCursorLocation(a.dom.select(".wpview-selection-"+d,c)[0],e),a.nodeChanged()}function h(b,c,d){var e=a.dom,f=e.create("p");v.ie&&v.ie<11||(f.innerHTML='
'),c?b.parentNode.insertBefore(f,b):e.insertAfter(f,b),l(),c&&d===w.ENTER?g(c,b):a.selection.setCursorLocation(f,0),a.nodeChanged()}function i(b){a.undoManager.transact(function(){h(b),a.dom.remove(b)})}function j(b){var c,e=a.dom;if(b){if(b===o)return void k(b);a.getBody().focus(),l(),o=b,e.setAttrib(b,"data-mce-selected",1),k(b),c=e.create("div",{"class":"wpview-clipboard",contenteditable:"true"},d(b)),a.dom.select(".wpview-body",b)[0].appendChild(c),e.bind(c,"beforedeactivate focusin focusout",f),e.bind(o,"beforedeactivate focusin focusout",f),B?a.selection.select(c):a.selection.select(c,!0),a.nodeChanged(),a.fire("wpview-selected",b)}}function k(b){var c=0,d=a.$(b).find(".toolbar"),e=tinymce.$(a.editorContainer).find(".mce-toolbar-grp")[0],f=e&&e.getBoundingClientRect().bottom||0;d.length&&a.iframeElement&&(c=b.getBoundingClientRect().top+a.iframeElement.getBoundingClientRect().top-f-48),0>c?d.removeClass("mce-arrow-down").css({top:-43+-1*c}):c>0&&!d.hasClass("mce-arrow-down")&&d.addClass("mce-arrow-down").css({top:""})}function l(){var b,c=a.dom;o&&(b=a.dom.select(".wpview-clipboard",o)[0],c.unbind(b),c.remove(b),c.unbind(o,"beforedeactivate focusin focusout click mouseup",f),c.setAttrib(o,"data-mce-selected",null)),o=null}function m(a){return a.replace(/]+data-wpview-text=\"([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>(?: |\u00a0)*<\/p><\/div>/g,"$1")}function n(a){return 47>=a&&a!==w.SPACEBAR&&a!==w.ENTER&&a!==w.DELETE&&a!==w.BACKSPACE&&(37>a||a>40)||a>=224||a>=144&&150>=a||a>=91&&93>=a||a>=112&&135>=a}var o,p,q,r,s,t,u,v=tinymce.Env,w=tinymce.util.VK,x=tinymce.dom.TreeWalker,y=!1,z=!0,A=function(){return!1},B=/iPad|iPod|iPhone/.test(navigator.userAgent);return"undefined"!=typeof wp&&wp.mce?(a.on("BeforeAddUndo",function(a){a.lastLevel&&m(a.level.content)===m(a.lastLevel.content)&&a.preventDefault()}),a.on("BeforeSetContent",function(b){var c;b.content&&(o&&i(o),c=a.selection.getNode(),(!b.content.match(/^\s*(https?:\/\/[^\s"]+)\s*$/i)||"P"===c.nodeName&&c.parentNode===a.getBody()&&a.dom.isEmpty(c))&&(b.content=wp.mce.views.setMarkers(b.content)))}),a.on("SetContent",function(){wp.mce.views.render()}),a.on("click",function(c){var d,e=c.clientX,f=c.clientY,h=a.getBody(),i=h.getBoundingClientRect(),j=h.firstChild,k=j.getBoundingClientRect(),l=h.lastChild,m=l.getBoundingClientRect();fm.bottom&&(d=b(l))?(g(!1,d),c.preventDefault()):(ei.right)&&tinymce.each(a.dom.select(".wpview-wrap"),function(a){var b=a.getBoundingClientRect();return f=b.top&&f<=b.bottom?(ei.right&&(g(!1,a),c.preventDefault()),!1):void 0})}),a.on("init",function(){var c=!1,d=a.selection,e=window.MutationObserver||window.WebKitMutationObserver;a.on("BeforeSetContent",function(){var c,e,f=b(d.getNode());f&&(!f.nextSibling||b(f.nextSibling)?(e=a.getDoc().createTextNode(""),a.dom.insertAfter(e,f)):(c=new x(f.nextSibling,f.nextSibling),e=c.next()),d.select(e),d.collapse(!0))}),a.dom.bind(a.getDoc(),"touchmove",function(){c=!0}),a.on("mousedown mouseup click touchend",function(d){var e=b(d.target);if(z=!1,e){if(d.stopImmediatePropagation(),d.preventDefault(),!("touchend"!==d.type&&"mousedown"!==d.type||d.metaKey||d.ctrlKey)){if(a.dom.hasClass(d.target,"edit"))return v.ie&&a.focus(),wp.mce.views.edit(a,e),!1;if(a.dom.hasClass(d.target,"remove"))return i(e),!1}return"touchend"===d.type&&c?c=!1:j(e),!1}("touchend"===d.type||"mousedown"===d.type)&&l(),"touchend"===d.type&&c&&(c=!1)},!0),e&&new e(function(){a.fire("wp-body-class-change")}).observe(a.getBody(),{attributes:!0,attributeFilter:["class"]})}),a.on("PreProcess",function(b){tinymce.each(a.dom.select("div[data-wpview-text]",b.node),function(a){a.textContent=a.innerText=" "})}),a.on("PostProcess",function(a){a.content&&(a.content=a.content.replace(/
]*?data-wpview-text="([^"]*)"[^>]*>[\s\S]*?<\/div>/g,function(a,b){return b?"

"+window.decodeURIComponent(b)+"

":""}))}),a.on("keydown",function(c){var d,e,f,k,m,p,r,s=c.keyCode,t=a.dom,u=a.selection;if(o){if((c.metaKey||c.ctrlKey)&&s!==w.BACKSPACE&&86!==s||s>=112&&123>=s)return void((c.metaKey||c.ctrlKey)&&88===s&&(y=o));if(e=b(u.getNode()),e!==o)return void l();s===w.LEFT?(g(!0,e),c.preventDefault()):s===w.UP?(e.previousSibling?b(e.previousSibling)?g(!0,e.previousSibling):(l(),u.select(e.previousSibling,!0),u.collapse()):g(!0,e),c.preventDefault()):s===w.RIGHT?(g(!1,e),c.preventDefault()):s===w.DOWN?(e.nextSibling?b(e.nextSibling)?g(!1,e.nextSibling):(l(),u.setCursorLocation(e.nextSibling,0)):g(!1,e),c.preventDefault()):n(s)||(i(o),(s===w.ENTER||s===w.DELETE||s===w.BACKSPACE)&&c.preventDefault())}else{if(c.metaKey||c.ctrlKey||s>=112&&123>=s)return;if(d=u.getNode(),q=d,e=b(d),u.isCollapsed()||(m=u.getRng(),(e=b(m.endContainer))?(p=m.cloneRange(),u.select(e.previousSibling,!0),u.collapse(),r=u.getRng(),p.setEnd(r.endContainer,r.endOffset),u.setRng(p)):(e=b(m.startContainer))&&(p=m.cloneRange(),p.setStart(e.nextSibling,0),u.setRng(p))),!e)return void(c.keyCode===w.BACKSPACE&&(a.dom.isEmpty(d)?(e=b(d.previousSibling))&&(g(!1,e),a.dom.remove(d),c.preventDefault()):(m=u.getRng())&&0===m.startOffset&&0===m.endOffset&&(e=b(d.previousSibling))&&(g(!1,e),c.preventDefault())));if(!(f=t.hasClass(e,"wpview-selection-before"))&&!(k=t.hasClass(e,"wpview-selection-after")))return;if(n(s))return;k&&s===w.UP||f&&s===w.BACKSPACE?(e.previousSibling?b(e.previousSibling)?g(!1,e.previousSibling):t.isEmpty(e.previousSibling)&&s===w.BACKSPACE?t.remove(e.previousSibling):(u.select(e.previousSibling,!0),u.collapse()):g(!0,e),c.preventDefault()):!k||s!==w.DOWN&&s!==w.RIGHT?!f||s!==w.UP&&s!==w.LEFT?f&&s===w.DOWN?(e.nextSibling?b(e.nextSibling)?g(!0,e.nextSibling):u.setCursorLocation(e.nextSibling,0):g(!1,e),c.preventDefault()):k&&s===w.LEFT||f&&s===w.RIGHT?(j(e),c.preventDefault()):k&&s===w.BACKSPACE?(i(e),c.preventDefault()):k?h(e):f&&h(e,!0,s):(e.previousSibling&&(b(e.previousSibling)?g(s===w.UP,e.previousSibling):(u.select(e.previousSibling,!0),u.collapse())),c.preventDefault()):(e.nextSibling&&(b(e.nextSibling)?g(s===w.RIGHT,e.nextSibling):u.setCursorLocation(e.nextSibling,0)),c.preventDefault()),s===w.ENTER&&c.preventDefault()}}),a.on("keyup",function(){y&&(i(y),y=!1)}),a.on("focus",function(){var c;s=!0,a.dom.addClass(a.getBody(),"has-focus"),z&&(c=b(a.getBody().firstChild))&&g(!0,c),z=!1}),a.on("blur",function(){s=!1,a.dom.removeClass(a.getBody(),"has-focus")}),a.on("NodeChange",function(d){var e=a.dom,f=a.dom.select(".wpview-wrap"),h=d.element.className,i=b(d.element),j=q;if(q=!1,clearInterval(p),tinymce.each(f,function(a){a.className&&(a.className=a.className.replace(/ ?\bwpview-(?:selection-before|selection-after|cursor-hide)\b/g,""))}),s&&i)if("wpview-selection-before"!==h&&"wpview-selection-after"!==h||!a.selection.isCollapsed())c(d.element,"wpview-clipboard")||r||(l(),r++,g(!0,i));else{if(r=0,l(),j===i.previousSibling)return void g(!0,i);if(j===i.nextSibling)return void g(!1,i);e.addClass(i,h),p=setInterval(function(){e.hasClass(i,"wpview-cursor-hide")?e.removeClass(i,"wpview-cursor-hide"):e.addClass(i,"wpview-cursor-hide")},500)}}),a.on("BeforeExecCommand",function(){var c,d=a.selection.getNode();d&&((u="wpview-selection-before"===d.className)||"wpview-selection-after"===d.className)&&(c=b(d))&&(h(c,u),t=c)}),a.on("ExecCommand",function(){var b,c;o&&(b=o,l(),j(b)),t&&(c=t[u?"previousSibling":"nextSibling"],c&&"P"===c.nodeName&&a.dom.isEmpty(c)&&(a.dom.remove(c),g(u,t)),t=!1)}),a.on("ResolveName",function(c){a.dom.hasClass(c.target,"wpview-wrap")?(c.name=a.dom.getAttrib(c.target,"data-wpview-type")||"wpview",c.stopPropagation()):b(c.target)&&(c.preventDefault(),c.stopPropagation())}),{getViewText:d,setViewText:e,getView:b}):{getViewText:A,setViewText:A,getView:A}}); \ No newline at end of file diff --git a/wp-includes/js/tinymce/wp-tinymce.js.gz b/wp-includes/js/tinymce/wp-tinymce.js.gz index d5f03f326b1273d7727cf48d6bb0772e25322837..21f34bec0646c2776ce6f2a11905b42d17236b5f 100644 GIT binary patch delta 3394 zcmV-I4ZZTSs0g~K2!MnEv;sH-2~}d3Vpn#{a<;cY0|EvD0$)0}Nd*E60RfMfRR#jO z0Z*3@2Ld;Lf9LhT7Zc#L2kJNWxV$R&W_Z*5YWsw;>!(^6-b$dG(IuNGj5t@h!=24) zPQC)YXkd3Nsue4`-TCyOiIwOt_twfLSQ5*RWIfE3QqKwHY z3N|g|!Sy1PUL6~W2DP1oH1-B0Bl9KHpn|JGH_xjDGnMhR$0hr*b3d=3GMy>UB_U2t zVmvVU3Fuspe%2tI!pJnDztDjs**s^qKfQxl8O)lnr6wxb0)4chdMXpcr>eLowcVfX zLgd(g+ebl&M;f(5L*_~G7>`?j6kdJsJIgaXG*jOg8&P%{O|8b}jyT>e?m$DnyL`pO zcg8F{fY*ilWDFyj!2n+g2jei3ox`KCkrWAj{By}E&D4~%*Nlci%*kbO{o=P-z`mtZ za~+1LtRO*mIufnV3%B(UZ4IG(?m!@+0Q-l3M?Z$6v+z+sq9H>?7hvT8RSp8&=@~tu z@prk156)$9u$|tLf^c0pWdkp^k;8>;ESuZiM3$m!Dv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s1ueSf7BTy7G;QK)ku_h{iFh0F#!EAcIt6tPf z(WK64TDR^K!r-LYxhvG6@-Q{}nEVQ=>sP2|c3X_+uONcp)A*LH6DBIYwC!FJ{7kNr zu|G=TDiyU0MzO7P*OppcXDCU>!1w?(P&{Ut^$oNBst{sAnv^%wD-)!>_G;@c28DDR zF$rNt*{mEFG_w|e=FDIKGiiQw6rliA0xAzS$~@`g;m$`U(v>qysZ}Z-#pKLbm`*0E z-~b91T4XDTJ)9+MzNw)yQm3g^tI|!--3jO)LlPTG#l{!CMK;lwz#g+>?s9>JYlyjn zu#8}pG>$87PBjY{M)r7z*eWPyF;3V3_|#Xx6P4+C)>hqrG|I%`M9s$)Ptf==&GP+f z)U$?|ZL`QY_CCN#rt3Vl9i+<0QiOy|vR2U&K4s`NKlUnfa`4h%J)#eQ==Y9KQ0pvR zl{Yq~pJ$k}S78n^_gp)S_0yb#!*Rm+o&xBl2f|(vZ1^_sqht>c9 diff --git a/wp-includes/media-template.php b/wp-includes/media-template.php index 86500ff0fd..76b2d32af4 100644 --- a/wp-includes/media-template.php +++ b/wp-includes/media-template.php @@ -1205,7 +1205,7 @@ function wp_print_media_templates() {