| | 676 | |
| | 677 | wp.mce.embed = { |
| | 678 | toView: function( content ) { |
| | 679 | var match = wp.shortcode.next( 'embed', content ); |
| | 680 | |
| | 681 | if ( ! match ) { |
| | 682 | return; |
| | 683 | } |
| | 684 | return { |
| | 685 | index: match.index, |
| | 686 | content: match.content, |
| | 687 | options: { |
| | 688 | content: match.content, |
| | 689 | shortcode: match.shortcode |
| | 690 | } |
| | 691 | }; |
| | 692 | }, |
| | 693 | View: wp.mce.View.extend({ |
| | 694 | className: 'oembed-data', |
| | 695 | initialize: function( options ) { |
| | 696 | this.content = options.content; |
| | 697 | this.parsed = false; |
| | 698 | _.bindAll( this, 'setHtml', 'setNode', 'fetch' ); |
| | 699 | $(this).on( 'ready', this.setNode ); |
| | 700 | }, |
| | 701 | |
| | 702 | setNode: function (e, node) { |
| | 703 | this.node = node; |
| | 704 | if ( ! this.parsed ) { |
| | 705 | this.fetch(); |
| | 706 | } else { |
| | 707 | this.parseMediaShortcodes(); |
| | 708 | } |
| | 709 | }, |
| | 710 | |
| | 711 | fetch: function () { |
| | 712 | $.ajax( { |
| | 713 | url : ajaxurl, |
| | 714 | type : 'post', |
| | 715 | data : { |
| | 716 | action: 'parse-content', |
| | 717 | post_ID: $( '#post_ID' ).val(), |
| | 718 | oembed_content: this.content |
| | 719 | } |
| | 720 | } ).done( this.setHtml ); |
| | 721 | }, |
| | 722 | |
| | 723 | setHtml: function (data) { |
| | 724 | this.parsed = data.content; |
| | 725 | $( this.node ).html( this.parsed ); |
| | 726 | |
| | 727 | this.parseMediaShortcodes(); |
| | 728 | }, |
| | 729 | |
| | 730 | parseMediaShortcodes: function () { |
| | 731 | $( '.wp-audio-shortcode, .wp-video-shortcode', this.node ).mediaelementplayer(); |
| | 732 | }, |
| | 733 | |
| | 734 | getHtml: function() { |
| | 735 | if ( ! this.parsed ) { |
| | 736 | return ''; |
| | 737 | } |
| | 738 | return this.parsed; |
| | 739 | } |
| | 740 | }), |
| | 741 | |
| | 742 | edit: function() {} |
| | 743 | }; |
| | 744 | wp.mce.views.register( 'embed', wp.mce.embed ); |