Skip to content

Commit

Permalink
Settings save animation, cache omnibox links
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrance committed May 21, 2014
1 parent fb90866 commit 5a473eb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
7 changes: 4 additions & 3 deletions Homely/res/js/background.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var links;
chrome.omnibox.onInputStarted.addListener(function() {
chrome.storage.local.get("links", function(store) {
links = [];
var newLinks = [];
for (var i in store.links["content"]) {
var blk = store.links["content"][i];
for (var j in blk.buttons) {
Expand All @@ -13,16 +13,17 @@ chrome.omnibox.onInputStarted.addListener(function() {
if (!item.title) item.title = item.url;
if (btn.title) item.title = btn.title + " > " + item.title;
if (blk.title) item.title = blk.title + " > " + item.title;
links.push(item);
newLinks.push(item);
}
}
} else if (btn.url) {
if (!btn.title) btn.title = btn.url;
if (blk.title) btn.title = blk.title + " > " + btn.title;
links.push(btn);
newLinks.push(btn);
}
}
}
links = newLinks;
});
});
chrome.omnibox.onInputChanged.addListener(function(text, suggest) {
Expand Down
40 changes: 23 additions & 17 deletions Homely/res/js/homely.js
Original file line number Diff line number Diff line change
Expand Up @@ -1952,14 +1952,14 @@ $(document).ready(function() {
// save and reload
$("#settings-save").click(function(e) {
$("#settings-alerts").empty();
var ok = true;
try {
settings.links["content"] = JSON.parse($("#settings-links-content").val());
} catch (e) {
ok = false;
$("#settings-alerts").append($("<div/>").addClass("alert alert-danger").text("The blocks source isn't valid JSON."));
$($("#settings-tabs a")[0]).click();
return;
}
$("#settings-save").prop("disabled", true).empty().append(fa("spinner fa-spin", false)).append(" Saving...");
settings.links["edit"] = {
menu: $("#settings-links-edit-menu").prop("checked"),
dragdrop: $("#settings-links-edit-dragdrop").prop("checked")
Expand Down Expand Up @@ -2090,22 +2090,28 @@ $(document).ready(function() {
enable: $("#settings-style-customcss-content").val() && $("#settings-style-customcss-enable").prop("checked"),
content: $("#settings-style-customcss-content").val()
};
if (ok) {
// write to local storage
chrome.storage.local.set(settings, function() {
if (chrome.runtime.lastError) {
alert("Unable to save: " + chrome.runtime.lastError.message);
return;
}
if (revokeError) {
alert("Failed to revoke some permissions: " + chrome.runtime.lastError.message);
}
// reload page
$("#settings").off("hidden.bs.modal").on("hidden.bs.modal", function(e) {
location.reload();
}).modal("hide");
$("#settings").on("hide.bs.modal", function(e) {
e.preventDefault();
});
// write to local storage
chrome.storage.local.set(settings, function() {
if (chrome.runtime.lastError) {
$("#settings-alerts").append($("<div/>").addClass("alert alert-danger").text("Unable to save: " + chrome.runtime.lastError.message));
$("#settings-save").prop("disabled", false).empty().append(fa("check", false)).append(" Save and reload");
return;
}
if (revokeError) {
$("#settings-alerts").append($("<div/>").addClass("alert alert-warning").text("Failed to revoke permissions: " + chrome.runtime.lastError.message));
}
$("#settings-save").empty().append(fa("check", false)).append(" Saved!");
// reload page
$("#settings").off("hide.bs.modal").off("hidden.bs.modal").on("hidden.bs.modal", function(e) {
location.reload();
});
}
setTimeout(function() {
$("#settings").modal("hide");
}, 250);
});
});
// links selection state
var linksHotkeys = {
Expand Down

0 comments on commit 5a473eb

Please sign in to comment.