]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/mce-view.min.js
WordPress 4.2
[autoinstalls/wordpress.git] / wp-includes / js / mce-view.min.js
index 697251e9da850b59f5e80f8c7125e575a5e4686c..c5de05d05c292624cda571a21b953a33463812e2 100644 (file)
@@ -1 +1 @@
-window.wp=window.wp||{},function(a){"use strict";var b={},c={},d=wp.media,e=[],f=0,g=50,h=["encodedText"];wp.mce=wp.mce||{},wp.mce.View=function(a){a=a||{},this.type=a.type,_.extend(this,_.pick(a,h)),this.initialize.apply(this,arguments)},_.extend(wp.mce.View.prototype,{initialize:function(){},getHtml:function(){return""},loadingPlaceholder:function(){return'<div class="loading-placeholder"><div class="dashicons dashicons-admin-media"></div><div class="wpview-loading"><ins></ins></div></div>'},render:function(c){(c||!this.rendered())&&(this.unbind(),this.setContent('<p class="wpview-selection-before"> </p><div class="wpview-body" contenteditable="false"><div class="toolbar mce-arrow-down">'+(_.isFunction(b[this.type].edit)?'<div class="dashicons dashicons-edit edit"></div>':"")+'<div class="dashicons dashicons-no remove"></div></div><div class="wpview-content wpview-type-'+this.type+'">'+(this.getHtml()||this.loadingPlaceholder())+"</div>"+(this.overlay?'<div class="wpview-overlay"></div>':"")+'</div><p class="wpview-selection-after"> </p>',"wrap"),a(this).trigger("ready"),this.rendered(!0))},unbind:function(){},getEditors:function(a){var b=[];return _.each(tinymce.editors,function(c){c.plugins.wpview&&(a&&a(c),b.push(c))},this),b},getNodes:function(b){var c=[],d=this;return this.getEditors(function(e){a(e.getBody()).find('[data-wpview-text="'+d.encodedText+'"]').each(function(d,f){b&&b(e,f,a(f).find(".wpview-content").get(0)),c.push(f)})}),c},setContent:function(a,b){this.getNodes(function(c,d,e){var f="wrap"===b||"replace"===b?d:e,g=a;_.isString(g)&&(g=c.dom.createFragment(g)),"replace"===b?c.dom.replace(g,f):(f.innerHTML="",f.appendChild(g))})},setIframes:function(b,c){var d=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver,e="video"===this.type||"audio"===this.type||"playlist"===this.type;b||-1!==c.indexOf("<script")?this.getNodes(function(f,h,i){var j,k,l,m,n=f.dom,o="",p=f.getBody().className||"";i.innerHTML="",b=b||"",e&&(wp.mce.views.sandboxStyles?o=wp.mce.views.sandboxStyles:(tinymce.each(n.$('link[rel="stylesheet"]',f.getDoc().head),function(a){a.href&&-1===a.href.indexOf("skins/lightgray/content.min.css")&&-1===a.href.indexOf("skins/wordpress/wp-content.css")&&(o+=n.getOuterHTML(a)+"\n")}),wp.mce.views.sandboxStyles=o)),setTimeout(function(){if(j=n.add(i,"iframe",{src:tinymce.Env.ie?'javascript:""':"",frameBorder:"0",allowTransparency:"true",scrolling:"no","class":"wpview-sandbox",style:{width:"100%",display:"block"}}),k=j.contentWindow.document,k.open(),k.write('<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'+b+o+'<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="'+p+'">'+c+"</body></html>"),k.close(),m=function(){j.contentWindow&&a(j).height(a(k.body).height())},d)new d(_.debounce(function(){m()},100)).observe(k.body,{attributes:!0,childList:!0,subtree:!0});else for(l=1;6>l;l++)setTimeout(m,700*l);e&&f.on("wp-body-class-change",function(){k.body.className=f.getBody().className})},g)}):this.setContent(c)},setError:function(a,b){this.setContent('<div class="wpview-error"><div class="dashicons dashicons-'+(b?b:"no")+'"></div><p>'+a+"</p></div>")},rendered:function(b){var c;return this.getNodes(function(d,e){null!=b?a(e).data("rendered",b===!0):c=c||!a(e).data("rendered")}),!c}}),wp.mce.View.extend=Backbone.View.extend,wp.mce.views={register:function(a,c){var d={type:a,View:{},toView:function(a){var b=wp.shortcode.next(this.type,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}}};c=_.defaults(c,d),c.View=wp.mce.View.extend(c.View),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.type=a,f.encodedText=h,e=new g.View(f),c[h]=e),wp.html.string({tag:"div",attrs:{"class":"wpview-wrap","data-wpview-text":h,"data-wpview-type":a},content:" "})):b},refreshView:function(a,b,d){var e,f,g,h=window.encodeURIComponent(b);g=wp.mce.views.getInstance(h),g||(f=a.toView(b),e=f.options,e.type=a.type,e.encodedText=h,g=new a.View(e),c[h]=g),g.render(d)},getInstance:function(a){return c[a]},render:function(a){_.each(c,function(b){b.render(a)})},edit:function(b){var c=a(b).data("wpview-type"),d=wp.mce.views.get(c);d&&d.edit(b)}},wp.mce.views.register("gallery",{View:{template:d.template("editor-gallery"),postID:a("#post_ID").val(),initialize:function(a){this.shortcode=a.shortcode,this.fetch()},fetch:function(){var a=this;this.attachments=wp.media.gallery.attachments(this.shortcode,this.postID),this.dfd=this.attachments.more().done(function(){a.render(!0)})},getHtml:function(){var a,b=this.shortcode.attrs.named,c=!1;return this.dfd&&"pending"===this.dfd.state()&&!this.attachments.length?"":(this.attachments.length&&(c=this.attachments.toJSON(),_.each(c,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))})),a={attachments:c,columns:b.columns?parseInt(b.columns,10):wp.media.galleryDefaults.columns},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(c){var g,h=e.shortcode(c).string();a(b).attr("data-wpview-text",window.encodeURIComponent(h)),g=d!==h,wp.mce.views.refreshView(f,h,g)}),c.on("close",function(){c.detach()})}}),wp.mce.av={View:{overlay:!0,action:"parse-media-shortcode",initialize:function(b){var c=this;this.shortcode=b.shortcode,_.bindAll(this,"setIframes","setNodes","fetch","stopPlayers"),a(this).on("ready",this.setNodes),a(document).on("media:edit",this.stopPlayers),this.fetch(),this.getEditors(function(a){a.on("hide",function(){e=[],f=0,c.stopPlayers()})})},pauseOtherWindows:function(a){_.each(e,function(b){b.sandboxId!==a.sandboxId&&_.each(b.mejs.players,function(a){a.pause()})})},iframeLoaded:function(b){return _.bind(function(){var c;b.mejs&&!_.isEmpty(b.mejs.players)&&(b.sandboxId=f,f++,e.push(b),c=_.bind(function(){this.pauseOtherWindows(b)},this),_.isEmpty(b.mejs.MediaPluginBridge.pluginMediaElements)||_.each(b.mejs.MediaPluginBridge.pluginMediaElements,function(a){a.addEventListener("play",c)}),_.each(b.mejs.players,function(b){a(b.node).on("play",c)},this))},this)},listenToSandboxes:function(){_.each(this.getNodes(),function(b){var c,d=a(".wpview-sandbox",b).get(0);d&&(c=d.contentWindow)&&a(c).load(_.bind(this.iframeLoaded(c),this))},this)},deferredListen:function(){window.setTimeout(_.bind(this.listenToSandboxes,this),this.getNodes().length*g)},setNodes:function(){this.parsed?(this.setIframes(this.parsed.head,this.parsed.body),this.deferredListen()):this.fail()},fetch:function(){var b=this;wp.ajax.send(this.action,{data:{post_ID:a("#post_ID").val()||0,type:this.shortcode.tag,shortcode:this.shortcode.string()}}).done(function(a){a?(b.parsed=a,b.setIframes(a.head,a.body),b.deferredListen()):b.fail(!0)}).fail(function(a){b.fail(a||!0)})},fail:function(a){if(!this.error){if(!a)return;this.error=a}this.error.message?"not-embeddable"===this.error.type&&"embed"===this.type||"not-ssl"===this.error.type||"no-items"===this.error.type?this.setError(this.error.message,"admin-media"):this.setContent("<p>"+this.original+"</p>","replace"):this.error.statusText?this.setError(this.error.statusText,"admin-media"):this.original&&this.setContent("<p>"+this.original+"</p>","replace")},stopPlayers:function(b){var c="remove"===b;this.getNodes(function(b,d,e){var f,g,h=a("iframe.wpview-sandbox",e).get(0);if(h&&(g=h.contentWindow)&&g.mejs)try{for(f in g.mejs.players)g.mejs.players[f].pause(),c&&g.mejs.players[f].remove()}catch(i){}})},unbind:function(){this.stopPlayers("remove")}},edit:function(b){var c,d,e,f=wp.media[this.type],g=this;a(document).trigger("media:edit"),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.type].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.views.register("video",_.extend({},wp.mce.av,{state:"video-details"})),wp.mce.views.register("audio",_.extend({},wp.mce.av,{state:"audio-details"})),wp.mce.views.register("playlist",_.extend({},wp.mce.av,{state:["playlist-edit","video-playlist-edit"]})),wp.mce.embedMixin={View:_.extend({},wp.mce.av.View,{overlay:!0,action:"parse-embed",initialize:function(b){this.content=b.content,this.original=b.url||b.shortcode.string(),this.shortcode=b.url?d.embed.shortcode({url:b.url}):b.shortcode,_.bindAll(this,"setIframes","setNodes","fetch"),a(this).on("ready",this.setNodes),this.fetch()}}),edit:function(b){var c,e,f=d.embed,g=this,h="embedURL"===this.type;a(document).trigger("media:edit"),e=window.decodeURIComponent(a(b).attr("data-wpview-text")),c=f.edit(e,h),c.on("close",function(){c.detach()}),c.state("embed").props.on("change:url",function(a,b){b&&(c.state("embed").metadata=a.toJSON())}),c.state("embed").on("select",function(){var d;d=h?c.state("embed").metadata.url:f.shortcode(c.state("embed").metadata).string(),a(b).attr("data-wpview-text",window.encodeURIComponent(d)),wp.mce.views.refreshView(g,d),c.detach()}),c.open()}},wp.mce.views.register("embed",_.extend({},wp.mce.embedMixin)),wp.mce.views.register("embedURL",_.extend({},wp.mce.embedMixin,{toView:function(a){var b=/(?:^|<p>)(https?:\/\/[^\s"]+?)(?:<\/p>\s*|$)/gi,c=b.exec(tinymce.trim(a));if(c)return{index:c.index,content:c[0],options:{url:c[1]}}}}))}(jQuery);
\ No newline at end of file
+window.wp=window.wp||{},function(a,b,c){"use strict";var d={},e={};b.mce=b.mce||{},b.mce.views={register:function(a,c){d[a]=b.mce.View.extend(_.extend(c,{type:a}))},unregister:function(a){delete d[a]},get:function(a){return d[a]},unbind:function(){_.each(e,function(a){a.unbind()})},setMarkers:function(a){var b,c,e=[{content:a}],f=this;return _.each(d,function(a,d){c=e.slice(),e=[],_.each(c,function(c){var g,h=c.content;if(c.processed)return void e.push(c);for(;h&&(g=a.prototype.match(h));)g.index&&e.push({content:h.substring(0,g.index)}),b=f.createInstance(d,g.content,g.options),e.push({content:'<p data-wpview-marker="'+b.encodedText+'">'+b.text+"</p>",processed:!0}),h=h.slice(g.index+g.content.length);h&&e.push({content:h})})}),_.pluck(e,"content").join("")},createInstance:function(a,b,c){var d,f,g=this.get(a);return b=tinymce.DOM.decode(b),d=encodeURIComponent(b),(f=this.getInstance(d))?f:(c=_.extend(c||{},{text:b,encodedText:d}),e[d]=new g(c))},getInstance:function(a){return"string"==typeof a?e[encodeURIComponent(a)]:e[c(a).attr("data-wpview-text")]},getText:function(a){return decodeURIComponent(c(a).attr("data-wpview-text")||"")},render:function(a){_.each(e,function(b){b.render(a)})},update:function(a,b,c){var d=this.getInstance(c);d&&d.update(a,b,c)},edit:function(a,b){var c=this.getInstance(b);c&&c.edit&&c.edit(c.text,function(d){c.update(d,a,b)})},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,d){c(b).data("rendered",!0),this.bindNode.call(this,a,b,d)},b?null:!1):this.setLoader())},bindNode:function(){},unbindNode:function(){},unbind:function(){this.getNodes(function(a,b,d){this.unbindNode.call(this,a,b,d),c(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(d){var e=this;c(d.getBody()).find('[data-wpview-text="'+e.encodedText+'"]').filter(function(){var a;return null==b?!0:(a=c(this).data("rendered")===!0,b?a:!a)}).each(function(){a.call(e,d,this,c(this).find(".wpview-content").get(0))})})},getMarkers:function(a){this.getEditors(function(b){var d=this;c(b.getBody()).find('[data-wpview-marker="'+this.encodedText+'"]').each(function(){a.call(d,b,this)})})},replaceMarkers:function(){this.getMarkers(function(a,b){return c(b).text()!==this.text?void a.dom.setAttrib(b,"data-wpview-marker",null):void a.dom.replace(a.dom.createFragment('<div class="wpview-wrap" data-wpview-text="'+this.encodedText+'" data-wpview-type="'+this.type+'"><p class="wpview-selection-before"> </p><div class="wpview-body" contenteditable="false"><div class="wpview-content wpview-type-'+this.type+'"></div></div><p class="wpview-selection-after"> </p></div>'),b)})},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,d,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))}),setTimeout(function(){function m(){var b,d;o.contentWindow&&(b=c(o),d=c(p.body).height(),b.height()!==d&&(b.height(d),a.nodeChanged()))}function n(){p.body.className=a.getBody().className}var o,p,q,r;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"}}),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+'">'+d+"</body></html>"),p.close(),c(o.contentWindow).on("load",m),g)q=new g(_.debounce(m,100)),q.observe(p.body,{attributes:!0,childList:!0,subtree:!0}),c(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),c(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 c=b.shortcode.next(this.type,a);return c?{index:c.index,content:c.content,options:{shortcode:c.shortcode}}:void 0},update:function(a,e,f){_.find(d,function(d,g){var h=d.prototype.match(a);return h?(c(f).data("rendered",!1),e.dom.setAttrib(f,"data-wpview-text",encodeURIComponent(a)),b.mce.views.createInstance(g,a,h.options).render(),e.focus(),!0):void 0})},remove:function(a,b){this.unbindNode.call(this,a,b,c(b).find(".wpview-content").get(0)),c(b).trigger("wp-mce-view-unbind"),a.dom.remove(b),a.focus()}})}(window,window.wp,window.jQuery),function(a,b,c){var d,e,f,g,h=c("#post_ID").val()||0;d={state:[],edit:function(a,b){var c=wp.media[this.type],d=c.edit(a);this.pausePlayers&&this.pausePlayers(),_.each(this.state,function(a){d.state(a).on("update",function(a){b(c.shortcode(a).string())})}),d.on("close",function(){d.detach()}),d.open()}},e=_.extend({},d,{state:["gallery-edit"],template:wp.media.template("editor-gallery"),initialize:function(){var a=wp.media.gallery.attachments(this.shortcode,h),b=this.shortcode.attrs.named,c=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))}),c.render(c.template({attachments:a,columns:b.columns?parseInt(b.columns,10):wp.media.galleryDefaults.columns}))}).fail(function(a,b){c.setError(b)})}}),f=_.extend({},d,{action:"parse-media-shortcode",initialize:function(){var a=this;this.url&&(this.loader=!1,this.shortcode=wp.media.embed.shortcode({url:this.text})),wp.ajax.post(this.action,{post_ID:h,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,d){var e=c("iframe.wpview-sandbox",d).get(0);e&&(e=e.contentWindow)&&e.mejs&&_.each(e.mejs.players,function(a){try{a.pause()}catch(b){}})})}}),g=_.extend({},f,{action:"parse-embed",edit:function(a,b){var c=wp.media.embed,d=c.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.shortcode(a).string())}),d.on("close",function(){d.detach()}),d.open()}}),b.register("gallery",_.extend({},e)),b.register("audio",_.extend({},f,{state:["audio-details"]})),b.register("video",_.extend({},f,{state:["video-details"]})),b.register("playlist",_.extend({},f,{state:["playlist-edit","video-playlist-edit"]})),b.register("embed",_.extend({},g)),b.register("embedURL",_.extend({},g,{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.jQuery);
\ No newline at end of file