SFBay Event Center
Big4Bio:SFBay Twitter Feed
(function($){
$("#emailFormat").hide();
})(jQuery);
var ea = { toggleForm: function () { if ($jq('#updateEa:visible').length > 0) { this.hideForm(); } else { this.showForm(); } $jq('#updateEa').slideToggle(); }, showForm: function() {
$jq( '.visitorActions input[name=_save]' ).attr( 'disabled', 'disabled' ); $jq( '#updateEaSuccess' ).hide(); },
hideForm: function() { $jq( '.visitorActions input[name=_save]' ).removeAttr( 'disabled' ); $jq( '#eaUpdateErrors' ).hide(); $jq( '#updateEaForm :text' ).val( '' ); },
update: function() {
$jq( '#eaUpdateErrors' ).hide();
$jq.ajax( { type: 'POST', url: $jq( '#updateEaForm' ).attr( 'action' ), dataType: "json", data: $jq( '#updateEaForm' ).serialize(), success: function( data, textStatus ) { ea._handleUpdateSuccess( data ); }, error: function( request, textStatus, errorThrown ) { ea._handleUpdateError( errorThrown ); }, beforeSend: function( request ) { $jq( '#eaUpdateWait' ).toggle(); }, complete: function( request, textStatus ) { $jq( '#eaUpdateWait' ).toggle(); } } ); },
_handleUpdateSuccess: function( rsp ) {
if ( rsp.status == 'failure' ) {
this._displayError( rsp.fieldErrors.emailAddr ); return; }
$jq( '#emailAddr' ).text( rsp.ea.emailAddr ); $jq( '#updateEaForm input[name=oldEmailAddr]' ).val( rsp.ea.emailAddr ); $jq( '#updateEaSuccess' ).show(); this.hideForm(); },
_handleUpdateError: function( error ) {
this._displayError( 'We are unable to update your email address at this time' ); },
_displayError: function( error ) {
error = error.replace( /\.ea\.[\w]+$/, '' ); // Strip off .ea.emailAddr $jq( '#eaUpdateErrors' ).text( error ); $jq( '#eaUpdateErrors' ).fadeIn( 'slow' ); } };
jQuery( document ).ready( function() { var address = "Address"; var update_profile = "Update Profile"; var yes_unsubscribe = "Unsubscribe"; var street_address = "Street"; var state_province = "Select a state/province"; var country_label = "Select a country"; var zip_code = "Zip Code"; var city = "City";
var buttonText = { update_profile: $jq('
').html(update_profile).text(), yes_unsubscribe: $jq(' ').html(yes_unsubscribe).text() }; var strings = { address: $jq(' ').html(address).text(), street_address: $jq(' ').html(street_address).text(), state_province: $jq(' ').html(state_province).text(), country: $jq(' ').html(country_label).text(), zip_code: $jq(' ').html(zip_code).text(), city: $jq(' ').html(city).text() }; var country = $jq('[data-name="Country"]'); var street = $jq('[data-name="Street Address"]'); var state_province = $jq('[data-name="State/Province"]'); var address_label = $jq(' ', { 'class': 'prop-input clearfix' }).append($jq('', { html: strings.address }));var first_address = $jq(" [data-name='Street Address'], [data-name='City'], [data-name='Zip Code'], [data-name='Country'], [data-name='State/Province'] ").first();
if(first_address.attr("data-name") !== "Country"){ country.insertBefore(first_address); }
$jq('input[data-input="Street Address"]').attr("placeholder",strings.street_address); $jq('input[data-input="City"]').attr("placeholder",strings.city); $jq('input[data-input="Zip Code"]').attr("placeholder",strings.zip_code); $jq('[data-name="Country"]').find('select > option:first-child').text(strings.country); $jq('[data-name="State/Province"]').find('select > option:first-child').text(strings.state_province); $jq('div[data-name="Street Address"],div[data-name="State/Province"],div[data-name="City"],div[data-name="Zip Code"]') .each(function(){ $jq(this).find('label').hide(); }); label_location = country.length ? country : first_address; address_label.insertBefore(label_location); if( first_address.find("span.required").length ){ address_label.find("label").prepend('*'); }
$jq( '#optoutAllRadio' ).click( function() { $jq( '#intCatSelection' ).hide(); $jq( '.visitorActions .btn-primary').val(buttonText.yes_unsubscribe); $jq( '#emailFormat :input' ).attr( 'disabled', 'disabled' ); $jq( '#subProfile :input' ).attr( 'disabled', 'disabled' ); }); $jq( '#optoutSomeRadio' ).click( function() { $jq( '#intCatSelection' ).slideDown(); $jq( '.visitorActions .btn-primary').val(buttonText.update_profile); $jq( '#emailFormat :input' ).removeAttr( 'disabled' ); $jq( '#subProfile :input' ).removeAttr( 'disabled' ); });
if ($jq( '#optoutAllRadio:checked').length > 0) { $jq( '#optoutAllRadio').trigger("click"); }
$jq( '#updateEmailAddrLink a' ).click( function() { ea.toggleForm(); });
$jq( '#updateEa .btn-primary' ).click( function() { ea.update(); return false; });
$jq( '#updateEa .btn-secondary' ).click( function() { ea.hideForm(); return false; });
var setInputType = (function getInputType() { var $input_id = state_province.find('input[value=1300]'), $select_input = state_province.find('select[id^="inputProp"]'), $text_input = $jq('', { 'id': $select_input.attr('id'), 'data-input': 'State/Province', 'name': $select_input.attr('name'), 'type': 'text', 'maxlength': '50', 'placeholder': 'State/Province',
}), init = function init(country_code) { var show_dropdown_input = country_code === 'us' || country_code === 'ca';
if (show_dropdown_input && $text_input.is(':visible')) { $input_id.val(1300); $text_input.replaceWith($select_input); } else if (!show_dropdown_input && $select_input.is(':visible')) { $input_id.val(1400); $select_input.replaceWith($text_input); } };
return init; })(), country_select = country.find(' > select');
if (country_select.val()) { setInputType(country_select.val()); }
country_select.on('change', function onCountryUpdate() { setInputType($jq(this).val()); });
$jq('input[data-input="Birthday"]').attr("placeholder","MM/DD").attr("maxlength", "5"); $jq('input[data-input="Anniversary"]').attr("placeholder","MM/DD/YYYY").attr("maxlength", "10");
// HTML5 Feature of "placeholder" in text input fields does not yet work in IE // this code will mimic the behavior of the placeholder attribute // so that it works in IE in the same way as other browsers // before executing the code, we expand the jquery.support object to check // if the placeholder feature works in the browser, if it does not // then we implement the javascript functions
// code concept from: https://www.cssnewbie.com/cross-browser-support-for-html5-placeholder-text-in-forms/ //detect if browser supports placeholders jQuery.support.placeholder = false; var test = document.createElement('input'); if('placeholder' in test) jQuery.support.placeholder = true;
if(!jQuery.support.placeholder) { //placeholder text is not supported jQuery('body').on({ focus: function () { if (jQuery(this).attr('placeholder') != '' && jQuery(this).val() == jQuery(this).attr('placeholder')) { jQuery(this).val('').removeClass('hasPlaceholder'); } }, blur: function () { if (jQuery(this).attr('placeholder') != '' && (jQuery(this).val() == '' || jQuery(this).val() == jQuery(this).attr('placeholder'))) { jQuery(this).val(jQuery(this).attr('placeholder')).addClass('hasPlaceholder'); } } }, '[placeholder]'); jQuery('form').submit(function () { jQuery(this).find('.hasPlaceholder').each(function() { jQuery(this).val(''); }); }); setInterval(function() { jQuery("[placeholder]:not('.init-ph')").blur().addClass("init-ph") }, 500); }
});
function onSubmit(response) { $jq( '#capResponse' ).val( response ); };