From 1242834b7fc993ef248f27e540d7063f5e6b24f1 Mon Sep 17 00:00:00 2001 From: lealife <lifephp@gmail.com> Date: Fri, 30 Oct 2015 13:57:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BF=AE=E6=94=B9=E4=B8=8E?= =?UTF-8?q?=E5=8F=AA=E8=AF=BB=E7=9A=84=E5=BF=AB=E6=8D=B7=E9=94=AE=20ctrl/c?= =?UTF-8?q?md=20+=20e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/leanote/leanote/issues/241 --- app/views/note/note-dev.html | 6 +++--- public/js/app/note.js | 35 ++++++++++++++++++----------------- public/js/app/page.js | 24 ++++++++++++++++++++---- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/app/views/note/note-dev.html b/app/views/note/note-dev.html index 2eaa03d..5466d8e 100644 --- a/app/views/note/note-dev.html +++ b/app/views/note/note-dev.html @@ -174,7 +174,7 @@ function log(o) { <li role="presentation" class="divider my-link writing-mobile-hide"></li> <li role="presentation" class="my-link toggle-editor-mode writing-mobile-hide" > - <a href="#writing"><i class="fa fa-rocket"></i> + <a href="#writing" title="{{msg . "writingMode"}} ctrl/cmd+e"><i class="fa fa-rocket"></i> {{msg . "writingMode"}}</a> </li> @@ -571,7 +571,7 @@ function log(o) { </div> <!-- 查看信息 --> <div id="infoToolbar" class="info-toolbar invisible"> - <a class="toolbar-update"><i class="fa fa-pencil"></i> <span class="lang">{{msg . "modify"}}</span></a> + <a class="toolbar-update" title="{{msg . "modify"}} ctrl/cmd+e"><i class="fa fa-pencil"></i> <span class="lang">{{msg . "modify"}}</span></a> <span class="lang">{{msg . "created"}}</span>: <span class="created-time"></span> <span class="lang">{{msg . "updated"}}</span>: <span class="updated-time"></span> </div> @@ -608,7 +608,7 @@ function log(o) { <div class="navbar navbar-default"> <div class="navbar-inner" id="wmd-button-bar"> <div id="mdInfoToolbar" class="info-toolbar invisible"> - <a class="toolbar-update"><i class="fa fa-pencil"></i> <span class="lang">{{msg . "modify"}}</span></a> + <a class="toolbar-update" title="{{msg . "modify"}} ctrl/cmd+e"><i class="fa fa-pencil"></i> <span class="lang">{{msg . "modify"}}</span></a> <span class="lang">{{msg . "created"}}</span>: <span class="created-time"></span> <span class="lang">{{msg . "updated"}}</span>: <span class="updated-time"></span> </div> diff --git a/public/js/app/note.js b/public/js/app/note.js index 2185520..bb7b105 100644 --- a/public/js/app/note.js +++ b/public/js/app/note.js @@ -1532,14 +1532,14 @@ Note.deleteNoteTag = function(item, tag) { }; // readonly -Note.readOnly = false; // 默认为false要好? -LEA.readOnly = false; +Note.readOnly = true; // 默认为false要好? +LEA.readOnly = true; // 切换只读模式 -Note.toggleReadOnly = function() { +Note.toggleReadOnly = function(needSave) { if(LEA.em && LEA.em.isWriting()) { // 写作模式下 return Note.toggleWriteable(); } - + var me = this; var note = me.getCurNote(); @@ -1567,12 +1567,13 @@ Note.toggleReadOnly = function() { $('#infoToolbar .updated-time').html(goNowToDatetime(note.UpdatedTime)); } + // 保存之 + if (needSave) { + Note.curChangedSaveIt(); + } + Note.readOnly = true; LEA.readOnly = true; - - if(note.readOnly) { - return; - } if(!note.IsMarkdown) { // 里面的pre也设为不可写 @@ -1580,8 +1581,6 @@ Note.toggleReadOnly = function() { LeaAce.setAceReadOnly($(this), true); }); } - - note.readOnly = true; }; // 切换到编辑模式 LEA.toggleWriteable = Note.toggleWriteable = function() { @@ -1601,10 +1600,6 @@ LEA.toggleWriteable = Note.toggleWriteable = function() { Note.readOnly = false; LEA.readOnly = false; - - if(!note.readOnly) { - return; - } if(!note.IsMarkdown) { // 里面的pre也设为不可写 @@ -1617,8 +1612,14 @@ LEA.toggleWriteable = Note.toggleWriteable = function() { MD.onResize(); } } - - note.readOnly = false; +}; +Note.toggleWriteableAndReadOnly = function () { + if (LEA.readOnly) { + Note.toggleWriteable(); + } + else { + Note.toggleReadOnly(true); + } }; Note.getPostUrl = function (note) { @@ -2498,4 +2499,4 @@ $(function() { }); // 定时器启动 -Note.startInterval(); \ No newline at end of file +Note.startInterval(); diff --git a/public/js/app/page.js b/public/js/app/page.js index a6e46ee..fbf48a9 100644 --- a/public/js/app/page.js +++ b/public/js/app/page.js @@ -487,8 +487,6 @@ function initEditor() { e.preventDefault(); return; } - // 这里就不要了, 避免两次updateNote - // Note.saveNote(e); // 当输入的时候, 把当前raw删除掉 LeaAce.removeCurToggleRaw(); @@ -563,8 +561,26 @@ function initEditor() { Note.curChangedSaveIt(); } - // 全局ctrl + s - $("body").on('keydown', Note.saveNote); + // 全局快捷键 + // ctrl + s 保存 + // ctrl+e 切换只读与可写 + $('body').on('keydown', function (e) { + var num = e.which ? e.which : e.keyCode; + var ctrlOrMetaKey = e.ctrlKey || e.metaKey; + if(ctrlOrMetaKey) { + // 保存 + if (num == 83 ) { // ctrl + s or command + s + Note.curChangedSaveIt(); + e.preventDefault(); + return false; + } + else if (num == 69) { // e + Note.toggleWriteableAndReadOnly(); + e.preventDefault(); + return false; + } + } + }); } //-----------------------