/* JCE Editor - 2.4beta2 | 26 March 2014 | http://www.joomlacontenteditor.net | Copyright (C) 2006 - 2014 Ryan Demmer. All rights reserved | GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html */
(function(){var each=tinymce.each,PreviewCss=tinymce.util.PreviewCss,Event=tinymce.dom.Event,DOM=tinymce.DOM;function toAbsolute(u,p){return u.replace(/url\(["']?(.+?)["']?\)/gi,function(a,b){if(b.indexOf('://')<0){return'url("'+p+b+'")';}
return a;});}
tinymce.create('tinymce.plugins.ImportCSS',{populateStyleSelect:function(){var ed=this.editor;var self=this,styleselect=ed.controlManager.get('styleselect');if(!styleselect||styleselect.hasClasses){return;}
var counter=Math.max(styleselect.getLength()-1,0),classes=this.import();if(classes.length===0){return;}
each(classes,function(o,idx){var name='style_'+(counter+idx),fmt;fmt={inline:'span',attributes:{'class':o['class']},selector:'*'};ed.formatter.register(name,fmt);styleselect.add(o['class'],name,{style:function(){return PreviewCss(ed,fmt);}});});styleselect.hasClasses=true;},init:function(ed,url){this.editor=ed;var self=this;ed.onPreInit.add(function(editor){var styleselect=ed.controlManager.get('styleselect');if(styleselect&&!styleselect.hasClasses&&ed.getParam('styleselect_stylesheet',true)){styleselect.onPostRender.add(function(ed,n){if(!styleselect.NativeListBox){Event.bind(DOM.get(n.id+'_text'),'focus mousedown',self.populateStyleSelect,self);Event.bind(DOM.get(n.id+'_open'),'focus mousedown',self.populateStyleSelect,self);}else{Event.bind(DOM.get(n.id,'focus'),self.populateStyleSelect,self);}});}
var fontselect=ed.controlManager.get('fontselect');if(fontselect){fontselect.onPostRender.add(function(){if(!self.fontface){self.import();}});}});ed.onNodeChange.add(function(){var styleselect=ed.controlManager.get('styleselect');if(styleselect&&!styleselect.hasClasses&&ed.getParam('styleselect_stylesheet',true)){return self.populateStyleSelect();}});},import:function(){var self=this,ed=this.editor,doc=ed.getDoc(),cl=[],ff=[],i,lo={},f=ed.settings.class_filter,ov,href='',rules=[],fontface=false;function parseCSS(stylesheet){each(stylesheet.imports,function(r){if(r.href.indexOf('://fonts.googleapis.com')>0){var v='@import url('+r.href+');';if(tinymce.inArray(ff,v)===-1){ff.unshift(v);}
return;}
parseCSS(r);});try{rules=stylesheet.cssRules||stylesheet.rules;if(stylesheet.href){href=stylesheet.href.substr(0,stylesheet.href.lastIndexOf('/')+1);}}catch(e){}
each(rules,function(r){switch(r.type||1){case 1:if(!r.type){}
if(r.selectorText){each(r.selectorText.split(','),function(v){v=v.replace(/^\s*|\s*$|^\s\./g,"");if(/\.mce/.test(v)||!/\.[\w\-]+$/.test(v))
return;ov=v;v=tinymce._replace(/.*\.([a-z0-9_\-]+).*/i,'$1',v);if(f&&!(v=f(v,ov)))
return;if(!lo[v]){cl.push({'class':v});lo[v]=1;}});}
break;case 3:if(r.href.indexOf('://fonts.googleapis.com')>0){var v='@import url('+r.href+');';if(tinymce.inArray(ff,v)===-1){ff.unshift(v);}}
if(tinymce.isGecko&&r.href.indexOf('://')!=-1){return;}
parseCSS(r.styleSheet);break;case 5:if(r.cssText&&/(fontawesome|glyphicons|icomoon)/i.test(r.cssText)===false){var v=toAbsolute(r.cssText,href);if(tinymce.inArray(ff,v)===-1){ff.push(v);}}
break;}});}
try{each(doc.styleSheets,function(styleSheet){parseCSS(styleSheet);});}catch(ex){}
if(ff.length&&self.fontface===false){try{var head=DOM.doc.getElementsByTagName('head')[0];var style=DOM.create('style',{type:'text/css'});var css=ff.join("\n");if(style.styleSheet){var setCss=function(){try{style.styleSheet.cssText=css;}catch(e){}};if(style.styleSheet.disabled){setTimeout(setCss,10);}else{setCss();}}else{style.appendChild(DOM.doc.createTextNode(css));}
head.appendChild(style);self.fontface=true;}catch(e){}}
return cl;}});tinymce.PluginManager.add('importcss',tinymce.plugins.ImportCSS);})();