Skip to content

Commit

Permalink
gallery-2011.02.23-19-01 ipeychev gallery-accordion
Browse files Browse the repository at this point in the history
  • Loading branch information
YUI Builder committed Feb 23, 2011
1 parent 2e1d590 commit 3e811c8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
39 changes: 31 additions & 8 deletions src/gallery-accordion/js/gallery-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,19 @@ Y.Accordion = Y.Base.create( AccName, Y.Widget, [], {
},


/**
* Binds an event to Accordion's contentBox.
*
* @method _bindItemChosenEvent
* @protected
*/
_bindItemChosenEvent: function(itemChosenEvent) {
var contentBox;

contentBox = this.get( CONTENT_BOX );
contentBox.delegate( itemChosenEvent, Y.bind( this._onItemChosenEvent, this ), '.yui3-widget-hd' );
},

/**
* Contains items for collapsing
* @property _forCollapsing
Expand Down Expand Up @@ -1338,18 +1351,26 @@ Y.Accordion = Y.Base.create( AccName, Y.Widget, [], {


/**
* Add listener to <code>itemChosen</code> event in Accordion's content box
* Add listener(s) to <code>itemChosen</code> event in Accordion's content box.
* If itemChosen is an Array, this function will invoke multiple times _bindItemChosenEvent
*
* @method bindUI
* @protected
*/
bindUI: function(){
var contentBox, itemChosenEvent;
var i, itemChosenEvent, length;

contentBox = this.get( CONTENT_BOX );
itemChosenEvent = this.get( 'itemChosen' );

contentBox.delegate( itemChosenEvent, Y.bind( this._onItemChosenEvent, this ), '.yui3-widget-hd' );
if( Lang.isArray(itemChosenEvent) ){
length = itemChosenEvent.length;

for( i = 0; i < length; i++ ) {
this._bindItemChosenEvent(itemChosenEvent[i]);
}
} else {
this._bindItemChosenEvent(itemChosenEvent);
}
},


Expand Down Expand Up @@ -1645,16 +1666,18 @@ Y.Accordion = Y.Base.create( AccName, Y.Widget, [], {
ATTRS : {
/**
* @description The event on which Accordion should listen for user interactions.
* The value can be also mousedown or mouseup. Mousedown event can be used if
* drag&drop is not enabled
* The value can be also 'mousedown', 'mouseup' or ['mouseenter','click'].
* Mousedown event can be used if drag&drop is not enabled.
*
* @attribute itemChosen
* @default click
* @type String
* @type String|Array
*/
itemChosen: {
value: "click",
validator: Lang.isString
validator: function( value ) {
return Lang.isString(value) || Lang.isArray(value);
}
},

/**
Expand Down
21 changes: 17 additions & 4 deletions src/gallery-accordion/tests/testaccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ YUI({
this.accordion1 = new Y.Accordion( {
srcNode: "#acc1",
useAnimation: true,
collapseOthersOnExpand: true
collapseOthersOnExpand: true,
itemChosen: ['click', 'mouseenter']
});


Expand Down Expand Up @@ -263,7 +264,7 @@ YUI({
header = Y.Node.getDOMNode(item3.getStdModNode( Y.WidgetStdMod.HEADER ));

Y.Event.simulate( header, "click" );
Y.Assert.areSame( true, item3.get( "expanded" ), "Item3 must be exapnded now" );
Y.Assert.areSame( true, item3.get( "expanded" ), "Item3 must be expanded now" );
},

testClickAlwaysVisible: function(){
Expand All @@ -276,11 +277,23 @@ YUI({

Y.Event.simulate( iconAlwaysVisible, "click" );

Y.Assert.areSame( true, item2.get( "expanded" ), "Item3 must be exapnded now" );
Y.Assert.areSame( true, item2.get( "expanded" ), "Item3 must be expanded now" );
Y.Assert.areSame( true, item2.get( "alwaysVisible" ), "Item3 must be always visible" );

Y.Assert.areSame( false, item3.get( "expanded" ), "Item3 must be collapsed now" );
}
},

testMouseEnter: function(){
var item0, header;

item0 = that.accordion1.getItem( 0 );

header = Y.Node.getDOMNode(item0.getStdModNode( Y.WidgetStdMod.HEADER ));

Y.Event.simulate( header, "mouseover" );

Y.Assert.areSame( false, item0.get( "expanded" ), "Item0 must be collapsed now" );
}

});

Expand Down

0 comments on commit 3e811c8

Please sign in to comment.