From 7396ca7f01ca884564b1dd86a8847d28364f1a96 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 22 Jun 2012 23:48:53 -0700 Subject: Fixing bug with gradient stop limits It seems that from-to stops are omitted if using objects with no 0 and/or 100 percent stops, seems like browser induced, but can't confirmed, bug never reported, but this should fix it. --- js/controllers/color-controller.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'js/controllers/color-controller.js') diff --git a/js/controllers/color-controller.js b/js/controllers/color-controller.js index 3165988d..2a6fe9bd 100755 --- a/js/controllers/color-controller.js +++ b/js/controllers/color-controller.js @@ -254,7 +254,12 @@ exports.ColorController = Montage.create(Component, { gradient.css = css; // arr = css.split('from('); - arr = arr[1].split('),'); + // + if (arr.length > 1) { + arr = arr[1].split('),'); + } else { + arr = (css.split(css.split('color-stop(')[0])[1]).split('),'); + } // for (i=0; arr[i]; i++) { arr[i] = arr[i].replace(/ color-stop\(/i, ""); @@ -264,14 +269,20 @@ exports.ColorController = Montage.create(Component, { arr[i] = arr[i].replace(/\)\)/i, ""); } // - if (i === 0) { + if (i === 0 && arr[i].indexOf('color-stop') === -1) { arr[i] = {css: arr[i], percent: 0}; } else if (i === arr.length-1) { - arr[i] = {css: arr[i], percent: 100}; + temp = arr[i].split(', rgb'); + if (temp.length > 1) { + arr[i] = {css: 'rgb'+temp[1].replace(/\)\)/i, ""), percent: Math.round(parseFloat(temp[0])*100)}; + } else { + arr[i] = {css: arr[i], percent: 100}; + } } else { // if (arr[i].indexOf('rgb') >= 0 && arr[i].indexOf('rgba') < 0) { temp = arr[i].split(', rgb'); + temp[0] = temp[0].replace(/color\-stop\(/gi, ''); arr[i] = {css: 'rgb'+temp[1], percent: Math.round(parseFloat(temp[0])*100)}; } else if (arr[i].indexOf('rgba') >= 0) { temp = arr[i].split(', rgba'); -- cgit v1.2.3