|
204 | 204 | '</div>' + |
205 | 205 | '</div>' |
206 | 206 | ); |
207 | | - |
| 207 | + |
208 | 208 | // The swatch |
209 | 209 | if( !settings.inline ) { |
210 | 210 | input.after('<span class="minicolors-swatch minicolors-sprite minicolors-input-swatch"><span class="minicolors-swatch-color"></span></span>'); |
|
217 | 217 | // Prevent text selection in IE |
218 | 218 | panel = input.parent().find('.minicolors-panel'); |
219 | 219 | panel.on('selectstart', function() { return false; }).end(); |
220 | | - |
| 220 | + |
221 | 221 | // Swatches |
222 | 222 | if (settings.swatches && settings.swatches.length !== 0) { |
223 | 223 | if (settings.swatches.length > 7) { |
|
239 | 239 | }); |
240 | 240 | settings.swatches[i] = swatch; |
241 | 241 | } |
242 | | - |
| 242 | + |
243 | 243 | } |
244 | 244 |
|
245 | 245 | // Inline controls |
|
495 | 495 | break; |
496 | 496 |
|
497 | 497 | } |
498 | | - |
| 498 | + |
499 | 499 | // Handle opacity |
500 | 500 | if( settings.opacity ) { |
501 | 501 | opacity = parseFloat(1 - (opacityPos.y / opacitySlider.height())).toFixed(2); |
502 | 502 | } else { |
503 | 503 | opacity = 1; |
504 | 504 | } |
505 | | - |
| 505 | + |
506 | 506 | updateInput(input, hex, opacity); |
507 | 507 | } |
508 | 508 | else { |
|
516 | 516 | doChange(input, hex, opacity); |
517 | 517 | } |
518 | 518 | } |
519 | | - |
| 519 | + |
520 | 520 | // Sets the value of the input and does the appropriate conversions |
521 | 521 | // to respect settings, also updates the swatch |
522 | 522 | function updateInput(input, value, opacity) { |
523 | 523 | var rgb, |
524 | | - |
| 524 | + |
525 | 525 | // Helpful references |
526 | 526 | minicolors = input.parent(), |
527 | 527 | settings = input.data('minicolors-settings'), |
528 | 528 | swatch = minicolors.find('.minicolors-input-swatch'); |
529 | | - |
| 529 | + |
530 | 530 | if( settings.opacity ) input.attr('data-opacity', opacity); |
531 | | - |
| 531 | + |
532 | 532 | // Set color string |
533 | 533 | if( settings.format === 'rgb' ) { |
534 | 534 | // Returns RGB(A) string |
535 | | - |
| 535 | + |
536 | 536 | // Checks for input format and does the conversion |
537 | 537 | if ( isRgb(value) ) { |
538 | 538 | rgb = parseRgb(value, true); |
539 | 539 | } |
540 | 540 | else { |
541 | 541 | rgb = hex2rgb(parseHex(value, true)); |
542 | 542 | } |
543 | | - |
| 543 | + |
544 | 544 | opacity = input.attr('data-opacity') === '' ? 1 : keepWithin( parseFloat( input.attr('data-opacity') ).toFixed(2), 0, 1 ); |
545 | 545 | if( isNaN( opacity ) || !settings.opacity ) opacity = 1; |
546 | 546 |
|
|
553 | 553 | } |
554 | 554 | } else { |
555 | 555 | // Returns hex color |
556 | | - |
| 556 | + |
557 | 557 | // Checks for input format and does the conversion |
558 | 558 | if ( isRgb(value) ) { |
559 | 559 | value = rgbString2hex(value); |
560 | 560 | } |
561 | | - |
| 561 | + |
562 | 562 | value = convertCase( value, settings.letterCase ); |
563 | 563 | } |
564 | 564 |
|
565 | 565 | // Update value from picker |
566 | 566 | input.val( value ); |
567 | | - |
| 567 | + |
568 | 568 | // Set swatch color |
569 | 569 | swatch.find('span').css({ |
570 | 570 | backgroundColor: value, |
|
750 | 750 |
|
751 | 751 | // Only run if it actually changed |
752 | 752 | if( !lastChange || lastChange.value !== value || lastChange.opacity !== opacity ) { |
753 | | - |
| 753 | + |
754 | 754 | // Remember last-changed value |
755 | 755 | input.data('minicolors-lastChange', { |
756 | 756 | value: value, |
|
772 | 772 | break; |
773 | 773 | } |
774 | 774 | } |
775 | | - |
| 775 | + |
776 | 776 | input.parent().find('.minicolors-swatches .minicolors-swatch').removeClass('selected'); |
777 | 777 | if (i !== -1) { |
778 | 778 | input.parent().find('.minicolors-swatches .minicolors-swatch').eq(i).addClass('selected'); |
|
0 commit comments