while (pos && pos.offsetParent) {
y += pos.offsetTop;
// Don't count X offset for <br> nodes
- if (!isBR(pos))
+ if (pos.nodeName != "BR")
x += pos.offsetLeft;
pos = pos.offsetParent;
}
}
if (cur) {
try{range.moveToElementText(cur);}
- catch(e){return false;}
+ catch(e){}
range.collapse(false);
}
else range.moveToElementText(node.parentNode);
if (count) range.move("character", count);
}
- else {
- try{range.moveToElementText(node);}
- catch(e){return false;}
- }
- return true;
+ else range.moveToElementText(node);
}
// Do a binary search through the container object, comparing
while (start < end) {
var middle = Math.ceil((end + start) / 2), node = container.childNodes[middle];
if (!node) return false; // Don't ask. IE6 manages this sometimes.
- if (!moveToNodeStart(range2, node)) return false;
+ moveToNodeStart(range2, node);
if (range.compareEndPoints("StartToStart", range2) == 1)
start = middle;
else
if (!selection) return null;
var topNode = select.selectionTopNode(container, start);
- while (topNode && !isBR(topNode))
+ while (topNode && topNode.nodeName != "BR")
topNode = topNode.previousSibling;
var range = selection.createRange(), range2 = range.duplicate();
// ancestors with a suitable offset. This goes down the DOM tree
// until a 'leaf' is reached (or is it *up* the DOM tree?).
function normalize(point){
- while (point.node.nodeType != 3 && !isBR(point.node)) {
+ while (point.node.nodeType != 3 && point.node.nodeName != "BR") {
var newNode = point.node.childNodes[point.offset] || point.node.nextSibling;
point.offset = 0;
while (!newNode && point.node.parentNode) {
};
select.selectMarked = function () {
- var cs = currentSelection;
- if (!(cs && (cs.changed || (webkit && cs.start.node == cs.end.node)))) return;
- var win = cs.window, range = win.document.createRange();
+ if (!currentSelection || !currentSelection.changed) return;
+ var win = currentSelection.window, range = win.document.createRange();
function setPoint(point, which) {
if (point.node) {
}
}
- setPoint(cs.end, "End");
- setPoint(cs.start, "Start");
+ setPoint(currentSelection.end, "End");
+ setPoint(currentSelection.start, "Start");
selectRange(range, win);
};
var offset = start ? range.startOffset : range.endOffset;
// Work around (yet another) bug in Opera's selection model.
if (window.opera && !start && range.endContainer == container && range.endOffset == range.startOffset + 1 &&
- container.childNodes[range.startOffset] && isBR(container.childNodes[range.startOffset]))
+ container.childNodes[range.startOffset] && container.childNodes[range.startOffset].nodeName == "BR")
offset--;
// For text nodes, we look at the node itself if the cursor is
// Occasionally, browsers will return the HTML node as
// selection. If the offset is 0, we take the start of the frame
// ('after null'), otherwise, we take the last node.
- else if (node.nodeName.toUpperCase() == "HTML") {
+ else if (node.nodeName == "HTML") {
return (offset == 1 ? null : container.lastChild);
}
// If the given node is our 'container', we just look up the
if (!range) return;
var topNode = select.selectionTopNode(container, start);
- while (topNode && !isBR(topNode))
+ while (topNode && topNode.nodeName != "BR")
topNode = topNode.previousSibling;
range = range.cloneRange();