| Current Path : /home/azimutno/www/components/com_jce/editor/tiny_mce/plugins/importcss/ |
| Current File : /home/azimutno/www/components/com_jce/editor/tiny_mce/plugins/importcss/editor_plugin.js |
/* jce - 2.8.1 | 2019-12-04 | https://www.joomlacontenteditor.net | Copyright (C) 2006 - 2019 Ryan Demmer. All rights reserved | GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html */
!function(){function toAbsolute(u,p){return u.replace(/url\(["']?(.+?)["']?\)/gi,function(a,b){return b.indexOf("://")<0?'url("'+p+b+'")':a})}function isEditorContentCss(url){return url.indexOf("/tiny_mce/")!==-1&&url.indexOf("content.css")!==-1}function cleanSelectorText(selectorText){var selector=/^(?:([a-z0-9\-_]+))?(\.[a-z0-9_\-\.]+)$/i.exec(selectorText);if(!selector)return"";var elementName=selector[1];return"body"!==elementName?selector[2].substr(1).split(".").join(" "):""}var each=tinymce.each,DOM=tinymce.DOM,PreviewCss=tinymce.util.PreviewCss;tinymce.create("tinymce.plugins.ImportCSS",{init:function(ed,url){this.editor=ed;var self=this;ed.onImportCSS=new tinymce.util.Dispatcher,ed.onImportCSS.add(function(){ed.settings.importcss_classes||self._import()}),ed.onInit.add(function(){ed.onImportCSS.dispatch()})},_import:function(){function isAllowedStylesheet(href){var styleselect=ed.getParam("styleselect_stylesheets");return!styleselect||("undefined"!=typeof filtered[href]?filtered[href]:(filtered[href]=href.indexOf(styleselect)!==-1,filtered[href]))}function parseCSS(stylesheet){each(stylesheet.imports,function(r){if(r.href.indexOf("://fonts.googleapis.com")>0){var v="@import url("+r.href+");";return void(self.fontface.indexOf(v)===-1&&self.fontface.unshift(v))}parseCSS(r)});try{if(rules=stylesheet.cssRules||stylesheet.rules,href=stylesheet.href,!href)return;if(isEditorContentCss(href))return;stylesheet.href&&(href=stylesheet.href.substr(0,stylesheet.href.lastIndexOf("/")+1))}catch(e){}each(rules,function(r){switch(r.type||1){case 1:if(!isAllowedStylesheet(stylesheet.href))return!0;!r.type,r.selectorText&&each(r.selectorText.split(","),function(v){v=v.replace(/^\s*|\s*$|^\s\./g,""),!/\.mce/.test(v)&&/\.[\w\-]+$/.test(v)&&v&&classes.indexOf(v)===-1&&classes.push(v)});break;case 3:if(r.href.indexOf("//fonts.googleapis.com")>0){var v="@import url("+r.href+");";fontface.indexOf(v)===-1&&fontface.unshift(v)}r.href.indexOf("//")===-1&&parseCSS(r.styleSheet);break;case 5:if(r.cssText&&/(fontawesome|glyphicons|icomoon)/i.test(r.cssText)===!1){var v=toAbsolute(r.cssText,href);fontface.indexOf(v)===-1&&fontface.push(v)}}})}var self=this,ed=this.editor,doc=ed.getDoc(),href="",rules=[],fonts=!1,fontface=[],filtered={},classes=[];if(!classes.length)try{each(doc.styleSheets,function(styleSheet){parseCSS(styleSheet)})}catch(ex){}if(!fontface.length&&!fonts)try{var head=DOM.doc.getElementsByTagName("head")[0],style=DOM.create("style",{type:"text/css"}),css=self.fontface.join("\n");if(style.styleSheet){var setCss=function(){try{style.styleSheet.cssText=css}catch(e){}};style.styleSheet.disabled?setTimeout(setCss,10):setCss()}else style.appendChild(DOM.doc.createTextNode(css));head.appendChild(style),fonts=!0}catch(e){}classes.length&&(ed.getParam("styleselect_sort",1)&&classes.sort(),ed.settings.importcss_classes=tinymce.map(classes,function(val){var cls=cleanSelectorText(val),style=PreviewCss(ed,{styles:[],attributes:[],classes:cls.split(" ")});return{selector:val,class:cls,style:style}}))}}),tinymce.PluginManager.add("importcss",tinymce.plugins.ImportCSS)}();