Няма описание

script.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. function parseHash(hash) {
  2. hash = hash.substring(1, hash.length);
  3. var hashObj = [];
  4. hash.split('&').forEach(function (q) {
  5. if (typeof q !== 'undefined') {
  6. hashObj.push(q);
  7. }
  8. });
  9. return hashObj;
  10. }
  11. var swpsmtp_urlHash = 'smtp';
  12. var swpsmtp_focusObj = false;
  13. var swpsmtp_urlHashArr = parseHash(window.location.hash);
  14. if (swpsmtp_urlHashArr[0] !== '') {
  15. swpsmtp_urlHash = swpsmtp_urlHashArr[0];
  16. }
  17. if (swpsmtp_urlHashArr[1] !== "undefined") {
  18. swpsmtp_focusObj = swpsmtp_urlHashArr[1];
  19. }
  20. jQuery(function ($) {
  21. var swpsmtp_activeTab = "";
  22. $('a.nav-tab').click(function (e) {
  23. if ($(this).attr('data-tab-name') !== swpsmtp_activeTab) {
  24. $('div.swpsmtp-tab-container[data-tab-name="' + swpsmtp_activeTab + '"]').hide();
  25. $('a.nav-tab[data-tab-name="' + swpsmtp_activeTab + '"]').removeClass('nav-tab-active');
  26. swpsmtp_activeTab = $(this).attr('data-tab-name');
  27. $('div.swpsmtp-tab-container[data-tab-name="' + swpsmtp_activeTab + '"]').show();
  28. $(this).addClass('nav-tab-active');
  29. $('input#swpsmtp-urlHash').val(swpsmtp_activeTab);
  30. if (window.location.hash !== swpsmtp_activeTab) {
  31. window.location.hash = swpsmtp_activeTab;
  32. }
  33. if (swpsmtp_focusObj) {
  34. $('html, body').animate({
  35. scrollTop: $('#' + swpsmtp_focusObj).offset().top
  36. }, 'fast', function () {
  37. $('#' + swpsmtp_focusObj).focus();
  38. swpsmtp_focusObj = false;
  39. });
  40. }
  41. }
  42. });
  43. $('a.nav-tab[data-tab-name="' + swpsmtp_urlHash + '"]').trigger('click');
  44. });
  45. jQuery(function ($) {
  46. $('#swpsmtp-mail input').not('.ignore-change').change(function () {
  47. $('#swpsmtp-save-settings-notice').show();
  48. $('#test-email-form-submit').prop('disabled', true);
  49. });
  50. $('#swpsmtp_enable_domain_check').change(function () {
  51. $('input[name="swpsmtp_allowed_domains"]').prop('disabled', !$(this).is(':checked'));
  52. $('input[name="swpsmtp_block_all_emails"]').prop('disabled', !$(this).is(':checked'));
  53. });
  54. $('#swpsmtp_clear_log_btn').click(function (e) {
  55. e.preventDefault();
  56. if (confirm(easywpsmtp.str.clear_log)) {
  57. var req = jQuery.ajax({
  58. url: ajaxurl,
  59. type: "post",
  60. data: { action: "swpsmtp_clear_log", nonce: easywpsmtp.clear_log_nonce }
  61. });
  62. req.done(function (data) {
  63. if (data === '1') {
  64. alert(easywpsmtp.str.log_cleared);
  65. } else {
  66. alert(easywpsmtp.str.error_occured + ' ' + data);
  67. }
  68. });
  69. }
  70. });
  71. $('#swpsmtp_export_settings_btn').click(function (e) {
  72. e.preventDefault();
  73. $('#swpsmtp_export_settings_frm').submit();
  74. });
  75. $('#swpsmtp_import_settings_btn').click(function (e) {
  76. e.preventDefault();
  77. $('#swpsmtp_import_settings_select_file').click();
  78. });
  79. $('#swpsmtp_import_settings_select_file').change(function (e) {
  80. e.preventDefault();
  81. $('#swpsmtp_import_settings_frm').submit();
  82. });
  83. $('#swpsmtp_self_destruct_btn').click(function (e) {
  84. e.preventDefault();
  85. if (confirm(easywpsmtp.str.confirm_self_destruct)) {
  86. var req = jQuery.ajax({
  87. url: ajaxurl,
  88. type: "post",
  89. data: { action: "swpsmtp_self_destruct", sd_code: easywpsmtp.sd_code }
  90. });
  91. req.done(function (data) {
  92. if (data === '1') {
  93. alert(easywpsmtp.str.self_destruct_completed);
  94. window.location.href = easywpsmtp.sd_redir_url;
  95. } else {
  96. alert(easywpsmtp.str.error_occured + ' ' + data);
  97. }
  98. });
  99. req.fail(function (err) {
  100. alert(easywpsmtp.str.error_occured + ' ' + err.status + ' (' + err.statusText + ')');
  101. });
  102. }
  103. });
  104. $('#test-email-form-submit').click(function () {
  105. $(this).val(easywpsmtp.str.sending);
  106. $(this).prop('disabled', true);
  107. $('#swpsmtp-spinner').addClass('is-active');
  108. $('#swpsmtp_settings_test_email_form').submit();
  109. return true;
  110. });
  111. });