v1.0
只读模式 group, 分享 评论更多问题 博客标签总是存在一个
This commit is contained in:
1 parent
7e458bb433
commit
6987a38820
1453 files changed
+114558
-91533
No files matched your search
Vendored
+2
-1
@@ -1 +1,2 @@
|
||||
Note.curNoteId="";Note.interval="";Note.itemIsBlog='<div class="item-blog"><i class="fa fa-bold" title="blog"></i></div><div class="item-setting"><i class="fa fa-cog" title="setting"></i></div>';Note.itemTplNoImg='<li href="#" class="item ?" noteId="?">';Note.itemTplNoImg+=Note.itemIsBlog+'<div class="item-desc"><p class="item-title">?</p><p class="item-info"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-clock-o"></i> <span class="updated-time">?</span></p><p class="desc">?</p></div></li>';Note.itemTpl='<li href="#" class="item ? item-image" noteId="?"><div class="item-thumb" style=""><img src="?"/></div>';Note.itemTpl+=Note.itemIsBlog+'<div class="item-desc" style=""><p class="item-title">?</p><p class="item-info"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-clock-o"></i> <span class="updated-time">?</span></p><p class="desc">?</p></div></li>';Note.newItemTpl='<li href="#" class="item item-active ?" fromUserId="?" noteId="?">';Note.newItemTpl+=Note.itemIsBlog+'<div class="item-desc" style="right: 0px;"><p class="item-title">?</p><p class="item-text"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-clock-o"></i> <span class="updated-time">?</span><br /><span class="desc">?</span></p></div></li>';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(t1<t2){return-1}else if(t1>t2){return 1}}else{if(t1<t2){return 1}else if(t1>t2){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);hasChaLine truncated
|
||||
Note.curNoteId="";Note.interval="";Note.itemIsBlog='<div class="item-blog"><i class="fa fa-bold" title="blog"></i></div><div class="item-setting"><i class="fa fa-cog" title="setting"></i></div>';Note.itemTplNoImg='<li href="#" class="item ?" noteId="?">';Note.itemTplNoImg+=Note.itemIsBlog+'<div class="item-desc"><p class="item-title">?</p><p class="item-info"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-clock-o"></i> <span class="updated-time">?</span></p><p class="desc">?</p></div></li>';Note.itemTpl='<li href="#" class="item ? item-image" noteId="?"><div class="item-thumb" style=""><img src="?"/></div>';Note.itemTpl+=Note.itemIsBlog+'<div class="item-desc" style=""><p class="item-title">?</p><p class="item-info"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-clock-o"></i> <span class="updated-time">?</span></p><p class="desc">?</p></div></li>';Note.newItemTpl='<li href="#" class="item item-active ?" fromUserId="?" noteId="?">';Note.newItemTpl+=Note.itemIsBlog+'<div class="item-desc" style="right: 0px;"><p class="item-title">?</p><p class="item-text"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-clock-o"></i> <span class="updated-time">?</span><br /><span class="desc">?</span></p></div></li>';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(t1<t2){return-1}else if(t1>t2){return 1}}else{if(t1<t2){return 1}else if(t1>t2){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,Version:cacheNote.Version||0};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.ImLine truncated
|
||||
Note.newNote(notebookId,false,"",true)});$("#notebookNavForNewNote").on("click","li div",function(){var notebookId=$(this).attr("notebookId");if($(this).hasClass("new-note-right")){Note.newNote(notebookId,false,"",true)}else{Note.newNote(notebookId)}});$("#searchNotebookForAdd").click(function(e){e.stopPropagation()});$("#searchNotebookForAdd").keyup(function(){var key=$(this).val();Notebook.searchNotebookForAddNote(key)});$("#searchNotebookForList").keyup(function(){var key=$(this).val();Notebook.searchNotebookForList(key)});$("#searchNoteInput").on("keydown",function(e){var theEvent=e;if(theEvent.keyCode==13||theEvent.keyCode==108){theEvent.preventDefault();Note.searchNote();return false}});$("#contentHistory").click(function(){Note.listNoteContentHistories()});$("#saveBtn").click(function(){Note.curChangedSaveIt(true)});$("#noteItemList").on("click",".item-blog",function(e){e.preventDefault();e.stopPropagation();var noteId=$(this).parent().attr("noteId");window.open("/blog/view/"+noteId)});$("#noteItemList").on("click",".item-my .item-setting",function(e){e.preventDefault();e.stopPropagation();var $p=$(this).parent();Note.contextmenu.showMenu(e,$p)});$(".toolbar-update").click(function(){Note.toggleWriteable()})});Note.startInterval();
|
||||
+303
-183
File diff suppressed because it is too large.
Load diff
Vendored
+1
-1
@@ -1 +1 @@
|
||||
Notebook.curNotebookId="";Notebook.cache={};Notebook.notebooks=[];Notebook.notebookNavForListNote="";Notebook.notebookNavForNewNote="";Notebook.setCache=function(notebook){var notebookId=notebook.NotebookId;if(!notebookId){return}if(!Notebook.cache[notebookId]){Notebook.cache[notebookId]={}}$.extend(Notebook.cache[notebookId],notebook)};Notebook.getCurNotebookId=function(){return Notebook.curNotebookId};Notebook.getCurNotebook=function(){return Notebook.cache[Notebook.curNotebookId]};Notebook._updateNotebookNumberNotes=function(notebookId,n){var self=this;var notebook=self.getNotebook(notebookId);if(!notebook){return}notebook.NumberNotes+=n;if(notebook.NumberNotes<0){notebook.NumberNotes=0}$("#numberNotes_"+notebookId).html(notebook.NumberNotes)};Notebook.incrNotebookNumberNotes=function(notebookId){var self=this;self._updateNotebookNumberNotes(notebookId,1)};Notebook.minusNotebookNumberNotes=function(notebookId){var self=this;self._updateNotebookNumberNotes(notebookId,-1)};Notebook.getNotebook=function(notebookId){return Notebook.cache[notebookId]};Notebook.getNotebookTitle=function(notebookId){var notebook=Notebook.cache[notebookId];if(notebook){return toHtmlEntity(notebook.Title)}else{return"未知"}};Notebook.getTreeSetting=function(isSearch,isShare){var noSearch=!isSearch;var self=this;function addDiyDom(treeId,treeNode){var spaceWidth=5;var switchObj=$("#"+treeId+" #"+treeNode.tId+"_switch"),icoObj=$("#"+treeId+" #"+treeNode.tId+"_ico");switchObj.remove();icoObj.before(switchObj);if(!isShare){if(!Notebook.isAllNotebookId(treeNode.NotebookId)&&!Notebook.isTrashNotebookId(treeNode.NotebookId)){icoObj.after($('<span class="notebook-number-notes" id="numberNotes_'+treeNode.NotebookId+'">'+(treeNode.NumberNotes||0)+"</span>"));icoObj.after($('<span class="fa notebook-setting" title="setting"></span>'))}}else{if(!Share.isDefaultNotebookId(treeNode.NotebookId)){icoObj.after($('<span class="fa notebook-setting" title="setting"></span>'))}}if(treeNode.level>1){var spaceStr="<span style='display: inline-block;width:"+spaceWidth*treeNode.level+"px'></span>";switchObj.before(spaceStr)}}function beforeDrag(treeId,treeNodes){for(var i=0,l=treeNodes.length;i<l;i++){if(treeNodes[i].drag===false){return false}}return true}function beforeDrop(treeId,treeNodes,targetNode,moveType){return targetNode?targetNode.drop!==false:true}function onDrop(e,treeId,treeNodes,targetNode,moveType){var treeNode=treeNodes[0];if(!targetNode){return}var parentNode;var treeObj=self.tree;var ajaxData={curNotebookId:treeNode.NotebookId};if(moveType=="inner"){parentNode=targetNode}else{parentNode=targetNode.getParentNode()}if(!parentNode){var nodes=treeObj.getNodes()}else{ajaxData.parentNotebookId=parentNode.NotebookId;var nextLevel=parentNode.level+1;function filter(node){return node.level==nextLevel}var nodes=treeObj.getNodesByFilter(filter,false,parentNode)}ajaxData.siblings=[];for(var i in nodes){var notebookId=nodes[i].NotebookId;if(!Notebook.isAllNotebookId(notebookId)&&!Notebook.isTrashNotebookId(notebookId)){ajaxData.siblings.push(notebookId)}}ajaxPost("/notebook/dragNotebooks",{data:JSON.stringify(ajaxData)});setTimeout(function(){Notebook.changeNav()},100)}if(!isShare){var onClick=function(e,treeId,treeNode){var notebookId=treeNode.NotebookId;Notebook.changeNotebook(notebookId)};var onDblClick=function(e){var notebookId=$(e.target).attr("notebookId");if(!Notebook.isAllNotebookId(notebookId)&&!Notebook.isTrashNotebookId(notebookId)){self.updateNotebookTitle(e.target)}}}else{var onClick=function(e,treeId,treeNode){var notebookId=treeNode.NotebookId;var fromUserId=$(e.target).closest(".friend-notebooks").attr("fromUserId");Share.changeNotebook(fromUserId,notebookId)};var onDblClick=null}var setting={view:{showLine:false,showIcon:false,selectedMulti:false,dblClickExpand:false,addDiyDom:addDiyDom},data:{key:{name:"Title",children:"Subs"}},edit:{enable:true,showRemoveBtn:false,showRenameBtn:false,drag:{isMove:noSearch,prev:noSearch,inner:noSearch,next:noSearch}},callback:{beforeDrag:beforeDrag,beforeDrop:beforeDrop,onDrop:onDrop,onClick:onClick,onDblClick:onDblClick,beforeRename:function(treeId,treeNode,newName,isCancel){if(newName==""){if(treeNode.IsNew){self.tree.removeNode(treeNode);return true}return false}if(treeNode.Title==newName){return true}if(treeNode.IsNew){var parentNode=treeNode.getParentNode();var parentNotebookId=parentNode?parentNode.NotebookId:"";self.doAddNotebook(treeNode.NotebookId,newName,parentNotebookId)}else{self.doUpdateNotebookTitle(treeNode.NotebookId,newName)}return true}}};if(isSearch){}return setting};Notebook.allNotebookId="0";Notebook.trashNotebookId="-1";Notebook.curNotebookIsTrashOrAll=function(){return Notebook.curNotebookId==Notebook.trashNotebookId||Notebook.curNotebookId==Notebook.allNotebookId};Notebook.renderNotebooks=function(notebooks){var self=this;if(!notebooks||typeof notebooks!="object"||notebooks.length<0){notebooks=[]}for(var i=0,len=notebooks.length;i<len;++i){var notebook=notebooks[i];noteLine truncated
|
||||
Notebook.curNotebookId="";Notebook.cache={};Notebook.notebooks=[];Notebook.notebookNavForListNote="";Notebook.notebookNavForNewNote="";Notebook.setCache=function(notebook){var notebookId=notebook.NotebookId;if(!notebookId){return}if(!Notebook.cache[notebookId]){Notebook.cache[notebookId]={}}$.extend(Notebook.cache[notebookId],notebook)};Notebook.getCurNotebookId=function(){return Notebook.curNotebookId};Notebook.getCurNotebook=function(){return Notebook.cache[Notebook.curNotebookId]};Notebook._updateNotebookNumberNotes=function(notebookId,n){var self=this;var notebook=self.getNotebook(notebookId);if(!notebook){return}notebook.NumberNotes+=n;if(notebook.NumberNotes<0){notebook.NumberNotes=0}$("#numberNotes_"+notebookId).html(notebook.NumberNotes)};Notebook.incrNotebookNumberNotes=function(notebookId){var self=this;self._updateNotebookNumberNotes(notebookId,1)};Notebook.minusNotebookNumberNotes=function(notebookId){var self=this;self._updateNotebookNumberNotes(notebookId,-1)};Notebook.getNotebook=function(notebookId){return Notebook.cache[notebookId]};Notebook.getNotebookTitle=function(notebookId){var notebook=Notebook.cache[notebookId];if(notebook){return notebook.Title}else{return"未知"}};Notebook.getTreeSetting=function(isSearch,isShare){var noSearch=!isSearch;var self=this;function addDiyDom(treeId,treeNode){var spaceWidth=5;var switchObj=$("#"+treeId+" #"+treeNode.tId+"_switch"),icoObj=$("#"+treeId+" #"+treeNode.tId+"_ico");switchObj.remove();icoObj.before(switchObj);if(!isShare){if(!Notebook.isAllNotebookId(treeNode.NotebookId)&&!Notebook.isTrashNotebookId(treeNode.NotebookId)){icoObj.after($('<span class="notebook-number-notes" id="numberNotes_'+treeNode.NotebookId+'">'+(treeNode.NumberNotes||0)+"</span>"));icoObj.after($('<span class="fa notebook-setting" title="setting"></span>'))}}else{if(!Share.isDefaultNotebookId(treeNode.NotebookId)){icoObj.after($('<span class="fa notebook-setting" title="setting"></span>'))}}if(treeNode.level>1){var spaceStr="<span style='display: inline-block;width:"+spaceWidth*treeNode.level+"px'></span>";switchObj.before(spaceStr)}}function beforeDrag(treeId,treeNodes){for(var i=0,l=treeNodes.length;i<l;i++){if(treeNodes[i].drag===false){return false}}return true}function beforeDrop(treeId,treeNodes,targetNode,moveType){return targetNode?targetNode.drop!==false:true}function onDrop(e,treeId,treeNodes,targetNode,moveType){var treeNode=treeNodes[0];if(!targetNode){return}var parentNode;var treeObj=self.tree;var ajaxData={curNotebookId:treeNode.NotebookId};if(moveType=="inner"){parentNode=targetNode}else{parentNode=targetNode.getParentNode()}if(!parentNode){var nodes=treeObj.getNodes()}else{ajaxData.parentNotebookId=parentNode.NotebookId;var nextLevel=parentNode.level+1;function filter(node){return node.level==nextLevel}var nodes=treeObj.getNodesByFilter(filter,false,parentNode)}ajaxData.siblings=[];for(var i in nodes){var notebookId=nodes[i].NotebookId;if(!Notebook.isAllNotebookId(notebookId)&&!Notebook.isTrashNotebookId(notebookId)){ajaxData.siblings.push(notebookId)}}ajaxPost("/notebook/dragNotebooks",{data:JSON.stringify(ajaxData)});setTimeout(function(){Notebook.changeNav()},100)}if(!isShare){var onClick=function(e,treeId,treeNode){var notebookId=treeNode.NotebookId;Notebook.changeNotebook(notebookId)};var onDblClick=function(e){var notebookId=$(e.target).attr("notebookId");if(!Notebook.isAllNotebookId(notebookId)&&!Notebook.isTrashNotebookId(notebookId)){self.updateNotebookTitle(e.target)}}}else{var onClick=function(e,treeId,treeNode){var notebookId=treeNode.NotebookId;var fromUserId=$(e.target).closest(".friend-notebooks").attr("fromUserId");Share.changeNotebook(fromUserId,notebookId)};var onDblClick=null}var setting={view:{showLine:false,showIcon:false,selectedMulti:false,dblClickExpand:false,addDiyDom:addDiyDom},data:{key:{name:"Title",children:"Subs"}},edit:{enable:true,showRemoveBtn:false,showRenameBtn:false,drag:{isMove:noSearch,prev:noSearch,inner:noSearch,next:noSearch}},callback:{beforeDrag:beforeDrag,beforeDrop:beforeDrop,onDrop:onDrop,onClick:onClick,onDblClick:onDblClick,beforeRename:function(treeId,treeNode,newName,isCancel){if(newName==""){if(treeNode.IsNew){self.tree.removeNode(treeNode);return true}return false}if(treeNode.Title==newName){return true}if(treeNode.IsNew){var parentNode=treeNode.getParentNode();var parentNotebookId=parentNode?parentNode.NotebookId:"";self.doAddNotebook(treeNode.NotebookId,newName,parentNotebookId)}else{self.doUpdateNotebookTitle(treeNode.NotebookId,newName)}return true}}};if(isSearch){}return setting};Notebook.allNotebookId="0";Notebook.trashNotebookId="-1";Notebook.curNotebookIsTrashOrAll=function(){return Notebook.curNotebookId==Notebook.trashNotebookId||Notebook.curNotebookId==Notebook.allNotebookId};Notebook.renderNotebooks=function(notebooks){var self=this;if(!notebooks||typeof notebooks!="object"||notebooks.length<0){notebooks=[]}for(var i=0,len=notebooks.length;i<len;++i){var notebook=notebooks[i];notebook.Title=triLine truncated
|
||||
+86
-87
@@ -1,7 +1,7 @@
|
||||
Notebook.curNotebookId = "";
|
||||
Notebook.cache = {}; // notebookId => {};
|
||||
Notebook.notebooks = []; // 按次序
|
||||
// <li role="presentation"><a role="menuitem" tabindex="-1" href="#">CSS</a></li>
|
||||
// <li role="presentation"><a role="menuitem" tabindex="-1" href="#">CSS</a></li>
|
||||
Notebook.notebookNavForListNote = ""; // html 为了note list上面和新建时的ul
|
||||
Notebook.notebookNavForNewNote = ""; // html 为了note list上面和新建时的ul
|
||||
|
||||
@@ -58,7 +58,7 @@ Notebook.getNotebook = function(notebookId) {
|
||||
Notebook.getNotebookTitle = function(notebookId) {
|
||||
var notebook = Notebook.cache[notebookId];
|
||||
if(notebook) {
|
||||
return toHtmlEntity(notebook.Title);
|
||||
return notebook.Title;
|
||||
} else {
|
||||
return "未知";
|
||||
}
|
||||
@@ -72,10 +72,10 @@ Notebook.getNotebookTitle = function(notebookId) {
|
||||
<li><a>August 13, 2013</a></li>
|
||||
</ul>
|
||||
*/
|
||||
|
||||
Notebook.getTreeSetting = function(isSearch, isShare){
|
||||
|
||||
Notebook.getTreeSetting = function(isSearch, isShare){
|
||||
var noSearch = !isSearch;
|
||||
|
||||
|
||||
var self = this;
|
||||
// 添加自定义dom
|
||||
function addDiyDom(treeId, treeNode) {
|
||||
@@ -120,15 +120,15 @@ Notebook.getTreeSetting = function(isSearch, isShare){
|
||||
var parentNode;
|
||||
var treeObj = self.tree;
|
||||
var ajaxData = {curNotebookId: treeNode.NotebookId};
|
||||
|
||||
|
||||
// 成为子节点, 那么只需要得到targetNode下所有的子结点即可
|
||||
if(moveType == "inner") {
|
||||
parentNode = targetNode;
|
||||
} else {
|
||||
parentNode = targetNode.getParentNode();
|
||||
}
|
||||
|
||||
// 在targetNode之前或之后,
|
||||
|
||||
// 在targetNode之前或之后,
|
||||
// 那么: 1) 需要将该parentNode下所有的node重新排序即可; 2) treeNodes[0]为parentNode的子
|
||||
if(!parentNode) {
|
||||
var nodes = treeObj.getNodes(); // 得到所有nodes
|
||||
@@ -140,7 +140,7 @@ Notebook.getTreeSetting = function(isSearch, isShare){
|
||||
}
|
||||
var nodes = treeObj.getNodesByFilter(filter, false, parentNode);
|
||||
}
|
||||
|
||||
|
||||
ajaxData.siblings = [];
|
||||
for(var i in nodes) {
|
||||
var notebookId = nodes[i].NotebookId;
|
||||
@@ -148,15 +148,15 @@ Notebook.getTreeSetting = function(isSearch, isShare){
|
||||
ajaxData.siblings.push(notebookId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ajaxPost("/notebook/dragNotebooks", {data: JSON.stringify(ajaxData)});
|
||||
|
||||
|
||||
// 这里慢!
|
||||
setTimeout(function() {
|
||||
Notebook.changeNav();
|
||||
}, 100);
|
||||
}
|
||||
|
||||
|
||||
if(!isShare) {
|
||||
var onClick = function(e, treeId, treeNode) {
|
||||
var notebookId = treeNode.NotebookId;
|
||||
@@ -176,7 +176,7 @@ Notebook.getTreeSetting = function(isSearch, isShare){
|
||||
};
|
||||
var onDblClick = null;
|
||||
}
|
||||
|
||||
|
||||
var setting = {
|
||||
view: {
|
||||
showLine: false,
|
||||
@@ -220,12 +220,12 @@ Notebook.getTreeSetting = function(isSearch, isShare){
|
||||
if(treeNode.Title == newName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// 如果是新添加的
|
||||
if(treeNode.IsNew) {
|
||||
var parentNode = treeNode.getParentNode();
|
||||
var parentNotebookId = parentNode ? parentNode.NotebookId : "";
|
||||
|
||||
|
||||
self.doAddNotebook(treeNode.NotebookId, newName, parentNotebookId);
|
||||
} else {
|
||||
self.doUpdateNotebookTitle(treeNode.NotebookId, newName);
|
||||
@@ -234,11 +234,11 @@ Notebook.getTreeSetting = function(isSearch, isShare){
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// 搜索不能拖拽
|
||||
if(isSearch) {
|
||||
}
|
||||
|
||||
|
||||
return setting;
|
||||
}
|
||||
Notebook.allNotebookId = "0";
|
||||
@@ -258,13 +258,13 @@ Notebook.renderNotebooks = function(notebooks) {
|
||||
var notebook = notebooks[i];
|
||||
notebook.Title = trimTitle(notebook.Title);
|
||||
}
|
||||
|
||||
|
||||
notebooks = [{NotebookId: Notebook.allNotebookId, Title: getMsg("all"), drop:false, drag: false}].concat(notebooks);
|
||||
notebooks.push({NotebookId: Notebook.trashNotebookId, Title: getMsg("trash"), drop:false, drag: false});
|
||||
Notebook.notebooks = notebooks; // 缓存之
|
||||
|
||||
|
||||
self.tree = $.fn.zTree.init($("#notebookList"), self.getTreeSetting(), notebooks);
|
||||
|
||||
|
||||
// 展开/折叠图标
|
||||
var $notebookList = $("#notebookList");
|
||||
$notebookList.hover(function () {
|
||||
@@ -274,16 +274,16 @@ Notebook.renderNotebooks = function(notebooks) {
|
||||
}, function() {
|
||||
$(this).removeClass("showIcon");
|
||||
});
|
||||
|
||||
|
||||
// 缓存所有notebooks信息
|
||||
if(!isEmpty(notebooks)) {
|
||||
Notebook.curNotebookId = notebooks[0].NotebookId;
|
||||
self.cacheAllNotebooks(notebooks);
|
||||
}
|
||||
|
||||
|
||||
// 渲染nav
|
||||
Notebook.renderNav();
|
||||
|
||||
|
||||
// 渲染第一个notebook作为当前
|
||||
Notebook.changeNotebookNavForNewNote(notebooks[0].NotebookId);
|
||||
}
|
||||
@@ -304,7 +304,7 @@ Notebook.expandNotebookTo = function(notebookId, userId) {
|
||||
var me = this;
|
||||
var selected = false;
|
||||
var tree = me.tree;
|
||||
|
||||
|
||||
// 共享的
|
||||
if(userId) {
|
||||
tree = Share.trees[userId];
|
||||
@@ -335,7 +335,7 @@ Notebook.expandNotebookTo = function(notebookId, userId) {
|
||||
}
|
||||
|
||||
|
||||
// RenderNotebooks调用,
|
||||
// RenderNotebooks调用,
|
||||
// nav 为了新建, 快速选择, 移动笔记
|
||||
// 这些在添加,修改,删除notebooks都要变动!!!
|
||||
Notebook.renderNav = function(nav) {
|
||||
@@ -375,7 +375,7 @@ Notebook.searchNotebookForList = function(key) {
|
||||
if(key) {
|
||||
$search.show();
|
||||
$notebookList.hide();
|
||||
|
||||
|
||||
var notebooks = self.tree.getNodesByParamFuzzy("Title", key);
|
||||
log('search');
|
||||
log(notebooks);
|
||||
@@ -400,25 +400,25 @@ Notebook.searchNotebookForList = function(key) {
|
||||
Notebook.getChangedNotebooks = function(notebooks) {
|
||||
var self = this;
|
||||
var navForNewNote = "";
|
||||
|
||||
|
||||
var len = notebooks.length;
|
||||
for(var i = 0; i < len; ++i) {
|
||||
var notebook = notebooks[i];
|
||||
|
||||
|
||||
var classes = "";
|
||||
if(!isEmpty(notebook.Subs)) {
|
||||
classes = "dropdown-submenu";
|
||||
}
|
||||
var eachForNew = tt('<li role="presentation" class="clearfix ?"><div class="new-note-left pull-left" title="为该笔记本新建笔记" href="#" notebookId="?">?</div><div title="为该笔记本新建markdown笔记" class="new-note-right pull-left" notebookId="?">M</div>', classes, notebook.NotebookId, toHtmlEntity(notebook.Title), notebook.NotebookId);
|
||||
|
||||
var eachForNew = tt('<li role="presentation" class="clearfix ?"><div class="new-note-left pull-left" title="为该笔记本新建笔记" href="#" notebookId="?">?</div><div title="为该笔记本新建markdown笔记" class="new-note-right pull-left" notebookId="?">M</div>', classes, notebook.NotebookId, notebook.Title, notebook.NotebookId);
|
||||
|
||||
if(!isEmpty(notebook.Subs)) {
|
||||
eachForNew += "<ul class='dropdown-menu'>";
|
||||
eachForNew += self.getChangedNotebooks(notebook.Subs);
|
||||
eachForNew += "</ul>";
|
||||
}
|
||||
|
||||
|
||||
eachForNew += '</li>';
|
||||
|
||||
|
||||
navForNewNote += eachForNew;
|
||||
}
|
||||
return navForNewNote;
|
||||
@@ -431,12 +431,12 @@ Notebook.changeNav = function() {
|
||||
var notebooks = Notebook.tree.getNodes();
|
||||
var pureNotebooks = notebooks.slice(1, -1); // 不含新和垃圾
|
||||
var html = self.getChangedNotebooks(pureNotebooks);
|
||||
|
||||
|
||||
self.everNavForNewNote = html;
|
||||
self.everNotebooks = pureNotebooks;
|
||||
|
||||
|
||||
$("#notebookNavForNewNote").html(html);
|
||||
|
||||
|
||||
// 移动, 复制重新来, 因为nav变了, 移动至-----的notebook导航也变了
|
||||
// 这里速度很慢
|
||||
var t1 = (new Date()).getTime();
|
||||
@@ -447,13 +447,13 @@ Notebook.changeNav = function() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的共享notebooks
|
||||
* 我的共享notebooks
|
||||
<div id="shareNotebooks">
|
||||
<div class="folderNote closed">
|
||||
<div class="folderHeader">
|
||||
<a>
|
||||
<h1>
|
||||
<i class="fa fa-angle-right"></i>
|
||||
<i class="fa fa-angle-right"></i>
|
||||
Life's</h1>
|
||||
</a>
|
||||
</div>
|
||||
@@ -470,11 +470,11 @@ Notebook.renderShareNotebooks = function(sharedUserInfos, shareNotebooks) {
|
||||
if(isEmpty(sharedUserInfos)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(!shareNotebooks || typeof shareNotebooks != "object" || shareNotebooks.length < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var $shareNotebooks = $("#shareNotebooks");
|
||||
var user2ShareNotebooks = {};
|
||||
for(var i in shareNotebooks) {
|
||||
@@ -484,18 +484,18 @@ Notebook.renderShareNotebooks = function(sharedUserInfos, shareNotebooks) {
|
||||
for(var i in sharedUserInfos) {
|
||||
var userInfo = sharedUserInfos[i];
|
||||
var userNotebooks = user2ShareNotebooks[userInfo.UserId] || {ShareNotebooks:[]};
|
||||
|
||||
|
||||
userNotebooks.ShareNotebooks = [{NotebookId: "-2", Title: "默认共享"}].concat(userNotebooks.ShareNotebooks)
|
||||
|
||||
var username = toHtmlEntity(userInfo.Username || userInfo.Email);
|
||||
var username = userInfo.Username || userInfo.Email;
|
||||
var header = tt('<div class="folderNote closed"><div class="folderHeader"><a><h1 title="? 的共享"><i class="fa fa-angle-right"></i>?</h1></a></div>', username, username);
|
||||
var body = '<ul class="folderBody">';
|
||||
for(var j in userNotebooks.ShareNotebooks) {
|
||||
var notebook = userNotebooks.ShareNotebooks[j];
|
||||
body += tt('<li><a notebookId="?">?</a></li>', notebook.NotebookId, toHtmlEntity(notebook.Title))
|
||||
body += tt('<li><a notebookId="?">?</a></li>', notebook.NotebookId, notebook.Title)
|
||||
}
|
||||
body += "</ul>";
|
||||
|
||||
|
||||
$shareNotebooks.append(header + body + "</div>")
|
||||
}
|
||||
}
|
||||
@@ -519,9 +519,9 @@ Notebook.changeNotebookNavForNewNote = function(notebookId, title) {
|
||||
var notebook = Notebook.cache[0];
|
||||
title = notebook.Title;
|
||||
}
|
||||
|
||||
|
||||
if(!Notebook.isAllNotebookId(notebookId) && !Notebook.isTrashNotebookId(notebookId)) {
|
||||
$("#curNotebookForNewNote").text(title).attr("notebookId", notebookId);
|
||||
$("#curNotebookForNewNote").html(title).attr("notebookId", notebookId);
|
||||
} else if(!$("#curNotebookForNewNote").attr("notebookId")) {
|
||||
// 但又没有一个笔记, 默认选第一个吧
|
||||
// 这里很可能会死循环, 万一用户没有其它笔记呢?
|
||||
@@ -537,36 +537,36 @@ Notebook.changeNotebookNavForNewNote = function(notebookId, title) {
|
||||
|
||||
// 改变导航, 两处
|
||||
// 单击左侧, 单击新建下拉时调用
|
||||
// 1 选中左侧导航,
|
||||
// 1 选中左侧导航,
|
||||
// 2 notelist上面 >
|
||||
// 3 新建笔记 - js >
|
||||
// 转成我的nav <-> 共享
|
||||
Notebook.toggleToMyNav = function(userId, notebookId) {
|
||||
$("#sharedNotebookNavForListNav").hide();
|
||||
$("#myNotebookNavForListNav").show();
|
||||
|
||||
|
||||
$("#newMyNote").show();
|
||||
$("#newSharedNote").hide();
|
||||
|
||||
|
||||
// 搜索tag隐藏
|
||||
$("#tagSearch").hide();
|
||||
}
|
||||
Notebook.changeNotebookNav = function(notebookId) {
|
||||
Notebook.curNotebookId = notebookId;
|
||||
Notebook.toggleToMyNav();
|
||||
|
||||
|
||||
// 1 改变当前的notebook
|
||||
Notebook.selectNotebook($(tt('#notebook [notebookId="?"]', notebookId)));
|
||||
|
||||
|
||||
var notebook = Notebook.cache[notebookId];
|
||||
|
||||
|
||||
if(!notebook) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 2
|
||||
$("#curNotebookForListNote").text(notebook.Title);
|
||||
|
||||
$("#curNotebookForListNote").html(notebook.Title);
|
||||
|
||||
// 3
|
||||
Notebook.changeNotebookNavForNewNote(notebookId, notebook.Title);
|
||||
}
|
||||
@@ -593,18 +593,18 @@ Notebook.changeNotebookSeq = 1;
|
||||
Notebook.changeNotebook = function(notebookId, callback) {
|
||||
var me = this;
|
||||
Notebook.changeNotebookNav(notebookId);
|
||||
|
||||
|
||||
Notebook.curNotebookId = notebookId;
|
||||
|
||||
|
||||
// 1
|
||||
Note.curChangedSaveIt();
|
||||
|
||||
|
||||
// 2 先清空所有
|
||||
Note.clearAll();
|
||||
|
||||
|
||||
var url = "/note/listNotes/";
|
||||
var param = {notebookId: notebookId};
|
||||
|
||||
|
||||
// 废纸篓
|
||||
if(Notebook.isTrashNotebookId(notebookId)) {
|
||||
url = "/note/listTrashNotes";
|
||||
@@ -639,12 +639,11 @@ Notebook.changeNotebook = function(notebookId, callback) {
|
||||
log('数量不一致');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 2 得到笔记本
|
||||
// 这里可以缓存起来, note按notebookId缓存
|
||||
// 这里可能点击过快导致前面点击的后来才返回
|
||||
me.showNoteAndEditorLoading();
|
||||
|
||||
me.changeNotebookSeq++;
|
||||
(function(seq) {
|
||||
ajaxGet(url, param, function(cacheNotes) {
|
||||
@@ -686,13 +685,13 @@ Notebook.changeNotebookForNewNote = function(notebookId) {
|
||||
if(Notebook.isTrashNotebookId(notebookId) || Notebook.isAllNotebookId(notebookId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Notebook.changeNotebookNav(notebookId, true);
|
||||
Notebook.curNotebookId = notebookId;
|
||||
|
||||
|
||||
var url = "/note/listNotes/";
|
||||
var param = {notebookId: notebookId};
|
||||
|
||||
|
||||
// 2 得到笔记本
|
||||
// 这里可以缓存起来, note按notebookId缓存
|
||||
ajaxGet(url, param, function(ret) {
|
||||
@@ -715,7 +714,7 @@ Notebook.shareNotebooks= function(target) {
|
||||
$("#friendsEmail").focus();
|
||||
}, 500);
|
||||
var notebookId = $(target).attr("notebookId");
|
||||
|
||||
|
||||
shareNoteOrNotebook(notebookId, false);
|
||||
}
|
||||
|
||||
@@ -728,7 +727,7 @@ Notebook.setNotebook2Blog = function(target) {
|
||||
if(notebook.IsBlog != undefined) {
|
||||
isBlog = !notebook.IsBlog;
|
||||
}
|
||||
|
||||
|
||||
// 那么, 如果当前是该notebook下, 重新渲染之
|
||||
if(Notebook.curNotebookId == notebookId) {
|
||||
if(isBlog) {
|
||||
@@ -736,7 +735,7 @@ Notebook.setNotebook2Blog = function(target) {
|
||||
} else {
|
||||
$("#noteList .item-blog").hide();
|
||||
}
|
||||
|
||||
|
||||
// 如果当前在所有笔记本下
|
||||
} else if(Notebook.curNotebookId == Notebook.allNotebookId){
|
||||
$("#noteItemList .item").each(function(){
|
||||
@@ -763,7 +762,7 @@ Notebook.setNotebook2Blog = function(target) {
|
||||
Notebook.updateNotebookTitle = function(target) {
|
||||
var self = Notebook;
|
||||
var notebookId = $(target).attr("notebookId");
|
||||
|
||||
|
||||
if(self.tree2) {
|
||||
self.tree2.editName(self.tree2.getNodeByTId(notebookId));
|
||||
} else {
|
||||
@@ -777,7 +776,7 @@ Notebook.doUpdateNotebookTitle = function(notebookId, newTitle) {
|
||||
Notebook.cache[notebookId].Title = newTitle;
|
||||
// 改变nav
|
||||
Notebook.changeNav();
|
||||
|
||||
|
||||
// 同步
|
||||
if(self.tree2) {
|
||||
var notebook = self.tree.getNodeByTId(notebookId);
|
||||
@@ -797,7 +796,7 @@ Notebook.addNotebook = function() {
|
||||
if($("#myNotebooks").hasClass("closed")) {
|
||||
$("#myNotebooks .folderHeader").trigger("click");
|
||||
}
|
||||
|
||||
|
||||
// 添加并修改
|
||||
self.tree.addNodes(null, {Title: "", NotebookId: getObjectId(), IsNew: true}, true, true);
|
||||
}
|
||||
@@ -811,10 +810,10 @@ Notebook.doAddNotebook = function(notebookId, title, parentNotebookId) {
|
||||
var notebook = self.tree.getNodeByTId(notebookId);
|
||||
$.extend(notebook, ret);
|
||||
notebook.IsNew = false;
|
||||
|
||||
|
||||
// 选中之
|
||||
Notebook.changeNotebook(notebookId);
|
||||
|
||||
|
||||
// 改变nav
|
||||
Notebook.changeNav();
|
||||
}
|
||||
@@ -828,9 +827,9 @@ Notebook.addChildNotebook = function(target) {
|
||||
if($("#myNotebooks").hasClass("closed")) {
|
||||
$("#myNotebooks .folderHeader").trigger("click");
|
||||
}
|
||||
|
||||
|
||||
var notebookId = $(target).attr("notebookId");
|
||||
|
||||
|
||||
// 添加并修改
|
||||
self.tree.addNodes(self.tree.getNodeByTId(notebookId), {Title: "", NotebookId: getObjectId(), IsNew: true}, false, true);
|
||||
}
|
||||
@@ -839,12 +838,12 @@ Notebook.addChildNotebook = function(target) {
|
||||
// 删除
|
||||
Notebook.deleteNotebook = function(target) {
|
||||
var self = Notebook;
|
||||
|
||||
|
||||
var notebookId = $(target).attr("notebookId");
|
||||
if(!notebookId) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ajaxGet("/notebook/deleteNotebook", {notebookId: notebookId}, function(ret) {
|
||||
if(ret.Ok) {
|
||||
/*
|
||||
@@ -855,7 +854,7 @@ Notebook.deleteNotebook = function(target) {
|
||||
self.tree2.removeNode(self.tree2.getNodeByTId(notebookId));
|
||||
}
|
||||
delete Notebook.cache[notebookId];
|
||||
|
||||
|
||||
// 改变nav
|
||||
Notebook.changeNav();
|
||||
} else {
|
||||
@@ -878,17 +877,17 @@ $(function() {
|
||||
var notebookId = $(this).find("a").attr("notebookId");
|
||||
Notebook.changeNotebook(notebookId);
|
||||
});
|
||||
|
||||
|
||||
// 修改笔记本标题, blur后修改标题之
|
||||
/*
|
||||
enterBlur("#notebookList", "input#editNotebookTitle");
|
||||
$("#notebookList").on("blur", "input#editNotebookTitle", Notebook.doUpdateNotebookTitle);
|
||||
*/
|
||||
|
||||
|
||||
//-------------------
|
||||
// 右键菜单
|
||||
var notebookListMenu = {
|
||||
width: 180,
|
||||
width: 180,
|
||||
items: [
|
||||
{ text: getMsg("shareToFriends"), alias: 'shareToFriends', icon: "", faIcon: "fa-share-square-o", action: Notebook.listNotebookShareUserInfo},
|
||||
{ type: "splitLine" },
|
||||
@@ -904,10 +903,10 @@ $(function() {
|
||||
parent: "#notebookList ",
|
||||
children: "li a"
|
||||
}
|
||||
|
||||
|
||||
// for search
|
||||
var notebookListMenu2 = {
|
||||
width: 180,
|
||||
width: 180,
|
||||
items: [
|
||||
{ text: getMsg("shareToFriends"), alias: 'shareToFriends', icon: "", faIcon: "fa-share-square-o", action: Notebook.listNotebookShareUserInfo},
|
||||
{ type: "splitLine" },
|
||||
@@ -922,7 +921,7 @@ $(function() {
|
||||
parent: "#notebookListForSearch ",
|
||||
children: "li a"
|
||||
}
|
||||
|
||||
|
||||
function applyrule(menu) {
|
||||
var notebookId = $(this).attr("notebookId");
|
||||
var notebook = Notebook.cache[notebookId];
|
||||
@@ -952,17 +951,17 @@ $(function() {
|
||||
var notebookId = $(this).attr("notebookId");
|
||||
return !Notebook.isTrashNotebookId(notebookId) && !Notebook.isAllNotebookId(notebookId);
|
||||
}
|
||||
|
||||
|
||||
Notebook.contextmenu = $("#notebookList li a").contextmenu(notebookListMenu);
|
||||
|
||||
|
||||
Notebook.contextmenuSearch = $("#notebookListForSearch li a").contextmenu(notebookListMenu2);
|
||||
|
||||
|
||||
// 添加笔记本
|
||||
$("#addNotebookPlus").click(function(e) {
|
||||
e.stopPropagation();
|
||||
Notebook.addNotebook();
|
||||
});
|
||||
|
||||
|
||||
// notebook setting
|
||||
$("#notebookList").on("click", ".notebook-setting", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
function editorMode(){this.writingHash="writing";this.normalHash="normal";this.isWritingMode=location.hash.indexOf(this.writingHash)>=0;this.toggleA=null}editorMode.prototype.toggleAText=function(isWriting){var self=this;setTimeout(function(){var toggleA=$(".toggle-editor-mode a");var toggleSpan=$(".toggle-editor-mode span");if(isWriting){toggleA.attr("href","#"+self.normalHash);toggleSpan.text(getMsg("normalMode"))}else{toggleA.attr("href","#"+self.writingHash);toggleSpan.text(getMsg("writingMode"))}},0)};editorMode.prototype.isWriting=function(hash){return hash.indexOf(this.writingHash)>=0};editorMode.prototype.init=function(){this.changeMode(this.isWritingMode);var self=this;$(".toggle-editor-mode").click(function(e){e.preventDefault();saveBookmark();var $a=$(this).find("a");var isWriting=self.isWriting($a.attr("href"));self.changeMode(isWriting);if(isWriting){setHash("m",self.writingHash)}else{setHash("m",self.normalHash)}restoreBookmark()})};editorMode.prototype.changeMode=function(isWritingMode){this.toggleAText(isWritingMode);if(isWritingMode){this.writtingMode()}else{this.normalMode()}$("#moreBtn i").removeClass("fa-angle-up").addClass("fa-angle-down")};editorMode.prototype.resizeEditor=function(){setTimeout(function(){resizeEditor()},10);setTimeout(function(){resizeEditor()},20);setTimeout(function(){resizeEditor()},500)};editorMode.prototype.normalMode=function(){var $c=$("#editorContent_ifr").contents();$c.contents().find("#writtingMode").remove();$c.contents().find('link[href$="editor-writting-mode.css"]').remove();$("#noteItemListWrap, #notesAndSort").show();$("#noteList").unbind("mouseenter").unbind("mouseleave");var theme=UserInfo.Theme||"default";theme+=".css";$("#themeLink").attr("href","/css/theme/"+theme);$("#mceToolbar").css("height","30px");this.resizeEditor();$("#noteList").width(UserInfo.NoteListWidth);$("#note").css("left",UserInfo.NoteListWidth)};editorMode.prototype.writtingMode=function(){$("#themeLink").attr("href","/css/theme/writting-overwrite.css");setTimeout(function(){var $c=$("#editorContent_ifr").contents();$c.contents().find("head").append('<link type="text/css" rel="stylesheet" href="/css/editor/editor-writting-mode.css" id="writtingMode">')},0);$("#noteItemListWrap, #notesAndSort").fadeOut();$("#noteList").hover(function(){$("#noteItemListWrap, #notesAndSort").fadeIn()},function(){$("#noteItemListWrap, #notesAndSort").fadeOut()});$("#mceToolbar").css("height","40px");this.resizeEditor();$("#noteList").width(250);$("#note").css("left",0)};editorMode.prototype.getWritingCss=function(){if(this.isWritingMode){return["/css/editor/editor-writting-mode.css"]}return[]};var em=new editorMode;var Resize={lineMove:false,mdLineMove:false,target:null,leftNotebook:$("#leftNotebook"),notebookSplitter:$("#notebookSplitter"),noteList:$("#noteList"),noteAndEditor:$("#noteAndEditor"),noteSplitter:$("#noteSplitter"),note:$("#note"),body:$("body"),leftColumn:$("#left-column"),rightColumn:$("#right-column"),mdSplitter:$("#mdSplitter2"),init:function(){var self=this;self.initEvent()},initEvent:function(){var self=this;$(".noteSplit").bind("mousedown",function(event){event.preventDefault();self.lineMove=true;$(this).css("background-color","#ccc");self.target=$(this).attr("id");$("#noteMask").css("z-index",99999)});self.mdSplitter.bind("mousedown",function(event){event.preventDefault();if($(this).hasClass("open")){self.mdLineMove=true}});self.body.bind("mousemove",function(event){if(self.lineMove){event.preventDefault();self.resize3Columns(event)}else if(self.mdLineMove){event.preventDefault();self.resizeMdColumns(event)}});self.body.bind("mouseup",function(event){self.stopResize();$("#noteMask").css("z-index",-1)});var everLeftWidth;$(".layout-toggler-preview").click(function(){var $t=$(this);var $p=self.leftColumn.parent();if($t.hasClass("open")){var totalWidth=$p.width();var minRightWidth=22;var leftWidth=totalWidth-minRightWidth;everLeftWidth=self.leftColumn.width();self.leftColumn.width(leftWidth);self.rightColumn.css("left","auto").width(minRightWidth);$t.removeClass("open");self.rightColumn.find(".layout-resizer").removeClass("open");$(".preview-container").hide()}else{$t.addClass("open");self.rightColumn.find(".layout-resizer").addClass("open");self.leftColumn.width(everLeftWidth);$(".preview-container").show();self.rightColumn.css("left",everLeftWidth).width("auto");if(MD){MD.onResize()}}})},stopResize:function(){var self=this;if(self.lineMove||self.mdLineMove){ajaxGet("/user/updateColumnWidth",{mdEditorWidth:UserInfo.MdEditorWidth,notebookWidth:UserInfo.NotebookWidth,noteListWidth:UserInfo.NoteListWidth},function(){})}self.lineMove=false;self.mdLineMove=false;$(".noteSplit").css("background","none");self.mdSplitter.css("background","none")},set3ColumnsWidth:function(notebookWidth,noteListWidth){var self=this;if(notebookWidth<150||noteListWidth<100){return}var noteWidth=self.body.width()-notebookWidth-noteListWidth;if(noteWidth<400){return}self.leftNotebook.width(notebookWidth);self.nLine truncated
|
||||
function editorMode(){this.writingHash="writing";this.normalHash="normal";this.isWritingMode=location.hash.indexOf(this.writingHash)>=0;this.toggleA=null}editorMode.prototype.toggleAText=function(isWriting){var self=this;setTimeout(function(){var toggleA=$(".toggle-editor-mode a");var toggleSpan=$(".toggle-editor-mode span");if(isWriting){toggleA.attr("href","#"+self.normalHash);toggleSpan.text(getMsg("normalMode"))}else{toggleA.attr("href","#"+self.writingHash);toggleSpan.text(getMsg("writingMode"))}},0)};editorMode.prototype.isWriting=function(hash){if(!hash){hash=location.hash}return hash.indexOf(this.writingHash)>=0};editorMode.prototype.init=function(){this.$themeLink=$("#themeLink");this.changeMode(this.isWritingMode);var self=this;$(".toggle-editor-mode").click(function(e){e.preventDefault();saveBookmark();var $a=$(this).find("a");var isWriting=self.isWriting($a.attr("href"));self.changeMode(isWriting);if(isWriting){setHash("m",self.writingHash)}else{setHash("m",self.normalHash)}restoreBookmark()})};editorMode.prototype.changeMode=function(isWritingMode){this.toggleAText(isWritingMode);if(isWritingMode){this.writtingMode()}else{this.normalMode()}};editorMode.prototype.resizeEditor=function(){setTimeout(function(){resizeEditor()},10);setTimeout(function(){resizeEditor()},20);setTimeout(function(){resizeEditor()},500)};editorMode.prototype.normalMode=function(){$("#noteItemListWrap, #notesAndSort").show();$("#noteList").unbind("mouseenter").unbind("mouseleave");var theme=UserInfo.Theme||"default";theme+=".css";var $themeLink=$("#themeLink");if(this.$themeLink.attr("href").indexOf("writting-overwrite.css")!=-1){this.$themeLink.attr("href","/css/theme/"+theme)}$("#noteList").width(UserInfo.NoteListWidth);$("#note").css("left",UserInfo.NoteListWidth)};editorMode.prototype.writtingMode=function(){if(this.$themeLink.attr("href").indexOf("writting-overwrite.css")==-1){this.$themeLink.attr("href","/css/theme/writting-overwrite.css")}$("#noteItemListWrap, #notesAndSort").fadeOut();$("#noteList").hover(function(){$("#noteItemListWrap, #notesAndSort").fadeIn()},function(){$("#noteItemListWrap, #notesAndSort").fadeOut()});this.resizeEditor();$("#noteList").width(250);$("#note").css("left",0);Note.toggleWriteable()};editorMode.prototype.getWritingCss=function(){if(this.isWritingMode){return["/css/editor/editor-writting-mode.css"]}return[]};var em=new editorMode;LEA.em=em;var Resize={lineMove:false,mdLineMove:false,target:null,leftNotebook:$("#leftNotebook"),notebookSplitter:$("#notebookSplitter"),noteList:$("#noteList"),noteAndEditor:$("#noteAndEditor"),noteSplitter:$("#noteSplitter"),note:$("#note"),body:$("body"),leftColumn:$("#left-column"),rightColumn:$("#right-column"),mdSplitter:$("#mdSplitter2"),init:function(){var self=this;self.initEvent()},initEvent:function(){var self=this;$(".noteSplit").bind("mousedown",function(event){event.preventDefault();self.lineMove=true;$(this).css("background-color","#ccc");self.target=$(this).attr("id");$("#noteMask").css("z-index",99999)});self.mdSplitter.bind("mousedown",function(event){event.preventDefault();if($(this).hasClass("open")){self.mdLineMove=true}});self.body.bind("mousemove",function(event){if(self.lineMove){event.preventDefault();self.resize3Columns(event)}else if(self.mdLineMove){event.preventDefault();self.resizeMdColumns(event)}});self.body.bind("mouseup",function(event){self.stopResize();$("#noteMask").css("z-index",-1)});var everLeftWidth;$(".layout-toggler-preview").click(function(){var $t=$(this);var $p=self.leftColumn.parent();if($t.hasClass("open")){var totalWidth=$p.width();var minRightWidth=22;var leftWidth=totalWidth-minRightWidth;everLeftWidth=self.leftColumn.width();self.leftColumn.width(leftWidth);self.rightColumn.css("left","auto").width(minRightWidth);$t.removeClass("open");self.rightColumn.find(".layout-resizer").removeClass("open");$(".preview-container").hide()}else{$t.addClass("open");self.rightColumn.find(".layout-resizer").addClass("open");self.leftColumn.width(everLeftWidth);$(".preview-container").show();self.rightColumn.css("left",everLeftWidth).width("auto");if(MD){MD.onResize()}}})},stopResize:function(){var self=this;if(self.lineMove||self.mdLineMove){ajaxGet("/user/updateColumnWidth",{mdEditorWidth:UserInfo.MdEditorWidth,notebookWidth:UserInfo.NotebookWidth,noteListWidth:UserInfo.NoteListWidth},function(){})}self.lineMove=false;self.mdLineMove=false;$(".noteSplit").css("background","none");self.mdSplitter.css("background","none")},set3ColumnsWidth:function(notebookWidth,noteListWidth){var self=this;if(notebookWidth<150||noteListWidth<100){return}var noteWidth=self.body.width()-notebookWidth-noteListWidth;if(noteWidth<400){return}self.leftNotebook.width(notebookWidth);self.notebookSplitter.css("left",notebookWidth);self.noteAndEditor.css("left",notebookWidth);self.noteList.width(noteListWidth);self.noteSplitter.css("left",noteListWidth);self.note.css("left",noteListWidth);UserInfo.NotebookWidth=notebookWidth;UserInfo.NoteListWidthLine truncated
|
||||
+74
-41
@@ -25,9 +25,13 @@ editorMode.prototype.toggleAText = function(isWriting) {
|
||||
}, 0);
|
||||
}
|
||||
editorMode.prototype.isWriting = function(hash) {
|
||||
if(!hash) {
|
||||
hash = location.hash;
|
||||
}
|
||||
return hash.indexOf(this.writingHash) >= 0
|
||||
}
|
||||
editorMode.prototype.init = function() {
|
||||
this.$themeLink = $("#themeLink");
|
||||
this.changeMode(this.isWritingMode);
|
||||
var self = this;
|
||||
$(".toggle-editor-mode").click(function(e) {
|
||||
@@ -54,8 +58,6 @@ editorMode.prototype.changeMode = function(isWritingMode) {
|
||||
} else {
|
||||
this.normalMode();
|
||||
}
|
||||
|
||||
$("#moreBtn i").removeClass("fa-angle-up").addClass("fa-angle-down");
|
||||
}
|
||||
|
||||
editorMode.prototype.resizeEditor = function() {
|
||||
@@ -71,42 +73,39 @@ editorMode.prototype.resizeEditor = function() {
|
||||
}, 500);
|
||||
}
|
||||
editorMode.prototype.normalMode = function() {
|
||||
// 最开始的时候就调用?
|
||||
/*
|
||||
var w = $(document).width();
|
||||
var h = $(document).height();
|
||||
$("#lock").css({right:0, bottom:0});
|
||||
*/
|
||||
|
||||
var $c = $("#editorContent_ifr").contents();
|
||||
|
||||
$c.contents().find("#writtingMode").remove();
|
||||
$c.contents().find('link[href$="editor-writting-mode.css"]').remove();
|
||||
|
||||
*/
|
||||
|
||||
$("#noteItemListWrap, #notesAndSort").show();
|
||||
$("#noteList").unbind("mouseenter").unbind("mouseleave");
|
||||
|
||||
var theme = UserInfo.Theme || "default";
|
||||
theme += ".css";
|
||||
$("#themeLink").attr("href", "/css/theme/" + theme);
|
||||
|
||||
$("#mceToolbar").css("height", "30px");
|
||||
|
||||
// $("#lock").animate({right:w},1000);
|
||||
|
||||
this.resizeEditor();
|
||||
var $themeLink = $("#themeLink");
|
||||
// 如果之前不是normal才换
|
||||
if(this.$themeLink.attr('href').indexOf('writting-overwrite.css') != -1) {
|
||||
this.$themeLink.attr("href", "/css/theme/" + theme);
|
||||
}
|
||||
|
||||
$("#noteList").width(UserInfo.NoteListWidth);
|
||||
$("#note").css("left", UserInfo.NoteListWidth);
|
||||
}
|
||||
|
||||
editorMode.prototype.writtingMode = function() {
|
||||
// $("#pageInner").removeClass("animated fadeInUp");
|
||||
|
||||
$("#themeLink").attr("href", "/css/theme/writting-overwrite.css");
|
||||
if(this.$themeLink.attr('href').indexOf('writting-overwrite.css') == -1) {
|
||||
this.$themeLink.attr("href", "/css/theme/writting-overwrite.css");
|
||||
}
|
||||
|
||||
/*
|
||||
setTimeout(function() {
|
||||
var $c = $("#editorContent_ifr").contents();
|
||||
$c.contents().find("head").append('<link type="text/css" rel="stylesheet" href="/css/editor/editor-writting-mode.css" id="writtingMode">');
|
||||
}, 0);
|
||||
*/
|
||||
|
||||
$("#noteItemListWrap, #notesAndSort").fadeOut();
|
||||
$("#noteList").hover(function() {
|
||||
@@ -116,7 +115,7 @@ editorMode.prototype.writtingMode = function() {
|
||||
});
|
||||
|
||||
// 点击扩展会使html的height生成, 切换后会覆盖css文件的
|
||||
$("#mceToolbar").css("height", "40px");
|
||||
// $("#mceToolbar").css("height", "40px");
|
||||
|
||||
//$("#pageInner").addClass("animated fadeInUp");
|
||||
|
||||
@@ -124,6 +123,9 @@ editorMode.prototype.writtingMode = function() {
|
||||
|
||||
$("#noteList").width(250);
|
||||
$("#note").css("left", 0);
|
||||
|
||||
// 切换到写模式
|
||||
Note.toggleWriteable();
|
||||
}
|
||||
|
||||
editorMode.prototype.getWritingCss = function() {
|
||||
@@ -133,6 +135,7 @@ editorMode.prototype.getWritingCss = function() {
|
||||
return [];
|
||||
}
|
||||
var em = new editorMode();
|
||||
LEA.em = em;
|
||||
|
||||
//----------------
|
||||
// 拖拉改变变宽度
|
||||
@@ -444,28 +447,20 @@ function initEditor() {
|
||||
var mceToobarEverHeight = 0;
|
||||
$("#moreBtn").click(function() {
|
||||
saveBookmark();
|
||||
|
||||
var height = $("#mceToolbar").height();
|
||||
|
||||
// 现在是折叠的
|
||||
if (height < $("#popularToolbar").height()) {
|
||||
$("#mceToolbar").height($("#popularToolbar").height());
|
||||
$(this).find("i").removeClass("fa-angle-down").addClass("fa-angle-up");
|
||||
mceToobarEverHeight = height;
|
||||
var $editor = $('#editor');
|
||||
if($editor.hasClass('all-tool')) {
|
||||
$editor.removeClass('all-tool');
|
||||
} else {
|
||||
$("#mceToolbar").height(mceToobarEverHeight);
|
||||
$(this).find("i").removeClass("fa-angle-up").addClass("fa-angle-down");
|
||||
$editor.addClass('all-tool');
|
||||
}
|
||||
|
||||
resizeEditor();
|
||||
|
||||
|
||||
restoreBookmark();
|
||||
});
|
||||
|
||||
// 初始化编辑器
|
||||
tinymce.init({
|
||||
inline: true,
|
||||
// theme: 'leanote',
|
||||
theme: 'leanote',
|
||||
valid_children: "+pre[div|#text|p|span|textarea|i|b|strong]", // ace
|
||||
/*
|
||||
protect: [
|
||||
@@ -477,7 +472,16 @@ function initEditor() {
|
||||
],
|
||||
*/
|
||||
setup: function(ed) {
|
||||
ed.on('keydown', Note.saveNote);
|
||||
ed.on('keydown', function(e) {
|
||||
// 如果是readony, 则不能做任何操作
|
||||
var num = e.which ? e.which : e.keyCode;
|
||||
// 如果是readony, 则不能做任何操作, 除了复制
|
||||
if(Note.readOnly && !((e.ctrlKey || e.metaKey) && num == 67)) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
Note.saveNote(e);
|
||||
});
|
||||
|
||||
// 为了把下拉菜单关闭
|
||||
ed.on("click", function(e) {
|
||||
@@ -496,7 +500,7 @@ function initEditor() {
|
||||
// height: 100,//这个应该是文档的高度, 而其上层的高度是$("#content").height(),
|
||||
// parentHeight: $("#content").height(),
|
||||
// content_css : ["/css/bootstrap.css", "/css/editor/editor.css"].concat(em.getWritingCss()),
|
||||
content_css : ["/css/editor/editor.css"].concat(em.getWritingCss()),
|
||||
content_css : ["/css/editor/editor.css"], // .concat(em.getWritingCss()),
|
||||
skin : "custom",
|
||||
language: LEA.locale, // 语言
|
||||
plugins : [
|
||||
@@ -983,9 +987,11 @@ LeaAce = {
|
||||
me.disableAddHistory();
|
||||
|
||||
// 本身就有格式的, 防止之前有格式的显示为<span>(ace下)
|
||||
if($pre.attr('style') || $pre.html().indexOf('style') != -1) {
|
||||
var classes = $pre.attr('class') || '';
|
||||
var isHtml = classes.indexOf('brush:html') != -1;
|
||||
if($pre.attr('style') ||
|
||||
(!isHtml && $pre.html().indexOf('style') != -1)) { // 如果是html就不用考虑了, 因为html格式的支持有style
|
||||
$pre.html($pre.text());
|
||||
// return;
|
||||
}
|
||||
$pre.find('.toggle-raw').remove();
|
||||
var preHtml = $pre.html();
|
||||
@@ -1018,6 +1024,9 @@ LeaAce = {
|
||||
aceEditor.setShowInvisibles(false); // OK 不显示空格
|
||||
aceEditor.setOption("wrap", "free");
|
||||
aceEditor.setShowInvisibles(false);
|
||||
|
||||
aceEditor.setReadOnly(Note.readOnly);
|
||||
|
||||
aceEditor.setAutoScrollEditorIntoView(true);
|
||||
aceEditor.setOption("maxLines", 10000);
|
||||
aceEditor.commands.addCommand({
|
||||
@@ -1077,10 +1086,17 @@ LeaAce = {
|
||||
var pres = content.find('pre');
|
||||
for(var i = 0 ; i < pres.length; ++i) {
|
||||
var pre = pres.eq(i);
|
||||
// 如果不是ace
|
||||
if(me.isInAce(pre)) {
|
||||
break;
|
||||
|
||||
var aceAndNode = me.isInAce(pre);
|
||||
if(aceAndNode) {
|
||||
if(isAceError(aceAndNode[0].getValue())) {
|
||||
console.error('之前有些没有destroy掉');
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout((function(pre) {
|
||||
return function() {
|
||||
pre.find('.toggle-raw').remove();
|
||||
@@ -1183,6 +1199,19 @@ LeaAce = {
|
||||
}
|
||||
return this._aceEditors[id];
|
||||
},
|
||||
setAceReadOnly: function(pre, readOnly) {
|
||||
var me = this;
|
||||
if(typeof pre == 'object') {
|
||||
var id = pre.attr('id');
|
||||
}
|
||||
else {
|
||||
var id = pre;
|
||||
}
|
||||
var ace = me.getAce(id);
|
||||
if(ace) {
|
||||
ace.setReadOnly(readOnly);
|
||||
}
|
||||
},
|
||||
// 当前焦点是否在aceEditor中
|
||||
nowIsInAce: function () {
|
||||
if(!this.canAce()) {
|
||||
@@ -1275,6 +1304,10 @@ LeaAce = {
|
||||
var aceEditor = aceEditorAndPre[0];
|
||||
var $pre = aceEditorAndPre[1];
|
||||
var value = aceEditor.getValue();
|
||||
// 表示有错
|
||||
if(isAceError(value)) {
|
||||
value = $pre.html();
|
||||
}
|
||||
value = value.replace(/</g, '<').replace(/>/g, '>');
|
||||
// var id = getAceId();
|
||||
var replacePre = $('<pre class="' + $pre.attr('class') + ' ace-to-pre">' + value + "</pre>");
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
Tag.classes={"蓝色":"label label-blue","红色":"label label-red","绿色":"label label-green","黄色":"label label-yellow",blue:"label label-blue",red:"label label-red",green:"label label-green",yellow:"label label-yellow"};Tag.mapCn2En={"蓝色":"blue","红色":"red","绿色":"green","黄色":"yellow"};Tag.mapEn2Cn={blue:"蓝色",red:"红色",green:"绿色",yellow:"黄色"};Tag.t=$("#tags");Tag.getTags=function(){var tags=[];Tag.t.children().each(function(){var text=$(this).data("tag");text=Tag.mapCn2En[text]||text;tags.push(text)});return tags};Tag.clearTags=function(){Tag.t.html("")};Tag.renderTags=function(tags){Tag.t.html("");if(isEmpty(tags)){return}for(var i=0;i<tags.length;++i){var tag=tags[i];Tag.appendTag(tag)}};function revertTagStatus(){$("#addTagTrigger").show();$("#addTagInput").hide()}function hideTagList(event){$("#tagDropdown").removeClass("open");if(event){event.stopPropagation()}}function showTagList(event){$("#tagDropdown").addClass("open");if(event){event.stopPropagation()}}Tag.renderReadOnlyTags=function(tags){$("#noteReadTags").html("");if(isEmpty(tags)){$("#noteReadTags").html(getMsg("noTag"))}var i=true;function getNextDefaultClasses(){if(i){return"label label-default";i=false}else{i=true;return"label label-info"}}for(var i in tags){var text=tags[i];text=Tag.mapEn2Cn[text]||text;text=text.replace(/[\r\n]/g,"");var classes=Tag.classes[text];if(!classes){classes=getNextDefaultClasses()}tag=tt('<span class="?">?</span>',classes,toHtmlEntity(text));$("#noteReadTags").append(tag)}};Tag.appendTag=function(tag,save){var isColor=false;var classes,text;if(typeof tag=="object"){classes=tag.classes;text=tag.text;if(!text){return}}else{tag=$.trim(tag);text=tag;if(!text){return}var classes=Tag.classes[text];if(classes){isColor=true}else{classes="label label-default"}}var rawText=text;if(LEA.locale=="zh"){text=Tag.mapEn2Cn[text]||text;rawText=Tag.mapCn2En[rawText]||rawText}text=text.replace(/[\r\n]/g,"");tag=tt('<span class="?" data-tag="?">?<i title="'+getMsg("delete")+'">X</i></span>',classes,text,toHtmlEntity(text));var isExists=false;$("#tags").children().each(function(){if(isColor){var tagHtml=$("<div></div>").append($(this).clone()).html();if(tagHtml==tag){$(this).remove();isExists=true}}else if(text+"X"==$(this).text()){$(this).remove();isExists=true}});$("#tags").append(tag);hideTagList();if(!isColor){reRenderTags()}if(save){Note.curNoteIsDirtied();if(!isExists){Note.curChangedSaveIt(true,function(){ajaxPost("/tag/updateTag",{tag:rawText},function(ret){if(reIsOk(ret)){Tag.addTagNav(ret.Item)}})})}}};function reRenderTags(){var defautClasses=["label label-default","label label-info"];var i=0;$("#tags").children().each(function(){var thisClasses=$(this).attr("class");if(thisClasses=="label label-default"||thisClasses=="label label-info"){$(this).removeClass(thisClasses).addClass(defautClasses[i%2]);i++}})}Tag.removeTag=function($target){var tag=$target.data("tag");$target.remove();reRenderTags();if(LEA.locale=="zh"){tag=Tag.mapCn2En[tag]||tag}Note.curChangedSaveIt(true,function(){ajaxPost("/tag/updateTag",{tag:tag},function(ret){if(reIsOk(ret)){Tag.addTagNav(ret.Item)}})})};Tag.tags=[];Tag.renderTagNav=function(tags){var me=this;tags=tags||[];Tag.tags=tags;$("#tagNav").html("");for(var i in tags){var noteTag=tags[i];var tag=noteTag.Tag;var text=tag;if(LEA.locale=="zh"){var text=Tag.mapEn2Cn[tag]||text}text=text.replace(/[\r\n]/g,"");var classes=Tag.classes[tag]||"label label-default";$("#tagNav").append(tt('<li data-tag="?"><a> <span class="?">?</span> <span class="tag-delete">X</span></li>',tag,classes,toHtmlEntity(text)))}};Tag.addTagNav=function(newTag){var me=this;for(var i in me.tags){var noteTag=me.tags[i];if(noteTag.Tag==newTag.Tag){me.tags.splice(i,1);break}}me.tags.unshift(newTag);me.renderTagNav(me.tags)};$(function(){$("#addTagTrigger").click(function(){$(this).hide();$("#addTagInput").show().focus().val("")});$("#addTagInput").click(function(event){showTagList(event)});$("#addTagInput").blur(function(){var val=$(this).val();if(val){Tag.appendTag(val,true)}return;$("#addTagTrigger").show();$("#addTagInput").hide()});$("#addTagInput").keydown(function(e){if(e.keyCode==13){hideTagList();if($("#addTagInput").val()){$(this).trigger("blur");$("#addTagTrigger").trigger("click")}else{$(this).trigger("blur")}}});$("#tagColor li").click(function(event){var a;if($(this).attr("role")){a=$(this).find("span")}else{a=$(this)}Tag.appendTag({classes:a.attr("class"),text:a.text()},true)});$("#tags").on("click","i",function(){Tag.removeTag($(this).parent())});function deleteTag(){$li=$(this).closest("li");var tag=$.trim($li.data("tag"));if(confirm("Are you sure ?")){ajaxPost("/tag/deleteTag",{tag:tag},function(re){if(reIsOk(re)){var item=re.Item;Note.deleteNoteTag(item,tag);$li.remove()}})}}function searchTag(){var $li=$(this).closest("li");var tag=$.trim($li.data("tag"));Note.curChangedSaveIt();Note.clearAll();$("#tagSearch").html($li.html()).show();$("#tagSearch .tag-delete").remove();showLLine truncated
|
||||
Tag.classes={"蓝色":"label label-blue","红色":"label label-red","绿色":"label label-green","黄色":"label label-yellow",blue:"label label-blue",red:"label label-red",green:"label label-green",yellow:"label label-yellow"};Tag.mapCn2En={"蓝色":"blue","红色":"red","绿色":"green","黄色":"yellow"};Tag.mapEn2Cn={blue:"蓝色",red:"红色",green:"绿色",yellow:"黄色"};Tag.t=$("#tags");Tag.getTags=function(){var tags=[];Tag.t.children().each(function(){var text=$(this).data("tag");text=Tag.mapCn2En[text]||text;tags.push(text)});return tags};Tag.clearTags=function(){Tag.t.html("")};Tag.renderTags=function(tags){Tag.t.html("");if(isEmpty(tags)){return}for(var i=0;i<tags.length;++i){var tag=tags[i];Tag.appendTag(tag)}};function revertTagStatus(){$("#addTagTrigger").show();$("#addTagInput").hide()}function hideTagList(event){$("#tagDropdown").removeClass("open");if(event){event.stopPropagation()}}function showTagList(event){$("#tagDropdown").addClass("open");if(event){event.stopPropagation()}}Tag.renderReadOnlyTags=function(tags){$("#noteReadTags").html("");if(isEmpty(tags)||tags.length==1&&tags[0]==""){$("#noteReadTags").html(getMsg("noTag"))}var i=true;function getNextDefaultClasses(){if(i){return"label label-default";i=false}else{i=true;return"label label-info"}}for(var i in tags){var text=tags[i];text=Tag.mapEn2Cn[text]||text;var classes=Tag.classes[text];if(!classes){classes=getNextDefaultClasses()}tag=tt('<span class="?">?</span>',classes,text);$("#noteReadTags").append(tag)}};Tag.appendTag=function(tag,save){var isColor=false;var classes,text;if(typeof tag=="object"){classes=tag.classes;text=tag.text;if(!text){return}}else{tag=$.trim(tag);text=tag;if(!text){return}var classes=Tag.classes[text];if(classes){isColor=true}else{classes="label label-default"}}var rawText=text;if(LEA.locale=="zh"){text=Tag.mapEn2Cn[text]||text;rawText=Tag.mapCn2En[rawText]||rawText}tag=tt('<span class="?" data-tag="?">?<i title="'+getMsg("delete")+'">X</i></span>',classes,text,text);var isExists=false;$("#tags").children().each(function(){if(isColor){var tagHtml=$("<div></div>").append($(this).clone()).html();if(tagHtml==tag){$(this).remove();isExists=true}}else if(text+"X"==$(this).text()){$(this).remove();isExists=true}});$("#tags").append(tag);hideTagList();if(!isColor){reRenderTags()}if(save){Note.curNoteIsDirtied();if(!isExists){Note.curChangedSaveIt(true,function(){ajaxPost("/tag/updateTag",{tag:rawText},function(ret){if(reIsOk(ret)){Tag.addTagNav(ret.Item)}})})}}};function reRenderTags(){var defautClasses=["label label-default","label label-info"];var i=0;$("#tags").children().each(function(){var thisClasses=$(this).attr("class");if(thisClasses=="label label-default"||thisClasses=="label label-info"){$(this).removeClass(thisClasses).addClass(defautClasses[i%2]);i++}})}Tag.removeTag=function($target){var tag=$target.data("tag");$target.remove();reRenderTags();if(LEA.locale=="zh"){tag=Tag.mapCn2En[tag]||tag}Note.curChangedSaveIt(true,function(){ajaxPost("/tag/updateTag",{tag:tag},function(ret){if(reIsOk(ret)){Tag.addTagNav(ret.Item)}})})};Tag.tags=[];Tag.renderTagNav=function(tags){var me=this;tags=tags||[];Tag.tags=tags;$("#tagNav").html("");for(var i in tags){var noteTag=tags[i];var tag=noteTag.Tag;var text=tag;if(LEA.locale=="zh"){var text=Tag.mapEn2Cn[tag]||text}var classes=Tag.classes[tag]||"label label-default";$("#tagNav").append(tt('<li data-tag="?"><a> <span class="?">?</span> <span class="tag-delete">X</span></li>',tag,classes,text))}};Tag.addTagNav=function(newTag){var me=this;for(var i in me.tags){var noteTag=me.tags[i];if(noteTag.Tag==newTag.Tag){me.tags.splice(i,1);break}}me.tags.unshift(newTag);me.renderTagNav(me.tags)};$(function(){$("#addTagTrigger").click(function(){$(this).hide();$("#addTagInput").show().focus().val("")});$("#addTagInput").click(function(event){showTagList(event)});$("#addTagInput").blur(function(){var val=$(this).val();if(val){Tag.appendTag(val,true)}return;$("#addTagTrigger").show();$("#addTagInput").hide()});$("#addTagInput").keydown(function(e){if(e.keyCode==13){hideTagList();if($("#addTagInput").val()){$(this).trigger("blur");$("#addTagTrigger").trigger("click")}else{$(this).trigger("blur")}}});$("#tagColor li").click(function(event){var a;if($(this).attr("role")){a=$(this).find("span")}else{a=$(this)}Tag.appendTag({classes:a.attr("class"),text:a.text()},true)});$("#tags").on("click","i",function(){Tag.removeTag($(this).parent())});function deleteTag(){$li=$(this).closest("li");var tag=$.trim($li.data("tag"));if(confirm("Are you sure ?")){ajaxPost("/tag/deleteTag",{tag:tag},function(re){if(reIsOk(re)){var item=re.Item;Note.deleteNoteTag(item,tag);$li.remove()}})}}function searchTag(){var $li=$(this).closest("li");var tag=$.trim($li.data("tag"));Note.curChangedSaveIt();Note.clearAll();$("#tagSearch").html($li.html()).show();$("#tagSearch .tag-delete").remove();showLoading();ajaxGet("/note/searchNoteByTags",{tags:[tag]},function(notes){hideLoading();if(notes){Note.renderNotLine truncated
|
||||
@@ -86,7 +86,7 @@ function showTagList(event) {
|
||||
Tag.renderReadOnlyTags = function(tags) {
|
||||
// 先清空
|
||||
$("#noteReadTags").html("");
|
||||
if(isEmpty(tags)) {
|
||||
if(isEmpty(tags) || (tags.length == 1 && tags[0] == "")) {
|
||||
$("#noteReadTags").html(getMsg("noTag"));
|
||||
}
|
||||
|
||||
@@ -104,13 +104,11 @@ Tag.renderReadOnlyTags = function(tags) {
|
||||
for(var i in tags) {
|
||||
var text = tags[i];
|
||||
text = Tag.mapEn2Cn[text] || text;
|
||||
text = text.replace(/[\r\n]/g, '');
|
||||
|
||||
var classes = Tag.classes[text];
|
||||
if(!classes) {
|
||||
classes = getNextDefaultClasses();
|
||||
}
|
||||
tag = tt('<span class="?">?</span>', classes, toHtmlEntity(text));
|
||||
tag = tt('<span class="?">?</span>', classes, text);
|
||||
|
||||
$("#noteReadTags").append(tag);
|
||||
}
|
||||
@@ -147,9 +145,7 @@ Tag.appendTag = function(tag, save) {
|
||||
text = Tag.mapEn2Cn[text] || text;
|
||||
rawText = Tag.mapCn2En[rawText] || rawText;
|
||||
}
|
||||
text = text.replace(/[\r\n]/g, '');
|
||||
|
||||
tag = tt('<span class="?" data-tag="?">?<i title="' + getMsg("delete") + '">X</i></span>', classes, text, toHtmlEntity(text));
|
||||
tag = tt('<span class="?" data-tag="?">?<i title="' + getMsg("delete") + '">X</i></span>', classes, text, text);
|
||||
|
||||
// 避免重复
|
||||
var isExists = false;
|
||||
@@ -239,9 +235,8 @@ Tag.renderTagNav = function(tags) {
|
||||
if(LEA.locale == "zh") {
|
||||
var text = Tag.mapEn2Cn[tag] || text;
|
||||
}
|
||||
text = text.replace(/[\r\n]/g, '');
|
||||
var classes = Tag.classes[tag] || "label label-default";
|
||||
$("#tagNav").append(tt('<li data-tag="?"><a> <span class="?">?</span> <span class="tag-delete">X</span></li>', tag, classes, toHtmlEntity(text)));
|
||||
$("#tagNav").append(tt('<li data-tag="?"><a> <span class="?">?</span> <span class="tag-delete">X</span></li>', tag, classes, text));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user