doap file added
[gnome.introspection-doc-generator] / Roo.js
1
2
3 /*
4  * Based on:
5  * Ext JS Library 1.1.1
6  * Copyright(c) 2006-2007, Ext JS, LLC.
7  *
8  * Originally Released Under LGPL - original licence link has changed is not relivant.
9  *
10  * Fork - LGPL
11  * <script type="text/javascript">
12  */
13  
14
15
16 /**
17  * @class Roo
18  * Roo core utilities and functions.
19  * @singleton
20  */
21 //Roo = imports['Roo.js']; 
22 //xnew = imports['xnew.js']; 
23 Roo = { }; 
24  
25 /**
26  * Copies all the properties of config to obj.
27  * @param {Object} obj The receiver of the properties
28  * @param {Object} config The source of the properties
29  * @param {Object} defaults A different object that will also be applied for default values
30  * @return {Object} returns obj
31  * @member Roo apply
32  */
33
34 Roo.apply = function(o, c, defaults){
35     if(defaults){
36         // no "this" reference for friendly out of scope calls
37         Roo.apply(o, defaults);
38     }
39     if(o && c && typeof c == 'object'){
40         for(var p in c){
41             o[p] = c[p];
42         }
43     }
44     return o;
45 };
46
47
48 (function(){ 
49
50     var idSeed = 0;
51
52     Roo.apply(Roo, {
53         
54         /**
55          * Generates unique ids. If the element already has an id, it is unchanged
56          * @param {String/HTMLElement/Element} el (optional) The element to generate an id for
57          * @param {String} prefix (optional) Id prefix (defaults "Roo-gen")
58          * @return {String} The generated Id.
59          */
60         id : function(el, prefix){
61             prefix = prefix || "roo-gen";
62             //el = Roo.getDom(el);
63             var id = prefix + (++idSeed);
64             return id;
65             //return el ? (el.id ? el.id : (el.id = id)) : id;
66         },
67         /**
68          * Extends one class with another class and optionally overrides members with the passed literal. This class
69          * also adds the function "override()" to the class that can be used to override
70          * members on an instance.
71          * @param {Object} subclass The class inheriting the functionality
72          * @param {Object} superclass The class being extended
73          * @param {Object} overrides (optional) A literal with members
74          * @method extend
75          */
76         extend : function(){
77             // inline overrides
78             var io = function(o){
79                 for(var m in o){
80                     this[m] = o[m];
81                 }
82             };
83             return function(sb, sp, overrides) {
84                 if (typeof(sp) == 'undefined') {
85                     // error condition - try and dump..
86                     imports['console.js'].console.dump(sb);
87                 }
88                 
89                 if(typeof sp == 'object'){ // eg. prototype, rather than function constructor..
90                     overrides = sp;
91                     sp = sb;
92                     sb = function(){sp.apply(this, arguments);};
93                 }
94                 var F = function(){}, sbp, spp = sp.prototype;
95                 F.prototype = spp;
96                 sbp = sb.prototype = new F();
97                 sbp.constructor=sb;
98                 sb.superclass=spp;
99                 
100                 if(spp.constructor == Object.prototype.constructor){
101                     spp.constructor=sp;
102                    
103                 }
104                 
105                 sb.override = function(o){
106                     Roo.override(sb, o);
107                 };
108                 sbp.override = io;
109                 Roo.override(sb, overrides);
110                 return sb;
111             };
112         }(),
113         /**
114          * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
115          * Usage:<pre><code>
116 Roo.override(MyClass, {
117     newMethod1: function(){
118         // etc.
119     },
120     newMethod2: function(foo){
121         // etc.
122     }
123 });
124  </code></pre>
125          * @param {Object} origclass The class to override
126          * @param {Object} overrides The list of functions to add to origClass.  This should be specified as an object literal
127          * containing one or more methods.
128          * @method override
129          */
130         override : function(origclass, overrides){
131             if(overrides){
132                 var p = origclass.prototype;
133                 for(var method in overrides){
134                     p[method] = overrides[method];
135                 }
136             }
137         },
138         
139         
140         /**
141          * Iterates an array calling the passed function with each item, stopping if your function returns false. If the
142          * passed array is not really an array, your function is called once with it.
143          * The supplied function is called with (Object item, Number index, Array allItems).
144          * @param {Array/NodeList/Mixed} array
145          * @param {Function} fn
146          * @param {Object} scope
147          */
148         each : function(array, fn, scope){
149             if(typeof array.length == "undefined" || typeof array == "string"){
150                 array = [array];
151             }
152             for(var i = 0, len = array.length; i < len; i++){
153                 if(fn.call(scope || array[i], array[i], i, array) === false){ return i; };
154             }
155         },
156         
157            /**
158          * Copies all the properties of config to obj if they don't already exist.
159          * @param {Object} obj The receiver of the properties
160          * @param {Object} config The source of the properties
161          * @return {Object} returns obj
162          */
163         applyIf : function(o, c){
164             if(o && c){
165                 for(var p in c){
166                     if(typeof o[p] == "undefined"){ o[p] = c[p]; }
167                 }
168             }
169             return o;
170         },
171
172         
173     })
174     
175     imports['xnew.js'].xnew.load( Roo,  'Roo' );
176 })();
177
178
179
180         
181