Print Friendly

Class YAHOO.ext.util.MixedCollection

Package:YAHOO.ext.util
Class:MixedCollection
Extends:Object
Defined In:MixedCollection.js
A Collection class that maintains both numeric indexes and keys and exposes events.

Public Properties

This class has no public properties.

Public Methods

Method Defined By
  MixedCollection(Boolean allowFunctions) MixedCollection
  add(String key, Object o) : Object MixedCollection
Adds an item to the collection.
  addAll(Object/Array objs) : void MixedCollection
Adds all elements of an Array or an Object to the collection.
  clear() : void MixedCollection
Removes all items from the collection.
  contains(Object o) : Boolean MixedCollection
Returns true if the collection contains the passed Object as an item.
  containsKey(String key) : Boolean MixedCollection
Returns true if the collection contains the passed Object as a key.
  each(Function fn, [Object scope]) : void MixedCollection
Executes the specified function once for every item in the collection, passing each item as the first and only parame...
  eachKey(Function fn, [Object scope]) : void MixedCollection
Executes the specified function once for every key in the collection, passing each key, and its associated item as th...
  find(Function fn, [Object scope]) : Object MixedCollection
Returns the first item in the collection which elicits a true return value from the passed selection function.
  first() : Object MixedCollection
Returns the first item in the collection.
  get(String/Number key) : Object MixedCollection
Returns the item associated with the passed key or index.
  getCount() : Number MixedCollection
Returns the number of items in the collection.
  getKey(o {Object}) : Object MixedCollection
MixedCollection has a generic way to fetch keys if you implement getKey. // normal way var mc = new Y...
  indexOf(Object o) : Number MixedCollection
Returns index within the collection of the passed Object.
  indexOfKey(String key) : Number MixedCollection
Returns index within the collection of the passed key.
  insert(Number index, String key, [Object o]) : Object MixedCollection
Inserts an item at the specified index in the collection.
  item(String/Number key) : Object MixedCollection
Returns the item associated with the passed key.
  last() : Object MixedCollection
Returns the last item in the collection.
  remove(Object o) : Object MixedCollection
Removed an item from the collection.
  removeAt(Number index) : void MixedCollection
Remove an item from a specified index in the collection.
  removeKey(String key) : void MixedCollection
Removed an item associated with the passed key fom the collection.
  replace(String key, [o {Object}]) : Object MixedCollection
Replaces an item in the collection.

Public Events

Event Defined By
  add : (Number index, Object o, String key) MixedCollection
Fires when an item is added to the collection.
  clear : () MixedCollection
Fires when the collection is cleared.
  remove : (Object o, [String key]) MixedCollection
Fires when an item is removed from the collection.
  replace : (String key, Object old, Object new) MixedCollection
Fires when an item is replaced in the collection.

Constructor Details

MixedCollection

public function MixedCollection(Boolean allowFunctions)
Parameters:
  • allowFunctions : Boolean
    True if the addAll function should add function references to the collection.

Method Details

add

public function add(String key, Object o)
Adds an item to the collection.
Parameters:
  • key : String
    The key to associate with the item
  • o : Object
    The item to add.
Returns:
  • Object
    The item added.
This method is defined by MixedCollection.

addAll

public function addAll(Object/Array objs)
Adds all elements of an Array or an Object to the collection.
Parameters:
  • objs : Object/Array
    An Object containing properties which will be added to the collection, or an Array of values, each of which are added to the collection.
Returns:
  • void
This method is defined by MixedCollection.

clear

public function clear()
Removes all items from the collection.
Parameters:
  • None.
Returns:
  • void
This method is defined by MixedCollection.

contains

public function contains(Object o)
Returns true if the collection contains the passed Object as an item.
Parameters:
  • o : Object
    The Object to look for in the collection.
Returns:
  • Boolean
    True if the collection contains the Object as an item.
This method is defined by MixedCollection.

containsKey

public function containsKey(String key)
Returns true if the collection contains the passed Object as a key.
Parameters:
  • key : String
    The key to look for in the collection.
Returns:
  • Boolean
    True if the collection contains the Object as a key.
This method is defined by MixedCollection.

each

public function each(Function fn, [Object scope])
Executes the specified function once for every item in the collection, passing each item as the first and only parameter.
Parameters:
  • fn : Function
    The function to execute for each item.
  • scope : Object
    (optional) The scope in which to execute the function.
Returns:
  • void
This method is defined by MixedCollection.

eachKey

public function eachKey(Function fn, [Object scope])
Executes the specified function once for every key in the collection, passing each key, and its associated item as the first two parameters.
Parameters:
  • fn : Function
    The function to execute for each item.
  • scope : Object
    (optional) The scope in which to execute the function.
Returns:
  • void
This method is defined by MixedCollection.

find

public function find(Function fn, [Object scope])
Returns the first item in the collection which elicits a true return value from the passed selection function.
Parameters:
  • fn : Function
    The selection function to execute for each item.
  • scope : Object
    (optional) The scope in which to execute the function.
Returns:
  • Object
    The first item in the collection which returned true from the selection function.
This method is defined by MixedCollection.

first

public function first()
Returns the first item in the collection.
Parameters:
  • None.
Returns:
  • Object
    the first item in the collection..
This method is defined by MixedCollection.

get

public function get(String/Number key)
Returns the item associated with the passed key or index.
Parameters:
  • key : String/Number
    The key or index of the item.
Returns:
  • Object
    The item associated with the passed key.
This method is defined by MixedCollection.

getCount

public function getCount()
Returns the number of items in the collection.
Parameters:
  • None.
Returns:
  • Number
    the number of items in the collection.
This method is defined by MixedCollection.

getKey

public function getKey(o {Object})
MixedCollection has a generic way to fetch keys if you implement getKey.

    // normal way
    var mc = new YAHOO.ext.util.MixedCollection();
    mc.add(someEl.dom.id, someEl);
    mc.add(otherEl.dom.id, otherEl);
    //and so on
    
    // using getKey
    var mc = new YAHOO.ext.util.MixedCollection();
    mc.getKey = function(el){
       return el.dom.id;
    }
    mc.add(someEl);
    mc.add(otherEl);
    // etc
                    
                
Parameters:
  • {Object} : o
    The item for which to find the key.
Returns:
  • Object
    The key for the passed item.
This method is defined by MixedCollection.

indexOf

public function indexOf(Object o)
Returns index within the collection of the passed Object.
Parameters:
  • o : Object
    The item to find the index of.
Returns:
  • Number
    index of the item.
This method is defined by MixedCollection.

indexOfKey

public function indexOfKey(String key)
Returns index within the collection of the passed key.
Parameters:
  • key : String
    The key to find the index of.
Returns:
  • Number
    index of the key.
This method is defined by MixedCollection.

insert

public function insert(Number index, String key, [Object o])
Inserts an item at the specified index in the collection.
Parameters:
  • index : Number
    The index to insert the item at.
  • key : String
    The key to associate with the new item, or the item itself.
  • o : Object
    (optional) If the second parameter was a key, the new item.
Returns:
  • Object
    The item inserted.
This method is defined by MixedCollection.

item

public function item(String/Number key)
Returns the item associated with the passed key.
Parameters:
  • key : String/Number
    The key or index of the item.
Returns:
  • Object
    The item associated with the passed key.
This method is defined by MixedCollection.

last

public function last()
Returns the last item in the collection.
Parameters:
  • None.
Returns:
  • Object
    the last item in the collection..
This method is defined by MixedCollection.

remove

public function remove(Object o)
Removed an item from the collection.
Parameters:
  • o : Object
    The item to remove.
Returns:
  • Object
    The item removed.
This method is defined by MixedCollection.

removeAt

public function removeAt(Number index)
Remove an item from a specified index in the collection.
Parameters:
  • index : Number
    The index within the collection of the item to remove.
Returns:
  • void
This method is defined by MixedCollection.

removeKey

public function removeKey(String key)
Removed an item associated with the passed key fom the collection.
Parameters:
  • key : String
    The key of the item to remove.
Returns:
  • void
This method is defined by MixedCollection.

replace

public function replace(String key, [o {Object}])
Replaces an item in the collection.
Parameters:
  • key : String
    The key associated with the item to replace, or the item to replace.
  • {Object} : o
    o (optional) If the first parameter passed was a key, the item to associate with that key.
Returns:
  • Object
    The new item.
This method is defined by MixedCollection.

Event Details

add

public event add
Fires when an item is added to the collection.
Subscribers will be called with the following parameters:
  • index : Number
    The index at which the item was added.
  • o : Object
    The item added.
  • key : String
    The key associated with the added item.
This event is defined by MixedCollection.

clear

public event clear
Fires when the collection is cleared.
Subscribers will be called with the following parameters:
  • None.
This event is defined by MixedCollection.

remove

public event remove
Fires when an item is removed from the collection.
Subscribers will be called with the following parameters:
  • o : Object
    The item being removed.
  • key : String
    (optional) The key associated with the removed item.
This event is defined by MixedCollection.

replace

public event replace
Fires when an item is replaced in the collection.
Subscribers will be called with the following parameters:
  • key : String
    he key associated with the new added.
  • old : Object
    The item being replaced.
  • new : Object
    The new item.
This event is defined by MixedCollection.

yui-ext - Copyright © 2006 Jack Slocum. | Yahoo! UI - Copyright © 2006 Yahoo! Inc.
All rights reserved.