From b75ee2198f15cf9b7a2e010b16c4636b3eea35f8 Mon Sep 17 00:00:00 2001 From: azaozz Date: Wed, 11 Apr 2012 00:20:42 +0000 Subject: [PATCH] Fix inserting links in the HTML editor in IE9, fixes #19528 git-svn-id: http://svn.automattic.com/wordpress/trunk@20428 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/wplink.dev.js | 47 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/wp-includes/js/wplink.dev.js b/wp-includes/js/wplink.dev.js index 7a186d4d7..d0c4b9a0a 100644 --- a/wp-includes/js/wplink.dev.js +++ b/wp-includes/js/wplink.dev.js @@ -160,7 +160,7 @@ var wpLink; }, htmlUpdate : function() { - var attrs, html, start, end, cursor, + var attrs, html, begin, end, cursor, textarea = wpLink.textarea; if ( ! textarea ) @@ -183,35 +183,34 @@ var wpLink; html += '>'; // Insert HTML - // W3C - if ( typeof textarea.selectionStart !== 'undefined' ) { - start = textarea.selectionStart; - end = textarea.selectionEnd; - selection = textarea.value.substring( start, end ); - html = html + selection + ''; - cursor = start + html.length; - - // If no next is selected, place the cursor inside the closing tag. - if ( start == end ) - cursor -= ''.length; - - textarea.value = textarea.value.substring( 0, start ) - + html - + textarea.value.substring( end, textarea.value.length ); - - // Update cursor position - textarea.selectionStart = textarea.selectionEnd = cursor; - - // IE - // Note: If no text is selected, IE will not place the cursor - // inside the closing tag. - } else if ( document.selection && wpLink.range ) { + if ( document.selection && wpLink.range ) { + // IE + // Note: If no text is selected, IE will not place the cursor + // inside the closing tag. textarea.focus(); wpLink.range.text = html + wpLink.range.text + ''; wpLink.range.moveToBookmark( wpLink.range.getBookmark() ); wpLink.range.select(); wpLink.range = null; + } else if ( typeof textarea.selectionStart !== 'undefined' ) { + // W3C + begin = textarea.selectionStart; + end = textarea.selectionEnd; + selection = textarea.value.substring( begin, end ); + html = html + selection + ''; + cursor = begin + html.length; + + // If no next is selected, place the cursor inside the closing tag. + if ( begin == end ) + cursor -= ''.length; + + textarea.value = textarea.value.substring( 0, begin ) + + html + + textarea.value.substring( end, textarea.value.length ); + + // Update cursor position + textarea.selectionStart = textarea.selectionEnd = cursor; } wpLink.close();