mirror of
https://github.com/phpbb/phpbb.git
synced 2025-01-18 06:38:43 +01:00
[ticket/8996] Revert initial fix to keep old behaviour on empty selection
Revert "[ticket/8996] Also fix the BBCode bug in subsilver2 and acp" This reverts commit eb1f15bc8b7b7a284b25b2c9b9942714b6848ebc. PHPBB3-8996
This commit is contained in:
parent
e596d2ca7e
commit
730d2d5d19
@ -28,8 +28,8 @@ function helpline(help)
|
||||
/**
|
||||
* Fix a bug involving the TextRange object. From
|
||||
* http://www.frostjedi.com/terra/scripts/demo/caretBug.html
|
||||
*/
|
||||
function initInsertions()
|
||||
*/
|
||||
function initInsertions()
|
||||
{
|
||||
var doc;
|
||||
if(document.forms[form_name])
|
||||
@ -66,7 +66,7 @@ function bbstyle(bbnumber)
|
||||
else
|
||||
{
|
||||
insert_text('[*]');
|
||||
document.forms[form_name].elements[text_name].focus();
|
||||
document.forms[form_name].elements[text_name].focus();
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ function bbstyle(bbnumber)
|
||||
function bbfontstyle(bbopen, bbclose)
|
||||
{
|
||||
theSelection = false;
|
||||
|
||||
|
||||
var textarea = document.forms[form_name].elements[text_name];
|
||||
|
||||
textarea.focus();
|
||||
@ -84,10 +84,14 @@ function bbfontstyle(bbopen, bbclose)
|
||||
if ((clientVer >= 4) && is_ie && is_win)
|
||||
{
|
||||
// Get text selection
|
||||
if (textarea.createTextRange && textarea.caretPos)
|
||||
theSelection = document.selection.createRange().text;
|
||||
|
||||
if (theSelection)
|
||||
{
|
||||
textarea.caretPos.text = bbopen + textarea.caretPos.text + bbclose;
|
||||
textarea.focus();
|
||||
// Add tags around selection
|
||||
document.selection.createRange().text = bbopen + theSelection + bbclose;
|
||||
document.forms[form_name].elements[text_name].focus();
|
||||
theSelection = '';
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -98,10 +102,10 @@ function bbfontstyle(bbopen, bbclose)
|
||||
theSelection = '';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//The new position for the cursor after adding the bbcode
|
||||
var caret_pos = getCaretPosition(textarea).start;
|
||||
var new_pos = caret_pos + bbopen.length;
|
||||
var new_pos = caret_pos + bbopen.length;
|
||||
|
||||
// Open tag
|
||||
insert_text(bbopen + bbclose);
|
||||
@ -112,12 +116,12 @@ function bbfontstyle(bbopen, bbclose)
|
||||
{
|
||||
textarea.selectionStart = new_pos;
|
||||
textarea.selectionEnd = new_pos;
|
||||
}
|
||||
}
|
||||
// IE
|
||||
else if (document.selection)
|
||||
{
|
||||
var range = textarea.createTextRange();
|
||||
range.move("character", bbopen.length);
|
||||
var range = textarea.createTextRange();
|
||||
range.move("character", new_pos);
|
||||
range.select();
|
||||
storeCaret(textarea);
|
||||
}
|
||||
@ -132,7 +136,7 @@ function bbfontstyle(bbopen, bbclose)
|
||||
function insert_text(text, spaces, popup)
|
||||
{
|
||||
var textarea;
|
||||
|
||||
|
||||
if (!popup)
|
||||
{
|
||||
textarea = document.forms[form_name].elements[text_name];
|
||||
@ -155,18 +159,18 @@ function insert_text(text, spaces, popup)
|
||||
mozWrap(textarea, text, '');
|
||||
textarea.selectionStart = sel_start + text.length;
|
||||
textarea.selectionEnd = sel_end + text.length;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else if (textarea.createTextRange && textarea.caretPos)
|
||||
{
|
||||
if (baseHeight != textarea.caretPos.boundingHeight)
|
||||
if (baseHeight != textarea.caretPos.boundingHeight)
|
||||
{
|
||||
textarea.focus();
|
||||
storeCaret(textarea);
|
||||
}
|
||||
var caret_pos = textarea.caretPos;
|
||||
caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -229,7 +233,7 @@ function addquote(post_id, username)
|
||||
theSelection = theSelection.replace(/<br\/>/ig, '\n');
|
||||
theSelection = theSelection.replace(/<\;/ig, '<');
|
||||
theSelection = theSelection.replace(/>\;/ig, '>');
|
||||
theSelection = theSelection.replace(/&\;/ig, '&');
|
||||
theSelection = theSelection.replace(/&\;/ig, '&');
|
||||
theSelection = theSelection.replace(/ \;/ig, ' ');
|
||||
}
|
||||
else if (document.all)
|
||||
@ -264,7 +268,7 @@ function mozWrap(txtarea, open, close)
|
||||
var selEnd = txtarea.selectionEnd;
|
||||
var scrollTop = txtarea.scrollTop;
|
||||
|
||||
if (selEnd == 1 || selEnd == 2)
|
||||
if (selEnd == 1 || selEnd == 2)
|
||||
{
|
||||
selEnd = selLength;
|
||||
}
|
||||
@ -288,17 +292,7 @@ function mozWrap(txtarea, open, close)
|
||||
*/
|
||||
function storeCaret(textEl)
|
||||
{
|
||||
var keyCode = false;
|
||||
if (is_ie)
|
||||
{
|
||||
keyCode = (event.keyCode) ? event.keyCode : event.charCode;
|
||||
}
|
||||
|
||||
// Did the user press Shift (16), Ctrl (17) or Alt (18)?
|
||||
// If so, we do not update the caretPos, so BBCodes can still be applied correctly.
|
||||
var is_control_key = (keyCode == 16 || keyCode == 17 || keyCode == 18);
|
||||
|
||||
if ((!is_ie || !is_control_key) && (textEl.createTextRange))
|
||||
if (textEl.createTextRange)
|
||||
{
|
||||
textEl.caretPos = document.selection.createRange().duplicate();
|
||||
}
|
||||
@ -334,7 +328,7 @@ function colorPalette(dir, width, height)
|
||||
{
|
||||
document.writeln('<tr>');
|
||||
}
|
||||
|
||||
|
||||
for (b = 0; b < 5; b++)
|
||||
{
|
||||
color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
|
||||
@ -374,9 +368,9 @@ function caretPosition()
|
||||
function getCaretPosition(txtarea)
|
||||
{
|
||||
var caretPos = new caretPosition();
|
||||
|
||||
|
||||
// simple Gecko/Opera way
|
||||
if (!is_ie && (txtarea.selectionStart || txtarea.selectionStart == 0))
|
||||
if (txtarea.selectionStart || txtarea.selectionStart == 0)
|
||||
{
|
||||
caretPos.start = txtarea.selectionStart;
|
||||
caretPos.end = txtarea.selectionEnd;
|
||||
@ -390,19 +384,19 @@ function getCaretPosition(txtarea)
|
||||
// a new selection of the whole textarea
|
||||
var range_all = document.body.createTextRange();
|
||||
range_all.moveToElementText(txtarea);
|
||||
|
||||
|
||||
// calculate selection start point by moving beginning of range_all to beginning of range
|
||||
var sel_start;
|
||||
for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++)
|
||||
{
|
||||
range_all.moveStart('character', 1);
|
||||
}
|
||||
|
||||
|
||||
txtarea.sel_start = sel_start;
|
||||
|
||||
|
||||
// we ignore the end value for IE, this is already dirty enough and we don't need it
|
||||
caretPos.start = txtarea.sel_start;
|
||||
caretPos.end = txtarea.sel_start;
|
||||
caretPos.end = txtarea.sel_start;
|
||||
}
|
||||
|
||||
return caretPos;
|
||||
|
@ -28,8 +28,8 @@ function helpline(help)
|
||||
/**
|
||||
* Fix a bug involving the TextRange object. From
|
||||
* http://www.frostjedi.com/terra/scripts/demo/caretBug.html
|
||||
*/
|
||||
function initInsertions()
|
||||
*/
|
||||
function initInsertions()
|
||||
{
|
||||
var doc;
|
||||
|
||||
@ -37,7 +37,7 @@ function initInsertions()
|
||||
{
|
||||
doc = document;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
doc = opener.document;
|
||||
}
|
||||
@ -60,12 +60,12 @@ function initInsertions()
|
||||
* bbstyle
|
||||
*/
|
||||
function bbstyle(bbnumber)
|
||||
{
|
||||
{
|
||||
if (bbnumber != -1)
|
||||
{
|
||||
bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]);
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
insert_text('[*]');
|
||||
document.forms[form_name].elements[text_name].focus();
|
||||
@ -86,10 +86,10 @@ function bbfontstyle(bbopen, bbclose)
|
||||
if ((clientVer >= 4) && is_ie && is_win)
|
||||
{
|
||||
// Get text selection
|
||||
textarea = document.forms[form_name].elements[text_name];
|
||||
if (textarea.createTextRange && textarea.caretPos)
|
||||
{
|
||||
textarea.caretPos.text = bbopen + textarea.caretPos.text + bbclose;
|
||||
textarea.focus();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -100,7 +100,7 @@ function bbfontstyle(bbopen, bbclose)
|
||||
theSelection = '';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//The new position for the cursor after adding the bbcode
|
||||
var caret_pos = getCaretPosition(textarea).start;
|
||||
var new_pos = caret_pos + bbopen.length;
|
||||
@ -114,12 +114,12 @@ function bbfontstyle(bbopen, bbclose)
|
||||
{
|
||||
textarea.selectionStart = new_pos;
|
||||
textarea.selectionEnd = new_pos;
|
||||
}
|
||||
}
|
||||
// IE
|
||||
else if (document.selection)
|
||||
{
|
||||
var range = textarea.createTextRange();
|
||||
range.move("character", new_pos);
|
||||
var range = textarea.createTextRange();
|
||||
range.move("character", new_pos);
|
||||
range.select();
|
||||
storeCaret(textarea);
|
||||
}
|
||||
@ -134,16 +134,16 @@ function bbfontstyle(bbopen, bbclose)
|
||||
function insert_text(text, spaces, popup)
|
||||
{
|
||||
var textarea;
|
||||
|
||||
if (!popup)
|
||||
|
||||
if (!popup)
|
||||
{
|
||||
textarea = document.forms[form_name].elements[text_name];
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
textarea = opener.document.forms[form_name].elements[text_name];
|
||||
}
|
||||
if (spaces)
|
||||
if (spaces)
|
||||
{
|
||||
text = ' ' + text + ' ';
|
||||
}
|
||||
@ -161,7 +161,7 @@ function insert_text(text, spaces, popup)
|
||||
}
|
||||
else if (textarea.createTextRange && textarea.caretPos)
|
||||
{
|
||||
if (baseHeight != textarea.caretPos.boundingHeight)
|
||||
if (baseHeight != textarea.caretPos.boundingHeight)
|
||||
{
|
||||
textarea.focus();
|
||||
storeCaret(textarea);
|
||||
@ -174,7 +174,7 @@ function insert_text(text, spaces, popup)
|
||||
{
|
||||
textarea.value = textarea.value + text;
|
||||
}
|
||||
if (!popup)
|
||||
if (!popup)
|
||||
{
|
||||
textarea.focus();
|
||||
}
|
||||
@ -291,7 +291,7 @@ function split_lines(text)
|
||||
do
|
||||
{
|
||||
var splitAt = line.indexOf(' ', 80);
|
||||
|
||||
|
||||
if (splitAt == -1)
|
||||
{
|
||||
splitLines[j] = line;
|
||||
@ -319,7 +319,7 @@ function mozWrap(txtarea, open, close)
|
||||
var selEnd = txtarea.selectionEnd;
|
||||
var scrollTop = txtarea.scrollTop;
|
||||
|
||||
if (selEnd == 1 || selEnd == 2)
|
||||
if (selEnd == 1 || selEnd == 2)
|
||||
{
|
||||
selEnd = selLength;
|
||||
}
|
||||
@ -351,9 +351,7 @@ function storeCaret(textEl)
|
||||
|
||||
// Did the user press Shift (16), Ctrl (17) or Alt (18)?
|
||||
// If so, we do not update the caretPos, so BBCodes can still be applied correctly.
|
||||
var is_control_key = (keyCode == 16 || keyCode == 17 || keyCode == 18);
|
||||
|
||||
if ((!is_ie || !is_control_key) && (textEl.createTextRange))
|
||||
if ((!is_ie || (keyCode != 16 && keyCode != 17 && keyCode != 18)) && (textEl.createTextRange))
|
||||
{
|
||||
textEl.caretPos = document.selection.createRange().duplicate();
|
||||
}
|
||||
@ -389,7 +387,7 @@ function colorPalette(dir, width, height)
|
||||
{
|
||||
document.writeln('<tr>');
|
||||
}
|
||||
|
||||
|
||||
for (b = 0; b < 5; b++)
|
||||
{
|
||||
color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
|
||||
@ -429,32 +427,33 @@ function caretPosition()
|
||||
function getCaretPosition(txtarea)
|
||||
{
|
||||
var caretPos = new caretPosition();
|
||||
|
||||
|
||||
// simple Gecko/Opera way
|
||||
if (!is_ie && (txtarea.selectionStart || txtarea.selectionStart == 0))
|
||||
if(!is_ie && (txtarea.selectionStart || txtarea.selectionStart == 0))
|
||||
{
|
||||
caretPos.start = txtarea.selectionStart;
|
||||
caretPos.end = txtarea.selectionEnd;
|
||||
}
|
||||
// dirty and slow IE way
|
||||
else if (document.selection)
|
||||
else if(document.selection)
|
||||
{
|
||||
|
||||
// get current selection
|
||||
var range = document.selection.createRange();
|
||||
|
||||
// a new selection of the whole textarea
|
||||
var range_all = document.body.createTextRange();
|
||||
range_all.moveToElementText(txtarea);
|
||||
|
||||
|
||||
// calculate selection start point by moving beginning of range_all to beginning of range
|
||||
var sel_start;
|
||||
for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++)
|
||||
{
|
||||
{
|
||||
range_all.moveStart('character', 1);
|
||||
}
|
||||
|
||||
|
||||
txtarea.sel_start = sel_start;
|
||||
|
||||
|
||||
// we ignore the end value for IE, this is already dirty enough and we don't need it
|
||||
caretPos.start = txtarea.sel_start;
|
||||
caretPos.end = txtarea.sel_start;
|
||||
|
@ -6,8 +6,8 @@
|
||||
// Startup variables
|
||||
var imageTag = false;
|
||||
var theSelection = false;
|
||||
|
||||
var bbcodeEnabled = true;
|
||||
|
||||
// Check for Browser & Platform for PC & IE specific bits
|
||||
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
|
||||
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
|
||||
@ -15,6 +15,7 @@ var clientVer = parseInt(navigator.appVersion); // Get browser version
|
||||
|
||||
var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1));
|
||||
var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1));
|
||||
|
||||
var baseHeight;
|
||||
|
||||
/**
|
||||
@ -28,8 +29,8 @@ function helpline(help)
|
||||
/**
|
||||
* Fix a bug involving the TextRange object. From
|
||||
* http://www.frostjedi.com/terra/scripts/demo/caretBug.html
|
||||
*/
|
||||
function initInsertions()
|
||||
*/
|
||||
function initInsertions()
|
||||
{
|
||||
var doc;
|
||||
|
||||
@ -37,15 +38,14 @@ function initInsertions()
|
||||
{
|
||||
doc = document;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
doc = opener.document;
|
||||
}
|
||||
|
||||
var textarea = doc.forms[form_name].elements[text_name];
|
||||
|
||||
if (is_ie && typeof(baseHeight) != 'number')
|
||||
{
|
||||
{
|
||||
textarea.focus();
|
||||
baseHeight = doc.selection.createRange().duplicate().boundingHeight;
|
||||
|
||||
@ -60,12 +60,12 @@ function initInsertions()
|
||||
* bbstyle
|
||||
*/
|
||||
function bbstyle(bbnumber)
|
||||
{
|
||||
{
|
||||
if (bbnumber != -1)
|
||||
{
|
||||
bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]);
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
insert_text('[*]');
|
||||
document.forms[form_name].elements[text_name].focus();
|
||||
@ -78,7 +78,7 @@ function bbstyle(bbnumber)
|
||||
function bbfontstyle(bbopen, bbclose)
|
||||
{
|
||||
theSelection = false;
|
||||
|
||||
|
||||
var textarea = document.forms[form_name].elements[text_name];
|
||||
|
||||
textarea.focus();
|
||||
@ -86,10 +86,14 @@ function bbfontstyle(bbopen, bbclose)
|
||||
if ((clientVer >= 4) && is_ie && is_win)
|
||||
{
|
||||
// Get text selection
|
||||
if (textarea.createTextRange && textarea.caretPos)
|
||||
theSelection = document.selection.createRange().text;
|
||||
|
||||
if (theSelection)
|
||||
{
|
||||
textarea.caretPos.text = bbopen + textarea.caretPos.text + bbclose;
|
||||
textarea.focus();
|
||||
// Add tags around selection
|
||||
document.selection.createRange().text = bbopen + theSelection + bbclose;
|
||||
document.forms[form_name].elements[text_name].focus();
|
||||
theSelection = '';
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -100,7 +104,7 @@ function bbfontstyle(bbopen, bbclose)
|
||||
theSelection = '';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//The new position for the cursor after adding the bbcode
|
||||
var caret_pos = getCaretPosition(textarea).start;
|
||||
var new_pos = caret_pos + bbopen.length;
|
||||
@ -114,12 +118,12 @@ function bbfontstyle(bbopen, bbclose)
|
||||
{
|
||||
textarea.selectionStart = new_pos;
|
||||
textarea.selectionEnd = new_pos;
|
||||
}
|
||||
}
|
||||
// IE
|
||||
else if (document.selection)
|
||||
{
|
||||
var range = textarea.createTextRange();
|
||||
range.move("character", new_pos);
|
||||
var range = textarea.createTextRange();
|
||||
range.move("character", new_pos);
|
||||
range.select();
|
||||
storeCaret(textarea);
|
||||
}
|
||||
@ -134,16 +138,16 @@ function bbfontstyle(bbopen, bbclose)
|
||||
function insert_text(text, spaces, popup)
|
||||
{
|
||||
var textarea;
|
||||
|
||||
if (!popup)
|
||||
|
||||
if (!popup)
|
||||
{
|
||||
textarea = document.forms[form_name].elements[text_name];
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
textarea = opener.document.forms[form_name].elements[text_name];
|
||||
}
|
||||
if (spaces)
|
||||
if (spaces)
|
||||
{
|
||||
text = ' ' + text + ' ';
|
||||
}
|
||||
@ -158,26 +162,28 @@ function insert_text(text, spaces, popup)
|
||||
mozWrap(textarea, text, '');
|
||||
textarea.selectionStart = sel_start + text.length;
|
||||
textarea.selectionEnd = sel_end + text.length;
|
||||
}
|
||||
}
|
||||
|
||||
else if (textarea.createTextRange && textarea.caretPos)
|
||||
{
|
||||
if (baseHeight != textarea.caretPos.boundingHeight)
|
||||
if (baseHeight != textarea.caretPos.boundingHeight)
|
||||
{
|
||||
textarea.focus();
|
||||
storeCaret(textarea);
|
||||
}
|
||||
|
||||
}
|
||||
var caret_pos = textarea.caretPos;
|
||||
caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
textarea.value = textarea.value + text;
|
||||
}
|
||||
if (!popup)
|
||||
if (!popup)
|
||||
{
|
||||
textarea.focus();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -273,6 +279,7 @@ function addquote(post_id, username, l_wrote)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
function split_lines(text)
|
||||
{
|
||||
var lines = text.split('\n');
|
||||
@ -291,7 +298,7 @@ function split_lines(text)
|
||||
do
|
||||
{
|
||||
var splitAt = line.indexOf(' ', 80);
|
||||
|
||||
|
||||
if (splitAt == -1)
|
||||
{
|
||||
splitLines[j] = line;
|
||||
@ -309,6 +316,7 @@ function split_lines(text)
|
||||
}
|
||||
return splitLines;
|
||||
}
|
||||
|
||||
/**
|
||||
* From http://www.massless.org/mozedit/
|
||||
*/
|
||||
@ -319,7 +327,7 @@ function mozWrap(txtarea, open, close)
|
||||
var selEnd = txtarea.selectionEnd;
|
||||
var scrollTop = txtarea.scrollTop;
|
||||
|
||||
if (selEnd == 1 || selEnd == 2)
|
||||
if (selEnd == 1 || selEnd == 2)
|
||||
{
|
||||
selEnd = selLength;
|
||||
}
|
||||
@ -343,17 +351,7 @@ function mozWrap(txtarea, open, close)
|
||||
*/
|
||||
function storeCaret(textEl)
|
||||
{
|
||||
var keyCode = false;
|
||||
if (is_ie)
|
||||
{
|
||||
keyCode = (event.keyCode) ? event.keyCode : event.charCode;
|
||||
}
|
||||
|
||||
// Did the user press Shift (16), Ctrl (17) or Alt (18)?
|
||||
// If so, we do not update the caretPos, so BBCodes can still be applied correctly.
|
||||
var is_control_key = (keyCode == 16 || keyCode == 17 || keyCode == 18);
|
||||
|
||||
if ((!is_ie || !is_control_key) && (textEl.createTextRange))
|
||||
if (textEl.createTextRange)
|
||||
{
|
||||
textEl.caretPos = document.selection.createRange().duplicate();
|
||||
}
|
||||
@ -389,7 +387,7 @@ function colorPalette(dir, width, height)
|
||||
{
|
||||
document.writeln('<tr>');
|
||||
}
|
||||
|
||||
|
||||
for (b = 0; b < 5; b++)
|
||||
{
|
||||
color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
|
||||
@ -429,15 +427,15 @@ function caretPosition()
|
||||
function getCaretPosition(txtarea)
|
||||
{
|
||||
var caretPos = new caretPosition();
|
||||
|
||||
|
||||
// simple Gecko/Opera way
|
||||
if (!is_ie && (txtarea.selectionStart || txtarea.selectionStart == 0))
|
||||
if(txtarea.selectionStart || txtarea.selectionStart == 0)
|
||||
{
|
||||
caretPos.start = txtarea.selectionStart;
|
||||
caretPos.end = txtarea.selectionEnd;
|
||||
}
|
||||
// dirty and slow IE way
|
||||
else if (document.selection)
|
||||
else if(document.selection)
|
||||
{
|
||||
// get current selection
|
||||
var range = document.selection.createRange();
|
||||
@ -445,16 +443,16 @@ function getCaretPosition(txtarea)
|
||||
// a new selection of the whole textarea
|
||||
var range_all = document.body.createTextRange();
|
||||
range_all.moveToElementText(txtarea);
|
||||
|
||||
|
||||
// calculate selection start point by moving beginning of range_all to beginning of range
|
||||
var sel_start;
|
||||
for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++)
|
||||
{
|
||||
{
|
||||
range_all.moveStart('character', 1);
|
||||
}
|
||||
|
||||
|
||||
txtarea.sel_start = sel_start;
|
||||
|
||||
|
||||
// we ignore the end value for IE, this is already dirty enough and we don't need it
|
||||
caretPos.start = txtarea.sel_start;
|
||||
caretPos.end = txtarea.sel_start;
|
||||
|
Loading…
x
Reference in New Issue
Block a user