widget-parent-debug.js revision aacc7c2be5854cf3e80028d47a46b6e6c39cc7ce
// TO DO
// - Ask Adam about "queuable" configuration for events
// 1. Provide convience of being able to set once via the constructor only
// 2. Disallow setting via "set"
// 3. Provide get access through standard "get()"
// - Talk to Adam about being able to listen for "selectedChange" and
// and "focusedChange" at the parent level
// - Future performance optimization, if add() is passed a config,
// defer the instance creation until the instance is needed
/**
* Provides an extension enabling a Widget to be a parent of another Widget.
*
* @module widget-parent
*/
/**
* Widget extension providing functionality enabling a Widget to be a
* parent of another Widget.
*
* @class WidgetParent
* @param {Object} config User configuration object.
*/
function Parent() {
}
/**
* @attribute defaultItemType
* @type String
*
* @description String representing the default type of the children
* managed by this Widget.
*/
},
/**
* @attribute activeItem
* @type Widget
* @readOnly
*
* @description Returns the Widget's currently focused descendant Widget.
*/
activeItem: {
readOnly: true
},
/**
* @attribute multiple
* @type Boolean
* @default false
* @writeOnce
*
* @description Boolean indicating if multiple children can be selected at
* once.
*/
multiple: {
value: false,
writeOnce: true
},
/**
* @attribute selection
* @type {Array|Widget}
* @readOnly
*
* @description Returns the currently selected child Widget. If the
* <code>mulitple</code> attribte is set to <code>true</code> will
* return an array of the currently selected children. If no children
* are selection, will return null.
*/
selection: {
readOnly: true,
return this._setSelection(val);
}
},
/**
* @attribute items
* @type Array
* @readOnly
*
* @description Returns an array of all of the children that are
* direct descendants.
*/
items: {
readOnly: true,
valueFn: function () {
return [];
}
}
};
/**
* Attribute change listener for the <code>selection</code>
* attribute, responsible for setting the value of the
* parent's <code>selected</code> attribute.
*
* @method _afterSelectionChange
* @protected
* @param {EventFacade} event The event facade for the attribute change.
*/
_afterSelectionChange: function (event) {
if (selection) {
}
else {
}
}
else {
if (prevSelection) {
// Set src equal to the current context to prevent
// unnecessary re-calculation of the selection.
}
}
}
},
/**
* Attribute change listener for the <code>selected</code>
* attribute.
*
* @method _afterParentSelectedChange
* @protected
* @param {EventFacade} event The event facade for the attribute change.
*/
_afterParentSelectedChange: function (event) {
});
}
},
/**
* Default setter for <code>selection</code> attribute changes.
*
* @method _setSelection
* @protected
* @param {Array|Widget} zIndex
* @return {Widget}
*/
_setSelection: function (item) {
var selection = null,
selection = [];
}
});
}
else {
}
}
return selection;
},
/**
* Attribute change listener for the <code>selected</code>
* attribute of child Widgets, responsible for setting the value of the
* parent's <code>selection</code> attribute.
*
* @method _afterChildSelectedChange
* @protected
* @param {EventFacade} event The event facade for the attribute change.
*/
_afterChildSelectedChange: function (event) {
}
},
/**
* Attribute change listener for the <code>focused</code>
* attribute of child Widgets, responsible for setting the value of the
* parent's <code>activeItem</code> attribute.
*
* @method _afterSelectedChange
* @protected
* @param {EventFacade} event The event facade for the attribute change.
*/
_afterChildFocusedChange: function (event) {
var val = null;
}
},
/**
* Creates an instance of a child Widget using the specified configuration.
* By default Widget instances will be created of the type specified
* by the <code>defaultItemType</code> attribute. Types can be explicitly
* defined via the <code>type</code> property of the configuration object
* literal.
*
* @method _createItem
* @protected
* @param config {Object} Object literal representing the configuration
* used to create an instance of a Widget.
*/
_createItem: function (config) {
var item,
}
else {
}
fnConstructor = Y[sType];
if (fnConstructor) {
}
return item;
},
/**
* Default itemAdded handler
*
* @method _defItemAdded
* @protected
* @param event {EventFacade} The Event object
* @param item {Widget} The Widget instance, or configuration
* object for the Widget to be added as a child.
* @param index {Number} Number representing the position at
* which the child will be inserted.
*/
_defItemAdded: function (event) {
}
}
else {
}
}
},
/**
* Default itemRemoved handler
*
* @method _defItemRemoved
* @protected
* @param event {EventFacade} The Event object
* @param item {Widget} The Widget instance to be removed.
* @param index {Number} Number representing the index of the Widget to
* be removed.
*/
_defItemRemoved: function (event) {
}
}
item.removeTarget(this);
},
/**
* @method add
* @param item {Widget|Object} The Widget instance, or configuration
* object for the Widget to be added as a child.
* @param index {Number} (Optional.) Number representing the position at
* which the child should be inserted.
* @description Adds a Widget as a child. If the specified Widget already
* has a parent it will be removed from its current parent before
* being added as a child.
* @return {Widget} Widget instance that was successfully added, otherwise
* null.
*/
var aItems,
success = false;
aItems = [];
if (oItem) {
}
}, this);
}
}
else {
}
else {
}
}
return returnVal;
},
/**
* @method remove
* @param index {Number} (Optional.) Number representing the index of the
* child to be removed.
* @description Removes the Widget from its parent. Optionally, can remove
* a child by specifying its index.
* @return {Widget} Widget instance that was successfully removed, otherwise
* null.
*/
item,
success = false;
if (item) {
}
}
},
/**
* @method removeAll
* @description Removes all of the children from the Widget.
* @return {Array} Array of Widgets that were successfully removed.
*/
removeAll: function () {
aRemoved = [],
item;
if (item) {
}
});
},
/**
* @method item
* @description Retrieves the child Widget at the specified index.
* @return {Widget} Widget instance.
*/
},
/**
* Renders all child Widgets for the parent.
* <p>
* This method in invoked after renderUI is invoked for the Widget class
* using YUI's aop infrastructure.
* </p>
* @method _renderUIParent
* @protected
*/
_renderUIParent: function () {
});
},
initializer: function (config) {
/**
* Fires when a Widget is add as a child.
* <p>
* Subscribers to the "on" moment of this event, will be notified
* before a child is added.
* </p>
* <p>
* Subscribers to the "after" moment of this event, will be notified
* after a child is added.
* </p>
*
* @event widget:itemAdded
* @preventable _defItemAdded
* @param {EventFacade} e The Event Facade
*/
/**
* Fires when a child Widget is removed.
* <p>
* Subscribers to the "on" moment of this event, will be notified
* before a child is removed.
* </p>
* <p>
* Subscribers to the "after" moment of this event, will be notified
* after a child is removed.
* </p>
*
* @event widget:itemRemoved
* @preventable _defItemAdded
* @param {EventFacade} e The Event Facade
*/
}
}
};
Y.WidgetParent = Parent;