2014-07-15 22:19:15 -04:00
|
|
|
/* global tinymce */
|
2015-02-25 18:13:25 -05:00
|
|
|
|
|
|
|
window.wp = window.wp || {};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The TinyMCE view API.
|
|
|
|
*
|
2014-04-07 02:59:16 -04:00
|
|
|
* 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.
|
2015-02-25 18:13:25 -05:00
|
|
|
*
|
|
|
|
* Diagram
|
|
|
|
*
|
|
|
|
* |- registered view constructor (type)
|
|
|
|
* | |- view instance (unique text)
|
|
|
|
* | | |- editor 1
|
|
|
|
* | | | |- view node
|
|
|
|
* | | | |- view node
|
|
|
|
* | | | |- ...
|
|
|
|
* | | |- editor 2
|
|
|
|
* | | | |- ...
|
|
|
|
* | |- view instance
|
|
|
|
* | | |- ...
|
|
|
|
* |- registered view
|
|
|
|
* | |- ...
|
2014-04-07 05:03:14 -04:00
|
|
|
*/
|
2015-02-25 18:13:25 -05:00
|
|
|
( function( window, wp, $ ) {
|
2014-06-11 22:49:16 -04:00
|
|
|
'use strict';
|
|
|
|
|
2012-09-23 20:13:18 -04:00
|
|
|
var views = {},
|
2015-03-05 07:36:28 -05:00
|
|
|
instances = {};
|
2014-07-15 18:18:14 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
wp.mce = wp.mce || {};
|
2014-03-05 02:01:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.mce.views
|
|
|
|
*
|
|
|
|
* A set of utilities that simplifies adding custom UI within a TinyMCE editor.
|
|
|
|
* At its core, it serves as a series of converters, transforming text to a
|
|
|
|
* custom UI, and back again.
|
|
|
|
*/
|
|
|
|
wp.mce.views = {
|
|
|
|
|
|
|
|
/**
|
2015-02-25 18:13:25 -05:00
|
|
|
* Registers a new view type.
|
2014-03-05 02:01:14 -05:00
|
|
|
*
|
2015-02-25 18:13:25 -05:00
|
|
|
* @param {String} type The view type.
|
|
|
|
* @param {Object} extend An object to extend wp.mce.View.prototype with.
|
2014-03-05 02:01:14 -05:00
|
|
|
*/
|
2015-02-25 18:13:25 -05:00
|
|
|
register: function( type, extend ) {
|
|
|
|
views[ type ] = wp.mce.View.extend( _.extend( extend, { type: type } ) );
|
2012-09-23 20:13:18 -04:00
|
|
|
},
|
|
|
|
|
2014-03-05 02:01:14 -05:00
|
|
|
/**
|
2015-02-25 18:13:25 -05:00
|
|
|
* Unregisters a view type.
|
2014-06-05 13:27:13 -04:00
|
|
|
*
|
2015-02-25 18:13:25 -05:00
|
|
|
* @param {String} type The view type.
|
2014-03-05 02:01:14 -05:00
|
|
|
*/
|
2015-02-25 18:13:25 -05:00
|
|
|
unregister: function( type ) {
|
|
|
|
delete views[ type ];
|
2012-09-23 20:13:18 -04:00
|
|
|
},
|
|
|
|
|
2014-03-05 02:01:14 -05:00
|
|
|
/**
|
2015-02-25 18:13:25 -05:00
|
|
|
* Returns the settings of a view type.
|
2014-06-05 13:27:13 -04:00
|
|
|
*
|
2015-02-25 18:13:25 -05:00
|
|
|
* @param {String} type The view type.
|
2015-02-26 14:32:24 -05:00
|
|
|
*
|
|
|
|
* @return {Function} The view constructor.
|
2014-03-05 02:01:14 -05:00
|
|
|
*/
|
2015-02-25 18:13:25 -05:00
|
|
|
get: function( type ) {
|
|
|
|
return views[ type ];
|
2012-09-23 20:13:18 -04:00
|
|
|
},
|
|
|
|
|
2014-04-11 20:46:14 -04:00
|
|
|
/**
|
2015-02-25 18:13:25 -05:00
|
|
|
* Unbinds all view nodes.
|
|
|
|
* Runs before removing all view nodes from the DOM.
|
2014-04-11 20:46:14 -04:00
|
|
|
*/
|
|
|
|
unbind: function() {
|
|
|
|
_.each( instances, function( instance ) {
|
|
|
|
instance.unbind();
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2014-03-05 02:01:14 -05:00
|
|
|
/**
|
2015-02-25 18:13:25 -05:00
|
|
|
* Scans a given string for each view's pattern,
|
|
|
|
* replacing any matches with markers,
|
|
|
|
* and creates a new instance for every match.
|
2014-03-05 02:01:14 -05:00
|
|
|
*
|
2015-02-25 18:13:25 -05:00
|
|
|
* @param {String} content The string to scan.
|
2015-04-04 19:00:26 -04:00
|
|
|
*
|
|
|
|
* @return {String} The string with markers.
|
2014-03-05 02:01:14 -05:00
|
|
|
*/
|
2015-02-25 18:13:25 -05:00
|
|
|
setMarkers: function( content ) {
|
2015-03-05 07:36:28 -05:00
|
|
|
var pieces = [ { content: content } ],
|
2015-02-25 18:13:25 -05:00
|
|
|
self = this,
|
2015-03-09 15:09:27 -04:00
|
|
|
instance,
|
2012-09-25 21:00:08 -04:00
|
|
|
current;
|
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
_.each( views, function( view, type ) {
|
2012-09-25 21:00:08 -04:00
|
|
|
current = pieces.slice();
|
|
|
|
pieces = [];
|
|
|
|
|
|
|
|
_.each( current, function( piece ) {
|
|
|
|
var remaining = piece.content,
|
|
|
|
result;
|
|
|
|
|
|
|
|
// Ignore processed pieces, but retain their location.
|
|
|
|
if ( piece.processed ) {
|
|
|
|
pieces.push( piece );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate through the string progressively matching views
|
|
|
|
// and slicing the string as we go.
|
2015-02-25 18:13:25 -05:00
|
|
|
while ( remaining && ( result = view.prototype.match( remaining ) ) ) {
|
2012-09-25 21:00:08 -04:00
|
|
|
// Any text before the match becomes an unprocessed piece.
|
2014-03-05 02:01:14 -05:00
|
|
|
if ( result.index ) {
|
2015-02-25 18:13:25 -05:00
|
|
|
pieces.push( { content: remaining.substring( 0, result.index ) } );
|
2014-03-05 02:01:14 -05:00
|
|
|
}
|
2012-09-25 21:00:08 -04:00
|
|
|
|
2015-03-09 15:09:27 -04:00
|
|
|
instance = self.createInstance( type, result.content, result.options );
|
2015-02-25 18:13:25 -05:00
|
|
|
|
2012-09-25 21:00:08 -04:00
|
|
|
// Add the processed piece for the match.
|
2015-02-25 18:13:25 -05:00
|
|
|
pieces.push( {
|
2015-03-09 15:09:27 -04:00
|
|
|
content: '<p data-wpview-marker="' + instance.encodedText + '">' + instance.text + '</p>',
|
2012-09-25 21:00:08 -04:00
|
|
|
processed: true
|
2015-02-25 18:13:25 -05:00
|
|
|
} );
|
2012-09-25 21:00:08 -04:00
|
|
|
|
|
|
|
// Update the remaining content.
|
|
|
|
remaining = remaining.slice( result.index + result.content.length );
|
|
|
|
}
|
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
// There are no additional matches.
|
|
|
|
// If any content remains, add it as an unprocessed piece.
|
2014-03-05 02:01:14 -05:00
|
|
|
if ( remaining ) {
|
2015-02-25 18:13:25 -05:00
|
|
|
pieces.push( { content: remaining } );
|
2014-03-05 02:01:14 -05:00
|
|
|
}
|
2015-02-25 18:13:25 -05:00
|
|
|
} );
|
|
|
|
} );
|
2012-09-25 21:00:08 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
return _.pluck( pieces, 'content' ).join( '' );
|
2012-09-25 21:00:08 -04:00
|
|
|
},
|
2012-09-23 20:13:18 -04:00
|
|
|
|
2014-03-05 02:01:14 -05:00
|
|
|
/**
|
2015-02-25 18:13:25 -05:00
|
|
|
* Create a view instance.
|
2014-03-05 02:01:14 -05:00
|
|
|
*
|
2015-02-25 18:13:25 -05:00
|
|
|
* @param {String} type The view type.
|
|
|
|
* @param {String} text The textual representation of the view.
|
|
|
|
* @param {Object} options Options.
|
2015-02-26 14:32:24 -05:00
|
|
|
*
|
|
|
|
* @return {wp.mce.View} The view instance.
|
2014-03-05 02:01:14 -05:00
|
|
|
*/
|
2015-02-25 18:13:25 -05:00
|
|
|
createInstance: function( type, text, options ) {
|
|
|
|
var View = this.get( type ),
|
2015-03-09 15:09:27 -04:00
|
|
|
encodedText,
|
|
|
|
instance;
|
|
|
|
|
2015-07-17 17:22:27 -04:00
|
|
|
text = tinymce.DOM.decode( text );
|
|
|
|
instance = this.getInstance( text );
|
2014-03-05 02:01:14 -05:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
if ( instance ) {
|
|
|
|
return instance;
|
2014-03-05 02:01:14 -05:00
|
|
|
}
|
2012-09-23 20:13:18 -04:00
|
|
|
|
2015-07-17 17:22:27 -04:00
|
|
|
encodedText = encodeURIComponent( text );
|
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
options = _.extend( options || {}, {
|
|
|
|
text: text,
|
|
|
|
encodedText: encodedText
|
|
|
|
} );
|
2012-09-23 20:13:18 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
return instances[ encodedText ] = new View( options );
|
2012-09-23 20:13:18 -04:00
|
|
|
},
|
|
|
|
|
2014-03-05 02:01:14 -05:00
|
|
|
/**
|
2015-02-25 18:13:25 -05:00
|
|
|
* Get a view instance.
|
2014-03-19 03:02:15 -04:00
|
|
|
*
|
2015-02-26 14:32:24 -05:00
|
|
|
* @param {(String|HTMLElement)} object The textual representation of the view or the view node.
|
|
|
|
*
|
|
|
|
* @return {wp.mce.View} The view instance or undefined.
|
|
|
|
*/
|
|
|
|
getInstance: function( object ) {
|
|
|
|
if ( typeof object === 'string' ) {
|
|
|
|
return instances[ encodeURIComponent( object ) ];
|
|
|
|
}
|
|
|
|
|
2015-03-11 18:40:28 -04:00
|
|
|
return instances[ $( object ).attr( 'data-wpview-text' ) ];
|
2015-02-26 14:32:24 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a view node, get the view's text.
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} node The view node.
|
|
|
|
*
|
|
|
|
* @return {String} The textual representation of the view.
|
2014-03-05 02:01:14 -05:00
|
|
|
*/
|
2015-02-26 14:32:24 -05:00
|
|
|
getText: function( node ) {
|
2015-03-11 18:40:28 -04:00
|
|
|
return decodeURIComponent( $( node ).attr( 'data-wpview-text' ) || '' );
|
2012-09-26 18:20:15 -04:00
|
|
|
},
|
|
|
|
|
2014-03-19 03:02:15 -04:00
|
|
|
/**
|
2015-02-25 18:13:25 -05:00
|
|
|
* Renders all view nodes that are not yet rendered.
|
2014-03-05 02:01:14 -05:00
|
|
|
*
|
2015-02-25 18:13:25 -05:00
|
|
|
* @param {Boolean} force Rerender all view nodes.
|
2014-03-05 02:01:14 -05:00
|
|
|
*/
|
2014-08-17 23:59:17 -04:00
|
|
|
render: function( force ) {
|
2014-03-05 02:01:14 -05:00
|
|
|
_.each( instances, function( instance ) {
|
2014-08-17 23:59:17 -04:00
|
|
|
instance.render( force );
|
2014-03-05 02:01:14 -05:00
|
|
|
} );
|
2012-09-26 18:20:15 -04:00
|
|
|
},
|
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* 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 ) {
|
2015-02-26 14:32:24 -05:00
|
|
|
var instance = this.getInstance( node );
|
2012-10-11 23:28:22 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
if ( instance ) {
|
|
|
|
instance.update( text, editor, node );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders any editing interface based on the view type.
|
|
|
|
*
|
|
|
|
* @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in.
|
|
|
|
* @param {HTMLElement} node The view node to edit.
|
|
|
|
*/
|
|
|
|
edit: function( editor, node ) {
|
2015-02-26 14:32:24 -05:00
|
|
|
var instance = this.getInstance( node );
|
2015-02-25 18:13:25 -05:00
|
|
|
|
|
|
|
if ( instance && instance.edit ) {
|
2015-02-26 14:32:24 -05:00
|
|
|
instance.edit( instance.text, function( text ) {
|
2015-02-25 18:13:25 -05:00
|
|
|
instance.update( text, editor, node );
|
|
|
|
} );
|
2014-03-05 02:01:14 -05:00
|
|
|
}
|
2015-02-26 14:32:24 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a given view node from the DOM.
|
|
|
|
*
|
|
|
|
* @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in.
|
|
|
|
* @param {HTMLElement} node The view node to remove.
|
|
|
|
*/
|
|
|
|
remove: function( editor, node ) {
|
|
|
|
var instance = this.getInstance( node );
|
|
|
|
|
|
|
|
if ( instance ) {
|
|
|
|
instance.remove( editor, node );
|
|
|
|
}
|
2014-03-05 02:01:14 -05:00
|
|
|
}
|
|
|
|
};
|
2012-10-11 23:28:22 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2015-02-26 14:32:24 -05:00
|
|
|
* @param {Object} options Options.
|
2015-02-25 18:13:25 -05:00
|
|
|
*/
|
|
|
|
wp.mce.View = function( options ) {
|
|
|
|
_.extend( this, options );
|
|
|
|
this.initialize();
|
|
|
|
};
|
2014-03-05 02:01:14 -05:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
wp.mce.View.extend = Backbone.View.extend;
|
2014-03-05 02:01:14 -05:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
_.extend( wp.mce.View.prototype, {
|
2012-10-11 19:52:09 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* The content.
|
|
|
|
*
|
|
|
|
* @type {*}
|
|
|
|
*/
|
|
|
|
content: null,
|
2014-08-17 23:59:17 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* Whether or not to display a loader.
|
|
|
|
*
|
|
|
|
* @type {Boolean}
|
|
|
|
*/
|
|
|
|
loader: true,
|
2012-10-11 19:52:09 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* Runs after the view instance is created.
|
|
|
|
*/
|
|
|
|
initialize: function() {},
|
2014-03-05 02:01:14 -05:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* Retuns the content to render in the view node.
|
|
|
|
*
|
|
|
|
* @return {*}
|
|
|
|
*/
|
|
|
|
getContent: function() {
|
|
|
|
return this.content;
|
|
|
|
},
|
2014-03-05 02:01:14 -05:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* Renders all view nodes tied to this view instance that are not yet rendered.
|
|
|
|
*
|
2015-04-04 19:00:26 -04:00
|
|
|
* @param {String} content The content to render. Optional.
|
2015-02-25 18:13:25 -05:00
|
|
|
* @param {Boolean} force Rerender all view nodes tied to this view instance.
|
|
|
|
*/
|
2015-04-04 19:00:26 -04:00
|
|
|
render: function( content, force ) {
|
|
|
|
if ( content != null ) {
|
|
|
|
this.content = content;
|
|
|
|
}
|
|
|
|
|
|
|
|
content = this.getContent();
|
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
// If there's nothing to render an no loader needs to be shown, stop.
|
2015-04-04 19:00:26 -04:00
|
|
|
if ( ! this.loader && ! content ) {
|
2015-02-25 18:13:25 -05:00
|
|
|
return;
|
|
|
|
}
|
2014-03-17 23:25:14 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
// We're about to rerender all views of this instance, so unbind rendered views.
|
|
|
|
force && this.unbind();
|
|
|
|
|
|
|
|
// Replace any left over markers.
|
|
|
|
this.replaceMarkers();
|
2012-10-11 19:52:09 -04:00
|
|
|
|
2015-04-04 19:00:26 -04:00
|
|
|
if ( content ) {
|
2015-04-21 14:36:24 -04:00
|
|
|
this.setContent( content, function( editor, node, contentNode ) {
|
2015-04-04 19:00:26 -04:00
|
|
|
$( node ).data( 'rendered', true );
|
2015-04-21 14:36:24 -04:00
|
|
|
this.bindNode.call( this, editor, node, contentNode );
|
2015-02-25 18:13:25 -05:00
|
|
|
}, force ? null : false );
|
|
|
|
} else {
|
|
|
|
this.setLoader();
|
2014-03-05 02:01:14 -05:00
|
|
|
}
|
2014-06-05 13:27:13 -04:00
|
|
|
},
|
2014-03-05 02:01:14 -05:00
|
|
|
|
2015-04-04 19:00:26 -04:00
|
|
|
/**
|
|
|
|
* Binds a given node after its content is added to the DOM.
|
|
|
|
*/
|
|
|
|
bindNode: function() {},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbinds a given node before its content is removed from the DOM.
|
|
|
|
*/
|
|
|
|
unbindNode: function() {},
|
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* Unbinds all view nodes tied to this view instance.
|
|
|
|
* Runs before their content is removed from the DOM.
|
|
|
|
*/
|
|
|
|
unbind: function() {
|
2015-04-21 14:36:24 -04:00
|
|
|
this.getNodes( function( editor, node, contentNode ) {
|
|
|
|
this.unbindNode.call( this, editor, node, contentNode );
|
2015-02-26 14:32:24 -05:00
|
|
|
$( node ).trigger( 'wp-mce-view-unbind' );
|
2015-02-25 18:13:25 -05:00
|
|
|
}, true );
|
|
|
|
},
|
2014-03-26 08:11:14 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* 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 );
|
|
|
|
},
|
2014-07-15 18:18:14 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* 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 ) {
|
2014-07-16 18:10:16 -04:00
|
|
|
var self = this;
|
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
$( editor.getBody() )
|
|
|
|
.find( '[data-wpview-text="' + self.encodedText + '"]' )
|
|
|
|
.filter( function() {
|
|
|
|
var data;
|
2014-07-15 18:18:14 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
if ( rendered == null ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = $( this ).data( 'rendered' ) === true;
|
2014-07-16 14:19:14 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
return rendered ? data : ! data;
|
|
|
|
} )
|
|
|
|
.each( function() {
|
|
|
|
callback.call( self, editor, this, $( this ).find( '.wpview-content' ).get( 0 ) );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
},
|
2014-06-05 13:27:13 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* Gets all marker nodes tied to this view instance.
|
|
|
|
*
|
|
|
|
* @param {Function} callback A callback.
|
|
|
|
*/
|
|
|
|
getMarkers: function( callback ) {
|
|
|
|
this.getEditors( function( editor ) {
|
|
|
|
var self = this;
|
2014-07-16 18:10:16 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
$( editor.getBody() )
|
|
|
|
.find( '[data-wpview-marker="' + this.encodedText + '"]' )
|
|
|
|
.each( function() {
|
|
|
|
callback.call( self, editor, this );
|
2014-11-30 03:45:22 -05:00
|
|
|
} );
|
2015-02-25 18:13:25 -05:00
|
|
|
} );
|
|
|
|
},
|
2014-11-30 03:45:22 -05:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* Replaces all marker nodes tied to this view instance.
|
|
|
|
*/
|
|
|
|
replaceMarkers: function() {
|
|
|
|
this.getMarkers( function( editor, node ) {
|
2015-03-04 15:35:27 -05:00
|
|
|
if ( $( node ).text() !== this.text ) {
|
2015-02-25 18:13:25 -05:00
|
|
|
editor.dom.setAttrib( node, 'data-wpview-marker', null );
|
|
|
|
return;
|
|
|
|
}
|
2014-11-30 03:45:22 -05:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
editor.dom.replace(
|
|
|
|
editor.dom.createFragment(
|
|
|
|
'<div class="wpview-wrap" data-wpview-text="' + this.encodedText + '" data-wpview-type="' + this.type + '">' +
|
|
|
|
'<p class="wpview-selection-before">\u00a0</p>' +
|
|
|
|
'<div class="wpview-body" contenteditable="false">' +
|
|
|
|
'<div class="wpview-content wpview-type-' + this.type + '"></div>' +
|
|
|
|
'</div>' +
|
|
|
|
'<p class="wpview-selection-after">\u00a0</p>' +
|
|
|
|
'</div>'
|
|
|
|
),
|
|
|
|
node
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
},
|
2014-11-30 03:45:22 -05:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* Removes all marker nodes tied to this view instance.
|
|
|
|
*/
|
|
|
|
removeMarkers: function() {
|
|
|
|
this.getMarkers( function( editor, node ) {
|
|
|
|
editor.dom.setAttrib( node, 'data-wpview-marker', null );
|
|
|
|
} );
|
|
|
|
},
|
2014-11-30 03:45:22 -05:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* 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( '<script' ) !== -1 ) {
|
2015-03-11 19:53:26 -04:00
|
|
|
this.setIframes( content.head || '', content.body, callback, rendered );
|
2015-02-25 18:13:25 -05:00
|
|
|
} else if ( _.isString( content ) && content.indexOf( '<script' ) !== -1 ) {
|
2015-03-11 19:53:26 -04:00
|
|
|
this.setIframes( '', content, callback, rendered );
|
2015-02-25 18:13:25 -05:00
|
|
|
} else {
|
|
|
|
this.getNodes( function( editor, node, contentNode ) {
|
|
|
|
content = content.body || content;
|
2014-11-30 03:45:22 -05:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
if ( content.indexOf( '<iframe' ) !== -1 ) {
|
|
|
|
content += '<div class="wpview-overlay"></div>';
|
2014-11-30 03:45:22 -05:00
|
|
|
}
|
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
contentNode.innerHTML = '';
|
|
|
|
contentNode.appendChild( _.isString( content ) ? editor.dom.createFragment( content ) : content );
|
2014-11-30 03:45:22 -05:00
|
|
|
|
2015-04-04 19:00:26 -04:00
|
|
|
callback && callback.call( this, editor, node, contentNode );
|
2015-02-25 18:13:25 -05:00
|
|
|
}, rendered );
|
|
|
|
}
|
|
|
|
},
|
2014-06-05 13:27:13 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* Sets the content in an iframe for all view nodes tied to this view instance.
|
|
|
|
*
|
|
|
|
* @param {String} head HTML string to be added to the head of the document.
|
|
|
|
* @param {String} body HTML string to be added to the body of the document.
|
|
|
|
* @param {Function} callback A callback. Optional.
|
|
|
|
* @param {Boolean} rendered Only set for (un)rendered nodes. Optional.
|
|
|
|
*/
|
|
|
|
setIframes: function( head, body, callback, rendered ) {
|
2015-04-04 19:00:26 -04:00
|
|
|
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver,
|
|
|
|
self = this;
|
2014-06-05 13:27:13 -04:00
|
|
|
|
2015-04-21 14:36:24 -04:00
|
|
|
this.getNodes( function( editor, node, contentNode ) {
|
2015-04-04 19:00:26 -04:00
|
|
|
var dom = editor.dom,
|
|
|
|
styles = '',
|
|
|
|
bodyClasses = editor.getBody().className || '',
|
2015-04-06 14:55:28 -04:00
|
|
|
editorHead = editor.getDoc().getElementsByTagName( 'head' )[0];
|
2015-04-04 19:00:26 -04:00
|
|
|
|
|
|
|
tinymce.each( dom.$( 'link[rel="stylesheet"]', editorHead ), function( link ) {
|
|
|
|
if ( link.href && link.href.indexOf( 'skins/lightgray/content.min.css' ) === -1 &&
|
|
|
|
link.href.indexOf( 'skins/wordpress/wp-content.css' ) === -1 ) {
|
|
|
|
|
|
|
|
styles += dom.getOuterHTML( link );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Seems the browsers need a bit of time to insert/set the view nodes,
|
2015-02-25 18:13:25 -05:00
|
|
|
// or the iframe will fail especially when switching Text => Visual.
|
|
|
|
setTimeout( function() {
|
2015-04-06 14:55:28 -04:00
|
|
|
var iframe, iframeDoc, observer, i;
|
|
|
|
|
2015-04-21 14:36:24 -04:00
|
|
|
contentNode.innerHTML = '';
|
2015-03-11 19:53:26 -04:00
|
|
|
|
2015-04-21 14:36:24 -04:00
|
|
|
iframe = dom.add( contentNode, 'iframe', {
|
2015-02-25 18:13:25 -05:00
|
|
|
/* jshint scripturl: true */
|
|
|
|
src: tinymce.Env.ie ? 'javascript:""' : '',
|
|
|
|
frameBorder: '0',
|
|
|
|
allowTransparency: 'true',
|
|
|
|
scrolling: 'no',
|
|
|
|
'class': 'wpview-sandbox',
|
|
|
|
style: {
|
|
|
|
width: '100%',
|
|
|
|
display: 'block'
|
|
|
|
}
|
|
|
|
} );
|
2014-08-22 14:55:15 -04:00
|
|
|
|
2015-04-21 14:36:24 -04:00
|
|
|
dom.add( contentNode, 'div', { 'class': 'wpview-overlay' } );
|
2015-02-25 18:13:25 -05:00
|
|
|
|
|
|
|
iframeDoc = iframe.contentWindow.document;
|
|
|
|
|
|
|
|
iframeDoc.open();
|
|
|
|
|
|
|
|
iframeDoc.write(
|
|
|
|
'<!DOCTYPE html>' +
|
|
|
|
'<html>' +
|
|
|
|
'<head>' +
|
|
|
|
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' +
|
|
|
|
head +
|
|
|
|
styles +
|
|
|
|
'<style>' +
|
|
|
|
'html {' +
|
|
|
|
'background: transparent;' +
|
|
|
|
'padding: 0;' +
|
|
|
|
'margin: 0;' +
|
|
|
|
'}' +
|
|
|
|
'body#wpview-iframe-sandbox {' +
|
|
|
|
'background: transparent;' +
|
|
|
|
'padding: 1px 0 !important;' +
|
|
|
|
'margin: -1px 0 0 !important;' +
|
|
|
|
'}' +
|
|
|
|
'body#wpview-iframe-sandbox:before,' +
|
|
|
|
'body#wpview-iframe-sandbox:after {' +
|
|
|
|
'display: none;' +
|
|
|
|
'content: "";' +
|
|
|
|
'}' +
|
|
|
|
'</style>' +
|
|
|
|
'</head>' +
|
|
|
|
'<body id="wpview-iframe-sandbox" class="' + bodyClasses + '">' +
|
|
|
|
body +
|
|
|
|
'</body>' +
|
|
|
|
'</html>'
|
|
|
|
);
|
|
|
|
|
|
|
|
iframeDoc.close();
|
|
|
|
|
2015-03-07 11:53:27 -05:00
|
|
|
function resize() {
|
2015-02-25 18:13:25 -05:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2015-03-07 11:53:27 -05:00
|
|
|
}
|
2015-02-25 18:13:25 -05:00
|
|
|
|
2015-04-06 14:55:28 -04:00
|
|
|
$( iframe.contentWindow ).on( 'load', resize );
|
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
if ( MutationObserver ) {
|
2015-03-07 11:53:27 -05:00
|
|
|
observer = new MutationObserver( _.debounce( resize, 100 ) );
|
2015-02-26 14:32:24 -05:00
|
|
|
|
|
|
|
observer.observe( iframeDoc.body, {
|
2015-02-25 18:13:25 -05:00
|
|
|
attributes: true,
|
|
|
|
childList: true,
|
|
|
|
subtree: true
|
|
|
|
} );
|
2015-03-07 11:53:27 -05:00
|
|
|
|
|
|
|
$( node ).one( 'wp-mce-view-unbind', function() {
|
|
|
|
observer.disconnect();
|
|
|
|
} );
|
2014-08-22 14:55:15 -04:00
|
|
|
} else {
|
2015-02-25 18:13:25 -05:00
|
|
|
for ( i = 1; i < 6; i++ ) {
|
|
|
|
setTimeout( resize, i * 700 );
|
|
|
|
}
|
2014-08-22 14:55:15 -04:00
|
|
|
}
|
2014-06-05 13:27:13 -04:00
|
|
|
|
2015-02-26 14:32:24 -05:00
|
|
|
function classChange() {
|
|
|
|
iframeDoc.body.className = editor.getBody().className;
|
|
|
|
}
|
|
|
|
|
2015-03-11 21:05:54 -04:00
|
|
|
editor.on( 'wp-body-class-change', classChange );
|
2015-02-26 14:32:24 -05:00
|
|
|
|
2015-03-11 21:05:54 -04:00
|
|
|
$( node ).one( 'wp-mce-view-unbind', function() {
|
|
|
|
editor.off( 'wp-body-class-change', classChange );
|
|
|
|
} );
|
2014-07-16 15:32:16 -04:00
|
|
|
|
2015-04-21 14:36:24 -04:00
|
|
|
callback && callback.call( self, editor, node, contentNode );
|
2015-03-11 19:53:26 -04:00
|
|
|
}, 50 );
|
2015-02-25 18:13:25 -05:00
|
|
|
}, rendered );
|
|
|
|
},
|
2014-07-16 15:32:16 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* Sets a loader for all view nodes tied to this view instance.
|
|
|
|
*/
|
|
|
|
setLoader: function() {
|
|
|
|
this.setContent(
|
|
|
|
'<div class="loading-placeholder">' +
|
|
|
|
'<div class="dashicons dashicons-admin-media"></div>' +
|
|
|
|
'<div class="wpview-loading"><ins></ins></div>' +
|
|
|
|
'</div>'
|
|
|
|
);
|
|
|
|
},
|
2014-07-22 17:49:16 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* 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(
|
|
|
|
'<div class="wpview-error">' +
|
|
|
|
'<div class="dashicons dashicons-' + ( dashicon || 'no' ) + '"></div>' +
|
|
|
|
'<p>' + message + '</p>' +
|
|
|
|
'</div>'
|
|
|
|
);
|
|
|
|
},
|
2014-07-16 14:19:14 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
}
|
|
|
|
};
|
2014-06-05 13:27:13 -04:00
|
|
|
}
|
2014-07-15 18:18:14 -04:00
|
|
|
},
|
2014-03-26 08:11:14 -04:00
|
|
|
|
|
|
|
/**
|
2015-02-25 18:13:25 -05:00
|
|
|
* Update the text of a given view node.
|
2014-03-26 08:11:14 -04:00
|
|
|
*
|
2015-02-25 18:13:25 -05:00
|
|
|
* @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.
|
2014-03-26 08:11:14 -04:00
|
|
|
*/
|
2015-02-25 18:13:25 -05:00
|
|
|
update: function( text, editor, node ) {
|
2015-02-27 17:29:26 -05:00
|
|
|
_.find( views, function( view, type ) {
|
|
|
|
var match = view.prototype.match( text );
|
|
|
|
|
|
|
|
if ( match ) {
|
|
|
|
$( node ).data( 'rendered', false );
|
|
|
|
editor.dom.setAttrib( node, 'data-wpview-text', encodeURIComponent( text ) );
|
|
|
|
wp.mce.views.createInstance( type, text, match.options ).render();
|
2015-04-01 17:50:27 -04:00
|
|
|
editor.focus();
|
2015-02-27 17:29:26 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} );
|
2015-02-26 14:32:24 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a given view node from the DOM.
|
|
|
|
*
|
|
|
|
* @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in.
|
|
|
|
* @param {HTMLElement} node The view node to remove.
|
|
|
|
*/
|
|
|
|
remove: function( editor, node ) {
|
2015-04-04 19:00:26 -04:00
|
|
|
this.unbindNode.call( this, editor, node, $( node ).find( '.wpview-content' ).get( 0 ) );
|
2015-02-26 14:32:24 -05:00
|
|
|
$( node ).trigger( 'wp-mce-view-unbind' );
|
|
|
|
editor.dom.remove( node );
|
2015-04-01 17:50:27 -04:00
|
|
|
editor.focus();
|
2015-02-25 18:13:25 -05:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
} )( 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 ) {
|
2014-06-18 19:03:15 -04:00
|
|
|
var media = wp.media[ this.type ],
|
2015-02-25 18:13:25 -05:00
|
|
|
frame = media.edit( text );
|
|
|
|
|
2015-02-25 19:31:31 -05:00
|
|
|
this.pausePlayers && this.pausePlayers();
|
2014-03-26 08:11:14 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
_.each( this.state, function( state ) {
|
|
|
|
frame.state( state ).on( 'update', function( selection ) {
|
|
|
|
update( media.shortcode( selection ).string() );
|
|
|
|
} );
|
|
|
|
} );
|
2014-03-26 08:11:14 -04:00
|
|
|
|
|
|
|
frame.on( 'close', function() {
|
|
|
|
frame.detach();
|
|
|
|
} );
|
2015-02-26 14:32:24 -05:00
|
|
|
|
|
|
|
frame.open();
|
2015-02-25 18:13:25 -05:00
|
|
|
}
|
|
|
|
};
|
2014-03-27 13:58:15 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2014-03-27 13:58:15 -04:00
|
|
|
} );
|
2015-02-25 18:13:25 -05:00
|
|
|
|
2015-04-04 19:00:26 -04:00
|
|
|
self.render( self.template( {
|
2015-02-25 18:13:25 -05:00
|
|
|
attachments: attachments,
|
|
|
|
columns: attrs.columns ? parseInt( attrs.columns, 10 ) : wp.media.galleryDefaults.columns
|
2015-04-04 19:00:26 -04:00
|
|
|
} ) );
|
2015-02-25 18:13:25 -05:00
|
|
|
} )
|
|
|
|
.fail( function( jqXHR, textStatus ) {
|
|
|
|
self.setError( textStatus );
|
|
|
|
} );
|
2014-03-26 08:11:14 -04:00
|
|
|
}
|
2015-02-25 18:13:25 -05:00
|
|
|
} );
|
2014-03-26 08:11:14 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
av = _.extend( {}, media, {
|
|
|
|
action: 'parse-media-shortcode',
|
2014-03-26 08:11:14 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
initialize: function() {
|
|
|
|
var self = this;
|
2014-03-26 08:11:14 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
if ( this.url ) {
|
|
|
|
this.loader = false;
|
|
|
|
this.shortcode = wp.media.embed.shortcode( {
|
2015-03-09 15:09:27 -04:00
|
|
|
url: this.text
|
2015-02-25 18:13:25 -05:00
|
|
|
} );
|
|
|
|
}
|
2014-05-10 19:36:18 -04:00
|
|
|
|
2015-04-04 19:00:26 -04:00
|
|
|
wp.ajax.post( this.action, {
|
|
|
|
post_ID: postID,
|
|
|
|
type: this.shortcode.tag,
|
|
|
|
shortcode: this.shortcode.string()
|
2015-02-25 18:13:25 -05:00
|
|
|
} )
|
|
|
|
.done( function( response ) {
|
2015-04-04 19:00:26 -04:00
|
|
|
self.render( response );
|
2015-02-25 18:13:25 -05:00
|
|
|
} )
|
|
|
|
.fail( function( response ) {
|
2015-02-25 19:31:31 -05:00
|
|
|
if ( self.url ) {
|
2015-02-25 18:13:25 -05:00
|
|
|
self.removeMarkers();
|
2014-06-11 22:49:16 -04:00
|
|
|
} else {
|
2015-02-25 18:13:25 -05:00
|
|
|
self.setError( response.message || response.statusText, 'admin-media' );
|
2014-05-10 19:36:18 -04:00
|
|
|
}
|
2015-02-25 18:13:25 -05:00
|
|
|
} );
|
2014-06-11 22:49:16 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
this.getEditors( function( editor ) {
|
|
|
|
editor.on( 'wpview-selected', function() {
|
2015-02-25 19:31:31 -05:00
|
|
|
self.pausePlayers();
|
2015-02-25 18:13:25 -05:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
},
|
2014-06-13 17:42:15 -04:00
|
|
|
|
2015-02-25 19:31:31 -05:00
|
|
|
pausePlayers: function() {
|
2015-02-25 18:13:25 -05:00
|
|
|
this.getNodes( function( editor, node, content ) {
|
|
|
|
var win = $( 'iframe.wpview-sandbox', content ).get( 0 );
|
2014-06-13 17:42:15 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
if ( win && ( win = win.contentWindow ) && win.mejs ) {
|
|
|
|
_.each( win.mejs.players, function( player ) {
|
|
|
|
try {
|
2015-02-25 19:31:31 -05:00
|
|
|
player.pause();
|
2015-02-25 18:13:25 -05:00
|
|
|
} catch ( e ) {}
|
|
|
|
} );
|
|
|
|
}
|
2014-06-13 17:42:15 -04:00
|
|
|
} );
|
2015-02-25 18:13:25 -05:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
embed = _.extend( {}, av, {
|
|
|
|
action: 'parse-embed',
|
|
|
|
|
|
|
|
edit: function( text, update ) {
|
|
|
|
var media = wp.media.embed,
|
2015-03-09 15:09:27 -04:00
|
|
|
frame = media.edit( text, this.url ),
|
2015-04-21 18:41:26 -04:00
|
|
|
self = this;
|
2015-02-25 18:13:25 -05:00
|
|
|
|
2015-02-25 19:31:31 -05:00
|
|
|
this.pausePlayers();
|
2015-02-25 18:13:25 -05:00
|
|
|
|
2015-04-21 18:41:26 -04:00
|
|
|
frame.state( 'embed' ).props.on( 'change:url', function( model, url ) {
|
2015-03-05 01:00:26 -05:00
|
|
|
if ( url && model.get( 'url' ) ) {
|
2015-02-25 18:13:25 -05:00
|
|
|
frame.state( 'embed' ).metadata = model.toJSON();
|
2014-06-13 17:42:15 -04:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
frame.state( 'embed' ).on( 'select', function() {
|
2015-03-05 01:00:26 -05:00
|
|
|
var data = frame.state( 'embed' ).metadata;
|
|
|
|
|
2015-04-21 18:41:26 -04:00
|
|
|
if ( self.url ) {
|
2015-03-05 01:00:26 -05:00
|
|
|
update( data.url );
|
2014-06-13 17:42:15 -04:00
|
|
|
} else {
|
2015-03-05 01:00:26 -05:00
|
|
|
update( media.shortcode( data ).string() );
|
2014-06-13 17:42:15 -04:00
|
|
|
}
|
2015-02-25 18:13:25 -05:00
|
|
|
} );
|
|
|
|
|
|
|
|
frame.on( 'close', function() {
|
2014-06-13 17:42:15 -04:00
|
|
|
frame.detach();
|
|
|
|
} );
|
2015-02-25 18:13:25 -05:00
|
|
|
|
2014-06-13 17:42:15 -04:00
|
|
|
frame.open();
|
|
|
|
}
|
2015-02-25 18:13:25 -05:00
|
|
|
} );
|
|
|
|
|
|
|
|
views.register( 'gallery', _.extend( {}, gallery ) );
|
|
|
|
|
|
|
|
views.register( 'audio', _.extend( {}, av, {
|
|
|
|
state: [ 'audio-details' ]
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
views.register( 'video', _.extend( {}, av, {
|
|
|
|
state: [ 'video-details' ]
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
views.register( 'playlist', _.extend( {}, av, {
|
|
|
|
state: [ 'playlist-edit', 'video-playlist-edit' ]
|
|
|
|
} ) );
|
2014-06-11 22:49:16 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
views.register( 'embed', _.extend( {}, embed ) );
|
2014-06-13 17:42:15 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
views.register( 'embedURL', _.extend( {}, embed, {
|
|
|
|
match: function( content ) {
|
2015-02-20 18:17:27 -05:00
|
|
|
var re = /(^|<p>)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi,
|
2015-02-25 19:31:31 -05:00
|
|
|
match = re.exec( content );
|
2014-06-11 22:49:16 -04:00
|
|
|
|
2015-02-25 18:13:25 -05:00
|
|
|
if ( match ) {
|
|
|
|
return {
|
|
|
|
index: match.index + match[1].length,
|
|
|
|
content: match[2],
|
|
|
|
options: {
|
2015-03-09 15:09:27 -04:00
|
|
|
url: true
|
2015-02-25 18:13:25 -05:00
|
|
|
}
|
|
|
|
};
|
2014-06-11 22:49:16 -04:00
|
|
|
}
|
2014-06-13 17:42:15 -04:00
|
|
|
}
|
|
|
|
} ) );
|
2015-02-25 18:13:25 -05:00
|
|
|
} )( window, window.wp.mce.views, window.jQuery );
|