Permalink
Browse files

Fixed two bugs.

QUnit-based tests for the fixed bugs.
  • Loading branch information...
1 parent 466c261 commit 3143bdeb86c061295c75fdaae3806f781fd9429b Martijn committed May 13, 2013
Showing with 63 additions and 3 deletions.
  1. +6 −3 jquery.colorpicker.js
  2. +39 −0 test/events.js
  3. +18 −0 test/index.html
View
@@ -1545,7 +1545,7 @@
};
};
- this.set = true;
+ this.set = false;
this.setAlpha = function(_a) {
if (_a !== null) {
@@ -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;
}
};
};
@@ -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() : '');
@@ -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();
View
@@ -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');
+});
View
@@ -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.