( function( $ ) { $(document).ready( function() { /* *** *** Create radio *** *** */ if( $( this ).find( 'input[type="radio"]' ) ) { var fakeContainer = $( '' ); var fakeRadio = $( '' ); var contRadioItem = $( '
' ); $( this ).each( function( k, bloggerRadio ) { $( bloggerRadio ).find( '.radio' ).removeClass( 'radio' ).addClass( 'blogger-radio-custom' ); $( bloggerRadio ).find( 'input[type="radio"]' ).wrap( fakeContainer ); var label = $( bloggerRadio ).find( '.blogger-fake-radio-container' ).next().detach(); /* remove all labels and save in variable */ $( bloggerRadio ).find( '.blogger-fake-radio-container' ).wrap( contRadioItem ); $( bloggerRadio ).find( '.blogger-radio-item-container' ).each( function() { /* separate label for each radio */ var radioContainer = this; $( label ).each(function() { if ( $( this ).attr( 'for' ) == $( radioContainer ).find( 'input' ).attr( 'id' ) ) { $( radioContainer ).append( $( this ) ); } }); }); $( bloggerRadio ).find( '.blogger-fake-radio-container' ).append( fakeRadio ); /* if radio was selected */ $( bloggerRadio ).find( 'input[type=radio]:checked' ).next().addClass( 'selected' ); /* if radio is disabled */ $( bloggerRadio ).find( 'input[type=radio]' ).each( function() { if( $( this ).attr( 'disabled' ) ) { $( this ).next().addClass( 'disabled' ); } }); /* events handlers */ $( bloggerRadio ).find( 'input[type="radio"]' ).on( 'click', function(){ $( bloggerRadio ).find( 'input[name="' + $( this ).attr( 'name' ) + '"]' ).next().removeClass( 'selected' ); $( this ).parent().find( '.blogger-fake-radio' ).addClass( 'selected' ); }); $( bloggerRadio ).find( '.blogger-fake-radio' ).on( 'click', function(){ if( ! $( this ).prev().attr( 'disabled' ) ) { $( this ).prev().trigger( 'click' ); } }); }); } /* *** *** Create checkboxes *** *** */ if( $( this ).find( 'input[type="checkbox"]' ) ) { var fakeContainerCheck = $( '' ); var fakeCheckbox = $( '' ); var contCheckboxItem = $( '' ); $( this ).each(function( k, bloggerCheckbox ) { $( bloggerCheckbox ).find( '.checkbox' ).removeClass( 'checkbox' ).addClass( 'blogger-checkbox-custom' ); $( bloggerCheckbox ).find( 'input[type="checkbox"]' ).wrap( fakeContainerCheck ); $( bloggerCheckbox ).find( '.blogger-fake-checkbox-container' ).wrap( contCheckboxItem ); $( bloggerCheckbox ).find( '.blogger-checkbox-item-container' ).each( function() { /* separate label for each checkbox */ var checkboxContainer = this; $( checkboxContainer ).next().each(function() { if( $( this ).attr( 'for' ) == $( checkboxContainer ).find( 'input' ).attr( 'id' ) ) { $( checkboxContainer ).append( $( this ) ); } }); }); $( bloggerCheckbox ).find( '.blogger-fake-checkbox-container' ).append( fakeCheckbox ); /* if checkbox was selected */ $( bloggerCheckbox ).find( 'input[type=checkbox]:checked' ).next().addClass( 'selected' ); /* if checkbox is disabled */ $( bloggerCheckbox ).find( 'input[type=checkbox]' ).each( function() { if( $( this ).attr( 'disabled' ) ) { $( this ).next().addClass( 'disabled' ); } }); /* events handlers */ $( bloggerCheckbox ).find( 'input[type="checkbox"]' ).on( 'click', function(){ var fCh = $( this ).parent().find( '.blogger-fake-checkbox' ); if( fCh.hasClass( 'selected' ) ) { fCh.removeClass( 'selected' ); } else { fCh.addClass( 'selected' ); } }); $( bloggerCheckbox ).find( '.blogger-fake-checkbox' ).on( 'click', function(){ if( ! $( this ).prev().attr( 'disabled' ) ) { $( this ).prev().trigger( 'click' ); } }); }); } /* *** *** Create clear button *** *** */ $( this ).find( 'input[type="reset"]' ).click( function() { var bloggerForms = $( this ).parents( 'form' ).first(); bloggerForms.find( '.blogger-select-block' ).find( '.blogger-option.index-0' ).click(); bloggerForms.find( '.blogger-fake-radio, .blogger-fake-checkbox' ).removeClass( 'selected' ); $( bloggerForms )[0].reset(); bloggerForms.find( 'input[type="file"]' ).change(); e.preventDefault; }); }); } )( jQuery );