2
YUI 3.13.0 (build 508226d)
3
Copyright 2013 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
8
YUI.add('widget-child', function (Y, NAME) {
11
* Extension enabling a Widget to be a child of another Widget.
13
* @module widget-child
19
* Widget extension providing functionality enabling a Widget to be a
20
* child of another Widget.
23
* @param {Object} config User configuration object.
27
// Widget method overlap
28
Y.after(this._syncUIChild, this, "syncUI");
29
Y.after(this._bindUIChild, this, "bindUI");
40
* @description Number indicating if the Widget is selected. Possible
43
* <dt>0</dt> <dd>(Default) Not selected</dd>
44
* <dt>1</dt> <dd>Fully selected</dd>
45
* <dt>2</dt> <dd>Partially selected</dd>
50
validator: Lang.isNumber
59
* @description Number representing the Widget's ordinal position in its
66
var parent = this.get("parent"),
70
index = parent.indexOf(this);
84
* @description Retrieves the parent of the Widget in the object hierarchy.
97
* @description Number representing the depth of this Widget relative to
98
* the root Widget in the object heirarchy.
102
getter: function () {
104
var parent = this.get("parent"),
105
root = this.get("root"),
112
if (parent == root) {
116
parent = parent.get("parent");
130
* @description Returns the root Widget in the object hierarchy. If the
131
* ROOT_TYPE property is set, the search for the root Widget will be
132
* constrained to parent Widgets of the specified type.
136
getter: function () {
138
var getParent = function (child) {
140
var parent = child.get("parent"),
141
FnRootType = child.ROOT_TYPE,
145
criteria = (parent && Y.instanceOf(parent, FnRootType));
148
return (criteria ? getParent(parent) : child);
152
return getParent(this);
162
* Constructor reference used to determine the root of a Widget-based
165
* Currently used to control the behavior of the <code>root</code>
166
* attribute so that recursing up the object heirarchy can be constrained
167
* to a specific type of Widget. Widget authors should set this property
168
* to the constructor function for a given Widget implementation.
171
* @property ROOT_TYPE
177
* Returns the node on which to bind delegate listeners.
179
* Override of Widget's implementation of _getUIEventNode() to ensure that
180
* all event listeners are bound to the Widget's topmost DOM element.
181
* This ensures that the firing of each type of Widget UI event (click,
182
* mousedown, etc.) is facilitated by a single, top-level, delegated DOM
185
* @method _getUIEventNode
189
_getUIEventNode: function () {
190
var root = this.get("root"),
194
returnVal = root.get("boundingBox");
202
* @description Returns the Widget's next sibling.
203
* @param {Boolean} circular Boolean indicating if the parent's first child
204
* should be returned if the child has no next sibling.
205
* @return {Widget} Widget instance.
207
next: function (circular) {
209
var parent = this.get("parent"),
213
sibling = parent.item((this.get("index")+1));
216
if (!sibling && circular) {
217
sibling = parent.item(0);
227
* @description Returns the Widget's previous sibling.
228
* @param {Boolean} circular Boolean indicating if the parent's last child
229
* should be returned if the child has no previous sibling.
230
* @return {Widget} Widget instance.
232
previous: function (circular) {
234
var parent = this.get("parent"),
235
index = this.get("index"),
238
if (parent && index > 0) {
239
sibling = parent.item([(index-1)]);
242
if (!sibling && circular) {
243
sibling = parent.item((parent.size() - 1));
251
// Override of Y.WidgetParent.remove()
252
// Sugar implementation allowing a child to remove itself from its parent.
253
remove: function (index) {
258
if (Lang.isNumber(index)) {
259
removed = Y.WidgetParent.prototype.remove.apply(this, arguments);
263
parent = this.get("parent");
266
removed = parent.remove(this.get("index"));
278
* @description Determines if the Widget is the root Widget in the
280
* @return {Boolean} Boolean indicating if Widget is the root Widget in the
283
isRoot: function () {
284
return (this == this.get("root"));
290
* @description Returns the Widget instance at the specified depth.
291
* @param {number} depth Number representing the depth of the ancestor.
292
* @return {Widget} Widget instance.
294
ancestor: function (depth) {
296
var root = this.get("root"),
299
if (this.get("depth") > depth) {
301
parent = this.get("parent");
303
while (parent != root && parent.get("depth") > depth) {
304
parent = parent.get("parent");
315
* Updates the UI to reflect the <code>selected</code> attribute value.
317
* @method _uiSetChildSelected
319
* @param {number} selected The selected value to be reflected in the UI.
321
_uiSetChildSelected: function (selected) {
323
var box = this.get("boundingBox"),
324
sClassName = this.getClassName("selected");
326
if (selected === 0) {
327
box.removeClass(sClassName);
330
box.addClass(sClassName);
337
* Default attribute change listener for the <code>selected</code>
338
* attribute, responsible for updating the UI, in response to
341
* @method _afterChildSelectedChange
343
* @param {EventFacade} event The event facade for the attribute change.
345
_afterChildSelectedChange: function (event) {
346
this._uiSetChildSelected(event.newVal);
351
* Synchronizes the UI to match the WidgetChild state.
353
* This method is invoked after bindUI is invoked for the Widget class
354
* using YUI's aop infrastructure.
357
* @method _syncUIChild
360
_syncUIChild: function () {
361
this._uiSetChildSelected(this.get("selected"));
366
* Binds event listeners responsible for updating the UI state in response
367
* to WidgetChild related state changes.
369
* This method is invoked after bindUI is invoked for the Widget class
370
* using YUI's aop infrastructure.
372
* @method _bindUIChild
375
_bindUIChild: function () {
376
this.after("selectedChange", this._afterChildSelectedChange);
381
Y.WidgetChild = Child;
384
}, '3.13.0', {"requires": ["base-build", "widget"]});