Make WordPress Core

Changeset 31602


Ignore:
Timestamp:
03/03/2015 12:00:42 AM (12 years ago)
Author:
azaozz
Message:

wpLink:

  • Prepend '​http://' to pasted URLs.
  • Do not prepend it when typing an URL.
  • Do not prepend it when pasting the same URL for the second time (trying to correct wrong guess).

Props iseulde. Fixes #18149.

File:
1 edited

Legend:

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

    r30707 r31602  
    33
    44( function( $ ) {
    5         var editor, searchTimer, River, Query,
     5        var editor, searchTimer, River, Query, correctedURL,
    66                inputs = {},
    77                rivers = {},
    … …  
    7373                                }, 500 );
    7474                        });
     75
     76                        inputs.url.on( 'paste blur', function() {
     77                                setTimeout( function() {
     78                                        var url = $.trim( inputs.url.val() );
     79
     80                                        if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) {
     81                                                inputs.url.val( 'http://' + url );
     82                                                correctedURL = url;
     83                                        }
     84                                }, 0 );
     85                        } );
    7586                },
    7687
    … …  
    184195                        inputs.backdrop.hide();
    185196                        inputs.wrap.hide();
     197
     198                        correctedURL = false;
     199
    186200                        $( document ).trigger( 'wplink-close', inputs.wrap );
    187201                },
    … …  
    212226
    213227                        // If there's no href, return.
    214                         if ( ! attrs.href || attrs.href == 'http://' )
     228                        if ( ! attrs.href )
    215229                                return;
    216230
    … …  
    310324                        } else {
    311325                                // Set URL to default.
    312                                 inputs.url.val( 'http://' );
     326                                inputs.url.val( '' );
    313327                        }
    314328
Note: See TracChangeset for help on using the changeset viewer.