/* * 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) { var noteid = $("#note_content").data("noteid"); if (noteid == "") { // Make a very random ID number and check that it won't collide, // in case the user is good at winning the lottery do { noteid = Math.floor(Math.random() * (9999999999 - 1000000000) + 1000000000); console.log("Generating random note ID: " + noteid); } while (notes.get(noteid) != null); var note = {id: noteid}; note.content = $("#note_content").val(); note.modified = (new Date()).toISOString(); notes.add(note); $("#note_content").data("noteid", noteid); } else { var note = notes.get(noteid); note.content = $("#note_content").val(); note.modified = (new Date()).toISOString(); notes.set(note); } notes.fix(note); notes.save(function () { app.toast.create({ text: 'Note saved.', closeTimeout: 2000 }).open(); $("#orig_content").val(note.content); }); if (typeof callback == "function") { 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}); }); } }