diff --git src/wp-includes/js/mce-view.js src/wp-includes/js/mce-view.js
index afd60fa..4be697e 100644
|
|
|
window.wp = window.wp || {}; |
| 550 | 550 | this.data = {}; |
| 551 | 551 | this.attachments = []; |
| 552 | 552 | this.shortcode = options.shortcode; |
| 553 | | _.bindAll( this, 'setPlayer' ); |
| 554 | | $(this).on('ready', this.setNode); |
| 555 | | }, |
| 556 | | |
| 557 | | /** |
| 558 | | * Set the element context for the view, and then fetch the playlist's |
| 559 | | * associated attachments. |
| 560 | | * |
| 561 | | * @param {Event} e |
| 562 | | * @param {HTMLElement} node |
| 563 | | */ |
| 564 | | setNode: function(e, node) { |
| 565 | | this.node = node; |
| 566 | 553 | this.fetch(); |
| 567 | 554 | }, |
| 568 | 555 | |
| | 556 | |
| 569 | 557 | /** |
| 570 | 558 | * Asynchronously fetch the shortcode's attachments |
| 571 | 559 | */ |
| 572 | 560 | fetch: function() { |
| 573 | 561 | this.attachments = wp.media.playlist.attachments( this.shortcode ); |
| 574 | | this.attachments.more().done( this.setPlayer ); |
| | 562 | this.dfd = this.attachments.more().done( _.bind( this.render, this ) ); |
| 575 | 563 | }, |
| 576 | 564 | |
| 577 | | /** |
| 578 | | * Get the HTML for the view (which also set's the data), replace the |
| 579 | | * current HTML, and then invoke the WPPlaylistView instance to render |
| 580 | | * the playlist in the editor |
| 581 | | * |
| 582 | | * @global WPPlaylistView |
| 583 | | * @global tinymce.editors |
| 584 | | */ |
| 585 | | setPlayer: function() { |
| 586 | | var p, |
| 587 | | html = this.getHtml(), |
| 588 | | t = this.encodedText, |
| 589 | | self = this; |
| 590 | | |
| 591 | | this.unsetPlayer(); |
| 592 | | |
| 593 | | _.each( tinymce.editors, function( editor ) { |
| 594 | | var doc; |
| 595 | | if ( editor.plugins.wpview ) { |
| 596 | | doc = editor.getDoc(); |
| 597 | | $( doc ).find( '[data-wpview-text="' + t + '"]' ).each(function(i, elem) { |
| 598 | | var node = $( elem ); |
| 599 | | node.html( html ); |
| 600 | | self.node = elem; |
| 601 | | }); |
| 602 | | } |
| 603 | | }, this ); |
| 604 | | |
| 605 | | if ( ! this.data.tracks ) { |
| 606 | | return; |
| 607 | | } |
| 608 | | |
| 609 | | p = new WPPlaylistView({ |
| 610 | | el: $( self.node ).find( '.wp-playlist' ).get(0), |
| 611 | | metadata: this.data |
| 612 | | }); |
| 613 | | |
| 614 | | this.player = p._player; |
| 615 | | }, |
| 616 | 565 | |
| 617 | 566 | /** |
| 618 | 567 | * Set the data that will be used to compile the Underscore template, |
| … |
… |
window.wp = window.wp || {}; |
| 695 | 644 | this.data = options; |
| 696 | 645 | |
| 697 | 646 | return this.template( options ); |
| | 647 | }, |
| | 648 | |
| | 649 | render: function() { |
| | 650 | var html = this.getHtml(); |
| | 651 | // Search all tinymce editor instances and update the placeholders |
| | 652 | _.each( tinymce.editors, function( editor ) { |
| | 653 | var doc, |
| | 654 | self = this; |
| | 655 | if ( editor.plugins.wpview ) { |
| | 656 | doc = editor.getDoc(); |
| | 657 | |
| | 658 | self.unsetPlayer(); |
| | 659 | |
| | 660 | $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each(function (i, elem) { |
| | 661 | var node = $( elem ), |
| | 662 | player; |
| | 663 | |
| | 664 | // The <ins> is used to mark the end of the wrapper div. Needed when comparing |
| | 665 | // the content as string for preventing extra undo levels. |
| | 666 | node.html( html ).append( '<ins data-wpview-end="1"></ins>' ); |
| | 667 | |
| | 668 | if ( ! self.data.tracks ) { |
| | 669 | return; |
| | 670 | } |
| | 671 | |
| | 672 | player = new WPPlaylistView({ |
| | 673 | el: $( elem ).find( '.wp-playlist' ).get(0), |
| | 674 | metadata: self.data |
| | 675 | }); |
| | 676 | |
| | 677 | self.player = player._player; |
| | 678 | }); |
| | 679 | } |
| | 680 | }, this ); |
| 698 | 681 | } |
| 699 | 682 | }); |
| 700 | 683 | _.extend( wp.mce.media.PlaylistView.prototype, wp.media.mixin ); |