From bf3c44e567675245bc5498d70869b7edbcbff6e6 Mon Sep 17 00:00:00 2001 From: kor Date: Tue, 24 Jul 2018 01:20:03 +1200 Subject: [PATCH 01/14] Setup basic add page visual and form. --- docs/asset/style.css | 47 +++++++++++++++++++++++++ docs/index.html | 1 + docs/logic/main.js | 46 +++++++++++++++++++++--- docs/logic/view.js | 84 +++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 173 insertions(+), 5 deletions(-) diff --git a/docs/asset/style.css b/docs/asset/style.css index de06500..8bb764f 100644 --- a/docs/asset/style.css +++ b/docs/asset/style.css @@ -43,6 +43,8 @@ --size-font-title: 1em; --size-font-body: 0.8em; --type-icon-size: 24px; /*font size of type icon/count*/ + + --animation-time: 200ms; } * { @@ -53,6 +55,7 @@ html { background: var(--color-main-bg-i); padding: 0em; margin: 0; + overflow-y: scroll; } body { padding: 0em; @@ -96,6 +99,7 @@ body { margin: 0px auto; width: 100%; float: left; + text-align: center; } .menu-item .count { padding-right: calc(var(--menu-item-elem-sep) / 2); @@ -150,6 +154,46 @@ body { float: left; } +/* PAGE */ +.page-overlay { + /* visual */ + background-color: #000; + opacity: 0; + -webkit-transition: opacity var(--animation-time) linear; + transition: opacity var(--animation-time) linear; + width: 100%; + height: 100%; + /* position */ + position: absolute; + z-index: -100; + left: 0; + top: 0; + /* content */ + display: flex; + align-items: center; + justify-content: center; +} +.page-overlay .content .row { + /*float: left; + clear: both;*/ + /*height: 40px;*/ +} +.page-overlay .content .row input { + padding: 10px; + width: 400px; + margin-bottom: 10px; + background-color: transparent; + color: #fff; + border-width: 1px; + border-style: solid; + border-color: var(--color-menu-item-i); + border-radius: var(--size-item-corner); +} +.page-overlay .content .row input::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */ + opacity: 1; + color: var(--color-menu-item-i); +} + /* CONTENT */ .container { background: var(--color-main-bg-i); @@ -161,6 +205,9 @@ body { } .grid { margin: var(--size-gutter) auto; + opacity: 1; + -webkit-transition: opacity 1000ms linear; + transition: opacity 1000ms linear; } .grid:after { /* clearfix */ diff --git a/docs/index.html b/docs/index.html index 9a2f242..120f399 100644 --- a/docs/index.html +++ b/docs/index.html @@ -18,6 +18,7 @@ +
diff --git a/docs/logic/main.js b/docs/logic/main.js index 8a39d4d..4dc598e 100644 --- a/docs/logic/main.js +++ b/docs/logic/main.js @@ -2,6 +2,8 @@ function Main() { this.db = null; this.view = null; + this.queryPrev = ''; + this.queryCur = ''; this.install = function() { @@ -19,11 +21,47 @@ function Main() this.load = function(target) { + this.queryPrev = this.queryCur; target = target.substr(0,1) == "#" ? target.substr(1,target.length-1) : target; - target = target.trim(); - var entries = this.db.filter(target); - this.view.display(entries); + this.queryCur = target.trim(); + + if (window.location.hash != this.queryCur) + { + window.location.hash = this.queryCur; + } + + if (this.queryCur == 'add') + { + this.view.add(); + } + else + { + this.view.display(this.db.filter(this.queryCur)); + } } } -window.addEventListener("hashchange", function() { main.load(window.document.location.hash); }); \ No newline at end of file +window.addEventListener("hashchange", function() { main.load(window.document.location.hash); }); + +document.onkeydown = function(evt) +{ + evt = evt || window.event; + var isEscape = false; + + if ("key" in evt) + { + isEscape = (evt.key == "Escape" || evt.key == "Esc"); + } + else + { + isEscape = (evt.keyCode == 27); + } + + if (isEscape) + { + if (main.queryCur == 'add') + { + main.load(main.queryPrev); + } + } +}; \ No newline at end of file diff --git a/docs/logic/view.js b/docs/logic/view.js index 6f43535..356faed 100644 --- a/docs/logic/view.js +++ b/docs/logic/view.js @@ -1,10 +1,15 @@ function View() { this.msnry = null; + this.overlay = null; + this.container = null; this.grid = null; this.menu = null; var parent = this; - + + // STATE + this.enabledOverlay = false; + const SETTINGS = { STATSNUMTAGS: 5, STATSNUMTYPE: 10, @@ -27,8 +32,11 @@ function View() this.install = function() { + this.overlay = document.getElementById("overlay"); + this.container = document.getElementById("container"); this.grid = document.getElementById("grid"); this.menu = document.getElementById("menu"); + this.setupAdd(); if (SETTINGS.USEMASONRY) { @@ -43,8 +51,75 @@ function View() } } + this.add = function() + { + this.setOverlay(true); + } + + this.setupAdd = function() + { + this.overlay.innerHTML = ''; + content += `
`; + + content += this.createFormInput('Title'); + content += this.createFormInput('Date'); + content += this.createFormInput('Person'); + content += this.createFormInput('Source'); + + content += this.createFormInput('Project'); + content += this.createFormInput('Type'); + content += this.createFormInput('Link'); + content += this.createFormInput('Tags'); + content += this.createFormInput('Note'); + content += this.createFormInput('Quote'); + content += this.createFormInput('Terms'); + content += this.createFormInput('Progress'); + // DONE + // REVI + + content += `
`; + this.overlay.innerHTML += content; + } + + this.createFormInput = function(id) + { + return `
+
+ +
+
`; + } + + this.setOverlay = function(value) + { + if (value && !this.enabledOverlay) + { + overlay.style.opacity = '1'; + // overlay.style.visibility = 'hidden'; + // overlay.style.display = 'none'; + overlay.style.zIndex = '1000'; + this.enabledOverlay = true; + setTimeout(function() + { + this.grid.innerHTML = ''; + this.grid.style.height = 0; + }, 200); + } + else if (!value && this.enabledOverlay) + { + overlay.style.opacity = '0'; + setTimeout(function() + { + overlay.style.zIndex = '-100'; + }, 200); + this.enabledOverlay = false; + } + } + this.display = function(db) { + this.setOverlay(false); + // BUILD this.grid.innerHTML = ''; this.grid.innerHTML += "
"; @@ -302,6 +377,13 @@ function View() { let menuContent = ``; + // ADD + menuContent += ``; + menuContent += ``; + menuContent += ``; + + menuContent += ``; + // TYPE menuContent += ``; menuContent += ``; + + + this.overlay.innerHTML += content; this.display = document.getElementById("display"); @@ -86,15 +97,21 @@ function Add() this.elementList[this.keys[i]].elem.onblur = this.onElemBlur; this.elementList[this.keys[i]].elemKey = document.getElementById("key" + this.elementList[this.keys[i]].key); } + setTimeout(function() + { + parent.setupData(); + }, 100); } - this.setupElement = function(key, desc) + this.setupElement = function(key, desc, type) { - this.elementList[key] = { key: key, desc: desc, added: false}; + this.elementList[key] = { key: key, desc: desc, type: type, added: false}; } this.onElemChanged = function(e) { + // TODO: Autocomplete tags, type + parent.setupData(); } this.onElemFocus = function(e) @@ -129,6 +146,65 @@ function Add() } } + this.setupData = function() + { + let value = ''; + for (var i = 0; i < parent.keys.length; i++) + { + if (parent.elementList[parent.keys[i]].key == 'Title') + { + if (parent.elementList[parent.keys[i]].elem.value != '') + { + value += parent.elementList[parent.keys[i]].elem.value.toUpperCase() + '
' + } + else + { + value += 'TITLE
'; + } + } + else if (parent.elementList[parent.keys[i]].elem.value != '') + { + value += '  '; + value += parent.elementList[parent.keys[i]].desc.toUpperCase() + ' : '; + + if (parent.elementList[parent.keys[i]].type == 'lower') + { + value += parent.elementList[parent.keys[i]].elem.value.toLowerCase(); + } + else if (parent.elementList[parent.keys[i]].type == 'text') + { + value += parent.elementList[parent.keys[i]].elem.value; + } + else if (parent.elementList[parent.keys[i]].type == 'url') + { + // TODO: validate + value += parent.elementList[parent.keys[i]].elem.value; + } + else if (parent.elementList[parent.keys[i]].type == 'tags') + { + // TODO: Format + value += parent.elementList[parent.keys[i]].elem.value; + } + else if (parent.elementList[parent.keys[i]].type == 'quote') + { + // TODO: Format + value += parent.elementList[parent.keys[i]].elem.value; + } + else if (parent.elementList[parent.keys[i]].type == 'title') + { + value += parent.elementList[parent.keys[i]].elem.value.toProperCase(); + } + else if (parent.elementList[parent.keys[i]].type == 'upper') + { + value += parent.elementList[parent.keys[i]].elem.value.toLowerCase(); + } + + value += '
'; + } + } + parent.display.innerHTML = value; + } + this.show = function() { this.setOverlay(true); @@ -172,6 +248,10 @@ function Add() } } +String.prototype.toProperCase = function () { + return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); +}; + document.onkeydown = function(evt) { evt = evt || window.event; From 0ee8108f11299e64e5c431e0ca5846d2a1ca4678 Mon Sep 17 00:00:00 2001 From: kor Date: Mon, 6 Aug 2018 00:49:48 +1200 Subject: [PATCH 07/14] Update data. --- docs/content/data.ndtl | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/docs/content/data.ndtl b/docs/content/data.ndtl index 170312e..1eb6aa3 100644 --- a/docs/content/data.ndtl +++ b/docs/content/data.ndtl @@ -2167,4 +2167,80 @@ AESTHETICS PERS : theneko SRCE : Merveilles LINK : https://www.youtube.com/watch?v=HCHFjj_qr5Q + TAGS : design + +TYPEFACE PAIRING + DATE : 12018-07-27 + PERS : rutherford + SRCE : Merveilles + TYPE : article + LINK : https://craze.co.uk/typeface+pairing + TAGS : design + +DECISIONS + DATE : 12018-07-28 + QOTE : 'Personal decisions are the leading cause of death' + TYPE : quote + LINK : https://pdfs.semanticscholar.org/375e/8c9e3df49a7962d12bb186a4ec7dc7d2b3ab.pdf + FILE : 12018-07-28_PersonalDecisionsAreTheLeading.pdf + +MICROMORT + DATE : 12018-07-28 + TYPE : term + TERM + > Micromort: 'a unit of risk defined as one-in-a-million chance of death.' + LINK : https://en.wikipedia.org/wiki/Micromort + +ARTISTS + DATE : 12018-07-28 + TYPE : quote + QOTE + > Alan Moore: “In latter times, I think that artists and writers have allowed themselves to be sold down the river. They have accepted the prevailing belief that art and writing are merely forms of entertainment. They are not seen as transformative forces that can change a human being, that can change a society. They are seen as simple entertainment. Things with which to fill 20 minutes, half an hour while we are waiting to die. + & It is not the job of artists to give the audience what the audience wants. If the audience knew what they needed then they wouldn’t be audience, they would be the artists. It is the job of artists to give the audience what they need.” + LINK : http://intellectual-thoughts.com/Alan%20Moore%20Quote.htm + TAGS : philosophy + +ELECTRON MEMORY + DATE : 12018-08-05 + TYPE : article + LINK : http://seenaburns.com/debugging-electron-memory-usage/ + PERS : nnkd + SRCE : Merveilles + PROJ : Memex + +ISOLATE + DATE : 12018-08-05 + TYPE : tool + LINK : https://github.com/seenaburns/isolate + TAGS : gallery, masonry, web, code, inspiration + PROJ : Memex + +CHEMICAL IMBALANCE + DATE : 12018-08-05 + TYPE : article + LINK : https://www.anxietycentre.com/anxiety/chemical-imbalance.shtml + TAGS : psychology + PERS : Adam Strauss + SRCE : DTFH + DONE : true + +SSL EXPLAINED + DATE : 12018-08-05 + TYPE : article + LINK : http://seenaburns.com/archive/ + TAGS : code + +ON ICONS + DATE : 12018-08-05 + TYPE : article + LINK : https://ia.net/topics/on-icons + PERS : rutherford + SRCE : Merveilles + +TURBO + TERM + > Turbo: compressor forcing additional air into an engine to allow for increased fuel ignition and thus increased power output. A turbo has two halves, one is driven by the exhaust from the engine the other forces air into the engine. Negative 'turbo lag' time until the engine can provide enough exhaust to spin up the turbo compressor. + > Supercharger: Like a turbo but instead of being driven by exhaust gas it is driven mechanically (belt to engine). Negative Takes power/efficiency away from driving engine output in order to drive the compressor. + > Electic supercharger: fully electronically driven turbo (generally powered by a higher voltage (48v) seperate from car 12v). Negative high electricity use. + > Electic turbo: a hybrid electric-assisted turbo (generally powered by a higher voltage (48v) seperate from car 12v) using a DC motor to start the turbo spinning sooner to remove turbo lag or at low revs when not enough exhaust to produced. Once the engine is providing enough exhaust to spin the turbo the motor will stop output. It can also be a seperate electric supercharger working in conjunction with a standard turbo. Negative complexity. ` \ No newline at end of file From 8e2902ca49e5469d55e9517dfdbbb8153facc11c Mon Sep 17 00:00:00 2001 From: kor Date: Mon, 6 Aug 2018 03:04:44 +1200 Subject: [PATCH 08/14] Add Isolate to readme. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c3544f0..e797464 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ npm start - Template parser: [Runic](https://wiki.xxiivv.com/#runic) - Grid layout: [Masonry](https://masonry.desandro.com/) -Thanks to Devine Lu Linvega ([Oscean](https://github.com/XXIIVV/Oscean)), Josh Avanier ([Log](https://github.com/joshavanier/log)), Rekka Bell ([kokorobot](https://github.com/rekkabell/kokorobot)) and Alexey Botkov ([Legacy](https://github.com/nomand/Legacy)) +Thanks to Devine Lu Linvega ([Oscean](https://github.com/XXIIVV/Oscean)), Josh Avanier ([Log](https://github.com/joshavanier/log)), Rekka Bell ([kokorobot](https://github.com/rekkabell/kokorobot)), Alexey Botkov ([Legacy](https://github.com/nomand/Legacy)), Seena Burns ([Isolate](https://github.com/seenaburns/isolate)) --- From 711192d1d155262ea1beb7912a6209e009d51898 Mon Sep 17 00:00:00 2001 From: kor Date: Mon, 6 Aug 2018 03:05:18 +1200 Subject: [PATCH 09/14] Add test for interprocess communication. --- docs/asset/style.css | 4 ++-- docs/index.html | 8 +++++++ docs/logic/add.js | 20 +++++++++++++++-- docs/logic/main.js | 3 +++ docs/logic/write.js | 23 +++++++++++++++++++ main.js | 53 +++++++++++++++++++++++++++++++++++++------- 6 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 docs/logic/write.js diff --git a/docs/asset/style.css b/docs/asset/style.css index 59b53ac..137ad87 100644 --- a/docs/asset/style.css +++ b/docs/asset/style.css @@ -173,8 +173,8 @@ body { /* visual */ background-color: var(--color-overlay-bg-i); opacity: 0; - -webkit-transition: opacity var(--animation-time) linear; - transition: opacity var(--animation-time) linear; + /*-webkit-transition: opacity var(--animation-time) linear; + transition: opacity var(--animation-time) linear;*/ width: 100%; height: 100%; /* position */ diff --git a/docs/index.html b/docs/index.html index 2578ec2..75fc2da 100644 --- a/docs/index.html +++ b/docs/index.html @@ -7,6 +7,13 @@ + + @@ -17,6 +24,7 @@ +
diff --git a/docs/logic/add.js b/docs/logic/add.js index 4f7c96c..8cbe0f7 100644 --- a/docs/logic/add.js +++ b/docs/logic/add.js @@ -1,3 +1,7 @@ +const { ipcRenderer } = nodeRequire('electron'); +// const mainProcess = remote.nodeRequire('./main.js'); +//const mainProcess = nodeRequire('./main.js'); + function Add() { this.overlay = null; @@ -83,12 +87,24 @@ function Add() content += `
`; - - this.overlay.innerHTML += content; this.display = document.getElementById("display"); + document.getElementById("enter").addEventListener('click', + () => + { + console.log('test test'); + // ipcRenderer.send('write', 'test'); + let Data = + { + message: "Hi", + someData: "Let's go" + }; + + ipcRenderer.send('request-mainprocess-action', Data); + }); + for (var i = 0; i < this.keys.length; i++) { this.elementList[this.keys[i]].elem = document.getElementById(this.elementList[this.keys[i]].key); diff --git a/docs/logic/main.js b/docs/logic/main.js index 9b620f5..d508db0 100644 --- a/docs/logic/main.js +++ b/docs/logic/main.js @@ -3,6 +3,7 @@ function Main() this.db = null; this.view = null; this.add = null; + this.write = null; this.queryPrev = ''; this.queryCur = ''; @@ -14,6 +15,8 @@ function Main() this.view.install(); this.add = new Add(); this.add.install(); + this.write = new Write(); + this.write.install(); var escape = document.getElementById("escape"); escape.onclick = function() diff --git a/docs/logic/write.js b/docs/logic/write.js new file mode 100644 index 0000000..2c85da7 --- /dev/null +++ b/docs/logic/write.js @@ -0,0 +1,23 @@ + +function Write() +{ + + this.install = function() + { + } + + this.insert = function(data) + { + let position = 5; // get insert position + + let foo = fs.openSync('foo.txt','r+'); + let buf = new Buffer("hello"); + fs.writeSync(foo, buf, 0, buf.length, position); + fs.close(foo); + } +} + +// fs.appendFile('mynewfile1.txt', 'Hello content!', function (err) { +// if (err) throw err; +// console.log('Saved!'); +// }); \ No newline at end of file diff --git a/main.js b/main.js index 93e9c35..1846484 100644 --- a/main.js +++ b/main.js @@ -2,6 +2,7 @@ const {app, BrowserWindow, webFrame, Menu} = require('electron') const path = require('path') const url = require('url') const shell = require('electron').shell; +const fs = require('fs'); let is_shown = true; @@ -49,10 +50,28 @@ app.on('ready', () => { app.win = new BrowserWindow({ webPreferences: { - nodeIntegration: false + nodeIntegration: true }, width: 950, height: 950, backgroundColor:"#ddd", minWidth: 587, minHeight: 540, frame:true, autoHideMenuBar: true, icon: __dirname + '/icon.ico'}) - app.win.loadURL(`file://${__dirname}/docs/index.html`) + app.win.loadURL(`file://${__dirname}/docs/index.html`); + + // app.win.webContents.on('did-finish-load', () => { + // let code = ` + // console.log("3"); + // document.getElementById("enter").addEventListener("click", + // function (e) + // { + // let foo = fs.openSync('foo.txt','r+'); + // let buf = new Buffer("hello"); + // fs.writeSync(foo, buf, 0, buf.length, 5); + // fs.close(foo); + // console.log('WROTE!'); + + // console.log(document.getElementById("display").value); + // });`; + // app.win.webContents.executeJavaScript(code); + // }); + // app.win.toggleDevTools(); app.win.on('closed', () => { @@ -79,11 +98,6 @@ app.on('ready', () => app.win.webContents.on('new-window', this.handleRedirect) }) - - - - - app.on('window-all-closed', () => { app.quit() @@ -93,4 +107,27 @@ app.on('activate', () => { if (app.win === null) { createWindow() } -}) \ No newline at end of file +}) + +// write = function(data) +// { +// let foo = fs.openSync('foo.txt','r+'); +// let buf = new Buffer("hello"); +// fs.writeSync(foo, buf, 0, buf.length, 5); +// fs.close(foo); +// console.log('WROTE!'); +// } + +const {ipcMain} = require('electron'); + +// Attach listener in the main process with the given ID +ipcMain.on('request-mainprocess-action', (event, arg) => { + // Displays the object sent from the renderer process: + //{ + // message: "Hi", + // someData: "Let's go" + //} + console.log( + arg + ); +}); \ No newline at end of file From dd9aac0721adcf1b72cd4b2fc1c69cb3e9d2afa2 Mon Sep 17 00:00:00 2001 From: kor Date: Mon, 6 Aug 2018 03:19:05 +1200 Subject: [PATCH 10/14] Add write test to IPC test. --- docs/content/data.ndtl | 10 +++++++++ docs/logic/add.js | 11 ++-------- foo.txt | 1 + main.js | 46 ++++++++---------------------------------- 4 files changed, 21 insertions(+), 47 deletions(-) create mode 100644 foo.txt diff --git a/docs/content/data.ndtl b/docs/content/data.ndtl index 1eb6aa3..fca65f1 100644 --- a/docs/content/data.ndtl +++ b/docs/content/data.ndtl @@ -2236,11 +2236,21 @@ ON ICONS LINK : https://ia.net/topics/on-icons PERS : rutherford SRCE : Merveilles + TAGS : design TURBO + DATE : 12018-08-05 + TYPE : term + TAGS : car TERM > Turbo: compressor forcing additional air into an engine to allow for increased fuel ignition and thus increased power output. A turbo has two halves, one is driven by the exhaust from the engine the other forces air into the engine. Negative 'turbo lag' time until the engine can provide enough exhaust to spin up the turbo compressor. > Supercharger: Like a turbo but instead of being driven by exhaust gas it is driven mechanically (belt to engine). Negative Takes power/efficiency away from driving engine output in order to drive the compressor. > Electic supercharger: fully electronically driven turbo (generally powered by a higher voltage (48v) seperate from car 12v). Negative high electricity use. > Electic turbo: a hybrid electric-assisted turbo (generally powered by a higher voltage (48v) seperate from car 12v) using a DC motor to start the turbo spinning sooner to remove turbo lag or at low revs when not enough exhaust to produced. Once the engine is providing enough exhaust to spin the turbo the motor will stop output. It can also be a seperate electric supercharger working in conjunction with a standard turbo. Negative complexity. + +ELECTRON IPC + DATE : 12018-08-06 + LINK : https://ourcodeworld.com/articles/read/537/how-to-execute-a-function-of-the-main-process-inside-the-renderer-process-in-electron-framework + PROJ : Memex + TAGS : web, code ` \ No newline at end of file diff --git a/docs/logic/add.js b/docs/logic/add.js index 8cbe0f7..f306bea 100644 --- a/docs/logic/add.js +++ b/docs/logic/add.js @@ -94,15 +94,8 @@ function Add() document.getElementById("enter").addEventListener('click', () => { - console.log('test test'); - // ipcRenderer.send('write', 'test'); - let Data = - { - message: "Hi", - someData: "Let's go" - }; - - ipcRenderer.send('request-mainprocess-action', Data); + console.log('called write'); + ipcRenderer.send('write', '
'+this.display.innerHTML); }); for (var i = 0; i < this.keys.length; i++) diff --git a/foo.txt b/foo.txt new file mode 100644 index 0000000..e2e107a --- /dev/null +++ b/foo.txt @@ -0,0 +1 @@ +123456789 \ No newline at end of file diff --git a/main.js b/main.js index 1846484..6285a48 100644 --- a/main.js +++ b/main.js @@ -3,6 +3,7 @@ const path = require('path') const url = require('url') const shell = require('electron').shell; const fs = require('fs'); +const { ipcMain } = require('electron'); let is_shown = true; @@ -54,24 +55,6 @@ app.on('ready', () => }, width: 950, height: 950, backgroundColor:"#ddd", minWidth: 587, minHeight: 540, frame:true, autoHideMenuBar: true, icon: __dirname + '/icon.ico'}) app.win.loadURL(`file://${__dirname}/docs/index.html`); - - // app.win.webContents.on('did-finish-load', () => { - // let code = ` - // console.log("3"); - // document.getElementById("enter").addEventListener("click", - // function (e) - // { - // let foo = fs.openSync('foo.txt','r+'); - // let buf = new Buffer("hello"); - // fs.writeSync(foo, buf, 0, buf.length, 5); - // fs.close(foo); - // console.log('WROTE!'); - - // console.log(document.getElementById("display").value); - // });`; - // app.win.webContents.executeJavaScript(code); - // }); - // app.win.toggleDevTools(); app.win.on('closed', () => { @@ -109,25 +92,12 @@ app.on('activate', () => { } }) -// write = function(data) -// { -// let foo = fs.openSync('foo.txt','r+'); -// let buf = new Buffer("hello"); -// fs.writeSync(foo, buf, 0, buf.length, 5); -// fs.close(foo); -// console.log('WROTE!'); -// } +ipcMain.on('write', (event, arg) => +{ + console.log('Write called! Entry = ' + arg); -const {ipcMain} = require('electron'); - -// Attach listener in the main process with the given ID -ipcMain.on('request-mainprocess-action', (event, arg) => { - // Displays the object sent from the renderer process: - //{ - // message: "Hi", - // someData: "Let's go" - //} - console.log( - arg - ); + let foo = fs.openSync('foo.txt','r+'); + let buf = new Buffer(arg); + fs.writeSync(foo, buf, 0, buf.length, 5); + fs.close(foo); }); \ No newline at end of file From df6b87825b6140805dd20cf746197e1433f1d5ff Mon Sep 17 00:00:00 2001 From: kor Date: Thu, 9 Aug 2018 03:48:24 +1200 Subject: [PATCH 11/14] Update data. --- docs/content/data.ndtl | 79 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 3 deletions(-) diff --git a/docs/content/data.ndtl b/docs/content/data.ndtl index fca65f1..4bf6c42 100644 --- a/docs/content/data.ndtl +++ b/docs/content/data.ndtl @@ -1,5 +1,3 @@ -let DATABASE = ` - AGAINST BEAUTY IN PHYSICS PERS : faun SRCE : Merveilles @@ -2253,4 +2251,79 @@ ELECTRON IPC LINK : https://ourcodeworld.com/articles/read/537/how-to-execute-a-function-of-the-main-process-inside-the-renderer-process-in-electron-framework PROJ : Memex TAGS : web, code -` \ No newline at end of file + +IROHA + DATE : 12018-08-06 + PERS : james + SRCE : Merveilles + TYPE : quote + QOTE + > Even the blossoming flowers + & Will eventually scatter + & Who in our world + & Is unchanging? + & The deep mountains of karma— + & We cross them today + & And we shall not have superficial dreams + & Nor be deluded + LINK : http://rendakud.tumblr.com/post/156991025541/iroha-poem + +THE WAY + DATE : 12018-08-06 + PERS : ypm + SRCE : Merveilles + TYPE : quote + QOTE + > Therefore the wise go about doing nothing, teaching no-talking. + & The ten thousand things rise and fall without cease, + & Creating, yet not possessing, + & Working, yet not taking credit. + & Working, yet not taking credit. + & Work i_____HERE_____orgotten. + & Therefore it lasts forever. + LINK : http://peacefulrivers.homestead.com/laotzu.html + +COMMON GROUND + DATE : 12018-08-09 + TYPE : podcast + LINK : http://rationallyspeakingpodcast.org/show/rs-214-anthony-aguirre-on-predicting-the-future-of-science-a.html + QOTE + > "When we're exchanging individual sound bites or one paragraph arguments it's really easy to find ways to disagree with people and have lots of contention where as if you take the time to sort of engage in a little bit more a full way with a book or with a person or with multi paragraphs - the common ground is there if you look for it at all... I think looking for that common ground and then working your way back from there to see... now that we have that common ground where are the places that we disagree and can we identify why? Its just a so much more pleasent way of interacting with different ideas and different people than... saying OK my premise is that they think this and I think that and so we are in disagreement, now how am I going to defend my point of view..." - Anthony Aguirre on Rationally Speaking podcast #214 @ 44:30+ + SEEN : true + +CLEAR TAMEI + DATE : 12018-08-09 + LINK : https://iglooghost.bandcamp.com/album/clear-tamei + TYPE : music + SEEN : true + +STEEL MOGU + DATE : 12018-08-09 + LINK : https://iglooghost.bandcamp.com/album/steel-mogu + TYPE : music + SEEN : false + +WATER WARS + DATE : 12018-08-09 + PERS : neauoire + SRCE : Merveilles + LINK : https://www.thenation.com/article/the-future-of-climate-change-is-widespread-civil-war/ + TYPE : article + SEEN : true + TAGS : env + +BROWSER TIMELINE + DATE : 12018-08-09 + PERS : neauoire + SRCE : Merveilles + LINK : https://en.wikipedia.org/wiki/Timeline_of_web_browsers + TYPE : article + TAGS : web + +DARPA WEB + DATE : 12018-08-09 + PERS : neauoire + SRCE : Merveilles + LINK : https://medium.com/@giacomo_59737/the-web-is-still-a-darpa-weapon-31e3c3b032b8 + TYPE : article + TAGS : web \ No newline at end of file From dfc294ad86a1ff03f0287a09d1ea9360a30d7ef1 Mon Sep 17 00:00:00 2001 From: kor Date: Thu, 9 Aug 2018 03:49:00 +1200 Subject: [PATCH 12/14] Update add. Messy but working correctly. --- docs/index.html | 3 --- docs/logic/add.js | 14 +++++++------- docs/logic/main.js | 26 ++++++++++++++++++++++---- docs/logic/wrap.js | 4 ++-- docs/logic/write.js | 23 ----------------------- foo.txt | 1 - main.js | 38 +++++++++++++++++++++++++++++++++----- 7 files changed, 64 insertions(+), 45 deletions(-) delete mode 100644 docs/logic/write.js delete mode 100644 foo.txt diff --git a/docs/index.html b/docs/index.html index 75fc2da..0c4beb1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -19,12 +19,10 @@ - -
@@ -35,7 +33,6 @@ \ No newline at end of file diff --git a/docs/logic/add.js b/docs/logic/add.js index f306bea..1e5429a 100644 --- a/docs/logic/add.js +++ b/docs/logic/add.js @@ -1,6 +1,4 @@ const { ipcRenderer } = nodeRequire('electron'); -// const mainProcess = remote.nodeRequire('./main.js'); -//const mainProcess = nodeRequire('./main.js'); function Add() { @@ -95,7 +93,10 @@ function Add() () => { console.log('called write'); - ipcRenderer.send('write', '
'+this.display.innerHTML); + let content = this.display.innerHTML.replace(/\s?()\s?/g, "\r\n"); // replace line breaks + content = content.replace(/ /g, ' '); // replace tabs/spaces + // var content = content.replace(/\u00a0/g, ' '); + ipcRenderer.send('write', "\r\n" + "\r\n" + content); }); for (var i = 0; i < this.keys.length; i++) @@ -164,15 +165,16 @@ function Add() { if (parent.elementList[parent.keys[i]].elem.value != '') { - value += parent.elementList[parent.keys[i]].elem.value.toUpperCase() + '
' + value += parent.elementList[parent.keys[i]].elem.value.toUpperCase(); } else { - value += 'TITLE
'; + value += 'TITLE'; } } else if (parent.elementList[parent.keys[i]].elem.value != '') { + value += '
'; value += '  '; value += parent.elementList[parent.keys[i]].desc.toUpperCase() + ' : '; @@ -207,8 +209,6 @@ function Add() { value += parent.elementList[parent.keys[i]].elem.value.toLowerCase(); } - - value += '
'; } } parent.display.innerHTML = value; diff --git a/docs/logic/main.js b/docs/logic/main.js index d508db0..7e20ece 100644 --- a/docs/logic/main.js +++ b/docs/logic/main.js @@ -6,23 +6,41 @@ function Main() this.write = null; this.queryPrev = ''; this.queryCur = ''; + var parent = this; this.install = function() { - this.db = new Wrap(DATABASE); - this.db.install(); + let dbLoaded = false; + const FILELOCATION = 'content/data.ndtl'; + var client = new XMLHttpRequest(); + client.open('GET', FILELOCATION); + client.onreadystatechange = function() + { + if (!dbLoaded && client.responseText.trim() != '') + { + dbLoaded = true; + parent.setup(client.responseText); + } + } + client.send(); + } + + this.setup = function(data) + { + this.db = new Wrap(); + this.db.install(data); this.view = new View(); this.view.install(); this.add = new Add(); this.add.install(); - this.write = new Write(); - this.write.install(); var escape = document.getElementById("escape"); escape.onclick = function() { main.load(main.queryPrev); } + + this.start(); } this.start = function() diff --git a/docs/logic/wrap.js b/docs/logic/wrap.js index 86f72e0..4ee3409 100644 --- a/docs/logic/wrap.js +++ b/docs/logic/wrap.js @@ -3,9 +3,9 @@ function Wrap() this.database = null; this.keys = null; - this.install = function() + this.install = function(data) { - this.database = new Indental(DATABASE).parse(); + this.database = new Indental(data).parse(); this.keys = Object.keys(this.database); this.process(); } diff --git a/docs/logic/write.js b/docs/logic/write.js deleted file mode 100644 index 2c85da7..0000000 --- a/docs/logic/write.js +++ /dev/null @@ -1,23 +0,0 @@ - -function Write() -{ - - this.install = function() - { - } - - this.insert = function(data) - { - let position = 5; // get insert position - - let foo = fs.openSync('foo.txt','r+'); - let buf = new Buffer("hello"); - fs.writeSync(foo, buf, 0, buf.length, position); - fs.close(foo); - } -} - -// fs.appendFile('mynewfile1.txt', 'Hello content!', function (err) { -// if (err) throw err; -// console.log('Saved!'); -// }); \ No newline at end of file diff --git a/foo.txt b/foo.txt deleted file mode 100644 index e2e107a..0000000 --- a/foo.txt +++ /dev/null @@ -1 +0,0 @@ -123456789 \ No newline at end of file diff --git a/main.js b/main.js index 6285a48..8a8f9f8 100644 --- a/main.js +++ b/main.js @@ -4,6 +4,7 @@ const url = require('url') const shell = require('electron').shell; const fs = require('fs'); const { ipcMain } = require('electron'); +const FILELOCATION = 'docs/content/data.ndtl'; let is_shown = true; @@ -94,10 +95,37 @@ app.on('activate', () => { ipcMain.on('write', (event, arg) => { - console.log('Write called! Entry = ' + arg); + // var fileLength = fs.statSync(FILELOCATION)['size']; + // console.log('Write called! Length = ' + fileLength); + // console.log('Write called! Entry = ' + arg); - let foo = fs.openSync('foo.txt','r+'); - let buf = new Buffer(arg); - fs.writeSync(foo, buf, 0, buf.length, 5); - fs.close(foo); + // const stream = fs.createReadStream(FILELOCATION, { encoding: 'utf8' }); + // stream.on('data', data => { + // header = data.split(/\n/)[0]; + // stream.destroy(); + // }); + // stream.on('close', () => { + // console.timeEnd(label); + // resolve(); + // }); + + // fs.readFile(FILELOCATION, "utf8", + // function(err, data) + // { + // console.log(data); + // var position = data.lastIndexOf('`'); + // console.log('Write called! position = ' + position); + + // let fileStream = fs.openSync(FILELOCATION, 'r+'); + // // let buf = new Buffer(arg); + // let buf = new Buffer('_____HERE_____'); + // fs.writeSync(fileStream, buf, 0, buf.length, position); + // fs.close(fileStream); + // } + // ); + + fs.appendFile(FILELOCATION, arg, function (err) { + if (err) throw err; + console.log('Saved!'); + }); }); \ No newline at end of file From 8d2eed7f3cb9291356a0ed96ccc32e8141f431a3 Mon Sep 17 00:00:00 2001 From: kor Date: Thu, 9 Aug 2018 04:32:54 +1200 Subject: [PATCH 13/14] Refactor. Clean up and fixing electron version write functionality breaking web version. --- docs/index.html | 8 ----- docs/logic/main.js | 7 ++-- main.js | 89 ++++++++++++++++++++-------------------------- preload.js | 4 +++ 4 files changed, 46 insertions(+), 62 deletions(-) create mode 100644 preload.js diff --git a/docs/index.html b/docs/index.html index 0c4beb1..ed97631 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,15 +5,7 @@ memex - - - diff --git a/docs/logic/main.js b/docs/logic/main.js index 7e20ece..d02afcb 100644 --- a/docs/logic/main.js +++ b/docs/logic/main.js @@ -7,18 +7,17 @@ function Main() this.queryPrev = ''; this.queryCur = ''; var parent = this; + const FILELOCATION = 'content/data.ndtl'; this.install = function() { - let dbLoaded = false; - const FILELOCATION = 'content/data.ndtl'; var client = new XMLHttpRequest(); client.open('GET', FILELOCATION); client.onreadystatechange = function() { - if (!dbLoaded && client.responseText.trim() != '') + if (client.responseText.trim() != '') { - dbLoaded = true; + client.onreadystatechange = null; parent.setup(client.responseText); } } diff --git a/main.js b/main.js index 8a8f9f8..8e47962 100644 --- a/main.js +++ b/main.js @@ -29,10 +29,27 @@ app.toggle_fullscreen = function() app.toggle_visible = function() { - if(process.platform == "win32"){ - if(!app.win.isMinimized()){ app.win.minimize(); } else{ app.win.restore(); } - } else { - if(is_shown){ app.win.hide(); } else{ app.win.show(); } + if(process.platform == "win32") + { + if(!app.win.isMinimized()) + { + app.win.minimize(); + } + else + { + app.win.restore(); + } + } + else + { + if(is_shown) + { + app.win.hide(); + } + else + { + app.win.show(); + } } } @@ -50,34 +67,33 @@ app.win = null; app.on('ready', () => { - app.win = new BrowserWindow({ - webPreferences: { - nodeIntegration: true - }, width: 950, height: 950, backgroundColor:"#ddd", minWidth: 587, minHeight: 540, frame:true, autoHideMenuBar: true, icon: __dirname + '/icon.ico'}) + app.win = new BrowserWindow( + { + webPreferences: + { + nodeIntegration: true, + preload: path.join(__dirname, 'preload.js') + }, width: 950, height: 950, backgroundColor:"#ddd", minWidth: 587, minHeight: 540, frame:true, autoHideMenuBar: true, icon: __dirname + '/icon.ico' + }) app.win.loadURL(`file://${__dirname}/docs/index.html`); - // app.win.toggleDevTools(); - app.win.on('closed', () => { + app.win.on('closed', () => + { win = null app.quit() }) - app.win.on('hide',function() { + app.win.on('hide', function() + { is_shown = false; }) - app.win.on('show',function() { + app.win.on('show', function() + { is_shown = true; }) - // app.win.webContents.on('new-window', function(event, url){ - // event.preventDefault(); - // // open(url); - // console.log('CALLED NEW WIN'); - // child_process.execSync('start ' + url) - // }) - app.win.webContents.on('will-navigate', this.handleRedirect) app.win.webContents.on('new-window', this.handleRedirect) }) @@ -87,7 +103,8 @@ app.on('window-all-closed', () => app.quit() }) -app.on('activate', () => { +app.on('activate', () => +{ if (app.win === null) { createWindow() } @@ -95,36 +112,8 @@ app.on('activate', () => { ipcMain.on('write', (event, arg) => { - // var fileLength = fs.statSync(FILELOCATION)['size']; - // console.log('Write called! Length = ' + fileLength); - // console.log('Write called! Entry = ' + arg); - - // const stream = fs.createReadStream(FILELOCATION, { encoding: 'utf8' }); - // stream.on('data', data => { - // header = data.split(/\n/)[0]; - // stream.destroy(); - // }); - // stream.on('close', () => { - // console.timeEnd(label); - // resolve(); - // }); - - // fs.readFile(FILELOCATION, "utf8", - // function(err, data) - // { - // console.log(data); - // var position = data.lastIndexOf('`'); - // console.log('Write called! position = ' + position); - - // let fileStream = fs.openSync(FILELOCATION, 'r+'); - // // let buf = new Buffer(arg); - // let buf = new Buffer('_____HERE_____'); - // fs.writeSync(fileStream, buf, 0, buf.length, position); - // fs.close(fileStream); - // } - // ); - - fs.appendFile(FILELOCATION, arg, function (err) { + fs.appendFile(FILELOCATION, arg, function (err) + { if (err) throw err; console.log('Saved!'); }); diff --git a/preload.js b/preload.js new file mode 100644 index 0000000..2456569 --- /dev/null +++ b/preload.js @@ -0,0 +1,4 @@ +window.nodeRequire = require; +delete window.require; +delete window.exports; +delete window.module; \ No newline at end of file From 28b3f2db292efb8464b29f038a358db9f8953021 Mon Sep 17 00:00:00 2001 From: kor Date: Fri, 10 Aug 2018 03:18:32 +1200 Subject: [PATCH 14/14] Fix write add functionality breaking web version. --- docs/logic/add.js | 531 +++++++++++++++++++++++---------------------- docs/logic/main.js | 16 +- docs/logic/view.js | 5 +- preload.js | 4 +- 4 files changed, 284 insertions(+), 272 deletions(-) diff --git a/docs/logic/add.js b/docs/logic/add.js index 1e5429a..7bb0cb1 100644 --- a/docs/logic/add.js +++ b/docs/logic/add.js @@ -1,294 +1,297 @@ -const { ipcRenderer } = nodeRequire('electron'); - -function Add() +if (window.showAdd != undefined && window.showAdd) { - this.overlay = null; - this.display = null; - this.grid = null; + const { ipcRenderer } = nodeRequire('electron'); - this.elementList = []; - this.keys = null; - var parent = this; - - // STATE - this.enabledOverlay = false; - this.addedTitle = false - this.addedDate = false - this.addedPerson = false - this.addedSource = false - this.addedProject = false - this.addedType = false - this.addedLink = false - this.addedTags = false - this.addedNote = false - this.addedQuote = false - this.addedTerms = false - this.addedProgress = false - - this.install = function() + function Add() { - this.grid = document.getElementById("grid"); - this.overlay = document.getElementById("overlay"); + this.overlay = null; + this.display = null; + this.grid = null; + + this.elementList = []; + this.keys = null; + var parent = this; + + // STATE + this.enabledOverlay = false; + this.addedTitle = false + this.addedDate = false + this.addedPerson = false + this.addedSource = false + this.addedProject = false + this.addedType = false + this.addedLink = false + this.addedTags = false + this.addedNote = false + this.addedQuote = false + this.addedTerms = false + this.addedProgress = false + + this.install = function() + { + this.grid = document.getElementById("grid"); + this.overlay = document.getElementById("overlay"); + + this.setupElement('Title', 'TITLE', 'upper'); + this.setupElement('Date', 'DATE', 'lower'); + this.setupElement('Type', 'TYPE', 'lower'); + this.setupElement('Link', 'LINK', 'url'); + this.setupElement('Person', 'PERS', 'text'); + this.setupElement('Source', 'SRCE', 'title'); + this.setupElement('Project', 'PROJ', 'text'); + this.setupElement('Tags', 'TAGS', 'tags'); + this.setupElement('Progress', 'PROG', 'text'); + this.setupElement('Note', 'NOTE', 'text'); // long + this.setupElement('Quote', 'QOTE', 'quote'); // long + this.setupElement('Terms', 'TERM', 'quote'); // long + // DONE + // REVI + this.keys = Object.keys(this.elementList); + + // SETUP + this.overlay.innerHTML = ''; + let content = `
` + + // ESCAPE + content += ``; + + // FORM + content += `
`; + for (var i = 0; i < this.keys.length; i++) + { + content += `
+
${this.elementList[this.keys[i]].desc}
+ +
`; + } + content += `
`; + + // DISPLAY + content += `
`; + content += `
`; + + // ENTER + content += ``; - this.setupElement('Title', 'TITLE', 'upper'); - this.setupElement('Date', 'DATE', 'lower'); - this.setupElement('Type', 'TYPE', 'lower'); - this.setupElement('Link', 'LINK', 'url'); - this.setupElement('Person', 'PERS', 'text'); - this.setupElement('Source', 'SRCE', 'title'); - this.setupElement('Project', 'PROJ', 'text'); - this.setupElement('Tags', 'TAGS', 'tags'); - this.setupElement('Progress', 'PROG', 'text'); - this.setupElement('Note', 'NOTE', 'text'); // long - this.setupElement('Quote', 'QOTE', 'quote'); // long - this.setupElement('Terms', 'TERM', 'quote'); // long - // DONE - // REVI - this.keys = Object.keys(this.elementList); + content += `
`; - // SETUP - this.overlay.innerHTML = ''; - let content = `
` + this.overlay.innerHTML += content; - // ESCAPE - content += ``; + this.display = document.getElementById("display"); - // FORM - content += `
`; - for (var i = 0; i < this.keys.length; i++) - { - content += `
-
${this.elementList[this.keys[i]].desc}
- -
`; + document.getElementById("enter").addEventListener('click', + () => + { + console.log('called write'); + let content = this.display.innerHTML.replace(/\s?()\s?/g, "\r\n"); // replace line breaks + content = content.replace(/ /g, ' '); // replace tabs/spaces + // var content = content.replace(/\u00a0/g, ' '); + ipcRenderer.send('write', "\r\n" + "\r\n" + content); + }); + + for (var i = 0; i < this.keys.length; i++) + { + this.elementList[this.keys[i]].elem = document.getElementById(this.elementList[this.keys[i]].key); + this.elementList[this.keys[i]].elem.oninput = this.onElemChanged; + this.elementList[this.keys[i]].elem.onfocus = this.onElemFocus; + this.elementList[this.keys[i]].elem.onblur = this.onElemBlur; + this.elementList[this.keys[i]].elemKey = document.getElementById("key" + this.elementList[this.keys[i]].key); + } + setTimeout(function() + { + parent.setupData(); + }, 100); } - content += ``; - // DISPLAY - content += `
`; - content += `
`; - - // ENTER - content += ``; - - content += `
`; - - this.overlay.innerHTML += content; - - this.display = document.getElementById("display"); - - document.getElementById("enter").addEventListener('click', - () => + this.setupElement = function(key, desc, type) { - console.log('called write'); - let content = this.display.innerHTML.replace(/\s?()\s?/g, "\r\n"); // replace line breaks - content = content.replace(/ /g, ' '); // replace tabs/spaces - // var content = content.replace(/\u00a0/g, ' '); - ipcRenderer.send('write', "\r\n" + "\r\n" + content); - }); - - for (var i = 0; i < this.keys.length; i++) - { - this.elementList[this.keys[i]].elem = document.getElementById(this.elementList[this.keys[i]].key); - this.elementList[this.keys[i]].elem.oninput = this.onElemChanged; - this.elementList[this.keys[i]].elem.onfocus = this.onElemFocus; - this.elementList[this.keys[i]].elem.onblur = this.onElemBlur; - this.elementList[this.keys[i]].elemKey = document.getElementById("key" + this.elementList[this.keys[i]].key); + this.elementList[key] = { key: key, desc: desc, type: type, added: false}; } - setTimeout(function() - { + + this.onElemChanged = function(e) + { + // TODO: Autocomplete tags, type parent.setupData(); - }, 100); - } - - this.setupElement = function(key, desc, type) - { - this.elementList[key] = { key: key, desc: desc, type: type, added: false}; - } - - this.onElemChanged = function(e) - { - // TODO: Autocomplete tags, type - parent.setupData(); - } - - this.onElemFocus = function(e) - { - for (var i = 0; i < parent.keys.length; i++) - { - if (e.target.id == parent.elementList[parent.keys[i]].key) - { - if (!parent.elementList[parent.keys[i]].added) - { - parent.elementList[parent.keys[i]].added = true; - parent.elementList[parent.keys[i]].elemKey.style.visibility = "visible"; - } - break; - } } - } - this.onElemBlur = function(e) - { - for (var i = 0; i < parent.keys.length; i++) + this.onElemFocus = function(e) { - if (e.target.id == parent.elementList[parent.keys[i]].key) + for (var i = 0; i < parent.keys.length; i++) { - if (parent.elementList[parent.keys[i]].elem.value == '' && parent.elementList[parent.keys[i]].added) + if (e.target.id == parent.elementList[parent.keys[i]].key) { - parent.elementList[parent.keys[i]].added = false; - parent.elementList[parent.keys[i]].elemKey.style.visibility = "hidden"; - } - break; - } - } - } - - this.setupData = function() - { - let value = ''; - for (var i = 0; i < parent.keys.length; i++) - { - if (parent.elementList[parent.keys[i]].key == 'Title') - { - if (parent.elementList[parent.keys[i]].elem.value != '') - { - value += parent.elementList[parent.keys[i]].elem.value.toUpperCase(); - } - else - { - value += 'TITLE'; - } - } - else if (parent.elementList[parent.keys[i]].elem.value != '') - { - value += '
'; - value += '  '; - value += parent.elementList[parent.keys[i]].desc.toUpperCase() + ' : '; - - if (parent.elementList[parent.keys[i]].type == 'lower') - { - value += parent.elementList[parent.keys[i]].elem.value.toLowerCase(); - } - else if (parent.elementList[parent.keys[i]].type == 'text') - { - value += parent.elementList[parent.keys[i]].elem.value; - } - else if (parent.elementList[parent.keys[i]].type == 'url') - { - // TODO: validate - value += parent.elementList[parent.keys[i]].elem.value; - } - else if (parent.elementList[parent.keys[i]].type == 'tags') - { - // TODO: Format - value += parent.elementList[parent.keys[i]].elem.value; - } - else if (parent.elementList[parent.keys[i]].type == 'quote') - { - // TODO: Format - value += parent.elementList[parent.keys[i]].elem.value; - } - else if (parent.elementList[parent.keys[i]].type == 'title') - { - value += parent.elementList[parent.keys[i]].elem.value.toProperCase(); - } - else if (parent.elementList[parent.keys[i]].type == 'upper') - { - value += parent.elementList[parent.keys[i]].elem.value.toLowerCase(); + if (!parent.elementList[parent.keys[i]].added) + { + parent.elementList[parent.keys[i]].added = true; + parent.elementList[parent.keys[i]].elemKey.style.visibility = "visible"; + } + break; } } } - parent.display.innerHTML = value; - } - this.show = function() - { - this.setOverlay(true); - - var date = new Date(); - var dateString = "1" + date.getFullYear() - + "-" + ("0"+(date.getMonth()+1)).slice(-2) - + "-" + ("0" + date.getDate()).slice(-2); - this.elementList['Date'].elem.value = dateString; - this.elementList['Date'].added = true; - this.elementList['Date'].elemKey.style.visibility = "visible"; - - setTimeout(function() - { - parent.elementList['Title'].elem.focus(); - }, 100); - } - - this.setOverlay = function(value) - { - if (value && !this.enabledOverlay) + this.onElemBlur = function(e) { - overlay.style.opacity = '1'; - overlay.style.zIndex = '1000'; - this.enabledOverlay = true; + for (var i = 0; i < parent.keys.length; i++) + { + if (e.target.id == parent.elementList[parent.keys[i]].key) + { + if (parent.elementList[parent.keys[i]].elem.value == '' && parent.elementList[parent.keys[i]].added) + { + parent.elementList[parent.keys[i]].added = false; + parent.elementList[parent.keys[i]].elemKey.style.visibility = "hidden"; + } + break; + } + } + } + + this.setupData = function() + { + let value = ''; + for (var i = 0; i < parent.keys.length; i++) + { + if (parent.elementList[parent.keys[i]].key == 'Title') + { + if (parent.elementList[parent.keys[i]].elem.value != '') + { + value += parent.elementList[parent.keys[i]].elem.value.toUpperCase(); + } + else + { + value += 'TITLE'; + } + } + else if (parent.elementList[parent.keys[i]].elem.value != '') + { + value += '
'; + value += '  '; + value += parent.elementList[parent.keys[i]].desc.toUpperCase() + ' : '; + + if (parent.elementList[parent.keys[i]].type == 'lower') + { + value += parent.elementList[parent.keys[i]].elem.value.toLowerCase(); + } + else if (parent.elementList[parent.keys[i]].type == 'text') + { + value += parent.elementList[parent.keys[i]].elem.value; + } + else if (parent.elementList[parent.keys[i]].type == 'url') + { + // TODO: validate + value += parent.elementList[parent.keys[i]].elem.value; + } + else if (parent.elementList[parent.keys[i]].type == 'tags') + { + // TODO: Format + value += parent.elementList[parent.keys[i]].elem.value; + } + else if (parent.elementList[parent.keys[i]].type == 'quote') + { + // TODO: Format + value += parent.elementList[parent.keys[i]].elem.value; + } + else if (parent.elementList[parent.keys[i]].type == 'title') + { + value += parent.elementList[parent.keys[i]].elem.value.toProperCase(); + } + else if (parent.elementList[parent.keys[i]].type == 'upper') + { + value += parent.elementList[parent.keys[i]].elem.value.toLowerCase(); + } + } + } + parent.display.innerHTML = value; + } + + this.show = function() + { + this.setOverlay(true); + + var date = new Date(); + var dateString = "1" + date.getFullYear() + + "-" + ("0"+(date.getMonth()+1)).slice(-2) + + "-" + ("0" + date.getDate()).slice(-2); + this.elementList['Date'].elem.value = dateString; + this.elementList['Date'].added = true; + this.elementList['Date'].elemKey.style.visibility = "visible"; + setTimeout(function() - { - this.grid.innerHTML = ''; - this.grid.style.height = 0; - }, 200); + { + parent.elementList['Title'].elem.focus(); + }, 100); } - else if (!value && this.enabledOverlay) - { - overlay.style.opacity = '0'; - setTimeout(function() - { - overlay.style.zIndex = '-100'; - }, 200); - this.enabledOverlay = false; - } - } -} -String.prototype.toProperCase = function () { - return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); -}; - -document.onkeydown = function(evt) -{ - evt = evt || window.event; - if (!evt.ctrlKey) - { - var isEscape = false; - var isA = false; - - if ("key" in evt) + this.setOverlay = function(value) { - isEscape = (evt.key == "Escape" || evt.key == "Esc"); - } - else - { - isEscape = (evt.keyCode == 27); - } - isA = (evt.keyCode == 65); - - if (isEscape) - { - if (main.queryCur == 'add') + if (value && !this.enabledOverlay) { - main.load(main.queryPrev); + overlay.style.opacity = '1'; + overlay.style.zIndex = '1000'; + this.enabledOverlay = true; + setTimeout(function() + { + this.grid.innerHTML = ''; + this.grid.style.height = 0; + }, 200); + } + else if (!value && this.enabledOverlay) + { + overlay.style.opacity = '0'; + setTimeout(function() + { + overlay.style.zIndex = '-100'; + }, 200); + this.enabledOverlay = false; } } - else if (isA && main.queryCur != 'add') - { - main.load('add'); - } } -}; \ No newline at end of file + + String.prototype.toProperCase = function () { + return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); + }; + + document.onkeydown = function(evt) + { + evt = evt || window.event; + if (!evt.ctrlKey) + { + var isEscape = false; + var isA = false; + + if ("key" in evt) + { + isEscape = (evt.key == "Escape" || evt.key == "Esc"); + } + else + { + isEscape = (evt.keyCode == 27); + } + isA = (evt.keyCode == 65); + + if (isEscape) + { + if (main.queryCur == 'add') + { + main.load(main.queryPrev); + } + } + else if (isA && main.queryCur != 'add') + { + main.load('add'); + } + } + }; +} \ No newline at end of file diff --git a/docs/logic/main.js b/docs/logic/main.js index d02afcb..e648eba 100644 --- a/docs/logic/main.js +++ b/docs/logic/main.js @@ -13,7 +13,8 @@ function Main() { var client = new XMLHttpRequest(); client.open('GET', FILELOCATION); - client.onreadystatechange = function() + client.overrideMimeType("text/plain"); + client.onreadystatechange = function(req, res) { if (client.responseText.trim() != '') { @@ -30,13 +31,16 @@ function Main() this.db.install(data); this.view = new View(); this.view.install(); - this.add = new Add(); - this.add.install(); - var escape = document.getElementById("escape"); - escape.onclick = function() + if (window.showAdd != undefined && window.showAdd) { - main.load(main.queryPrev); + this.add = new Add(); + this.add.install(); + var escape = document.getElementById("escape"); + escape.onclick = function() + { + main.load(main.queryPrev); + } } this.start(); diff --git a/docs/logic/view.js b/docs/logic/view.js index 4b23361..bfb26ac 100644 --- a/docs/logic/view.js +++ b/docs/logic/view.js @@ -49,7 +49,10 @@ function View() this.display = function(db) { - main.add.setOverlay(false); + if (window.showAdd != undefined && window.showAdd) + { + main.add.setOverlay(false); + } // BUILD this.grid.innerHTML = ''; diff --git a/preload.js b/preload.js index 2456569..ab00e21 100644 --- a/preload.js +++ b/preload.js @@ -1,4 +1,6 @@ window.nodeRequire = require; delete window.require; delete window.exports; -delete window.module; \ No newline at end of file +delete window.module; + +// window.showAdd = true; \ No newline at end of file