Skip to content

Commit d9ddaa1

Browse files
authored
Merge pull request #46 from Offerel/dev
- Added loader animation - Added option to remove media - Added Option to disable displayed formats - Added automatic ToC creation - Replaced tag library with [tagify v3.22.1](https://github.com/yairEO/tagify) - Removed HTML Format - Reduced http requests to speed up - Fixed empty response when delete a note
2 parents 155da8c + aaadb8c commit d9ddaa1

17 files changed

+225
-243
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
### v2.0.0
22
- Added loader animation
3-
- Add option to remove media
3+
- Added option to remove media
4+
- Added Option to disable displayed formats
5+
- Added automatic ToC creation
46
- Replaced tag library with [tagify v3.22.1](https://github.com/yairEO/tagify)
57
- Removed HTML Format
68
- Reduced http requests to speed up
9+
- Fixed empty response when delete a note
710

811
### v1.5.8
912
- Changed Markdown Editor to [EasyMD v2.13.0](https://github.com/ionaru/easy-markdown-editor)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# PrimitiveNotes Plugin (Roundcube)
2-
This is a simple notes plugin for Roundcube. Mainly notes in Markdown format, but also images (jpg, png) and PDF files are supported. The files are stored in a compatible format to TagSpaces, so that you can transfer these notes directly.
2+
This is a simple notes plugin for Roundcube. Mainly notes in Markdown, but also images (jpg, png) and PDF files are supported. The files are stored in a name-compatible format to TagSpaces, so that you can transfer these notes directly.
33

44
# History
55
Originally, the idea for a standalone note app came from that I wanted to separate my notes from Evernote. Afterwards I ended up at TagSpaces. As TagSpace was too slow and extensive for me personally, I decided to develop my own app. This resulted first in a standalone project and was converted later to this plugin for Roundcube.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"homepage": "https://github.com/Offerel/roundcube_primitivenotes",
66
"type": "roundcube-plugin",
77
"license": "AGPL-3.0",
8-
"version": "1.5.9",
8+
"version": "2.0.0",
99
"authors": [
1010
{
1111
"name": "Offerel",

config.inc.php.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ $config['notes_basepath'] = '/path/to/server/folder/'; // absolute base! path wh
33
$config['notes_folder'] = '/files/Notes/'; // notes folder under basepath. in the end the folder is calculated by 'basepath' + 'username' + 'notes_folder'
44
$config['media_folder'] = '.media'; // folder to store embedded images or binary file like *.pdf
55
$config['default_format'] = 'md'; // default format, you can choose between 'md' or 'txt'
6+
$config['list_formats'] = ['md', 'txt']; // list of displayed formats, can be a combination of md, html, txt, pdf, jpg, png
67
$config['yaml_support'] = true; // set to true, if you want enable yaml support
78
$config['yaml_start'] = '---'; // the yaml header should starts as the first sign in a markdown note and is marked by default with '---'
89
$config['yaml_end'] = '---'; // the signs which marks the end of the yaml header

localization/de_DE.inc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ $labels['note_subject'] = 'Per E-Mail senden: ';
1515
$labels['note_formathtml'] = 'HTML';
1616
$labels['note_formatmd'] = 'Markdown';
1717
$labels['note_formattxt'] = 'Normaler Text';
18+
$labels['note_formatpdf'] = 'Adobe PDF';
19+
$labels['note_formatjpg'] = 'JPG';
20+
$labels['note_formatpng'] = 'PNG';
1821
$labels['ariallabelnewoptions'] = 'Optionen';
1922
$labels['note_defaultformat'] = 'Standard Format';
23+
$labels['note_listformat'] = 'Angezeigte Formate';
2024
$labels['note_yamls'] = 'Aktiviere YAML';
21-
$labels['note_rmedia_md'] = 'Lösche automatisch eingbettete Medien mit Markdown Files';
25+
$labels['note_rmedia_md'] = 'Eingbettete Medien automatisch löschen';
2226
?>

localization/en_US.inc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ $labels['note_del_note'] = 'Do you really want to delete "%note%"?';
1414
$labels['note_subject'] = 'Send by e-mail: ';
1515
$labels['note_formathtml'] = 'HTML';
1616
$labels['note_formatmd'] = 'Markdown';
17-
$labels['note_formattxt'] = 'Pure Text';
17+
$labels['note_formattxt'] = 'Plain Text';
18+
$labels['note_formatpdf'] = 'Adobe PDF';
19+
$labels['note_formatjpg'] = 'JPG';
20+
$labels['note_formatpng'] = 'PNG';
1821
$labels['ariallabelnewoptions'] = 'Options';
1922
$labels['note_defaultformat'] = 'Default Format';
23+
$labels['note_listformat'] = 'Displayed Formats';
2024
$labels['note_yamls'] = 'Enable YAML';
21-
$labels['note_rmedia_md'] = 'Remove automatically embedded Media with Markdown Files';
25+
$labels['note_rmedia_md'] = 'Remove automatically embedded Media';
2226
?>

localization/es_AR.inc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ $labels['note_subject'] = 'Enviar por correo: ';
1515
$labels['note_formathtml'] = 'HTML';
1616
$labels['note_formatmd'] = 'Markdown';
1717
$labels['note_formattxt'] = 'Texto Plano';
18+
$labels['note_formatpdf'] = 'Adobe PDF';
19+
$labels['note_formatjpg'] = 'JPG';
20+
$labels['note_formatpng'] = 'PNG';
1821
$labels['ariallabelnewoptions'] = 'Opciones';
1922
$labels['note_defaultformat'] = 'Formato estándar';
23+
$labels['note_listformat'] = 'Formatos mostrados';
2024
$labels['note_yamls'] = 'Activa YAML';
21-
$labels['note_rmedia_md'] = 'Elimina automáticamente los medios incrustados con Markdown Files';
25+
$labels['note_rmedia_md'] = 'Elimina automáticamente los medios incrustados';
2226
?>

localization/pt_BR.inc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ $labels['note_subject'] = 'Enviando por e-mail: ';
1515
$labels['note_formathtml'] = 'HTML';
1616
$labels['note_formatmd'] = 'Remarcar';
1717
$labels['note_formattxt'] = 'Texto puro';
18+
$labels['note_formatpdf'] = 'Adobe PDF';
19+
$labels['note_formatjpg'] = 'JPG';
20+
$labels['note_formatpng'] = 'PNG';
1821
$labels['ariallabelnewoptions'] = 'Opções';
19-
$labels['note_rmedia_md'] = 'Exclua automaticamente a mídia incorporada com arquivos Markdown';
20-
?>
22+
$labels['note_defaultformat'] = 'Formato Padrão';
23+
$labels['note_listformat'] = 'Formatos Exibidos';
24+
$labels['note_yamls'] = 'Habilitar YAML';
25+
$labels['note_rmedia_md'] = 'Exclua automaticamente a mídia incorporada';
26+
?>

localization/ru_RU.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ $labels['note_subject'] = 'Заметка: ';
1515
$labels['note_formathtml'] = 'HTML заметка';
1616
$labels['note_formatmd'] = 'Простая заметка';
1717
$labels['note_formattxt'] = 'Текстовая заметка';
18+
$labels['note_formatpdf'] = 'Adobe PDF';
19+
$labels['note_formatjpg'] = 'JPG';
20+
$labels['note_formatpng'] = 'PNG';
1821
$labels['ariallabelnewoptions'] = 'Параметры';
1922
$labels['note_defaultformat'] = 'Стандартный формат';
23+
$labels['note_listformat'] = 'Отображаемые форматы';
2024
$labels['note_yamls'] = 'Активировать YAML';
2125
$labels['note_rmedia_md'] = 'Автоматическое удаление встроенного мультимедиа с помощью файлов Markdown';
2226
?>

notes.js

Lines changed: 90 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ $(document).ready(function(){
3737
element: document.getElementById('editor1'),
3838
autoDownloadFontAwesome: false,
3939
autofocus: true,
40-
//autosave: true,
41-
//forceSync: true,
4240
spellChecker: false,
4341
autofocus: true,
4442
status: false,
4543
promptURLs: true,
46-
//sideBySideFullscreen: false,
44+
//sideBySideFullscreen: false,
4745
renderingConfig: {
48-
codeSyntaxHighlighting: true,
46+
codeSyntaxHighlighting: true,
4947
},
5048
toolbar: [{ name: 'Save',
5149
action: saveFile,
@@ -119,17 +117,7 @@ $(document).ready(function(){
119117
let bSeperator = document.createElement('i');
120118
bSeperator.classList.add("separator");
121119
toolbar.appendChild(bSeperator);
122-
/*
123-
let bUndo = document.createElement('li');
124-
bUndo.id = 'bUndo';
125-
bUndo.classList.add("fa", "fa-undo");
126-
toolbar.appendChild(bUndo);
127-
128-
let bRedo = document.createElement('li');
129-
bRedo.id = 'bRedo';
130-
bRedo.classList.add("fa", "fa-repeat", "fa-redo");
131-
toolbar.appendChild(bRedo);
132-
*/
120+
133121
editor.parentNode.insertBefore(toolbar, editor);
134122
document.querySelector('.EasyMDEContainer').style = 'display: none';
135123
editor.style = 'display: block';
@@ -145,6 +133,13 @@ $(document).ready(function(){
145133
mde.togglePreview();
146134
document.querySelector('#main_area .editor-toolbar').style.display = 'none';
147135
document.getElementById('estate').value = 's';
136+
let headerTitle = document.createElement('span');
137+
headerTitle.id = 'headerTitle';
138+
headerTitle.classList.add('headerTitle');
139+
headerTitle.innerText = document.getElementById('note_name').value;
140+
document.querySelector('#main_header #note_name').replaceWith(headerTitle);
141+
document.querySelector('tags').classList.remove('edit');
142+
tagify.setReadonly(true);
148143
}
149144
}
150145
});
@@ -194,8 +189,9 @@ $(document).ready(function(){
194189
function showNote(id) {
195190
document.querySelector('#main_area .editor-toolbar').style.display = 'none';
196191
if(document.getElementById('atoolbar')) document.getElementById('atoolbar').remove();
197-
198-
let loader = document.createElement("div");
192+
if(document.getElementById('tbutton')) document.getElementById('tbutton').remove();
193+
194+
let loader = document.createElement("div");
199195
loader.classList.add("db-spinner");
200196
loader.id = "db-spinner";
201197
document.getElementById("main").appendChild(loader);
@@ -224,6 +220,7 @@ $(document).ready(function(){
224220

225221
if(document.getElementById('bcontent')) document.getElementById('bcontent').remove();
226222
document.querySelector('.EasyMDEContainer').classList.remove('EasyMDEContainerH');
223+
if(document.getElementById('tocdiv')) document.getElementById('tocdiv').remove();
227224

228225
let headerTitle = document.createElement('span');
229226
headerTitle.id = 'headerTitle';
@@ -241,14 +238,52 @@ $(document).ready(function(){
241238
document.querySelector('.EasyMDEContainer').style = 'display: block;';
242239
document.getElementById('editor1').style = 'display none;';
243240
mde.value(note.content);
244-
245241
document.getElementById('editor1').value = note.content;
246242

247243
if(note.mime_type.substr(0, 4) == 'text') {
248244
if(document.getElementById('estate').value == 'e') {
249245
document.getElementById('estate').value = 's';
250246
mde.togglePreview();
251-
}
247+
}
248+
var headings = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
249+
if(headings.length > 0) {
250+
let tbutton = document.createElement('button');
251+
tbutton.id = 'tbutton';
252+
tbutton.innerText = 'ToC';
253+
document.getElementById('main_header').appendChild(tbutton);
254+
255+
let tocdiv = document.createElement('div');
256+
tocdiv.id = 'tocdiv';
257+
let o = 0;
258+
let a = 0;
259+
let list = 'c%';
260+
headings.forEach(function(element){
261+
a = element.tagName.substr(1,1);
262+
if(o < a) {
263+
list = list.replace('c%','<li><ul><li><a title="'+element.innerText+'" href="#' + element.id + '">' + element.innerText + '</a></li>c%</ul></li>');
264+
} else if(o > a) {
265+
list = list.replace('c%','</ul><li><a title="'+element.innerText+'" href="#' + element.id + '">' + element.innerText + '</a></li>c%');
266+
} else {
267+
list = list.replace('c%','<li><a title="'+element.innerText+'" href="#' + element.id + '">' + element.innerText + '</a></li>c%');
268+
}
269+
o = a;
270+
});
271+
list = list.replace('c%</ul>','');
272+
tocdiv.innerHTML = list;
273+
274+
tbutton.addEventListener('click', function(e) {
275+
e.preventDefault();
276+
tocdiv.classList.toggle('tdhidden');
277+
});
278+
279+
document.querySelector('.EasyMDEContainer').appendChild(tocdiv);
280+
281+
document.querySelectorAll('#tocdiv a').forEach(function(elem) {
282+
elem.addEventListener('click', function(){
283+
tocdiv.classList.toggle('tdhidden');
284+
});
285+
});
286+
}
252287
} else {
253288
let bcontent = document.createElement('object');
254289
bcontent.data = 'data:' + note.mime_type + ';base64,' + note.content;
@@ -297,8 +332,42 @@ $(document).ready(function(){
297332
}
298333

299334
function saveFile(editor) {
300-
document.getElementById('action').value = "editNote";
301-
document.getElementById('metah').submit();
335+
let loader = document.createElement("div");
336+
loader.classList.add("db-spinner");
337+
loader.id = "db-spinner";
338+
document.getElementById("main").appendChild(loader);
339+
340+
let fname = document.getElementById('fname').value;
341+
let extb = fname.lastIndexOf('.') + 1;
342+
343+
let tags = tagify.value;
344+
let tArr = [];
345+
for (let tag in tags) {
346+
tArr.push(tags[tag].value);
347+
}
348+
349+
$.ajax({
350+
type: 'POST',
351+
url: 'notes.php',
352+
data: {
353+
action: "editNote",
354+
note_name: document.getElementById('note_name').value,
355+
fname: fname,
356+
ntags: tArr,
357+
editor1: mde.value(),
358+
ftype: fname.substr(extb),
359+
},
360+
success: function(response){
361+
if(response == '') {
362+
console.log('Note saved successfully');
363+
location.reload();
364+
} else
365+
alert(response);
366+
367+
loader.remove();
368+
}
369+
});
370+
302371
}
303372

304373
function uplLocalImage() {

0 commit comments

Comments
 (0)