Support note list view and sorter
This commit is contained in:
11
public/js/app.min.js
vendored
11
public/js/app.min.js
vendored
File diff suppressed because one or more lines are too long
@ -74,7 +74,7 @@ Note.setNoteCache = function(content, clear) {
|
||||
if(clear) {
|
||||
Note.clearCacheByNotebookId(content.NotebookId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Note.setCurNoteId = function (noteId) {
|
||||
this.curNoteId = noteId;
|
||||
@ -90,7 +90,7 @@ Note.getCurNote = function() {
|
||||
return null;
|
||||
}
|
||||
return self.cache[self.curNoteId];
|
||||
}
|
||||
};
|
||||
Note.getNote = function(noteId) {
|
||||
var self = this;
|
||||
return self.cache[noteId];
|
||||
@ -114,35 +114,43 @@ Note.notebookHasNotes = function(notebookId) {
|
||||
};
|
||||
|
||||
// 得到notebook下的notes, 按什么排序 updatedTime?
|
||||
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 {
|
||||
}
|
||||
|
||||
// 从所有的notes中找到notebookId的, 并排序之
|
||||
var notes = [];
|
||||
var sortBys = [];
|
||||
for(var i in Note.cache) {
|
||||
if(!i) {
|
||||
continue;
|
||||
}
|
||||
var note = Note.cache[i];
|
||||
Note.getNotesByNotebookId = function(notebookId) {
|
||||
var sorterAndOrder = Note.getSorterAndOrder();
|
||||
var sortBy = sorterAndOrder.sortBy;
|
||||
var isAsc = sorterAndOrder.isAsc;
|
||||
|
||||
Note.listIsIn();
|
||||
|
||||
if (!notebookId) {
|
||||
notebookId = "all";
|
||||
}
|
||||
|
||||
if (!Note.cacheByNotebookId[notebookId]) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (Note.cacheByNotebookId[notebookId][sortBy]) {
|
||||
if (Note.cacheByNotebookId[notebookId][sortBy][isAsc]) {
|
||||
return Note.cacheByNotebookId[notebookId][sortBy][isAsc];
|
||||
}
|
||||
// 逆序
|
||||
Note.cacheByNotebookId[notebookId][sortBy][!isAsc].reverse();
|
||||
var notes = Note.cacheByNotebookId[notebookId][sortBy][!isAsc];
|
||||
Note.cacheByNotebookId[notebookId][sortBy][!isAsc] = null;
|
||||
Note.cacheByNotebookId[notebookId][sortBy][isAsc] = notes;
|
||||
return notes;
|
||||
}
|
||||
|
||||
// 从所有的notes中找到notebookId的, 并排序之
|
||||
var notes = [];
|
||||
for (var i in Note.cache) {
|
||||
if (!i) {
|
||||
continue;
|
||||
}
|
||||
var note = Note.cache[i];
|
||||
if (!note) {
|
||||
continue;
|
||||
}
|
||||
// 不要trash的not, 共享的也不要
|
||||
if(note.IsTrash || note.IsShared) {
|
||||
continue;
|
||||
@ -150,43 +158,27 @@ Note.getNotesByNotebookId = function(notebookId, sortBy, isAsc) {
|
||||
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.sortNotes(notes);
|
||||
|
||||
// 缓存之
|
||||
Note.cacheByNotebookId[notebookId][sortBy] = {};
|
||||
Note.cacheByNotebookId[notebookId][sortBy][isAsc] = notes;
|
||||
return notes;
|
||||
};
|
||||
|
||||
|
||||
// called by Notebook
|
||||
// render 所有notes, 和第一个note的content
|
||||
Note.renderNotesAndFirstOneContent = function(ret) {
|
||||
Note.renderNotesAndFirstOneContent = function(ret, hasSorted) {
|
||||
// 错误的ret是一个Object
|
||||
if(!isArray(ret)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// note 导航
|
||||
Note.renderNotes(ret);
|
||||
Note.renderNotes(ret, false, false, hasSorted);
|
||||
// 渲染第一个
|
||||
if(!isEmpty(ret[0])) {
|
||||
Note.changeNoteForPjax(ret[0].NoteId, true, false);
|
||||
@ -201,7 +193,7 @@ Note.renderNotesAndFirstOneContent = function(ret) {
|
||||
// 所以不用isDirty()
|
||||
// 只用Note.readOnly, 如果Note.readOnly, 那么不判断内容
|
||||
//
|
||||
Note.curHasChanged = function(force) {
|
||||
Note.curHasChanged = function(force, isRefreshOrCtrls) {
|
||||
var cacheNote = Note.getCurNote();
|
||||
if (!cacheNote) {
|
||||
return false;
|
||||
@ -222,6 +214,11 @@ Note.curHasChanged = function(force) {
|
||||
|
||||
if (cacheNote.IsNew) {
|
||||
hasChanged.hasChanged = true;
|
||||
hasChanged.title = title;
|
||||
// 来源
|
||||
if (LEA.topInfo) {
|
||||
hasChanged.Src = LEA.topInfo.src;
|
||||
}
|
||||
}
|
||||
|
||||
if(cacheNote.Title != title) {
|
||||
@ -270,6 +267,15 @@ Note.curHasChanged = function(force) {
|
||||
} else {
|
||||
content = contents;
|
||||
}
|
||||
|
||||
// 如果是插件, 且没有改动任何地方
|
||||
if ( hasChanged.Src && LEA.topInfo && title === LEA.topInfo.title && !hasChanged.Tags &&
|
||||
(!content || content == '<p><br></p>')) {
|
||||
// 如果不是手动ctrl+s, 则不保存
|
||||
if (!(isRefreshOrCtrls && isRefreshOrCtrls.ctrls)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 比较text, 因为note Nav会添加dom会导致content改变
|
||||
/*
|
||||
@ -369,7 +375,7 @@ Note.genAbstract = function(content, len) {
|
||||
var d = document.createElement("div");
|
||||
d.innerHTML = result
|
||||
return d.innerHTML;
|
||||
}
|
||||
};
|
||||
|
||||
Note.getImgSrc = function(content) {
|
||||
if(!content) {
|
||||
@ -383,7 +389,7 @@ Note.getImgSrc = function(content) {
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
// 如果当前的改变了, 就保存它
|
||||
// 以后要定时调用
|
||||
@ -391,7 +397,7 @@ Note.getImgSrc = function(content) {
|
||||
// 定时保存传false
|
||||
Note.saveInProcess = {}; // noteId => bool, true表示该note正在保存到服务器, 服务器未响应
|
||||
Note.savePool = {}; // 保存池, 以后的保存先放在pool中, id => note
|
||||
Note.curChangedSaveIt = function(force, callback) {
|
||||
Note.curChangedSaveIt = function(force, callback, isRefreshOrCtrls) {
|
||||
var me = this;
|
||||
// 如果当前没有笔记, 不保存
|
||||
// 或者是共享的只读笔记
|
||||
@ -401,7 +407,7 @@ Note.curChangedSaveIt = function(force, callback) {
|
||||
}
|
||||
var hasChanged;
|
||||
try {
|
||||
hasChanged = Note.curHasChanged(force);
|
||||
hasChanged = Note.curHasChanged(force, isRefreshOrCtrls);
|
||||
} catch(e) {
|
||||
// console.error('获取当前改变的笔记错误!');
|
||||
callback && callback(false);
|
||||
@ -450,7 +456,8 @@ Note.curChangedSaveIt = function(force, callback) {
|
||||
Note.setNoteCache(hasChanged, false);
|
||||
// 设置更新时间
|
||||
Note.setNoteCache({"NoteId": hasChanged.NoteId, "UpdatedTime": (new Date()).format("yyyy-MM-ddThh:mm:ss.S")}, false);
|
||||
|
||||
Note.clearCacheByNotebookId(hasChanged.NotebookId);
|
||||
|
||||
return hasChanged;
|
||||
}
|
||||
else {
|
||||
@ -493,13 +500,13 @@ Note.startUpdatePoolNoteInterval = function() {
|
||||
// 样式
|
||||
Note.clearSelect = function(target) {
|
||||
$(".item").removeClass("item-active");
|
||||
}
|
||||
};
|
||||
Note.selectTarget = function(target) {
|
||||
this.clearSelect();
|
||||
$(target).addClass("item-active");
|
||||
|
||||
// this.batch.reset();
|
||||
}
|
||||
};
|
||||
|
||||
// 改变note
|
||||
// 可能改变的是share note
|
||||
@ -516,7 +523,12 @@ Note.directToNote = function(noteId) {
|
||||
var $p = $("#noteItemList");
|
||||
var pHeight = $p.height();
|
||||
// 相对于父亲的位置
|
||||
var pTop = $("[noteId='" + noteId + "']").position().top;
|
||||
var position = $("[noteId='" + noteId + "']").position();
|
||||
if (!position) {
|
||||
console.error('no position: ' + noteId);
|
||||
return;
|
||||
}
|
||||
var pTop = position.top;
|
||||
var scrollTop = $p.scrollTop();
|
||||
pTop += scrollTop;
|
||||
/*
|
||||
@ -816,20 +828,168 @@ Note.hideEditorMask = function() {
|
||||
$("#editorMask").css("z-index", -10).hide();
|
||||
};
|
||||
|
||||
/**
|
||||
* 切换视图
|
||||
* @param {[type]} e [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
Note.toggleView = function (e) {
|
||||
var view;
|
||||
if (typeof e == 'object' && e) {
|
||||
view = $(e.target).data('view');
|
||||
}
|
||||
else {
|
||||
view = e;
|
||||
}
|
||||
if (!view) {
|
||||
view = 'snippet';
|
||||
}
|
||||
if (view == 'list') {
|
||||
$('#noteItemList').addClass('list');
|
||||
}
|
||||
else {
|
||||
$('#noteItemList').removeClass('list');
|
||||
}
|
||||
localStorage.setItem('viewStyle', view);
|
||||
$('.view-style').removeClass('checked');
|
||||
$('.view-' + view).addClass('checked');
|
||||
};
|
||||
|
||||
// 重新设置sorter, 此时要重新render
|
||||
// sortType = dateCreatedASC dateCreatedDESC
|
||||
Note.setNotesSorter = function (e) {
|
||||
var sorterType = $(e.currentTarget).data('sorter');
|
||||
if (!sorterType) {
|
||||
sorterType = 'dateUpdatedDESC';
|
||||
}
|
||||
localStorage.setItem("sorterType", sorterType);
|
||||
// alert(localStorage.getItem("sorterType"));
|
||||
Note.checkSorter(sorterType);
|
||||
|
||||
// 如果当前是tagSearch, search, star 怎么办?
|
||||
// 重新Render
|
||||
if (Note._isTag || Note._isSearch || Note._isShare) {
|
||||
Note.renderNotesAndFirstOneContent(Note._everNotes, false);
|
||||
} else {
|
||||
// 其实这里也可以用Note._everNotes, 主要是为了缓存数据
|
||||
Notebook.changeNotebook(Notebook.curNotebookId);
|
||||
}
|
||||
// Note.renderNotesAndTargetNote(Note._everNotes, false, false);
|
||||
// Api.writeConfig(Config);
|
||||
};
|
||||
|
||||
var $sorterStyles = $('.sorter-style');
|
||||
Note.checkSorter = function (sorterType) {
|
||||
// UC无痕浏览
|
||||
if (!sorterType) {
|
||||
sorterType = 'dateUpdatedDESC';
|
||||
}
|
||||
var $selected = $('.sorter-' + sorterType);
|
||||
if ($selected.is('.checked')) {
|
||||
return;
|
||||
}
|
||||
$sorterStyles.removeClass('checked');
|
||||
$selected.addClass('checked');
|
||||
};
|
||||
|
||||
// render前先排序
|
||||
Note.sortNotesToRender = function (notes) {
|
||||
Note.sortNotes(notes);
|
||||
};
|
||||
|
||||
Note.sortNotes = function (notes) {
|
||||
if (isEmpty(notes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var sorterAndOrder = Note.getSorterAndOrder();
|
||||
var sortBy = sorterAndOrder.sortBy;
|
||||
var isAsc = sorterAndOrder.isAsc;
|
||||
|
||||
// 排序之
|
||||
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.getSorterAndOrder = function () {
|
||||
var sortBy = "UpdatedTime";
|
||||
var isAsc = false; // 默认是降序
|
||||
var sorterType = localStorage.getItem('sorterType');
|
||||
// console.log(sorterType);
|
||||
Note.checkSorter(sorterType);
|
||||
if (sorterType) {
|
||||
switch(sorterType) {
|
||||
case 'dateCreatedASC':
|
||||
sortBy = 'CreatedTime';
|
||||
isAsc = true;
|
||||
break;
|
||||
case 'dateCreatedDESC':
|
||||
sortBy = 'CreatedTime';
|
||||
isAsc = false;
|
||||
break;
|
||||
case 'dateUpdatedASC':
|
||||
sortBy = 'UpdatedTime';
|
||||
isAsc = true;
|
||||
break;
|
||||
case 'dateUpdatedDESC':
|
||||
sortBy = 'UpdatedTime';
|
||||
isAsc = false;
|
||||
break;
|
||||
case 'titleASC':
|
||||
sortBy = 'Title';
|
||||
isAsc = true;
|
||||
break;
|
||||
case 'titleDESC':
|
||||
sortBy = 'Title';
|
||||
isAsc = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
console.log({sortBy: sortBy, isAsc: isAsc});
|
||||
return {sortBy: sortBy, isAsc: isAsc};
|
||||
};
|
||||
|
||||
// 列表是
|
||||
Note.listIsIn = function (isTag, isSearch, isShare) {
|
||||
this._isTag = isTag;
|
||||
this._isSearch = isSearch;
|
||||
this._isShare = isShare;
|
||||
};
|
||||
|
||||
// 这里如果notes过多>100个将会很慢!!, 使用setTimeout来分解
|
||||
Note.renderNotesC = 0;
|
||||
Note.renderNotes = function(notes, forNewNote, isShared) {
|
||||
Note.renderNotes = function(notes, forNewNote, isShared, hasSorted) {
|
||||
var renderNotesC = ++Note.renderNotesC;
|
||||
|
||||
this.clearSeqForNew();
|
||||
this.batch.reset();
|
||||
|
||||
// 为了切换排序方式用
|
||||
Note._everNotes = notes;
|
||||
|
||||
// 手机端不用
|
||||
// slimScroll使得手机端滚动不流畅
|
||||
if(!LEA.isMobile && !Mobile.isMobile()) {
|
||||
$("#noteItemList").slimScroll({ scrollTo: '0px', height: "100%", onlyScrollBar: true});
|
||||
}
|
||||
|
||||
|
||||
if(!notes || typeof notes != "object" || notes.length <= 0) {
|
||||
// 如果没有, 那么是不是应该hide editor?
|
||||
if(!forNewNote) {
|
||||
@ -849,6 +1009,11 @@ Note.renderNotes = function(notes, forNewNote, isShared) {
|
||||
// 20个一次
|
||||
var len = notes.length;
|
||||
var c = Math.ceil(len/20);
|
||||
|
||||
// 重新排序
|
||||
if (!hasSorted) {
|
||||
Note.sortNotes(notes);
|
||||
}
|
||||
|
||||
Note._renderNotes(notes, forNewNote, isShared, 1);
|
||||
|
||||
@ -900,9 +1065,11 @@ Note._renderNotes = function(notes, forNewNote, isShared, tang) { // 第几趟
|
||||
} else {
|
||||
tmp = tt(Note.itemTplNoImg, classes, i, note.NoteId, note.Title, Notebook.getNotebookTitle(note.NotebookId), goNowToDatetime(note.UpdatedTime), note.Desc);
|
||||
}
|
||||
tmp = $(tmp);
|
||||
if(!note.IsBlog) {
|
||||
tmp = $(tmp);
|
||||
tmp.find(".item-blog").hide();
|
||||
tmp.removeClass('item-b');
|
||||
} else {
|
||||
tmp.addClass('item-b');
|
||||
}
|
||||
Note.noteItemListO.append(tmp);
|
||||
|
||||
@ -937,22 +1104,36 @@ Note.newNoteSeq = function () {
|
||||
// isShare时fromUserId才有用
|
||||
// 3.8 add isMarkdown
|
||||
Note.newNote = function(notebookId, isShare, fromUserId, isMarkdown) {
|
||||
if (!notebookId) {
|
||||
notebookId = $("#curNotebookForNewNote").attr('notebookId');
|
||||
}
|
||||
|
||||
// 切换编辑器
|
||||
switchEditor(isMarkdown);
|
||||
Note.hideEditorMask();
|
||||
|
||||
|
||||
// 防止从共享read only跳到添加
|
||||
Note.hideReadOnly();
|
||||
|
||||
|
||||
Note.stopInterval();
|
||||
// 保存当前的笔记
|
||||
Note.curChangedSaveIt();
|
||||
|
||||
Note.batch.reset();
|
||||
|
||||
var note = {NoteId: getObjectId(), Title: "", Tags:[], Content:"", NotebookId: notebookId, IsNew: true, FromUserId: fromUserId, IsMarkdown: isMarkdown}; // 是新的
|
||||
|
||||
var note = {NoteId: getObjectId(),
|
||||
Title: "", Tags:[], Content:"",
|
||||
NotebookId: notebookId, IsNew: true, FromUserId: fromUserId,
|
||||
IsMarkdown: isMarkdown,
|
||||
UpdatedTime: new Date(),
|
||||
CreatedTime: new Date()}; // 是新的
|
||||
if (LEA.topInfo && LEA.topInfo.title) {
|
||||
note.Title = LEA.topInfo.title;
|
||||
}
|
||||
|
||||
// 添加到缓存中
|
||||
Note.addNoteCache(note);
|
||||
Note.clearCacheByNotebookId(notebookId);
|
||||
|
||||
// 清空附件数
|
||||
Attach.clearNoteAttachNum();
|
||||
@ -975,9 +1156,12 @@ Note.newNote = function(notebookId, isShare, fromUserId, isMarkdown) {
|
||||
}
|
||||
|
||||
// notebook是否是Blog
|
||||
newItem = $(newItem);
|
||||
if(!notebook.IsBlog) {
|
||||
newItem = $(newItem);
|
||||
newItem.find(".item-blog").hide();
|
||||
newItem.removeClass('item-b');
|
||||
}
|
||||
else {
|
||||
newItem.addClass('item-b');
|
||||
}
|
||||
|
||||
// 是否在当前notebook下, 不是则切换过去, 并得到该notebook下所有的notes, 追加到后面!
|
||||
@ -1261,6 +1445,10 @@ Note.searchNote = function() {
|
||||
// 先取消上一个
|
||||
showLoading();
|
||||
Notebook.showNoteAndEditorLoading();
|
||||
|
||||
Note.listIsIn(false, true);
|
||||
$("#tagSearch").hide();
|
||||
|
||||
Note.lastSearch = $.post("/note/searchNote", {key: val}, function(notes) {
|
||||
hideLoading();
|
||||
Notebook.hideNoteAndEditorLoading();
|
||||
@ -1317,9 +1505,9 @@ Note._setBlog = function(target, isBlog) {
|
||||
var noteId = noteIds[i];
|
||||
var $t = me.getTargetById(noteId);
|
||||
if(isBlog) {
|
||||
$t.find(".item-blog").show();
|
||||
$t.addClass('item-b');
|
||||
} else {
|
||||
$t.find(".item-blog").hide();
|
||||
$t.removeClass('item-b');
|
||||
}
|
||||
me.setNoteCache({NoteId: noteId, IsBlog: isBlog}, false); // 不清空NotesByNotebookId缓存
|
||||
}
|
||||
@ -1742,6 +1930,7 @@ Note.initContextmenu = function() {
|
||||
items.push("copy." + notebookTitle);
|
||||
}
|
||||
}
|
||||
// console.log(items);
|
||||
|
||||
// diable 这里
|
||||
menu.applyrule({
|
||||
@ -2450,7 +2639,6 @@ $(function() {
|
||||
Note.curChangedSaveIt(true);
|
||||
});
|
||||
|
||||
|
||||
// blog
|
||||
Note.$itemList.on("click", ".item-blog", function(e) {
|
||||
e.preventDefault();
|
||||
@ -2511,6 +2699,16 @@ $(function() {
|
||||
e.preventDefault();
|
||||
window.open(href);
|
||||
});
|
||||
|
||||
var view = localStorage.getItem('viewStyle');
|
||||
Note.toggleView(view);
|
||||
// view 切换
|
||||
$('.view-style').click(function (e) {
|
||||
Note.toggleView(e);
|
||||
});
|
||||
$('.sorter-style').click(function (e) {
|
||||
Note.setNotesSorter(e);
|
||||
});
|
||||
});
|
||||
|
||||
// 定时器启动
|
||||
|
@ -527,7 +527,7 @@ Notebook.changeNotebookNavForNewNote = function(notebookId, title) {
|
||||
Notebook.changeNotebookNavForNewNote(notebookId, title);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 改变导航, 两处
|
||||
// 单击左侧, 单击新建下拉时调用
|
||||
@ -544,7 +544,7 @@ Notebook.toggleToMyNav = function(userId, notebookId) {
|
||||
|
||||
// 搜索tag隐藏
|
||||
$("#tagSearch").hide();
|
||||
}
|
||||
};
|
||||
Notebook.changeNotebookNav = function(notebookId) {
|
||||
Notebook.curNotebookId = notebookId;
|
||||
Notebook.toggleToMyNav();
|
||||
@ -615,7 +615,7 @@ Notebook.changeNotebook = function(notebookId, callback) {
|
||||
if(callback) {
|
||||
callback(cacheNotes);
|
||||
} else {
|
||||
Note.renderNotesAndFirstOneContent(cacheNotes);
|
||||
Note.renderNotesAndFirstOneContent(cacheNotes, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -628,7 +628,7 @@ Notebook.changeNotebook = function(notebookId, callback) {
|
||||
if(callback) {
|
||||
callback(cacheNotes);
|
||||
} else {
|
||||
Note.renderNotesAndFirstOneContent(cacheNotes);
|
||||
Note.renderNotesAndFirstOneContent(cacheNotes, true);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
@ -653,7 +653,7 @@ Notebook.changeNotebook = function(notebookId, callback) {
|
||||
if(callback) {
|
||||
callback(cacheNotes);
|
||||
} else {
|
||||
Note.renderNotesAndFirstOneContent(cacheNotes);
|
||||
Note.renderNotesAndFirstOneContent(cacheNotes, false);
|
||||
}
|
||||
me.hideNoteAndEditorLoading();
|
||||
});
|
||||
@ -728,19 +728,22 @@ Notebook.setNotebook2Blog = function(target) {
|
||||
// 那么, 如果当前是该notebook下, 重新渲染之
|
||||
if(Notebook.curNotebookId == notebookId) {
|
||||
if(isBlog) {
|
||||
$("#noteList .item-blog").show();
|
||||
$('.item').addClass('item-b');
|
||||
} else {
|
||||
$("#noteList .item-blog").hide();
|
||||
$('.item').removeClass('item-b');
|
||||
}
|
||||
|
||||
// 如果当前在所有笔记本下
|
||||
} else if(Notebook.curNotebookId == Notebook.allNotebookId){
|
||||
$("#noteItemList .item").each(function(){
|
||||
var noteId = $(this).attr("noteId");
|
||||
var note = Note.cache[noteId];
|
||||
if(note.NotebookId == notebookId) {
|
||||
if(isBlog) $(this).find(".item-blog").show();
|
||||
else $(this).find(".item-blog").hide();
|
||||
if (isBlog) {
|
||||
$(this).addClass('item-b');
|
||||
}
|
||||
else {
|
||||
$(this).removeClass('item-b');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -972,4 +975,4 @@ $(function() {
|
||||
var $p = $(this).parent();
|
||||
Notebook.contextmenuSearch.showMenu(e, $p);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,16 @@
|
||||
// 主页渲染
|
||||
//-------------
|
||||
|
||||
function sendLog (key, value) {
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
if (!value) {
|
||||
value = '';
|
||||
}
|
||||
ajaxGet('/index/log', {key: key, value: value});
|
||||
}
|
||||
|
||||
//----------------------
|
||||
// 编辑器模式
|
||||
function editorMode() {
|
||||
@ -88,7 +98,7 @@ editorMode.prototype.normalMode = function() {
|
||||
var $themeLink = $("#themeLink");
|
||||
// 如果之前不是normal才换
|
||||
if(this.$themeLink.attr('href').indexOf('writting-overwrite.css') != -1) {
|
||||
this.$themeLink.attr("href", "/css/theme/" + theme);
|
||||
this.$themeLink.attr("href", LEA.sPath + "/css/theme/" + theme);
|
||||
}
|
||||
|
||||
$("#noteList").width(UserInfo.NoteListWidth);
|
||||
@ -103,7 +113,7 @@ editorMode.prototype.writtingMode = function() {
|
||||
return;
|
||||
}
|
||||
if(this.$themeLink.attr('href').indexOf('writting-overwrite.css') == -1) {
|
||||
this.$themeLink.attr("href", "/css/theme/writting-overwrite.css");
|
||||
this.$themeLink.attr("href", LEA.sPath + "/css/theme/writting-overwrite.css");
|
||||
}
|
||||
|
||||
/*
|
||||
@ -237,7 +247,7 @@ var Resize = {
|
||||
$('.preview-container').show();
|
||||
self.rightColumn.css('left', everLeftWidth).width('auto');
|
||||
|
||||
if(MD) {
|
||||
if(MD) {
|
||||
MD.resize();
|
||||
}
|
||||
}
|
||||
@ -582,7 +592,7 @@ function initEditor() {
|
||||
if (LEA.isLogout) {
|
||||
return;
|
||||
}
|
||||
Note.curChangedSaveIt(true);
|
||||
Note.curChangedSaveIt(true, null, {refresh: true});
|
||||
}
|
||||
|
||||
// 全局快捷键
|
||||
@ -594,7 +604,7 @@ function initEditor() {
|
||||
if(ctrlOrMetaKey) {
|
||||
// 保存
|
||||
if (num == 83 ) { // ctrl + s or command + s
|
||||
Note.curChangedSaveIt();
|
||||
Note.curChangedSaveIt(true, null, {ctrls: true});
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
@ -656,6 +666,11 @@ function scrollTo(self, tagName, text) {
|
||||
}
|
||||
}
|
||||
|
||||
function hideMask () {
|
||||
$("#mainMask").html("");
|
||||
$("#mainMask").hide(100);
|
||||
}
|
||||
|
||||
//--------------
|
||||
// 调用之
|
||||
// $(function() {
|
||||
@ -722,7 +737,7 @@ function scrollTo(self, tagName, text) {
|
||||
if (arr.length == 2) {
|
||||
id = arr[1];
|
||||
}
|
||||
$("#themeLink").attr("href", "/css/theme/" + val + ".css?id=" + id);
|
||||
$("#themeLink").attr("href", LEA.sPath + "/css/theme/" + val + ".css?id=" + id);
|
||||
ajaxPost("/user/updateTheme", {theme: val}, function(re) {
|
||||
if(reIsOk(re)) {
|
||||
UserInfo.Theme = val
|
||||
@ -812,8 +827,13 @@ function scrollTo(self, tagName, text) {
|
||||
Resize.set3ColumnsWidth(UserInfo.NotebookWidth, UserInfo.NoteListWidth);
|
||||
Resize.setMdColumnWidth(UserInfo.MdEditorWidth);
|
||||
|
||||
if (UserInfo.LeftIsMin) {
|
||||
minLeft(false);
|
||||
if (!Mobile.isMobile()) {
|
||||
if (UserInfo.LeftIsMin) {
|
||||
minLeft(false);
|
||||
}
|
||||
else {
|
||||
maxLeft(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
maxLeft(false);
|
||||
@ -822,8 +842,7 @@ function scrollTo(self, tagName, text) {
|
||||
// end
|
||||
// 开始时显示loading......
|
||||
// 隐藏mask
|
||||
$("#mainMask").html("");
|
||||
$("#mainMask").hide(100);
|
||||
// hideMask();
|
||||
|
||||
// 4/25 防止dropdown太高
|
||||
// dropdown
|
||||
@ -1438,45 +1457,174 @@ LeaAce = {
|
||||
}
|
||||
};
|
||||
|
||||
function initLeanoteIfrPlugin () {
|
||||
// 如果在iframe下, 很可能是嵌入了leanote
|
||||
if (self != window.parent) {
|
||||
LEA.topInfo = {};
|
||||
// 收到消息
|
||||
window.addEventListener('message', function(e) {
|
||||
console.log('child 收到消息: ')
|
||||
console.log(e.data);
|
||||
LEA.topInfo = e.data || {};
|
||||
LEA.topInfo.got = true;
|
||||
}, false);
|
||||
if (window.parent.postMessage) {
|
||||
window.parent.postMessage('leanote', '*');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 通过src得到note
|
||||
function getNoteBySrc(src, callback) {
|
||||
ajaxGet('/note/getNoteAndContentBySrc', {src: src}, function (ret) {
|
||||
if (ret && ret.Ok) {
|
||||
var data = ret.Item;
|
||||
if (data) {
|
||||
var noteInfo = data.NoteInfo;
|
||||
var contentInfo = data.NoteContentInfo;
|
||||
for (var i in contentInfo) {
|
||||
noteInfo[i] = contentInfo[i];
|
||||
}
|
||||
callback(noteInfo);
|
||||
}
|
||||
else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 得到top的info's src
|
||||
var _topInfoStart = (new Date()).getTime();
|
||||
function getTopInfoSrc (callback) {
|
||||
if (LEA.topInfo.got) {
|
||||
return callback(LEA.topInfo.src);
|
||||
}
|
||||
else {
|
||||
// 超过1000ms, 不行
|
||||
if ((new Date()).getTime() - _topInfoStart > 2000) {
|
||||
return callback();
|
||||
}
|
||||
setTimeout(function () {
|
||||
getTopInfoSrc(callback);
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
|
||||
// note.html调用
|
||||
// 实始化页面
|
||||
function initPage() {
|
||||
// 不要用$(function() {}) 因为要等到<script>都加载了才执行
|
||||
// $(function() {
|
||||
Notebook.renderNotebooks(notebooks);
|
||||
Share.renderShareNotebooks(sharedUserInfos, shareNotebooks);
|
||||
|
||||
// 如果初始打开的是共享的笔记
|
||||
// 那么定位到我的笔记
|
||||
if(curSharedNoteNotebookId) {
|
||||
Share.firstRenderShareNote(curSharedUserId, curSharedNoteNotebookId, curNoteId);
|
||||
// 初始打开的是我的笔记
|
||||
} else {
|
||||
Note.setNoteCache(noteContentJson);
|
||||
Note.renderNotes(notes);
|
||||
if(curNoteId) {
|
||||
// 指定某个note时才target notebook, /note定位到最新
|
||||
// ie10&+要setTimeout
|
||||
setTimeout(function() {
|
||||
Note.changeNoteForPjax(curNoteId, true, curNotebookId);
|
||||
initLeanoteIfrPlugin();
|
||||
if (LEA.topInfo) {
|
||||
getTopInfoSrc(function (src) {
|
||||
if (src) {
|
||||
getNoteBySrc (src, function (srcNote) {
|
||||
_initPage(srcNote, true);
|
||||
});
|
||||
if(!curNotebookId) {
|
||||
Notebook.selectNotebook($(tt('#notebook [notebookId="?"]', Notebook.allNotebookId)));
|
||||
} else {
|
||||
_initPage(false, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
_initPage();
|
||||
}
|
||||
}
|
||||
|
||||
function _initPage(srcNote, isTop) {
|
||||
if (srcNote) {
|
||||
curNoteId = srcNote.NoteId;
|
||||
curNotebookId = srcNote.NotebookId;
|
||||
noteContentJson = srcNote; // 当前笔记变成我的
|
||||
}
|
||||
else if(isTop) {
|
||||
curNoteId = null;
|
||||
}
|
||||
|
||||
Notebook.renderNotebooks(notebooks);
|
||||
Share.renderShareNotebooks(sharedUserInfos, shareNotebooks);
|
||||
|
||||
// 如果初始打开的是共享的笔记
|
||||
// 那么定位到我的笔记
|
||||
if(curSharedNoteNotebookId) {
|
||||
Share.firstRenderShareNote(curSharedUserId, curSharedNoteNotebookId, curNoteId);
|
||||
// 初始打开的是我的笔记
|
||||
} else {
|
||||
Note.setNoteCache(noteContentJson);
|
||||
// 判断srcNote是否在notes中
|
||||
var isExists = false;
|
||||
if (isTop && srcNote && notes) {
|
||||
for (var i = 0; i < notes.length; ++i) {
|
||||
var note = notes[i];
|
||||
if (note.NoteId === srcNote.NoteId) {
|
||||
isExists = true;
|
||||
notes.splice(i, 1);
|
||||
notes.unshift(srcNote);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 指定笔记, 也要保存最新笔记
|
||||
if(latestNotes.length > 0) {
|
||||
for(var i = 0; i < latestNotes.length; ++i) {
|
||||
Note.addNoteCache(latestNotes[i]);
|
||||
if (!isExists) {
|
||||
notes.unshift(srcNote);
|
||||
}
|
||||
}
|
||||
|
||||
Tag.renderTagNav(tagsJson);
|
||||
// init notebook后才调用
|
||||
initSlimScroll();
|
||||
|
||||
LeaAce.handleEvent();
|
||||
// });
|
||||
}
|
||||
Note.renderNotes(notes);
|
||||
|
||||
if(curNoteId) {
|
||||
// 指定某个note时才target notebook, /note定位到最新
|
||||
// ie10&+要setTimeout
|
||||
setTimeout(function() {
|
||||
Note.changeNoteForPjax(curNoteId, true, curNotebookId);
|
||||
if (isTop) {
|
||||
Note.toggleWriteable();
|
||||
setTimeout(function () {
|
||||
Note.toggleWriteable();
|
||||
}, 100);
|
||||
// 如果是markdown
|
||||
setTimeout(function () {
|
||||
Note.toggleWriteable();
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
if(!curNotebookId) {
|
||||
Notebook.selectNotebook($(tt('#notebook [notebookId="?"]', Notebook.allNotebookId)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 指定笔记, 也要保存最新笔记
|
||||
if(latestNotes.length > 0) {
|
||||
for(var i = 0; i < latestNotes.length; ++i) {
|
||||
Note.addNoteCache(latestNotes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Tag.renderTagNav(tagsJson);
|
||||
// init notebook后才调用
|
||||
initSlimScroll();
|
||||
|
||||
LeaAce.handleEvent();
|
||||
|
||||
// 如果是插件, 则切换到编辑页, 并切换到写作模式
|
||||
if (isTop) {
|
||||
Mobile.toEditor();
|
||||
|
||||
// 如果没有, 则新建之
|
||||
if (!srcNote) {
|
||||
Note.newNote();
|
||||
Note.toggleWriteable(true);
|
||||
setTimeout(function () {
|
||||
Note.toggleWriteable(true);
|
||||
}, 100);
|
||||
// 如果是markdown
|
||||
setTimeout(function () {
|
||||
Note.toggleWriteable(true);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
hideMask();
|
||||
}
|
@ -208,7 +208,7 @@ Share.toggleToSharedNav = function(userId, notebookId) {
|
||||
var self = this;
|
||||
// for list
|
||||
$("#curNotebookForListNote").html(Share.notebookCache[notebookId].Title + '(' + Share.sharedUserInfos[userId].Username + ")");
|
||||
|
||||
Note.listIsIn(false, false, true);
|
||||
// for new
|
||||
// 如果该用户下有新建的note, 那么列出, 如果没有, 则列出我的笔记
|
||||
var forNew = Share.userNavs[userId].forNew;
|
||||
|
@ -236,8 +236,10 @@ Tag.renderTagNav = function(tags) {
|
||||
var text = Tag.mapEn2Cn[tag] || text;
|
||||
}
|
||||
text = trimTitle(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));
|
||||
if (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));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -367,6 +369,7 @@ $(function() {
|
||||
|
||||
$("#tagSearch").html($li.html()).show();
|
||||
$("#tagSearch .tag-delete").remove();
|
||||
Note.listIsIn(true, false);
|
||||
|
||||
showLoading();
|
||||
ajaxGet("/note/searchNoteByTags", {tags: [tag]}, function(notes) {
|
||||
@ -375,7 +378,7 @@ $(function() {
|
||||
// 和note搜索一样
|
||||
// 设空, 防止发生上述情况
|
||||
// Note.curNoteId = "";
|
||||
|
||||
|
||||
Note.renderNotes(notes);
|
||||
if(!isEmpty(notes)) {
|
||||
Note.changeNote(notes[0].NoteId);
|
||||
@ -387,4 +390,4 @@ $(function() {
|
||||
// $("#minTagNav").on("click", "li", searchTag);
|
||||
|
||||
$("#myTag .folderBody").on("click", "li .tag-delete", deleteTag);
|
||||
});
|
||||
});
|
6
public/js/markdown-v2.min.js
vendored
6
public/js/markdown-v2.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user