var Editor=function(){this.nav=jQuery(".nav-tab-wrapper.custom").find(".nav-tab"),this.tabs=jQuery(".tabs > .tab"),this.active=0,this.navActiveClass="nav-tab-active",this.tabActiveClass="active-tab",this.tabindex=jQuery("#tab-index"),this._initEditors()};Editor.prototype.open=function(a){if(this.active!=a){var b=this,c=b.tabs,d=b.nav,e=b.active;jQuery(d[e]).removeClass(b.navActiveClass),jQuery(d[a]).addClass(b.navActiveClass),jQuery(c[e]).removeClass(b.tabActiveClass),jQuery(c[a]).addClass(b.tabActiveClass),b.active=a,b.tabindex.val(a),b.applyCss()}},Editor.prototype._initEditors=function(){this.editors=[ace.edit("editor1"),ace.edit("editor2")],jQuery.each(this.editors,function(a,b){b.setTheme("ace/theme/monokai"),b.getSession().setMode("ace/mode/css"),b.on("change",function(){var c="#codesource"+(a+1),d=b.getValue();jQuery(c).html(d),jQuery("#arwprev").html(d)})})},Editor.prototype.applyCss=function(){var a="#codesource"+(this.active+1),b=jQuery(a).html();jQuery("#arwprev").html(b),jQuery.each(this.editors,function(a,b){b.resize()})},Editor.prototype.openFileDialog=function(){var a=document.getElementById("files");if(a&&document.createEvent){var b=document.createEvent("MouseEvents");b.initEvent("click",!0,!1),a.dispatchEvent(b)}},Editor.prototype.handleFileSelect=function(a){var b=this,c=a.target.files;if(!c.length)return void alert("Please select a file!");var d=c[0],e=0,f=d.size-1,g=new FileReader;g.onloadend=function(a){if(a.target.readyState==FileReader.DONE){var c,d=a.target.result;if(d.match(/theme1/))c=0;else{if(!d.match(/theme2/))return void(d="");c=1}b.editors[c].setValue(d),b.active!=c&&b.open(c)}};var h=d.slice(e,f+1);g.readAsBinaryString(h)},jQuery(function(a){var b=new Editor;"undefined"!=typeof editor_tab&&b.open(editor_tab),a("#theme-css-editor").on("click","a.nav-tab",function(c){c.preventDefault(),b.open(a(this).index())}),a("#import-theme").on("click",function(a){a.preventDefault(),b.openFileDialog()}),a("#files").on("change",function(c){b.handleFileSelect(c),a(this).val("")})});