From 5a473eb67c7551e0725b2afb8909abc60238e6b0 Mon Sep 17 00:00:00 2001 From: Ollie Terrance Date: Wed, 21 May 2014 22:11:09 +0100 Subject: [PATCH] Settings save animation, cache omnibox links --- Homely/res/js/background.js | 7 ++++--- Homely/res/js/homely.js | 40 +++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Homely/res/js/background.js b/Homely/res/js/background.js index 616a49a..20f3b1a 100644 --- a/Homely/res/js/background.js +++ b/Homely/res/js/background.js @@ -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) { @@ -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) { diff --git a/Homely/res/js/homely.js b/Homely/res/js/homely.js index d80b5c8..c7ebf73 100644 --- a/Homely/res/js/homely.js +++ b/Homely/res/js/homely.js @@ -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($("
").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") @@ -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($("
").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($("
").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 = {