You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
function saveme(callback) {
|
|
function finishSave(note, callback) {
|
|
NOTES.fixAll();
|
|
NOTES.sync(function () {
|
|
app.toast.create({
|
|
text: 'Note saved.',
|
|
closeTimeout: 2000
|
|
}).open();
|
|
$("#orig_content").val(note.content);
|
|
});
|
|
if (typeof callback == "function") {
|
|
callback();
|
|
}
|
|
}
|
|
|
|
var noteid = $("#note_content").data("noteid");
|
|
if (noteid == "") {
|
|
var note = {
|
|
content: $("#note_content").val(),
|
|
modified: Math.round((new Date()).getTime() / 1000)
|
|
};
|
|
NOTES.add(note, function (n) {
|
|
$("#note_content").data("noteid", n.noteid);
|
|
finishSave(n, callback);
|
|
});
|
|
} else {
|
|
var note = NOTES.get(noteid);
|
|
note.content = $("#note_content").val();
|
|
note.modified = Math.round((new Date()).getTime() / 1000);
|
|
NOTES.set(note);
|
|
finishSave(note, callback);
|
|
}
|
|
}
|
|
|
|
function exiteditor() {
|
|
if ($("#note_content").val() == "" || $("#note_content").val() === $("#orig_content").val()) {
|
|
router.back({force: true, ignoreCache: true, reload: true});
|
|
} else {
|
|
saveme(function () {
|
|
router.back({force: true, ignoreCache: true, reload: true});
|
|
});
|
|
}
|
|
} |