Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Interface Builder
- */
- ;( function( $, underscore ) {
- 'use strict';
- var cxInterfaceBuilder = {
- component: {
- showClass: 'show',
- localStorage: {},
- controlConditions: window.cxInterfaceBuilder.conditions || {},
- controlValues: window.cxInterfaceBuilder.fields || {},
- conditionState: {},
- init: function() {
- this.conditionsHandleInit();
- },
- addEvent: function() {
- $( 'body' )
- .off( 'click.cxInterfaceBuilder' )
- .on( 'click.cxInterfaceBuilder',
- this.tabClass + ' ' + this.buttonClass + ', ' +
- this.toggleClass + ' ' + this.buttonClass + ', ' +
- this.accordionClass + ' ' + this.buttonClass,
- this.componentClick.bind( this )
- );
- },
- conditionsHandleInit: function() {
- var self = this;
- $( window ).on( 'cx-switcher-change', function( event ) {
- var controlName = event.controlName,
- controlStatus = event.controlStatus;
- self.updateConditionRules( controlName, controlStatus );
- self.renderConditionRules();
- } );
- $( window ).on( 'cx-select2-change', function( event ) {
- var controlName = event.controlName,
- controlStatus = event.controlStatus;
- self.updateConditionRules( controlName, controlStatus );
- self.renderConditionRules();
- } );
- $( window ).on( 'cx-radio-change', function( event ) {
- var controlName = event.controlName,
- controlStatus = event.controlStatus;
- self.updateConditionRules( controlName, controlStatus );
- self.renderConditionRules();
- } );
- $( window ).on( 'cx-checkbox-change', function( event ) {
- var controlName = event.controlName,
- controlStatus = event.controlStatus,
- updatedStatus = {};
- $.each( controlStatus[ controlName ], function( checkbox, value ) {
- updatedStatus[ checkbox ] = cxInterfaceBuilder.utils.filterBoolValue( value );
- } );
- self.updateConditionRules( controlName, updatedStatus );
- self.renderConditionRules();
- } );
- this.generateConditionRules();
- self.renderConditionRules();
- },
- generateConditionRules: function() {
- var self = this;
- $.each( this.controlConditions, function( control, conditions ) {
- $.each( conditions, function( control, value ) {
- if( self.controlValues.hasOwnProperty( control ) ) {
- self.conditionState[ control ] = self.controlValues[ control ];
- }
- } );
- } );
- },
- updateConditionRules: function( name, status ) {
- this.conditionState[ name ] = status;
- },
- renderConditionRules: function() {
- var self = this;
- $.each( this.controlConditions, function( control, conditions ) {
- var $selector = $( '.cx-control[data-control-name="' + control + '"]' ),
- hidden = true;
- $selector.addClass( 'cx-control-hidden' );
- $.each( conditions, function( control, value ) {
- hidden = true;
- if( self.conditionState.hasOwnProperty( control ) ) {
- if( self.conditionState[ control ] === value ) {
- hidden = false;
- }
- if( 'object' === typeof self.conditionState[ control ] ) {
- hidden = false;
- $.each( value, function( prop, val ) {
- if( val !== self.conditionState[ control ][ prop ] ) {
- hidden = true;
- return false;
- }
- } );
- }
- }
- if( hidden ) {
- return false;
- }
- } );
- if( hidden ) {
- $selector.addClass( 'cx-control-hidden' );
- } else {
- $selector.removeClass( 'cx-control-hidden' );
- }
- } );
- },
- },
- };
- cxInterfaceBuilder.init();
- }( jQuery, window._ ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement