Author: nbelaevski
Date: 2009-04-17 11:07:41 -0400 (Fri, 17 Apr 2009)
New Revision: 13639
Modified:
trunk/ui/colorPicker/src/main/config/component/colorPicker.xml
trunk/ui/colorPicker/src/main/java/org/richfaces/renderkit/ColorPickerRendererBase.java
trunk/ui/colorPicker/src/main/resources/org/richfaces/renderkit/html/scripts/ui.colorpicker.js
trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx
Log:
https://jira.jboss.org/jira/browse/RF-6845
Modified: trunk/ui/colorPicker/src/main/config/component/colorPicker.xml
===================================================================
--- trunk/ui/colorPicker/src/main/config/component/colorPicker.xml 2009-04-17 13:54:46 UTC
(rev 13638)
+++ trunk/ui/colorPicker/src/main/config/component/colorPicker.xml 2009-04-17 15:07:41 UTC
(rev 13639)
@@ -75,11 +75,11 @@
</property>
<property>
- <name>onchange</name>
+ <name>onselect</name>
<classname>java.lang.String</classname>
</property>
<property>
- <name>onsubmit</name>
+ <name>onchange</name>
<classname>java.lang.String</classname>
</property>
<property>
Modified:
trunk/ui/colorPicker/src/main/java/org/richfaces/renderkit/ColorPickerRendererBase.java
===================================================================
---
trunk/ui/colorPicker/src/main/java/org/richfaces/renderkit/ColorPickerRendererBase.java 2009-04-17
13:54:46 UTC (rev 13638)
+++
trunk/ui/colorPicker/src/main/java/org/richfaces/renderkit/ColorPickerRendererBase.java 2009-04-17
15:07:41 UTC (rev 13639)
@@ -25,7 +25,7 @@
}
private static final String[] EVENT_ATTRIBUTES = {
- "onchange", "onbeforeshow", "onshow", "onhide",
"onsubmit"
+ "onchange", "onbeforeshow", "onshow", "onhide",
"onselect"
};
public String encodeEvents(FacesContext context, UIComponent component) {
Modified:
trunk/ui/colorPicker/src/main/resources/org/richfaces/renderkit/html/scripts/ui.colorpicker.js
===================================================================
---
trunk/ui/colorPicker/src/main/resources/org/richfaces/renderkit/html/scripts/ui.colorpicker.js 2009-04-17
13:54:46 UTC (rev 13638)
+++
trunk/ui/colorPicker/src/main/resources/org/richfaces/renderkit/html/scripts/ui.colorpicker.js 2009-04-17
15:07:41 UTC (rev 13639)
@@ -122,7 +122,7 @@
this.patternDec.compile("[^0-9]+");
this.charMin = 65;
var o = this.options, self = this,
- tpl = $(o.clientId.toString()+"-colorPicker-popup");
+ tpl = $(" + div.rich-color-picker-wrapper", this.element);
if (o.color.indexOf('hsb') > -1) {
this.color = this._fixColors(o.color, 'hsb');//
this._fixHSB(this._fixColors(o.color, 'hsb'));
@@ -140,7 +140,7 @@
this.fields = this.picker.find('input')
.bind('keydown', function(e) { return self._keyDown.call(self, e); })
- .bind('change', function(e) { return self._change.call(self, e); })
+ .bind('change', function(e) { return self._select.call(self, e); })
.bind('blur', function(e) { return self._blur.call(self, e); })
.bind('focus', function(e) { return self._focus.call(self, e); });
@@ -153,7 +153,7 @@
this.newColor = this.picker.find('div.rich-color-picker-new-color');
this.currentColor = this.picker.find('div.rich-color-picker-current-color');
- this.iconColor = $(o.clientId.toString()+' .rich-color-picker-icon');
+ this.iconColor = $('.rich-color-picker-icon', this.element);
this.picker.find('.rich-color-picker-submit')
.bind('mouseenter', function(e) { return self._enterSubmit.call(self, e); })
@@ -257,7 +257,7 @@
};
},
- _change: function(e, target) {
+ _select: function(e, target) {
var col;
target = target || e.target;
@@ -306,7 +306,7 @@
this._setSelector(col);
this._setHue(col);
this._setNewColor(col);
- this._trigger('change', e, this._createEventArgument(col));
+ this._trigger('select', e, this._createEventArgument(col));
},
_blur: function(e) {
this.fields.parent().removeClass('rich-color-picker-focus');
@@ -325,7 +325,7 @@
y: this.picker.find('div.rich-color-picker-rainbow').offset().top
};
- this._change.apply(this, [e, this
+ this._select.apply(this, [e, this
.fields
.eq(4)
.val(parseInt(360*(150 - Math.max(0,Math.min(150,(e.pageY -
this.currentHue.y))))/150, 10))
@@ -339,7 +339,7 @@
},
_moveHue: function(e) {
- this._change.apply(this, [e, this
+ this._select.apply(this, [e, this
.fields
.eq(4)
.val(parseInt(360*(150 - Math.max(0,Math.min(150,(e.pageY -
this.currentHue.y))))/150, 10))
@@ -360,7 +360,7 @@
pos: this.picker.find('div.rich-color-picker-color').offset()
};
- this._change.apply(this, [e, this
+ this._select.apply(this, [e, this
.fields
.eq(6)
.val(parseInt(100*(150 - Math.max(0,Math.min(150,(e.pageY -
this.currentSelector.pos.top))))/150, 10))
@@ -376,7 +376,7 @@
},
_moveSelector: function(e) {
- this._change.apply(this, [e, this
+ this._select.apply(this, [e, this
.fields
.eq(6)
.val(parseInt(100*(150 - Math.max(0,Math.min(150,(e.pageY -
this.currentSelector.pos.top))))/150, 10))
@@ -410,7 +410,22 @@
var col = this.color;
this._setCurrentColor(col);
this._setIconColor(col);
- this._trigger("submit", e, this._createEventArgument(col));
+
+ var rgb = col.toRGB();
+ var newValue;
+
+ if (this.options.rgbColorMode) {
+ newValue = 'rgb('+rgb.r+', '+rgb.g+', '+rgb.b+')';
+ } else {
+ newValue = '#' + this._RGBToHex(rgb);
+ }
+
+ var input = $('input', this.element);
+ if (newValue !== input.val()) {
+ input.val(newValue);
+ this._trigger("change", e, this._createEventArgument(col));
+ }
+
this.picker.hide();
$(document).unbind('mousedown.colorPicker');
return false;
@@ -428,7 +443,7 @@
this.picker.css('visibility', 'hidden').css('display',
'block');
- var input = $(this.options.clientId.toString()+' input');
+ var input = $('input', this.element);
var inputOffsets = input.offset();
var elementRect = {left:inputOffsets.left, top: inputOffsets.top, width:
this.element.width(), height:input.outerHeight()};
Richfaces.jQuery.position(elementRect, this.picker);
Modified: trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx
===================================================================
--- trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx 2009-04-17
13:54:46 UTC (rev 13638)
+++ trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx 2009-04-17
15:07:41 UTC (rev 13639)
@@ -22,6 +22,7 @@
<c:object var="showEvent" type="java.lang.String" />
<c:object var="clientIdJquery" type="java.lang.String" />
<c:object var="colorMode" type="java.lang.String" />
+ <c:object var="isRGBColorMode" type="boolean" />
<c:object var="value" type="java.lang.String"
value="#{this:getInputValue(context, component)}" />
<f:call name="addPopupToAjaxRendered" />
@@ -110,8 +111,10 @@
colorMode = (String) component.getAttributes().get("colorMode");
showEvent = (String) component.getAttributes().get("showEvent");
+ isRGBColorMode = UIColorPicker.COLOR_MODE_RGB.equals(colorMode);
+
if (value == null || value.length() == 0){
- if (UIColorPicker.COLOR_MODE_RGB.equals(colorMode)) {
+ if (isRGBColorMode) {
value = "rgb(255, 255, 255)";
} else {
value = "#ffffff";
@@ -138,19 +141,7 @@
flat: #{component.attributes['flat']},
color: "#{value}",
showEvent: "#{showEvent}",
- clientId: '\##{clientIdJquery}',
- submit: function(e, ui) {
- switch("#{colorMode}"){
- case "hex":
- jQuery('\##{clientIdJquery} input').val('#' + ui.hex);
- break;
- case "rgb":
- jQuery('\##{clientIdJquery} input').val('rgb('+ui.rgb.r+',
'+ui.rgb.g+', '+ui.rgb.b+')');
- break;
- default:
- jQuery('\##{clientIdJquery} input').val('#' + ui.hex);
- }
- }
+ rgbColorMode: #{isRGBColorMode}
})#{this:encodeEvents(context, component)};
</script>