(function(e){var j,k,i=null,l=null,m=null,h={init:function(){var a=document.getElementById("editor");j=e(a);e.editplus.setPlugin("clip",function(d,f){if(i){i.find("input").val("");i.find("textarea").val(f.text);i.dialog("open")}else{i=e("#addclip");i.find("textarea").val(f.text);ct.dialog("\u6dfb\u52a0\u6a21\u677f\u526a\u8f91",i,450,document.compatMode=="CSS1Compat"?220:340,function(){var g="name="+encodeURIComponent(i.find("input").val())+"&code="+encodeURIComponent(i.find("textarea").val());e.ajax({dataType:"json",
type:"post",data:g,url:"?app=system&controller=template&action=addclip",success:function(n){h.addOneClip(n)}})})}},{text:"\u8f6c\u5316\u4e3a\u526a\u8f91",desc:"\u8f6c\u5316\u4e3a\u526a\u8f91"}).setPlugin("template",function(d,f){ct.dialog("\u63d2\u5165\u5b50\u6a21\u677f\u6807\u7b7e","template",300,100,function(g){j.insertSection("{template '"+g.find("input:eq(0)").val()+"'}",f.selection)}).find("input").val("")},{desc:"\u5b50\u6a21\u677f"}).setPlugin("section",function(d,f){ct.form("\u6dfb\u52a0/\u8f6c\u5316\u4e3a\u533a\u5757",
"?app=section&controller=section&action=save&src=tpl",610,460,function(g){if(g.state){h.addOneSection(g.data);j.insertSection('<!--#include virtual="/section/'+g.data.sectionid+'.html"--\><!--'+g.data.name+"--\>",f.selection);return true}},function(g){f.text&&setTimeout(function(){e(g).find("div.editarea>textarea:last").val(f.text)},0)})},{text:"\u6dfb\u52a0/\u8f6c\u5316\u4e3a\u533a\u5757",desc:"\u6dfb\u52a0/\u8f6c\u5316\u4e3a\u533a\u5757"});k=j.editplus({buttons:"fullscreen,wrap,|,db,content,discuz,phpwind,shopex,|,loop,ifelse,elseif,template,|,preview,section,clip",
width:430,height:430});var c=function(){var d=ct.innerWidth();k.setDim(d-220)};window.onresize=c;c();l=e("#clipContainer");h.loadClip();m=e("#sectionContainer");h.loadSection();var b=e("#toolbox>div.toolarea");e("#tooltab").tabnav({dataType:null,initFocus:1,forceFocus:true,focused:function(d){b.hide();d=d.attr("index");b[d].style.display="block";h.add=d==0?k.clip:k.section}}).prev("a").click(function(){h.add(e(this),k.getSelection());return false});e(a.form).ajaxForm(function(d){d.state?ct.confirm("\u4fdd\u5b58\u6210\u529f\uff0c\u7ee7\u7eed\u5f85\u5728\u6b64\u9875\uff1f",
null,function(){ct.assoc.close()}):ct.error(d.error)})},addOneClip:function(a,c){var b=e('<li><a href="">'+a.name+"</a></li>"),d=b.find("a");d.click(function(){var f=k.getSelection(),g=(a.code||"").replace(/\^\!/g,f.text);j.insertSection(g,f.selection);return false}).contextMenu("#clip_menu",function(f){h[f](d,a.clipid)});c?c.replaceWith(b):l.append(b);return b},addOneSection:function(a){var c=e('<li><a class="'+a.type+'" href="">'+a.name+"</a></li>"),b=c.find("a");b.click(function(){j.insertSection('<!--#include virtual="/section/'+
a.sectionid+'.html"--\><!--'+a.name+"--\>");return false}).contextMenu("#section_menu",function(d){h[d](b,a.sectionid)});m.prepend(c);return c},delClip:function(a,c){ct.confirm('\u786e\u5b9a\u8981\u5220\u9664\u526a\u8f91"'+a.text()+'"\u5417\uff1f',function(){e.post("?app=system&controller=template&action=delclip","clipid="+c,function(b){b.state&&a.parent().remove()},"json")})},editClip:function(a,c){ct.form("\u7f16\u8f91\u526a\u8f91:"+a.html(),"?app=system&controller=template&action=editclip&clipid="+
c,450,220,function(b){if(b.state){h.addOneClip(b.data,a.parent());return true}})},loadClip:function(){l.empty();e.getJSON("?app=system&controller=template&action=loadclip",function(a){for(var c=0,b;b=a[c++];h.addOneClip(b));})},loadSection:function(){m.empty();e.getJSON("?app=section&controller=section&action=loadSection",function(a){for(var c=0,b;b=a[c++];h.addOneSection(b));})},viewSection:function(a,c){ct.ajax("\u67e5\u770b\u533a\u5757\uff1a"+a.html(),"?app=section&controller=data&action=view&sectionid="+
c)},setProperty:function(a,c){var b="?app=section&controller=section&action=save&sectionid="+c;ct.form("\u8bbe\u7f6e\u533a\u5757\u201c"+a.html()+"\u201d\u5c5e\u6027",b,610,460,function(d){if(d.state){a.html(d.name);return true}})},insertClip:function(a){a.click()},insertSection:function(a){a.click()},add:null};window.editplus=h})(jQuery);
