Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #37 from bpierre/master

ColorPicker: Firefox compatibility
  • Loading branch information...
commit cfef365e2c023c75a7a6554dc8bb987c2c08e807 2 parents 2564e93 + bd376b1
@tj authored
Showing with 42 additions and 14 deletions.
  1. +21 −7 build/ui.js
  2. +21 −7 lib/components/color-picker/color-picker.js
View
28 build/ui.js
@@ -597,6 +597,17 @@ function rgba(r,g,b,a) {
}
/**
+ * Mouse position util.
+ */
+function localPos(e) {
+ var offset = $(e.target).offset();
+ return {
+ x: e.pageX - offset.left
+ , y: e.pageY - offset.top
+ };
+}
+
+/**
* Initialize a new `ColorPicker`.
*
* Emits:
@@ -682,10 +693,11 @@ ColorPicker.prototype.spectrumEvents = function(){
, down;
function update(e) {
- var color = self.hueAt(e.offsetY - 4);
+ var offsetY = localPos(e).y
+ , color = self.hueAt(offsetY - 4);
self.hue(color.toString());
self.emit('change', color);
- self._huePos = e.offsetY;
+ self._huePos = offsetY;
self.render();
}
@@ -716,10 +728,12 @@ ColorPicker.prototype.mainEvents = function(){
, down;
function update(e) {
- var color = self.colorAt(e.offsetX, e.offsetY);
+ var color;
+ self._colorPos = localPos(e);
+ color = self.colorAt(self._colorPos.x, self._colorPos.y);
self.color(color.toString());
self.emit('change', color);
- self._colorPos = e;
+
self.render();
}
@@ -759,7 +773,7 @@ ColorPicker.prototype.colorAt = function(x, y){
};
/**
- * Get the RGB value at `y`.
+ * Get the RGB value at `y`.
*
* @param {Type} name
* @return {Type}
@@ -870,8 +884,8 @@ ColorPicker.prototype.renderMain = function(options){
, ctx = canvas.getContext('2d')
, w = this.w
, h = this.h
- , x = (this._colorPos.offsetX || w) + .5
- , y = (this._colorPos.offsetY || 0) + .5;
+ , x = (this._colorPos.x || w) + .5
+ , y = (this._colorPos.y || 0) + .5;
canvas.width = w;
canvas.height = h;
View
28 lib/components/color-picker/color-picker.js
@@ -22,6 +22,17 @@ function rgba(r,g,b,a) {
}
/**
+ * Mouse position util.
+ */
+function localPos(e) {
+ var offset = $(e.target).offset();
+ return {
+ x: e.pageX - offset.left
+ , y: e.pageY - offset.top
+ };
+}
+
+/**
* Initialize a new `ColorPicker`.
*
* Emits:
@@ -107,10 +118,11 @@ ColorPicker.prototype.spectrumEvents = function(){
, down;
function update(e) {
- var color = self.hueAt(e.offsetY - 4);
+ var offsetY = localPos(e).y
+ , color = self.hueAt(offsetY - 4);
self.hue(color.toString());
self.emit('change', color);
- self._huePos = e.offsetY;
+ self._huePos = offsetY;
self.render();
}
@@ -141,10 +153,12 @@ ColorPicker.prototype.mainEvents = function(){
, down;
function update(e) {
- var color = self.colorAt(e.offsetX, e.offsetY);
+ var color;
+ self._colorPos = localPos(e);
+ color = self.colorAt(self._colorPos.x, self._colorPos.y);
self.color(color.toString());
self.emit('change', color);
- self._colorPos = e;
+
self.render();
}
@@ -184,7 +198,7 @@ ColorPicker.prototype.colorAt = function(x, y){
};
/**
- * Get the RGB value at `y`.
+ * Get the RGB value at `y`.
*
* @param {Type} name
* @return {Type}
@@ -295,8 +309,8 @@ ColorPicker.prototype.renderMain = function(options){
, ctx = canvas.getContext('2d')
, w = this.w
, h = this.h
- , x = (this._colorPos.offsetX || w) + .5
- , y = (this._colorPos.offsetY || 0) + .5;
+ , x = (this._colorPos.x || w) + .5
+ , y = (this._colorPos.y || 0) + .5;
canvas.width = w;
canvas.height = h;
Please sign in to comment.
Something went wrong with that request. Please try again.