From 0ee47f17f146c33f110a7fee1b0e1fbf143b96fe Mon Sep 17 00:00:00 2001 From: William Crandell Date: Wed, 7 Nov 2018 15:05:47 -0500 Subject: [PATCH 1/3] preserve validity when cloning closes #156 --- tinycolor.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tinycolor.js b/tinycolor.js index 9580299..fa9681d 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -13,7 +13,7 @@ var trimLeft = /^\s+/, mathRandom = Math.random; function tinycolor (color, opts) { - + color = (color) ? color : ''; opts = opts || { }; @@ -44,7 +44,7 @@ function tinycolor (color, opts) { if (this._g < 1) { this._g = mathRound(this._g); } if (this._b < 1) { this._b = mathRound(this._b); } - this._ok = rgb.ok; + this._ok = opts.perserve?opts.ok:rgb.ok; this._tc_id = tinyCounter++; } @@ -209,8 +209,9 @@ tinycolor.prototype = { return formattedString || this.toHexString(); }, - clone: function() { - return tinycolor(this.toString()); + clone: function(_opts) { + //this.opts.perserve = true; + return tinycolor(this.toString(), _opts); }, _applyModification: function(fn, args) { From 536aabd6a7d9bc91ce30a342795e591928970f7f Mon Sep 17 00:00:00 2001 From: William Crandell Date: Wed, 7 Nov 2018 15:47:08 -0500 Subject: [PATCH 2/3] I said I made it work so I made it work this may not be the optimal way to get it done but it does in fact work --- tinycolor.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tinycolor.js b/tinycolor.js index fa9681d..3827a98 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -15,7 +15,7 @@ var trimLeft = /^\s+/, function tinycolor (color, opts) { color = (color) ? color : ''; - opts = opts || { }; + opts = opts || {'preserve': false}; // If input is already a tinycolor, return itself if (color instanceof tinycolor) { @@ -44,8 +44,10 @@ function tinycolor (color, opts) { if (this._g < 1) { this._g = mathRound(this._g); } if (this._b < 1) { this._b = mathRound(this._b); } - this._ok = opts.perserve?opts.ok:rgb.ok; + this._ok = opts.preserve?opts.ok:rgb.ok; + opts.ok = this._ok; this._tc_id = tinyCounter++; + this._opts = opts; } tinycolor.prototype = { @@ -209,9 +211,9 @@ tinycolor.prototype = { return formattedString || this.toHexString(); }, - clone: function(_opts) { - //this.opts.perserve = true; - return tinycolor(this.toString(), _opts); + clone: function() { + this._opts.preserve = true; + return tinycolor(this.toString(), this._opts); }, _applyModification: function(fn, args) { From 7fc83de31ba57ca8835f8f24c27d18e36e2733ab Mon Sep 17 00:00:00 2001 From: William Crandell Date: Wed, 7 Nov 2018 15:54:17 -0500 Subject: [PATCH 3/3] Update tinycolor.js --- tinycolor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tinycolor.js b/tinycolor.js index 3827a98..4370be5 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -45,6 +45,7 @@ function tinycolor (color, opts) { if (this._b < 1) { this._b = mathRound(this._b); } this._ok = opts.preserve?opts.ok:rgb.ok; + opts.preserve = false; opts.ok = this._ok; this._tc_id = tinyCounter++; this._opts = opts;