mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-25 10:38:11 +01:00
eddc48def7
Fixes #27509. Built from https://develop.svn.wordpress.org/trunk@27733 git-svn-id: http://core.svn.wordpress.org/trunk@27570 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
6.9 KiB
JavaScript
1 line
6.9 KiB
JavaScript
window.wp=window.wp||{},function(a){var b={},c={},d=wp.media,e=["encodedText"];wp.mce=wp.mce||{},wp.mce.View=function(a){a||(a={}),_.extend(this,_.pick(a,e)),this.initialize.apply(this,arguments)},_.extend(wp.mce.View.prototype,{initialize:function(){},html:function(){},render:function(){var b=this.getHtml();_.each(tinymce.editors,function(c){var d,e=this;c.plugins.wpview&&(d=c.getDoc(),a(d).find('[data-wpview-text="'+this.encodedText+'"]').each(function(c,d){var f=a(d);f.html(b),a(e).trigger("ready",d)}))},this)}}),wp.mce.View.extend=Backbone.View.extend,wp.mce.views={register:function(a,c){b[a]=c},get:function(a){return b[a]},unregister:function(a){delete b[a]},toViews:function(a){var c,d=[{content:a}];return _.each(b,function(a,b){c=d.slice(),d=[],_.each(c,function(c){var e,f=c.content;if(c.processed)return void d.push(c);for(;f&&(e=a.toView(f));)e.index&&d.push({content:f.substring(0,e.index)}),d.push({content:wp.mce.views.toView(b,e.content,e.options),processed:!0}),f=f.slice(e.index+e.content.length);f&&d.push({content:f})})}),_.pluck(d,"content").join("")},toView:function(a,b,d){var e,f,g=wp.mce.views.get(a),h=window.encodeURIComponent(b);return g?(wp.mce.views.getInstance(h)||(f=d,f.encodedText=h,e=new g.View(f),c[h]=e),wp.html.string({tag:"div",attrs:{"class":"wpview-wrap wpview-type-"+a,"data-wpview-text":h,"data-wpview-type":a,contenteditable:"false"},content:" "})):b},refreshView:function(a,b){var d,e,f,g=window.encodeURIComponent(b);f=wp.mce.views.getInstance(g),f||(e=a.toView(b),d=e.options,d.encodedText=g,f=new a.View(d),c[g]=f),wp.mce.views.render()},getInstance:function(a){return c[a]},render:function(){_.each(c,function(a){a.render()})},edit:function(b){var c=a(b).data("wpview-type"),d=wp.mce.views.get(c);d&&d.edit(b)}},wp.mce.gallery={shortcode:"gallery",toView:function(a){var b=wp.shortcode.next(this.shortcode,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}},View:wp.mce.View.extend({className:"editor-gallery",template:d.template("editor-gallery"),postID:a("#post_ID").val(),initialize:function(a){this.shortcode=a.shortcode,this.fetch()},fetch:function(){this.attachments=wp.media.gallery.attachments(this.shortcode,this.postID),this.attachments.more().done(_.bind(this.render,this))},getHtml:function(){var a,b,c=this.shortcode.attrs.named;if(this.attachments.length)return b=this.attachments.toJSON(),_.each(b,function(a){a.thumbnail=a.sizes.thumbnail?a.sizes.thumbnail:a.sizes.full}),a={attachments:b,columns:c.columns?parseInt(c.columns,10):3},this.template(a)}}),edit:function(b){var c,d,e=wp.media.gallery,f=this;d=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=e.edit(d),c.state("gallery-edit").on("update",function(d){var g=e.shortcode(d).string();a(b).attr("data-wpview-text",window.encodeURIComponent(g)),wp.mce.views.refreshView(f,g),c.detach()})}},wp.mce.views.register("gallery",wp.mce.gallery),wp.mce.media={toView:function(a){var b=wp.shortcode.next(this.shortcode,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}},edit:function(b){var c,d,e=wp.media[this.shortcode],f=this;wp.media.mixin.pauseAllPlayers(),d=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=e.edit(d),c.on("close",function(){c.detach()}),c.state(f.state).on("update",function(d){var e=wp.media[f.shortcode].shortcode(d).string();a(b).attr("data-wpview-text",window.encodeURIComponent(e)),wp.mce.views.refreshView(f,e),c.detach()}),c.open()}},wp.mce.media.View=wp.mce.View.extend({initialize:function(b){this.shortcode=b.shortcode,_.bindAll(this,"setPlayer"),a(this).on("ready",this.setPlayer)},setPlayer:function(b,c){if(c){var d,e=this,f=this.ua.is("ff"),g=".wp-"+this.shortcode.tag+"-shortcode";if(this.player&&this.unsetPlayer(),d=a(c).find(g),!this.isCompatible(d))return d.closest(".wpview-wrap").addClass("wont-play"),d.parent().hasClass("wpview-wrap")||d.parent().replaceWith(d),void d.replaceWith("<p>"+d.find("source").eq(0).prop("src")+"</p>");d.closest(".wpview-wrap").removeClass("wont-play"),f?d.prop("preload","metadata"):d.prop("preload","none"),d=wp.media.view.MediaDetails.prepareSrc(d.get(0)),f?setTimeout(function(){e.player=new MediaElementPlayer(d,this.mejsSettings)},50):this.player=new MediaElementPlayer(d,this.mejsSettings)}},getHtml:function(){var a=_.defaults(this.shortcode.attrs.named,wp.media[this.shortcode.tag].defaults);return this.template({model:a})}}),_.extend(wp.mce.media.View.prototype,wp.media.mixin),wp.mce.video=_.extend({},wp.mce.media,{shortcode:"video",state:"video-details",View:wp.mce.media.View.extend({className:"editor-video",template:d.template("editor-video")})}),wp.mce.views.register("video",wp.mce.video),wp.mce.audio=_.extend({},wp.mce.media,{shortcode:"audio",state:"audio-details",View:wp.mce.media.View.extend({className:"editor-audio",template:d.template("editor-audio")})}),wp.mce.views.register("audio",wp.mce.audio),wp.mce.media.PlaylistView=wp.mce.View.extend({className:"editor-playlist",template:d.template("editor-playlist"),initialize:function(b){this.data={},this.attachments=[],this.shortcode=b.shortcode,_.bindAll(this,"setPlayer"),a(this).on("ready",this.setNode)},setNode:function(a,b){this.node=b,this.fetch()},fetch:function(){this.attachments=wp.media[this.shortcode.tag].attachments(this.shortcode),this.attachments.more().done(this.setPlayer)},setPlayer:function(){var b,c=this.getHtml(),d=this.encodedText,e=this;this.unsetPlayer(),_.each(tinymce.editors,function(b){var f;b.plugins.wpview&&(f=b.getDoc(),a(f).find('[data-wpview-text="'+d+'"]').each(function(b,d){var f=a(d);f.html(c),e.node=d}))},this),b=new WPPlaylistView({el:a(e.node).find(".wp-playlist").get(0),metadata:this.data}),this.player=b._player},getHtml:function(){var a,b,c=this.shortcode.attrs.named,e=wp.media[this.shortcode.tag],f="playlist"===this.shortcode.tag?"audio":"video",g=[];if(this.attachments.length)return _.each(e.defaults,function(a,b){c[b]=e.coerce(c,b)}),b=this.attachments.toJSON(),a={type:f,style:c.style,tracklist:c.tracklist,tracknumbers:c.tracknumbers,images:c.images,artists:c.artists},_.each(b,function(b){var c={},e={},h={src:b.url,type:b.mime,title:b.title,caption:b.caption,description:b.description,meta:b.meta};"video"===f?(c.width=b.width,c.height=b.height,d.view.settings.contentWidth?(e.width=d.view.settings.contentWidth-22,e.height=Math.ceil(c.height*e.width/c.width),a.width||(a.width=e.width,a.height=e.height)):a.width||(a.width=b.width,a.height=b.height),h.dimensions={original:c,resized:_.isEmpty(e)?c:e}):a.width=400,h.image=b.image,h.thumb=b.thumb,g.push(h)}),a.tracks=g,this.data=a,this.template(a)}}),_.extend(wp.mce.media.PlaylistView.prototype,wp.media.mixin),wp.mce.playlist=_.extend({},wp.mce.media,{shortcode:"playlist",state:"playlist-edit",View:wp.mce.media.PlaylistView}),wp.mce.views.register("playlist",wp.mce.playlist),wp.mce["video-playlist"]=_.extend({},wp.mce.media,{shortcode:"video-playlist",state:"video-playlist-edit",View:wp.mce.media.PlaylistView}),wp.mce.views.register("video-playlist",wp.mce["video-playlist"])}(jQuery); |