PluginProbe ʕ •ᴥ•ʔ
Products Compare for WooCommerce / 1.0.13.1
Products Compare for WooCommerce v1.0.13.1
3.6.2.8 3.6.2.7 trunk 1.0.1 1.0.10 1.0.10.1 1.0.11 1.0.11.1 1.0.12 1.0.13 1.0.13.1 1.0.2 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 3.5 3.5.0.1 3.5.0.2 3.5.1 3.5.1.1 3.5.1.2 3.5.1.3 3.5.1.4 3.5.1.5 3.5.1.6 3.5.1.7 3.5.2 3.5.2.1 3.5.2.2 3.5.2.3 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.7.1 3.5.7.2 3.5.7.3 3.5.7.4 3.5.7.5 3.5.7.6 3.5.7.7 3.5.7.8 3.5.7.9 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.2.1 3.6.2.2 3.6.2.3 3.6.2.4 3.6.2.5 3.6.2.6
products-compare-for-woocommerce / js / colpick.js
products-compare-for-woocommerce / js Last commit date
admin.js 7 years ago colpick.js 7 years ago jquery.cookie.js 7 years ago jquery.mousewheel.min.js 7 years ago products_compare.js 7 years ago
colpick.js
521 lines
1 /*
2 colpick Color Picker
3 Copyright 2013 Jose Vargas. Licensed under GPL license. Based on Stefan Petre's Color Picker www.eyecon.ro, dual licensed under the MIT and GPL licenses
4
5 For usage and examples: colpick.com/plugin
6 */
7
8 (function ($) {
9 var colpick = function () {
10 var
11 tpl = '<div class="colpick"><div class="colpick_color"><div class="colpick_color_overlay1"><div class="colpick_color_overlay2"><div class="colpick_selector_outer"><div class="colpick_selector_inner"></div></div></div></div></div><div class="colpick_hue"><div class="colpick_hue_arrs"><div class="colpick_hue_larr"></div><div class="colpick_hue_rarr"></div></div></div><div class="colpick_new_color"></div><div class="colpick_current_color"></div><div class="colpick_hex_field"><div class="colpick_field_letter">#</div><input type="text" maxlength="6" size="6" /></div><div class="colpick_rgb_r colpick_field"><div class="colpick_field_letter">R</div><input type="text" maxlength="3" size="3" /><div class="colpick_field_arrs"><div class="colpick_field_uarr"></div><div class="colpick_field_darr"></div></div></div><div class="colpick_rgb_g colpick_field"><div class="colpick_field_letter">G</div><input type="text" maxlength="3" size="3" /><div class="colpick_field_arrs"><div class="colpick_field_uarr"></div><div class="colpick_field_darr"></div></div></div><div class="colpick_rgb_b colpick_field"><div class="colpick_field_letter">B</div><input type="text" maxlength="3" size="3" /><div class="colpick_field_arrs"><div class="colpick_field_uarr"></div><div class="colpick_field_darr"></div></div></div><div class="colpick_hsb_h colpick_field"><div class="colpick_field_letter">H</div><input type="text" maxlength="3" size="3" /><div class="colpick_field_arrs"><div class="colpick_field_uarr"></div><div class="colpick_field_darr"></div></div></div><div class="colpick_hsb_s colpick_field"><div class="colpick_field_letter">S</div><input type="text" maxlength="3" size="3" /><div class="colpick_field_arrs"><div class="colpick_field_uarr"></div><div class="colpick_field_darr"></div></div></div><div class="colpick_hsb_b colpick_field"><div class="colpick_field_letter">B</div><input type="text" maxlength="3" size="3" /><div class="colpick_field_arrs"><div class="colpick_field_uarr"></div><div class="colpick_field_darr"></div></div></div><div class="colpick_submit"></div></div>',
12 defaults = {
13 showEvent: 'click',
14 onShow: function () {},
15 onBeforeShow: function(){},
16 onHide: function () {},
17 onChange: function () {},
18 onSubmit: function () {},
19 colorScheme: 'light',
20 color: '3289c7',
21 livePreview: true,
22 flat: false,
23 layout: 'full',
24 submit: 1,
25 submitText: 'OK',
26 height: 156
27 },
28 //Fill the inputs of the plugin
29 fillRGBFields = function (hsb, cal) {
30 var rgb = hsbToRgb(hsb);
31 $(cal).data('colpick').fields
32 .eq(1).val(rgb.r).end()
33 .eq(2).val(rgb.g).end()
34 .eq(3).val(rgb.b).end();
35 },
36 fillHSBFields = function (hsb, cal) {
37 $(cal).data('colpick').fields
38 .eq(4).val(Math.round(hsb.h)).end()
39 .eq(5).val(Math.round(hsb.s)).end()
40 .eq(6).val(Math.round(hsb.b)).end();
41 },
42 fillHexFields = function (hsb, cal) {
43 $(cal).data('colpick').fields.eq(0).val(hsbToHex(hsb));
44 },
45 //Set the round selector position
46 setSelector = function (hsb, cal) {
47 $(cal).data('colpick').selector.css('backgroundColor', '#' + hsbToHex({h: hsb.h, s: 100, b: 100}));
48 $(cal).data('colpick').selectorIndic.css({
49 left: parseInt($(cal).data('colpick').height * hsb.s/100, 10),
50 top: parseInt($(cal).data('colpick').height * (100-hsb.b)/100, 10)
51 });
52 },
53 //Set the hue selector position
54 setHue = function (hsb, cal) {
55 $(cal).data('colpick').hue.css('top', parseInt($(cal).data('colpick').height - $(cal).data('colpick').height * hsb.h/360, 10));
56 },
57 //Set current and new colors
58 setCurrentColor = function (hsb, cal) {
59 $(cal).data('colpick').currentColor.css('backgroundColor', '#' + hsbToHex(hsb));
60 },
61 setNewColor = function (hsb, cal) {
62 $(cal).data('colpick').newColor.css('backgroundColor', '#' + hsbToHex(hsb));
63 },
64 //Called when the new color is changed
65 change = function (ev) {
66 var cal = $(this).parent().parent(), col;
67 if (this.parentNode.className.indexOf('_hex') > 0) {
68 cal.data('colpick').color = col = hexToHsb(fixHex(this.value));
69 fillRGBFields(col, cal.get(0));
70 fillHSBFields(col, cal.get(0));
71 } else if (this.parentNode.className.indexOf('_hsb') > 0) {
72 cal.data('colpick').color = col = fixHSB({
73 h: parseInt(cal.data('colpick').fields.eq(4).val(), 10),
74 s: parseInt(cal.data('colpick').fields.eq(5).val(), 10),
75 b: parseInt(cal.data('colpick').fields.eq(6).val(), 10)
76 });
77 fillRGBFields(col, cal.get(0));
78 fillHexFields(col, cal.get(0));
79 } else {
80 cal.data('colpick').color = col = rgbToHsb(fixRGB({
81 r: parseInt(cal.data('colpick').fields.eq(1).val(), 10),
82 g: parseInt(cal.data('colpick').fields.eq(2).val(), 10),
83 b: parseInt(cal.data('colpick').fields.eq(3).val(), 10)
84 }));
85 fillHexFields(col, cal.get(0));
86 fillHSBFields(col, cal.get(0));
87 }
88 setSelector(col, cal.get(0));
89 setHue(col, cal.get(0));
90 setNewColor(col, cal.get(0));
91 cal.data('colpick').onChange.apply(cal.parent(), [col, hsbToHex(col), hsbToRgb(col), cal.data('colpick').el, 0]);
92 },
93 //Change style on blur and on focus of inputs
94 blur = function (ev) {
95 $(this).parent().removeClass('colpick_focus');
96 },
97 focus = function () {
98 $(this).parent().parent().data('colpick').fields.parent().removeClass('colpick_focus');
99 $(this).parent().addClass('colpick_focus');
100 },
101 //Increment/decrement arrows functions
102 downIncrement = function (ev) {
103 ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
104 var field = $(this).parent().find('input').focus();
105 var current = {
106 el: $(this).parent().addClass('colpick_slider'),
107 max: this.parentNode.className.indexOf('_hsb_h') > 0 ? 360 : (this.parentNode.className.indexOf('_hsb') > 0 ? 100 : 255),
108 y: ev.pageY,
109 field: field,
110 val: parseInt(field.val(), 10),
111 preview: $(this).parent().parent().data('colpick').livePreview
112 };
113 $(document).mouseup(current, upIncrement);
114 $(document).mousemove(current, moveIncrement);
115 },
116 moveIncrement = function (ev) {
117 ev.data.field.val(Math.max(0, Math.min(ev.data.max, parseInt(ev.data.val - ev.pageY + ev.data.y, 10))));
118 if (ev.data.preview) {
119 change.apply(ev.data.field.get(0), [true]);
120 }
121 return false;
122 },
123 upIncrement = function (ev) {
124 change.apply(ev.data.field.get(0), [true]);
125 ev.data.el.removeClass('colpick_slider').find('input').focus();
126 $(document).off('mouseup', upIncrement);
127 $(document).off('mousemove', moveIncrement);
128 return false;
129 },
130 //Hue slider functions
131 downHue = function (ev) {
132 ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
133 var current = {
134 cal: $(this).parent(),
135 y: $(this).offset().top
136 };
137 $(document).on('mouseup touchend',current,upHue);
138 $(document).on('mousemove touchmove',current,moveHue);
139
140 var pageY = ((ev.type == 'touchstart') ? ev.originalEvent.changedTouches[0].pageY : ev.pageY );
141 change.apply(
142 current.cal.data('colpick')
143 .fields.eq(4).val(parseInt(360*(current.cal.data('colpick').height - (pageY - current.y))/current.cal.data('colpick').height, 10))
144 .get(0),
145 [current.cal.data('colpick').livePreview]
146 );
147 return false;
148 },
149 moveHue = function (ev) {
150 var pageY = ((ev.type == 'touchmove') ? ev.originalEvent.changedTouches[0].pageY : ev.pageY );
151 change.apply(
152 ev.data.cal.data('colpick')
153 .fields.eq(4).val(parseInt(360*(ev.data.cal.data('colpick').height - Math.max(0,Math.min(ev.data.cal.data('colpick').height,(pageY - ev.data.y))))/ev.data.cal.data('colpick').height, 10))
154 .get(0),
155 [ev.data.preview]
156 );
157 return false;
158 },
159 upHue = function (ev) {
160 fillRGBFields(ev.data.cal.data('colpick').color, ev.data.cal.get(0));
161 fillHexFields(ev.data.cal.data('colpick').color, ev.data.cal.get(0));
162 $(document).off('mouseup touchend',upHue);
163 $(document).off('mousemove touchmove',moveHue);
164 return false;
165 },
166 //Color selector functions
167 downSelector = function (ev) {
168 ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
169 var current = {
170 cal: $(this).parent(),
171 pos: $(this).offset()
172 };
173 current.preview = current.cal.data('colpick').livePreview;
174
175 $(document).on('mouseup touchend',current,upSelector);
176 $(document).on('mousemove touchmove',current,moveSelector);
177
178 var payeX,pageY;
179 if(ev.type == 'touchstart') {
180 pageX = ev.originalEvent.changedTouches[0].pageX,
181 pageY = ev.originalEvent.changedTouches[0].pageY;
182 } else {
183 pageX = ev.pageX;
184 pageY = ev.pageY;
185 }
186
187 change.apply(
188 current.cal.data('colpick').fields
189 .eq(6).val(parseInt(100*(current.cal.data('colpick').height - (pageY - current.pos.top))/current.cal.data('colpick').height, 10)).end()
190 .eq(5).val(parseInt(100*(pageX - current.pos.left)/current.cal.data('colpick').height, 10))
191 .get(0),
192 [current.preview]
193 );
194 return false;
195 },
196 moveSelector = function (ev) {
197 var payeX,pageY;
198 if(ev.type == 'touchmove') {
199 pageX = ev.originalEvent.changedTouches[0].pageX,
200 pageY = ev.originalEvent.changedTouches[0].pageY;
201 } else {
202 pageX = ev.pageX;
203 pageY = ev.pageY;
204 }
205
206 change.apply(
207 ev.data.cal.data('colpick').fields
208 .eq(6).val(parseInt(100*(ev.data.cal.data('colpick').height - Math.max(0,Math.min(ev.data.cal.data('colpick').height,(pageY - ev.data.pos.top))))/ev.data.cal.data('colpick').height, 10)).end()
209 .eq(5).val(parseInt(100*(Math.max(0,Math.min(ev.data.cal.data('colpick').height,(pageX - ev.data.pos.left))))/ev.data.cal.data('colpick').height, 10))
210 .get(0),
211 [ev.data.preview]
212 );
213 return false;
214 },
215 upSelector = function (ev) {
216 fillRGBFields(ev.data.cal.data('colpick').color, ev.data.cal.get(0));
217 fillHexFields(ev.data.cal.data('colpick').color, ev.data.cal.get(0));
218 $(document).off('mouseup touchend',upSelector);
219 $(document).off('mousemove touchmove',moveSelector);
220 return false;
221 },
222 //Submit button
223 clickSubmit = function (ev) {
224 var cal = $(this).parent();
225 var col = cal.data('colpick').color;
226 cal.data('colpick').origColor = col;
227 setCurrentColor(col, cal.get(0));
228 cal.data('colpick').onSubmit(col, hsbToHex(col), hsbToRgb(col), cal.data('colpick').el);
229 },
230 //Show/hide the color picker
231 show = function (ev) {
232 // Prevent the trigger of any direct parent
233 ev.stopPropagation();
234 var cal = $('#' + $(this).data('colpickId'));
235 cal.data('colpick').onBeforeShow.apply(this, [cal.get(0)]);
236 var pos = $(this).offset();
237 var top = pos.top + this.offsetHeight;
238 var left = pos.left;
239 var viewPort = getViewport();
240 var calW = cal.width();
241 if (left + calW > viewPort.l + viewPort.w) {
242 left -= calW;
243 }
244 cal.css({left: left + 'px', top: top + 'px'});
245 if (cal.data('colpick').onShow.apply(this, [cal.get(0)]) != false) {
246 cal.show();
247 }
248 //Hide when user clicks outside
249 $('html').mousedown({cal:cal}, hide);
250 cal.mousedown(function(ev){ev.stopPropagation();})
251 },
252 hide = function (ev) {
253 if (ev.data.cal.data('colpick').onHide.apply(this, [ev.data.cal.get(0)]) != false) {
254 ev.data.cal.hide();
255 }
256 $('html').off('mousedown', hide);
257 },
258 getViewport = function () {
259 var m = document.compatMode == 'CSS1Compat';
260 return {
261 l : window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft),
262 w : window.innerWidth || (m ? document.documentElement.clientWidth : document.body.clientWidth)
263 };
264 },
265 //Fix the values if the user enters a negative or high value
266 fixHSB = function (hsb) {
267 return {
268 h: Math.min(360, Math.max(0, hsb.h)),
269 s: Math.min(100, Math.max(0, hsb.s)),
270 b: Math.min(100, Math.max(0, hsb.b))
271 };
272 },
273 fixRGB = function (rgb) {
274 return {
275 r: Math.min(255, Math.max(0, rgb.r)),
276 g: Math.min(255, Math.max(0, rgb.g)),
277 b: Math.min(255, Math.max(0, rgb.b))
278 };
279 },
280 fixHex = function (hex) {
281 var len = 6 - hex.length;
282 if (len > 0) {
283 var o = [];
284 for (var i=0; i<len; i++) {
285 o.push('0');
286 }
287 o.push(hex);
288 hex = o.join('');
289 }
290 return hex;
291 },
292 restoreOriginal = function () {
293 var cal = $(this).parent();
294 var col = cal.data('colpick').origColor;
295 cal.data('colpick').color = col;
296 fillRGBFields(col, cal.get(0));
297 fillHexFields(col, cal.get(0));
298 fillHSBFields(col, cal.get(0));
299 setSelector(col, cal.get(0));
300 setHue(col, cal.get(0));
301 setNewColor(col, cal.get(0));
302 };
303 return {
304 init: function (opt) {
305 opt = $.extend({}, defaults, opt||{});
306 //Set color
307 if (typeof opt.color == 'string') {
308 opt.color = hexToHsb(opt.color);
309 } else if (opt.color.r != undefined && opt.color.g != undefined && opt.color.b != undefined) {
310 opt.color = rgbToHsb(opt.color);
311 } else if (opt.color.h != undefined && opt.color.s != undefined && opt.color.b != undefined) {
312 opt.color = fixHSB(opt.color);
313 } else {
314 return this;
315 }
316
317 //For each selected DOM element
318 return this.each(function () {
319 //If the element does not have an ID
320 if (!$(this).data('colpickId')) {
321 var options = $.extend({}, opt);
322 options.origColor = opt.color;
323 //Generate and assign a random ID
324 var id = 'collorpicker_' + parseInt(Math.random() * 1000);
325 $(this).data('colpickId', id);
326 //Set the tpl's ID and get the HTML
327 var cal = $(tpl).attr('id', id);
328 //Add class according to layout
329 cal.addClass('colpick_'+options.layout+(options.submit?'':' colpick_'+options.layout+'_ns'));
330 //Add class if the color scheme is not default
331 if(options.colorScheme != 'light') {
332 cal.addClass('colpick_'+options.colorScheme);
333 }
334 //Setup submit button
335 cal.find('div.colpick_submit').html(options.submitText).click(clickSubmit);
336 //Setup input fields
337 options.fields = cal.find('input').change(change).blur(blur).focus(focus);
338 cal.find('div.colpick_field_arrs').mousedown(downIncrement).end().find('div.colpick_current_color').click(restoreOriginal);
339 //Setup hue selector
340 options.selector = cal.find('div.colpick_color').on('mousedown touchstart',downSelector);
341 options.selectorIndic = options.selector.find('div.colpick_selector_outer');
342 //Store parts of the plugin
343 options.el = this;
344 options.hue = cal.find('div.colpick_hue_arrs');
345 huebar = options.hue.parent();
346 //Paint the hue bar
347 var UA = navigator.userAgent.toLowerCase();
348 var isIE = navigator.appName === 'Microsoft Internet Explorer';
349 var IEver = isIE ? parseFloat( UA.match( /msie ([0-9]{1,}[\.0-9]{0,})/ )[1] ) : 0;
350 var ngIE = ( isIE && IEver < 10 );
351 var stops = ['#ff0000','#ff0080','#ff00ff','#8000ff','#0000ff','#0080ff','#00ffff','#00ff80','#00ff00','#80ff00','#ffff00','#ff8000','#ff0000'];
352 if(ngIE) {
353 var i, div;
354 for(i=0; i<=11; i++) {
355 div = $('<div></div>').attr('style','height:8.333333%; filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='+stops[i]+', endColorstr='+stops[i+1]+'); -ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='+stops[i]+', endColorstr='+stops[i+1]+')";');
356 huebar.append(div);
357 }
358 } else {
359 stopList = stops.join(',');
360 huebar.attr('style','background:-webkit-linear-gradient(top,'+stopList+'); background: -o-linear-gradient(top,'+stopList+'); background: -ms-linear-gradient(top,'+stopList+'); background:-moz-linear-gradient(top,'+stopList+'); -webkit-linear-gradient(top,'+stopList+'); background:linear-gradient(to bottom,'+stopList+'); ');
361 }
362 cal.find('div.colpick_hue').on('mousedown touchstart',downHue);
363 options.newColor = cal.find('div.colpick_new_color');
364 options.currentColor = cal.find('div.colpick_current_color');
365 //Store options and fill with default color
366 cal.data('colpick', options);
367 fillRGBFields(options.color, cal.get(0));
368 fillHSBFields(options.color, cal.get(0));
369 fillHexFields(options.color, cal.get(0));
370 setHue(options.color, cal.get(0));
371 setSelector(options.color, cal.get(0));
372 setCurrentColor(options.color, cal.get(0));
373 setNewColor(options.color, cal.get(0));
374 //Append to body if flat=false, else show in place
375 if (options.flat) {
376 cal.appendTo(this).show();
377 cal.css({
378 position: 'relative',
379 display: 'block'
380 });
381 } else {
382 cal.appendTo(document.body);
383 $(this).on(options.showEvent, show);
384 cal.css({
385 position:'absolute'
386 });
387 }
388 }
389 });
390 },
391 //Shows the picker
392 showPicker: function() {
393 return this.each( function () {
394 if ($(this).data('colpickId')) {
395 show.apply(this);
396 }
397 });
398 },
399 //Hides the picker
400 hidePicker: function() {
401 return this.each( function () {
402 if ($(this).data('colpickId')) {
403 $('#' + $(this).data('colpickId')).hide();
404 }
405 });
406 },
407 //Sets a color as new and current (default)
408 setColor: function(col, setCurrent) {
409 setCurrent = (typeof setCurrent === "undefined") ? 1 : setCurrent;
410 if (typeof col == 'string') {
411 col = hexToHsb(col);
412 } else if (col.r != undefined && col.g != undefined && col.b != undefined) {
413 col = rgbToHsb(col);
414 } else if (col.h != undefined && col.s != undefined && col.b != undefined) {
415 col = fixHSB(col);
416 } else {
417 return this;
418 }
419 return this.each(function(){
420 if ($(this).data('colpickId')) {
421 var cal = $('#' + $(this).data('colpickId'));
422 cal.data('colpick').color = col;
423 cal.data('colpick').origColor = col;
424 fillRGBFields(col, cal.get(0));
425 fillHSBFields(col, cal.get(0));
426 fillHexFields(col, cal.get(0));
427 setHue(col, cal.get(0));
428 setSelector(col, cal.get(0));
429
430 setNewColor(col, cal.get(0));
431 cal.data('colpick').onChange.apply(cal.parent(), [col, hsbToHex(col), hsbToRgb(col), cal.data('colpick').el, 1]);
432 if(setCurrent) {
433 setCurrentColor(col, cal.get(0));
434 }
435 }
436 });
437 }
438 };
439 }();
440 //Color space convertions
441 var hexToRgb = function (hex) {
442 var hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
443 return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
444 };
445 var hexToHsb = function (hex) {
446 return rgbToHsb(hexToRgb(hex));
447 };
448 var rgbToHsb = function (rgb) {
449 var hsb = {h: 0, s: 0, b: 0};
450 var min = Math.min(rgb.r, rgb.g, rgb.b);
451 var max = Math.max(rgb.r, rgb.g, rgb.b);
452 var delta = max - min;
453 hsb.b = max;
454 hsb.s = max != 0 ? 255 * delta / max : 0;
455 if (hsb.s != 0) {
456 if (rgb.r == max) hsb.h = (rgb.g - rgb.b) / delta;
457 else if (rgb.g == max) hsb.h = 2 + (rgb.b - rgb.r) / delta;
458 else hsb.h = 4 + (rgb.r - rgb.g) / delta;
459 } else hsb.h = -1;
460 hsb.h *= 60;
461 if (hsb.h < 0) hsb.h += 360;
462 hsb.s *= 100/255;
463 hsb.b *= 100/255;
464 return hsb;
465 };
466 var hsbToRgb = function (hsb) {
467 var rgb = {};
468 var h = hsb.h;
469 var s = hsb.s*255/100;
470 var v = hsb.b*255/100;
471 if(s == 0) {
472 rgb.r = rgb.g = rgb.b = v;
473 } else {
474 var t1 = v;
475 var t2 = (255-s)*v/255;
476 var t3 = (t1-t2)*(h%60)/60;
477 if(h==360) h = 0;
478 if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
479 else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
480 else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
481 else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
482 else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
483 else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
484 else {rgb.r=0; rgb.g=0; rgb.b=0}
485 }
486 return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)};
487 };
488 var rgbToHex = function (rgb) {
489 var hex = [
490 rgb.r.toString(16),
491 rgb.g.toString(16),
492 rgb.b.toString(16)
493 ];
494 $.each(hex, function (nr, val) {
495 if (val.length == 1) {
496 hex[nr] = '0' + val;
497 }
498 });
499 return hex.join('');
500 };
501 var hsbToHex = function (hsb) {
502 return rgbToHex(hsbToRgb(hsb));
503 };
504 $.fn.extend({
505 colpick: colpick.init,
506 colpickHide: colpick.hidePicker,
507 colpickShow: colpick.showPicker,
508 colpickSetColor: colpick.setColor
509 });
510 $.extend({
511 colpick:{
512 rgbToHex: rgbToHex,
513 rgbToHsb: rgbToHsb,
514 hsbToHex: hsbToHex,
515 hsbToRgb: hsbToRgb,
516 hexToHsb: hexToHsb,
517 hexToRgb: hexToRgb
518 }
519 });
520 })(jQuery);
521