(function($) { "use strict"; /** * Divi AiO Tabs */ $(".daio-nav-bar .daio-main-navigation a").on("click", function(e) { e.preventDefault(); $(".daio-nav-bar .daio-main-navigation a").removeClass("link-active"); $(this).addClass( "link-active" ); var tab = $(this).attr("href"); $(".daio-settings-content").removeClass("active-content"); $(".daio-settings-contents") .find( tab ) .addClass( "active-content" ); }); /** * Button */ var saveBtn = $( ".daio-header-right .daio-button" ); $('.daio-checkbox input[type="checkbox"]').on("click", function(e) { saveBtn.addClass("save-now"); saveBtn.removeAttr("disabled").css("cursor", "pointer"); }); /** * Ajax Save */ $( ".daio-settings-save" ).on( "click", function(e) { e.preventDefault(); var $this = $(this); if ( $this.hasClass("save-now") ) { $.ajax({ url: daio_script_vars.ajaxurl, type: "post", data: { action: "save_settings_with_ajax", security: daio_script_vars.nonce, fields: $("form#daio-settings").serialize() }, beforeSend: function() { $this.html( ' Saving Data... ' ); }, success: function(response) { console.log( response ); setTimeout( function() { $this.html("Save Now"); swal( "All Settings Saved!", "Click OK to continue", "success" ); saveBtn.removeClass("save-now"); }, 1000); }, error: function( response ) { console.log( response ); swal("Oops...", "Something went wrong!", "error"); } }); } else { $(this) .attr("disabled", "true") .css("cursor", "not-allowed"); } }); })(jQuery);