settings.js
50 lines
| 1 | /** |
| 2 | * Script for settings screen |
| 3 | */ |
| 4 | (function ($) { |
| 5 | |
| 6 | /** |
| 7 | * Validation |
| 8 | */ |
| 9 | $('form *[data-needs-validation]').on('input', function (ev) { |
| 10 | var $this = $(this); |
| 11 | var form = $this.closest('form'); |
| 12 | var submit = form.find('*[type=submit]'); |
| 13 | submit.attr('disabled', true); |
| 14 | |
| 15 | $.ajax(ajaxurl, { |
| 16 | method: 'post', |
| 17 | dataType: 'json', |
| 18 | data: { |
| 19 | action: 'wpmc_validate_option', |
| 20 | name: $this.attr('name'), |
| 21 | value: $this.val() |
| 22 | } |
| 23 | |
| 24 | }).always(function () { |
| 25 | submit.attr('disabled', false); |
| 26 | |
| 27 | }).done(function (response) { |
| 28 | if (response.success) { |
| 29 | $this[0].setCustomValidity(''); |
| 30 | |
| 31 | } else { // Invalid Data |
| 32 | $this[0].setCustomValidity(response.data.message); |
| 33 | } |
| 34 | }); |
| 35 | }); |
| 36 | |
| 37 | /** |
| 38 | * Scanning Method |
| 39 | */ |
| 40 | $('select#wpmc_method').on('change', function (ev) { |
| 41 | var selected = $(this).val(); |
| 42 | if (selected == 'media') { // Method = "Media Library" |
| 43 | $('input#wpmc_media_library').attr('disabled', true); |
| 44 | } else { // Method = Other Else |
| 45 | $('input#wpmc_media_library').attr('disabled', false); |
| 46 | } |
| 47 | }); |
| 48 | |
| 49 | })(jQuery); |
| 50 |