diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index 3a21e01fa7..d7775ea4b8 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/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 '' + - '
\u00a0
' + - '\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( '