"Calendar Re-occurence"
Bootstrap 3.3.0 Snippet by theklf99

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <!-- Description start --> <div class="row"> <div class="col-xs-12 padding10 text-center"> <p></p>I created this bootstrap snippet as part of a calendar system I'm planning for Joomla K2.</p> <p>The idea of this form is to ask the user if the event re-occurs, how often it re-occurs and the type of the re-occurence daily, weekly, monthly, yearly.</p> <p>There are limits on the amount of gap between each type which change accordingly</p> <ul class="list-unstyled"><li>31 days (max days in month)</li> <li>52 weeks (weeks in year)</li> <li>12 months (months in year)</li> <li>and 20 years (time between Preston Guilds!)</li> </ul> <p>These can be altered to your own limits on javascript lines 60-71 as well as the text that goes after the "Every xx days/weeks/etc"</p> <p>once the user edits the data it turns the data into a DateInterval code which it stores in hidden field recur_code</p> <p>it also stores the mode in recur_mode - 0 = "no re-occurence", 1 = "re-occurence with end date", 2 = "re-occur forever"</p> <p>The various options are automatically shown/hidden depending on user choices</p> </div> </div> <!-- Description end --> <form> <input id="recur_mode" type="hidden" /> <input id="recur_code" type="hidden" /> <div id="reoccur" class="form-group row radioBtn"> <label class="col-md-4">Does this event re-occur?</label> <div class="col-md-8"> <a class="btn btn-primary btn-sm active" data-active="yes" data-value="yes" data-info="recur reoccur indef recur_mode" >YES</a> <a class="btn btn-primary btn-sm notActive" data-active="no" data-value="no" data-info="recur reoccur indef recur_mode" >NO</a> </div> </div> <fieldset id="reoccur_option"> <legend>Re-occuring options</legend> <div id="indef" class="form-group row radioBtn"> <label class="col-md-4">Does this event re-occur indefinitely?</label> <div class="col-md-8"> <a class="yes btn btn-primary btn-sm active" data-active="yes" data-value="yes" data-info="recur reoccur indef recur_mode" >YES</a> <a class="no btn btn-primary btn-sm notActive" data-active="no" data-value="no" data-info="recur reoccur indef recur_mode" >NO</a> </div> </div> <div id="recur_end" class="form-group row"> <label class="col-md-4">Re-occur until</label> <div class="col-md-8"> <input type="date" id="recur_date" /> </div> </div> <div id="period_type" class="form-group row"> <label class="col-md-4">Repeat</label> <div class="col-md-8"> <a class="btn btn-primary btn-sm active" data-active="yes" data-value="D">Daily</a> <a class="btn btn-primary btn-sm notActive" data-active="no" data-value="W">Weekly</a> <a class="btn btn-primary btn-sm notActive" data-active="no" data-value="M">Monthly</a> <a class="btn btn-primary btn-sm notActive" data-active="no" data-value="Y">Yearly</a> <input type="hidden" id="period_type_val" value="D" /> </div> </div> <div id="period_skip" class="form-group row"> <label class="col-md-4">Every</label> <div class="col-md-8"> <input type="number" min="1" max="31" value="1" /> <span class="period_text">days</span> </div> </div> </fieldset> </form> </div>
.padding10 { padding : 10px ; } .notActive { background : #fff ; color : #3071a9 ; }
function buildCode () { var skip = parseInt ( jQuery ( '#period_skip input' ).val () ) ; var period_code = jQuery ( '#period_type_val' ).val () ; if ( period_code == 'W' ) { period_code = 'D' ; skip *= 7 ; } jQuery ( '#recur_code' ).val ( 'P'+skip+period_code ) ; } function decodeCode () { var code = jQuery ( '#recur_code' ).val () ; if ( code ) { var interval = code.match (/\d+/) ; var period = code.match (/[A-OQ-Z]+/) ; if ( ( period = 'D' ) && ( interval % 7 === 0 ) ) { period = 'W' ; interval /= 7 ; } jQuery ( '#period_skip input' ).val ( interval ) ; jQuery ( '#period_type a').each ( function ( index, item ) { if ( jQuery(item).data ( 'value' ) == period ) jQuery(item).trigger ( 'click' ) ; } ) ; jQuery ( '#period_type_val' ).val ( period ) ; } } jQuery( document ).ready ( function() { jQuery('#period_skip input').blur ( function () { var max_val = parseInt ( jQuery (this).attr('max') ) ; if ( parseInt ( jQuery(this).val () ) > max_val ) jQuery (this).val ( max_val ) ; buildCode () ; } ); jQuery('#period_type a').on('click', function () { jQuery(this).data('active', 'yes' ).removeClass('notActive').addClass('active'); jQuery(this).siblings().data ('active', 'no' ).removeClass('active').addClass('notActive'); var max_val = 0 ; jQuery ( '#period_type_val' ).val ( jQuery(this).data('value') ) ; switch ( jQuery(this).data('value') ) { case 'D' : max_val = 31 ; jQuery ( '.period_text' ).text ( ' days' ) ; break ; case 'W' : max_val = 52 ; jQuery ( '.period_text' ).text ( ' weeks' ) ; break ; case 'M' : max_val = 12 ; jQuery ( '.period_text' ).text ( ' months' ) ; break ; case 'Y' : max_val = 20 ; jQuery ( '.period_text' ).text ( ' years' ) ; break ; } jQuery('#period_skip input').attr ( 'max', max_val ) ; if ( parseInt ( jQuery('#period_skip input').val () ) > max_val ) jQuery ( '#period_skip input' ).val ( max_val ) ; buildCode () ; }); jQuery('.radioBtn a').on ('click', function() { var info = jQuery(this).data('info').split ( " " ) ; switch ( info[0] ) { case 'recur' : jQuery(this).data('active', 'yes' ).removeClass('notActive').addClass('active'); jQuery(this).siblings().data ('active', 'no' ).removeClass('active').addClass('notActive'); var recur ; jQuery('#'+info[1]+' a').each ( function ( index, item ) { if ( jQuery(item).data('active') == 'yes' ) { recur = ( ( jQuery(item).data ('value') == 'yes' ? 1 : 0 ) ) ; return false ; } } ) ; if ( recur == 1 ) { jQuery('#reoccur_option' ).removeClass ( 'hidden' ) ; jQuery('#'+info[2]+' a').each ( function ( index, item ) { if ( jQuery(item).data('active') == 'yes' ) { recur = ( ( jQuery(item).data ('value') == 'yes' ? 2 : 1 ) ) ; return false ; } } ) ; } else jQuery('#reoccur_option').addClass ( 'hidden' ) ; if ( recur == 1 ) jQuery('#recur_end').removeClass ( 'hidden' ) ; else jQuery('#recur_end').addClass ( 'hidden' ) ; jQuery('#'+info[3]).val ( recur ) ; buildCode () ; } }) ; decodeCode () ; jQuery('#reoccur a').trigger ( 'click' ) ; } );

Related: See More


Questions / Comments: