You need to be logged in to post in the forums. If you do not have an account, please sign up first.
W3C is good ). I've changed my code. Now it's working but i have some trouble (in opera) using this peace of code (this is a part of code which is doing some formatting stuff with selected text inside content editable div)
next_element = bound_element.nextSibling; //bound_element is span, next_element seems to be text node
new_range = document.createRange();
new_range.setStart(sel_range.startContainer,sel_range.startOffset);//sel_range - previous selection
new_range.setEnd(next_element,0);
new_range.surroundContents(newNode);
newNode.style.fontWeight = "bold";
After using this part of code all is working fine but opera doesn't respond for 5-10 seconds. Finally newNode appears. Where is the problem? Thanks!
next_element = bound_element.nextSibling; //bound_element is span, next_element seems to be text node
new_range = document.createRange();
new_range.setStart(sel_range.startContainer,sel_range.startOffset);//sel_range - previous selection
new_range.setEnd(next_element,0);
new_range.surroundContents(newNode);
newNode.style.fontWeight = "bold";
After using this part of code all is working fine but opera doesn't respond for 5-10 seconds. Finally newNode appears. Where is the problem? Thanks!
Without more context about "bound_element", it's still not possible to help you any further. Where does it come from?
Wrapping just the selection with new_node works fine for me.
Also, the W3C Range api is horrible, for one specific reason: surroundContents. It throws BAD_BOUNDARYPOINTS_ERR for its main use case.
Did you look at the execCommand api in html5?
Wrapping just the selection with new_node works fine for me.
Also, the W3C Range api is horrible, for one specific reason: surroundContents. It throws BAD_BOUNDARYPOINTS_ERR for its main use case.
Did you look at the execCommand api in html5?
26. October 2009, 11:48:25 (edited)
I know that opera doesn't support execCommand... Am i wrong?
"Also, the W3C Range api is horrible, for one specific reason: surroundContents. It throws BAD_BOUNDARYPOINTS_ERR for its main use case." that is why i have to use nextSibling. And after using nextSibling i have a problem discribed earlier.
"Also, the W3C Range api is horrible, for one specific reason: surroundContents. It throws BAD_BOUNDARYPOINTS_ERR for its main use case." that is why i have to use nextSibling. And after using nextSibling i have a problem discribed earlier.
Originally posted by zim32:
I know that opera doesn't support execCommand... Am i wrong?
Opera does support it since Opera 9, although the clipboard functions aren't supported.
Originally posted by zim32:
I haven't been able to reproduce that. Your code always fails with the exception, because your range starts in the startContainer and ends in the next_element. It should end at the end of startContainer if you want to avoid the exception. Without knowing how you get bound_element, we can't get any further.And after using nextSibling i have a problem discribed earlier.
Opera calculates range boundaries incorrectly.
Here the simple example working in FireFox, Safari, Chrome and throwing BAD_BOUNDARYPOINTS_ERR exception in Opera:
It does not correspond the standard which says:
I'm trying to surround a part of the Text node only but Opera throws the exception.
Here the simple example working in FireFox, Safari, Chrome and throwing BAD_BOUNDARYPOINTS_ERR exception in Opera:
//the 'start' element is a SPAN
var oTextNode = document.getElementById('start').childNodes[0];
var sel = document.createRange();
sel.setStart( oTextNode, 14);
sel.setEndAfter( oTextNode);
sel.surroundContents(document.createElement('span'));
It does not correspond the standard which says:
The surroundContents() method raises an exception if the Range partially selects a non-Text node.
I'm trying to surround a part of the Text node only but Opera throws the exception.
the following workarounds work:
So the obvious usage of API:
1. sel.setEnd( oTextNode, oTextNode.nodeValue.length);
2. sel.setEnd( oTextNode.parentNode.insertBefore(
document.createTextNode(''), oTextNode.nextSibling), 0);
3. oTextNode.splitText(oTextNode.nodeValue.length);
sel.setEnd( oTextNode.nextSibling, 0);
So the obvious usage of API:
sel.setEndAfter( oTextNode);is also expected to work.