- setDefaultValues: function() {
- // Set URL and description to defaults.
- // Leave the new tab setting as-is.
- inputs.url.val( 'http://' );
- inputs.title.val( '' );
+ getUrlFromSelection: function( selection ) {
+ if ( ! selection ) {
+ if ( this.isMCE() ) {
+ selection = editor.selection.getContent({ format: 'text' });
+ } else if ( document.selection && wpLink.range ) {
+ selection = wpLink.range.text;
+ } else if ( typeof this.textarea.selectionStart !== 'undefined' ) {
+ selection = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd );
+ }
+ }
+
+ selection = $.trim( selection );
+
+ if ( selection && emailRegexp.test( selection ) ) {
+ // Selection is email address
+ return 'mailto:' + selection;
+ } else if ( selection && urlRegexp.test( selection ) ) {
+ // Selection is URL
+ return selection.replace( /&|�?38;/gi, '&' );
+ }
+
+ return '';
+ },
+
+ setDefaultValues: function( selection ) {
+ inputs.url.val( this.getUrlFromSelection( selection ) );
+
+ // Empty the search field and swap the "rivers".
+ inputs.search.val('');
+ wpLink.searchInternalLinks();