/*
 Copyright (c) CKSource - Frederico Knabben. All rights reserved.

 For licensing, see LICENSE.html or http://ckeditor.com/license

*/
(function(){function k(a){var b=null!=a.config.autosave_SaveKey?a.config.autosave_SaveKey:"autosave_"+window.location+"_"+a.id,g=null!=a.config.autosave_NotOlderThen?a.config.autosave_NotOlderThen:1440,c=null!=a.config.autosave_saveOnDestroy?a.config.autosave_saveOnDestroy:!1,d=null!=a.config.autosave_saveDetectionSelectors?a.config.autosave_saveDetectionSelectors:"a[href^\x3d'javascript:__doPostBack'][id*\x3d'Save'],a[id*\x3d'Cancel']";CKEDITOR.scriptLoader.load(CKEDITOR.getUrl(CKEDITOR.plugins.getPath("autosave")+
"js/extensions.min.js"),function(){p(a,b);if(localStorage.getItem(b)){var c=h(b),d=c.data,c=c.saveTime;a.getSnapshot()==d?localStorage.removeItem(b):moment(new Date).diff(new Date(c),"minutes")>g?e(b):(d=a.lang.autosave.loadSavedContent.replace("{0}",moment(c).locale(a.config.language).format(a.lang.autosave.dateFormat)),confirm(d)?a.openDialog("autosaveDialog"):e(b))}});jQuery(d).click(function(){e(b)});a.on("change",l);a.on("destroy",function(){c&&m(b,a)})}function p(a,b){CKEDITOR.dialog.add("autosaveDialog",
function(){return{title:a.lang.autosave.title,minHeight:155,height:300,width:750,onShow:function(){n(this,a,b)},onOk:function(){if(localStorage.getItem(b)){var g=h(b);a.loadSnapshot(g.data);e(b)}},onCancel:function(){e(b)},contents:[{label:"",id:"general",elements:[{type:"radio",id:"diffType",label:a.lang.autosave.diffType,items:[[a.lang.autosave.sideBySide,"sideBySide"],[a.lang.autosave.inline,"inline"]],"default":"sideBySide",onClick:function(){n(this._.dialog,a,b)}},{type:"html",id:"diffContent",
html:""}]}],buttons:[{id:"ok",type:"button",label:a.lang.autosave.ok,"class":"cke_dialog_ui_button_ok cke_dialog_autosave_ok",onClick:function(a){a=a.data.dialog;!1!==a.fire("ok",{hide:!0}).hide&&a.hide()}},{id:"cancel",type:"button",label:a.lang.autosave.no,"class":"cke_dialog_ui_button_cancel",onClick:function(a){a=a.data.dialog;!1!==a.fire("cancel",{hide:!0}).hide&&a.hide()}}]}})}function h(a){a=LZString.decompressFromUTF16(localStorage.getItem(a));return JSON.parse(a)}function m(a,b){var c=LZString.compressToUTF16(JSON.stringify({data:b.getSnapshot(),
saveTime:new Date}));localStorage.setItem(a,c);(new CKEDITOR.plugins.notification(b,{message:b.lang.autosave.autoSaveMessage,type:"success"})).show()}function e(a){c&&clearTimeout(c);localStorage.removeItem(a)}function n(a,b,c){c=h(c);var e=difflib.stringAsLines(b.getSnapshot()),d=difflib.stringAsLines(c.data),f=(new difflib.SequenceMatcher(e,d)).get_opcodes();a.getContentElement("general","diffContent").getElement().setHtml('\x3cdiv class\x3d"diffContent"\x3e'+diffview.buildView({baseTextLines:e,
newTextLines:d,opcodes:f,baseTextName:b.lang.autosave.loadedContent,newTextName:b.lang.autosave.autoSavedContent+moment(c.saveTime).locale(b.config.language).format(b.lang.autosave.dateFormat)+"'",contextSize:3,viewType:"inline"==a.getContentElement("general","diffType").getValue()?1:0}).outerHTML+"\x3c/div\x3e")}if(function(){if("undefined"===typeof Storage)return!1;try{return localStorage.getItem("___test_key"),!0}catch(a){return!1}}()){CKEDITOR.plugins.add("autosave",{lang:"en,zh-cn",requires:"notification",
version:.13,init:function(a){CKEDITOR.document.appendStyleSheet(CKEDITOR.getUrl(CKEDITOR.plugins.getPath("autosave")+"css/autosave.min.css"));a.on("instanceReady",function(){"undefined"===typeof jQuery?CKEDITOR.scriptLoader.load("http://cdn.wuzhicms.com/jquery/2.1.4/jquery.min.js",function(){jQuery.noConflict();k(a)}):CKEDITOR.scriptLoader.load(CKEDITOR.getUrl(CKEDITOR.plugins.getPath("autosave")+"js/extensions.min.js"),function(){k(a)})},a,null,100)}});var c=0,f=!1,l=function(a){c||(c=setTimeout(q,
1E3*(null!=CKEDITOR.config.autosave_delay?CKEDITOR.config.autosave_delay:10),a))},q=function(a){if(f)l(a);else if(a.editor.checkDirty()||a.editor.plugins.bbcode)f=!0,a=a.editor,m(null!=a.config.autosave_SaveKey?a.config.autosave_SaveKey:"autosave_"+window.location+"_"+a.id,a),c=0,f=!1}}else CKEDITOR.plugins.add("autosave",{})})();