mirror of
https://github.com/zombieFox/nightTab.git
synced 2024-12-01 04:23:27 +01:00
[bug] fix data and background feedback
This commit is contained in:
parent
b23b7b22a6
commit
0aa76fca39
@ -17,6 +17,21 @@ var background = (function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mod.image = {
|
||||||
|
file: function(name, data) {
|
||||||
|
helper.setObject({
|
||||||
|
object: state.get(),
|
||||||
|
path: "background.image.file.name",
|
||||||
|
newValue: name
|
||||||
|
});
|
||||||
|
helper.setObject({
|
||||||
|
object: state.get(),
|
||||||
|
path: "background.image.file.data",
|
||||||
|
newValue: data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var bind = {};
|
var bind = {};
|
||||||
|
|
||||||
bind.feedback = {
|
bind.feedback = {
|
||||||
@ -108,13 +123,15 @@ var background = (function() {
|
|||||||
controlBackgroundImageFileFeedback.appendChild(para1);
|
controlBackgroundImageFileFeedback.appendChild(para1);
|
||||||
controlBackgroundImageFileFeedback.appendChild(para2);
|
controlBackgroundImageFileFeedback.appendChild(para2);
|
||||||
},
|
},
|
||||||
success: function(action) {
|
success: function(name, action) {
|
||||||
var controlBackgroundImageFileFeedback = helper.e(".control-background-image-file-feedback");
|
var controlBackgroundImageFileFeedback = helper.e(".control-background-image-file-feedback");
|
||||||
var para1 = helper.node("p:Success! Setting Background image.|class:muted small");
|
var para1 = helper.node("p:Success! Setting Background image.|class:muted small");
|
||||||
var para2 = helper.node("p:" + state.get().background.image.file.name);
|
var para2 = helper.node("p:" + name);
|
||||||
controlBackgroundImageFileFeedback.appendChild(para1);
|
controlBackgroundImageFileFeedback.appendChild(para1);
|
||||||
controlBackgroundImageFileFeedback.appendChild(para2);
|
controlBackgroundImageFileFeedback.appendChild(para2);
|
||||||
bind.feedback.animation.set("is-pop", action);
|
if (action) {
|
||||||
|
bind.feedback.animation.set("is-pop", action);
|
||||||
|
};
|
||||||
},
|
},
|
||||||
clear: function() {
|
clear: function() {
|
||||||
var controlBackgroundImageFileFeedback = helper.e(".control-background-image-file-feedback");
|
var controlBackgroundImageFileFeedback = helper.e(".control-background-image-file-feedback");
|
||||||
@ -159,26 +176,19 @@ var background = (function() {
|
|||||||
reader.onload = function(event) {
|
reader.onload = function(event) {
|
||||||
if (fileList.item(0).size <= 5000000) {
|
if (fileList.item(0).size <= 5000000) {
|
||||||
if (fileList.item(0).type.split("/")[0] == "image") {
|
if (fileList.item(0).type.split("/")[0] == "image") {
|
||||||
helper.setObject({
|
mod.image.file(fileList[0].name, event.target.result);
|
||||||
object: state.get(),
|
data.save();
|
||||||
path: "background.image.file.name",
|
|
||||||
newValue: fileList[0].name
|
|
||||||
});
|
|
||||||
helper.setObject({
|
|
||||||
object: state.get(),
|
|
||||||
path: "background.image.file.data",
|
|
||||||
newValue: event.target.result
|
|
||||||
});
|
|
||||||
data.save();;
|
|
||||||
render.feedback.clear();
|
render.feedback.clear();
|
||||||
render.feedback.success(render.image);
|
render.feedback.success(fileList[0].name, render.image);
|
||||||
render.input.clear();
|
render.input.clear();
|
||||||
} else {
|
} else {
|
||||||
|
// not an image file
|
||||||
render.feedback.clear();
|
render.feedback.clear();
|
||||||
render.feedback.fail.filetype(fileList[0].name);
|
render.feedback.fail.filetype(fileList[0].name);
|
||||||
render.input.clear();
|
render.input.clear();
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
// file size too big
|
||||||
render.feedback.clear();
|
render.feedback.clear();
|
||||||
render.feedback.fail.size(fileList[0].name);
|
render.feedback.fail.size(fileList[0].name);
|
||||||
render.input.clear();
|
render.input.clear();
|
||||||
|
136
src/js/data.js
136
src/js/data.js
@ -91,55 +91,83 @@ var data = (function() {
|
|||||||
tempAchor.remove();
|
tempAchor.remove();
|
||||||
};
|
};
|
||||||
|
|
||||||
var render = {
|
var bind = {};
|
||||||
feedback: function(type) {
|
|
||||||
_renderFeedback(type);
|
bind.feedback = {
|
||||||
|
animation: {
|
||||||
|
set: function(animationClass, action) {
|
||||||
|
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
|
||||||
|
helper.addClass(controlDataImportFeedback, animationClass);
|
||||||
|
var animationEndAction = function() {
|
||||||
|
if (action) {
|
||||||
|
action();
|
||||||
|
};
|
||||||
|
bind.feedback.animation.reset();
|
||||||
|
};
|
||||||
|
controlDataImportFeedback.addEventListener("animationend", animationEndAction, false);
|
||||||
|
},
|
||||||
|
reset: function() {
|
||||||
|
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
|
||||||
|
helper.removeClass(controlDataImportFeedback, "is-shake");
|
||||||
|
helper.removeClass(controlDataImportFeedback, "is-pop");
|
||||||
|
controlDataImportFeedback.removeEventListener("animationend", bind.feedback.animation.reset, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var _renderFeedback = function(type, data) {
|
var render = {};
|
||||||
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
|
|
||||||
var _setFeedbackAnimation = function(animationClass) {
|
render.reload = function() {
|
||||||
helper.addClass(controlDataImportFeedback, animationClass);
|
location.reload();
|
||||||
controlDataImportFeedback.addEventListener("animationend", _resetFeedbackAnimation, false);
|
};
|
||||||
};
|
|
||||||
var _resetFeedbackAnimation = function() {
|
render.input = {
|
||||||
helper.removeClass(controlDataImportFeedback, "is-shake");
|
clear: function() {
|
||||||
helper.removeClass(controlDataImportFeedback, "is-pop");
|
var input = helper.e(".control-data-import");
|
||||||
controlDataImportFeedback.removeEventListener("animationend", _resetFeedbackAnimation, false);
|
input.value = "";
|
||||||
};
|
}
|
||||||
var clear = function() {
|
};
|
||||||
|
|
||||||
|
render.feedback = {
|
||||||
|
empty: function() {
|
||||||
|
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
|
||||||
|
var para1 = helper.node("p:No JSON file selected.|class:muted small");
|
||||||
|
controlDataImportFeedback.appendChild(para1);
|
||||||
|
},
|
||||||
|
success: function(name, action) {
|
||||||
|
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
|
||||||
|
var para1 = helper.node("p:Success! Restoring nightTab Bookmarks and Settings.|class:muted small");
|
||||||
|
var para2 = helper.node("p:" + name);
|
||||||
|
controlDataImportFeedback.appendChild(para1);
|
||||||
|
controlDataImportFeedback.appendChild(para2);
|
||||||
|
if (action) {
|
||||||
|
bind.feedback.animation.set("is-pop", action);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
clear: function() {
|
||||||
|
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
|
||||||
while (controlDataImportFeedback.lastChild) {
|
while (controlDataImportFeedback.lastChild) {
|
||||||
controlDataImportFeedback.removeChild(controlDataImportFeedback.lastChild);
|
controlDataImportFeedback.removeChild(controlDataImportFeedback.lastChild);
|
||||||
};
|
};
|
||||||
};
|
},
|
||||||
var feedbackMessage = {
|
fail: {
|
||||||
empty: "No file selected.",
|
notJson: function(name) {
|
||||||
success: "Success! Restoring nightTab Bookmarks and Settings.",
|
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
|
||||||
fail: {
|
var para1 = helper.node("p:Not a JSON file. Make sure the selected file came from nightTab.|class:small muted");
|
||||||
notNightTabJson: "Not the right kind of JSON file. Make sure the selected file came from nightTab.",
|
var para2 = helper.node("p:" + name);
|
||||||
notJson: "Not a JSON file. Make sure the selected file came from nightTab."
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var action = {
|
|
||||||
empty: function() {
|
|
||||||
var para1 = helper.node("p:" + feedbackMessage.empty + "|class:muted small");
|
|
||||||
controlDataImportFeedback.appendChild(para1);
|
|
||||||
},
|
|
||||||
success: function() {
|
|
||||||
var para1 = helper.node("p:" + feedbackMessage.current + "|class:muted small");
|
|
||||||
var para2 = helper.node("p:" + state.get().background.image.file.name);
|
|
||||||
controlDataImportFeedback.appendChild(para1);
|
controlDataImportFeedback.appendChild(para1);
|
||||||
controlDataImportFeedback.appendChild(para2);
|
controlDataImportFeedback.appendChild(para2);
|
||||||
controlDataImportFeedback.addEventListener("animationend", function() {
|
bind.feedback.animation.set("is-shake");
|
||||||
restore(JSON.parse(data));
|
},
|
||||||
location.reload();
|
notNightTabJson: function(name) {
|
||||||
}, false);
|
var controlDataImportFeedback = helper.e(".control-data-import-feedback");
|
||||||
_setFeedbackAnimation("is-pop");
|
var para1 = helper.node("p:Not the right kind of JSON file. Make sure the selected file came from nightTab.|class:small muted");
|
||||||
|
var para2 = helper.node("p:" + name);
|
||||||
|
controlDataImportFeedback.appendChild(para1);
|
||||||
|
controlDataImportFeedback.appendChild(para2);
|
||||||
|
bind.feedback.animation.set("is-shake");
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
clear();
|
|
||||||
action[type]();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var importData = function() {
|
var importData = function() {
|
||||||
@ -161,21 +189,23 @@ var data = (function() {
|
|||||||
if (helper.isJsonString(event.target.result)) {
|
if (helper.isJsonString(event.target.result)) {
|
||||||
// is this a nightTab JSON
|
// is this a nightTab JSON
|
||||||
if (JSON.parse(event.target.result).nighttab) {
|
if (JSON.parse(event.target.result).nighttab) {
|
||||||
_renderFeedback("success", event.target.result);
|
render.feedback.clear();
|
||||||
// console.log("is a JSON and a nightTab file");
|
render.feedback.success(fileList[0].name, function() {
|
||||||
// controlDataImportFeedback.addEventListener("animationend", function() {
|
restore(JSON.parse(event.target.result));
|
||||||
// restore(JSON.parse(event.target.result));
|
render.reload();
|
||||||
// location.reload();
|
});
|
||||||
// }, false);
|
render.input.clear();
|
||||||
} else {
|
} else {
|
||||||
_renderFeedback("fail");
|
// not a nightTab JSON file
|
||||||
// console.log("is a JSON file but not a nightTab file");
|
render.feedback.clear();
|
||||||
// _feedback(feedbackMessage.fail.notNightTabJson, "is-shake");
|
render.feedback.fail.notNightTabJson(fileList[0].name);
|
||||||
|
render.input.clear();
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
_renderFeedback("fail");
|
// not a JSON file
|
||||||
// console.log("not a JSON file");
|
render.feedback.clear();
|
||||||
// _feedback(feedbackMessage.fail.notJson, "is-shake");
|
render.feedback.fail.notJson(fileList[0].name);
|
||||||
|
render.input.clear();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
// invoke the reader
|
// invoke the reader
|
||||||
@ -184,7 +214,7 @@ var data = (function() {
|
|||||||
|
|
||||||
var init = function() {
|
var init = function() {
|
||||||
restore(data.load());
|
restore(data.load());
|
||||||
render.feedback("empty");
|
render.feedback.empty();
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
var version = (function() {
|
var version = (function() {
|
||||||
|
|
||||||
var current = "3.42.0";
|
var current = "3.43.0";
|
||||||
|
|
||||||
var compare = function(a, b) {
|
var compare = function(a, b) {
|
||||||
var pa = a.split(".");
|
var pa = a.split(".");
|
||||||
|
Loading…
Reference in New Issue
Block a user