Skip to content

Commit

Permalink
Merge pull request #5 from danlevan/pr/4
Browse files Browse the repository at this point in the history
Pr/4
  • Loading branch information
8lueberry committed Mar 20, 2015
2 parents b0f0d96 + 3dcf1f5 commit ccb552b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 1.2.1
# 1.2.2

2015-03-18
2015-03-20

- Add random function in the js version

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "google-material-color",
"version": "1.2.1",
"version": "1.2.2",
"description": "Google material color (http://www.google.com/design/spec/style/color.html) implementation for Sass, Less, Stylus, CSS and JS.",
"main": "dist/palette.js",
"scripts": {
Expand Down
29 changes: 24 additions & 5 deletions src/templates/js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@
root.palette = factory();
}
})(this, function() {
// avoid using lodash in dependencies
function keys(obj) {
var keys, key;

keys = [];

for (var key in obj) if (obj.hasOwnProperty(key)) {
keys.push(key);
}

return keys;
}

// avoid using lodash in dependencies
function random(min, max) {
return Math.floor(Math.random() * ( max - min + 1 )) + min;
}


return {
palette: { <%
_.forIn(colors, function(shades, color) { %>
Expand All @@ -25,12 +44,12 @@ _.forIn(shades, function(hex, shade) { %>
random: function(shade) {
var colors, color, shades;

colors = _.keys(this.palette);
color = colors[_.random(0, colors.length - 1)];
colors = keys(this.palette);
color = colors[random(0, colors.length - 1)];

if (_.isUndefined(shade)) {
shades = _.keys(color);
shade = shades[_.random(0, shades.length - 1)];
if (shade == null) {
shades = keys(color);
shade = shades[random(0, shades.length - 1)];
}

return this.get(color, shade);
Expand Down

0 comments on commit ccb552b

Please sign in to comment.