From 76622cd99cf671531cfa21c5d6243f3e4e185116 Mon Sep 17 00:00:00 2001 From: Jez Ng Date: Mon, 29 Oct 2012 17:56:32 -0400 Subject: Convert strings to numbers when saving options page. This avoids the need to continually re-parse the strings each time we load the option value. --- options/options.coffee | 13 ++++++++----- options/options.html | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'options') diff --git a/options/options.coffee b/options/options.coffee index 6dc2c8dd..abe3fee7 100644 --- a/options/options.coffee +++ b/options/options.coffee @@ -56,11 +56,14 @@ saveOptions = -> # the freedom to change the defaults in the future. for fieldName in editableFields field = $(fieldName) - if field.getAttribute("type") is "checkbox" - fieldValue = field.checked - else - fieldValue = field.value.trim() - field.value = fieldValue + switch field.getAttribute("type") + when "checkbox" + fieldValue = field.checked + when "number" + fieldValue = parseFloat field.value + else + fieldValue = field.value.trim() + field.value = fieldValue # If it's empty and not a field that we allow to be empty, restore to the default value if not fieldValue and canBeEmptyFields.indexOf(fieldName) is -1 diff --git a/options/options.html b/options/options.html index d5f836e7..f6059618 100644 --- a/options/options.html +++ b/options/options.html @@ -188,7 +188,7 @@