diff options
| author | Kumar Priyansh <[email protected]> | 2020-07-18 01:28:03 +0530 |
|---|---|---|
| committer | Kumar Priyansh <[email protected]> | 2020-07-18 01:28:03 +0530 |
| commit | 5a70de65d4e689d7e246b565c306b809d417f6b7 (patch) | |
| tree | 815be3f935453cf98b42e0bdaba7f7029fd913a8 /src | |
| parent | 796b7f3f1eeaee548a9df67e9a72bd849bc97afb (diff) | |
| download | authorr-5a70de65d4e689d7e246b565c306b809d417f6b7.tar.xz authorr-5a70de65d4e689d7e246b565c306b809d417f6b7.zip | |
Add/Update Chapters Function
Diffstat (limited to 'src')
| -rw-r--r-- | src/views/templates/blank/template.html | 2 | ||||
| -rw-r--r-- | src/views/templates/blank/template.js | 46 |
2 files changed, 42 insertions, 6 deletions
diff --git a/src/views/templates/blank/template.html b/src/views/templates/blank/template.html index a1d8477..b41acac 100644 --- a/src/views/templates/blank/template.html +++ b/src/views/templates/blank/template.html @@ -15,7 +15,7 @@ <h1 class="window-title">Blank Template</h1> <div class="toolbars"> - <button title="Add a new chapter" class="button button-default"> + <button id="addChapter" title="Add a new chapter" class="button button-default"> <i class="icon nk-plus"></i> </button> diff --git a/src/views/templates/blank/template.js b/src/views/templates/blank/template.js index d20f8ea..d45edc3 100644 --- a/src/views/templates/blank/template.js +++ b/src/views/templates/blank/template.js @@ -4,24 +4,49 @@ const MenuItem = remote.MenuItem; const { ipcRenderer } = require('electron'); const chapterList = ['Chapterfl1']; -const chapterCount = chapterList.length; +const currentActiveChapter = 0; +let chapterNameCount = 1; $(document).ready(function () { updateChapters(); + setActiveChapter(currentActiveChapter); }); function updateChapters() { + + if (!chapterList.length) { + addChapter(); + } + $('#chapters').empty(); chapterList.forEach(chapter => { const chapterName = chapter.replace(/fl/g, ' '); - $('#chapters').append(`<span id="${chapter}" class="item active chapter_navigation">${chapterName}</span>`) + $('#chapters').append(`<span id="${chapter}" class="item chapter_navigation">${chapterName}</span>`) }); + + setActiveChapter(currentActiveChapter); +} + +function setActiveChapter(currentActiveChapter) { + const chapter = chapterList[currentActiveChapter]; + $(`#${chapter}`).addClass('active'); +} + +function addChapter() { + const chapterCount = chapterList.length; + chapterList[chapterCount] = `Chapterfl${chapterNameCount+1}`; + chapterNameCount++; + updateChapters(); } +$('#addChapter').click(() => { + addChapter(); +}) + let currentSelectedChapterForContextAction = null; let rightClickPosition = null; const chapterMenu = new Menu() -const chapterContextItems = new MenuItem({ +const renameChapterMenuItem = new MenuItem({ label: 'Rename Chapter', click: (e) => { const currentChapter = currentSelectedChapterForContextAction.replace(/fl/g, ' '); @@ -54,8 +79,19 @@ const chapterContextItems = new MenuItem({ updateChapters(); }); } -}) -chapterMenu.append(chapterContextItems); +}); + +const deleteChapterMenuItem = new MenuItem({ + label: 'Delete Chapter', + click: (e) => { + const index = chapterList.findIndex(chapter => chapter === currentSelectedChapterForContextAction); + chapterList.splice(index, 1); + updateChapters(); + } +}); + +chapterMenu.append(renameChapterMenuItem); +chapterMenu.append(deleteChapterMenuItem); $(document).on('contextmenu', '.chapter_navigation', (e) => { e.preventDefault(); |
