[refactor] improve bookmark edit function

This commit is contained in:
zombieFox 2019-03-16 20:56:03 +00:00
parent f96f3552ea
commit e87a00453b
2 changed files with 14 additions and 4 deletions

View File

@ -188,10 +188,17 @@ var bookmarks = (function() {
all.push(newBookmark);
};
var edit = function(object, timeStamp) {
var edit = function(override) {
var options = {
bookmarkData: null,
timeStamp: null
};
if (override) {
options = helper.applyOptions(options, override);
};
for (var i = 0; i < all.length; i++) {
if (all[i].timeStamp === timeStamp) {
all[i] = object;
if (all[i].timeStamp === options.timeStamp) {
all[i] = options.bookmarkData;
};
};
};

View File

@ -90,7 +90,10 @@ var link = (function() {
options.bookmarkData.letter = options.form.querySelector(".link-form-input-letter").value;
options.bookmarkData.name = options.form.querySelector(".link-form-input-name").value;
options.bookmarkData.url = options.form.querySelector(".link-form-input-url").value;
bookmarks.edit(options.bookmarkData, options.bookmarkData.timeStamp);
bookmarks.edit({
bookmarkData: options.bookmarkData,
timeStamp: options.bookmarkData.timeStamp
});
}
};
action[options.action]();