diff options
| author | Kumar Priyansh <[email protected]> | 2020-07-18 01:02:26 +0530 |
|---|---|---|
| committer | Kumar Priyansh <[email protected]> | 2020-07-18 01:02:26 +0530 |
| commit | 796b7f3f1eeaee548a9df67e9a72bd849bc97afb (patch) | |
| tree | 81f994dc01ff213a11f640f1092950ffeec36385 /src/views | |
| parent | 61d76581dfd79af06da591305e2c8b2e01790b57 (diff) | |
| download | authorr-796b7f3f1eeaee548a9df67e9a72bd849bc97afb.tar.xz authorr-796b7f3f1eeaee548a9df67e9a72bd849bc97afb.zip | |
Rename Chapter Function: Event Handling
Diffstat (limited to 'src/views')
| -rw-r--r-- | src/views/system/chapterRename.html | 49 | ||||
| -rw-r--r-- | src/views/templates/blank/template.html | 31 | ||||
| -rw-r--r-- | src/views/templates/blank/template.js | 65 |
3 files changed, 144 insertions, 1 deletions
diff --git a/src/views/system/chapterRename.html b/src/views/system/chapterRename.html new file mode 100644 index 0000000..28a6ee8 --- /dev/null +++ b/src/views/system/chapterRename.html @@ -0,0 +1,49 @@ +<!DOCTYPE html> +<html lang="en"> + +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Document</title> + <link rel="stylesheet" href="../../nativekit/css/all.css"> +</head> + +<body> + <div class="window"> + <footer class="statusbar titlebar draggable"> + <h1 class="window-title">Change Chapter Name</h1> + <div class="padded"> + <div class="form-group"> + <input type="text" class="form-control" id="newChapterName" placeholder="New Chapter Name"> + </div> + </div> + <div class="toolbars"> + <button id="ok" class="button button-blue pull-right">OK</button> + <button id="cancel" class="button button-default pull-right">Cancel</button> + </div> + </footer> + </div> +</body> +<script>window.$ = window.jQuery = require('jquery');</script> +<script> + $('#newChapterName').focus(); + $(document).on('keypress', function (e) { + if (e.which == 13) { + $('#ok').click(); + } + }) + const remote = require('electron').remote; + const { ipcRenderer } = require('electron'); + $('#cancel').click(function () { + var window = remote.getCurrentWindow(); + window.close(); + }); + $('#ok').click(function () { + ipcRenderer.send('renamedChapter', $('#newChapterName').val()); + }) + ipcRenderer.on('currentChapterName', (event, arg) => { + $('#newChapterName').val(arg); + }) +</script> + +</html>
\ No newline at end of file diff --git a/src/views/templates/blank/template.html b/src/views/templates/blank/template.html index 7a07207..a1d8477 100644 --- a/src/views/templates/blank/template.html +++ b/src/views/templates/blank/template.html @@ -1,11 +1,40 @@ <!DOCTYPE html> <html lang="en"> + <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> + <link rel="stylesheet" href="../../../nativekit/css/all.css"> + <link rel="stylesheet" href="template.css"> </head> + <body> - <h1>The Blank Template</h1> + <div class="window"> + <header class="titlebar draggable"> + <h1 class="window-title">Blank Template</h1> + <div class="toolbars"> + + <button title="Add a new chapter" class="button button-default"> + <i class="icon nk-plus"></i> + </button> + + </div> + </header> + <div class="content"> + <div class="pane-group"> + <div class="pane sidebar pane-normal"> + <nav class="nav-group"> + <h5 class="title">Chapters</h5> + <div id="chapters"></div> + </nav> + </div> + <div class="pane"></div> + </div> + </div> + </div> + <script>window.$ = window.jQuery = require('jquery');</script> + <script src="template.js"></script> </body> + </html>
\ No newline at end of file diff --git a/src/views/templates/blank/template.js b/src/views/templates/blank/template.js index e69de29..d20f8ea 100644 --- a/src/views/templates/blank/template.js +++ b/src/views/templates/blank/template.js @@ -0,0 +1,65 @@ +const remote = require('electron').remote +const Menu = remote.Menu; +const MenuItem = remote.MenuItem; +const { ipcRenderer } = require('electron'); + +const chapterList = ['Chapterfl1']; +const chapterCount = chapterList.length; + +$(document).ready(function () { + updateChapters(); +}); + +function updateChapters() { + $('#chapters').empty(); + chapterList.forEach(chapter => { + const chapterName = chapter.replace(/fl/g, ' '); + $('#chapters').append(`<span id="${chapter}" class="item active chapter_navigation">${chapterName}</span>`) + }); +} + +let currentSelectedChapterForContextAction = null; +let rightClickPosition = null; +const chapterMenu = new Menu() +const chapterContextItems = new MenuItem({ + label: 'Rename Chapter', + click: (e) => { + const currentChapter = currentSelectedChapterForContextAction.replace(/fl/g, ' '); + let child = new remote.BrowserWindow({ + parent: remote.getCurrentWindow(), + modal: true, + width: 360, + height: 135, + frame: false, + show: false, + titleBarStyle: 'hidden', + webPreferences: { + nodeIntegration: true, + enableRemoteModule: true + } + }) + child.loadURL('file://' + __dirname + '/../../system/chapterRename.html') + child.once('show', function () { + child.webContents.send('currentChapterName', currentChapter); + }); + child.once('ready-to-show', () => { + child.show() + }); + ipcRenderer.on('renamedChapter', (event, message) => { + const newChapterName = message; + const index = chapterList.findIndex(chapter => chapter === currentSelectedChapterForContextAction); + const newChapterId = newChapterName.replace(/ /g, 'fl'); + chapterList[index] = newChapterId; + currentSelectedChapterForContextAction = null; + updateChapters(); + }); + } +}) +chapterMenu.append(chapterContextItems); + +$(document).on('contextmenu', '.chapter_navigation', (e) => { + e.preventDefault(); + currentSelectedChapterForContextAction = e.target.id; + rightClickPosition = { x: e.x, y: e.y }; + chapterMenu.popup(remote.getCurrentWindow()); +}); |
