diff options
author | Chi Cheng <cloudream@gmail.com> | 2008-08-17 02:15:55 +0000 |
---|---|---|
committer | Chi Cheng <cloudream@gmail.com> | 2008-08-17 02:15:55 +0000 |
commit | dd6a17b434c471af0a809f38806859c93d9c1bb4 (patch) | |
tree | 5374cc4e63c8e0e3ef9678874380c6ce497dc5b5 /ui/ui.colorpicker.js | |
parent | 8c3be4fdcbbbc24c84963a4039f72f7863b98167 (diff) | |
download | jquery-ui-dd6a17b434c471af0a809f38806859c93d9c1bb4.tar.gz jquery-ui-dd6a17b434c471af0a809f38806859c93d9c1bb4.zip |
Internal methods: fixes #3195, #3196, #3200, #3201, #3209
Diffstat (limited to 'ui/ui.colorpicker.js')
-rw-r--r-- | ui/ui.colorpicker.js | 226 |
1 files changed, 113 insertions, 113 deletions
diff --git a/ui/ui.colorpicker.js b/ui/ui.colorpicker.js index 6cc797369..45e1d3ec4 100644 --- a/ui/ui.colorpicker.js +++ b/ui/ui.colorpicker.js @@ -14,18 +14,18 @@ $.widget("ui.colorpicker", {
- init: function() {
+ _init: function() {
this.charMin = 65;
var o = this.options, self = this,
tpl = '<div class="ui-colorpicker clearfix"><div class="ui-colorpicker-color"><div><div></div></div></div><div class="ui-colorpicker-hue"><div></div></div><div class="ui-colorpicker-new-color"></div><div class="ui-colorpicker-current-color"></div><div class="ui-colorpicker-hex"><label for="ui-colorpicker-hex" title="hex">#</label><input type="text" maxlength="6" size="6" /></div><div class="ui-colorpicker-rgb-r ui-colorpicker-field"><label for="ui-colorpicker-rgb-r">R</label><input type="text" maxlength="3" size="3" /><span></span></div><div class="ui-colorpicker-rgb-g ui-colorpicker-field"><label for="ui-colorpicker-rgb-g">G</label><input type="text" maxlength="3" size="3" /><span></span></div><div class="ui-colorpicker-rgb-b ui-colorpicker-field"><label for="ui-colorpicker-rgb-b">B</label><input type="text" maxlength="3" size="3" /><span></span></div><div class="ui-colorpicker-hsb-h ui-colorpicker-field"><label for="ui-colorpicker-hsb-h">H</label><input type="text" maxlength="3" size="3" /><span></span></div><div class="ui-colorpicker-hsb-s ui-colorpicker-field"><label for="ui-colorpicker-hsb-s">S</label><input type="text" maxlength="3" size="3" /><span></span></div><div class="ui-colorpicker-hsb-b ui-colorpicker-field"><label for="ui-colorpicker-hsb-b">B</label><input type="text" maxlength="3" size="3" /><span></span></div><button class="ui-colorpicker-submit ui-default-state" name="submit" type="submit">Done</button></div>';
if (typeof o.color == 'string') {
- this.color = this.HexToHSB(o.color);
+ this.color = this._HexToHSB(o.color);
} else if (o.color.r != undefined && o.color.g != undefined && o.color.b != undefined) {
- this.color = this.RGBToHSB(o.color);
+ this.color = this._RGBToHSB(o.color);
} else if (o.color.h != undefined && o.color.s != undefined && o.color.b != undefined) {
- this.color = this.fixHSB(o.color);
+ this.color = this._fixHSB(o.color);
} else {
return this;
}
@@ -40,33 +40,33 @@ $.widget("ui.colorpicker", { }
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('blur', function(e) { return self.blur.call(self, e); })
- .bind('focus', function(e) { return self.focus.call(self, e); });
+ .bind('keydown', function(e) { return self._keyDown.call(self, e); })
+ .bind('change', function(e) { return self._change.call(self, e); })
+ .bind('blur', function(e) { return self._blur.call(self, e); })
+ .bind('focus', function(e) { return self._focus.call(self, e); });
- this.picker.find('span').bind('mousedown', function(e) { return self.downIncrement.call(self, e); });
+ this.picker.find('span').bind('mousedown', function(e) { return self._downIncrement.call(self, e); });
- this.selector = this.picker.find('div.ui-colorpicker-color').bind('mousedown', function(e) { return self.downSelector.call(self, e); });
+ this.selector = this.picker.find('div.ui-colorpicker-color').bind('mousedown', function(e) { return self._downSelector.call(self, e); });
this.selectorIndic = this.selector.find('div div');
this.hue = this.picker.find('div.ui-colorpicker-hue div');
- this.picker.find('div.ui-colorpicker-hue').bind('mousedown', function(e) { return self.downHue.call(self, e); });
+ this.picker.find('div.ui-colorpicker-hue').bind('mousedown', function(e) { return self._downHue.call(self, e); });
this.newColor = this.picker.find('div.ui-colorpicker-new-color');
this.currentColor = this.picker.find('div.ui-colorpicker-current-color');
this.picker.find('div.ui-colorpicker-submit')
- .bind('mouseenter', function(e) { return self.enterSubmit.call(self, e); })
- .bind('mouseleave', function(e) { return self.leaveSubmit.call(self, e); })
- .bind('click', function(e) { return self.clickSubmit.call(self, e); });
+ .bind('mouseenter', function(e) { return self._enterSubmit.call(self, e); })
+ .bind('mouseleave', function(e) { return self._leaveSubmit.call(self, e); })
+ .bind('click', function(e) { return self._clickSubmit.call(self, e); });
- this.fillRGBFields(this.color);
- this.fillHSBFields(this.color);
- this.fillHexFields(this.color);
- this.setHue(this.color);
- this.setSelector(this.color);
- this.setCurrentColor(this.color);
- this.setNewColor(this.color);
+ this._fillRGBFields(this.color);
+ this._fillHSBFields(this.color);
+ this._fillHexFields(this.color);
+ this._setHue(this.color);
+ this._setSelector(this.color);
+ this._setCurrentColor(this.color);
+ this._setNewColor(this.color);
if (o.flat) {
this.picker.css({
@@ -74,7 +74,7 @@ $.widget("ui.colorpicker", { display: 'block'
});
} else {
- $(this.element).bind(o.eventName+".colorpicker", function(e) { return self.show.call(self, e); });
+ $(this.element).bind(o.eventName+".colorpicker", function(e) { return self._show.call(self, e); });
}
},
@@ -86,96 +86,96 @@ $.widget("ui.colorpicker", { },
- fillRGBFields: function(hsb) {
- var rgb = this.HSBToRGB(hsb);
+ _fillRGBFields: function(hsb) {
+ var rgb = this._HSBToRGB(hsb);
this.fields
.eq(1).val(rgb.r).end()
.eq(2).val(rgb.g).end()
.eq(3).val(rgb.b).end();
},
- fillHSBFields: function(hsb) {
+ _fillHSBFields: function(hsb) {
this.fields
.eq(4).val(hsb.h).end()
.eq(5).val(hsb.s).end()
.eq(6).val(hsb.b).end();
},
- fillHexFields: function (hsb) {
+ _fillHexFields: function (hsb) {
this.fields
- .eq(0).val(this.HSBToHex(hsb)).end();
+ .eq(0).val(this._HSBToHex(hsb)).end();
},
- setSelector: function(hsb) {
- this.selector.css('backgroundColor', '#' + this.HSBToHex({h: hsb.h, s: 100, b: 100}));
+ _setSelector: function(hsb) {
+ this.selector.css('backgroundColor', '#' + this._HSBToHex({h: hsb.h, s: 100, b: 100}));
this.selectorIndic.css({
left: parseInt(150 * hsb.s/100, 10),
top: parseInt(150 * (100-hsb.b)/100, 10)
});
},
- setHue: function(hsb) {
+ _setHue: function(hsb) {
this.hue.css('top', parseInt(150 - 150 * hsb.h/360, 10));
},
- setCurrentColor: function(hsb) {
- this.currentColor.css('backgroundColor', '#' + this.HSBToHex(hsb));
+ _setCurrentColor: function(hsb) {
+ this.currentColor.css('backgroundColor', '#' + this._HSBToHex(hsb));
},
- setNewColor: function(hsb) {
- this.newColor.css('backgroundColor', '#' + this.HSBToHex(hsb));
+ _setNewColor: function(hsb) {
+ this.newColor.css('backgroundColor', '#' + this._HSBToHex(hsb));
},
- keyDown: function(e) {
+ _keyDown: function(e) {
var pressedKey = e.charCode || e.keyCode || -1;
if ((pressedKey >= this.charMin && pressedKey <= 90) || pressedKey == 32) {
return false;
}
},
- change: function(e, target) {
+ _change: function(e, target) {
var col;
target = target || e.target;
if (target.parentNode.className.indexOf('-hex') > 0) {
- this.color = col = this.HexToHSB(this.value);
- this.fillRGBFields(col.color);
- this.fillHSBFields(col);
+ this.color = col = this._HexToHSB(this.value);
+ this._fillRGBFields(col.color);
+ this._fillHSBFields(col);
} else if (target.parentNode.className.indexOf('-hsb') > 0) {
- this.color = col = this.fixHSB({
+ this.color = col = this._fixHSB({
h: parseInt(this.fields.eq(4).val(), 10),
s: parseInt(this.fields.eq(5).val(), 10),
b: parseInt(this.fields.eq(6).val(), 10)
});
- this.fillRGBFields(col);
- this.fillHexFields(col);
+ this._fillRGBFields(col);
+ this._fillHexFields(col);
} else {
- this.color = col = this.RGBToHSB(this.fixRGB({
+ this.color = col = this._RGBToHSB(this._fixRGB({
r: parseInt(this.fields.eq(1).val(), 10),
g: parseInt(this.fields.eq(2).val(), 10),
b: parseInt(this.fields.eq(3).val(), 10)
}));
- this.fillHexFields(col);
- this.fillHSBFields(col);
+ this._fillHexFields(col);
+ this._fillHSBFields(col);
}
- this.setSelector(col);
- this.setHue(col);
- this.setNewColor(col);
+ this._setSelector(col);
+ this._setHue(col);
+ this._setNewColor(col);
- this.trigger('change', e, { options: this.options, hsb: col, hex: this.HSBToHex(col), rgb: this.HSBToRGB(col) });
+ this._trigger('change', e, { options: this.options, hsb: col, hex: this._HSBToHex(col), rgb: this._HSBToRGB(col) });
},
- blur: function(e) {
+ _blur: function(e) {
var col = this.color;
- this.fillRGBFields(col);
- this.fillHSBFields(col);
- this.fillHexFields(col);
- this.setHue(col);
- this.setSelector(col);
- this.setNewColor(col);
+ this._fillRGBFields(col);
+ this._fillHSBFields(col);
+ this._fillHexFields(col);
+ this._setHue(col);
+ this._setSelector(col);
+ this._setNewColor(col);
this.fields.parent().removeClass('ui-colorpicker-focus');
},
- focus: function(e) {
+ _focus: function(e) {
this.charMin = e.target.parentNode.className.indexOf('-hex') > 0 ? 70 : 65;
this.fields.parent().removeClass('ui-colorpicker-focus');
$(e.target.parentNode).addClass('ui-colorpicker-focus');
},
- downIncrement: function(e) {
+ _downIncrement: function(e) {
var field = $(e.target).parent().find('input').focus(), self = this;
this.currentIncrement = {
@@ -185,44 +185,44 @@ $.widget("ui.colorpicker", { field: field,
val: parseInt(field.val(), 10)
};
- $(document).bind('mouseup.cpSlider', function(e) { return self.upIncrement.call(self, e); });
- $(document).bind('mousemove.cpSlider', function(e) { return self.moveIncrement.call(self, e); });
+ $(document).bind('mouseup.cpSlider', function(e) { return self._upIncrement.call(self, e); });
+ $(document).bind('mousemove.cpSlider', function(e) { return self._moveIncrement.call(self, e); });
return false;
},
- moveIncrement: function(e) {
+ _moveIncrement: function(e) {
this.currentIncrement.field.val(Math.max(0, Math.min(this.currentIncrement.max, parseInt(this.currentIncrement.val + e.pageY - this.currentIncrement.y, 10))));
- this.change.apply(this, [e, this.currentIncrement.field.get(0)]);
+ this._change.apply(this, [e, this.currentIncrement.field.get(0)]);
return false;
},
- upIncrement: function(e) {
+ _upIncrement: function(e) {
this.currentIncrement.el.removeClass('ui-colorpicker-slider').find('input').focus();
- this.change.apply(this, [e, this.currentIncrement.field.get(0)]);
+ this._change.apply(this, [e, this.currentIncrement.field.get(0)]);
$(document).unbind('mouseup.cpSlider');
$(document).unbind('mousemove.cpSlider');
return false;
},
- downHue: function(e) {
+ _downHue: function(e) {
this.currentHue = {
y: this.picker.find('div.ui-colorpicker-hue').offset().top
};
- this.change.apply(this, [e, this
+ this._change.apply(this, [e, this
.fields
.eq(4)
.val(parseInt(360*(150 - Math.max(0,Math.min(150,(e.pageY - this.currentHue.y))))/150, 10))
.get(0)]);
var self = this;
- $(document).bind('mouseup.cpSlider', function(e) { return self.upHue.call(self, e); });
- $(document).bind('mousemove.cpSlider', function(e) { return self.moveHue.call(self, e); });
+ $(document).bind('mouseup.cpSlider', function(e) { return self._upHue.call(self, e); });
+ $(document).bind('mousemove.cpSlider', function(e) { return self._moveHue.call(self, e); });
return false;
},
- moveHue: function(e) {
+ _moveHue: function(e) {
- this.change.apply(this, [e, this
+ this._change.apply(this, [e, this
.fields
.eq(4)
.val(parseInt(360*(150 - Math.max(0,Math.min(150,(e.pageY - this.currentHue.y))))/150, 10))
@@ -231,19 +231,19 @@ $.widget("ui.colorpicker", { return false;
},
- upHue: function(e) {
+ _upHue: function(e) {
$(document).unbind('mouseup.cpSlider');
$(document).unbind('mousemove.cpSlider');
return false;
},
- downSelector: function(e) {
+ _downSelector: function(e) {
var self = this;
this.currentSelector = {
pos: this.picker.find('div.ui-colorpicker-color').offset()
};
- this.change.apply(this, [e, this
+ this._change.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))
@@ -252,14 +252,14 @@ $.widget("ui.colorpicker", { .val(parseInt(100*(Math.max(0,Math.min(150,(e.pageX - this.currentSelector.pos.left))))/150, 10))
.get(0)
]);
- $(document).bind('mouseup.cpSlider', function(e) { return self.upSelector.call(self, e); });
- $(document).bind('mousemove.cpSlider', function(e) { return self.moveSelector.call(self, e); });
+ $(document).bind('mouseup.cpSlider', function(e) { return self._upSelector.call(self, e); });
+ $(document).bind('mousemove.cpSlider', function(e) { return self._moveSelector.call(self, e); });
return false;
},
- moveSelector: function(e) {
+ _moveSelector: function(e) {
- this.change.apply(this, [e, this
+ this._change.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))
@@ -271,33 +271,33 @@ $.widget("ui.colorpicker", { return false;
},
- upSelector: function(e) {
+ _upSelector: function(e) {
$(document).unbind('mouseup.cpSlider');
$(document).unbind('mousemove.cpSlider');
return false;
},
- enterSubmit: function(e) {
+ _enterSubmit: function(e) {
this.picker.find('div.ui-colorpicker-submit').addClass('ui-colorpicker-focus');
},
- leaveSubmit: function(e) {
+ _leaveSubmit: function(e) {
this.picker.find('div.ui-colorpicker-submit').removeClass('ui-colorpicker-focus');
},
- clickSubmit: function(e) {
+ _clickSubmit: function(e) {
var col = this.color;
this.origColor = col;
- this.setCurrentColor(col);
+ this._setCurrentColor(col);
- this.trigger("submit", e, { options: this.options, hsb: col, hex: this.HSBToHex(col), rgb: this.HSBToRGB(col) });
+ this._trigger("submit", e, { options: this.options, hsb: col, hex: this._HSBToHex(col), rgb: this._HSBToRGB(col) });
return false;
},
- show: function(e) {
+ _show: function(e) {
- this.trigger("beforeShow", e, { options: this.options, hsb: this.color, hex: this.HSBToHex(this.color), rgb: this.HSBToRGB(this.color) });
+ this._trigger("beforeShow", e, { options: this.options, hsb: this.color, hex: this._HSBToHex(this.color), rgb: this._HSBToRGB(this.color) });
var pos = this.element.offset();
- var viewPort = this.getScroll();
+ var viewPort = this._getScroll();
var top = pos.top + this.element[0].offsetHeight;
var left = pos.left;
if (top + 176 > viewPort.t + Math.min(viewPort.h,viewPort.ih)) {
@@ -307,26 +307,26 @@ $.widget("ui.colorpicker", { left -= 356;
}
this.picker.css({left: left + 'px', top: top + 'px'});
- if (this.trigger("show", e, { options: this.options, hsb: this.color, hex: this.HSBToHex(this.color), rgb: this.HSBToRGB(this.color) }) != false) {
+ if (this._trigger("show", e, { options: this.options, hsb: this.color, hex: this._HSBToHex(this.color), rgb: this._HSBToRGB(this.color) }) != false) {
this.picker.show();
}
var self = this;
- $(document).bind('mousedown.colorpicker', function(e) { return self.hide.call(self, e); });
+ $(document).bind('mousedown.colorpicker', function(e) { return self._hide.call(self, e); });
return false;
},
- hide: function(e) {
+ _hide: function(e) {
- if (!this.isChildOf(this.picker[0], e.target, this.picker[0])) {
- if (this.trigger("hide", e, { options: this.options, hsb: this.color, hex: this.HSBToHex(this.color), rgb: this.HSBToRGB(this.color) }) != false) {
+ if (!this._isChildOf(this.picker[0], e.target, this.picker[0])) {
+ if (this._trigger("hide", e, { options: this.options, hsb: this.color, hex: this._HSBToHex(this.color), rgb: this._HSBToRGB(this.color) }) != false) {
this.picker.hide();
}
$(document).unbind('mousedown.colorpicker');
}
},
- isChildOf: function(parentEl, el, container) {
+ _isChildOf: function(parentEl, el, container) {
if (parentEl == el) {
return true;
}
@@ -344,7 +344,7 @@ $.widget("ui.colorpicker", { }
return false;
},
- getScroll: function() {
+ _getScroll: function() {
var t,l,w,h,iw,ih;
if (document.documentElement) {
t = document.documentElement.scrollTop;
@@ -361,28 +361,28 @@ $.widget("ui.colorpicker", { ih = self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0;
return { t: t, l: l, w: w, h: h, iw: iw, ih: ih };
},
- fixHSB: function(hsb) {
+ _fixHSB: function(hsb) {
return {
h: Math.min(360, Math.max(0, hsb.h)),
s: Math.min(100, Math.max(0, hsb.s)),
b: Math.min(100, Math.max(0, hsb.b))
};
},
- fixRGB: function(rgb) {
+ _fixRGB: function(rgb) {
return {
r: Math.min(255, Math.max(0, rgb.r)),
g: Math.min(255, Math.max(0, rgb.g)),
b: Math.min(255, Math.max(0, rgb.b))
};
},
- HexToRGB: function (hex) {
+ _HexToRGB: function (hex) {
var hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
},
- HexToHSB: function(hex) {
- return this.RGBToHSB(this.HexToRGB(hex));
+ _HexToHSB: function(hex) {
+ return this._RGBToHSB(this._HexToRGB(hex));
},
- RGBToHSB: function(rgb) {
+ _RGBToHSB: function(rgb) {
var hsb = {};
hsb.b = Math.max(Math.max(rgb.r,rgb.g),rgb.b);
hsb.s = (hsb.b <= 0) ? 0 : Math.round(100*(hsb.b - Math.min(Math.min(rgb.r,rgb.g),rgb.b))/hsb.b);
@@ -398,7 +398,7 @@ $.widget("ui.colorpicker", { hsb.h = Math.round(hsb.h);
return hsb;
},
- HSBToRGB: function(hsb) {
+ _HSBToRGB: function(hsb) {
var rgb = {};
var h = Math.round(hsb.h);
var s = Math.round(hsb.s*255/100);
@@ -420,7 +420,7 @@ $.widget("ui.colorpicker", { }
return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)};
},
- RGBToHex: function(rgb) {
+ _RGBToHex: function(rgb) {
var hex = [
rgb.r.toString(16),
rgb.g.toString(16),
@@ -433,29 +433,29 @@ $.widget("ui.colorpicker", { });
return hex.join('');
},
- HSBToHex: function(hsb) {
- return this.RGBToHex(this.HSBToRGB(hsb));
+ _HSBToHex: function(hsb) {
+ return this._RGBToHex(this._HSBToRGB(hsb));
},
setColor: function(col) {
if (typeof col == 'string') {
- col = this.HexToHSB(col);
+ col = this._HexToHSB(col);
} else if (col.r != undefined && col.g != undefined && col.b != undefined) {
- col = this.RGBToHSB(col);
+ col = this._RGBToHSB(col);
} else if (col.h != undefined && col.s != undefined && col.b != undefined) {
- col = this.fixHSB(col);
+ col = this._fixHSB(col);
} else {
return this;
}
this.color = col;
this.origColor = col;
- this.fillRGBFields(col);
- this.fillHSBFields(col);
- this.fillHexFields(col);
- this.setHue(col);
- this.setSelector(col);
- this.setCurrentColor(col);
- this.setNewColor(col);
+ this._fillRGBFields(col);
+ this._fillHSBFields(col);
+ this._fillHexFields(col);
+ this._setHue(col);
+ this._setSelector(col);
+ this._setCurrentColor(col);
+ this._setNewColor(col);
}
|