| 1 |
/*global redux_change, redux*/ |
| 2 |
|
| 3 |
/** |
| 4 |
* Switch |
| 5 |
* Dependencies : jquery |
| 6 |
* Feature added by : Smartik - http://smartik.ws/ |
| 7 |
* Date : 03.17.2013 |
| 8 |
*/ |
| 9 |
|
| 10 |
(function( $ ) { |
| 11 |
"use strict"; |
| 12 |
|
| 13 |
redux.field_objects = redux.field_objects || {}; |
| 14 |
redux.field_objects.switch = redux.field_objects.switch || {}; |
| 15 |
|
| 16 |
$( document ).ready( |
| 17 |
function() { |
| 18 |
//redux.field_objects.switch.init(); |
| 19 |
} |
| 20 |
); |
| 21 |
|
| 22 |
redux.field_objects.switch.init = function( selector ) { |
| 23 |
|
| 24 |
if ( !selector ) { |
| 25 |
selector = $( document ).find( ".redux-group-tab:visible" ).find( '.redux-container-switch:visible' ); |
| 26 |
} |
| 27 |
|
| 28 |
$( selector ).each( |
| 29 |
function() { |
| 30 |
var el = $( this ); |
| 31 |
var parent = el; |
| 32 |
if ( !el.hasClass( 'redux-field-container' ) ) { |
| 33 |
parent = el.parents( '.redux-field-container:first' ); |
| 34 |
} |
| 35 |
if ( parent.is( ":hidden" ) ) { // Skip hidden fields |
| 36 |
return; |
| 37 |
} |
| 38 |
if ( parent.hasClass( 'redux-field-init' ) ) { |
| 39 |
parent.removeClass( 'redux-field-init' ); |
| 40 |
} else { |
| 41 |
return; |
| 42 |
} |
| 43 |
el.find( ".cb-enable" ).click( |
| 44 |
function() { |
| 45 |
if ( $( this ).hasClass( 'selected' ) ) { |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
var parent = $( this ).parents( '.switch-options' ); |
| 50 |
|
| 51 |
$( '.cb-disable', parent ).removeClass( 'selected' ); |
| 52 |
$( this ).addClass( 'selected' ); |
| 53 |
$( '.checkbox-input', parent ).val( 1 ).trigger('change'); |
| 54 |
|
| 55 |
redux_change( $( '.checkbox-input', parent ) ); |
| 56 |
|
| 57 |
//fold/unfold related options |
| 58 |
var obj = $( this ); |
| 59 |
var $fold = '.f_' + obj.data( 'id' ); |
| 60 |
|
| 61 |
el.find( $fold ).slideDown( 'normal', "swing" ); |
| 62 |
} |
| 63 |
); |
| 64 |
|
| 65 |
el.find( ".cb-disable" ).click( |
| 66 |
function() { |
| 67 |
if ( $( this ).hasClass( 'selected' ) ) { |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
var parent = $( this ).parents( '.switch-options' ); |
| 72 |
|
| 73 |
$( '.cb-enable', parent ).removeClass( 'selected' ); |
| 74 |
$( this ).addClass( 'selected' ); |
| 75 |
$( '.checkbox-input', parent ).val( 0 ).trigger('change'); |
| 76 |
|
| 77 |
redux_change( $( '.checkbox-input', parent ) ); |
| 78 |
|
| 79 |
//fold/unfold related options |
| 80 |
var obj = $( this ); |
| 81 |
var $fold = '.f_' + obj.data( 'id' ); |
| 82 |
|
| 83 |
el.find( $fold ).slideUp( 'normal', "swing" ); |
| 84 |
} |
| 85 |
); |
| 86 |
|
| 87 |
el.find( '.cb-enable span, .cb-disable span' ).find().attr( 'unselectable', 'on' ); |
| 88 |
} |
| 89 |
); |
| 90 |
}; |
| 91 |
})( jQuery ); |