CKEDITOR.plugins.add("doksoft_backup",{lang:"ru,en",init:function(a){a.on("instanceReady",function(g){var b=document.createElement("div"),i=0,c="display:inline-block; margin-left:10px;position:relative;margin-top:-2px;overflow:hidden;float:right;",f="doksoft_backup_"+a.name,k=true,h="";b.setAttribute("style",c);if(localStorage.getItem(f)==undefined){localStorage.setItem(f,"{}");}var j=function(e){var m=new Date(parseInt(e));var l=function(n){if(n<10){n="0"+n;}return n;};return m.getHours()+"."+l(m.getMinutes())+"."+l(m.getSeconds());};a.backup=function(l){var q=false,m=new Date().getTime(),e={};if(l!="del"){var p=a.getSnapshot();if(p!=""){if(localStorage.getItem(f)&&h&&p!=h){e=JSON.parse(localStorage.getItem(f));e[m]=p;localStorage.setItem(f,JSON.stringify(e));q=true;}}}else{if(confirm(a.lang.doksoft_backup.mess1)){localStorage.setItem(f,"{}");q=true;}}if(q||k){if(k&&localStorage.getItem(f)){e=JSON.parse(localStorage.getItem(f));}var n="<option>---</option>";for(var o in e){n+='<option value="'+o+'">'+j(o)+"</option>";}i.setHtml(n);k=false;}h=p;},a.restore=function(){var m=a.getSnapshot();var l=i.getValue();var e=JSON.parse(localStorage.getItem(f));if(e[l]!=undefined&&(m==""||confirm(a.lang.doksoft_backup.mess))){a.loadSnapshot(e[l]);}};var d=0;a.on("change",function(){clearTimeout(d);d=setTimeout(function(){a.backup();},3000);});b.innerHTML='<select style=" padding:0px; min-height: 25px;display: inline-block;" id="backuper_'+a.name+'"></select>&nbsp;<input type="image" value="del" onclick="CKEDITOR.instances[\''+a.name+"'].backup('del'); return false;\" src=\""+CKEDITOR.basePath+'plugins/doksoft_backup/clear.png"/>';b.onchange=a.restore;CKEDITOR.document.getById(a.ui.spaceId?a.ui.spaceId("bottom"):"cke_bottom_"+a.name).append(new CKEDITOR.dom.node(b));i=CKEDITOR.document.getById("backuper_"+a.name);a.backup();});}});