Note.curNoteId="";Note.interval="";Note.itemIsBlog='
';Note.itemTplNoImg='
  • ';Note.itemTplNoImg+=Note.itemIsBlog+'

    ?

    ? ?

    ?

  • ';Note.itemTpl='
  • ';Note.itemTpl+=Note.itemIsBlog+'

    ?

    ? ?

    ?

  • ';Note.newItemTpl='
  • ';Note.newItemTpl+=Note.itemIsBlog+'

    ?

    ? ?
    ?

  • ';Note.noteItemListO=$("#noteItemList");Note.cacheByNotebookId={all:{}};Note.notebookIds={};Note.isReadOnly=false;Note.intervalTime=6e5;Note.startInterval=function(){Note.interval=setInterval(function(){log("自动保存开始...");changedNote=Note.curChangedSaveIt(false)},Note.intervalTime)};Note.stopInterval=function(){clearInterval(Note.interval);setTimeout(function(){Note.startInterval()},Note.intervalTime)};Note.addNoteCache=function(note){Note.cache[note.NoteId]=note;Note.clearCacheByNotebookId(note.NotebookId)};Note.setNoteCache=function(content,clear){if(!Note.cache[content.NoteId]){Note.cache[content.NoteId]=content}else{$.extend(Note.cache[content.NoteId],content)}if(clear==undefined){clear=true}if(clear){Note.clearCacheByNotebookId(content.NotebookId)}};Note.getCurNote=function(){var self=this;if(self.curNoteId==""){return null}return self.cache[self.curNoteId]};Note.getNote=function(noteId){var self=this;return self.cache[noteId]};Note.clearCacheByNotebookId=function(notebookId){if(notebookId){Note.cacheByNotebookId[notebookId]={};Note.cacheByNotebookId["all"]={};Note.notebookIds[notebookId]=true}};Note.notebookHasNotes=function(notebookId){var notes=Note.getNotesByNotebookId(notebookId);return!isEmpty(notes)};Note.getNotesByNotebookId=function(notebookId,sortBy,isAsc){if(!sortBy){sortBy="UpdatedTime"}if(isAsc=="undefined"){isAsc=false}if(!notebookId){notebookId="all"}if(!Note.cacheByNotebookId[notebookId]){return[]}if(Note.cacheByNotebookId[notebookId][sortBy]){return Note.cacheByNotebookId[notebookId][sortBy]}else{}var notes=[];var sortBys=[];for(var i in Note.cache){if(!i){continue}var note=Note.cache[i];if(note.IsTrash||note.IsShared){continue}if(notebookId=="all"||note.NotebookId==notebookId){notes.push(note)}}notes.sort(function(a,b){var t1=a[sortBy];var t2=b[sortBy];if(isAsc){if(t1t2){return 1}}else{if(t1t2){return-1}}return 0});Note.cacheByNotebookId[notebookId][sortBy]=notes;return notes};Note.curNoteIsDirtied=function(){var me=this;var note=me.getCurNote();if(note){note.isDirty=true}};Note.renderNotesAndFirstOneContent=function(ret){if(!isArray(ret)){return}Note.renderNotes(ret);if(!isEmpty(ret[0])){Note.changeNoteForPjax(ret[0].NoteId,true,false)}else{}};Note.curHasChanged=function(force){if(force==undefined){force=true}var cacheNote=Note.cache[Note.curNoteId]||{};var title=$("#noteTitle").val();var tags=Tag.getTags();var contents=getEditorContent(cacheNote.IsMarkdown);var content,preview;var contentText;if(isArray(contents)){content=contents[0];preview=contents[1];contentText=content;if(content&&previewIsEmpty(preview)&&Converter){preview=Converter.makeHtml(content)}if(!content){preview=""}cacheNote.Preview=preview}else{content=contents;try{contentText=$(content).text()}catch(e){}}var hasChanged={hasChanged:false,IsNew:cacheNote.IsNew,IsMarkdown:cacheNote.IsMarkdown,FromUserId:cacheNote.FromUserId,NoteId:cacheNote.NoteId,NotebookId:cacheNote.NotebookId};if(hasChanged.IsNew){$.extend(hasChanged,cacheNote)}else{if(!cacheNote.isDirty){log("no dirty");hasChanged.hasChanged=false;return hasChanged}}if(cacheNote.Title!=title){hasChanged.hasChanged=true;hasChanged.Title=title;if(!hasChanged.Title){}}if(!arrayEqual(cacheNote.Tags,tags)){hasChanged.hasChanged=true;hasChanged.Tags=tags.join(",")}if(force&&cacheNote.Content!=content||!force&&(!cacheNote.IsMarkdown&&$(cacheNote.Content).text()!=contentText||cacheNote.IsMarkdown&&cacheNote.Content!=contentText)){hasChanged.hasChanged=true;hasChanged.Content=content;var c=preview||content;if(!cacheNote.HasSelfDefined||!cacheNote.IsBlog){hasChanged.Desc=Note.genDesc(c);hasChanged.ImgSrc=Note.getImgSrc(c);hasChanged.Abstract=Note.genAbstract(c)}}else{log("text相同");log(cacheNote.Content==content)}hasChanged["UserId"]=cacheNote["UserId"]||"";return hasChanged};Note.genDesc=function(content){if(!content){return""}content=content.replace(/
    /g,"
    ");content=content.replace(/<\/p>/g,"

    ");content=content.replace(/<\/div>/g," ");content=$("
    ").html(content).text();content=content.replace(//g,">");if(content.length<300){return content}return content.substring(0,300)};Note.genAbstract=function(content,len){if(!content){return""}if(len==undefined){len=1e3}if(content.length"&&isCode){n=n-1;isCode=false}else if(temp==";"&&isHTML){isHTML=false}if(!isCode&&!isHTML){n=n+1}result+=temp;if(n>=maxLen){break}}var d=document.createElement("div");d.innerHTML=result;return d.innerHTML};Note.getImgSrc=function(content){if(!content){return""}var imgs=$(content).find("img");for(var i in imgs){var src=imgs.eq(i).attr("src");if(src){return src}}return""};Note.saveInProcess={};Note.savePool={};Note.curChangedSaveIt=function(force){var me=this;if(!Note.curNoteId||Note.isReadOnly){return}var hasChanged=Note.curHasChanged(force);if(hasChanged.hasChanged||hasChanged.IsNew){Note.renderChangedNote(hasChanged);delete hasChanged.hasChanged;showMsg(getMsg("saving"));me.saveInProcess[hasChanged.NoteId]=true;ajaxPost("/note/updateNoteOrContent",hasChanged,function(ret){me.saveInProcess[hasChanged.NoteId]=false;if(hasChanged.IsNew){ret.IsNew=false;Note.setNoteCache(ret,false);Pjax.changeNote(ret)}callback&&callback();showMsg(getMsg("saveSuccess"),1e3)});if(hasChanged["Tags"]!=undefined&&typeof hasChanged["Tags"]=="string"){hasChanged["Tags"]=hasChanged["Tags"].split(",")}Note.setNoteCache(hasChanged,false);Note.setNoteCache({NoteId:hasChanged.NoteId,UpdatedTime:(new Date).format("yyyy-MM-ddThh:mm:ss.S")},false);return hasChanged}return false};Note.updatePoolNote=function(){var me=this;for(var noteId in me.savePool){if(!noteId){continue}delete me.savePool[noteId];var hasChanged=me.savePool[noteId];me.saveInProcess[noteId]=true;ajaxPost("/note/updateNoteOrContent",hasChanged,function(ret){me.saveInProcess[noteId]=false})}};Note.updatePoolNoteInterval=null;Note.startUpdatePoolNoteInterval=function(){return;var me=this;if(me.updatePoolNoteInterval){return}me.updatePoolNoteInterval=setTimeout(function(){log("update pool");me.updatePoolNote()},1e3)};Note.selectTarget=function(target){$(".item").removeClass("item-active");$(target).addClass("item-active")};Note.showContentLoading=function(){$("#noteMaskForLoading").css("z-index",99999)};Note.hideContentLoading=function(){$("#noteMaskForLoading").css("z-index",-1)};Note.directToNote=function(noteId){var $p=$("#noteItemList");var pHeight=$p.height();var pTop=$("[noteId='"+noteId+"']").position().top;var scrollTop=$p.scrollTop();pTop+=scrollTop;if(pTop>=scrollTop&&pTop<=pHeight+scrollTop){}else{var top=pTop;log("定位到特定note, 在可视范围内");if(!LEA.isMobile&&!Mobile.isMobile()){$("#noteItemList").scrollTop(top);$("#noteItemList").slimScroll({scrollTo:top+"px",height:"100%",onlyScrollBar:true})}else{}}};Note.changeNoteForPjax=function(noteId,mustPush,needTargetNotebook){var me=this;var note=me.getNote(noteId);if(!note){return}var isShare=note.Perm!=undefined;if(needTargetNotebook==undefined){needTargetNotebook=true}me.changeNote(noteId,isShare,true,function(note){if(mustPush==undefined){mustPush=true}if(mustPush){Pjax.changeNote(note)}if(needTargetNotebook){Note.directToNote(noteId)}});if(needTargetNotebook){if(isShare){if($("#myShareNotebooks").hasClass("closed")){$("#myShareNotebooks .folderHeader").trigger("click")}}else{if($("#myNotebooks").hasClass("closed")){$("#myNotebooks .folderHeader").trigger("click")}}Notebook.expandNotebookTo(note.NotebookId)}};Note.contentAjax=null;Note.contentAjaxSeq=1;Note.changeNote=function(selectNoteId,isShare,needSaveChanged,callback){var self=this;Note.stopInterval();var target=$(tt('[noteId="?"]',selectNoteId));Note.selectTarget(target);if(needSaveChanged==undefined){needSaveChanged=true}if(needSaveChanged){var changedNote=Note.curChangedSaveIt()}Note.curNoteId="";var cacheNote=Note.cache[selectNoteId];if(!isShare){if(cacheNote.Perm!=undefined){isShare=true}}var hasPerm=!isShare||Share.hasUpdatePerm(selectNoteId);if(hasPerm){Note.hideReadOnly();Note.renderNote(cacheNote);switchEditor(cacheNote.IsMarkdown)}else{Note.renderNoteReadOnly(cacheNote)}Attach.renderNoteAttachNum(selectNoteId,true);Note.contentAjaxSeq++;var seq=Note.contentAjaxSeq;function setContent(ret){Note.contentAjax=null;if(seq!=Note.contentAjaxSeq){return}Note.setNoteCache(ret,false);ret=Note.cache[selectNoteId];if(hasPerm){Note.renderNoteContent(ret)}else{Note.renderNoteContentReadOnly(ret)}self.hideContentLoading();callback&&callback(ret)}if(cacheNote.Content){setContent(cacheNote);return}var url="/note/getNoteContent";var param={noteId:selectNoteId};if(isShare){url="/share/getShareNoteContent";param.sharedUserId=cacheNote.UserId}self.showContentLoading();if(Note.contentAjax!=null){Note.contentAjax.abort()}Note.contentAjax=ajaxGet(url,param,setContent)};Note.renderChangedNote=function(changedNote){if(!changedNote){return}var $leftNoteNav=$(tt('[noteId="?"]',changedNote.NoteId));if(changedNote.Title){$leftNoteNav.find(".item-title").text(changedNote.Title)}if(changedNote.Desc){$leftNoteNav.find(".desc").html(changedNote.Desc)}if(changedNote.ImgSrc){$thumb=$leftNoteNav.find(".item-thumb");if($thumb.length>0){$thumb.find("img").attr("src",changedNote.ImgSrc)}else{$leftNoteNav.append(tt('
    ',changedNote.ImgSrc));$leftNoteNav.addClass("item-image")}$leftNoteNav.find(".item-desc").removeAttr("style")}else if(changedNote.ImgSrc==""){$leftNoteNav.find(".item-thumb").remove();$leftNoteNav.removeClass("item-image")}};Note.clearNoteInfo=function(){Note.curNoteId="";Tag.clearTags();$("#noteTitle").val("");setEditorContent("");$("#noteRead").hide()};Note.clearNoteList=function(){Note.noteItemListO.html("")};Note.clearAll=function(){Note.curNoteId="";Note.clearNoteInfo();Note.clearNoteList()};Note.renderNote=function(note){if(!note){return}$("#noteTitle").val(trimTitle(note.Title));Tag.renderTags(note.Tags);note.isDirty=false};Note.renderNoteContent=function(content){setEditorContent(content.Content,content.IsMarkdown,content.Preview);Note.curNoteId=content.NoteId};Note.showEditorMask=function(){$("#editorMask").css("z-index",10).show();if(Notebook.curNotebookIsTrashOrAll()){$("#editorMaskBtns").hide();$("#editorMaskBtnsEmpty").show()}else{$("#editorMaskBtns").show();$("#editorMaskBtnsEmpty").hide()}};Note.hideEditorMask=function(){$("#editorMask").css("z-index",-10).hide()};Note.renderNotesC=0;Note.renderNotes=function(notes,forNewNote,isShared){var renderNotesC=++Note.renderNotesC;if(!LEA.isMobile&&!Mobile.isMobile()){$("#noteItemList").slimScroll({scrollTo:"0px",height:"100%",onlyScrollBar:true})}if(!notes||typeof notes!="object"||notes.length<=0){if(!forNewNote){Note.showEditorMask()}return}Note.hideEditorMask();if(forNewNote==undefined){forNewNote=false}if(!forNewNote){Note.noteItemListO.html("")}var len=notes.length;var c=Math.ceil(len/20);Note._renderNotes(notes,forNewNote,isShared,1);for(var i=0;i'+getMsg("close")+"");options={};options.show=true;$("#leanoteDialog").modal(options);ajaxGet("/noteContentHistory/listHistories",{noteId:Note.curNoteId},function(re){if(!isArray(re)){$content.html(getMsg("noHistories"));return}var str="

    "+getMsg("historiesNum")+'

    ';note=Note.cache[Note.curNoteId];var s="div";if(note.IsMarkdown){s="pre"}for(i in re){var content=re[i];content.Ab=Note.genAbstract(content.Content,200);str+=tt('",i,+i+1,s,content.Ab,s,goNowToDatetime(content.UpdatedTime))}str+="
    #??
    '+getMsg("datetime")+': ?
    ";$content.html(str);$("#historyList .all").click(function(){$p=$(this).parent().parent();var seq=$p.attr("seq");var $c=$p.find(".each-content");var info=re[seq];if(!info.unfold){$(this).text(getMsg("fold"));$c.html(info.Content);info.unfold=true}else{$(this).text(getMsg("unfold"));$c.html(info.Ab);info.unfold=false}});$("#historyList .back").click(function(){$p=$(this).parent().parent();var seq=$p.attr("seq");if(confirm(getMsg("confirmBackup"))){Note.curChangedSaveIt();note=Note.cache[Note.curNoteId];setEditorContent(re[seq].Content,note.IsMarkdown);hideDialog()}})})};Note.exportPDF=function(target){var noteId=$(target).attr("noteId");ajaxGet("/note/exportPdf",{noteId:noteId},function(ret){})};Note.html2Image=function(target){var noteId=$(target).attr("noteId");showDialog("html2ImageDialog",{title:"分享到社区",postShow:function(){ajaxGet("/note/html2Image",{noteId:noteId},function(ret){if(typeof ret=="object"&&ret.Ok){$("#leanoteDialog .weibo span").html("生成成功, 右键图片保存到本地.");$("#leanoteDialog .weibo img").attr("src",ret.Id+"?"+(new Date).getTime());$("#leanoteDialog .btn-share").removeClass("disabled");var note=Note.cache[noteId];var pic=UrlPrefix+ret.Id;var title=encodeURI(note.Title+" ("+UserInfo.Username+"分享. 来自leanote.com)");var windowParam="width=700, height=580, top=180, left=320, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no";$("#leanoteDialog .sendWeiboBtn").click(function(){var url="http://service.weibo.com/share/share.php?title="+title;url+="&pic="+pic;window.open(url,"分享到新浪微博",windowParam)});$("#leanoteDialog .sendTxWeiboBtn").click(function(){var _appkey="801542571";var url="http://share.v.t.qq.com/index.php?c=share&a=index&appkey="+_appkey+"&title="+title+"&url=&pic="+pic;window.open(url,"分享到腾讯微博",windowParam)});$("#leanoteDialog .sendQQBtn").click(function(){var url="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url="+UrlPrefix+"&title="+title+"&pics="+pic;window.open(url,"分享QQ空间",windowParam)});$("#leanoteDialog .sendRRBtn").click(function(){var url="http://widget.renren.com/dialog/share?resourceUrl="+UrlPrefix+"&srcUrl="+UrlPrefix+"&title="+title+"&pic="+pic;window.open(url,"分享人人网",windowParam)})}else{$("#leanoteDialog .weibo").html("对不起, 我们出错了!")}})}})};Note.showReadOnly=function(){Note.isReadOnly=true;$("#noteRead").show()};Note.hideReadOnly=function(){Note.isReadOnly=false;$("#noteRead").hide()};Note.renderNoteReadOnly=function(note){Note.showReadOnly();$("#noteReadTitle").text(note.Title);Tag.renderReadOnlyTags(note.Tags);$("#noteReadCreatedTime").html(goNowToDatetime(note.CreatedTime));$("#noteReadUpdatedTime").html(goNowToDatetime(note.UpdatedTime))};Note.renderNoteContentReadOnly=function(note){if(note.IsMarkdown){$("#noteReadContent").html('
    '+note.Content+"
    ")}else{$("#noteReadContent").html(note.Content)}};Note.lastSearch=null;Note.lastKey=null;Note.lastSearchTime=new Date;Note.isOver2Seconds=false;Note.isSameSearch=function(key){var now=new Date;var duration=now.getTime()-Note.lastSearchTime.getTime();Note.isOver2Seconds=duration>2e3?true:false;if(!Note.lastKey||Note.lastKey!=key||duration>1e3){Note.lastKey=key;Note.lastSearchTime=now;return false}if(key==Note.lastKey){return true}Note.lastSearchTime=now;Note.lastKey=key;return false};Note.searchNote=function(){var val=$("#searchNoteInput").val();if(!val){Notebook.changeNotebook("0");return}if(Note.isSameSearch(val)){return}if(Note.lastSearch){Note.lastSearch.abort()}Note.curChangedSaveIt();Note.clearAll();showLoading();Note.lastSearch=$.post("/note/searchNote",{key:val},function(notes){hideLoading();if(notes){Note.lastSearch=null;Note.renderNotes(notes);if(!isEmpty(notes)){Note.changeNote(notes[0].NoteId,false)}}else{}})};Note.setNote2Blog=function(target){var noteId=$(target).attr("noteId");var note=Note.cache[noteId];var isBlog=true;if(note.IsBlog!=undefined){isBlog=!note.IsBlog}if(isBlog){$(target).find(".item-blog").show()}else{$(target).find(".item-blog").hide()}ajaxPost("/note/setNote2Blog",{noteId:noteId,isBlog:isBlog},function(ret){if(ret){Note.setNoteCache({NoteId:noteId,IsBlog:isBlog},false)}})};Note.setAllNoteBlogStatus=function(notebookId,isBlog){if(!notebookId){return}var notes=Note.getNotesByNotebookId(notebookId);if(!isArray(notes)){return}var len=notes.length;if(len==0){for(var i in Note.cache){if(Note.cache[i].NotebookId==notebookId){Note.cache[i].IsBlog=isBlog}}}else{for(var i=0;i'+attach.Title+"")}});self.linkAllBtnO.on("click",function(e){e.stopPropagation();var note=Note.getCurNote();if(!note){return}var src=UrlPrefix+"/attach/downloadAll?noteId="+Note.curNoteId;var title=note.Title?note.Title+".tar.gz":"all.tar.gz";if(LEA.isMarkdownEditor()&&MD){MD.insertLink(src,title)}else{tinymce.activeEditor.insertContent(''+title+"")}})},attachListO:$("#attachList"),attachNumO:$("#attachNum"),attachDropdownO:$("#attachDropdown"),downloadAllBtnO:$("#downloadAllBtn"),linkAllBtnO:$("#linkAllBtn"),clearNoteAttachNum:function(){var self=this;self.attachNumO.html("").hide()},renderNoteAttachNum:function(noteId,needHide){var self=this;var note=Note.getNote(noteId);if(note.AttachNum){self.attachNumO.html("("+note.AttachNum+")").show();self.downloadAllBtnO.show();self.linkAllBtnO.show()}else{self.attachNumO.hide();self.downloadAllBtnO.hide();self.linkAllBtnO.hide()}if(needHide){self.attachDropdownO.removeClass("open")}},_renderAttachs:function(attachs){var self=this;var html="";var attachNum=attachs.length;for(var i=0;i'+'
    '+toHtmlEntity(each.Title)+"
    "+'
    '+' '+' '+' '+"
    "+"";self.attachsMap[each.AttachId]=each}self.attachListO.html(html);var note=Note.getCurNote();if(note){note.AttachNum=attachNum;self.renderNoteAttachNum(note.NoteId,false)}},renderAttachs:function(noteId){var self=this;if(self.loadedNoteAttachs[noteId]){self._renderAttachs(self.loadedNoteAttachs[noteId]);return}self.attachListO.html('
  • ');ajaxGet("/attach/getAttachs",{noteId:noteId},function(ret){var list=[];if(ret.Ok){list=ret.List;if(!list){list=[]}}self.loadedNoteAttachs[noteId]=list;self._renderAttachs(list)})},addAttach:function(attachInfo){var self=this;if(!self.loadedNoteAttachs[attachInfo.NoteId]){self.loadedNoteAttachs[attachInfo.NoteId]=[]}self.loadedNoteAttachs[attachInfo.NoteId].push(attachInfo);self.renderAttachs(attachInfo.NoteId)},deleteAttach:function(attachId){var self=this;var noteId=Note.curNoteId;var attachs=self.loadedNoteAttachs[noteId];for(var i=0;i