(function ($) { 'use strict'; /** * Global doc.ready function */ $(document).ready(function () { $('.amp-settings-form').submit(function (e) { e.preventDefault(); $.post(amp_data.wp_post, $(this).serialize(), function (d) { reloadAMPSSettingsMobileScreen(); UIkit.notify(" Your settings have been saved.", {pos: 'bottom-right', status: "success"}); }); }); // Set the selected option of selects $('select').each(function () { var attr = $(this).attr('data-value'); if (typeof attr !== typeof undefined && attr !== false && attr !== '') { $(this).val(attr); } }); $('#register_for_amp').submit(function () { var result = false; var email = $.trim($('#register_aamp_email').val()); var name = $.trim($('#register_aamp_name').val()); if (name == '') { $('.register_aamp_container .uk-alert.form-notices').removeClass('uk-alert-success').addClass('uk-alert-danger').text('Name is required!').slideDown(); return false; } if (email == '') { $('.register_aamp_container .uk-alert.form-notices').removeClass('uk-alert-success').addClass('uk-alert-danger').text('Email Address Invalid').slideDown(); return false; } var data = {action: 'register_advanced_amp', email: email}; jQuery.post(amp_data.wp_get, data, function (response) { response = JSON.parse(response); if (response.status === true) { return true; } else if (response.status === false) { return false; } }); }); // Header Color Picker $('.spectrum').each(function () { var element = $(this); var value = element.val(); element.spectrum({ preferredFormat: "hex", showInput: true, showAlpha: true, color: value, change: function (color) { $.post(amp_data.wp_post, $('.amp-settings-form').serialize(), function (d) { reloadAMPSSettingsMobileScreen(); UIkit.notify(" Your settings have been saved.", {pos: 'bottom-right', status: "success"}); }); } }); }); // Select Images $('.imageSelect').click(function (e) { e.preventDefault(); var target = $(this).data('target'); var image = wp.media({ title: 'Select Image', multiple: false }).open() .on('select', function (e) { // This will return the selected image from the Media Uploader, the result is an object var uploaded_image = image.state().get('selection').first(); // We convert uploaded_image to a JSON object to make accessing it easier // Output to the console uploaded_image var image_url = uploaded_image.toJSON().url; // Let's assign the url value to the input field $('#' + target).val(image_url); }); }); $('#non_secure_content_checkbox').click(function () { if ($(this).is(':checked')) { $('.yes-options').slideDown('slow'); $('.options_to_deal_with_non_secure_content').prop('disabled', false); } else { $('.yes-options').slideUp('slow'); $('.options_to_deal_with_non_secure_content').prop('disabled', true); } }); jQuery('#on_facebook').click(function () { var thisChecked = jQuery(this).is(':checked'); var inputElem = jQuery('#on_facebook_app_id'); if (thisChecked) { inputElem.slideDown('slow'); } else { inputElem.slideUp('slow'); } }); $('body').on('click', '#disable_menu_display', function () { if ($(this).is(':checked')) { $('#select_amp_menu_block').slideUp(); } else { $('#select_amp_menu').val('default'); $('#select_amp_menu_block').slideDown(); } }); $('body').on('click', '#disable_recent_posts', function () { if ($(this).is(':checked')) { $('#relevancy_basis').slideUp(); } else { $('#relevancy_basis').slideDown(); } }); // Run Mobile Test $('.uk-button-run-test').click(function () { var button = $(this); button.attr('disabled', 'disabled'); button.find('i').removeClass('fa-play').addClass('fa-spin').addClass('fa-refresh'); var website = $('#mobile-test-url').val(); if (website == "") { UIkit.notify(" URL cannot be empty!", {pos: 'bottom-right', status: "error"}); button.removeAttr('disabled'); button.find('i').addClass('fa-play').removeClass('fa-spin').removeClass('fa-refresh'); return null; } var data = [{ name: 'action', value: 'amp_mobile_test' }, { name: 'website', value: website }]; $.post(amp_data.wp_post, data, function (d) { button.removeAttr('disabled'); button.find('i').addClass('fa-play').removeClass('fa-spin').removeClass('fa-refresh'); if (d.hasOwnProperty('status')) { if (d.status == 'ERROR') { UIkit.notify(" " + d.message, { pos: 'bottom-right', status: "error" }); } } else { d = JSON.parse(d); if (d.hasOwnProperty('responseCode')) { if (d.responseCode == 200) { // Give the link to screenshot button $('.mobile-screenshot-button').attr('href', website); // Apply the logic here var container = $('.mobile-results'); // Apply the Passed/Not Passed Status container.find('.mobile-status').removeClass('uk-text-danger').removeClass('uk-text-success'); if (d.ruleGroups.USABILITY.pass == true) { container.find('.mobile-status').addClass('uk-text-success').html(' Your URL has passed the Mobile Friendly Test!'); } else { container.find('.mobile-status').addClass('uk-text-danger').html(' Your URL did not pass the Mobile Friendly Test!'); } // Apply the progress bar changes container.find('.uk-progress-bar').css('width', d.ruleGroups.USABILITY.score + '%').html('Score: ' + d.ruleGroups.USABILITY.score + ' of 100'); // Show the problems if any var problems = $('.mobile-problems'); var problem_list = $('.mobile-problems-list'); if (d.ruleGroups.USABILITY.score < 100) { problems.slideDown(); problem_list.empty(); problem_list.append('