From ee840492dde8b94f7ac4d5e0a5833e866f809306 Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Fri, 8 Jun 2012 18:58:19 -0400 Subject: [PATCH] Default text size is now explicitly "normal" if not otherwise set. This is sort of a "partial cherry-pick" of commit 3e41b0840d5cf0b991a03d2d6b44907ec28030d0 in that it doesn't move the CSS outside of text.js; it just fixes #86, which is a much less volatile change right now. --- js/fc/ui/text.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/js/fc/ui/text.js b/js/fc/ui/text.js index 3f3e3b8..fb63b72 100755 --- a/js/fc/ui/text.js +++ b/js/fc/ui/text.js @@ -82,7 +82,11 @@ define(function() { // refesh code mirror codeMirror.refresh(); // update localstorage - if (supportsLocalStorage()) { localStorage["ThimbleTextSize"] = size; } + if (supportsLocalStorage()) try { + // TODO: Consider using lscache here, as it automatically deals + // w/ edge cases like out-of-space exceptions. + localStorage["ThimbleTextSize"] = size; + } catch (e) { /* Out of storage space, no big deal. */ } // mark text size in drop-down $("#text-nav-item li").removeClass("selected"); $("#text-nav-item li[data-size="+size+"]").addClass("selected"); @@ -94,14 +98,11 @@ define(function() { t.click(fn); }); - /** - * If there is a thimble text size set, trigger it. - */ - if (supportsLocalStorage()) { - if (typeof localStorage["ThimbleTextSize"] !== "undefined") { - var textSize = localStorage["ThimbleTextSize"]; - $("#text-nav-item li[data-size="+textSize+"]").click(); - } - } + var defaultSize = "normal"; + var lastSize = supportsLocalStorage() && localStorage["ThimbleTextSize"]; + if (lastSize && $("#text-nav-item li[data-size="+lastSize+"]").length) + defaultSize = lastSize; + + $("#text-nav-item li[data-size="+defaultSize+"]").click(); }; });