04889ca5f0
git-svn-id: https://develop.svn.wordpress.org/trunk@22024 602fd350-edb4-49c9-b593-d223f7449a82
1 line
4.2 KiB
JavaScript
1 line
4.2 KiB
JavaScript
if(typeof wp==="undefined"){var wp={}}(function(){wp.html=_.extend(wp.html||{},{attrs:function(c){var a,b;if("/"===c[c.length-1]){c=c.slice(0,-1)}a=wp.shortcode.attrs(c);b=a.named;_.each(a.numeric,function(d){if(/\s/.test(d)){return}b[d]=""});return b},string:function(a){var c="<"+a.tag,b=a.content||"";_.each(a.attrs,function(e,d){c+=" "+d;if(""===e){return}if(_.isBoolean(e)){e=e?"true":"false"}c+='="'+e+'"'});if(a.single){return c+" />"}c+=">";c+=_.isObject(b)?wp.html.string(b):b;return c+"</"+a.tag+">"}})}());(function(b){var a={},c={};wp.mce=wp.mce||{};wp.mce.view={defaults:{view:Backbone.View,text:function(d){return d.options.original},toView:function(e){if(!this.pattern){return}this.pattern.lastIndex=0;var d=this.pattern.exec(e);if(!d){return}return{index:d.index,content:d[0],options:{original:d[0],results:d}}}},shortcode:{view:Backbone.View,text:function(d){return d.options.shortcode.text()},toView:function(e){var d=wp.shortcode.next(this.tag,e);if(!d){return}return{index:d.index,content:d.content,options:{shortcode:d.shortcode}}}},add:function(i,e){var g,d,h,f;g=e.extend?wp.mce.view.get(e.extend):wp.mce.view.defaults;_.defaults(e,g);e.id=i;f={remove:function(){delete c[this.el.id];this.$el.parent().remove();if(d){d.apply(this,arguments)}return this}};if(_.isFunction(e.view)){h=e.view}else{h=g.view;d=e.view.remove;_.defaults(f,e.view)}if(!d&&!h._mceview){d=h.prototype.remove}e.view=h.extend(f,{_mceview:true});a[i]=e},get:function(d){return a[d]},remove:function(d){delete a[d]},toViews:function(e){var d=[{content:e}],f;_.each(a,function(h,g){f=d.slice();d=[];_.each(f,function(k){var j=k.content,i;if(k.processed){d.push(k);return}while(j&&(i=h.toView(j))){if(i.index){d.push({content:j.substring(0,i.index)})}d.push({content:wp.mce.view.toView(g,i.options),processed:true});j=j.slice(i.index+i.content.length)}if(j){d.push({content:j})}})});return _.pluck(d,"content").join("")},toView:function(f,h){var g=wp.mce.view.get(f),e,i,d;if(!g){return""}e=new g.view(_.extend(h||{},{viewType:f}));i=e.el.id=e.el.id||_.uniqueId("__wpmce-");c[i]=e;d="span"===e.tagName?"span":"div";return"<"+d+' class="wp-view-wrap" data-wp-view="'+i+'" contenteditable="false"></'+d+">"},render:function(d){b(".wp-view-wrap",d).each(function(){var g=b(this),f=g.data("wp-view"),e=c[f];if(!e){return}e.render();e.$el.detach();g.empty().append(e.el).append("<span data-wp-view-end></span>")})},toText:function(d){return d.replace(/<(?:div|span)[^>]+data-wp-view="([^"]+)"[^>]*>.*?<span data-wp-view-end[^>]*><\/span><\/(?:div|span)>/g,function(g,h){var e=c[h],f;if(e){f=wp.mce.view.get(e.options.viewType)}return e&&f?f.text(e):""})},removeInternalAttrs:function(e){var d={};_.each(e,function(g,f){if(-1===f.indexOf("data-mce")){d[f]=g}});return d},attrs:function(d){return wp.mce.view.removeInternalAttrs(wp.html.attrs(d))},l10n:_.isUndefined(_wpMceViewL10n)?{}:_wpMceViewL10n}}(jQuery));(function(b){var a=wp.mce.view,c;a.add("attachment",{pattern:new RegExp("(?:<a([^>]*)>)?<img([^>]*class=(?:\"[^\"]*|'[^']*)\\bwp-image-(\\d+)[^>]*)>(?:</a>)?"),text:function(d){var e=_.clone(d.img),g=e["class"].split(/\s+/),f;if(d.align){g.push("align"+d.align)}if(d.size){g.push("size-"+d.size)}g.push("wp-image-"+d.model.id);e["class"]=_.compact(g).join(" ");f={tag:"img",attrs:e,single:true};if(d.anchor){f={tag:"a",attrs:d.anchor,content:f}}return wp.html.string(f)},view:{className:"editor-attachment",template:media.template("editor-attachment"),events:{"click .close":"remove"},initialize:function(){var d=this,e=this.options.results,g=e[3],f;this.model=wp.media.model.Attachment.get(g);if(e[1]){this.anchor=a.attrs(e[1])}this.img=a.attrs(e[2]);f=this.img["class"];f=f.replace(/(?:^|\s)wp-image-\d+/,"");f=f.replace(/(?:^|\s)size-(\S+)/,function(h,i){d.size=i;return""});f=f.replace(/(?:^|\s)align(left|center|right|none)(?:\s|$)/,function(h,i){d.align=i;return""});this.img["class"]=f;this.$el.addClass("spinner");this.model.fetch().done(_.bind(this.render,this))},render:function(){var e=this.model.toJSON(),d;if(!e.url){return}d={url:"image"===e.type?e.url:e.icon,uploading:e.uploading};_.extend(d,wp.media.fit({width:e.width,height:e.height,maxWidth:a.l10n.contentWidth}));if(this.size&&e.sizes&&e.sizes[this.size]){_.extend(d,_.pick(e.sizes[this.size],"url","width","height"))}this.$el.html(this.template(d))}}})}(jQuery)); |