From ff79dfc7c38cde42d6ca48e1a72958d65a53b801 Mon Sep 17 00:00:00 2001 From: LucasYuNju Date: Wed, 28 Dec 2016 16:08:41 +0800 Subject: [PATCH] Switch view by change noteItemList's classList --- public/js/app/note.js | 47 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/public/js/app/note.js b/public/js/app/note.js index 683f81e0..4e4884f3 100644 --- a/public/js/app/note.js +++ b/public/js/app/note.js @@ -20,31 +20,31 @@ Note.cacheByNotebookId = {all: {}}; Note.notebookIds = {}; // notebookId => true // 初始化模版字符串 -(function() { - Note.itemTpl = {}; - Note.itemTplNoImg = {}; - // blog, star, settings - var itemIsBlog = '
'; +// blog, star, settings +var itemIsBlog = '
'; +Note.itemTplNoImg = '
  • '; +Note.itemTplNoImg += itemIsBlog + '

    ?

    ? ?

    ?

  • '; +Note.itemTpl = '
  • '; +Note.itemTpl += itemIsBlog + '

    ?

    ? ?

    ?

  • '; - // list view - Note.itemTplNoImg.list = '
  • '; - Note.itemTplNoImg.list += itemIsBlog + '

    ?

  • '; - Note.itemTpl.list = '
  • '; - Note.itemTpl.list += itemIsBlog + '

    ?

  • '; - - // summary view - Note.itemTplNoImg.summary = '
  • '; - Note.itemTplNoImg.summary += itemIsBlog + '

    ?

    ? ?

    ?

  • '; - Note.itemTpl.summary = '
  • '; - Note.itemTpl.summary += itemIsBlog + '

    ?

    ? ?

    ?

  • '; -})(); +Note.switchView = function(view) { + if (view === 'list') { + $('#noteItemList').removeClass('snippet-view'); + $('#noteItemList').addClass('list-view'); + } + else if (view === 'snippet') { + $('#noteItemList').removeClass('list-view'); + $('#noteItemList').addClass('snippet-view'); + } +} +Note.switchView(Config.view || 'summary'); Note.getItemTpl = function() { - return Note.itemTpl[Config.view || 'summary']; + return Note.itemTpl; } Note.getItemTplNoImg = function() { - return Note.itemTplNoImg[Config.view ||'summary']; + return Note.itemTplNoImg; } // 定时保存信息 @@ -3223,15 +3223,14 @@ $(function() { // 切换列表视图 $("#viewModeDropdown").click(function() { - console.log("*******"); var themeSubmenus = new gui.Menu(); themeSubmenus.append(new gui.MenuItem({ - checked: Config.view === "summary", + checked: Config.view === "snippet", label: "摘要视图", type: "checkbox", click: function() { - Config.view = 'summary'; - Notebook.renderCurNotebook(); + Config.view = 'snippet'; + Note.switchView('snippet'); Api.writeConfig(Config); } })); @@ -3241,7 +3240,7 @@ $(function() { type: "checkbox", click: function() { Config.view = 'list'; - Notebook.renderCurNotebook(); + Note.switchView('list'); Api.writeConfig(Config); } }));