| @@ -14,14 +14,32 @@ | ||
| 14 | 14 | $(document).on('click', '.show_subscribe span:not(.is-subscribed) a', function(){ |
| 15 | 15 | $( ".show_subscribe span:not(.is-subscribed) a" ).text( "Subscribing..." ); |
| 16 | 16 | }); |
| 17 | 17 | |
| 18 | - // if has class | |
| 18 | + // Ensure the subscription success alert appears at most once. | |
| 19 | 19 | if ( $( ".show_subscribe .is-subscribed" ).length ) { |
| 20 | - $( ".post-header" ).before( '<div class="alert alert-success bbp__success-subscribe"><div class="mailIcon"><svg width="60" height="60" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path data-name="envelope-Filled" d="M10.36 11.71 3.19 6.62A4.5 4.5 0 0 1 7 4.5h10a4.5 4.5 0 0 1 3.81 2.11l-7.15 5.08a3 3 0 0 1-3.3.02ZM21.48 8.6l-6.68 4.74a5.082 5.082 0 0 1-2.81.85 4.968 4.968 0 0 1-2.76-.84L2.52 8.6c-.01.13-.02.27-.02.4v6A4.507 4.507 0 0 0 7 19.5h10a4.507 4.507 0 0 0 4.5-4.5V9c0-.13-.01-.27-.02-.4Z" style="fill:#4c52f1"/></svg></div><span>You are subscribed to this forum, and will receive emails for future topic activity.</span> <a class="bbpc-unsubscribe-link" data-forum-id='+bbpc_localize_script.bbpc_subscribed_forum_id+' href="javascript:void()">Unsubscribe</a> from '+bbpc_localize_script.bbpc_subscribed_forum_title+'</div>' ); | |
| 20 | + var $existingSuccess = $( ".bbp__success-subscribe" ); | |
| 21 | + | |
| 22 | + if ( $existingSuccess.length > 1 ) { | |
| 23 | + $existingSuccess.not( ':first' ).remove(); | |
| 24 | + } | |
| 25 | + | |
| 26 | + if ( !$( ".bbp__success-subscribe" ).length ) { | |
| 27 | + var $targetHeader = $( ".post-header" ).first(); | |
| 28 | + | |
| 29 | + if ( !$targetHeader.length ) { | |
| 30 | + $targetHeader = $( "#bbpress-forums" ).first(); | |
| 31 | + } | |
| 32 | + | |
| 33 | + if ( $targetHeader.length ) { | |
| 34 | + var successHtml = '<div class="alert alert-success bbp__success-subscribe"><div class="mailIcon"><svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path data-name="envelope-Filled" d="M10.36 11.71 3.19 6.62A4.5 4.5 0 0 1 7 4.5h10a4.5 4.5 0 0 1 3.81 2.11l-7.15 5.08a3 3 0 0 1-3.3.02ZM21.48 8.6l-6.68 4.74a5.082 5.082 0 0 1-2.81.85 4.968 4.968 0 0 1-2.76-.84L2.52 8.6c-.01.13-.02.27-.02.4v6A4.507 4.507 0 0 0 7 19.5h10a4.507 4.507 0 0 0 4.5-4.5V9c0-.13-.01-.27-.02-.4Z" style="fill:#4c52f1"/></svg></div><div class="bbp__success-subscribe-content"><p class="bbp__success-subscribe-text">You are subscribed to this forum, and will receive emails for future topic activity.</p><p class="bbp__success-subscribe-action"><a class="bbpc-unsubscribe-link" data-forum-id='+forumax_localize_script.bbpc_subscribed_forum_id+' href="javascript:void()">Unsubscribe</a> from '+forumax_localize_script.bbpc_subscribed_forum_title+'</p></div></div>'; | |
| 35 | + $targetHeader.before( successHtml ); | |
| 36 | + } | |
| 37 | + } | |
| 21 | 38 | } |
| 22 | - | |
| 23 | - $('.bbpc-unsubscribe-link').click(function(){ | |
| 39 | + | |
| 40 | + $(document).on('click', '.bbpc-unsubscribe-link', function(e){ | |
| 41 | + e.preventDefault(); | |
| 24 | 42 | let data_id = $(this).attr('data-forum-id'); |
| 25 | 43 | $('#subscribe-'+data_id+' a').click().text( "Unsubscribing..." ); |
| 26 | 44 | $(this).text( "Unsubscribing..." ); |
| 27 | 45 | }); |