From d8f819fdda733226b159478b6f9e9efd418acabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helen=20Hou-Sand=C3=AD?= Date: Mon, 29 Jul 2013 01:01:33 +0000 Subject: [PATCH] Set the default internal search value for the link dialog to be the text that is highlighted in the editor. props greuben. fixes #16276. git-svn-id: http://core.svn.wordpress.org/trunk@24841 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/wplink.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/wp-includes/js/wplink.js b/wp-includes/js/wplink.js index 232fd4e2f9..4e4cec560b 100644 --- a/wp-includes/js/wplink.js +++ b/wp-includes/js/wplink.js @@ -279,10 +279,27 @@ var wpLink; inputs.url.focus(); }, setDefaultValues : function() { + var selectedText, + textarea = wpLink.textarea; + // Set URL and description to defaults. // Leave the new tab setting as-is. inputs.url.val('http://'); inputs.title.val(''); + if ( wpLink.isMCE() ) { + selectedText = tinyMCEPopup.editor.selection.getContent( { format: 'text' } ); + } else { + if ( document.selection && wpLink.range ) { + selectedText = wpLink.range.text; + } else if ( typeof textarea.selectionStart !== 'undefined' ) { + selectedText = textarea.value.substring( textarea.selectionStart, textarea.selectionEnd ); + } + } + if ( selectedText && ( selectedText = selectedText.replace( /^\s+|\s+$/g, '' ) ) ) { + if ( ! $('#search-panel').is(':visible') ) + $('#internal-toggle').trigger('click'); + inputs.search.val( selectedText ).trigger('keyup'); + } // Update save prompt. inputs.submit.val( wpLinkL10n.save );