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 = r; // usefull so we dont have to keep referening to it.
22 * find a parent node eg. LI / OL
23 * @param {string|Array} node name or array of nodenames
24 * @return {DomElement|false}
26 Roo.apply(Roo.lib.Selection.prototype,
31 ownerDocument : false,
33 getRangeAt : function(n)
35 return Roo.lib.Range.wrap(Selection.prototype.getRangeAt.call(this,n));
39 * insert node at selection
40 * @param {DomElement|string} node
41 * @param {string} cursor (after|in|none) where to place the cursor after inserting.
43 insertNode: function(node, cursor)
45 if (typeof(node) == 'string') {
46 node = this.ownerDocument.createElement(node);
48 node.innerHTML = ' ';
52 var range = this.getRangeAt(0);
54 if (this.type != 'Caret') {
55 range.deleteContents();
57 range.insertNode(node);
58 if (cursor == 'none') {
61 var sn = node.childNodes[0]; // select the contents.
62 if (cursor == 'after') {
63 sn = node.insertAdjacentHTML('afterend', ' ');
67 cursorStart : function(n)
69 var range = this.getRangeAt(0);
70 range = range.cloneRange();
73 range.collapse(false);
75 this.removeAllRanges();