1 /**
  2  * implementation of the tQuery.Node
  3  *
  4  * @class base class for tQuery objects
  5  *
  6  * @param {Object} object an instance or an array of instance
  7 */
  8 tQuery.Node	= function(object)
  9 {
 10 	// handle parameters
 11 	if( object instanceof Array )	this._lists	= object;
 12 	else if( !object )		this._lists	= [];
 13 	else				this._lists	= [object];
 14 	this.length	= this._lists.length;
 15 };
 16 
 17 //////////////////////////////////////////////////////////////////////////////////
 18 //										//
 19 //////////////////////////////////////////////////////////////////////////////////
 20 
 21 /**
 22  * Retrieve the elements matched by the tQuery object
 23  * 
 24  * @param {Function} callback the function to notify. function(element){ }.
 25  * 			loop interrupted if it returns false
 26  * 
 27  * @returns {Boolean} return true if completed, false if interrupted
 28 */
 29 tQuery.Node.prototype.get	= function(idx)
 30 {
 31 	if( idx === undefined )	return this._lists;
 32 	// sanity check - it MUST be defined
 33 	console.assert(this._lists[idx], "element not defined");
 34 	return this._lists[idx];
 35 };
 36 
 37 /**
 38  * loop over element
 39  * 
 40  * @param {Function} callback the function to notify. function(element){ }.
 41  * 			loop interrupted if it returns false
 42  * 
 43  * @returns {Boolean} return true if completed, false if interrupted
 44 */
 45 tQuery.Node.prototype.each	= function(callback)
 46 {
 47 	return tQuery.each(this._lists, callback)
 48 };
 49 
 50 /**
 51  * getter/setter of the back pointer
 52  *
 53  * @param {Object} back the value to return when .back() is called. optional
 54 */
 55 tQuery.Node.prototype.back	= function(value)
 56 {
 57 	if( value  === undefined )	return this._back;
 58 	this._back	= value;
 59 	return this;
 60 };
 61 
 62 //////////////////////////////////////////////////////////////////////////////////
 63 //										//
 64 //////////////////////////////////////////////////////////////////////////////////
 65 
 66 /**
 67  * same as .data() in jquery
 68 */
 69 tQuery.Node.prototype.data	= function(key, value)
 70 {
 71 	// handle the setter case
 72 	if( value ){
 73 		this.each(function(element){
 74 			tQuery.data(element, key, value);
 75 		});
 76 		return this;	// for chained API
 77 	}
 78 	// return the value of the first element
 79 	if( this.length > 0 )	return tQuery.data(this.get(0), key)
 80 	// return undegined if the list is empty
 81 	console.assert(this.length === 0);
 82 	return undefined
 83 }
 84 
 85 
 86 /**
 87  * same as .data() in jquery
 88 */
 89 tQuery.Node.prototype.removeData	= function(key)
 90 {
 91 	this.each(function(element){
 92 		tQuery.removeData(element, key);
 93 	});
 94 	return this;	// for chained API
 95 }