- setDefaultValues : function() {
- // Set URL and description to defaults.
- // Leave the new tab setting as-is.
- inputs.url.val('http://');
- inputs.title.val('');
+
+ setDefaultValues: function() {
+ var selection,
+ emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
+ urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;
+
+ if ( this.isMCE() ) {
+ selection = editor.selection.getContent();
+ } 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 );
+ }
+
+ if ( selection && emailRegexp.test( selection ) ) {
+ // Selection is email address
+ inputs.url.val( 'mailto:' + selection );
+ } else if ( selection && urlRegexp.test( selection ) ) {
+ // Selection is URL
+ inputs.url.val( selection.replace( /&|�?38;/gi, '&' ) );
+ } else {
+ // Set URL to default.
+ inputs.url.val( '' );
+ }