Your Guide to Everything Brooklyn!
"); var items = new Array; var count = 1; $(this).find('option').each(function() { var text = $(this).text(); var selected = ($(this).is(':selected')) ? true : false; var d_class = (count % 7 == 1) ? " newline" : ''; var s_class = (selected == true) ? " selected" : ''; items.push($("
"+text+"
").data('value', $(this).val()).data('selector', selected)); count ++; }); if (items.length > 0) { items.push("
"); } $.each(items, function(k, item) { $div.append(item); }); $(this).replaceWith($div); }); }; var reset_selector_widget = function($selector) { $selector.removeData('selector').find('.item').each(function() { $(this).removeData('selector').find('a').removeClass('selected'); }) }; var toggle_interval_details = function($select) { $select.each(function() { var $this = $(this), $date_range = $this.closest('.inner').find('.date_range'), $rule = $this.closest('.rule'), output = { options:'', extra:'' }; $this. closest('.repeat_select'). siblings('.options').remove(). end(). closest('.repeat'). siblings('.end').remove(). end(). find('br.clear').remove(). end(). find('.picker_three').remove(); if (_get_rule_type($rule) == '-' ) { $date_range.removeClass('inactive'). find('.time').hide().end(). find('.all_day').hide(). find('checkbox').attr('checked', 'checked'); } switch($this.val()) { case 'daily' : output = _html_repeat_interval_daily(); restore_date_fields($this); break; case 'weekly' : output = _html_repeat_interval_weekly(); restore_date_fields($this); break; case 'monthly' : output = _html_repeat_interval_monthly(); restore_date_fields($this); break; case 'yearly' : output = _html_repeat_interval_yearly(); restore_date_fields($this); break; case 'select_dates' : output = _html_repeat_interval_dates(); // Discard From and To date fields if (_get_rule_type($rule) == '-' ) { $date_range.addClass('inactive'); } $this. closest('.rule:not(.first)'). find('.date_range .date input'). datepicker('destroy').remove(). end(). find('.date_range .time label').remove(); break; default : restore_date_fields($this); if (_get_rule_type($rule) == '-' ) { $date_range.addClass('inactive'); } if (_get_rule_type($rule) == '+' && _get_rule_all_day($rule) == '') { toggle_time_fields($this); } break; }; $this.closest('.repeat_select').after(output.options).closest('.repeat').after(output.extra); initialize_interval_details($this.closest('.rule')); }); }; // ------------------------------------- // html templates // these should really be in another format // ------------------------------------- var _html_repeat_interval_daily = function() { var output = { options: '
day(s).

', extra: '
' + '

' }; return output; }; var _html_repeat_interval_weekly = function() { var output = { options: '
'+SSCalendar.lang.week_s_on+':


', extra: '

' }; return output; }; var _html_repeat_interval_monthly = function() { var output = { options: '

'+SSCalendar.lang.only_on+':



', extra: '

' }; return output; }; var _html_repeat_interval_yearly = function() { var output = { options: '
'+SSCalendar.lang.year_s+'.

', extra: '

' }; return output; }; var _html_repeat_interval_dates = function() { var output = { options: '
', extra: '' }; return output; }; var _html_end_by_date = function() { var output = '
'; return output; }; var _html_end_after = function() { var output = '
'+SSCalendar.lang.time_s+'
'; return output; }; var _html_new_rule = function() { var time = new Date(); var myTime = time.getTime(); var output = '
' + '
' + '
' + '' + '
' + '
' + '' + '
' + '
' + '
' + '' + '' + '
' + '
' + '
' + '
' + '
' + ' ' + '' + '
' + '
' + '
' + '' + '' + '
' + '
' + '' + '' + '' + '
' + '
' + '
' + '
' + '
' + '' + '' + '
' + '
' + '' + '' + '' + '
' + '
' + '
' + '
' + '
' + '
' + '' + '' + '
' + '
' + '
' + '
' + '
' + '
' + '
'; return output; }; // ------------------------------------- // restore date fields // ------------------------------------- var restore_date_fields = function($context) { var $range = $context.closest('.rule').find('.date_range'); if ($range.find('.date input, .time label').length == 0) { $range.find('.from .date label'). after(''); $range.find('.to .date label'). after(''); $range.find('.time').prepend(''); // Add date picker to From field var $rule = $context.closest('.rule'); $('input[name=start_date]', $rule).datepicker({ dateFormat : SSCalendar.dateFormat, firstDay : SSCalendar.firstDay, changeMonth : true, changeYear : true, onSelect : function() { update_to_field_mindate($rule, true); update_picker_three_mindate($rule); update_end_by_mindate($rule); } }); // Add date picker to To field $('input[name=end_date]', $rule).datepicker({ dateFormat : SSCalendar.dateFormat, firstDay : SSCalendar.firstDay, changeMonth : true, changeYear : true }); update_from_field_mindate($rule); update_to_field_mindate($rule, true); //removed this because it was setting it to the current date eventhough its restoring //update_end_by_mindate($rule); } $range.find('.date.inactive').removeClass('inactive'); //this adds back in a spacer that css depends on being there //(yes, that is bad, but look around this file.) if ($context.val() == 'none') { $context.parent().parent(). append('

'); } }; // ------------------------------------- // initialize_interval_details // ------------------------------------- var initialize_interval_details = function($rule) { create_selector_widget($('select.selector', $rule)); toggle_monthly_by($rule); toggle_end_by($rule); create_select_dates_picker($rule); }; // ------------------------------------- // toggle_monthly_by // ------------------------------------- var toggle_monthly_by = function($context) { if ($context == undefined) { $context = $('div.rule', $cal_fields); } $context.each(function() { if ($(this).find('select[name=interval]', $context).val() == 'monthly') { var $select = $(this).find('select[name=by]', $context); var val = $select.val(); $(this). find('.'+val).show().end(). find('.extended'). filter(':not(.'+val+')'). filter(':not(.dows)').hide(); $select.unbind('change').change(function() { toggle_monthly_by($(this).closest('.rule')); }); } }); }; // ------------------------------------- // toggle end by // ------------------------------------- var toggle_end_by = function($context) { if ($context == undefined) { $context = $cal_fields; } $context.find('select[name=end]').change(function() { var $select = $(this); switch($select.val()) { case 'by_date' : $select.parent(). siblings('.options').remove().end(). after(_html_end_by_date()); $select.parent().siblings('.options').find('input').datepicker({ dateFormat : SSCalendar.dateFormat, firstDay : SSCalendar.firstDay, changeMonth : true, changeYear : true }); update_end_by_mindate($(this).closest('.rule')); break; case 'after' : $select.parent().siblings('.options').remove().end().after(_html_end_after()); break; default : $select.parent().siblings('.options').remove(); break; }; }) }; // ------------------------------------- // renumber_rules // ------------------------------------- var renumber_rules = function() { $('.rule', $cal_fields).each(function(n) { $(this).find('.rule_number span').text(n+1); }); }; // ------------------------------------- // save calendar data (runs on submit) // ------------------------------------- var save_calendar_data = function() { var success = false; var data = new Object; // Remove old saved data $('#calendar_data').remove(); // Remove old errors $('#calendar_errors').remove(); // Get the calendar ID data.calendar_id = $('select[name=calendar_calendar_id]', $cal_fields).val(); // Prepare for our rule data data.rules = new Array; data.dates = new Array; // Iterate through the rules $('div.rule', $cal_fields).each(function() { var first = $(this).is('.first'); var rule = { 'rule_id' : _get_rule_id($(this).find('input[name=rule_id]')), 'rule_type' : _get_rule_type($(this)), 'all_day' : _get_rule_all_day($(this)), 'start_time': (_get_rule_all_day($(this)) == 'y') ? '' : _get_rule_time($(this).find('.date_range .from .time input')), 'end_time' : (_get_rule_all_day($(this)) == 'y') ? '' : _get_rule_time($(this).find('.date_range .to .time input')) }; if ($(this).find('select[name=interval]').val() == 'select_dates') { if (first != true) { $(this).find('input[name=start_date], input[name=end_date]').remove(); } else { rule.start_date = _get_rule_date($(this).find('input[name=start_date]')); rule.end_date = _get_rule_date($(this).find('input[name=end_date]')); data.rules.push(rule); } var dates = $(this).find('.picker_three').data('values'); $.each(dates, function(k, v) { var o = { 'date' : $.datepicker.formatDate( 'yymmdd', _get_date(v), SSCalendar.dateFormatSettings ), 'start_time' : rule.start_time, 'end_time' : rule.end_time, 'all_day' : rule.all_day, 'rule_type' : rule.rule_type }; data.dates.push(o); }); } else { rule.start_date = _get_rule_date($(this).find('input[name=start_date]')); rule.end_date = _get_rule_date($(this).find('input[name=end_date]')); rule.all_day = _get_rule_all_day($(this)); rule.repeat_years = _get_rule_years($(this)); rule.repeat_months = _get_rule_months($(this)); rule.repeat_weeks = _get_rule_weeks($(this)); rule.repeat_days = _get_rule_days($(this)); rule.days_of_week = _get_rule_dow($(this)); rule.relative_dow = _get_rule_relative($(this)); rule.days_of_month = _get_rule_dom($(this)); rule.months_of_year = ''; rule.end_by = _get_rule_date($(this).find('input[name=end_by_date]')); rule.end_after = _get_rule_end_after($(this)); data.rules.push(rule); } }); // Save the rules as hidden inputs var string = '
'; if (data.calendar_id) { string += _create_hidden_input('calendar_id', data.calendar_id); } $.each(data.rules, function(k, rule) { $.each(rule, function(name, value) { string += _create_hidden_input(name+'['+k+']', value); }); }); $.each(data.dates, function(k, date) { $.each(date, function(name, value) { string += _create_hidden_input('occurrences['+name+'][]', value); }); }); string += '
'; if ($('#entryform').length > 0) { $('#entryform').append(string); } else if ($('#publishForm').length > 0) { $('#publishForm').append(string); } else if ($('#submit_button').length > 0) { $('#submit_button').before(string); } // TODO: We could check for errors at some point... success = true; return success; }; //END save_calendar_data // ------------------------------------- // get rule id // ------------------------------------- var _get_rule_id = function($context) { if ($context.closest('.rule').find('select[name=interval]').val() == 'none') { return ''; } var val = $context.val(); return (val == undefined) ? '' : val; }; // ------------------------------------- // _get_rule_type // ------------------------------------- var _get_rule_type = function($context) { var val = $context.find('select[name=type]').val(); return (val == undefined || val == '') ? '+' : val; }; // ------------------------------------- // _get_rule_date // ------------------------------------- var _get_rule_date = function($field) { var val = $field.val(); if (val == undefined) { return ''; } val = $.datepicker.formatDate( 'yymmdd', _get_date(val), SSCalendar.dateFormatSettings ); return val; }; // ------------------------------------- // _get_rule_all_day // ------------------------------------- var _get_rule_all_day = function($context) { return ($('.all_day input:checkbox', $context). is(':checked')) ? 'y' : ''; }; // ------------------------------------- // _get_rule_time // ------------------------------------- var _get_rule_time = function($field) { var val = String($field.val()); if (val == undefined || val == '') { return ''; } var minute = ''; var hour = ''; var ampm = ($field.siblings('select[name=ampm]').length == 1) ? $field.siblings('select[name=ampm]').val() : ''; // Just an hour if (val.length == 1 || val.length == 2) { minute = '00'; hour = val; } else if (val.indexOf(':') != -1) { var temp = val.split(':'); hour = temp[0]; minute = temp[1]; } else if (val.length == 3 || val.length == 4) { minute = val.substring(val.length - 2); hour = val.substring(0, val.length - 2); } else { minute = '00'; hour = '00'; } // Remove leading zero, or else we won't like what parseInt() gives us if (hour.substring(0, 1) == 0) { hour = hour.substring(1); } //adjust hours to military if pm if (ampm == 'pm' && parseInt(hour, 10) 23) { hour = '00'; } //no negatives of over 60m if (parseInt(minute, 10) 59) { minute = '00'; } //add leading 0 if (hour.length == 1) { hour = "0" + hour; } return hour + minute; }; //END _get_rule_time // ------------------------------------- // _get_rule_years // ------------------------------------- var _get_rule_years = function($context) { var val = ''; if ($('select[name=interval]', $context).val() == 'yearly') { val = $('input[name=every]', $context).val(); } return val; }; // ------------------------------------- // _get_rule_months // ------------------------------------- var _get_rule_months = function($context) { var val = ''; if ($('select[name=interval]', $context).val() == 'monthly') { val = $('input[name=every]', $context).val(); } return val; }; // ------------------------------------- // _get_rule_weeks // ------------------------------------- var _get_rule_weeks = function($context) { var val = ''; if ($('select[name=interval]', $context).val() == 'weekly') { val = $('input[name=every]', $context).val(); } return val; }; // ------------------------------------- // _get_rule_days // ------------------------------------- var _get_rule_days = function($context) { var val = ''; if ($('select[name=interval]', $context).val() == 'daily') { val = $('input[name=every]', $context).val(); } return val; }; // ------------------------------------- // _get_rule_dow // ------------------------------------- var _get_rule_dow = function($context) { var val = []; $('.dows .selector .item', $context).each(function() { if ($(this).data('selector') == true) { val.push($(this).data('value')); } }); return val.join('|'); }; // ------------------------------------- // _get_rule_relative // ------------------------------------- var _get_rule_relative = function($context) { var val = []; if ($('select[name=by]', $context).val() == 'by_relative') { $('.by_relative .selector .item', $context).each(function(){ if ($(this).data('selector') == true) { val.push($(this).data('value')); } }); } return val.join('|'); }; // ------------------------------------- // _get_rule_dom // ------------------------------------- var _get_rule_dom = function($context) { var val = new Array; if ($('select[name=by]', $context).val() == 'by_date') { $('.by_date .selector .item', $context).each(function() { if ($(this).data('selector') == true) { val.push($(this).data('value')); } }); } return val.join('|'); }; // ------------------------------------- // _get_rule_end_after // ------------------------------------- var _get_rule_end_after = function($context) { var val = ''; if ($('select[name=end]', $context).val() == 'after') { val = $('input[name=end_after]', $context).val(); } return val; } // ------------------------------------- // _create_hidden_input // ------------------------------------- var _create_hidden_input = function(name, value) { return ''; }; // ------------------------------------- // show_hide_x // ------------------------------------- var show_hide_x = function() { var $rules = $('.rule', $cal_fields); // Hide X if there is only one rule if ($rules.length == 1) { $('.rule_close, .type', $rules).addClass('inactive'); } // Hide X on the first rule if there is only one include rule else if ($('.type select[value="+"]', $rules).length == 1) { $('.type select[value="+"]', $rules).closest('.rule'). find('.rule_close, .type').addClass('inactive'); } // Show X on first rule else { $('.rule:first .rule_close', $cal_fields).removeClass('inactive'); } } //------------------------------------------------------------------ // start everything //------------------------------------------------------------------ // Systems are go! initialize(); // 12 hour or 24 hour? var time_format = ( $('.rule.first select[name=ampm]', $cal_fields).length > 0 ) ? '12' : '24'; // When the user clicks submit, the work is just getting started... $('input[name=submit], input[name=save], .calendar_submit').click(function() { return save_calendar_data(); }); // Toggle open/close the Dates & Options fields $('.label a', $cal_fields).click(function() { // Hide 'em, Danno $('#calendar_wrapper', $cal_fields).toggle(); // Swap the +/- image $(this).find('img').toggle(); return false; }); // Toggle the time fields when switching between Include and Exclude $('select[name=type]').live('change', function() { var val = $(this).val(); //if we are at val== '-', lets make select dates default if none is selected if (val == '-') { if ($(this).closest('.rule').find('select[name=interval]').val() == 'none') { $(this).closest('.rule').find('select[name=interval]').val('select_dates').trigger('change'); } } if (val == '+') { $(this).closest('.inner'). find('.date_range, .date_range *').removeClass('inactive'). find('.time').show().end(). find('.all_day').show(); } else if ($(this).closest('.rule').find('select[name=interval]').val() == 'select_dates') { $(this).closest('.inner').find('.date_range').addClass('inactive'); } else { $(this).closest('.inner'). find('.date_range'). find('.time, .all_day').addClass('inactive'); } show_hide_x(); }); // Toggle display of time fields $('div.all_day input:checkbox').live('change', function() { toggle_time_fields($(this)); }); // Toggle display of event details $('#calendar_calendars select[name=calendar_calendar_id]', $cal_fields).change(function() { //fills the hidden field so 'required' field works if ($hidden_field) { $hidden_field.val($.trim($(this).val())); } toggle_event_details(); }); //fills the hidden field so 'required' field works (in case this is an edit) if ($hidden_field) { $hidden_field.val( $.trim( $('#calendar_calendars select[name=calendar_calendar_id]', $cal_fields).val() ) ); } // Toggle display of interval details $('.repeat_select select', $cal_fields).change(function() { toggle_interval_details($(this)); }); // Selector widget actions $('.selector .item a', $cal_fields).live('click', function() { var $item = $(this).closest('.item'); toggle_selector_item($item); return false; }); // Add a new rule $('#calendar_new_date button').click(function() { var $rule = $(_html_new_rule()); // Get rid of am/pm dropdowns if we're in 24 hour time if (time_format == '24') { $rule.find('select[name=ampm]').remove(); } // Add rule number $rule.find('div.rule_number span').text($('.rule', $cal_fields).length+1); // Add date picker to From field $('input[name=start_date]', $rule).datepicker({ dateFormat : SSCalendar.dateFormat, firstDay : SSCalendar.firstDay, changeMonth : true, changeYear : true, onSelect : function() { update_to_field_mindate($rule, true); update_picker_three_mindate($rule); update_end_by_mindate($rule); update_picker_three_mindate($rule); } }); // Add date picker to To field $('input[name=end_date]', $rule).datepicker({ dateFormat : SSCalendar.dateFormat, firstDay : SSCalendar.firstDay, changeMonth : true, changeYear : true }); update_from_field_mindate($rule); update_to_field_mindate($rule, true); // Toggle display of interval details $('.repeat_select select', $rule).change(function() { toggle_interval_details($(this)); }); $('#calendar_wrapper div.rule:last').after($rule); show_hide_x(); return false; }); // Close the rule $('.rule_close', $cal_fields).live('click', function(){ $firstrule = $(this).closest('.rule.first'); if ($firstrule.length == 1) { var $includes = $('.type select[value="+"]', $cal_fields). not($firstrule.find('.type select')); if ($includes.length > 0) { $includes.eq(0). closest('.rule').addClass('first'). replaceAll($firstrule). find('.group').addClass('first'); } } else { $(this).closest('.rule').remove(); } renumber_rules(); show_hide_x(); // Remove rule_type from first rule $('.rule.first .type').addClass('inactive'); return false; }); }); jQuery.expr[':'].regex = function(elem, index, match) { var matchParams = match[3].split(','), validLabels = /^(data|css):/, attr = { method: matchParams[0].match(validLabels) ? matchParams[0].split(':')[0] : 'attr', property: matchParams.shift().replace(validLabels,'') }, regexFlags = 'ig', regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags); return regex.test(jQuery(elem)[attr.method](attr.property)); }
Due to our upcoming changes, WE ARE NO LONGER ACCEPTING SUBMISSIONS FOR EVENTS WITH DATES AFTER MARCH 30. Follow our social media platforms or sign up for our newsletter to stay in the loop!
Advertise with us

Events Calendar

+
Add your event More events
Advertise with us

Food & Drink

+

Arts & Leisure

+

Shopping & Style

+