@@ -17,16 +17,16 @@
|
|||||||
<link href="/css/font-awesome-4.2.0/css/font-awesome-min.css" rel="stylesheet" />
|
<link href="/css/font-awesome-4.2.0/css/font-awesome-min.css" rel="stylesheet" />
|
||||||
<link href="/css/zTreeStyle/zTreeStyle-min.css" rel="stylesheet" />
|
<link href="/css/zTreeStyle/zTreeStyle-min.css" rel="stylesheet" />
|
||||||
<!-- mdeditor -->
|
<!-- mdeditor -->
|
||||||
<link href="/public/dist/themes/default-min.css" rel="stylesheet" />
|
<link href="/public/dist/themes/default.css" rel="stylesheet" />
|
||||||
<!-- context-menu -->
|
<!-- context-menu -->
|
||||||
<link rel="stylesheet" href="/js/contextmenu/css/contextmenu-min.css" type="text/css" />
|
<link rel="stylesheet" href="/js/contextmenu/css/contextmenu-min.css?id=1" type="text/css" />
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var hash = location.hash;
|
var hash = location.hash;
|
||||||
if(hash.indexOf("writing") >= 0) {
|
if(hash.indexOf("writing") >= 0) {
|
||||||
var files = '<link rel="stylesheet" href="/css/theme/writting-overwrite.css" type="text/css" id="themeLink" />';
|
var files = '<link rel="stylesheet" href="/css/theme/writting-overwrite.css?id=3" type="text/css" id="themeLink" />';
|
||||||
} else {
|
} else {
|
||||||
var files ='<link rel="stylesheet" href="/css/theme/{{if .userInfo.Theme}}{{.userInfo.Theme}}{{else}}default{{end}}.css?t=4" type="text/css" id="themeLink" />';
|
var files ='<link rel="stylesheet" href="/css/theme/{{if .userInfo.Theme}}{{.userInfo.Theme}}{{else}}default{{end}}.css?id=7" type="text/css" id="themeLink" />';
|
||||||
}
|
}
|
||||||
document.write(files);
|
document.write(files);
|
||||||
</script>
|
</script>
|
||||||
@@ -427,6 +427,7 @@ function log(o) {
|
|||||||
|
|
||||||
<!-- 遮罩, 为了resize3Columns用 -->
|
<!-- 遮罩, 为了resize3Columns用 -->
|
||||||
<div id="noteMask" class="note-mask"></div>
|
<div id="noteMask" class="note-mask"></div>
|
||||||
|
<!-- for loading -->
|
||||||
<div id="noteMaskForLoading" class="note-mask"> <!-- z-index: 11 -->
|
<div id="noteMaskForLoading" class="note-mask"> <!-- z-index: 11 -->
|
||||||
<img src="/images/loading-24.gif"/>
|
<img src="/images/loading-24.gif"/>
|
||||||
<br />
|
<br />
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
// 3. 什么时候设置curNoteId? 是ajax得到内容之后设置
|
// 3. 什么时候设置curNoteId? 是ajax得到内容之后设置
|
||||||
|
|
||||||
// note
|
// note
|
||||||
Note.curNoteId = "";
|
Note.curNoteId = '';
|
||||||
|
|
||||||
Note.interval = ""; // 定时器
|
Note.interval = ""; // 定时器
|
||||||
|
|
||||||
@@ -33,22 +33,23 @@ Note.notebookIds = {}; // notebookId => true
|
|||||||
|
|
||||||
Note.isReadOnly = false;
|
Note.isReadOnly = false;
|
||||||
// 定时保存信息
|
// 定时保存信息
|
||||||
Note.intervalTime = 600000; // 600s, 10mins
|
Note.intervalTime = 600 * 000; // 600s, 10mins
|
||||||
|
Note.intervalTime = 10 * 1000; // 10s
|
||||||
Note.startInterval = function() {
|
Note.startInterval = function() {
|
||||||
|
clearInterval(Note.interval);
|
||||||
Note.interval = setInterval(function() {
|
Note.interval = setInterval(function() {
|
||||||
log("自动保存开始...")
|
log("自动保存开始...");
|
||||||
changedNote = Note.curChangedSaveIt(false);
|
Note.curChangedSaveIt();
|
||||||
}, Note.intervalTime); // 600s, 10mins
|
}, Note.intervalTime); // 600s, 10mins
|
||||||
}
|
};
|
||||||
// 停止, 当切换note时
|
// 停止, 当切换note时
|
||||||
// 但过5000后自动启动
|
// 但过5000后自动启动
|
||||||
Note.stopInterval = function() {
|
Note.stopInterval = function() {
|
||||||
clearInterval(Note.interval);
|
clearInterval(Note.interval);
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
Note.startInterval();
|
Note.startInterval();
|
||||||
}, Note.intervalTime);
|
}, Note.intervalTime);
|
||||||
}
|
};
|
||||||
|
|
||||||
// note = {NoteId, Desc, UserId,...}
|
// note = {NoteId, Desc, UserId,...}
|
||||||
Note.addNoteCache = function(note) {
|
Note.addNoteCache = function(note) {
|
||||||
@@ -80,7 +81,7 @@ Note.setCurNoteId = function (noteId) {
|
|||||||
};
|
};
|
||||||
Note.clearCurNoteId = function () {
|
Note.clearCurNoteId = function () {
|
||||||
this.curNoteId = null;
|
this.curNoteId = null;
|
||||||
}
|
};
|
||||||
|
|
||||||
// 得到当前的笔记
|
// 得到当前的笔记
|
||||||
Note.getCurNote = function() {
|
Note.getCurNote = function() {
|
||||||
@@ -93,7 +94,7 @@ Note.getCurNote = function() {
|
|||||||
Note.getNote = function(noteId) {
|
Note.getNote = function(noteId) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return self.cache[noteId];
|
return self.cache[noteId];
|
||||||
}
|
};
|
||||||
|
|
||||||
// 每当有notebookId相应的note改变时都要重新清空之
|
// 每当有notebookId相应的note改变时都要重新清空之
|
||||||
// 并设置该notebookId有值
|
// 并设置该notebookId有值
|
||||||
@@ -103,14 +104,14 @@ Note.clearCacheByNotebookId = function(notebookId) {
|
|||||||
Note.cacheByNotebookId["all"] = {};
|
Note.cacheByNotebookId["all"] = {};
|
||||||
Note.notebookIds[notebookId] = true;
|
Note.notebookIds[notebookId] = true;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// notebook是否有notes
|
// notebook是否有notes
|
||||||
// called by Notebook
|
// called by Notebook
|
||||||
Note.notebookHasNotes = function(notebookId) {
|
Note.notebookHasNotes = function(notebookId) {
|
||||||
var notes = Note.getNotesByNotebookId(notebookId);
|
var notes = Note.getNotesByNotebookId(notebookId);
|
||||||
return !isEmpty(notes);
|
return !isEmpty(notes);
|
||||||
}
|
};
|
||||||
|
|
||||||
// 得到notebook下的notes, 按什么排序 updatedTime?
|
// 得到notebook下的notes, 按什么排序 updatedTime?
|
||||||
Note.getNotesByNotebookId = function(notebookId, sortBy, isAsc) {
|
Note.getNotesByNotebookId = function(notebookId, sortBy, isAsc) {
|
||||||
@@ -176,15 +177,6 @@ Note.getNotesByNotebookId = function(notebookId, sortBy, isAsc) {
|
|||||||
return notes;
|
return notes;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 该笔记点击后已污染
|
|
||||||
Note.curNoteIsDirtied = function() {
|
|
||||||
var me = this;
|
|
||||||
var note = me.getCurNote();
|
|
||||||
if(note) {
|
|
||||||
note.isDirty = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// called by Notebook
|
// called by Notebook
|
||||||
// render 所有notes, 和第一个note的content
|
// render 所有notes, 和第一个note的content
|
||||||
Note.renderNotesAndFirstOneContent = function(ret) {
|
Note.renderNotesAndFirstOneContent = function(ret) {
|
||||||
@@ -204,25 +196,69 @@ Note.renderNotesAndFirstOneContent = function(ret) {
|
|||||||
|
|
||||||
// 当前的note是否改变过了?
|
// 当前的note是否改变过了?
|
||||||
// 返回已改变的信息
|
// 返回已改变的信息
|
||||||
// force bool true表示content比较是比较HTML, 否则比较text, 默认为true
|
//
|
||||||
// 定时保存用false
|
// isDirty()不好判断, 因为富文本编辑器下用快捷键, 插入图片的问题
|
||||||
|
// 所以不用isDirty()
|
||||||
|
// 只用Note.readOnly, 如果Note.readOnly, 那么不判断内容
|
||||||
|
//
|
||||||
Note.curHasChanged = function(force) {
|
Note.curHasChanged = function(force) {
|
||||||
if(force == undefined) {
|
var cacheNote = Note.getCurNote();
|
||||||
force = true;
|
if (!cacheNote) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
var cacheNote = Note.cache[Note.curNoteId] || {};
|
|
||||||
// 收集当前信息, 与cache比对
|
// 收集当前信息, 与cache比对
|
||||||
var title = $("#noteTitle").val();
|
var title = $('#noteTitle').val();
|
||||||
var tags = Tag.getTags(); // TODO
|
var tags = Tag.getTags();
|
||||||
|
|
||||||
|
var hasChanged = {
|
||||||
|
hasChanged: false, // 总的是否有改变
|
||||||
|
IsNew: cacheNote.IsNew, // 是否是新添加的
|
||||||
|
IsMarkdown: cacheNote.IsMarkdown, // 是否是markdown笔记
|
||||||
|
FromUserId: cacheNote.FromUserId, // 是否是共享新建的
|
||||||
|
NoteId: cacheNote.NoteId,
|
||||||
|
NotebookId: cacheNote.NotebookId
|
||||||
|
};
|
||||||
|
|
||||||
|
if (cacheNote.IsNew) {
|
||||||
|
hasChanged.hasChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cacheNote.Title != title) {
|
||||||
|
hasChanged.hasChanged = true; // 本页使用用小写
|
||||||
|
hasChanged.Title = title; // 要传到后台的用大写
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!arrayEqual(cacheNote.Tags, tags)) {
|
||||||
|
hasChanged.hasChanged = true;
|
||||||
|
hasChanged.Tags = tags.join(","); // 为什么? 因为空数组不会传到后台
|
||||||
|
}
|
||||||
|
|
||||||
|
// 是否需要检查内容呢?
|
||||||
|
|
||||||
|
var needCheckContent = false;
|
||||||
|
if (cacheNote.IsNew || force || !Note.readOnly) {
|
||||||
|
needCheckContent = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标题, 标签, 内容都没改变
|
||||||
|
if (!hasChanged.hasChanged && !needCheckContent) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!needCheckContent) {
|
||||||
|
return hasChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
//===========
|
||||||
|
// 内容的比较
|
||||||
|
|
||||||
// 如果是markdown返回[content, preview]
|
// 如果是markdown返回[content, preview]
|
||||||
var contents = getEditorContent(cacheNote.IsMarkdown);
|
var contents = getEditorContent(cacheNote.IsMarkdown);
|
||||||
var content, preview;
|
var content, preview;
|
||||||
var contentText;
|
|
||||||
if (isArray(contents)) {
|
if (isArray(contents)) {
|
||||||
content = contents[0];
|
content = contents[0];
|
||||||
preview = contents[1];
|
preview = contents[1];
|
||||||
contentText = content;
|
|
||||||
// preview可能没来得到及解析
|
// preview可能没来得到及解析
|
||||||
if (content && previewIsEmpty(preview) && Converter) {
|
if (content && previewIsEmpty(preview) && Converter) {
|
||||||
preview = Converter.makeHtml(content);
|
preview = Converter.makeHtml(content);
|
||||||
@@ -233,47 +269,19 @@ Note.curHasChanged = function(force) {
|
|||||||
cacheNote.Preview = preview; // 仅仅缓存在前台
|
cacheNote.Preview = preview; // 仅仅缓存在前台
|
||||||
} else {
|
} else {
|
||||||
content = contents;
|
content = contents;
|
||||||
try {
|
|
||||||
contentText = $(content).text();
|
|
||||||
} catch(e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var hasChanged = {
|
|
||||||
hasChanged: false, // 总的是否有改变
|
|
||||||
IsNew: cacheNote.IsNew, // 是否是新添加的
|
|
||||||
IsMarkdown: cacheNote.IsMarkdown, // 是否是markdown笔记
|
|
||||||
FromUserId: cacheNote.FromUserId, // 是否是共享新建的
|
|
||||||
NoteId: cacheNote.NoteId,
|
|
||||||
NotebookId: cacheNote.NotebookId,
|
|
||||||
Version: cacheNote.Version || 0, // 版本控制
|
|
||||||
};
|
|
||||||
|
|
||||||
if(hasChanged.IsNew) {
|
|
||||||
$.extend(hasChanged, cacheNote);
|
|
||||||
} else {
|
|
||||||
if(!force && !cacheNote.isDirty) {
|
|
||||||
log("no dirty");
|
|
||||||
hasChanged.hasChanged = false;
|
|
||||||
return hasChanged;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cacheNote.Title != title) {
|
|
||||||
hasChanged.hasChanged = true; // 本页使用用小写
|
|
||||||
hasChanged.Title = title; // 要传到后台的用大写
|
|
||||||
if(!hasChanged.Title) {
|
|
||||||
// alert(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!arrayEqual(cacheNote.Tags, tags)) {
|
|
||||||
hasChanged.hasChanged = true;
|
|
||||||
hasChanged.Tags = tags.join(","); // 为什么? 因为空数组不会传到后台
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 比较text, 因为note Nav会添加dom会导致content改变
|
// 比较text, 因为note Nav会添加dom会导致content改变
|
||||||
if((force && cacheNote.Content != content) || (!force && (/**/(!cacheNote.IsMarkdown && $(cacheNote.Content).text() != contentText) || (cacheNote.IsMarkdown && cacheNote.Content != contentText)) /**/) ) {
|
/*
|
||||||
|
if((force && cacheNote.Content != content)
|
||||||
|
|| (!force && (
|
||||||
|
(!cacheNote.IsMarkdown && $(cacheNote.Content).text() != contentText)
|
||||||
|
|| (cacheNote.IsMarkdown && cacheNote.Content != contentText)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
*/
|
||||||
|
if (cacheNote.Content != content) {
|
||||||
hasChanged.hasChanged = true;
|
hasChanged.hasChanged = true;
|
||||||
hasChanged.Content = content;
|
hasChanged.Content = content;
|
||||||
|
|
||||||
@@ -288,13 +296,13 @@ Note.curHasChanged = function(force) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log("text相同");
|
log("text相同");
|
||||||
log(cacheNote.Content == content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hasChanged["UserId"] = cacheNote["UserId"] || "";
|
if (hasChanged.hasChanged) {
|
||||||
|
return hasChanged;
|
||||||
return hasChanged;
|
}
|
||||||
}
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
// 由content生成desc
|
// 由content生成desc
|
||||||
// 换行不要替换
|
// 换行不要替换
|
||||||
@@ -406,13 +414,22 @@ Note.savePool = {}; // 保存池, 以后的保存先放在pool中, id => note
|
|||||||
Note.curChangedSaveIt = function(force, callback) {
|
Note.curChangedSaveIt = function(force, callback) {
|
||||||
var me = this;
|
var me = this;
|
||||||
// 如果当前没有笔记, 不保存
|
// 如果当前没有笔记, 不保存
|
||||||
|
// 或者是共享的只读笔记
|
||||||
if(!Note.curNoteId || Note.isReadOnly) {
|
if(!Note.curNoteId || Note.isReadOnly) {
|
||||||
|
log(!Note.curNoteId ? '无当前笔记' : '共享只读');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var hasChanged;
|
||||||
|
try {
|
||||||
|
hasChanged = Note.curHasChanged(force);
|
||||||
|
} catch(e) {
|
||||||
|
console.error('获取当前改变的笔记错误!');
|
||||||
|
callback && callback(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasChanged = Note.curHasChanged(force);
|
if(hasChanged && hasChanged.hasChanged) {
|
||||||
|
log('需要保存...');
|
||||||
if(hasChanged.hasChanged || hasChanged.IsNew) {
|
|
||||||
// 把已改变的渲染到左边 item-list
|
// 把已改变的渲染到左边 item-list
|
||||||
Note.renderChangedNote(hasChanged);
|
Note.renderChangedNote(hasChanged);
|
||||||
delete hasChanged.hasChanged;
|
delete hasChanged.hasChanged;
|
||||||
@@ -456,6 +473,10 @@ Note.curChangedSaveIt = function(force, callback) {
|
|||||||
|
|
||||||
return hasChanged;
|
return hasChanged;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
log('无需保存');
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -613,7 +634,7 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. 设空, 防止在内容得到之前又发生保存
|
// 2. 设空, 防止在内容得到之前又发生保存
|
||||||
Note.curNoteId = "";
|
Note.clearCurNoteId();
|
||||||
|
|
||||||
// 2 得到现在的
|
// 2 得到现在的
|
||||||
// ajax之
|
// ajax之
|
||||||
@@ -648,9 +669,10 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged, callback) {
|
|||||||
|
|
||||||
Note.contentAjaxSeq++;
|
Note.contentAjaxSeq++;
|
||||||
var seq = Note.contentAjaxSeq;
|
var seq = Note.contentAjaxSeq;
|
||||||
function setContent(ret) {
|
|
||||||
|
function setContent(ret, seq2) {
|
||||||
Note.contentAjax = null;
|
Note.contentAjax = null;
|
||||||
if(seq != Note.contentAjaxSeq) {
|
if(seq2 != Note.contentAjaxSeq) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Note.setNoteCache(ret, false);
|
Note.setNoteCache(ret, false);
|
||||||
@@ -658,20 +680,14 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged, callback) {
|
|||||||
// 把其它信息也带上
|
// 把其它信息也带上
|
||||||
ret = Note.cache[selectNoteId]
|
ret = Note.cache[selectNoteId]
|
||||||
Note.renderNoteContent(ret);
|
Note.renderNoteContent(ret);
|
||||||
/* 都用editable的render
|
|
||||||
if(hasPerm) {
|
|
||||||
Note.renderNoteContent(ret);
|
|
||||||
} else {
|
|
||||||
Note.renderNoteContentReadOnly(ret);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
self.hideContentLoading();
|
self.hideContentLoading();
|
||||||
|
|
||||||
callback && callback(ret);
|
callback && callback(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cacheNote.Content) {
|
if(cacheNote.Content) {
|
||||||
setContent(cacheNote);
|
setContent(cacheNote, seq);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -686,12 +702,14 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged, callback) {
|
|||||||
if(Note.contentAjax != null) {
|
if(Note.contentAjax != null) {
|
||||||
Note.contentAjax.abort();
|
Note.contentAjax.abort();
|
||||||
}
|
}
|
||||||
Note.contentAjax = ajaxGet(url, param, function (ret) {
|
Note.contentAjax = ajaxGet(url, param, (function (seq2) {
|
||||||
// 因为之前Content内的IsBlog和Note的IsBlog不同步, 所以去掉Content中的IsBlog
|
return function (ret) {
|
||||||
delete ret['IsBlog'];
|
// 因为之前Content内的IsBlog和Note的IsBlog不同步, 所以去掉Content中的IsBlog
|
||||||
setContent(ret);
|
delete ret['IsBlog'];
|
||||||
});
|
setContent(ret, seq2);
|
||||||
}
|
}
|
||||||
|
})(seq));
|
||||||
|
};
|
||||||
|
|
||||||
// 渲染
|
// 渲染
|
||||||
|
|
||||||
@@ -725,12 +743,12 @@ Note.renderChangedNote = function(changedNote) {
|
|||||||
$leftNoteNav.find(".item-thumb").remove(); // 以前有, 现在没有了
|
$leftNoteNav.find(".item-thumb").remove(); // 以前有, 现在没有了
|
||||||
$leftNoteNav.removeClass("item-image");
|
$leftNoteNav.removeClass("item-image");
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// 清空右侧note信息, 可能是共享的,
|
// 清空右侧note信息, 可能是共享的,
|
||||||
// 此时需要清空只读的, 且切换到note edit模式下
|
// 此时需要清空只读的, 且切换到note edit模式下
|
||||||
Note.clearNoteInfo = function() {
|
Note.clearNoteInfo = function() {
|
||||||
Note.curNoteId = "";
|
Note.clearCurNoteId();
|
||||||
Tag.clearTags();
|
Tag.clearTags();
|
||||||
$("#noteTitle").val("");
|
$("#noteTitle").val("");
|
||||||
setEditorContent("");
|
setEditorContent("");
|
||||||
@@ -743,20 +761,21 @@ Note.clearNoteInfo = function() {
|
|||||||
|
|
||||||
// 只隐藏即可
|
// 只隐藏即可
|
||||||
$("#noteRead").hide();
|
$("#noteRead").hide();
|
||||||
}
|
};
|
||||||
|
|
||||||
// 清除noteList导航
|
// 清除noteList导航
|
||||||
Note.clearNoteList = function() {
|
Note.clearNoteList = function() {
|
||||||
Note.noteItemListO.html(""); // 清空
|
Note.noteItemListO.html(""); // 清空
|
||||||
}
|
};
|
||||||
|
|
||||||
// 清空所有, 在转换notebook时使用
|
// 清空所有, 在转换notebook时使用
|
||||||
Note.clearAll = function() {
|
Note.clearAll = function() {
|
||||||
// 当前的笔记清空掉
|
// 当前的笔记清空掉
|
||||||
Note.curNoteId = "";
|
Note.clearCurNoteId();
|
||||||
|
|
||||||
Note.clearNoteInfo();
|
Note.clearNoteInfo();
|
||||||
Note.clearNoteList();
|
Note.clearNoteList();
|
||||||
}
|
};
|
||||||
|
|
||||||
Note.renderNote = function(note) {
|
Note.renderNote = function(note) {
|
||||||
if(!note) {
|
if(!note) {
|
||||||
@@ -769,20 +788,19 @@ Note.renderNote = function(note) {
|
|||||||
// 当前正在编辑的
|
// 当前正在编辑的
|
||||||
// tags
|
// tags
|
||||||
Tag.renderTags(note.Tags);
|
Tag.renderTags(note.Tags);
|
||||||
|
};
|
||||||
// 笔记是新render的, 没有污染过
|
|
||||||
note.isDirty = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// render content
|
// render content
|
||||||
Note.renderNoteContent = function(content) {
|
Note.renderNoteContent = function(content) {
|
||||||
|
|
||||||
setEditorContent(content.Content, content.IsMarkdown, content.Preview, function() {
|
setEditorContent(content.Content, content.IsMarkdown, content.Preview, function() {
|
||||||
Note.curNoteId = content.NoteId;
|
Note.setCurNoteId(content.NoteId);
|
||||||
Note.toggleReadOnly();
|
Note.toggleReadOnly();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 只有在renderNoteContent时才设置curNoteId
|
// 只有在renderNoteContent时才设置curNoteId
|
||||||
Note.curNoteId = content.NoteId;
|
// Note.curNoteId = content.NoteId;
|
||||||
}
|
};
|
||||||
|
|
||||||
// 初始化时渲染最初的notes
|
// 初始化时渲染最初的notes
|
||||||
/**
|
/**
|
||||||
@@ -813,10 +831,10 @@ Note.showEditorMask = function() {
|
|||||||
$("#editorMaskBtns").show();
|
$("#editorMaskBtns").show();
|
||||||
$("#editorMaskBtnsEmpty").hide();
|
$("#editorMaskBtnsEmpty").hide();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
Note.hideEditorMask = function() {
|
Note.hideEditorMask = function() {
|
||||||
$("#editorMask").css("z-index", -10).hide();
|
$("#editorMask").css("z-index", -10).hide();
|
||||||
}
|
};
|
||||||
|
|
||||||
// 这里如果notes过多>100个将会很慢!!, 使用setTimeout来分解
|
// 这里如果notes过多>100个将会很慢!!, 使用setTimeout来分解
|
||||||
Note.renderNotesC = 0;
|
Note.renderNotesC = 0;
|
||||||
@@ -878,7 +896,7 @@ Note.renderNotes = function(notes, forNewNote, isShared) {
|
|||||||
}
|
}
|
||||||
})(i), i*2000);
|
})(i), i*2000);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
Note._renderNotes = function(notes, forNewNote, isShared, tang) { // 第几趟
|
Note._renderNotes = function(notes, forNewNote, isShared, tang) { // 第几趟
|
||||||
var len = notes.length;
|
var len = notes.length;
|
||||||
for(var i = (tang-1)*20; i < len && i < tang*20; ++i) {
|
for(var i = (tang-1)*20; i < len && i < tang*20; ++i) {
|
||||||
@@ -949,6 +967,8 @@ Note.newNote = function(notebookId, isShare, fromUserId, isMarkdown) {
|
|||||||
Note.stopInterval();
|
Note.stopInterval();
|
||||||
// 保存当前的笔记
|
// 保存当前的笔记
|
||||||
Note.curChangedSaveIt();
|
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}; // 是新的
|
||||||
// 添加到缓存中
|
// 添加到缓存中
|
||||||
@@ -1006,25 +1026,13 @@ Note.newNote = function(notebookId, isShare, fromUserId, isMarkdown) {
|
|||||||
|
|
||||||
Note.renderNote(note);
|
Note.renderNote(note);
|
||||||
Note.renderNoteContent(note);
|
Note.renderNoteContent(note);
|
||||||
Note.curNoteId = note.NoteId;
|
Note.setCurNoteId(note.NoteId);
|
||||||
|
|
||||||
// 更新数量
|
// 更新数量
|
||||||
Notebook.incrNotebookNumberNotes(notebookId)
|
Notebook.incrNotebookNumberNotes(notebookId)
|
||||||
|
|
||||||
// 切换到写模式
|
// 切换到写模式
|
||||||
Note.toggleWriteable();
|
Note.toggleWriteable();
|
||||||
}
|
|
||||||
|
|
||||||
// 保存note ctrl + s
|
|
||||||
Note.saveNote = function(e) {
|
|
||||||
var num = e.which ? e.which : e.keyCode;
|
|
||||||
// 保存
|
|
||||||
if((e.ctrlKey || e.metaKey) && num == 83 ) { // ctrl + s or command + s
|
|
||||||
Note.curChangedSaveIt();
|
|
||||||
e.preventDefault();
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 删除或移动笔记后, 渲染下一个或上一个
|
// 删除或移动笔记后, 渲染下一个或上一个
|
||||||
@@ -1162,7 +1170,7 @@ Note.deleteNote = function(target, contextmenuItem, isShared) {
|
|||||||
Note.listNoteShareUserInfo = function(target) {
|
Note.listNoteShareUserInfo = function(target) {
|
||||||
var noteId = $(target).attr("noteId");
|
var noteId = $(target).attr("noteId");
|
||||||
showDialogRemote("/share/listNoteShareUserInfo", {noteId: noteId});
|
showDialogRemote("/share/listNoteShareUserInfo", {noteId: noteId});
|
||||||
}
|
};
|
||||||
|
|
||||||
// 共享笔记
|
// 共享笔记
|
||||||
Note.shareNote = function(target) {
|
Note.shareNote = function(target) {
|
||||||
@@ -1200,12 +1208,12 @@ Note.showReadOnly = function() {
|
|||||||
// $("#noteRead").show();
|
// $("#noteRead").show();
|
||||||
|
|
||||||
$('#note').addClass('read-only');
|
$('#note').addClass('read-only');
|
||||||
}
|
};
|
||||||
Note.hideReadOnly = function() {
|
Note.hideReadOnly = function() {
|
||||||
Note.isReadOnly = false;
|
Note.isReadOnly = false;
|
||||||
$('#note').removeClass('read-only');
|
$('#note').removeClass('read-only');
|
||||||
$("#noteRead").hide();
|
$("#noteRead").hide();
|
||||||
}
|
};
|
||||||
// read only
|
// read only
|
||||||
Note.renderNoteReadOnly = function(note) {
|
Note.renderNoteReadOnly = function(note) {
|
||||||
Note.showReadOnly();
|
Note.showReadOnly();
|
||||||
@@ -1215,9 +1223,7 @@ Note.renderNoteReadOnly = function(note) {
|
|||||||
|
|
||||||
$("#noteReadCreatedTime").html(goNowToDatetime(note.CreatedTime));
|
$("#noteReadCreatedTime").html(goNowToDatetime(note.CreatedTime));
|
||||||
$("#noteReadUpdatedTime").html(goNowToDatetime(note.UpdatedTime));
|
$("#noteReadUpdatedTime").html(goNowToDatetime(note.UpdatedTime));
|
||||||
}
|
};
|
||||||
Note.renderNoteContentReadOnly = function(note) {
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------
|
//---------------------------
|
||||||
// 搜索
|
// 搜索
|
||||||
@@ -1245,7 +1251,7 @@ Note.isSameSearch = function(key) {
|
|||||||
Note.lastSearchTime = now;
|
Note.lastSearchTime = now;
|
||||||
Note.lastKey = key;
|
Note.lastKey = key;
|
||||||
return false;
|
return false;
|
||||||
}
|
};
|
||||||
|
|
||||||
Note.searchNote = function() {
|
Note.searchNote = function() {
|
||||||
var val = $("#searchNoteInput").val();
|
var val = $("#searchNoteInput").val();
|
||||||
@@ -1287,7 +1293,7 @@ Note.searchNote = function() {
|
|||||||
// 不是这个原因, 下面的Note.changeNote会导致保存
|
// 不是这个原因, 下面的Note.changeNote会导致保存
|
||||||
|
|
||||||
// 设空, 防止发生上述情况
|
// 设空, 防止发生上述情况
|
||||||
// Note.curNoteId = "";
|
// Note.clearCurNoteId();
|
||||||
|
|
||||||
Note.renderNotes(notes);
|
Note.renderNotes(notes);
|
||||||
if(!isEmpty(notes)) {
|
if(!isEmpty(notes)) {
|
||||||
@@ -1298,7 +1304,7 @@ Note.searchNote = function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Note.lastSearch.abort();
|
// Note.lastSearch.abort();
|
||||||
}
|
};
|
||||||
|
|
||||||
Note.$itemList = $('#noteItemList');
|
Note.$itemList = $('#noteItemList');
|
||||||
Note.getTargetById = function(noteId) {
|
Note.getTargetById = function(noteId) {
|
||||||
@@ -1654,7 +1660,7 @@ Note.getContextNotebooks = function(notebooks) {
|
|||||||
copys2.push(copy2);
|
copys2.push(copy2);
|
||||||
}
|
}
|
||||||
return [moves, copys, copys2];
|
return [moves, copys, copys2];
|
||||||
}
|
};
|
||||||
// Notebook调用
|
// Notebook调用
|
||||||
Note.contextmenu = null;
|
Note.contextmenu = null;
|
||||||
Note.notebooksCopy = []; // share会用到
|
Note.notebooksCopy = []; // share会用到
|
||||||
@@ -1762,7 +1768,7 @@ Note.initContextmenu = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Note.contextmenu = $("#noteItemList .item-my").contextmenu(noteListMenu);
|
Note.contextmenu = $("#noteItemList .item-my").contextmenu(noteListMenu);
|
||||||
}
|
};
|
||||||
|
|
||||||
// 附件
|
// 附件
|
||||||
// 笔记的附件需要ajax获取
|
// 笔记的附件需要ajax获取
|
||||||
@@ -1816,7 +1822,7 @@ var Attach = {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
var attachId = $(this).closest('li').data("id");
|
var attachId = $(this).closest('li').data("id");
|
||||||
var attach = self.attachsMap[attachId];
|
var attach = self.attachsMap[attachId];
|
||||||
var src = UrlPrefix + "/attach/download?attachId=" + attachId;
|
var src = UrlPrefix + "/api/file/getAttach?fileId=" + attachId;
|
||||||
Note.toggleWriteable();
|
Note.toggleWriteable();
|
||||||
if(LEA.isMarkdownEditor() && MD) {
|
if(LEA.isMarkdownEditor() && MD) {
|
||||||
MD.insertLink(src, attach.Title);
|
MD.insertLink(src, attach.Title);
|
||||||
@@ -1986,9 +1992,11 @@ Note.batch = {
|
|||||||
|
|
||||||
cancelInBatch: function () {
|
cancelInBatch: function () {
|
||||||
Note.inBatch = false;
|
Note.inBatch = false;
|
||||||
|
this.$body.removeClass('batch');
|
||||||
},
|
},
|
||||||
setInBatch: function () {
|
setInBatch: function () {
|
||||||
Note.inBatch = true;
|
Note.inBatch = true;
|
||||||
|
this.$body.addClass('batch');
|
||||||
},
|
},
|
||||||
|
|
||||||
// 是否是多选, 至少选了2个
|
// 是否是多选, 至少选了2个
|
||||||
@@ -2001,8 +2009,6 @@ Note.batch = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 得到开始的笔记
|
// 得到开始的笔记
|
||||||
_startNoteO: null, // 开始选择的笔记
|
_startNoteO: null, // 开始选择的笔记
|
||||||
getStartNoteO: function () {
|
getStartNoteO: function () {
|
||||||
@@ -2145,7 +2151,6 @@ Note.batch = {
|
|||||||
//----------
|
//----------
|
||||||
// 多选操作
|
// 多选操作
|
||||||
//----------
|
//----------
|
||||||
|
|
||||||
if (isMulti || isConti) {
|
if (isMulti || isConti) {
|
||||||
Note.curChangedSaveIt();
|
Note.curChangedSaveIt();
|
||||||
}
|
}
|
||||||
@@ -2267,15 +2272,11 @@ Note.batch = {
|
|||||||
if (me.isInBatch()) {
|
if (me.isInBatch()) {
|
||||||
// 清空当前笔记, 不让自动保存
|
// 清空当前笔记, 不让自动保存
|
||||||
Note.clearCurNoteId();
|
Note.clearCurNoteId();
|
||||||
|
|
||||||
me.$body.addClass('batch');
|
|
||||||
me.renderBatchNotes();
|
me.renderBatchNotes();
|
||||||
|
|
||||||
me.setInBatch();
|
me.setInBatch();
|
||||||
|
|
||||||
// 单个处理
|
// 单个处理
|
||||||
} else {
|
} else {
|
||||||
me.$body.removeClass('batch');
|
|
||||||
me.clearRender();
|
me.clearRender();
|
||||||
me.cancelInBatch();
|
me.cancelInBatch();
|
||||||
|
|
||||||
@@ -2397,16 +2398,6 @@ $(function() {
|
|||||||
|
|
||||||
Note.batch.init();
|
Note.batch.init();
|
||||||
|
|
||||||
// 当前笔记可以已修改
|
|
||||||
$('#editorContent, #wmd-input, #noteTitle').on('keyup input', function() {
|
|
||||||
Note.curNoteIsDirtied();
|
|
||||||
});
|
|
||||||
/*
|
|
||||||
$('#addTagInput').click(function() {
|
|
||||||
Note.curNoteIsDirtied();
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
//------------------
|
//------------------
|
||||||
// 新建笔记
|
// 新建笔记
|
||||||
// 1. 直接点击新建 OR
|
// 1. 直接点击新建 OR
|
||||||
@@ -2459,6 +2450,7 @@ $(function() {
|
|||||||
// Note.initContextmenu();
|
// Note.initContextmenu();
|
||||||
|
|
||||||
$("#saveBtn").click(function() {
|
$("#saveBtn").click(function() {
|
||||||
|
// 只有在这里, 才会force
|
||||||
Note.curChangedSaveIt(true);
|
Note.curChangedSaveIt(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2496,7 +2488,22 @@ $(function() {
|
|||||||
$('.toolbar-update').click(function() {
|
$('.toolbar-update').click(function() {
|
||||||
Note.toggleWriteable();
|
Note.toggleWriteable();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
// 笔记内容里的链接跳转
|
||||||
|
$('#editorContent').on('click', 'a', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (Note.readOnly) {
|
||||||
|
var href = $(this).attr('href');
|
||||||
|
window.open(href);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('#preview-contents').on('click', 'a', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var href = $(this).attr('href');
|
||||||
|
window.open(href);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 定时器启动
|
// 定时器启动
|
||||||
Note.startInterval();
|
Note.startInterval();
|
||||||
@@ -558,7 +558,7 @@ function initEditor() {
|
|||||||
|
|
||||||
// 刷新时保存 参考autosave插件
|
// 刷新时保存 参考autosave插件
|
||||||
window.onbeforeunload = function(e) {
|
window.onbeforeunload = function(e) {
|
||||||
Note.curChangedSaveIt();
|
Note.curChangedSaveIt(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 全局快捷键
|
// 全局快捷键
|
||||||
|
|||||||
@@ -172,8 +172,6 @@ Tag.appendTag = function(tag, save) {
|
|||||||
|
|
||||||
// 笔记已污染
|
// 笔记已污染
|
||||||
if(save) {
|
if(save) {
|
||||||
Note.curNoteIsDirtied();
|
|
||||||
|
|
||||||
// 如果之前不存, 则添加之
|
// 如果之前不存, 则添加之
|
||||||
if(!isExists) {
|
if(!isExists) {
|
||||||
Note.curChangedSaveIt(true, function() {
|
Note.curChangedSaveIt(true, function() {
|
||||||
@@ -373,4 +371,4 @@ $(function() {
|
|||||||
// $("#minTagNav").on("click", "li", searchTag);
|
// $("#minTagNav").on("click", "li", searchTag);
|
||||||
|
|
||||||
$("#myTag .folderBody").on("click", "li .tag-delete", deleteTag);
|
$("#myTag .folderBody").on("click", "li .tag-delete", deleteTag);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -204,7 +204,6 @@ function formSerializeDataToJson(formSerializeData) {
|
|||||||
return $.extend(datas, arrObj);
|
return $.extend(datas, arrObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ajax请求返回结果后的操作
|
// ajax请求返回结果后的操作
|
||||||
// 用于ajaxGet(), ajaxPost()
|
// 用于ajaxGet(), ajaxPost()
|
||||||
function _ajaxCallback(ret, successFunc, failureFunc) {
|
function _ajaxCallback(ret, successFunc, failureFunc) {
|
||||||
@@ -229,9 +228,9 @@ function _ajaxCallback(ret, successFunc, failureFunc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
function _ajax(type, url, param, successFunc, failureFunc, async) {
|
function _ajax(type, url, param, successFunc, failureFunc, async) {
|
||||||
log("-------------------ajax:");
|
// log("-------------------ajax:");
|
||||||
log(url);
|
// log(url);
|
||||||
log(param);
|
// log(param);
|
||||||
if(typeof async == "undefined") {
|
if(typeof async == "undefined") {
|
||||||
async = true;
|
async = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -279,9 +278,9 @@ function ajaxPost(url, param, successFunc, failureFunc, async) {
|
|||||||
_ajax("POST", url, param, successFunc, failureFunc, async);
|
_ajax("POST", url, param, successFunc, failureFunc, async);
|
||||||
}
|
}
|
||||||
function ajaxPostJson(url, param, successFunc, failureFunc, async) {
|
function ajaxPostJson(url, param, successFunc, failureFunc, async) {
|
||||||
log("-------------------ajaxPostJson:");
|
// log("-------------------ajaxPostJson:");
|
||||||
log(url);
|
// log(url);
|
||||||
log(param);
|
// log(param);
|
||||||
|
|
||||||
// 默认是异步的
|
// 默认是异步的
|
||||||
if(typeof async == "undefined") {
|
if(typeof async == "undefined") {
|
||||||
@@ -696,6 +695,13 @@ function goNowToDatetime(goNow) {
|
|||||||
if(!goNow) {
|
if(!goNow) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
if (typeof goNow == 'object') {
|
||||||
|
try {
|
||||||
|
return goNow.format("yyyy-M-d hh:mm:ss");
|
||||||
|
} catch(e) {
|
||||||
|
return getCurDate();
|
||||||
|
}
|
||||||
|
}
|
||||||
return goNow.substr(0, 10) + " " + goNow.substr(11, 8);
|
return goNow.substr(0, 10) + " " + goNow.substr(11, 8);
|
||||||
}
|
}
|
||||||
function getCurDate() {
|
function getCurDate() {
|
||||||
|
|||||||
Reference in New Issue
Block a user