Skip to content

Commit

Permalink
Fixes 174
Browse files Browse the repository at this point in the history
  • Loading branch information
claviska committed Oct 6, 2015
1 parent e1433b0 commit c3d57f4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 1 addition & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,7 @@ <h3 id="methods">Methods</h3>
<dd>
<p>
Gets or sets a control's color value. To use this method as a setter, pass
<code>data</code> in as a hex value. (You can also obtain this value by checking the
input element's <code>value</code> attribute.)
in a color string or an object (ex: <code>{color: '#fc0', opacity: .5}</code>).
</p>
</dd>
</dl>
Expand Down
12 changes: 11 additions & 1 deletion jquery.minicolors.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,17 @@
} else {
// Setter
$(this).each( function() {
updateFromInput($(this).val(data));
if( typeof(data) === 'object' ) {
if( data.opacity ) {
$(this).attr('data-opacity', keepWithin(data.opacity, 0, 1));
}
if( data.color ) {
$(this).val(data.color);
}
} else {
$(this).val(data);
}
updateFromInput($(this));
});
}
return $(this);
Expand Down
Loading

2 comments on commit c3d57f4

@onassar
Copy link
Contributor

@onassar onassar commented on c3d57f4 Oct 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome I'll give this a go shortly. Thanks for the quick turn around!

@onassar
Copy link
Contributor

@onassar onassar commented on c3d57f4 Jan 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally got around to testing this. Thanks @claviska. Works like a charm. Worth noting for anyone else that the required syntax is:

$input.minicolors('value', {
    'opacity': '0.5',
    'color': '#000000'
});

Please sign in to comment.