balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

redux-spacing.js (1835B)


      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 	redux.field_objects.spacing.init = function( selector ) {
     10 		selector = $.redux.getSelector( selector, 'spacing' );
     11 
     12 		$( selector ).each(
     13 			function() {
     14 				var el     = $( this );
     15 				var parent = el;
     16 
     17 				if ( ! el.hasClass( 'redux-field-container' ) ) {
     18 					parent = el.parents( '.redux-field-container:first' );
     19 				}
     20 
     21 				if ( parent.is( ':hidden' ) ) {
     22 					return;
     23 				}
     24 
     25 				if ( parent.hasClass( 'redux-field-init' ) ) {
     26 					parent.removeClass( 'redux-field-init' );
     27 				} else {
     28 					return;
     29 				}
     30 
     31 				el.find( '.redux-spacing-units' ).select2();
     32 
     33 				el.find( '.redux-spacing-input' ).on(
     34 					'change',
     35 					function() {
     36 						var value;
     37 
     38 						var units = $( this ).parents( '.redux-field:first' ).find( '.field-units' ).val();
     39 
     40 						if ( 0 !== $( this ).parents( '.redux-field:first' ).find( '.redux-spacing-units' ).length ) {
     41 							units = $( this ).parents( '.redux-field:first' ).find( '.redux-spacing-units option:selected' ).val();
     42 						}
     43 
     44 						value = $( this ).val();
     45 
     46 						if ( 'undefined' !== typeof units && value ) {
     47 							value += units;
     48 						}
     49 
     50 						if ( $( this ).hasClass( 'redux-spacing-all' ) ) {
     51 							$( this ).parents( '.redux-field:first' ).find( '.redux-spacing-value' ).each(
     52 								function() {
     53 									$( this ).val( value );
     54 								}
     55 							);
     56 						} else {
     57 							$( '#' + $( this ).attr( 'rel' ) ).val( value );
     58 						}
     59 					}
     60 				);
     61 
     62 				el.find( '.redux-spacing-units' ).on(
     63 					'change',
     64 					function() {
     65 						$( this ).parents( '.redux-field:first' ).find( '.redux-spacing-input' ).change();
     66 
     67 						el.find( '.field-units' ).val( $( this ).val() );
     68 					}
     69 				);
     70 			}
     71 		);
     72 	};
     73 })( jQuery );