WordPress.org

Make WordPress Core

Ticket #25873: mce-view.diff

File mce-view.diff, 6.1 KB (added by seamusleahy, 7 years ago)

Patch to add  

  • wp-includes/js/mce-view.js

     
    242242                                        'class':           'wp-view-wrap wp-view-type-' + viewType,
    243243                                        'data-wp-view':    id,
    244244                                        'contenteditable': false
    245                                 }
     245                                },
     246                                'content': ' '
    246247                        });
    247248                },
    248249
  • wp-includes/js/mce-view.min.js

     
    1 window.wp=window.wp||{},function(a){var b={},c={};wp.mce=wp.mce||{},wp.mce.view={defaults:{pattern:{view:Backbone.View,text:function(a){return a.options.original},toView:function(a){if(this.pattern){this.pattern.lastIndex=0;var b=this.pattern.exec(a);if(b)return{index:b.index,content:b[0],options:{original:b[0],results:b}}}}},shortcode:{view:Backbone.View,text:function(a){return a.options.shortcode.string()},toView:function(a){var b=wp.shortcode.next(this.shortcode,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}}}},add:function(a,d){var e,f,g,h;e=d.extend?wp.mce.view.get(d.extend):d.shortcode?wp.mce.view.defaults.shortcode:wp.mce.view.defaults.pattern,_.defaults(d,e),d.id=a,h={remove:function(){return delete c[this.el.id],this.$el.parent().remove(),f&&f.apply(this,arguments),this}},_.isFunction(d.view)?g=d.view:(g=e.view,f=d.view.remove,_.defaults(h,d.view)),f||g._mceview||(f=g.prototype.remove),d.view=g.extend(h,{_mceview:!0}),b[a]=d},get:function(a){return b[a]},remove:function(a){delete b[a]},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 d.push(c),void 0;for(;f&&(e=a.toView(f));)e.index&&d.push({content:f.substring(0,e.index)}),d.push({content:wp.mce.view.toView(b,e.options),processed:!0}),f=f.slice(e.index+e.content.length);f&&d.push({content:f})})}),_.pluck(d,"content").join("")},toView:function(b,d){var e,f,g=wp.mce.view.get(b);return g?(e=new g.view(_.extend(d||{},{viewType:b})),f=e.el.id=e.el.id||_.uniqueId("__wpmce-"),c[f]=e,e.$wrapper=a(),wp.html.string({tag:"span"===e.tagName?"span":"div",attrs:{"class":"wp-view-wrap wp-view-type-"+b,"data-wp-view":f,contenteditable:!1}})):""},render:function(b){a(".wp-view-wrap",b).each(function(){var b=a(this),c=wp.mce.view.instance(this);c&&(c.$wrapper=b,c.render(),c.$el.detach(),b.empty().append(c.el).append('<span data-wp-view-end class="wp-view-end"></span>'))})},toText:function(a){return a.replace(/<(?:div|span)[^>]+data-wp-view="([^"]+)"[^>]*>.*?<span[^>]+data-wp-view-end[^>]*><\/span><\/(?:div|span)>/g,function(a,b){var d,e=c[b];return e&&(d=wp.mce.view.get(e.options.viewType)),e&&d?d.text(e):""})},removeInternalAttrs:function(a){var b={};return _.each(a,function(a,c){-1===c.indexOf("data-mce")&&(b[c]=a)}),b},attrs:function(a){return wp.mce.view.removeInternalAttrs(wp.html.attrs(a))},instance:function(b){var d=a(b).data("wp-view");return d?c[d]:void 0},select:function(b){var c=a(b);c.hasClass("selected")||(c.addClass("selected"),a(b.firstChild).trigger("select"))},deselect:function(b){var c=a(b);c.hasClass("selected")&&(c.removeClass("selected"),a(b.firstChild).trigger("deselect"))}}}(jQuery);
    2  No newline at end of file
     1window.wp=window.wp||{};(function(e){var t={},n={};wp.mce=wp.mce||{};wp.mce.view={defaults:{pattern:{view:Backbone.View,text:function(e){return e.options.original},toView:function(e){if(!this.pattern)return;this.pattern.lastIndex=0;var t=this.pattern.exec(e);if(!t)return;return{index:t.index,content:t[0],options:{original:t[0],results:t}}}},shortcode:{view:Backbone.View,text:function(e){return e.options.shortcode.string()},toView:function(e){var t=wp.shortcode.next(this.shortcode,e);if(!t)return;return{index:t.index,content:t.content,options:{shortcode:t.shortcode}}}}},add:function(e,r){var i,s,o,u;if(r.extend)i=wp.mce.view.get(r.extend);else if(r.shortcode)i=wp.mce.view.defaults.shortcode;else i=wp.mce.view.defaults.pattern;_.defaults(r,i);r.id=e;u={remove:function(){delete n[this.el.id];this.$el.parent().remove();if(s)s.apply(this,arguments);return this}};if(_.isFunction(r.view)){o=r.view}else{o=i.view;s=r.view.remove;_.defaults(u,r.view)}if(!s&&!o._mceview)s=o.prototype.remove;r.view=o.extend(u,{_mceview:true});t[e]=r},get:function(e){return t[e]},remove:function(e){delete t[e]},toViews:function(e){var n=[{content:e}],r;_.each(t,function(e,t){r=n.slice();n=[];_.each(r,function(r){var i=r.content,s;if(r.processed){n.push(r);return}while(i&&(s=e.toView(i))){if(s.index)n.push({content:i.substring(0,s.index)});n.push({content:wp.mce.view.toView(t,s.options),processed:true});i=i.slice(s.index+s.content.length)}if(i)n.push({content:i})})});return _.pluck(n,"content").join("")},toView:function(t,r){var i=wp.mce.view.get(t),s,o;if(!i)return"";s=new i.view(_.extend(r||{},{viewType:t}));o=s.el.id=s.el.id||_.uniqueId("__wpmce-");n[o]=s;s.$wrapper=e();return wp.html.string({tag:"span"===s.tagName?"span":"div",attrs:{"class":"wp-view-wrap wp-view-type-"+t,"data-wp-view":o,contenteditable:false},content:" "})},render:function(t){e(".wp-view-wrap",t).each(function(){var t=e(this),n=wp.mce.view.instance(this);if(!n)return;n.$wrapper=t;n.render();n.$el.detach();t.empty().append(n.el).append('<span data-wp-view-end class="wp-view-end"></span>')})},toText:function(e){return e.replace(/<(?:div|span)[^>]+data-wp-view="([^"]+)"[^>]*>.*?<span[^>]+data-wp-view-end[^>]*><\/span><\/(?:div|span)>/g,function(e,t){var r=n[t],i;if(r)i=wp.mce.view.get(r.options.viewType);return r&&i?i.text(r):""})},removeInternalAttrs:function(e){var t={};_.each(e,function(e,n){if(-1===n.indexOf("data-mce"))t[n]=e});return t},attrs:function(e){return wp.mce.view.removeInternalAttrs(wp.html.attrs(e))},instance:function(t){var r=e(t).data("wp-view");if(r)return n[r]},select:function(t){var n=e(t);if(n.hasClass("selected"))return;n.addClass("selected");e(t.firstChild).trigger("select")},deselect:function(t){var n=e(t);if(!n.hasClass("selected"))return;n.removeClass("selected");e(t.firstChild).trigger("deselect")}}})(jQuery)
     2 No newline at end of file