X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/wordpress.git/blobdiff_plain/0461a5f2e55c8d5f1fde96ca2e83117152573c7d..9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f:/wp-includes/js/mce-view.js diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index ec167ca4..85484ef4 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -1,4 +1,4 @@ -/* global tinymce, MediaElementPlayer, WPPlaylistView */ +/* global tinymce */ /** * Note: this API is "experimental" meaning that it will probably change * in the next few releases based on feedback from 3.9.0. @@ -8,7 +8,9 @@ // Ensure the global `wp` object exists. window.wp = window.wp || {}; -(function($){ +( function( $ ) { + 'use strict'; + var views = {}, instances = {}, media = wp.media, @@ -22,34 +24,237 @@ window.wp = window.wp || {}; * * 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 = {}); - _.extend(this, _.pick(options, viewOptions)); - this.initialize.apply(this, arguments); + 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() {}, - render: function() { - var html = this.getHtml(); - // Search all tinymce editor instances and update the placeholders + 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 ) { - var doc, self = this; if ( editor.plugins.wpview ) { - doc = editor.getDoc(); - $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each(function (i, elem) { - var node = $( elem ); - // The is used to mark the end of the wrapper div. Needed when comparing - // the content as string for preventing extra undo levels. - node.html( html ).append( '' ); - $( self ).trigger( 'ready', elem ); - }); + if ( callback ) { + callback( editor ); + } + + editors.push( editor ); } }, this ); + + return editors; }, - unbind: function() {} + 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( '