(function($) { $( document ).ready( function () { $( '#newsletter-subscription-button' ).on( 'click', function() { var $email_id = $( '#newsletter_subs_email' ).val(); if ($email_id === '') { alert( 'Please enter valid email ID!' ); return; } //validate email ID var emailRegex = new RegExp( /^([\w\.\-\+]+)@([\w\-]+)((\.(\w){2,3})+)$/i ); if ( ! emailRegex.test( $email_id ) ) { return; } $( "#gd-newsletter-subscription-msg" ).toggleClass( 'gd-newsletter-subscription-success-msg', true ); $( "#gd-newsletter-subscription-msg" ).toggleClass( 'gd-newsletter-subscription-failure-msg', false ); $( "#gd-newsletter-subscription-msg" ).empty().append( "Processing... Please wait..." ); $.ajax( { method: "POST", url: '/wp-json/newsletter/v1/subscribe-all/' + $email_id, success: function (response) { if ( response.code === 500 ) { $( "#gd-newsletter-subscription-msg" ).toggleClass( 'gd-newsletter-subscription-failure-msg', true ); $( "#gd-newsletter-subscription-msg" ).toggleClass( 'gd-newsletter-subscription-success-msg', false ); $( "#gd-newsletter-subscription-msg" ).empty().append( 'Failed to sign up. Please try later!' ); } else { if (response.status) { $( "#gd-newsletter-subscription-msg" ).toggleClass( 'gd-newsletter-subscription-success-msg', true ); $( "#gd-newsletter-subscription-msg" ).toggleClass( 'gd-newsletter-subscription-failure-msg', false ); $( "#gd-newsletter-subscription-msg" ).empty().append( "You have successfully signed up to receive newsletters from GOLDDERBY.COM!" ); } else { var error_message = $( response.results )[0].ErrorMessage; if (error_message.includes( "Violation of PRIMARY KEY constraint" )) { var msg = 'You are already subscribed to GOLDDERBY.COM newsletters!'; } else { var msg = '"Failed to sign up. Please try later!'; } $( "#gd-newsletter-subscription-msg" ).toggleClass( 'gd-newsletter-subscription-failure-msg', true ); $( "#gd-newsletter-subscription-msg" ).toggleClass( 'gd-newsletter-subscription-success-msg', false ); $( "#gd-newsletter-subscription-msg" ).empty().append( msg ); } } }, fail: function (response) { $( "#gd-newsletter-subscription-msg" ).toggleClass( 'gd-newsletter-subscription-failure-msg', true ); $( "#gd-newsletter-subscription-msg" ).toggleClass( 'gd-newsletter-subscription-success-msg', false ); $( "#gd-newsletter-subscription-msg" ).empty().append( "Failed to sign up. Please try later!" ); } } ); } ); $( '#signup-button' ).on( 'click', function() { $( "#newsletter-subscription-msg" ).toggleClass( 'newsletter-subscription-success-msg', true ); $( "#newsletter-subscription-msg" ).toggleClass( 'newsletter-subscription-failure-msg', false ); $( "#newsletter-subscription-msg" ).empty().append( "Processing... Please wait..." ); var nonce = $( '#newsletter-nonce' ).val(); $email_id = $( '#subscriber_email_id' ).val(); if ( $email_id === '' ) { return false; } //validate email ID var emailRegex = new RegExp( /^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$/i ); if ( ! emailRegex.test( $email_id ) ) { return false; } $.ajax( { method: "POST", url: '/wp-json/newsletter/v1/subscribe-newsletters/', beforeSend: function (xhr) { xhr.setRequestHeader( 'X-WP-Nonce', nonce ); }, data: { EmailAddress: $email_id, First_Name: $( '#First_Name' ).val(), Last_Name: $( '#Last_Name' ).val(), Zip_Code: $( '#Zip_Code' ).val(), Country: $( '#Country' ).val(), Company: $( '#Company' ).val(), Title: $( '#Title' ).val(), Film_Industry: $( '#Film_Industry' ).val(), TV_Industry: $( '#TV_Industry' ).val(), Theater_Industry: $( '#Theater_Industry' ).val(), Music_Industry: $( '#Music_Industry' ).val(), Internet_Industry: $( '#Internet_Industry' ).val(), Industry: $( '#Industry' ).val(), AMPAS: $( '#AMPAS' ).val(), TV_Academy: $( '#TV_Academy' ).val(), Recording_Academy: $( '#Recording_Academy' ).val(), SAG_AFTRA: $( '#SAG_AFTRA' ).val(), PublicistsGuild: $( '#PublicistsGuild' ).val(), ProducerGuild: $( '#ProducerGuild' ).val(), WriterGuild: $( '#WriterGuild' ).val(), DirectorGuild: $( '#DirectorGuild' ).val(), HFPA: $( '#HFPA' ).val(), CostumeDesigners: $( '#CostumeDesigners' ).val(), MusicGuild: $( '#MusicGuild' ).val(), MakeUp: $( '#MakeUp' ).val(), ArtDirectorGuild: $( '#ArtDirectorGuild' ).val(), SoundGuild: $( '#SoundGuild' ).val(), MakeUp: $( '#MakeUp' ).val(), ArtDirectorGuild: $( '#ArtDirectorGuild' ).val(), SoundGuild: $( '#SoundGuild' ).val(), VisualEffects: $( '#VisualEffects' ).val(), Cinematographers: $( '#Cinematographers' ).val(), Editors: $( '#Editors' ).val(), Animation: $( '#Animation' ).val(), Guild_or_union_affiliation: $( '#Guild_or_union_affiliation' ).val(), Profession_Actor_Performer: $( '#Profession_Actor_Performer' ).val(), Profession_Agent_Manager: $( '#Profession_Agent_Manager' ).val(), Profession_Director: $( '#Profession_Director' ).val(), Profession_Executive: $( '#Profession_Executive' ).val(), Profession_Lawyer: $( '#Profession_Lawyer' ).val(), Profession_Marketing: $( '#Profession_Marketing' ).val(), Profession_Producer: $( '#Profession_Producer' ).val(), Profession_Production: $( '#Profession_Production' ).val(), Profession_Publicist: $( '#Profession_Publicist' ).val(), Profession_Writer: $( '#Profession_Writer' ).val(), Profession_Other: $( '#Profession_Other' ).val(), AllNewsletters_Opted_In: $( '#AllNewsletters_Opted_In' ).val(), OscarsGoldenGlobe_Opted_In: $( '#OscarsGoldenGlobe_Opted_In' ).val(), Emmys_Opted_In: $( '#Emmys_Opted_In' ).val(), Tonys_Opted_In: $( '#Tonys_Opted_In' ).val(), Grammys_Opted_In: $( '#Grammys_Opted_In' ).val(), AmericanIdol_Opted_In: $( '#AmericanIdol_Opted_In' ).val(), AmericasGotTalet_Opted_In: $( '#AmericasGotTalet_Opted_In' ).val(), BigBrother_Opted_In: $( '#BigBrother_Opted_In' ).val(), DanceWStars_Opted_In: $( '#DanceWStars_Opted_In' ).val(), HellKitchen_Opted_In: $( '#HellKitchen_Opted_In' ).val(), SYTYCD_Opted_In: $( '#SYTYCD_Opted_In' ).val(), Survivor_Opted_In: $( '#Survivor_Opted_In' ).val(), AmazingRace_Opted_In: $( '#AmazingRace_Opted_In' ).val(), RuPaul_Opted_In: $( '#RuPaul_Opted_In' ).val(), TopChef_Opted_In: $( '#TopChef_Opted_In' ).val(), TheVoice_Opted_In: $( '#TheVoice_Opted_In' ).val(), WorldOfDance_Opted_In: $( '#WorldOfDance_Opted_In' ).val(), RealityTV_Opted_In: $( '#RealityTV_Opted_In' ).val(), }, success: function (response) { if ( response.code === 500 ) { $( "#newsletter-subscription-msg" ).toggleClass( 'newsletter-subscription-failure-msg', true ); $( "#newsletter-subscription-msg" ).toggleClass( 'newsletter-subscription-success-msg', false ); $( "#newsletter-subscription-msg" ).empty().append( 'Failed to sign up. Please try later!' ); } else { if (response.status) { $( "#newsletter-subscription-msg" ).toggleClass( 'newsletter-subscription-success-msg', true ); $( "#newsletter-subscription-msg" ).toggleClass( 'newsletter-subscription-failure-msg', false ); $( "#newsletter-subscription-msg" ).empty().append( "You have successfully signed up / updated newsletter subscriptions!" ); } else { var error_message = $( response.results )[0].ErrorMessage; if (error_message.includes( "Violation of PRIMARY KEY constraint" )) { var msg = 'You are already subscribed to GOLDDERBY.COM newsletters!'; } else { var msg = '"Failed to sign up. Please try later!'; } $( "#newsletter-subscription-msg" ).toggleClass( 'newsletter-subscription-failure-msg', true ); $( "#newsletter-subscription-msg" ).toggleClass( 'newsletter-subscription-success-msg', false ); $( "#newsletter-subscription-msg" ).empty().append( msg ); } } }, fail: function (response) { $( "#newsletter-subscription-msg" ).toggleClass( 'newsletter-subscription-failure-msg', true ); $( "#newsletter-subscription-msg" ).toggleClass( 'newsletter-subscription-success-msg', false ); $( "#newsletter-subscription-msg" ).empty().append( "Failed to sign up. Please try later!" ); } } ); } ); $( 'input[type=checkbox]' ).change( function () { var is_checked = false; if ($( this ).is( ':checked' )) { if ('AllNewsletters_Opted_In' !== $( this ).prop( 'name' )) { $( "input[name=AllNewsletters_Opted_In]" ).prop( 'checked', false ); $( "input[name=AllNewsletters_Opted_In]" ).prop( 'value', 'No' ); $( this ).prop( 'checked', true ); $( this ).prop( 'value', 'Yes' ); } else { $( "input[name=AllNewsletters_Opted_In]" ).prop( 'checked', true ); $( "input[name=AllNewsletters_Opted_In]" ).prop( 'value', 'Yes' ); $( 'input[type=checkbox]' ).each( function () { if ('AllNewsletters_Opted_In' !== $( this ).prop( 'name' )) { $( this ).prop( 'checked', false ); $( this ).prop( 'value', 'No' ); } } ); } } else { $( 'input[type=checkbox]' ).each( function () { if ($( this ).is( ':checked' )) { is_checked = true; } else { $( this ).prop( 'checked', false ); $( this ).prop( 'value', 'No' ); } } ); if ( ! is_checked) { $( "input[name=AllNewsletters_Opted_In]" ).prop( 'checked', true ); $( "input[name=AllNewsletters_Opted_In]" ).prop( 'value', 'Yes' ); } } } ); $( '#header-newsletter-subscription-button' ).on( 'click', function() { var $email_id = $( '#header-newsletter_subs_email' ).val(); if ($email_id === '') { alert( 'Please enter valid email ID!' ); return; } //validate email ID var emailRegex = new RegExp( /^([\w\.\-\+]+)@([\w\-]+)((\.(\w){2,3})+)$/i ); if ( ! emailRegex.test( $email_id ) ) { return; } $( '#header-newsletter_subs_email' ).val( '' ); $( '#header-newsletter_subs_email' ).attr( 'placeholder', 'Processing... Please wait...' ); $.ajax( { method: "POST", url: '/wp-json/newsletter/v1/subscribe-all/' + $email_id, success: function (response) { if ( response.code === 500 ) { $( '#header-newsletter_subs_email' ).attr( 'placeholder', 'Failed to sign up. Please try later!' ); $( '#header-newsletter_subs_email' ).css( 'color', '#fb1506' ); } else { if (response.status) { $( '#header-newsletter_subs_email' ).attr( 'placeholder', 'Signed Up successfully!' ); $( '#header-newsletter_subs_email' ).css( 'color', '#008000' ); } else { var error_message = $( response.results )[0].ErrorMessage; if (error_message.includes( 'Violation of PRIMARY KEY constraint' )) { var msg = 'You are already subscribed!'; } else { var msg = 'Failed to sign up. Please try later!'; } $( '#header-newsletter_subs_email' ).attr( 'placeholder', '' ); $( '#header-newsletter_subs_email' ).attr( 'placeholder', msg ); $( '#header-newsletter_subs_email' ).css( 'color', '#fb1506' ); } } }, fail: function (response) { $( '#header-newsletter_subs_email' ).attr( 'placeholder', 'Failed to sign up. Please try later!' ); $( '#header-newsletter_subs_email' ).css( 'color', '#fb1506' ); } } ); } ); } ); })(jQuery);