(function(){var each=tinymce.each,JSON=tinymce.util.JSON,Node=tinymce.html.Node;tinymce.create('tinymce.plugins.CodePlugin',{init:function(ed,url){var self=this;this.editor=ed;this.url=url;ed.onPreInit.add(function(){if(ed.getParam('code_javascript')){ed.schema.addValidElements('script[src|charset|defer|type|xml::space]')}ed.parser.addNodeFilter('script',function(nodes,name){for(var i=0;i<nodes.length;i++){var node=nodes[i];self._serializeSpan(node)}});ed.serializer.addNodeFilter('span',function(nodes,name,args){for(var i=0;i<nodes.length;i++){var node=nodes[i],cls=node.attr('class');if(cls&&/mceSCRIPT/.test(cls)){self._buildScript(node)}}})});ed.onInit.add(function(){if(ed.settings.content_css!==false)ed.dom.loadCSS(url+"/css/content.css")});ed.onBeforeSetContent.add(function(ed,o){if(/<(\?|script)/.test(o.content)){if(!ed.getParam('code_javascript')){o.content=o.content.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi,'')}if(!ed.getParam('code_php')){o.content=o.content.replace(/<\?(php)?([\s\S]*?)\?>/gi,'')}o.content=o.content.replace(/\="([^"]+?)"/g,function(a,b){if(/<\?(php)?/.test(b)){b=ed.dom.encode(b)}return'="'+b+'"'});if(/<textarea/.test(o.content)){o.content=o.content.replace(/<textarea([^>]*)>([\s\S]*?)<\/textarea>/gi,function(a,b,c){if(/<\?(php)?/.test(c)){c=ed.dom.encode(c)}return'<textarea'+b+'>'+c+'</textarea>'})}o.content=o.content.replace(/<([^>]+)<\?(php)?(.+?)\?>([^>]*?)>/gi,function(a,b,c,d,e){if(b.charAt(b.length)!==' '){b+=' '}return'<'+b+'data-mce-php="'+d+'" '+e+'>'});o.content=o.content.replace(/<\?(php)?([\s\S]+?)\?>/gi,'<span class="mcePHP" data-mce-type="php"><!--PHP$2PHP--></span>')}});ed.onPostProcess.add(function(ed,o){if(o.get){if(/mcePHP/.test(o.content)){o.content=o.content.replace(/"(.*?)&lt;\?(php)?([^"]+)\?&gt;(.*?)"/g,function(a,b,c,d,e){return'"'+b+'<?php'+t._decode(d)+'?>'+e+'"'});o.content=o.content.replace(/<textarea([^>]*)>([\s\S]*?)<\/textarea>/gi,function(a,b,c){if(/&lt;\?php/.test(c)){c=self._decode(c)}return'<textarea'+b+'>'+c+'</textarea>'});o.content=o.content.replace(/data-mce-php="([^"]+?)"/g,function(a,b){return'<?php'+self._decode(b)+'?>'});o.content=o.content.replace(/<span([^>]+)class="mcePHP"([^>]+)>(<!--PHP)?([\s\S]*?)(PHP-->)?<\/span>/g,function(a,b,c,d,e){return'<?php'+self._decode(e)+'?>'})}if(/<script/.test(o.content)){o.content=o.content.replace(/<script([^>]+)>([\s\S]*?)<\/script>/g,function(a,b,c){c=self._trim(c);c=c.replace(/&nbsp;/g,' ');c=self._decode(c);if(c&&/\S*/.test(c)){if(c&&ed.getParam('code_cdata',false)){c='\n// <![CDATA[\n'+c+'\n// ]]>\n'}else{c='\n'+c+'\n'}}return'<script'+b+'>'+c+'</script>'})}}})},_buildScript:function(n){var self=this,ed=this.editor,s,node,text;if(!n.parent)return;p=JSON.parse(n.attr('data-mce-json'))||{};p.type='text/javascript';if(p.src){p.src=ed.dom.decode(p.src).replace(/&amp;/g,'&')}if(n.firstChild){s=self._trim(n.firstChild.value)}node=new Node('script',1);text=new Node('#text',3);text.value=this._decode(s);each(p,function(v,k){node.attr(k,v)});node.append(text);n.replace(node);return true},_serializeSpan:function(n){var self=this,ed=this.editor,dom=ed.dom,v,k,p={};if(!n.parent)return;each(n.attributes,function(at){if(at.name=='type')return;p[at.name]=at.value});var name=n.name.toUpperCase();var span=new Node('span',1);span.attr('class','mce'+name);span.attr('data-mce-json',JSON.serialize(p));span.attr('data-mce-type',n.name);var text=new Node('#comment',8);if(n.firstChild){text.value=n.firstChild.value}span.append(text);n.replace(span)},_decode:function(s){return s.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&').replace(/&quot;/g,'"')},_encode:function(s){s=s.replace(/&amp;/g,'&');return this.editor.dom.encode(s)},_trim:function(s){s=s.replace(/(\/\/\s+<!\[CDATA\[)/gi,'\n');s=s.replace(/(<!--\[CDATA\[|\]\]-->)/gi,'\n');s=s.replace(/^[\r\n]*|[\r\n]*$/g,'');s=s.replace(/^\s*(\/\/\s*<!--|\/\/\s*<!\[CDATA\[|<!--|<!\[CDATA\[)[\r\n]*/gi,'');s=s.replace(/\s*(\/\/\s*\]\]>|\/\/\s*-->|\]\]>|-->|\]\]-->)\s*$/g,'');return s},getInfo:function(){return{longname:'Code',author:'Ryan Demmer',authorurl:'http://www.joomlacontenteditor.net',infourl:'http://www.joomlacontenteditor.net',version:'1.5.7.10'}}});tinymce.PluginManager.add('code',tinymce.plugins.CodePlugin)})();