X-Git-Url: http://git.roojs.org/?p=gnome.introspection-doc-generator;a=blobdiff_plain;f=XObject.js;h=1508659aa44604a62c052a3287cc7cbb449c0274;hp=05b35dc58311394618c7f46af7c6c9f6fc8c69e9;hb=44e5eb8d418d148e64e0c29f3c44d081f66804d4;hpb=f7af1758bacb68e2164817e2e7e7e993bf987a16 diff --git a/XObject.js b/XObject.js index 05b35dc..1508659 100644 --- a/XObject.js +++ b/XObject.js @@ -32,13 +32,13 @@ * * * - * @arg xtype {String|Function} constructor or string. - * @arg id {String} (optional) id for registry - * @arg xns {String|Object} (optional) namespace eg. Gtk or 'Gtk' - used with xtype. - * @arg items {Array} (optional) list of child elements which will be constructed.. using XObject + * @arg xtype {String|Function} constructor or string. + * @arg id {String} (optional) id for registry + * @arg xns {String|Object} (optional) namespace eg. Gtk or 'Gtk' - used with xtype. + * @arg items {Array} (optional) list of child elements which will be constructed.. using XObject * @arg listeners {Object} (optional) map Gobject signals to functions - * @arg pack {Function|String|Array} (optional) how this object gets added to it's parent - * @arg el {Object} (optional) premade GObject + * @arg pack {Function|String|Array} (optional) how this object gets added to it's parent + * @arg el {Object} (optional) premade GObject * * --- needs a xdebug option! * @@ -57,12 +57,8 @@ function XObject (cfg) { if (cfg.init) { this.init = cfg.init; // override! } - - } - - XObject.prototype = { /** * @property el {GObject} the Gtk / etc. element. @@ -113,9 +109,9 @@ XObject.prototype = { for (var i in o) { if ((typeof(o[i]) == 'object') || (typeof(o[i]) == 'function') || - i == 'pack' || - i == 'id' || - i == 'xtype' || + i == 'pack' || + i == 'id' || + i == 'xtype' || i == 'xdebug' || i == 'xns' ) { @@ -185,8 +181,7 @@ XObject.prototype = { * @arg cfg {Object} same as XObject constructor. */ addItem : function(o) { - - + var item = (o.constructor == XObject) ? o : new XObject(o); item.init(); item.parent = this; @@ -195,12 +190,14 @@ XObject.prototype = { if (item.pack===false) { // no return; } + if (typeof(item.pack) == 'function') { // parent, child item.pack.apply(o, [ o , o.items[i] ]); item.parent = this; return; } + var args = []; var pack_m = false; if (typeof(item.pack) == 'string') { @@ -225,17 +222,15 @@ XObject.prototype = { if (pack_m) { this.el[pack_m].apply(this.el, args); } - - - }, + /** - * @method addListener - * Connects a method to a signal. (gjs/Seed aware) - * - * @arg sig {String} name of signal - * @arg fn {Function} handler. - */ + * @method addListener + * Connects a method to a signal. (gjs/Seed aware) + * + * @arg sig {String} name of signal + * @arg fn {Function} handler. + */ addListener : function(sig, fn) { @@ -250,48 +245,49 @@ XObject.prototype = { } else { this.el.connect( sig, _li); } - - }, - /** - * @method get - * Finds an object in the child elements using xid of object. - * prefix with '.' to look up the tree.. multiple '..' to look further up.. - * - * @arg name {String} name of signal - * @return {XObject|false} the object if found. - */ + + /** + * @method get + * Finds an object in the child elements using xid of object. + * prefix with '.' to look up the tree.. multiple '..' to look further up.. + * + * @arg name {String} name of signal + * @return {XObject|false} the object if found. + */ get : function(xid) { var ret= false; if (xid[0] == '.') { return this.parent.get(xid.substring(1)); } - - + this.items.forEach(function(ch) { if (ch.id == xid) { ret = ch; return true; - } - }) + } else + return false; + }); + if (ret) { return ret; } + // iterate children. this.items.forEach(function(ch) { ret = ch.get(xid); if (ret) { return true; - } - }) + } else + return false; + }); + return ret; } - - } - - + + /** * Copies all the properties of config to obj. * @@ -302,8 +298,6 @@ XObject.prototype = { * @return {Object} returns obj * @member XObject extend */ - - XObject.extend = function(o, c, defaults){ if(defaults){ // no "this" reference for friendly out of scope calls @@ -326,24 +320,22 @@ XObject.extend(XObject, * @return {Object} returns obj * @member Object extendIf */ - - extendIf : function(o, c){ if(!o || !c || typeof c != 'object'){ return o; } + for(var p in c){ if (typeof(o[p]) != 'undefined') { continue; } o[p] = c[p]; } + return o; }, - - /** * Extends one class with another class and optionally overrides members with the passed literal. This class * also adds the function "override()" to the class that can be used to override @@ -359,6 +351,7 @@ XObject.extend(XObject, * ... methods and properties. * } * }); + * * @param {Function} constructor The class inheriting the functionality * @param {Object} superclass The class being extended * @param {Object} overrides (optional) A literal with members @@ -372,6 +365,7 @@ XObject.extend(XObject, this[m] = o[m]; } }; + return function(sb, sp, overrides) { if (typeof(sp) == 'undefined') { // error condition - try and dump.. @@ -398,7 +392,6 @@ XObject.extend(XObject, }; }(), - /** * returns a list of keys of the object. * @param {Object} obj object to inspect @@ -429,7 +422,6 @@ XObject.extend(XObject, * x = XObject.createDelegate(a, this); * */ - createDelegate : function(method, obj, args, appendArgs){ return function() { @@ -438,12 +430,11 @@ XObject.extend(XObject, callArgs = Array.prototype.slice.call(arguments, 0); callArgs = callArgs.concat(args); }else if(typeof appendArgs == "number"){ - callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first - var applyArgs = [appendArgs, 0].concat(args); // create method call params + callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first + var applyArgs = [appendArgs, 0].concat(args); // create method call params Array.prototype.splice.apply(callArgs, applyArgs); // splice them in } return method.apply(obj || window, callArgs); }; } - -}); \ No newline at end of file +});