|
@@ -33,7 +33,7 @@
|
|
|
<a href="index.html" class="modal-close waves-effect waves-light btn-large red"><i class="large material-icons left">keyboard_backspace</i> Retour</a>
|
|
|
</div>
|
|
|
<div class="col s6 right-align">
|
|
|
- <button class="btn-floating btn-large waves-effect waves-light red tooltipped" data-position="left" data-tooltip="Sauvegarder"><i class="large material-icons">save</i></button>
|
|
|
+ <button class="btn-floating btn-large waves-effect waves-light red tooltipped" data-position="left" data-tooltip="Sauvegarder" onclick="validCard(saveCard())"><i class="large material-icons">save</i></button>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="row">
|
|
@@ -59,6 +59,7 @@
|
|
|
<script type="text/javascript" src="js/binder.js"></script>
|
|
|
<script type="text/javascript">
|
|
|
const GET = parseURLParameter();
|
|
|
+ let mdEditor;
|
|
|
|
|
|
$(document).ready(() => {
|
|
|
// Set up data and print
|
|
@@ -68,7 +69,7 @@
|
|
|
// Load tooltip
|
|
|
const tooltip = M.Tooltip.init(document.querySelectorAll('.tooltipped'))[0];
|
|
|
// Load markdown editor
|
|
|
- const mdEditor = loadMarkdownEditor();
|
|
|
+ mdEditor = loadMarkdownEditor();
|
|
|
// Load data if update and markdown editor
|
|
|
if (GET.id) {
|
|
|
loadData().then(data => {
|
|
@@ -95,6 +96,37 @@
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ function validCard(callback) {
|
|
|
+ if (callback) {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function saveCard() {
|
|
|
+ let id;
|
|
|
+ // Update
|
|
|
+ if (GET.id) {
|
|
|
+ id = GET.id;
|
|
|
+ }
|
|
|
+ // Create
|
|
|
+ else {
|
|
|
+ id = uniqId();
|
|
|
+ const list = JSON.parse(localStorage.list);
|
|
|
+ list.push(id);
|
|
|
+ localStorage.setItem('list', JSON.stringify(list));
|
|
|
+ }
|
|
|
+ // Set object
|
|
|
+ const data = {
|
|
|
+ id: id,
|
|
|
+ title: $('#title').val(),
|
|
|
+ content: mdEditor.value()
|
|
|
+ }
|
|
|
+ // Save
|
|
|
+ localStorage.setItem(id, JSON.stringify(data));
|
|
|
+ // Go back to main page
|
|
|
+ document.location = 'index.html';
|
|
|
+ }
|
|
|
</script>
|
|
|
</body>
|
|
|
</html>
|