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
This commit is contained in:
parent
339a365bb3
commit
b75ee2198f
|
@ -160,7 +160,7 @@ var wpLink;
|
||||||
},
|
},
|
||||||
|
|
||||||
htmlUpdate : function() {
|
htmlUpdate : function() {
|
||||||
var attrs, html, start, end, cursor,
|
var attrs, html, begin, end, cursor,
|
||||||
textarea = wpLink.textarea;
|
textarea = wpLink.textarea;
|
||||||
|
|
||||||
if ( ! textarea )
|
if ( ! textarea )
|
||||||
|
@ -183,35 +183,34 @@ var wpLink;
|
||||||
html += '>';
|
html += '>';
|
||||||
|
|
||||||
// Insert HTML
|
// Insert HTML
|
||||||
// W3C
|
if ( document.selection && wpLink.range ) {
|
||||||
if ( typeof textarea.selectionStart !== 'undefined' ) {
|
// IE
|
||||||
start = textarea.selectionStart;
|
// Note: If no text is selected, IE will not place the cursor
|
||||||
end = textarea.selectionEnd;
|
// inside the closing tag.
|
||||||
selection = textarea.value.substring( start, end );
|
|
||||||
html = html + selection + '</a>';
|
|
||||||
cursor = start + html.length;
|
|
||||||
|
|
||||||
// If no next is selected, place the cursor inside the closing tag.
|
|
||||||
if ( start == end )
|
|
||||||
cursor -= '</a>'.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 ) {
|
|
||||||
textarea.focus();
|
textarea.focus();
|
||||||
wpLink.range.text = html + wpLink.range.text + '</a>';
|
wpLink.range.text = html + wpLink.range.text + '</a>';
|
||||||
wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
|
wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
|
||||||
wpLink.range.select();
|
wpLink.range.select();
|
||||||
|
|
||||||
wpLink.range = null;
|
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 + '</a>';
|
||||||
|
cursor = begin + html.length;
|
||||||
|
|
||||||
|
// If no next is selected, place the cursor inside the closing tag.
|
||||||
|
if ( begin == end )
|
||||||
|
cursor -= '</a>'.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();
|
wpLink.close();
|
||||||
|
|
Loading…
Reference in New Issue