]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/mce-view.min.js
WordPress 4.3
[autoinstalls/wordpress.git] / wp-includes / js / mce-view.min.js
index 147f2a3d0d3405527bb07727d1de3182cf257959..d168b0d78c0a871b32f4d7680ef70a9d31e07a8b 100644 (file)
@@ -1 +1 @@
-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(){},getHtml: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).append('<ins data-wpview-end="1"></ins>'),a(e).trigger("ready",d)}))},this)},unbind:function(){}}),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]},unbind:function(){_.each(c,function(a){a.unbind()})},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.dfd=this.attachments.more().done(_.bind(this.render,this))},getHtml:function(){var a,b=this.shortcode.attrs.named,c=!1;if(!this.dfd||"pending"!==this.dfd.state()||this.attachments.length)return this.attachments.length&&(c=this.attachments.toJSON(),_.each(c,function(a){a.sizes&&(a.sizes.thumbnail?a.thumbnail=a.sizes.thumbnail:a.sizes.full&&(a.thumbnail=a.sizes.full))})),a={attachments:c,columns:b.columns?parseInt(b.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={loaded:!1,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,f=wp.media[this.shortcode],g=this;wp.media.mixin.pauseAllPlayers(),d=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=f.edit(d),c.on("close",function(){c.detach()}),e=function(d){var e=wp.media[g.shortcode].shortcode(d).string();a(b).attr("data-wpview-text",window.encodeURIComponent(e)),wp.mce.views.refreshView(g,e),c.detach()},_.isArray(g.state)?_.each(g.state,function(a){c.state(a).on("update",e)}):c.state(g.state).on("update",e),c.open()}},wp.mce.media.View=wp.mce.View.extend({initialize:function(b){this.players=[],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(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)),setTimeout(function(){wp.mce.media.loaded=!0,e.players.push(new MediaElementPlayer(d,e.mejsSettings))},wp.mce.media.loaded?10:500)}},getHtml:function(){var a=this.shortcode.attrs.named;return a.content=this.shortcode.content,this.template({model:_.defaults(a,wp.media[this.shortcode.tag].defaults)})},unbind:function(){this.unsetPlayers()}}),_.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(a){this.players=[],this.data={},this.attachments=[],this.shortcode=a.shortcode,this.fetch()},fetch:function(){this.attachments=wp.media.playlist.attachments(this.shortcode),this.dfd=this.attachments.more().done(_.bind(this.render,this))},render:function(){var b=this.getHtml(),c=this;_.each(tinymce.editors,function(d){var e;d.plugins.wpview&&(e=d.getDoc(),a(e).find('[data-wpview-text="'+this.encodedText+'"]').each(function(d,e){var f=a(e);f.html(b).append('<ins data-wpview-end="1"></ins>'),c.data.tracks&&c.players.push(new WPPlaylistView({el:a(e).find(".wp-playlist").get(0),metadata:c.data}).player)}))},this)},getHtml:function(){var a,b,c=this.shortcode.attrs.named,e=wp.media.playlist,f=[];if(!this.dfd||"pending"!==this.dfd.state()||this.attachments.length)return _.each(e.defaults,function(a,b){c[b]=e.coerce(c,b)}),a={type:c.type,style:c.style,tracklist:c.tracklist,tracknumbers:c.tracknumbers,images:c.images,artists:c.artists},this.attachments.length?(b=this.attachments.toJSON(),_.each(b,function(b){var e={},g={},h={src:b.url,type:b.mime,title:b.title,caption:b.caption,description:b.description,meta:b.meta};"video"===c.type?(e.width=b.width,e.height=b.height,d.view.settings.contentWidth?(g.width=d.view.settings.contentWidth-22,g.height=Math.ceil(e.height*g.width/e.width),a.width||(a.width=g.width,a.height=g.height)):a.width||(a.width=b.width,a.height=b.height),h.dimensions={original:e,resized:_.isEmpty(g)?e:g}):a.width=400,h.image=b.image,h.thumb=b.thumb,f.push(h)}),a.tracks=f,this.data=a,this.template(a)):this.template(a)},unbind:function(){this.unsetPlayers()}}),_.extend(wp.mce.media.PlaylistView.prototype,wp.media.mixin),wp.mce.playlist=_.extend({},wp.mce.media,{shortcode:"playlist",state:["playlist-edit","video-playlist-edit"],View:wp.mce.media.PlaylistView}),wp.mce.views.register("playlist",wp.mce.playlist)}(jQuery);
\ No newline at end of file
+!function(a,b,c,d){"use strict";var e={},f={};b.mce=b.mce||{},b.mce.views={register:function(a,c){e[a]=b.mce.View.extend(_.extend(c,{type:a}))},unregister:function(a){delete e[a]},get:function(a){return e[a]},unbind:function(){_.each(f,function(a){a.unbind()})},setMarkers:function(a){var b,c,d=[{content:a}],f=this;return _.each(e,function(a,e){c=d.slice(),d=[],_.each(c,function(c){var g,h,i=c.content;if(c.processed)return void d.push(c);for(;i&&(g=a.prototype.match(i));)g.index&&d.push({content:i.substring(0,g.index)}),b=f.createInstance(e,g.content,g.options),h=b.loader?".":b.text,d.push({content:'<p data-wpview-marker="'+b.encodedText+'">'+h+"</p>",processed:!0}),i=i.slice(g.index+g.content.length);i&&d.push({content:i})})}),a=_.pluck(d,"content").join(""),a.replace(/<p>\s*<p data-wpview-marker=/g,"<p data-wpview-marker=").replace(/<\/p>\s*<\/p>/g,"</p>")},createInstance:function(a,b,c,d){var e,g,h=this.get(a);return b=tinymce.DOM.decode(b),!d&&(g=this.getInstance(b))?g:(e=encodeURIComponent(b),c=_.extend(c||{},{text:b,encodedText:e}),f[e]=new h(c))},getInstance:function(a){return"string"==typeof a?f[encodeURIComponent(a)]:f[d(a).attr("data-wpview-text")]},getText:function(a){return decodeURIComponent(d(a).attr("data-wpview-text")||"")},render:function(a){_.each(f,function(b){b.render(a)})},update:function(a,b,c,d){var e=this.getInstance(c);e&&e.update(a,b,c,d)},edit:function(a,b){var c=this.getInstance(b);c&&c.edit&&c.edit(c.text,function(d,e){c.update(d,a,b,e)})},remove:function(a,b){var c=this.getInstance(b);c&&c.remove(a,b)}},b.mce.View=function(a){_.extend(this,a),this.initialize()},b.mce.View.extend=Backbone.View.extend,_.extend(b.mce.View.prototype,{content:null,loader:!0,initialize:function(){},getContent:function(){return this.content},render:function(a,b){null!=a&&(this.content=a),a=this.getContent(),(this.loader||a)&&(b&&this.unbind(),this.replaceMarkers(),a?this.setContent(a,function(a,b,c){d(b).data("rendered",!0),this.bindNode.call(this,a,b,c)},b?null:!1):this.setLoader())},bindNode:function(){},unbindNode:function(){},unbind:function(){this.getNodes(function(a,b,c){this.unbindNode.call(this,a,b,c),d(b).trigger("wp-mce-view-unbind")},!0)},getEditors:function(a){_.each(tinymce.editors,function(b){b.plugins.wpview&&a.call(this,b)},this)},getNodes:function(a,b){this.getEditors(function(c){var e=this;d(c.getBody()).find('[data-wpview-text="'+e.encodedText+'"]').filter(function(){var a;return null==b?!0:(a=d(this).data("rendered")===!0,b?a:!a)}).each(function(){a.call(e,c,this,d(this).find(".wpview-content").get(0))})})},getMarkers:function(a){this.getEditors(function(b){var c=this;d(b.getBody()).find('[data-wpview-marker="'+this.encodedText+'"]').each(function(){a.call(c,b,this)})})},replaceMarkers:function(){this.getMarkers(function(a,b){var c,e=b===a.selection.getNode();return this.loader||d(b).text()===this.text?(c=a.$('<div class="wpview-wrap" data-wpview-text="'+this.encodedText+'" data-wpview-type="'+this.type+'"><p class="wpview-selection-before">\xa0</p><div class="wpview-body" contenteditable="false"><div class="wpview-content wpview-type-'+this.type+'"></div></div><p class="wpview-selection-after">\xa0</p></div>'),a.$(b).replaceWith(c),void(e&&a.wp.setViewCursor(!1,c[0]))):void a.dom.setAttrib(b,"data-wpview-marker",null)})},removeMarkers:function(){this.getMarkers(function(a,b){a.dom.setAttrib(b,"data-wpview-marker",null)})},setContent:function(a,b,c){_.isObject(a)&&-1!==a.body.indexOf("<script")?this.setIframes(a.head||"",a.body,b,c):_.isString(a)&&-1!==a.indexOf("<script")?this.setIframes("",a,b,c):this.getNodes(function(c,d,e){a=a.body||a,-1!==a.indexOf("<iframe")&&(a+='<div class="wpview-overlay"></div>'),e.innerHTML="",e.appendChild(_.isString(a)?c.dom.createFragment(a):a),b&&b.call(this,c,d,e)},c)},setIframes:function(b,c,e,f){var g=a.MutationObserver||a.WebKitMutationObserver||a.MozMutationObserver,h=this;this.getNodes(function(a,f,i){var j=a.dom,k="",l=a.getBody().className||"",m=a.getDoc().getElementsByTagName("head")[0];tinymce.each(j.$('link[rel="stylesheet"]',m),function(a){a.href&&-1===a.href.indexOf("skins/lightgray/content.min.css")&&-1===a.href.indexOf("skins/wordpress/wp-content.css")&&(k+=j.getOuterHTML(a))}),h.iframeHeight&&j.add(i,"div",{style:{width:"100%",height:h.iframeHeight}}),setTimeout(function(){function m(){var b;s||o.contentWindow&&(b=d(o),h.iframeHeight=d(p.body).height(),b.height()!==h.iframeHeight&&(b.height(h.iframeHeight),a.nodeChanged()))}function n(){p.body.className=a.getBody().className}var o,p,q,r,s;if(i.innerHTML="",o=j.add(i,"iframe",{src:tinymce.Env.ie?'javascript:""':"",frameBorder:"0",allowTransparency:"true",scrolling:"no","class":"wpview-sandbox",style:{width:"100%",display:"block"},height:h.iframeHeight}),j.add(i,"div",{"class":"wpview-overlay"}),p=o.contentWindow.document,p.open(),p.write('<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'+b+k+'<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="'+l+'">'+c+"</body></html>"),p.close(),h.iframeHeight&&(s=!0,setTimeout(function(){s=!1,m()},3e3)),d(o.contentWindow).on("load",m),g)q=new g(_.debounce(m,100)),q.observe(p.body,{attributes:!0,childList:!0,subtree:!0}),d(f).one("wp-mce-view-unbind",function(){q.disconnect()});else for(r=1;6>r;r++)setTimeout(m,700*r);a.on("wp-body-class-change",n),d(f).one("wp-mce-view-unbind",function(){a.off("wp-body-class-change",n)}),e&&e.call(h,a,f,i)},50)},f)},setLoader:function(){this.setContent('<div class="loading-placeholder"><div class="dashicons dashicons-admin-media"></div><div class="wpview-loading"><ins></ins></div></div>')},setError:function(a,b){this.setContent('<div class="wpview-error"><div class="dashicons dashicons-'+(b||"no")+'"></div><p>'+a+"</p></div>")},match:function(a){var b=c.next(this.type,a);return b?{index:b.index,content:b.content,options:{shortcode:b.shortcode}}:void 0},update:function(a,c,f,g){_.find(e,function(e,h){var i=e.prototype.match(a);return i?(d(f).data("rendered",!1),c.dom.setAttrib(f,"data-wpview-text",encodeURIComponent(a)),b.mce.views.createInstance(h,a,i.options,g).render(),c.focus(),!0):void 0})},remove:function(a,b){this.unbindNode.call(this,a,b,d(b).find(".wpview-content").get(0)),d(b).trigger("wp-mce-view-unbind"),a.dom.remove(b),a.focus()}})}(window,window.wp,window.wp.shortcode,window.jQuery),function(a,b,c,d){var e,f,g,h;e={state:[],edit:function(a,b){var d=this.type,e=c[d].edit(a);this.pausePlayers&&this.pausePlayers(),_.each(this.state,function(a){e.state(a).on("update",function(a){b(c[d].shortcode(a).string(),"gallery"===d)})}),e.on("close",function(){e.detach()}),e.open()}},f=_.extend({},e,{state:["gallery-edit"],template:c.template("editor-gallery"),initialize:function(){var a=c.gallery.attachments(this.shortcode,c.view.settings.post.id),b=this.shortcode.attrs.named,d=this;a.more().done(function(){a=a.toJSON(),_.each(a,function(a){a.sizes&&(b.size&&a.sizes[b.size]?a.thumbnail=a.sizes[b.size]:a.sizes.thumbnail?a.thumbnail=a.sizes.thumbnail:a.sizes.full&&(a.thumbnail=a.sizes.full))}),d.render(d.template({attachments:a,columns:b.columns?parseInt(b.columns,10):c.galleryDefaults.columns}))}).fail(function(a,b){d.setError(b)})}}),g=_.extend({},e,{action:"parse-media-shortcode",initialize:function(){var a=this;this.url&&(this.loader=!1,this.shortcode=c.embed.shortcode({url:this.text})),wp.ajax.post(this.action,{post_ID:c.view.settings.post.id,type:this.shortcode.tag,shortcode:this.shortcode.string()}).done(function(b){a.render(b)}).fail(function(b){a.url?a.removeMarkers():a.setError(b.message||b.statusText,"admin-media")}),this.getEditors(function(b){b.on("wpview-selected",function(){a.pausePlayers()})})},pausePlayers:function(){this.getNodes(function(a,b,c){var e=d("iframe.wpview-sandbox",c).get(0);e&&(e=e.contentWindow)&&e.mejs&&_.each(e.mejs.players,function(a){try{a.pause()}catch(b){}})})}}),h=_.extend({},g,{action:"parse-embed",edit:function(a,b){var d=c.embed.edit(a,this.url),e=this;this.pausePlayers(),d.state("embed").props.on("change:url",function(a,b){b&&a.get("url")&&(d.state("embed").metadata=a.toJSON())}),d.state("embed").on("select",function(){var a=d.state("embed").metadata;b(e.url?a.url:c.embed.shortcode(a).string())}),d.on("close",function(){d.detach()}),d.open()}}),b.register("gallery",_.extend({},f)),b.register("audio",_.extend({},g,{state:["audio-details"]})),b.register("video",_.extend({},g,{state:["video-details"]})),b.register("playlist",_.extend({},g,{state:["playlist-edit","video-playlist-edit"]})),b.register("embed",_.extend({},h)),b.register("embedURL",_.extend({},h,{match:function(a){var b=/(^|<p>)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi,c=b.exec(a);return c?{index:c.index+c[1].length,content:c[2],options:{url:!0}}:void 0}}))}(window,window.wp.mce.views,window.wp.media,window.jQuery);
\ No newline at end of file