text: ﻿/*
  Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
  For licensing, see LICENSE.html or http://ckeditor.com/license
  */
  
  (function(){var a=0,b=0,c=false,d=false,e=false,f='',g='',h='',i='',j='',k=true,l='',m=/^form$|^body$/i,n=/^form$/i,o=(function(){var y=null,z=function(G,H){if(!H){s(G,f[5].path,f[5].title+G.lang.autosave.noUrl);window.clearTimeout(i);i=CKEDITOR.tools.setTimeout(s,5000,null,[G,f[1].path,f[1].title]);throw new Error(G.lang.autosave.noUrl);}y=G;},A=(function(){var G=[function(){return{xhr:new XMLHttpRequest(),xhrTimeout:false};},function(){return{xhr:new ActiveXObject('Msxml2.XMLHTTP'),xhrTimeout:false};},function(){return{xhr:new ActiveXObject('Microsoft.XMLHTTP'),xhrTimeout:false};}];for(var H=0,I=G.length;H<I;H++){try{G[H]();}catch(J){continue;}A=G[H];return G[H];}throw new Error(y.lang.autosave.noXhr);})(),B=function(G){var H=G.split('?')[1];if(!H)return G;var I=C(H);G=G.replace(/\?.*/,'?'+I);return G;},C=function(G){var H=G.split('&'),I='';for(var J=0,K=H.length;J<K;J++){if(H[J].substring(0,H[J].indexOf('='))!=y.config.autosaveContentParamName)H[J]=H[J].replace(/\=.*/,'='+encodeURIComponent(H[J].substring(H[J].indexOf('=')+1)));I+=(J===0?'':'&')+H[J];}return I;},D=function(G,H){var I='';I=y.lang.autosave['error'+G];if(!I)if(H)I='('+G+') '+H;else I=y.lang.autosave.defaultErrorMessage.replace(/(###)/,G);s(y,f[5].path,f[5].title+I);},E=function(){var G=new Date(),H=G.getHours(),I=G.getMinutes(),J=G.getSeconds();if(H<10)H='0'+H;if(I<10)I='0'+I;if(J<10)J='0'+J;return H+':'+I+':'+J;},F=function(G,H){if(G)return H?f[1].path:f[0].path;else return H?f[1].title:f[0].title+h;};return{request:function(G,H,I,J){z(G,I);var K=A();K.xhr.onreadystatechange=function(){K.xhrTimeout=false;if(y.config.autosaveRequestTimeout)if(K.xhr.readyState==1)j=window.setTimeout(function(){if(K.xhr.readyState==1||K.xhr.readyState==2&&CKEDITOR.env.opera){K.xhr.abort();K.xhrTimeout=true;s(y,f[5].path,f[5].title+y.lang.autosave.requestTimeout);window.clearTimeout(i);i=CKEDITOR.tools.setTimeout(t,10000,null,[y,F(true,b),F(false,b)]);e=false;if(b)a+=b;}},y.config.autosaveRequestTimeout*1000);if(K.xhr.readyState==4&&!K.xhrTimeout){if(K.xhr.status>=200&&K.xhr.status<300||K.xhr.status==304||K.xhr.status===0||K.xhr.status==1223){if(y.config.autosaveRequestTimeout)window.clearTimeout(j);var L='',M='';if(K.xhr.responseXML){L=K.xhr.responseXML.getElementsByTagName('result')[0];M=K.xhr.responseXML.getElementsByTagName('error')[0];}if(L&&L.attributes.getNamedItem('status')&&L.attributes.getNamedItem('status').value=='ok'){h=E();s(y,f[4].path,f[4].title+h);window.clearTimeout(i);i=CKEDITOR.tools.setTimeout(t,5000,null,[y,f[0].path,f[0].title+h]);
  b=0;}else if(M&&(M.attributes.getNamedItem('statuscode')&&M.attributes.getNamedItem('statuscode').value||M.attributes.getNamedItem('message')&&M.attributes.getNamedItem('message').value)){if(M.attributes.getNamedItem('message')&&M.attributes.getNamedItem('message').value)s(y,f[5].path,f[5].title+M.attributes.getNamedItem('message').value);else D(M.attributes.getNamedItem('statuscode').value);window.clearTimeout(i);i=CKEDITOR.tools.setTimeout(t,10000,null,[y,F(true,b),F(false,b)]);}else{s(y,f[5].path,f[5].title+(K.xhr.responseText?K.xhr.responseText:K.xhr.status?y.lang.autosave.defaultErrorMessage.replace(/(###)/,K.xhr.status):y.lang.autosave.unknownError));window.clearTimeout(i);i=CKEDITOR.tools.setTimeout(t,10000,null,[y,F(true,b),F(false,b)]);}}else{D(K.xhr.status,K.xhr.responseText);window.clearTimeout(i);i=CKEDITOR.tools.setTimeout(t,10000,null,[y,F(true,b),F(false,b)]);}e=false;if(b)a+=b;}};if(H=='GET'){I=I.indexOf('?')>0?I+'&'+J:I+'?'+J;I=B(I);J=null;}K.xhr.open(H,I,true);if(H=='POST'){K.xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');J=C(J);}K.xhr.send(J);}};})();function p(y){if(y.checkDirty()){a++;y.resetDirty();s(y,f[1].path,f[1].title);}if(!e){e=true;if(c||d){if(d){d=false;if(a>0&&k)q(y);else e=false;}else{c=false;q(y);}}else if(y.config.autosaveSensitivity&&a>=y.config.autosaveSensitivity){if(k){window.clearTimeout(l);k=false;q(y);}else e=false;}else{e=false;if(!y.config.autosaveSensitivity&&!y.config.autosaveRefreshTime)a=0;}}if(c)c=false;};function q(y){var z=y.getData();b=a;a=0;r(y,z);};function r(y,z){s(y,f[3].path,f[3].title);o.request(y,y.config.autosaveMethod,y.config.autosaveTargetUrl,'autosaveaction=draft&ckeditorname='+y.name+'&'+y.config.autosaveContentParamName+'='+encodeURIComponent(z));window.clearTimeout(l);k=false;l=window.setTimeout(function(){k=true;},y.config.autosaveMinTimeBetweenRequests*1000);};function s(y,z,A){var B=CKEDITOR.document.getById(y._.commands.autosave.uiItems[0]._.id);B.getFirst().setStyle('background-image','url('+y.plugins.autosave.path+z+')');B.setAttribute('title',A);B.getChild(1).setHtml(A);};function t(y,z,A){if(a===b&&!e&&!y.checkDirty())s(y,z,A);};function u(y,z,A){if(y.addEventListener)y.addEventListener(z,A,false);else if(y.attachEvent)y.attachEvent('on'+z,A);};function v(y){e=true;y.config.autosaveUseOnBeforeUnload=false;window.clearInterval(g);window.clearTimeout(i);window.clearTimeout(l);return true;};function w(y,z){if(!z)z=document.getElementsByTagName('body')[0];
  var A='',B=new RegExp('\\b'+y+'\\b'),C=z.getElementsByTagName('*');for(var D=0,E=C.length;D<E;D++){if(B.test(C[D].className)){A=C[D];break;}}return A;};function x(y){if(!m.test(y.nodeName))return x(y.parentNode);else if(n.test(y.nodeName))return y;else return null;};CKEDITOR.plugins.add('autosave',{lang:['en','pl','zh-cn'],init:function(y){y.on('instanceReady',function(z){if(y.config.autosaveRefreshTime&&parseInt(y.config.autosaveRefreshTime,10)<parseInt(y.config.autosaveMinTimeBetweenRequests,10))y.config.autosaveRefreshTime=y.config.autosaveMinTimeBetweenRequests;y.on('saveSnapshot',function(){if(!z.data||!z.data.contentOnly)p(y);});y.on('beforeCommandExec',function(D){if(D.data.name=='save')v(y);});y.getCommand('undo').on('afterUndo',function(){p(y);});y.getCommand('redo').on('afterRedo',function(){p(y);});y.on('contentDom',function(){y.document.on('keydown',function(D){if(D.data.$.ctrlKey||D.data.$.metaKey)return;var E=D.data.$.keyCode;if(E==8||E==13||E==32||E>=46&&E<=90||E>=96&&E<=111||E>=186&&E<=222)window.setTimeout(function(){p(y);},100);});y.document.on('drop',function(){p(y);});y.document.getBody().on('drop',function(){p(y);});});y.fire('contentDom');y.on('mode',function(D){if(y.mode!='source')return;y.textarea.on('keydown',function(E){if(E.data.$.ctrlKey||E.data.$.metaKey)return;var F=E.data.$.keyCode;if(F==8||F==13||F==32||F>=46&&F<=90||F>=96&&F<=111||F>=186&&F<=222)window.setTimeout(function(){p(y);},100);});y.textarea.on('drop',function(){p(y);});y.textarea.on('input',function(){p(y);});});y.on('afterCommandExec',function(D){if(D.data.name=='source')return;if(D.data.command.canUndo!==false)p(y);});z.editor.on('destroy',function(D){window.clearInterval(g);window.clearTimeout(i);window.clearTimeout(l);});if(y.config.autosaveParentFormId&&document.getElementById(y.config.autosaveParentFormId)){var A=document.getElementById(y.config.autosaveParentFormId);u(A,'submit',function(){v(y);});}else{var B=w(y.id);if(B){var C=x(B);if(C)u(C,'submit',function(){v(y);});}}if(y.config.autosaveUseOnBeforeUnload)window.onbeforeunload=function(){if(y.config.autosaveUseOnBeforeUnload)if(a>0||e)return y.lang.autosave.looseChanges;};if(y.config.autosaveRefreshTime&&!parseInt(y.config.autosaveRefreshTime,10)<1)g=window.setInterval(function(){d=true;p(y);},y.config.autosaveRefreshTime*1000);window.onunload=function(){window.clearInterval(g);window.clearTimeout(i);window.clearTimeout(l);window.onbeforeunload=null;};});f=[{path:'images/autosaveClean.gif',title:y.lang.autosave.draftSaved},{path:'images/autosaveDirty.gif',title:y.lang.autosave.needsSaving},{path:'images/loadingBig.gif',title:y.lang.autosave.inProgress},{path:'images/loadingSmall.gif',title:y.lang.autosave.inProgress},{path:'images/tick_animated.gif',title:y.lang.autosave.draftSaved},{path:'images/cross_animated.gif',title:y.lang.autosave.errorTemplate}];
  y.addCommand('autosave',{modes:{wysiwyg:1,source:1},exec:function(z){p(z);}});y.ui.addButton('Autosave',{label:y.lang.autosave.defaultMessage,command:'autosave',click:function(z){c=true;z.execCommand('autosave');},icon:this.path+'images/autosaveClean.gif'});}});})();CKEDITOR.tools.extend(CKEDITOR.config,{autosaveSensitivity:20,autosaveRefreshTime:30,autosaveUseOnBeforeUnload:true,autosaveTargetUrl:'',autosaveParentFormId:'',autosaveMethod:'POST',autosaveContentParamName:'content',autosaveRequestTimeout:10,autosaveMinTimeBetweenRequests:15});
  