Ticket #31412: 31412.16.patch
File 31412.16.patch, 6.6 KB (added by , 10 years ago) |
---|
-
src/wp-includes/js/mce-view.js
64 64 * Returns the settings of a view type. 65 65 * 66 66 * @param {String} type The view type. 67 * 68 * @return {Function} The view constructor. 67 69 */ 68 70 get: function( type ) { 69 71 return views[ type ]; … … 142 144 * @param {String} type The view type. 143 145 * @param {String} text The textual representation of the view. 144 146 * @param {Object} options Options. 147 * 148 * @return {wp.mce.View} The view instance. 145 149 */ 146 150 createInstance: function( type, text, options ) { 147 151 var View = this.get( type ), … … 163 167 /** 164 168 * Get a view instance. 165 169 * 166 * @param {String} text The textual representation of the view. 170 * @param {(String|HTMLElement)} object The textual representation of the view or the view node. 171 * 172 * @return {wp.mce.View} The view instance. 167 173 */ 168 getInstance: function( text ) { 169 return instances[ encodeURIComponent( text ) ]; 174 getInstance: function( object ) { 175 if ( typeof object === 'string' ) { 176 return instances[ encodeURIComponent( object ) ]; 177 } 178 179 return instances[ $( object ).data( 'wpview-text' ) ]; 180 }, 181 182 /** 183 * Given a view node, get the view's text. 184 * 185 * @param {HTMLElement} node The view node. 186 * 187 * @return {String} The textual representation of the view. 188 */ 189 getText: function( node ) { 190 return decodeURIComponent( $( node ).data( 'wpview-text' ) || '' ); 170 191 }, 171 192 172 193 /** … … 188 209 * @param {HTMLElement} node The view node to update. 189 210 */ 190 211 update: function( text, editor, node ) { 191 var oldText = decodeURIComponent( $( node ).data( 'wpview-text' ) ), 192 instance = this.getInstance( oldText ); 212 var instance = this.getInstance( node ); 193 213 194 214 if ( instance ) { 195 215 instance.update( text, editor, node ); … … 203 223 * @param {HTMLElement} node The view node to edit. 204 224 */ 205 225 edit: function( editor, node ) { 206 var text = decodeURIComponent( $( node ).data( 'wpview-text' ) ), 207 instance = this.getInstance( text ); 226 var instance = this.getInstance( node ); 208 227 209 228 if ( instance && instance.edit ) { 210 instance.edit( text, function( text ) {229 instance.edit( instance.text, function( text ) { 211 230 instance.update( text, editor, node ); 212 231 } ); 213 232 } 233 }, 234 235 /** 236 * Remove a given view node from the DOM. 237 * 238 * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in. 239 * @param {HTMLElement} node The view node to remove. 240 */ 241 remove: function( editor, node ) { 242 var instance = this.getInstance( node ); 243 244 if ( instance ) { 245 instance.remove( editor, node ); 246 } 214 247 } 215 248 }; 216 249 … … 218 251 * A Backbone-like View constructor intended for use when rendering a TinyMCE View. 219 252 * The main difference is that the TinyMCE View is not tied to a particular DOM node. 220 253 * 221 * @param {Object} Options.254 * @param {Object} options Options. 222 255 */ 223 256 wp.mce.View = function( options ) { 224 257 _.extend( this, options ); … … 227 260 228 261 wp.mce.View.extend = Backbone.View.extend; 229 262 230 _.extend( wp.mce.View.prototype, {263 _.extend( wp.mce.View.prototype, Backbone.Events, { 231 264 232 265 /** 233 266 * The content. … … 275 308 this.replaceMarkers(); 276 309 277 310 if ( this.getContent() ) { 278 this.setContent( this.getContent(), function( editor, node ) {311 this.setContent( this.getContent(), function( editor, node, contentNode ) { 279 312 $( node ).data( 'rendered', true ); 280 this. bindNodes.apply( this, arguments);313 this.trigger( 'bind', editor, node, contentNode ); 281 314 }, force ? null : false ); 282 315 } else { 283 316 this.setLoader(); … … 285 318 }, 286 319 287 320 /** 288 * Binds a given rendered view node.289 * Runs after a view node's content is added to the DOM.290 *291 * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in.292 * @param {HTMLElement} node The view node.293 * @param {HTMLElement} contentNode The view's content node.294 */295 bindNodes: function( /* editor, node, contentNode */ ) {},296 297 /**298 321 * Unbinds all view nodes tied to this view instance. 299 322 * Runs before their content is removed from the DOM. 300 323 */ 301 324 unbind: function() { 302 this.getNodes( function( ) {303 this. unbindNodes.apply( this, arguments);325 this.getNodes( function( editor, node, contentNode ) { 326 this.trigger( 'unbind', editor, node, contentNode ); 304 327 }, true ); 305 328 }, 306 329 307 330 /** 308 * Unbinds a given view node.309 * Runs before the view node's content is removed from the DOM.310 *311 * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in.312 * @param {HTMLElement} node The view node.313 * @param {HTMLElement} contentNode The view's content node.314 */315 unbindNodes: function( /* editor, node, contentNode */ ) {},316 317 /**318 331 * Gets all the TinyMCE editor instances that support views. 319 332 * 320 333 * @param {Function} callback A callback. … … 631 644 $( node ).data( 'rendered', false ); 632 645 editor.dom.setAttrib( node, 'data-wpview-text', encodeURIComponent( text ) ); 633 646 wp.mce.views.createInstance( this.type, text, this.match( text ).options ).render(); 647 }, 648 649 /** 650 * Remove a given view node from the DOM. 651 * 652 * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in. 653 * @param {HTMLElement} node The view node to remove. 654 */ 655 remove: function( editor, node ) { 656 this.trigger( 'unbind', editor, node, $( node ).find( '.wpview-content' ).get( 0 ) ); 657 editor.dom.remove( node ); 634 658 } 635 659 } ); 636 660 } )( window, window.wp, window.jQuery ); -
src/wp-includes/js/tinymce/plugins/wpview/plugin.js
72 72 } 73 73 74 74 function removeView( view ) { 75 // TODO: trigger an event to run a clean up function.76 // Maybe `jQuery( view ).trigger( 'remove' );`?77 75 editor.undoManager.transact( function() { 78 76 handleEnter( view ); 79 editor.dom.remove(view );77 wp.mce.views.remove( editor, view ); 80 78 }); 81 79 } 82 80 … … 107 105 clipboard = dom.create( 'div', { 108 106 'class': 'wpview-clipboard', 109 107 'contenteditable': 'true' 110 }, decodeURIComponent( editor.dom.getAttrib( viewNode, 'data-wpview-text' )) );108 }, wp.mce.views.getText( viewNode ) ); 111 109 112 110 editor.dom.select( '.wpview-body', viewNode )[0].appendChild( clipboard ); 113 111