-
Notifications
You must be signed in to change notification settings - Fork 2
/
plugin.min.js
1 lines (1 loc) · 1.66 KB
/
plugin.min.js
1
var tinymce=window.tinymce,jQuery=window.jQuery;!function(a){a.PluginManager.add("inlinestyles",function(a){function b(a){var b={};for(var c in a){var d=a[c].split(":");""!==d[0].trim()&&""!==d[1].trim()&&(b[d[0].trim()]=d[1].trim())}return b}function c(a){if(a[0]&&a[0].styleSheets&&a[0].styleSheets.length){var c=a[0].styleSheets[0];if(c.cssRules)for(var d in c.cssRules)try{var e=c.cssRules[d];if(!isNaN(e))break;var f=a.find(e.selectorText),g=e.cssText.replace(e.selectorText,"");g=g.replace("{","").replace("}","");var h=g.split(";");f.css(b(h))}catch(i){console.error(i)}}}function d(a,b,c){a.indexOf(b)>-1&&c.push(new RegExp(b,"i"))}function e(a){var b=window.open("","tmpHtml","width=0,height=0");window.blur();var e=b.document,g=jQuery(e);e.write(a),c(g),g.find("style").remove();var h=g.find("html").html();b.close();var i=[];return d(h,'href="',i),d(h,'src="',i),f(h,i)}function f(a,b){for(var c=a,d=0;d<b.length;d++)c=g(c,b[d]);return c}function g(a,b){function c(){var c=d.indexOf('"'),e=d.indexOf('"',c+1),h=a.substring(g+c+1,g+e+1);h=h.replace(/&/g,"&");var i="/".length,j="/i".length;f+=String(b).substring(i,String(b).length-j)+h,g+=e}for(var d,e,f="",g=0;g<a.length;g++)if(d=a.substring(g),e=d.search(b),0!==e){if(!(e>0)){f+=a.substring(g);break}f+=a.substring(g,e),g=e-1}else c();return f}function h(a){var b;try{b=e(a.content)}catch(c){console.error("Inlining css stylesheets failed"),console.error(c),console.error(c.stack)}b&&(a.content="<!DOCTYPE html><html>"+b+"</html>")}var i=!1,j=!1;a.on("GetContent",function(a){i=a.source_view||!1}),a.on("BeforeSetContent",function(a){a.ignoreInlinify||(i?(i=!1,h(a)):!j&&a.content&&a.content.length&&(h(a),j=!0))})})}(tinymce);