| 1 |
/*global redux*/ |
| 2 |
|
| 3 |
(function( $ ) { |
| 4 |
"use strict"; |
| 5 |
|
| 6 |
redux.field_objects = redux.field_objects || {}; |
| 7 |
redux.field_objects.spacing = redux.field_objects.spacing || {}; |
| 8 |
|
| 9 |
$( document ).ready( |
| 10 |
function() { |
| 11 |
//redux.field_objects.spacing.init(); |
| 12 |
} |
| 13 |
); |
| 14 |
|
| 15 |
redux.field_objects.spacing.init = function( selector ) { |
| 16 |
|
| 17 |
if ( !selector ) { |
| 18 |
selector = $( document ).find( ".redux-group-tab:visible" ).find( '.redux-container-spacing:visible' ); |
| 19 |
} |
| 20 |
|
| 21 |
$( selector ).each( |
| 22 |
function() { |
| 23 |
var el = $( this ); |
| 24 |
var parent = el; |
| 25 |
if ( !el.hasClass( 'redux-field-container' ) ) { |
| 26 |
parent = el.parents( '.redux-field-container:first' ); |
| 27 |
} |
| 28 |
if ( parent.is( ":hidden" ) ) { // Skip hidden fields |
| 29 |
return; |
| 30 |
} |
| 31 |
if ( parent.hasClass( 'redux-field-init' ) ) { |
| 32 |
parent.removeClass( 'redux-field-init' ); |
| 33 |
} else { |
| 34 |
return; |
| 35 |
} |
| 36 |
var default_params = { |
| 37 |
width: 'resolve', |
| 38 |
triggerChange: true, |
| 39 |
allowClear: true |
| 40 |
}; |
| 41 |
|
| 42 |
var select2_handle = el.find( '.select2_params' ); |
| 43 |
if ( select2_handle.size() > 0 ) { |
| 44 |
var select2_params = select2_handle.val(); |
| 45 |
|
| 46 |
select2_params = JSON.parse( select2_params ); |
| 47 |
default_params = $.extend( {}, default_params, select2_params ); |
| 48 |
} |
| 49 |
|
| 50 |
el.find( ".redux-spacing-units" ).select2( default_params ); |
| 51 |
|
| 52 |
el.find( '.redux-spacing-input' ).on( |
| 53 |
'change', function() { |
| 54 |
var units = $( this ).parents( '.redux-field:first' ).find( '.field-units' ).val(); |
| 55 |
|
| 56 |
if ( $( this ).parents( '.redux-field:first' ).find( '.redux-spacing-units' ).length !== 0 ) { |
| 57 |
units = $( this ).parents( '.redux-field:first' ).find( '.redux-spacing-units option:selected' ).val(); |
| 58 |
} |
| 59 |
|
| 60 |
var value = $( this ).val(); |
| 61 |
|
| 62 |
if ( typeof units !== 'undefined' && value ) { |
| 63 |
value += units; |
| 64 |
} |
| 65 |
|
| 66 |
if ( $( this ).hasClass( 'redux-spacing-all' ) ) { |
| 67 |
$( this ).parents( '.redux-field:first' ).find( '.redux-spacing-value' ).each( |
| 68 |
function() { |
| 69 |
$( this ).val( value ); |
| 70 |
} |
| 71 |
); |
| 72 |
} else { |
| 73 |
$( '#' + $( this ).attr( 'rel' ) ).val( value ); |
| 74 |
} |
| 75 |
} |
| 76 |
); |
| 77 |
|
| 78 |
el.find( '.redux-spacing-units' ).on( |
| 79 |
'change', function() { |
| 80 |
$( this ).parents( '.redux-field:first' ).find( '.redux-spacing-input' ).change(); |
| 81 |
} |
| 82 |
); |
| 83 |
} |
| 84 |
); |
| 85 |
}; |
| 86 |
})( jQuery ); |