Skip to content

Commit

Permalink
Fixed two bugs.
Browse files Browse the repository at this point in the history
QUnit-based tests for the fixed bugs.
  • Loading branch information
Martijn authored and Martijn committed May 13, 2013
1 parent 466c261 commit 3143bde
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
9 changes: 6 additions & 3 deletions jquery.colorpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@
};
};

this.set = true;
this.set = false;

this.setAlpha = function(_a) {
if (_a !== null) {
Expand Down Expand Up @@ -1795,10 +1795,12 @@
if (args.length == 2) {
this.setSpaces(args[0]);
this.setAlpha(args[1] === 0 ? 0 : args[1] || 1);
this.set = true;
}
if (args.length > 2) {
this.setRGB(args[0], args[1], args[2]);
this.setAlpha(args[3] === 0 ? 0 : args[3] || 1);
this.set = true;
}
};
};
Expand Down Expand Up @@ -2015,6 +2017,7 @@
switch (property) {
case 'color':
case 'background-color':
case 'backgroundColor':
case 'outline-color':
case 'border-color':
$(this.options.altField).css(property, this.color.set? this.color.toCSS() : '');
Expand Down Expand Up @@ -2323,9 +2326,9 @@
// update input element content
if (!this.inline) {
if (!this.color.set) {
this.element.val('');
this.element.val('').change();
} else if (!this.color.equals(this._parseColor(this.element.val()))) {
this.element.val(this._formatColor(this.options.colorFormat, this.color));
this.element.val(this._formatColor(this.options.colorFormat, this.color)).change();
}

this._setImageBackground();
Expand Down
39 changes: 39 additions & 0 deletions test/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module('events');

test("Empty input value should not set altField background to black", function() {
expect(4);

var $input = $('<input type="text" value=""/>').appendTo("#qunit-fixture");
var $altfield = $('<div/>').appendTo("#qunit-fixture");

equal($altfield.css('backgroundColor'), 'rgba(0, 0, 0, 0)', 'Initial state, no color');

var jqcp = $input.colorpicker({
altField: $altfield
});

equal($altfield.css('backgroundColor'), 'rgba(0, 0, 0, 0)', 'After creation, no color');

jqcp.colorpicker('open');

equal($altfield.css('backgroundColor'), 'rgba(0, 0, 0, 0)', 'After open, no color');

jqcp.colorpicker('close');

equal($altfield.css('backgroundColor'), 'rgba(0, 0, 0, 0)', 'After close, no color');
});

asyncTest("Changing the color in input should trigger a 'change' event on the input", function() {
expect(1);

var $input = $('<input type="text" value=""/>').appendTo("#qunit-fixture");

$input.change(function() {
ok(true, 'triggered');
start();
});

var jqcp = $input.colorpicker();

jqcp.colorpicker('setColor', 'red');
});
18 changes: 18 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JQCP QUnit test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css"/>
<script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="../jquery.colorpicker.js"></script>
<script src="events.js"></script>
</body>
</html>

0 comments on commit 3143bde

Please sign in to comment.