Changeset 3377292
- Timestamp:
- 10/13/2025 07:55:31 AM (6 months ago)
- Location:
- yournotify/trunk
- Files:
-
- 4 edited
-
assets/js/frontend.js (modified) (8 diffs)
-
includes/class-yournotify-optin.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
-
yournotify.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
yournotify/trunk/assets/js/frontend.js
r3377287 r3377292 3 3 */ 4 4 (function ($) { 5 6 }(jQuery));7 5 function ensureNotice($form) { 8 6 var $notice = $form.find('.js-yournotify-frontend-notice'); 9 7 if (!$notice.length) { 10 8 $notice = $('<div class="js-yournotify-frontend-notice"/>'); 11 // place after submit button area12 9 var $submit = $form.find('button[type="submit"], input[type="submit"]').last(); 13 if ($submit.length) { 14 $notice.insertAfter($submit); 15 } else { 16 $form.append($notice); 17 } 10 if ($submit.length) { $notice.insertAfter($submit); } 11 else { $form.append($notice); } 18 12 } 19 13 return $notice; … … 24 18 if (submitting) { 25 19 $btn.data('yn-text', $btn.is('input,button') ? ($btn.is('input') ? $btn.val() : $btn.text()) : ''); 26 if ($btn.is('input')) $btn.val( YournotifyVars && YournotifyVars.i18n ? YournotifyVars.i18n.loading : 'Submitting…');27 else $btn.text( YournotifyVars && YournotifyVars.i18n ? YournotifyVars.i18n.loading : 'Submitting…');20 if ($btn.is('input')) $btn.val(window.YournotifyVars && YournotifyVars.i18n ? YournotifyVars.i18n.loading : 'Submitting…'); 21 else $btn.text(window.YournotifyVars && YournotifyVars.i18n ? YournotifyVars.i18n.loading : 'Submitting…'); 28 22 $btn.prop('disabled', true).addClass('is-loading'); 29 23 } else { 30 24 var original = $btn.data('yn-text'); 31 if (typeof original === 'string') { 32 if ($btn.is('input')) $btn.val(original); else $btn.text(original); 33 } 25 if (typeof original === 'string') { if ($btn.is('input')) $btn.val(original); else $btn.text(original); } 34 26 $btn.prop('disabled', false).removeClass('is-loading'); 35 27 } … … 37 29 38 30 function gatherData($form) { 39 // Support both shortcode and widget fields40 31 var name = ($form.find('input[name="name"]').val() || $form.find('.yournotify-subscribe__name-input').val() || '').trim(); 41 32 var email = ($form.find('input[name="email"]').val() || $form.find('.yournotify-subscribe__email-input').val() || '').trim(); … … 51 42 telephone: tel 52 43 }; 53 if (apiKey) data.api_key = apiKey; // server will also map to jwt44 if (apiKey) data.api_key = apiKey; 54 45 if (listId) data.list_id = listId; 55 46 return data; … … 63 54 64 55 function handleSubmit(e) { 65 e.preventDefault();56 if (e) e.preventDefault(); 66 57 var $form = $(this); 67 58 var $btn = $form.find('button[type="submit"], input[type="submit"]').first(); … … 70 61 71 62 var data = gatherData($form); 72 73 63 if (!data.email) { 74 64 renderMessage($notice, '<div class="alert alert-danger">Email is required.</div>', true); … … 87 77 var msg = (resp.data && resp.data.message) ? resp.data.message : '<div class="alert alert-success">Subscribed successfully.</div>'; 88 78 renderMessage($notice, msg, false); 89 // Do not auto-redirect; show message inline 90 try { $form[0].reset(); } catch(e){} 79 try { $form[0].reset(); } catch(err){} 91 80 } else { 92 var err = (resp && resp.data && resp.data.message) ? resp.data.message : (YournotifyVars && YournotifyVars.i18n ? YournotifyVars.i18n.generic_error : 'Something went wrong. Please try again.');93 renderMessage($notice, '<div class="alert alert-danger">'+ err +'</div>', true);81 var errMsg = (resp && resp.data && resp.data.message) ? resp.data.message : (window.YournotifyVars && YournotifyVars.i18n ? YournotifyVars.i18n.generic_error : 'Something went wrong. Please try again.'); 82 renderMessage($notice, '<div class="alert alert-danger">'+ errMsg +'</div>', true); 94 83 } 95 84 }).fail(function(){ 96 var err = ( YournotifyVars && YournotifyVars.i18n) ? YournotifyVars.i18n.generic_error : 'Something went wrong. Please try again.';85 var err = (window.YournotifyVars && YournotifyVars.i18n) ? YournotifyVars.i18n.generic_error : 'Something went wrong. Please try again.'; 97 86 renderMessage($notice, '<div class="alert alert-danger">'+ err +'</div>', true); 98 87 }).always(function(){ … … 103 92 } 104 93 94 // Submit intercept 105 95 $(document).on('submit', '.yournotify-subscribe-form', handleSubmit); 106 96 $(document).on('submit', 'form.yournotify-subscribe', handleSubmit); 97 // Guard: prevent default click submits and route to handler 98 $(document).on('click', '.yournotify-subscribe-form button[type="submit"], .yournotify-subscribe-form input[type="submit"], form.yournotify-subscribe button[type="submit"], form.yournotify-subscribe input[type="submit"]', function(e){ 99 e.preventDefault(); 100 $(this).closest('form').trigger('submit'); 101 return false; 102 }); 103 104 }(jQuery)); -
yournotify/trunk/includes/class-yournotify-optin.php
r3377287 r3377292 18 18 ], $atts, 'yournotify_subscribe'); 19 19 20 $action = admin_url('admin-ajax.php'); 20 // We'll submit via AJAX; avoid native navigation to admin-ajax.php 21 $action = ''; 21 22 $nonce = wp_create_nonce('yournotify_subscribe'); 22 23 $api_key = get_option('yournotify_api_key',''); 23 24 $list_id = get_option('yournotify_list_id',''); 24 25 25 $html = '<form method="post" action="'.esc_url($action).'" class="yournotify-subscribe-form">';26 $html = '<form method="post" action="'.esc_url($action).'" class="yournotify-subscribe-form" onsubmit="return false">'; 26 27 $html .= '<input type="hidden" name="action" value="yournotify_subscribe_submit">'; 27 28 $html .= '<input type="hidden" name="_wpnonce" value="'.esc_attr($nonce).'">'; -
yournotify/trunk/readme.txt
r3377287 r3377292 4 4 Requires at least: 4.6 5 5 Tested up to: 6.7 6 Stable tag: 2.1. 06 Stable tag: 2.1.1 7 7 License: GPLv3 or later 8 8 -
yournotify/trunk/yournotify.php
r3377287 r3377292 4 4 * Plugin URI: https://yournotify.com 5 5 * Description: Yournotify WP Plugin — Subscriber Form and SMTP override. 6 * Version: 2.1. 06 * Version: 2.1.1 7 7 * Author: Yournotify 8 8 * Author URI: https://yournotify.com
Note: See TracChangeset
for help on using the changeset viewer.