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

1 line
9.1 KiB
JavaScript
Raw Permalink Normal View History

!function(n,m,t,g){"use strict";var c={},o={};m.mce=m.mce||{},m.mce.views={register:function(e,t){c[e]=m.mce.View.extend(_.extend(t,{type:e}))},unregister:function(e){delete c[e]},get:function(e){return c[e]},unbind:function(){_.each(o,function(e){e.unbind()})},setMarkers:function(e){var a,t,r=[{content:e}],d=this;return _.each(c,function(s,o){t=r.slice(),r=[],_.each(t,function(e){var t,n,i=e.content;if(e.processed)r.push(e);else{for(;i&&(t=s.prototype.match(i));)t.index&&r.push({content:i.substring(0,t.index)}),n=(a=d.createInstance(o,t.content,t.options)).loader?".":a.text,r.push({content:a.ignore?n:'<p data-wpview-marker="'+a.encodedText+'">'+n+"</p>",processed:!0}),i=i.slice(t.index+t.content.length);i&&r.push({content:i})}})}),(e=_.pluck(r,"content").join("")).replace(/<p>\s*<p data-wpview-marker=/g,"<p data-wpview-marker=").replace(/<\/p>\s*<\/p>/g,"</p>")},createInstance:function(e,t,n,i){var s,e=this.get(e);return-1!==t.indexOf("[")&&-1!==t.indexOf("]")&&(t=t.replace(/\[[^\]]+\]/g,function(e){return e.replace(/[\r\n]/g,"")})),!i&&(s=this.getInstance(t))?s:(s=encodeURIComponent(t),n=_.extend(n||{},{text:t,encodedText:s}),o[s]=new e(n))},getInstance:function(e){return"string"==typeof e?o[encodeURIComponent(e)]:o[g(e).attr("data-wpview-text")]},getText:function(e){return decodeURIComponent(g(e).attr("data-wpview-text")||"")},render:function(t){_.each(o,function(e){e.render(null,t)})},update:function(e,t,n,i){var s=this.getInstance(n);s&&s.update(e,t,n,i)},edit:function(n,i){var s=this.getInstance(i);s&&s.edit&&s.edit(s.text,function(e,t){s.update(e,n,i,t)})},remove:function(e,t){var n=this.getInstance(t);n&&n.remove(e,t)}},m.mce.View=function(e){_.extend(this,e),this.initialize()},m.mce.View.extend=Backbone.View.extend,_.extend(m.mce.View.prototype,{content:null,loader:!0,initialize:function(){},getContent:function(){return this.content},render:function(e,t){null!=e&&(this.content=e),e=this.getContent(),(this.loader||e)&&(t&&this.unbind(),this.replaceMarkers(),e?this.setContent(e,function(e,t){g(t).data("rendered",!0),this.bindNode.call(this,e,t)},!!t&&null):this.setLoader())},bindNode:function(){},unbindNode:function(){},unbind:function(){this.getNodes(function(e,t){this.unbindNode.call(this,e,t)},!0)},getEditors:function(t){_.each(tinymce.editors,function(e){e.plugins.wpview&&t.call(this,e)},this)},getNodes:function(n,i){this.getEditors(function(e){var t=this;g(e.getBody()).find('[data-wpview-text="'+t.encodedText+'"]').filter(function(){var e;return null==i||(e=!0===g(this).data("rendered"),i?e:!e)}).each(function(){n.call(t,e,this,this)})})},getMarkers:function(n){this.getEditors(function(e){var t=this;g(e.getBody()).find('[data-wpview-marker="'+this.encodedText+'"]').each(function(){n.call(t,e,this)})})},replaceMarkers:function(){this.getMarkers(function(e,t){var n;this.loader||g(t).text()===tinymce.DOM.decode(this.text)?(n=e.$('<div class="wpview wpview-wrap" data-wpview-text="'+this.encodedText+'" data-wpview-type="'+this.type+'" contenteditable="false"></div>'),e.$(t).replaceWith(n)):e.dom.setAttrib(t,"data-wpview-marker",null)})},removeMarkers:function(){this.getMarkers(function(e,t){e.dom.setAttrib(t,"data-wpview-marker",null)})},setContent:function(n,i,e){_.isObject(n)&&-1!==n.body.indexOf("<script")?this.setIframes(n.head||"",n.body,i,e):_.isString(n)&&-1!==n.indexOf("<script")?this.setIframes("",n,i,e):this.getNodes(function(e,t){-1!==(n=n.body||n).indexOf("<iframe")&&(n+='<span class="mce-shim"></span>'),e.undoManager.transact(function(){t.innerHTML="",t.appendChild(_.isString(n)?e.dom.createFragment(n):n),e.dom.add(t,"span",{"class":"wpview-end"})}),i&&i.call(this,e,t)},e)},setIframes:function(l,h,p,e){var t,f=this;-1!==h.indexOf("[")&&-1!==h.indexOf("]")&&(t=new RegExp("\\[\\/?(?:"+n.mceViewL10n.shortcodes.join("|")+")[^\\]]*?\\]","g"),h=h.replace(t,function(e){return e.replace(/</g,"&lt;").replace(/>/g,"&gt;")})),this.getNodes(function(t,e){var n,i,s,o,a=t.dom,r="",d=t.getBody().className||"",c=t.getDoc().getElementsByTagName("head")[0];if(tinymce.each(a.$('link[rel="stylesheet"]',c),function(e){e.