diff --git a/node_modules/note.js b/node_modules/note.js index 7a0a387b..313890c2 100644 --- a/node_modules/note.js +++ b/node_modules/note.js @@ -145,6 +145,29 @@ var Note = { }); }, + searchNote: function(key, callback) { + var reg = new RegExp(key); + Notes.find({IsTrash: false, LocalIsDelete: false, $or: [{Title: reg}, {Content: reg}]}).sort({'UpdatedTime': -1}).exec(function(err, notes) { + if(!err && notes) { + console.log('search ' + key + ' result: ' + notes.length); + callback(notes); + } else { + callback([]); + } + }); + }, + + searchNoteByTag: function(tag, callback) { + Notes.find({IsTrash: false, LocalIsDelete: false, Tags: {$in: [tag]}}).sort({'UpdatedTime': -1}).exec(function(err, notes) { + if(!err && notes) { + console.log('search by tag: ' + tag + ' result: ' + notes.length); + callback(notes); + } else { + callback([]); + } + }); + }, + deleteNote: function(noteId, callback) { Notes.update({NoteId: noteId}, {$set: {IsTrash: true, IsDirty: true}}, function(err, n) { if(err || !n) { diff --git a/public/css/theme/basic.less b/public/css/theme/basic.less index 4d1b1310..82baacdb 100644 --- a/public/css/theme/basic.less +++ b/public/css/theme/basic.less @@ -1454,4 +1454,22 @@ top: 4px; #noteItemList .item-conflict { border: 2px solid #DBB624; +} + +#tagNav { + i, em { + font-style: normal; + } + .tag-delete { + display: none; + font-size: 12px; + } + li:hover { + .tag-delete { + display: inline-block; + } + } + a:hover { + background: none !important; + } } \ No newline at end of file diff --git a/public/css/theme/default.css b/public/css/theme/default.css index 548e628c..bde8337d 100644 --- a/public/css/theme/default.css +++ b/public/css/theme/default.css @@ -1317,6 +1317,20 @@ h3 { #noteItemList .item-conflict { border: 2px solid #DBB624; } +#tagNav i, +#tagNav em { + font-style: normal; +} +#tagNav .tag-delete { + display: none; + font-size: 12px; +} +#tagNav li:hover .tag-delete { + display: inline-block; +} +#tagNav a:hover { + background: none !important; +} ::selection { background: #000000; color: #ffffff; diff --git a/public/css/theme/simple.css b/public/css/theme/simple.css index 78047cf0..a9a666d3 100644 --- a/public/css/theme/simple.css +++ b/public/css/theme/simple.css @@ -1317,6 +1317,20 @@ h3 { #noteItemList .item-conflict { border: 2px solid #DBB624; } +#tagNav i, +#tagNav em { + font-style: normal; +} +#tagNav .tag-delete { + display: none; + font-size: 12px; +} +#tagNav li:hover .tag-delete { + display: inline-block; +} +#tagNav a:hover { + background: none !important; +} ::selection { background: #000000; color: #ffffff; diff --git a/public/css/theme/writting-overwrite.css b/public/css/theme/writting-overwrite.css index 7289826b..0d8c24d4 100644 --- a/public/css/theme/writting-overwrite.css +++ b/public/css/theme/writting-overwrite.css @@ -1317,6 +1317,20 @@ h3 { #noteItemList .item-conflict { border: 2px solid #DBB624; } +#tagNav i, +#tagNav em { + font-style: normal; +} +#tagNav .tag-delete { + display: none; + font-size: 12px; +} +#tagNav li:hover .tag-delete { + display: inline-block; +} +#tagNav a:hover { + background: none !important; +} @font-face { font-family: 'Open Sans'; font-style: normal; diff --git a/public/css/theme/writting.css b/public/css/theme/writting.css index 99f49e69..ec90d71a 100644 --- a/public/css/theme/writting.css +++ b/public/css/theme/writting.css @@ -1317,6 +1317,20 @@ h3 { #noteItemList .item-conflict { border: 2px solid #DBB624; } +#tagNav i, +#tagNav em { + font-style: normal; +} +#tagNav .tag-delete { + display: none; + font-size: 12px; +} +#tagNav li:hover .tag-delete { + display: inline-block; +} +#tagNav a:hover { + background: none !important; +} @font-face { font-family: 'Open Sans'; font-style: normal; diff --git a/public/js/app/note.js b/public/js/app/note.js index 6317c25b..7602285c 100644 --- a/public/js/app/note.js +++ b/public/js/app/note.js @@ -1293,6 +1293,8 @@ Note.isSameSearch = function(key) { return false; } +// 搜索笔记 +Note.searchSeq = 0; Note.searchNote = function() { var val = $("#searchNoteInput").val(); if(!val) { @@ -1304,11 +1306,12 @@ Note.searchNote = function() { if(Note.isSameSearch(val)) { return; } - + + // 之前有, 还有结束的 - if(Note.lastSearch) { - Note.lastSearch.abort(); - } + // if(Note.lastSearch) { + // Note.lastSearch.abort(); + // } // 步骤与tag的搜索一样 // 1 @@ -1320,21 +1323,13 @@ Note.searchNote = function() { // 发送请求之 // 先取消上一个 showLoading(); - Note.lastSearch = ajaxPost("/note/searchNote", {key: val}, function(notes) { + + Note.searchSeq++; + var t = Note.searchSeq; + NoteService.searchNote(val, function(notes) { hideLoading(); - if(notes) { - // 成功后设为空 - Note.lastSearch = null; - // renderNotes只是note列表加载, 右侧笔记详情还没加载 - // 这个时候, 定位第一个, 保存之前的, - // 如果: 第一次搜索, renderNotes OK, 还没等到changeNote时 - // 第二次搜索来到, Note.curChangedSaveIt(); - // 导致没有标题了 - // 不是这个原因, 下面的Note.changeNote会导致保存 - - // 设空, 防止发生上述情况 - // Note.curNoteId = ""; - + if(t == Note.searchSeq && notes) { + Notebook.changeCurNotebookTitle('Search results', false, notes.length); Note.renderNotes(notes); if(!isEmpty(notes)) { Note.changeNote(notes[0].NoteId, false/*, true || Note.isOver2Seconds*/); // isShare, needSaveChanged?, 超过2秒就要保存 @@ -2109,11 +2104,10 @@ $(function() { //--------------------------- // 搜索, 按enter才搜索 - /* $("#searchNoteInput").on("keyup", function(e) { Note.searchNote(); }); - */ + /* $("#searchNoteInput").on("keydown", function(e) { var theEvent = e; // window.event || arguments.callee.caller.arguments[0]; if(theEvent.keyCode == 13 || theEvent.keyCode == 108) { @@ -2122,6 +2116,7 @@ $(function() { return false; } }); + */ //-------------------- // Note.initContextmenu(); diff --git a/public/js/app/notebook.js b/public/js/app/notebook.js index f5afb87d..dc8fda67 100644 --- a/public/js/app/notebook.js +++ b/public/js/app/notebook.js @@ -689,7 +689,7 @@ Notebook.changeNotebook = function(notebookId, callback) { }; // 改变标签, isStarred是否是星笔记本 -Notebook.changeCurNotebookTitle = function(title, isStarred) { +Notebook.changeCurNotebookTitle = function(title, isStarred, subTitle) { var me = this; $("#curNotebookForListNote").html(title); me.isStarred = isStarred; diff --git a/public/js/app/tag.js b/public/js/app/tag.js index fca8572e..6d3204be 100644 --- a/public/js/app/tag.js +++ b/public/js/app/tag.js @@ -261,7 +261,7 @@ Tag.renderTagNav = function(tags) { } */ var classes = Tag.classes[tag] || "label label-default"; - $("#tagNav").append(tt('
  • ? (?) X
  • ', tag, classes, text, noteTag.Count)); + $("#tagNav").append(tt('
  • ? (?) X
  • ', tag, classes, text, noteTag.Count)); } }; @@ -375,17 +375,20 @@ $(function() { // 也会把curNoteId清空 Note.clearAll(); - $("#tagSearch").html($li.html()).show(); - $("#tagSearch .tag-delete").remove(); + // $("#tagSearch").html($li.html()).show(); + + var h = $li.html(); + Notebook.changeCurNotebookTitle(h); + $('#curNotebookForListNote').find('i, em').remove(); + // $("#tagSearch .tag-delete").remove(); showLoading(); - ajaxGet("/note/searchNoteByTags", {tags: [tag]}, function(notes) { + NoteService.searchNoteByTag(tag, function(notes) { hideLoading(); if(notes) { // 和note搜索一样 // 设空, 防止发生上述情况 // Note.curNoteId = ""; - Note.renderNotes(notes); if(!isEmpty(notes)) { Note.changeNote(notes[0].NoteId);