WordPress.org

Make WordPress Core

Changeset 32992


Ignore:
Timestamp:
06/28/2015 11:06:14 PM (4 years ago)
Author:
azaozz
Message:

wpLink: always attempt to correct the URL before getting the URL field value. Fixes an edge case where the URL was not corrected when the user submitted the form by pressing Enter.
Props andfinally. Fixes #32412.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/wplink.js

    r32958 r32992  
    7878            });
    7979
    80             function correctURL() {
    81                 var url = $.trim( inputs.url.val() );
    82 
    83                 if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) {
    84                     inputs.url.val( 'http://' + url );
    85                     correctedURL = url;
    86                 }
    87             }
    88 
    8980            inputs.url.on( 'paste', function() {
    90                 setTimeout( correctURL, 0 );
     81                setTimeout( wpLink.correctURL, 0 );
    9182            } );
    9283
    93             inputs.url.on( 'blur', correctURL );
     84            inputs.url.on( 'blur', wpLink.correctURL );
     85        },
     86
     87        // If URL wasn't corrected last time and doesn't start with http:, https:, ? # or /, prepend http://
     88        correctURL: function () {
     89            var url = $.trim( inputs.url.val() );
     90
     91            if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) {
     92                inputs.url.val( 'http://' + url );
     93                correctedURL = url;
     94            }
    9495        },
    9596
     
    268269
    269270        getAttrs: function() {
     271            wpLink.correctURL();
     272
    270273            return {
    271274                href: $.trim( inputs.url.val() ),
Note: See TracChangeset for help on using the changeset viewer.