"use strict"; jQuery(document).ready(function ($) { // if google button is display if ($(".woo-slg-social-googleplus").length > 0) { var auth2; var googleUser = {}; if (WOOSlg.google_client_id != "") { var woo_slg_start_app = function () { google.accounts.id.initialize({ client_id: WOOSlg.google_client_id, callback: handleCredentialResponse }); $(".woo-slg-social-googleplus").each(function(key, value) { var buttonid = $(this).attr('id'); var newbutton_id = buttonid +"-"+ key; $(this).attr('id', newbutton_id); var image = $(this).parents("a").find("img").width(); google.accounts.id.renderButton( document.getElementById(newbutton_id), { theme: "filled_blue", size: "medium", width: "standard", type: "standard", width : image+"px" } ); }); google.accounts.id.prompt(); }; // initialize google library woo_slg_start_app(); }else{ var object = $('.woo-slg-social-googleplus'); var errorel = $(object).parents('.woo-slg-social-container').find('.woo-slg-login-error'); errorel.hide(); errorel.html(''); // display error if (WOOSlg.gperror == '1') { errorel.show(); errorel.html(WOOSlg.gperrormsg); return false; } } function handleCredentialResponse(response) { // send ajax google data var object = $('.woo-slg-social-googleplus'); // Define some veriable var useragreement = 'false'; // Check user agreement selected or not if ( jQuery(object).parents('.woo-slg-social-container').find('#wooslg-user-agree-check').is(":checked")) { useragreement = 'true'; } var woo_slg_post_data = { action: 'woo_slg_social_login', type: 'googleplus', gp_userdata: response.credential, useragreement : useragreement, }; $.ajax({ url: WOOSlg.ajaxurl, type: 'post', data: woo_slg_post_data, success: function (woo_slg_google_ajax_response) { if (woo_slg_google_ajax_response) { woo_slg_social_connect('googleplus', object); } } }); } } if (document.URL.indexOf('code=') != -1 && WOOSlg.fbappid != '' && navigator.userAgent.match('CriOS')) { facebookTimer = setInterval(function () { if (typeof FB != "undefined") { FB.getLoginStatus(function (response) { if (response.status === 'connected') { var object = $('a.woo-slg-social-login-facebook'); woo_slg_social_connect('facebook', object); clearInterval(facebookTimer); } }, true); } }, 300); } // login with facebook // login with google+ // login with linkedin $(document).on('click', 'a.woo-slg-social-login-linkedin', function () { var object = $(this); var errorel = $(this).parents('.woo-slg-social-container').find('.woo-slg-login-error'); errorel.hide(); errorel.html(''); if (WOOSlg.lierror == '1') { errorel.show(); errorel.html(WOOSlg.lierrormsg); return false; } else { var linkedinurl = $(this).closest('.woo-slg-social-container').find('.woo-slg-social-li-redirect-url').val(); if (linkedinurl == '') { alert(WOOSlg.urlerror); return false; } var linkedinLogin = window.open(linkedinurl, "linkedin", "scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,height=400,width=600"); var lTimer = setInterval(function () { //set interval for executing the code to popup try { if (linkedinLogin.location.hostname == window.location.hostname) { //if login domain host name and window location hostname is equal then it will go ahead clearInterval(lTimer); linkedinLogin.close(); woo_slg_social_connect('linkedin', object); } } catch (e) { } }, 300); } }); $(document).on('click', 'a.woo-slg-social-login-apple', function () { var object = $(this); var errorel = $(this).parents('.woo-slg-social-container').find('.woo-slg-login-error'); errorel.hide(); errorel.html(''); if (WOOSlg.appleerror == '1') { errorel.show(); errorel.html(WOOSlg.appleerrormsg); return false; } }); // login with twitter $(document).on('click', 'a.woo-slg-social-login-twitter', function () { var object = $(this); var errorel = $(this).parents('.woo-slg-social-container').find('.woo-slg-login-error'); var parents = $(this).parents('div.woo-slg-social-container'); var appendurl = ''; //check button is clicked form widget if (parents.hasClass('woo-slg-widget-content')) { appendurl = '&container=widget'; } errorel.hide(); errorel.html(''); if (WOOSlg.twerror == '1') { errorel.show(); errorel.html(WOOSlg.twerrormsg); return false; } else { var twitterurl = WOOSlg.tw_authurl; if (twitterurl == '') { alert(WOOSlg.urlerror); return false; } var twLogin = window.open(twitterurl, "twitter_login", "scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,height=400,width=600"); var tTimer = setInterval(function () { //set interval for executing the code to popup try { if (twLogin.location.hostname == window.location.hostname) { //if login domain host name and window location hostname is equal then it will go ahead clearInterval(tTimer); twLogin.close(); if (WOOSlg.userid != '') { woo_slg_social_connect('twitter', object); } else { window.parent.location = WOOSlg.socialloginredirect + appendurl; } } } catch (e) { } }, 300); } }); // login with yahoo $(document).on('click', 'a.woo-slg-social-login-yahoo', function () { var object = $(this); var errorel = $(this).parents('.woo-slg-social-container').find('.woo-slg-login-error'); errorel.hide(); errorel.html(''); if (WOOSlg.yherror == '1') { errorel.show(); errorel.html(WOOSlg.yherrormsg); return false; } else { var yahoourl = $(this).closest('.woo-slg-social-container').find('.woo-slg-social-yh-redirect-url').val(); if (yahoourl == '') { alert(WOOSlg.urlerror); return false; } var yhLogin = window.open(yahoourl, "yahoo_login", "scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,height=400,width=600"); var yTimer = setInterval(function () { //set interval for executing the code to popup try { if (yhLogin.location.hostname == window.location.hostname) { //if login domain host name and window location hostname is equal then it will go ahead clearInterval(yTimer); yhLogin.close(); woo_slg_social_connect('yahoo', object); } } catch (e) { } }, 300); } }); // login with foursquare $(document).on('click', 'a.woo-slg-social-login-foursquare', function () { var object = $(this); var errorel = $(this).parents('.woo-slg-social-container').find('.woo-slg-login-error'); errorel.hide(); errorel.html(''); if (WOOSlg.fserror == '1') { errorel.show(); errorel.html(WOOSlg.fserrormsg); return false; } else { var foursquareurl = $(this).closest('.woo-slg-social-container').find('.woo-slg-social-fs-redirect-url').val(); if (foursquareurl == '') { alert(WOOSlg.urlerror); return false; } var fsLogin = window.open(foursquareurl, "foursquare_login", "scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,height=400,width=600"); var fsTimer = setInterval(function () { //set interval for executing the code to popup try { if (fsLogin.location.hostname == window.location.hostname) { //if login domain host name and window location hostname is equal then it will go ahead clearInterval(fsTimer); fsLogin.close(); woo_slg_social_connect('foursquare', object); } } catch (e) { } }, 300); } }); // login with windows live $(document).on('click', 'a.woo-slg-social-login-windowslive', function () { var object = $(this); var errorel = $(this).parents('.woo-slg-social-container').find('.woo-slg-login-error'); errorel.hide(); errorel.html(''); if (WOOSlg.wlerror == '1') { errorel.show(); errorel.html(WOOSlg.wlerrormsg); return false; } else { var windowsliveurl = $(this).closest('.woo-slg-social-container').find('.woo-slg-social-wl-redirect-url').val(); if (windowsliveurl == '') { alert(WOOSlg.urlerror); return false; } var wlLogin = window.open(windowsliveurl, "windowslive_login", "scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,height=400,width=600"); var wlTimer = setInterval(function () { //set interval for executing the code to popup try { if (wlLogin.location.hostname == window.location.hostname) { //if login domain host name and window location hostname is equal then it will go ahead clearInterval(wlTimer); wlLogin.close(); woo_slg_social_connect('windowslive', object); } } catch (e) { } }, 300); } }); // login with Line $(document).on('click', 'a.woo-slg-social-login-line', function () { var object = $(this); var errorel = $(this).parents('.woo-slg-social-container').find('.woo-slg-login-error'); errorel.hide(); errorel.html(''); if (WOOSlg.lineerror == '1') { errorel.show(); errorel.html(WOOSlg.lineerrormsg); return false; } else { var lineurl = $(this).closest('.woo-slg-social-container').find('.woo-slg-social-line-redirect-url').val(); if (lineurl == '') { alert(WOOSlg.urlerror); return false; } var lineLogin = window.open(lineurl, "line_login", "scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,height=400,width=600"); var lineTimer = setInterval(function () { //set interval for executing the code to popup try { if (lineLogin.location.hostname == window.location.hostname) { //if login domain host name and window location hostname is equal then it will go ahead clearInterval(lineTimer); lineLogin.close(); woo_slg_social_connect('line', object); } } catch (e) { } }, 300); } }); // login with VK.com $(document).on('click', 'a.woo-slg-social-login-vk', function () { var object = $(this); var errorel = $(this).parents('.woo-slg-social-container').find('.woo-slg-login-error'); errorel.hide(); errorel.html(''); if (WOOSlg.vkerror == '1') { errorel.show(); errorel.html(WOOSlg.vkerrormsg); return false; } else { var vkurl = $(this).closest('.woo-slg-social-container').find('.woo-slg-social-vk-redirect-url').val(); if (vkurl == '') { alert(WOOSlg.urlerror); return false; } var vkLogin = window.open(vkurl, "vk_login", "scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,height=400,width=600"); var vkTimer = setInterval(function () { //set interval for executing the code to popup try { if (vkLogin.location.hostname == window.location.hostname) { //if login domain host name and window location hostname is equal then it will go ahead clearInterval(vkTimer); vkLogin.close(); woo_slg_social_connect('vk', object); } } catch (e) { } }, 300); } }); // Social login toggle on checkout, shortcode page $(document).on('click', '.woo-slg-show-social-login', function () { $('.woo-slg-social-container-checkout').slideToggle(); }); // Social login toggle on widget area $(document).on('click', '.woo-slg-show-social-login-widget', function () { $('.woo-slg-social-container-widget').slideToggle(); }); // Social login toggle on widget area $(document).on('click', '.woo-slg-login-page .woo-slg-show-social-login', function () { $("html, body").animate({scrollTop: $(document).height()}, "slow"); }); //My Account Show Link Buttons "woo-slg-show-link" $(document).on('click', '.woo-slg-show-link', function () { $('.woo-slg-show-link').hide(); $('.woo-slg-profile-link-container').show(); }); // login with paypal $(document).on('click', 'a.woo-slg-social-login-paypal', function () { var object = $(this); var errorel = $(this).parents('.woo-slg-social-container').find('.woo-slg-login-error'); errorel.hide(); errorel.html(''); if (WOOSlg.paypalerror == '1') { errorel.show(); errorel.html(WOOSlg.paypalerrormsg); return false; } else { var paypalurl = $(this).closest('.woo-slg-social-container').find('.woo-slg-social-paypal-redirect-url').val(); if (paypalurl == '') { alert(WOOSlg.urlerror); return false; } var paypalLogin = window.open(paypalurl, "paypal_login", "scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,height=400,width=600"); var paypalTimer = setInterval(function () { //set interval for executing the code to popup try { if (paypalLogin.location.hostname == window.location.hostname) { //if login domain host name and window location hostname is equal then it will go ahead clearInterval(paypalTimer); paypalLogin.close(); woo_slg_social_connect('paypal', object); } } catch (e) { } }, 300); } }); // login with amazon $(document).on('click', 'a.woo-slg-social-login-amazon', function () { var object = $(this); var errorel = $(this).parents('.woo-slg-social-container').find('.woo-slg-login-error'); errorel.hide(); errorel.html(''); if (WOOSlg.amazonerror == '1') { errorel.show(); errorel.html(WOOSlg.amazonerrormsg); return false; } else { var amazonurl = $(this).closest('.woo-slg-social-container').find('.woo-slg-social-amazon-redirect-url').val(); if (amazonurl == '') { alert(WOOSlg.urlerror); return false; } var amazonLogin = window.open(amazonurl, "amazon_login", "scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,height=400,width=600"); var amazonTimer = setInterval(function () { //set interval for executing the code to popup try { if (amazonLogin.location.hostname == window.location.hostname) { //if login domain host name and window location hostname is equal then it will go ahead clearInterval(amazonTimer); amazonLogin.close(); woo_slg_social_connect('amazon', object); } } catch (e) { } }, 300); } }); // login with email $(".woo_slg_email_login_using").hide(); $(".woo-slg-email-login-btn-resend").hide(); $(document).on('click', '.woo-slg-email-login-btn', function (e) { $(".woo_slg_email_login_using").hide(); var login_container = $(this).closest('.woo-slg-email-login-container'); var current_obj = $(this); var email = login_container.find('.woo-slg-email-login'); var redirect_url = login_container.find('input[name="woo_slg_login_redirect_url"]').val(); var errorel = login_container.find('.woo-slg-login-email-error'); var successel = login_container.find('.woo-slg-login-success'); var errorelotp = login_container.find('.woo-slg-login-email-otp-error'); var successelotp = login_container.find('.woo-slg-login-otp-success'); var validateEmail = validateEmailAddress(email.val()); errorel.hide(); errorel.html(''); successel.hide(); successel.html(''); if (email.val().length == 0 || !validateEmail) { if (WOOSlg.emailerrormsg) { errorel.show(); errorel.html(WOOSlg.emailerrormsg); return false; } } var data = { action: 'woo_slg_login_email', email: email.val(), current_url: window.location.href }; //show loader login_container.find('.woo-slg-login-loader').show(); login_container.find('.woo-slg-email-login-wrap').hide(); jQuery.post(WOOSlg.ajaxurl, data, function (response) { // hide loader login_container.find('.woo-slg-login-loader').hide(); login_container.find('.woo-slg-email-login-wrap').show(); if (response != '') { var response = jQuery.parseJSON(response); if (response.success) { if (response.message == "") { if (redirect_url != '') { // check if caching option is selected if( WOOSlg.caching_enable == 'yes') { //check ? is exist in url or not var strexist = redirect_url.indexOf("?"); if( strexist >= 0 ) { redirect_url = redirect_url + '&no-caching=1'; } else { redirect_url = redirect_url + '?no-caching=1'; } } window.location = redirect_url; } else { //if user created successfully then reload the page var current_url = window.location.href; // check if caching option is selected if( WOOSlg.caching_enable == 'yes') { //check ? is exist in url or not var strexist = current_url.indexOf("?"); if( strexist >= 0 ) { current_url = current_url + '&no-caching=1'; } else { current_url = current_url + '?no-caching=1'; } } window.location = current_url; } } else { errorelotp.hide(); successel.show(); successel.html(response.message); if(response.woo_slg_enable_email_otp_varification == 'yes'){ current_obj.parent().parent().find('.woo_slg_email_login_using').show(); } } } if (response.error) { errorel.show(); errorel.html(response.message); } } }); return false; }); $(document).on('click', '.woo-slg-email-login-btn-resend', function (e) { $(".woo_slg_email_login_using").hide(); var login_container = $(this).closest('.woo-slg-email-login-container'); var current_obj = $(this); var email = login_container.find('.woo-slg-email-login'); var redirect_url = login_container.find('input[name="woo_slg_login_redirect_url"]').val(); var errorel = login_container.find('.woo-slg-login-email-error'); var successel = login_container.find('.woo-slg-login-success'); var errorelotp = login_container.find('.woo-slg-login-email-otp-error'); var successelotp = login_container.find('.woo-slg-login-otp-success'); var validateEmail = validateEmailAddress(email.val()); errorel.hide(); errorel.html(''); successel.hide(); successel.html(''); if (email.val().length == 0 || !validateEmail) { if (WOOSlg.emailerrormsg) { errorel.show(); errorel.html(WOOSlg.emailerrormsg); return false; } } var data = { action: 'woo_slg_login_email', email: email.val(), resendit:'1', }; //show loader login_container.find('.woo-slg-login-loader').show(); login_container.find('.woo-slg-email-login-wrap').hide(); jQuery.post(WOOSlg.ajaxurl, data, function (response) { // hide loader login_container.find('.woo-slg-login-loader').hide(); login_container.find('.woo-slg-email-login-wrap').show(); if (response != '') { var response = jQuery.parseJSON(response); if (response.success) { if (response.message == "") { if (redirect_url != '') { // check if caching option is selected if( WOOSlg.caching_enable == 'yes') { //check ? is exist in url or not var strexist = redirect_url.indexOf("?"); if( strexist >= 0 ) { redirect_url = redirect_url + '&no-caching=1'; } else { redirect_url = redirect_url + '?no-caching=1'; } } window.location = redirect_url; } else { //if user created successfully then reload the page var current_url = window.location.href; // check if caching option is selected if( WOOSlg.caching_enable == 'yes') { //check ? is exist in url or not var strexist = current_url.indexOf("?"); if( strexist >= 0 ) { current_url = current_url + '&no-caching=1'; } else { current_url = current_url + '?no-caching=1'; } } window.location = current_url; } } else { errorelotp.hide(); successel.show(); successel.html(response.message); if(response.woo_slg_enable_email_otp_varification == 'yes'){ current_obj.parent().parent().find('.woo_slg_email_login_using').show(); } } } if (response.error) { errorel.show(); errorel.html(response.message); } } }); return false; }); $(document).on('click', '.woo-slg-email-login-container .woo-slg-email-login-btn-otp', function () { var login_container = $(this).closest('.woo-slg-email-login-container'); var redirect_url = login_container.find('input[name="woo_slg_login_redirect_url"]').val(); var errorel = login_container.find('.woo-slg-login-email-otp-error'); var successel = login_container.find('.woo-slg-login-otp-success'); var otp = login_container.find('.woo-slg-otp-login'); var validateOTP = otp.val(); if (otp.val().length == 0 || !validateOTP) { if (WOOSlg.otperrormsg) { errorel.show(); errorel.html(WOOSlg.otperrormsg); return false; } } var data = { action: 'woo_slg_login_otp_email', otp: otp.val() }; login_container.find('.woo-slg-login-loader').show(); login_container.find('.woo-slg-email-login-wrap').hide(); jQuery.post(WOOSlg.ajaxurl, data, function (response) { // hide loader login_container.find('.woo-slg-login-loader').hide(); login_container.find('.woo-slg-email-login-wrap').show(); if (response != '') { var response = jQuery.parseJSON(response); if (response.success) { if (response.message == "") { if (redirect_url != '') { // check if caching option is selected if( WOOSlg.caching_enable == 'yes') { //check ? is exist in url or not var strexist = redirect_url.indexOf("?"); if( strexist >= 0 ) { redirect_url = redirect_url + '&no-caching=1'; } else { redirect_url = redirect_url + '?no-caching=1'; } } window.location = redirect_url; } else { //if user created successfully then reload the page var current_url = window.location.href; // check if caching option is selected if( WOOSlg.caching_enable == 'yes') { //check ? is exist in url or not var strexist = current_url.indexOf("?"); if( strexist >= 0 ) { current_url = current_url + '&no-caching=1'; } else { current_url = current_url + '?no-caching=1'; } } window.location = current_url; } } else { errorel.hide(); successel.show(); successel.html(response.message); window.location = redirect_url; } } if (response.error) { jQuery(".woo-slg-login-success").hide(); jQuery(".woo-slg-login-email-error").hide(); errorel.show(); errorel.html(response.message); } } }); }); }); // Social Connect Process function woo_slg_social_connect(type, object) { // Define some veriable var useragreement = 'false'; // Check user agreement selected or not if ( jQuery(object).parents('.woo-slg-social-container').find('#wooslg-user-agree-check').is(":checked")) { useragreement = 'true'; } var data = { action: 'woo_slg_social_login', type: type, useragreement : useragreement }; // Show loader jQuery(object).parents('.woo-slg-social-container').find('.woo-slg-login-loader').show(); jQuery(object).parents('.woo-slg-social-container').find('.woo-slg-social-wrap').hide(); jQuery.post(WOOSlg.ajaxurl, data, function (response) { // hide loader jQuery(object).parents('.woo-slg-social-container').find('.woo-slg-login-loader').hide(); jQuery(object).parents('.woo-slg-social-container').find('.woo-slg-social-wrap').show(); var redirect_url = object.parents('.woo-slg-social-container').find('.woo-slg-redirect-url').val(); if( response.indexOf('restrict') > -1 ){ jQuery(object).parents('.woo-slg-social-container').find('.woo-slg-restrict').remove(); jQuery(object).parents('.woo-slg-social-container').append('