WordPress/wp-includes/js/mce-view.min.js

1 line
8.3 KiB
JavaScript
Raw Normal View History

window.wp=window.wp||{},function(a){"use strict";var b={},c={},d=wp.media,e=["encodedText"];wp.mce=wp.mce||{},wp.mce.View=function(a){a=a||{},this.type=a.type,_.extend(this,_.pick(a,e)),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(){var c=this.getHtml()||this.loadingPlaceholder();this.setContent('<p class="wpview-selection-before"> </p><div class="wpview-body" contenteditable="false"><div class="toolbar">'+(_.isFunction(b[this.type].edit)?'<div class="dashicons dashicons-edit edit"></div>':"")+'<div class="dashicons dashicons-no-alt remove"></div></div><div class="wpview-content wpview-type-'+this.type+'">'+c+"</div>"+(this.overlay?'<div class="wpview-overlay"></div>':"")+'</div><p class="wpview-selection-after"> </p>',function(b,c,d){a(b).trigger("ready",[c,d])},"wrap")},unbind:function(){},getNodes:function(b){var c=[];return _.each(tinymce.editors,function(d){d.plugins.wpview&&a(d.getBody()).find('[data-wpview-text="'+this.encodedText+'"]').each(function(a,e){b&&b(d,e),c.push(e)})},this),c},setContent:function(b,c,d){var e=this;this.getNodes(function(f,g){var h=a(g).find(".wpview-content"),i=g;h.length&&"wrap"!==d&&(g=h=h[0]),_.isString(b)?"replace"===d?g=f.dom.replace(f.dom.createFragment(b),i):f.dom.setHTML(g,b):"replace"===d?g=f.dom.replace(b,i):a(g).empty().append(b),_.isFunction(c)&&c(e,f,a(g).find(".wpview-content")[0])})},createIframe:function(b){var c=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;-1!==b.indexOf("<script")?this.getNodes(function(d,e){var f,g,h,i,j=d.dom;if(e=a(e).find(".wpview-content")[0])if(e.innerHTML="",f=j.add(e,"iframe",{src:tinymce.Env.ie?'javascript:""':"",frameBorder:"0",allowTransparency:"true",scrolling:"no",style:{width:"100%",display:"block"}}),g=f.contentWindow.document,g.open(),g.write('<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body data-context="iframe-sandbox" style="padding: 0; margin: 0;" class="'+d.getBody().className+'">'+b+"</body></html>"),g.close(),i=function(){f.contentWindow&&a(f).height(a(g.body).height())},c)new c(_.debounce(function(){i()},100)).observe(g.body,{attributes:!0,childList:!0,subtree:!0});else for(h=1;6>h;h++)setTimeout(i,700*h)}):this.setContent(b)},setError:function(a,b){this.setContent('<div class="wpview-error"><div class="dashicons dashicons-'+(b?b:"no")+'"></div><p>'+a+"</p></div>")}}),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){var d,e,f,g=window.encodeURIComponent(b);f=wp.mce.views.getInstance(g),f||(e=a.toView(b),d=e.options,d.type=a.type,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){