jqueryui
4 years ago
select2
6 years ago
validation
2 years ago
wp-color-picker-alpha
5 years ago
autocomplete.js
6 years ago
autosave.js
7 years ago
button-group.js
3 years ago
clone.js
2 years ago
color.js
3 years ago
date.js
3 years ago
datetime.js
3 years ago
file-input.js
4 years ago
file-upload.js
4 years ago
file.js
3 years ago
image-advanced.js
4 years ago
image-select.js
6 years ago
image-upload.js
4 years ago
input-list.js
3 years ago
map-frontend.js
4 years ago
map.js
4 years ago
media.js
3 years ago
modal.js
2 years ago
notification.js
6 years ago
oembed.js
2 years ago
osm-frontend.js
5 years ago
osm.js
2 years ago
post.js
3 years ago
range.js
4 years ago
script.js
3 years ago
select-advanced.js
3 years ago
select-tree.js
5 years ago
select.js
3 years ago
slider.js
6 years ago
taxonomy.js
3 years ago
time.js
6 years ago
user.js
3 years ago
validation.min.js
2 years ago
video.js
6 years ago
wysiwyg.js
2 years ago
color.js
56 lines
| 1 | ( function( $, rwmb ) { |
| 2 | 'use strict'; |
| 3 | |
| 4 | /** |
| 5 | * Transform an input into a color picker. |
| 6 | */ |
| 7 | function transform() { |
| 8 | const $this = $( this ); |
| 9 | const mode = $this.data( 'options' )[ 'mode' ]; |
| 10 | const alpha = $this.data( 'alpha-enabled' ); |
| 11 | |
| 12 | function initChange() { |
| 13 | if ( null !== mode && 'hex' !== mode && !alpha ) { |
| 14 | const color = new Color( $this.iris( 'option', 'color' ) ); |
| 15 | $this.val( color.toCSS( mode ) ); |
| 16 | } |
| 17 | triggerChange(); |
| 18 | } |
| 19 | |
| 20 | function triggerChange() { |
| 21 | $this.trigger( 'color:change' ).trigger( 'mb_change' ); |
| 22 | } |
| 23 | |
| 24 | const $container = $this.closest( '.wp-picker-container' ), |
| 25 | // Hack: the picker needs a small delay (learn from the Kirki plugin). |
| 26 | options = $.extend( |
| 27 | { |
| 28 | change: function() { |
| 29 | setTimeout( initChange, 20 ); |
| 30 | }, |
| 31 | clear: function() { |
| 32 | setTimeout( triggerChange, 20 ); |
| 33 | } |
| 34 | }, |
| 35 | $this.data( 'options' ) |
| 36 | ); |
| 37 | |
| 38 | // Clone doesn't have input for color picker, we have to add the input and remove the color picker container |
| 39 | if ( $container.length > 0 ) { |
| 40 | $this.insertBefore( $container ); |
| 41 | $container.remove(); |
| 42 | } |
| 43 | |
| 44 | // Show color picker. |
| 45 | $this.wpColorPicker( options ); |
| 46 | } |
| 47 | |
| 48 | function init( e ) { |
| 49 | $( e.target ).find( '.rwmb-color' ).each( transform ); |
| 50 | } |
| 51 | |
| 52 | rwmb.$document |
| 53 | .on( 'mb_ready', init ) |
| 54 | .on( 'clone', '.rwmb-color', transform ); |
| 55 | } )( jQuery, rwmb ); |
| 56 |