Skip to content

Commit

Permalink
add clone() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan committed Oct 12, 2015
1 parent b86cca7 commit bef7ce7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/test.js
Expand Up @@ -26,6 +26,19 @@ test("Original input", function() {
ok (new tinycolor(null).getOriginalInput() === "", "when given a null value, an empty string is returned");
});

test("Cloning color", function() {
var originalColor = tinycolor("red");
var originalColorRgbString = originalColor.toRgbString();

var clonedColor = originalColor.clone();
ok (clonedColor.toRgbString() === originalColor.toRgbString(), "cloned color is identical");

clonedColor.setAlpha(0.5);
ok (clonedColor.toRgbString() !== originalColor.toRgbString(), "cloned color is changing independently from original color");
ok (originalColorRgbString === originalColor.toRgbString(), "original color was not changed by cloned color change");
});


// Taken from convertWikipediaColors.html
var conversions = [
{"hex":"#FFFFFF","hex8":"#FFFFFFFF","rgb":{"r":"100.0%","g":"100.0%","b":"100.0%"},"hsv":{"h":"0","s":"0.000","v":"1.000"},"hsl":{"h":"0","s":"0.000","l":"1.000"}},
Expand Down
3 changes: 3 additions & 0 deletions tinycolor.js
Expand Up @@ -207,6 +207,9 @@ tinycolor.prototype = {

return formattedString || this.toHexString();
},
clone: function() {
return tinycolor(this.toString());
},

_applyModification: function(fn, args) {
var color = fn.apply(null, [this].concat([].slice.call(args)));
Expand Down

0 comments on commit bef7ce7

Please sign in to comment.