/* JCE Editor - 2.4.6 | 19 January 2015 | 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,extend=tinymce.extend,Node=tinymce.html.Node;function split(str,delim){return str.split(delim||',');}
var fontIconRe=/<([a-z0-9]+)([^>]+)class="([^"]*)(glyph|uk-)?(fa|icon)-([\w-]+)([^"]*)"([^>]*)>(&nbsp;|\u00a0)?<\/\1>/gi;var emptyRx=/<(ol|ul|sub|sup|blockquote|span|font|a|table|tbody|tr|strong|em|b|i)\b([^>]+)><\/\1>/gi;var paddedRx=/<(p|h1|h2|h3|h4|h5|h6|pre|div|address|caption)\b([^>]+)>(&nbsp;|\u00a0)<\/\1>/gi;tinymce.create('tinymce.plugins.CleanupPlugin',{init:function(ed,url){var self=this;this.editor=ed;if(ed.settings.verify_html===false){ed.settings.validate=false;}
ed.onPreInit.add(function(){ed.schema.addValidElements('a[href|target|ping|rel|media|type|id|name|accesskey|class|dir|draggable|download|item|hidden|itemprop|role|spellcheck|style|subject|title|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup]');ed.schema.addValidElements('picture[id|accesskey|class|dir|lang|style|tabindex|title|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup]');ed.schema.addValidElements('source[src|srcset|media|type|sizes|id|accesskey|class|dir|lang|style|tabindex|title]');ed.schema.addValidChildren('picture[source|img]');if(ed.settings.validate){var elements=ed.schema.elements;each(split('span,a,i'),function(name){if(elements[name]){elements[name].removeEmpty=false;}});}
if(ed.settings.validate){var invalidAttribValue=ed.getParam('invalid_attribute_values','');if(invalidAttribValue){function replaceAttributeValue(nodes,name,re){var i=nodes.length,node;while(i--){node=nodes[i];if(new RegExp(re).test(node.attr(name))){node.attr(name,"");if(name==='src'||name==='href'){node.attr('data-mce-'+name,"");}}}}
each(tinymce.explode(invalidAttribValue),function(item){var re,matches=/([a-z\*]+)\[([a-z]+)([\^\$]?=)["']([^"']+)["']\]/i.exec(item);if(matches&&matches.length==5){var tag=matches[1],attrib=matches[2],expr=matches[3],value=matches[4];switch(expr){default:case'=':re='('+value+')';break;case'!=':re='(^'+value+')';break;case'^=':re='^('+value+')';break;case'$=':re='('+value+')$';break;}
if(tag=='*'){ed.parser.addAttributeFilter(attrib,function(nodes,name){replaceAttributeValue(nodes,name,re);});}else{ed.parser.addNodeFilter(tag,function(nodes,name){replaceAttributeValue(nodes,attrib,re);});}}});}}else{ed.serializer.addNodeFilter(ed.settings.invalid_elements,function(nodes,name){var i=nodes.length,node;if(ed.schema.isValidChild('body',name)){while(i--){node=nodes[i];node.remove();}}});ed.parser.addNodeFilter(ed.settings.invalid_elements,function(nodes,name){var i=nodes.length,node;if(ed.schema.isValidChild('body',name)){while(i--){node=nodes[i];if(name==='span'&&node.attr('data-mce-type')){continue;}
node.unwrap();}}});}
ed.parser.addNodeFilter('a,i,span',function(nodes,name){var i=nodes.length,node,cls;while(i--){node=nodes[i],cls=node.attr('class');if(cls){node.attr('data-mce-bootstrap','1');if(!node.firstChild){node.append(new Node('#text','3')).value='\u00a0';}}}});ed.serializer.addAttributeFilter('data-mce-bootstrap',function(nodes,name){var i=nodes.length,node,fc;while(i--){node=nodes[i],fc=node.firstChild;node.attr('data-mce-bootstrap',null);if(fc&&(fc.value==='\u00a0'||fc.value==='&nbsp;')){fc.remove();}}});ed.parser.addAttributeFilter('onclick,ondblclick',function(nodes,name){var i=nodes.length,node;while(i--){node=nodes[i];node.attr('data-mce-'+name,node.attr(name));node.attr(name,null);}});ed.serializer.addAttributeFilter('data-mce-onclick,data-mce-ondblclick',function(nodes,name){var i=nodes.length,node,k;while(i--){node=nodes[i],k=name.replace('data-mce-','');node.attr(k,node.attr(name));node.attr(name,null);}});ed.serializer.addNodeFilter('br',function(nodes,name){var i=nodes.length,node,k;if(i){while(i--){node=nodes[i];if(node.parent&&node.parent.name==="body"&&!node.prev){node.remove();}}}});ed.parser.addNodeFilter('br',function(nodes,name){var i=nodes.length,node,k;if(i){while(i--){node=nodes[i];if(node.parent&&node.parent.name==="body"&&!node.prev){node.remove();}}}});});if(ed.settings.validate===false&&ed.settings.verify_html===false){ed.addCommand('mceCleanup',function(){var s=ed.settings,se=ed.selection,bm;bm=se.getBookmark();var content=ed.getContent({cleanup:true});var schema=new tinymce.html.Schema({validate:true,verify_html:true,valid_styles:s.valid_styles,valid_children:s.valid_children,custom_elements:s.custom_elements,extended_valid_elements:s.extended_valid_elements});content=new tinymce.html.Serializer({validate:true},schema).serialize(new tinymce.html.DomParser({validate:true},schema).parse(content));ed.setContent(content,{cleanup:true});se.moveToBookmark(bm);});}
ed.onBeforeSetContent.add(function(ed,o){o.content=o.content.replace(/^<br>/,'');o.content=self.convertFromGeshi(o.content);if(ed.settings.validate){if(ed.getParam('invalid_attributes')){var s=ed.getParam('invalid_attributes','');o.content=o.content.replace(new RegExp('<([^>]+)('+s.replace(/,/g,'|')+')="([^"]+)"([^>]*)>','gi'),'<$1$4>');}}
o.content=o.content.replace(fontIconRe,'<$1$2class="$3$4$5-$6$7"$8>&nbsp;</$1>');o.content=o.content.replace(/<(a|i|span)([^>]+)><\/\1>/gi,'<$1$2>&nbsp;</$1>');});ed.onPostProcess.add(function(ed,o){if(o.set){o.content=self.convertFromGeshi(o.content);}
if(o.get){o.content=self.convertToGeshi(o.content);o.content=o.content.replace(/<a([^>]*)class="jce(box|popup|lightbox|tooltip|_tooltip)"([^>]*)><\/a>/gi,'');o.content=o.content.replace(/<span class="jce(box|popup|lightbox|tooltip|_tooltip)">(.*?)<\/span>/gi,'$2');o.content=o.content.replace(/_mce_(src|href|style|coords|shape)="([^"]+)"\s*?/gi,'');if(ed.settings.validate===false){o.content=o.content.replace(/<body([^>]*)>([\s\S]*)<\/body>/,'$2');if(!ed.getParam('remove_tag_padding')){o.content=o.content.replace(/<(p|h1|h2|h3|h4|h5|h6|th|td|pre|div|address|caption)([^>]*)><\/\1>/gi,'<$1$2>&nbsp;</$1>');}}
if(!ed.getParam('table_pad_empty_cells',true)){o.content=o.content.replace(/<(th|td)([^>]*)>(&nbsp;|\u00a0)<\/\1>/gi,'<$1$2></$1>');}
o.content=o.content.replace(fontIconRe,'<$1$2class="$3$4$5-$6$7"$8></$1>');o.content=o.content.replace(/<(a|i|span)([^>]+)>(&nbsp;|\u00a0)<\/\1>/gi,'<$1$2></$1>');if(ed.getParam('remove_div_padding')){o.content=o.content.replace(/<div([^>]*)>(&nbsp;|\u00a0)<\/div>/g,'<div$1></div>');}
if(ed.getParam('pad_empty_tags',true)===false){o.content=o.content.replace(paddedRx,'<$1$2></$1>');}}});ed.onSaveContent.add(function(ed,o){if(ed.getParam('cleanup_pluginmode')){var entities={'&#39;':"'",'&amp;':'&','&quot;':'"','&apos;':"'"};o.content=o.content.replace(/&(#39|apos|amp|quot);/gi,function(a){return entities[a];});}});ed.addButton('cleanup',{title:'advanced.cleanup_desc',cmd:'mceCleanup'});},convertFromGeshi:function(h){h=h.replace(/<pre xml:lang="([^"]+)"([^>]*)>(.*?)<\/pre>/g,function(a,b,c,d){var attr='';if(c&&/\w/.test(c)){attr=c.split(' ').join(' data-geshi-');}
return'<pre data-geshi-lang="'+b+'"'+attr+'>'+d+'</pre>';});return h;},convertToGeshi:function(h){h=h.replace(/<pre([^>]+)data-geshi-lang="([^"]+)"([^>]*)>(.*?)<\/pre>/g,function(a,b,c,d,e){var s=b+d;s=s.replace(/data-geshi-/gi,'').replace(/\s+/g,' ').replace(/\s$/,'');return'<pre xml:lang="'+c+'"'+s+'>'+e+'</pre>';});return h;},getInfo:function(){return{longname:'Cleanup',author:'Ryan Demmer',authorurl:'http://www.joomlacontenteditor.net',infourl:'http://www.joomlacontenteditor.net',version:'2.4.6'};}});tinymce.PluginManager.add('cleanup',tinymce.plugins.CleanupPlugin);})();