js 优化
* 标题按tab切换到内容 * 左侧最小化用css控制 * resize markdown editor v2 * Ace剪切导致行数减少 * 删除不要的代码
This commit is contained in:
@ -1019,20 +1019,20 @@ Note.newNote = function(notebookId, isShare, fromUserId, isMarkdown) {
|
||||
// 插入到第一个位置
|
||||
Note.noteItemListO.prepend(newItem);
|
||||
}
|
||||
|
||||
|
||||
Note.selectTarget($(tt('[noteId="?"]', note.NoteId)));
|
||||
|
||||
|
||||
$("#noteTitle").focus();
|
||||
|
||||
Note.renderNote(note);
|
||||
Note.renderNoteContent(note);
|
||||
Note.setCurNoteId(note.NoteId);
|
||||
|
||||
|
||||
// 更新数量
|
||||
Notebook.incrNotebookNumberNotes(notebookId)
|
||||
|
||||
// 切换到写模式
|
||||
Note.toggleWriteable();
|
||||
Note.toggleWriteable(true);
|
||||
};
|
||||
|
||||
// 删除或移动笔记后, 渲染下一个或上一个
|
||||
@ -1589,7 +1589,7 @@ Note.toggleReadOnly = function(needSave) {
|
||||
}
|
||||
};
|
||||
// 切换到编辑模式
|
||||
LEA.toggleWriteable = Note.toggleWriteable = function() {
|
||||
LEA.toggleWriteable = Note.toggleWriteable = function(isFromNewNote) {
|
||||
var me = Note;
|
||||
|
||||
// $('#infoToolbar').hide();
|
||||
@ -1612,9 +1612,11 @@ LEA.toggleWriteable = Note.toggleWriteable = function() {
|
||||
$('#editorContent pre').each(function() {
|
||||
LeaAce.setAceReadOnly($(this), false);
|
||||
});
|
||||
isFromNewNote || tinymce.activeEditor.focus();
|
||||
}
|
||||
else {
|
||||
if(MD) {
|
||||
isFromNewNote || MD.focus();
|
||||
MD.onResize();
|
||||
}
|
||||
}
|
||||
@ -2429,6 +2431,17 @@ $(function() {
|
||||
var key = $(this).val();
|
||||
Notebook.searchNotebookForList(key);
|
||||
});
|
||||
|
||||
// note title 里按tab, 切换到编辑区
|
||||
$('#noteTitle').on("keydown", function(e) {
|
||||
var keyCode = e.keyCode || e.witch;
|
||||
// tab
|
||||
if (keyCode == 9) {
|
||||
// 一举两得, 即切换到了writable, 又focus了
|
||||
Note.toggleWriteable();
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
//---------------------------
|
||||
// 搜索, 按enter才搜索
|
||||
@ -2438,17 +2451,14 @@ $(function() {
|
||||
});
|
||||
*/
|
||||
$("#searchNoteInput").on("keydown", function(e) {
|
||||
var theEvent = e; // window.event || arguments.callee.caller.arguments[0];
|
||||
if(theEvent.keyCode == 13 || theEvent.keyCode == 108) {
|
||||
theEvent.preventDefault();
|
||||
var keyCode = e.keyCode || e.witch;
|
||||
if(keyCode == 13 || keyCode == 108) {
|
||||
e.preventDefault();
|
||||
Note.searchNote();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
//--------------------
|
||||
// Note.initContextmenu();
|
||||
|
||||
$("#saveBtn").click(function() {
|
||||
// 只有在这里, 才会force
|
||||
Note.curChangedSaveIt(true);
|
||||
@ -2492,18 +2502,26 @@ $(function() {
|
||||
//
|
||||
// 笔记内容里的链接跳转
|
||||
$('#editorContent').on('click', 'a', function (e) {
|
||||
e.preventDefault();
|
||||
if (Note.readOnly) {
|
||||
var href = $(this).attr('href');
|
||||
// 是一个hash
|
||||
if (href && href[0] == '#') {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
window.open(href);
|
||||
}
|
||||
});
|
||||
$('#preview-contents').on('click', 'a', function (e) {
|
||||
e.preventDefault();
|
||||
var href = $(this).attr('href');
|
||||
// 是一个hash
|
||||
if (href && href[0] == '#') {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
window.open(href);
|
||||
});
|
||||
});
|
||||
|
||||
// 定时器启动
|
||||
Note.startInterval();
|
||||
Note.startInterval();
|
||||
|
@ -295,13 +295,20 @@ var Resize = {
|
||||
resizeEditor();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
resizeMDInterval: null,
|
||||
// mdeditor
|
||||
resizeMdColumns: function(event) {
|
||||
var self = this;
|
||||
if (self.mdLineMove) {
|
||||
var mdEditorWidth = event.clientX - self.leftColumn.offset().left; // self.leftNotebook.width() - self.noteList.width();
|
||||
self.setMdColumnWidth(mdEditorWidth);
|
||||
|
||||
clearInterval(self.resizeMDInterval);
|
||||
|
||||
self.resizeMDInterval = setTimeout(function () {
|
||||
MD.aceEditor && MD.aceEditor.resize();
|
||||
}, 50);
|
||||
}
|
||||
},
|
||||
// 设置宽度
|
||||
@ -493,10 +500,20 @@ function initEditor() {
|
||||
});
|
||||
|
||||
// 为了把下拉菜单关闭
|
||||
/*
|
||||
ed.on("click", function(e) {
|
||||
// $("body").trigger("click");
|
||||
// console.log(tinymce.activeEditor.selection.getNode());
|
||||
});
|
||||
*/
|
||||
|
||||
// electron下有问题, Ace剪切导致行数减少, #16
|
||||
ed.on('cut', function(e) {
|
||||
if($(e.target).hasClass('ace_text-input')) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// fix TinyMCE Removes site base url
|
||||
@ -506,10 +523,9 @@ function initEditor() {
|
||||
remove_script_host:false,
|
||||
|
||||
selector : "#editorContent",
|
||||
// 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 不再需要
|
||||
// content_css : [LEA.sPath + "/css/editor/editor.css"], // .concat(em.getWritingCss()),
|
||||
skin : "custom",
|
||||
language: LEA.locale, // 语言
|
||||
plugins : [
|
||||
@ -674,23 +690,11 @@ function scrollTo(self, tagName, text) {
|
||||
}
|
||||
});
|
||||
|
||||
// 打开设置
|
||||
function openSetInfoDialog(whichTab) {
|
||||
showDialogRemote("/user/account", {tab: whichTab});
|
||||
}
|
||||
// 帐号设置
|
||||
$("#setInfo").click(function() {
|
||||
openSetInfoDialog(0);
|
||||
});
|
||||
// 邮箱验证
|
||||
$("#wrongEmail").click(function() {
|
||||
openSetInfoDialog(1);
|
||||
});
|
||||
|
||||
$("#setAvatarMenu").click(function() {
|
||||
showDialog2("#avatarDialog", {title: "头像设置", postShow: function() {
|
||||
}});
|
||||
});
|
||||
$("#setTheme").click(function() {
|
||||
showDialog2("#setThemeDialog", {title: "主题设置", postShow: function() {
|
||||
if (!UserInfo.Theme) {
|
||||
@ -717,14 +721,7 @@ function scrollTo(self, tagName, text) {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//-------------
|
||||
// 邮箱验证
|
||||
if(!UserInfo.Verified) {
|
||||
// $("#leanoteMsg").hide();
|
||||
// $("#verifyMsg").show();
|
||||
}
|
||||
|
||||
|
||||
// 禁止双击选中文字
|
||||
$("#notebook, #newMyNote, #myProfile, #topNav, #notesAndSort", "#leanoteNavTrigger").bind("selectstart", function(e) {
|
||||
e.preventDefault();
|
||||
@ -735,39 +732,21 @@ function scrollTo(self, tagName, text) {
|
||||
function updateLeftIsMin(is) {
|
||||
ajaxGet("/user/updateLeftIsMin", {leftIsMin: is})
|
||||
}
|
||||
|
||||
// 最小化左侧
|
||||
var $page = $('#page');
|
||||
function minLeft(save) {
|
||||
$("#leftNotebook").width(30);
|
||||
$("#notebook").hide();
|
||||
// 左侧
|
||||
$("#noteAndEditor").css("left", 30)
|
||||
$("#notebookSplitter").hide();
|
||||
|
||||
// $("#leftSwitcher").removeClass("fa-angle-left").addClass("fa-angle-right");
|
||||
|
||||
// logo
|
||||
$("#logo").hide();
|
||||
$("#leftSwitcher").hide();
|
||||
$("#leftSwitcher2").show();
|
||||
$("#leftNotebook .slimScrollDiv").hide();
|
||||
|
||||
$page.addClass('mini-left');
|
||||
if(save) {
|
||||
updateLeftIsMin(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 展开右侧
|
||||
function maxLeft(save) {
|
||||
$page.removeClass('mini-left');
|
||||
$("#noteAndEditor").css("left", UserInfo.NotebookWidth);
|
||||
$("#leftNotebook").width(UserInfo.NotebookWidth);
|
||||
$("#notebook").show();
|
||||
$("#notebookSplitter").show();
|
||||
|
||||
// $("#leftSwitcher").removeClass("fa-angle-right").addClass("fa-angle-left");
|
||||
|
||||
$("#leftSwitcher2").hide();
|
||||
$("#logo").show();
|
||||
$("#leftSwitcher").show();
|
||||
$("#leftNotebook .slimScrollDiv").show();
|
||||
|
||||
if(save) {
|
||||
updateLeftIsMin(false);
|
||||
}
|
||||
@ -948,7 +927,7 @@ var Pjax = {
|
||||
var title = noteInfo.Title;
|
||||
var url = '/note/' + noteId;
|
||||
if (location.href.indexOf('?online') > 0) {
|
||||
url += '?online=1'
|
||||
url += '?online=' + /online=([0-9])/.exec(location.href)[1];
|
||||
}
|
||||
if(location.hash) {
|
||||
url += location.hash;
|
||||
@ -1043,7 +1022,9 @@ LeaAce = {
|
||||
b = brush.split(':')[1];
|
||||
} catch(e) {}
|
||||
}
|
||||
b = b || "javascript";
|
||||
if (!b || b === 'false') {
|
||||
b = 'javascript';
|
||||
}
|
||||
aceEditor.session.setMode("ace/mode/" + b);
|
||||
aceEditor.session.setOption("useWorker", false); // 不用语法检查
|
||||
// retina
|
||||
|
Reference in New Issue
Block a user