Skip to content

Commit

Permalink
Add multinote support
Browse files Browse the repository at this point in the history
  • Loading branch information
mesacarlos committed May 5, 2019
1 parent e3fb367 commit 34005a7
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 16 deletions.
16 changes: 8 additions & 8 deletions browserNotes2.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
<!--- BrowserNotes 2 --->
<script src="script/service.js"></script>
<script defer src="script/lang.js"></script>
<script src="script/notemanager.js"></script>
<script src="script/utils.js"></script>
<script src="script/fileReader.js"></script>
<script src="script/fileWriter.js"></script>
</head>
<body>
<nav class="navbar navbar-light bg-light">
<div class="negrita" id="title" contenteditable onkeypress="reflectChangesOnJson()">Your browser does not support this script</div>
<div class="negrita" id="title" contenteditable onkeyup="reflectChangesOnJson();updateNotesList();">Your browser does not support this script</div>
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link disabled" id="info"></a>
Expand All @@ -41,28 +42,27 @@
<a class="dropdown-item" href="#" id="glinkbtn" onclick="saveToLink()"></a>
</div>
</li>
<li class="nav-item dropdown" style="display: none;">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" id="note-dropdown">Note</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#" id="addNote" onclick="addNote()">Añadir nota</a>
<a class="dropdown-item" href="#" id="deleteNote" onclick="deleteNote()">Borrar nota</a>
<div class="dropdown-menu" id="noteslist">
<a class="dropdown-item" href="#" id="addNote" onclick="addNote()"></a>
<a class="dropdown-item" href="#" id="deleteNote" onclick="deleteNote()"></a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#" onclick="openNote(0)">Por defecto</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#" id="chpwd" onclick="chPwd(lang.change_password)"></a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" id="lang-dropdown">Language</a>
<div class="dropdown-menu">
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#" onclick="setLanguage('en_US')">English</a>
<a class="dropdown-item" href="#" onclick="setLanguage('es_ES')">Español</a>
</div>
</li>
</ul>
</nav>
<div class="main" id="main" contenteditable onkeypress="reflectChangesOnJson()">Your browser does not support this script. Please check JavaScript is enabled and try again.</div>
<div class="main" id="main" contenteditable onkeyup="reflectChangesOnJson()">Your browser does not support this script. Please check JavaScript is enabled and try again.</div>
<label for="file-load" class="oculto">Etiqueta</label><input type="file" name="file-load" id="file-load" class="oculto" accept=".AESjson" onchange="loadFile(this)">

<!-- Password set Modal start -->
Expand Down
13 changes: 11 additions & 2 deletions script/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function setLanguage(locale){
"password_modal": "Password",
"file_loaded": "File loaded successfully.",
"save_storage": "Save to WebStorage",
"load_storage": "Load from WebStorage"
"load_storage": "Load from WebStorage",
"note": "Note",
"add_note": "Add note",
"delete_note": "Delete note"
}
break;
case "es_ES":
Expand Down Expand Up @@ -62,7 +65,10 @@ function setLanguage(locale){
"password_modal": "Contraseña",
"file_loaded": "Archivo cargado con éxito.",
"save_storage": "Guardar WebStorage",
"load_storage": "Leer WebStorage"
"load_storage": "Leer WebStorage",
"note": "Nota",
"add_note": "Añadir nota",
"delete_note": "Borrar nota"
}
break;
default:
Expand All @@ -86,6 +92,9 @@ function setLanguage(locale){
document.getElementById("modalChangePasswordTitle").textContent = lang.password_modal;
document.getElementById("modalChangePasswordInput1").placeholder = lang.password_modal;
document.getElementById("modalChangePasswordInput2").placeholder = lang.pwd_change_confirm;
document.getElementById("note-dropdown").textContent = lang.note;
document.getElementById("addNote").textContent = lang.add_note;
document.getElementById("deleteNote").textContent = lang.delete_note;
if(!oldLang || oldLang.note_title == getTitle())
document.getElementById("title").innerText = lang.note_title;
if(!oldLang || oldLang.note_content == getText())
Expand Down
69 changes: 69 additions & 0 deletions script/notemanager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Initializes note
*/
function initializeNotes(){
index = 0;
jsonFile = new Object();
jsonFile.version = 1;
jsonFile.notes = new Array();
jsonFile.notes[index] = new Object();

//Set default phrases
document.getElementById("title").innerText = lang.note_title;
document.getElementById("main").innerText = lang.note_content;
reflectChangesOnJson();
}

/**
* Add a note to document
*/
function addNote(){
//1. Save actual note before unloading it from view
reflectChangesOnJson();

//2. Create new note and show it
index = jsonFile.notes.length;
jsonFile.notes[index] = new Object();
document.getElementById("title").innerText = lang.note_title;
document.getElementById("main").innerText = lang.note_content;

//3. Update jsonFile and add it to menu (navbar)
reflectChangesOnJson();
updateNotesList();
}

/**
* Delete a note from document
*/
function deleteNote(){
jsonFile.notes.splice(index, 1); //Delete note from object
index = jsonFile.notes.length - 1; //Point to last note in array
if(index == -1){
initializeNotes(); //Reinitialize notes as they are all deleted
}else{
updateVisibleNote(); //Show the last note
}
updateNotesList();
}

/**
* Update notes from dropdown at navbar
*/
function updateNotesList(){
//Delete all notes in dropdown
$('.notemenuitem').remove();

//Add all other notes
for(var i = 0; i < jsonFile.notes.length; i++){
$('#noteslist').append('<a class="dropdown-item notemenuitem" href="#" onclick="openNote(' + i + ')">' + jsonFile.notes[i].title + '</a>');
}
}

/**
* Opens a note
*/
function openNote(noteToView){
reflectChangesOnJson();
index = noteToView;
updateVisibleNote();
}
10 changes: 4 additions & 6 deletions script/service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Encriptador v2.2
Encriptador v2.3
https://github.com/mesacarlos
(c) 2018-2019 Carlos Mesa. All rights reserved.
*/
Expand All @@ -14,14 +14,11 @@ var pendingEncryptedJson;
* Also, check for possible notes in the URL. If set, load saved note and ask for password.
*/
$(document).ready(function() {
index = 0;
jsonFile = new Object();
jsonFile.version = 1;
jsonFile.notes = new Array();
jsonFile.notes[index] = new Object();
initializeNotes();
if(window.location.search){
loadURL();
}
updateNotesList();
});

/**
Expand Down Expand Up @@ -106,6 +103,7 @@ function decrypt(encryptedJson){
throw "Password Incorrect";
jsonFile = JSON.parse(result);
updateVisibleNote();
updateNotesList();
showInfo(lang.file_loaded);
} catch (e) {
//Password is not correct or is not defined and must be prompted.
Expand Down

0 comments on commit 34005a7

Please sign in to comment.