6 * Copyright(c) 2006-2007, Ext JS, LLC.
8 * Originally Released Under LGPL - original licence link has changed is not relivant.
11 * <script type="text/javascript">
18 * Roo core utilities and functions.
21 //Roo = imports['Roo.js'];
22 //xnew = imports['xnew.js'];
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
34 Roo.apply = function(o, c, defaults){
36 // no "this" reference for friendly out of scope calls
37 Roo.apply(o, defaults);
39 if(o && c && typeof c == 'object'){
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.
60 id : function(el, prefix){
61 prefix = prefix || "roo-gen";
62 //el = Roo.getDom(el);
63 var id = prefix + (++idSeed);
65 //return el ? (el.id ? el.id : (el.id = id)) : id;
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
83 return function(sb, sp, overrides) {
84 if (typeof(sp) == 'undefined') {
85 // error condition - try and dump..
86 imports['console.js'].console.dump(sb);
89 if(typeof sp == 'object'){ // eg. prototype, rather than function constructor..
92 sb = function(){sp.apply(this, arguments);};
94 var F = function(){}, sbp, spp = sp.prototype;
96 sbp = sb.prototype = new F();
100 if(spp.constructor == Object.prototype.constructor){
105 sb.override = function(o){
109 Roo.override(sb, overrides);
114 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
116 Roo.override(MyClass, {
117 newMethod1: function(){
120 newMethod2: function(foo){
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.
130 override : function(origclass, overrides){
132 var p = origclass.prototype;
133 for(var method in overrides){
134 p[method] = overrides[method];
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
148 each : function(array, fn, scope){
149 if(typeof array.length == "undefined" || typeof array == "string"){
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; };
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
163 applyIf : function(o, c){
166 if(typeof o[p] == "undefined"){ o[p] = c[p]; }
175 imports['xnew.js'].xnew.load( Roo, 'Roo' );