Tweak note field auto-save triggering

This avoids unnecessary timeout calls and fixes a problem where typing
in a newly initialized note doesn't save it until the first blur().
This commit is contained in:
Dan Stillman 2016-07-17 14:55:02 -04:00
parent b0157efd23
commit 4449da7e91
2 changed files with 9 additions and 15 deletions

View file

@ -241,11 +241,6 @@
// Update note
var noteField = this._id('noteField');
if (this.item) {
if (!noteField.changed) {
Zotero.debug("Note hasn't been modified -- not saving");
return;
}
let changed = this.item.setNote(noteField.value);
if (changed && this.saveOnEdit) {
yield this.item.saveTx();

View file

@ -400,6 +400,7 @@
case 'keypress':
// Ignore keypresses that don't change
// any text
//Zotero.debug(event.which);
if (!event.which &&
event.keyCode != event.DOM_VK_DELETE &&
event.keyCode != event.DOM_VK_BACK_SPACE) {
@ -426,18 +427,16 @@
clearTimeout(self._timer);
}
if (event.type == 'change') {
self._changed = true;
// Trigger command event on change
if (event.type == 'keypress' || event.type == 'change') {
self._timer = self.timeout && setTimeout(function () {
var attr = self.getAttribute('oncommand');
attr = attr.replace('this', 'thisObj');
var func = new Function('thisObj', 'event', attr);
func(self, event);
}, self.timeout);
}
// Get the command event
self._timer = self.timeout && setTimeout(function () {
var attr = self.getAttribute('oncommand');
attr = attr.replace('this', 'thisObj');
var func = new Function('thisObj', 'event', attr);
func(self, event);
}, self.timeout);
return true;
};
break;