more styling
[roojs1] / Roo / lib / Range.js
1 /**
2  * @class Roo.lib.Range
3  * @constructor
4  * This is a toolkit, normally used to copy features into a Dom Range element
5  * Roo.lib.Range.wrap(x);
6  *
7  *
8  *
9  */
10 Roo.lib.Range = function() { };
11
12 /**
13  * Wrap a Dom Range object, to give it new features...
14  * @static
15  * @param {Range} the range to wrap
16  */
17 Roo.lib.Range.wrap = function(r) {
18     return Roo.apply(r, Roo.lib.Range.prototype);
19 };
20 /**
21  * find a parent node eg. LI / OL
22  * @param {string|Array} node name or array of nodenames
23  * @return {DomElement|false}
24  */
25 Roo.apply(Roo.lib.Range.prototype,
26 {
27     
28     closest : function(str)
29     {
30         if (typeof(str) != 'string') {
31             // assume it's a array.
32             for(var i = 0;i < str.length;i++) {
33                 var r = this.closest(str[i]);
34                 if (r !== false) {
35                     return r;
36                 }
37                 
38             }
39             return false;
40         }
41         str = str.toLowerCase();
42         var n = this.commonAncestorContainer; // might not be a node
43         while (n.nodeType != 1) {
44             n = n.parentNode;
45         }
46         
47         if (n.nodeName.toLowerCase() == str ) {
48             return n;
49         }
50         if (n.nodeName.toLowerCase() == 'body') {
51             return false;
52         }
53             
54         return n.closest(str) || false;
55         
56     },
57     cloneRange : function()
58     {
59         return Roo.lib.Range.wrap(Range.prototype.cloneRange.call(this));
60     }
61 });