From b13b148395c8b6d2340b5257d7d6cd8896703c09 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Sun, 22 May 2016 14:43:02 -0300 Subject: [PATCH] Save note colors on HEX with upper case --- js/script.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/js/script.js b/js/script.js index d455b7b..8a10fd4 100644 --- a/js/script.js +++ b/js/script.js @@ -202,6 +202,20 @@ View.prototype = { modaltitle.html(""); modalcontent.html(""); }, + colorToHex: function(color) { + if (color.substr(0, 1) === '#') { + return color.toUpperCase();; + } + var digits = /(.*?)rgb\((\d+), (\d+), (\d+)\)/.exec(color); + + var red = parseInt(digits[2]); + var green = parseInt(digits[3]); + var blue = parseInt(digits[4]); + + var rgb = blue | (green << 8) | (red << 16); + + return digits[1] + '#' + rgb.toString(16).toUpperCase(); + }, renderContent: function () { var source = $('#content-tpl').html(); var template = Handlebars.compile(source); @@ -301,7 +315,7 @@ View.prototype = { var id = modalnote.data('id'); var title = modaltitle.html(); var content = modalcontent.html(); - var color = modalnote.css("background-color"); + var color = self.colorToHex(modalnote.css("background-color")); self._notes.updateId(id, title, content, color).done(function () { self._notes.unsetActive();