Making WordPress.org

Changeset 9602


Ignore:
Timestamp:
03/18/2020 04:31:40 AM (5 years ago)
Author:
dd32
Message:

Support Forums: Confirm before leaving a page when a reply/thread has been started but not submitted.

Props denisco.
Fixes #155.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/functions.php

    r9601 r9602  
    2424
    2525    wp_enqueue_script( 'wporg-support-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20181209', true );
    26     wp_enqueue_script( 'wporg-support-forums', get_template_directory_uri() . '/js/forums.js', array( 'jquery' ), '20180801', true );
     26    wp_enqueue_script( 'wporg-support-forums', get_template_directory_uri() . '/js/forums.js', array( 'jquery' ), '20200318', true );
    2727}
    2828add_action( 'wp_enqueue_scripts', 'wporg_support_scripts' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/js/forums.js

    r7519 r9602  
    11( function( $ ) {
     2    if ( $( '#new-post' ).length ) {
     3        var requireConfirmClose = false;
    24
    3     $( '#new-post' ).submit(function() {
    4         $( '[type="submit"]', $(this) ).prop( 'disabled', 'disabled' );
    5     });
     5        $( '#new-post' ).submit( function() {
     6            $( '[type="submit"]', $( this ) ).prop( 'disabled', 'disabled' );
    67
    7 } )( window.jQuery );
     8            requireConfirmClose = false;
     9        } );
     10
     11        $( '#new-post' ).one( 'input', 'input[type=text], textarea', function() {
     12            requireConfirmClose = true;
     13        } );
     14
     15        window.addEventListener( 'beforeunload', function( e ) {
     16            if ( requireConfirmClose ) {
     17                e.preventDefault();
     18
     19                // Chrome requires returnValue to be set.
     20                e.returnValue = '';
     21            }
     22        } );
     23    }
     24}( window.jQuery ) );
Note: See TracChangeset for help on using the changeset viewer.