2 * @class Roo.lib.Selection
4 * This is a toolkit, normally used to copy features into a Dom Selection element
5 * Roo.lib.Selection.wrap(x);
10 Roo.lib.Selection = function() { };
13 * Wrap a Dom Range object, to give it new features...
15 * @param {Range} the range to wrap
17 Roo.lib.Selection.wrap = function(r, doc) {
18 Roo.apply(r, Roo.lib.Selection.prototype);
19 r.ownerDocument = doc; // usefull so we dont have to keep referening to it.
23 * find a parent node eg. LI / OL
24 * @param {string|Array} node name or array of nodenames
25 * @return {DomElement|false}
27 Roo.apply(Roo.lib.Selection.prototype,
32 ownerDocument : false,
34 getRangeAt : function(n)
36 return Roo.lib.Range.wrap(Selection.prototype.getRangeAt.call(this,n));
40 * insert node at selection
41 * @param {DomElement|string} node
42 * @param {string} cursor (after|in|none) where to place the cursor after inserting.
44 insertNode: function(node, cursor)
46 if (typeof(node) == 'string') {
47 node = this.ownerDocument.createElement(node);
49 node.innerHTML = ' ';
53 var range = this.getRangeAt(0);
55 if (this.type != 'Caret') {
56 range.deleteContents();
58 var sn = node.childNodes[0]; // select the contents.
62 range.insertNode(node);
63 if (cursor == 'after') {
64 node.insertAdjacentHTML('afterend', ' ');
65 sn = node.nextSibling;
68 if (cursor == 'none') {
75 cursorText : function(n)
78 //var range = this.getRangeAt(0);
79 range = Roo.lib.Range.wrap(new Range());
80 //range.selectNode(n);
82 var ix = Array.from(n.parentNode.childNodes).indexOf(n);
83 range.setStart(n.parentNode,ix);
84 range.setEnd(n.parentNode,ix+1);
85 //range.collapse(false);
87 this.removeAllRanges();
90 Roo.log([n, range, this,this.baseOffset,this.extentOffset, this.type]);
92 cursorAfter : function(n)
94 if (!n.nextSibling || n.nextSibling.nodeValue != ' ') {
95 n.insertAdjacentHTML('afterend', ' ');
97 this.cursorText (n.nextSibling);