2015-04-03 19:24:09 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-04-03 19:24:09 +00:00
|
|
|
"ui/accordion"
|
2015-04-07 14:30:07 +00:00
|
|
|
], function( $, testHelper ) {
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
var setupTeardown = testHelper.setupTeardown,
|
|
|
|
state = testHelper.state;
|
2012-04-19 15:37:33 +00:00
|
|
|
|
|
|
|
module( "accordion: events", setupTeardown() );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2012-01-31 16:46:31 +00:00
|
|
|
test( "create", function() {
|
2013-03-15 10:45:38 +00:00
|
|
|
expect( 10 );
|
2012-01-31 16:46:31 +00:00
|
|
|
|
|
|
|
var element = $( "#list1" ),
|
|
|
|
headers = element.children( "h3" ),
|
|
|
|
contents = headers.next();
|
|
|
|
|
|
|
|
element.accordion({
|
|
|
|
create: function( event, ui ) {
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.header.length, 1, "header length" );
|
2012-01-31 16:46:31 +00:00
|
|
|
strictEqual( ui.header[ 0 ], headers[ 0 ], "header" );
|
2013-01-22 14:19:04 +00:00
|
|
|
equal( ui.panel.length, 1, "panel length" );
|
|
|
|
strictEqual( ui.panel[ 0 ], contents[ 0 ], "panel" );
|
2012-01-31 16:46:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
element.accordion( "destroy" );
|
|
|
|
|
|
|
|
element.accordion({
|
|
|
|
active: 2,
|
|
|
|
create: function( event, ui ) {
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.header.length, 1, "header length" );
|
2012-01-31 16:46:31 +00:00
|
|
|
strictEqual( ui.header[ 0 ], headers[ 2 ], "header" );
|
2013-01-22 14:19:04 +00:00
|
|
|
equal( ui.panel.length, 1, "panel length" );
|
|
|
|
strictEqual( ui.panel[ 0 ], contents[ 2 ], "panel" );
|
2012-01-31 16:46:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
element.accordion( "destroy" );
|
|
|
|
|
|
|
|
element.accordion({
|
|
|
|
active: false,
|
|
|
|
collapsible: true,
|
|
|
|
create: function( event, ui ) {
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.header.length, 0, "header length" );
|
2013-01-22 14:19:04 +00:00
|
|
|
equal( ui.panel.length, 0, "panel length" );
|
2012-01-31 16:46:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
element.accordion( "destroy" );
|
|
|
|
});
|
|
|
|
|
2011-01-25 05:05:55 +00:00
|
|
|
test( "beforeActivate", function() {
|
2011-04-04 16:00:04 +00:00
|
|
|
expect( 38 );
|
2011-04-15 15:29:26 +00:00
|
|
|
var element = $( "#list1" ).accordion({
|
2012-04-19 14:50:09 +00:00
|
|
|
active: false,
|
|
|
|
collapsible: true
|
|
|
|
}),
|
|
|
|
headers = element.find( ".ui-accordion-header" ),
|
|
|
|
content = element.find( ".ui-accordion-content" );
|
2011-01-25 03:40:03 +00:00
|
|
|
|
2011-04-15 15:29:26 +00:00
|
|
|
element.one( "accordionbeforeactivate", function( event, ui ) {
|
2011-04-04 15:53:19 +00:00
|
|
|
ok( !( "originalEvent" in event ) );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.oldHeader.length, 0 );
|
2012-05-30 12:40:03 +00:00
|
|
|
equal( ui.oldPanel.length, 0 );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.newHeader.length, 1 );
|
2011-01-25 03:40:03 +00:00
|
|
|
strictEqual( ui.newHeader[ 0 ], headers[ 0 ] );
|
2012-05-30 12:40:03 +00:00
|
|
|
equal( ui.newPanel.length, 1 );
|
|
|
|
strictEqual( ui.newPanel[ 0 ], content[ 0 ] );
|
2012-04-19 15:37:33 +00:00
|
|
|
state( element, 0, 0, 0 );
|
2011-01-25 03:40:03 +00:00
|
|
|
});
|
2011-04-15 15:29:26 +00:00
|
|
|
element.accordion( "option", "active", 0 );
|
2012-04-19 15:37:33 +00:00
|
|
|
state( element, 1, 0, 0 );
|
2011-01-25 03:40:03 +00:00
|
|
|
|
2011-04-15 15:29:26 +00:00
|
|
|
element.one( "accordionbeforeactivate", function( event, ui ) {
|
2011-06-13 14:54:47 +00:00
|
|
|
equal( event.originalEvent.type, "click" );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.oldHeader.length, 1 );
|
2011-01-25 03:40:03 +00:00
|
|
|
strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] );
|
2012-05-30 12:40:03 +00:00
|
|
|
equal( ui.oldPanel.length, 1 );
|
|
|
|
strictEqual( ui.oldPanel[ 0 ], content[ 0 ] );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.newHeader.length, 1 );
|
2011-01-25 03:40:03 +00:00
|
|
|
strictEqual( ui.newHeader[ 0 ], headers[ 1 ] );
|
2012-05-30 12:40:03 +00:00
|
|
|
equal( ui.newPanel.length, 1 );
|
|
|
|
strictEqual( ui.newPanel[ 0 ], content[ 1 ] );
|
2012-04-19 15:37:33 +00:00
|
|
|
state( element, 1, 0, 0 );
|
2011-01-25 03:40:03 +00:00
|
|
|
});
|
|
|
|
headers.eq( 1 ).click();
|
2012-04-19 15:37:33 +00:00
|
|
|
state( element, 0, 1, 0 );
|
2011-01-25 03:40:03 +00:00
|
|
|
|
2011-04-15 15:29:26 +00:00
|
|
|
element.one( "accordionbeforeactivate", function( event, ui ) {
|
2011-04-04 15:53:19 +00:00
|
|
|
ok( !( "originalEvent" in event ) );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.oldHeader.length, 1 );
|
2011-01-25 03:40:03 +00:00
|
|
|
strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] );
|
2012-05-30 12:40:03 +00:00
|
|
|
equal( ui.oldPanel.length, 1 );
|
|
|
|
strictEqual( ui.oldPanel[ 0 ], content[ 1 ] );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.newHeader.length, 0 );
|
2012-05-30 12:40:03 +00:00
|
|
|
equal( ui.newPanel.length, 0 );
|
2012-04-19 15:37:33 +00:00
|
|
|
state( element, 0, 1, 0 );
|
2011-01-25 03:40:03 +00:00
|
|
|
});
|
2011-04-15 15:29:26 +00:00
|
|
|
element.accordion( "option", "active", false );
|
2012-04-19 15:37:33 +00:00
|
|
|
state( element, 0, 0, 0 );
|
2011-01-25 05:52:42 +00:00
|
|
|
|
2011-04-15 15:29:26 +00:00
|
|
|
element.one( "accordionbeforeactivate", function( event, ui ) {
|
2011-04-04 15:53:19 +00:00
|
|
|
ok( !( "originalEvent" in event ) );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.oldHeader.length, 0 );
|
2012-05-30 12:40:03 +00:00
|
|
|
equal( ui.oldPanel.length, 0 );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.newHeader.length, 1 );
|
2011-01-25 05:52:42 +00:00
|
|
|
strictEqual( ui.newHeader[ 0 ], headers[ 2 ] );
|
2012-05-30 12:40:03 +00:00
|
|
|
equal( ui.newPanel.length, 1 );
|
|
|
|
strictEqual( ui.newPanel[ 0 ], content[ 2 ] );
|
2011-01-25 05:52:42 +00:00
|
|
|
event.preventDefault();
|
2012-04-19 15:37:33 +00:00
|
|
|
state( element, 0, 0, 0 );
|
2011-01-25 05:52:42 +00:00
|
|
|
});
|
2011-04-15 15:29:26 +00:00
|
|
|
element.accordion( "option", "active", 2 );
|
2012-04-19 15:37:33 +00:00
|
|
|
state( element, 0, 0, 0 );
|
2011-01-25 03:40:03 +00:00
|
|
|
});
|
|
|
|
|
2011-01-25 05:05:55 +00:00
|
|
|
test( "activate", function() {
|
2011-04-04 19:26:32 +00:00
|
|
|
expect( 21 );
|
2011-04-15 15:29:26 +00:00
|
|
|
var element = $( "#list1" ).accordion({
|
2012-04-19 14:50:09 +00:00
|
|
|
active: false,
|
|
|
|
collapsible: true
|
|
|
|
}),
|
|
|
|
headers = element.find( ".ui-accordion-header" ),
|
|
|
|
content = element.find( ".ui-accordion-content" );
|
2011-01-25 03:40:03 +00:00
|
|
|
|
2011-04-15 15:29:26 +00:00
|
|
|
element.one( "accordionactivate", function( event, ui ) {
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.oldHeader.length, 0 );
|
2012-05-30 12:40:03 +00:00
|
|
|
equal( ui.oldPanel.length, 0 );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.newHeader.length, 1 );
|
2011-01-25 03:40:03 +00:00
|
|
|
strictEqual( ui.newHeader[ 0 ], headers[ 0 ] );
|
2012-05-30 12:40:03 +00:00
|
|
|
equal( ui.newPanel.length, 1 );
|
|
|
|
strictEqual( ui.newPanel[ 0 ], content[ 0 ] );
|
2011-01-25 03:40:03 +00:00
|
|
|
});
|
2011-04-15 15:29:26 +00:00
|
|
|
element.accordion( "option", "active", 0 );
|
2011-01-25 03:40:03 +00:00
|
|
|
|
2011-04-15 15:29:26 +00:00
|
|
|
element.one( "accordionactivate", function( event, ui ) {
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.oldHeader.length, 1 );
|
2011-01-25 03:40:03 +00:00
|
|
|
strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] );
|
2012-05-30 12:40:03 +00:00
|
|
|
equal( ui.oldPanel.length, 1 );
|
|
|
|
strictEqual( ui.oldPanel[ 0 ], content[ 0 ] );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.newHeader.length, 1 );
|
2011-01-25 03:40:03 +00:00
|
|
|
strictEqual( ui.newHeader[ 0 ], headers[ 1 ] );
|
2012-05-30 12:40:03 +00:00
|
|
|
equal( ui.newPanel.length, 1 );
|
|
|
|
strictEqual( ui.newPanel[ 0 ], content[ 1 ] );
|
2011-01-25 03:40:03 +00:00
|
|
|
});
|
|
|
|
headers.eq( 1 ).click();
|
|
|
|
|
2011-04-15 15:29:26 +00:00
|
|
|
element.one( "accordionactivate", function( event, ui ) {
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.oldHeader.length, 1 );
|
2011-01-25 03:40:03 +00:00
|
|
|
strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] );
|
2012-05-30 12:40:03 +00:00
|
|
|
equal( ui.oldPanel.length, 1 );
|
|
|
|
strictEqual( ui.oldPanel[ 0 ], content[ 1 ] );
|
2012-04-23 18:25:23 +00:00
|
|
|
equal( ui.newHeader.length, 0 );
|
2012-05-30 12:40:03 +00:00
|
|
|
equal( ui.newPanel.length, 0 );
|
2011-01-25 03:40:03 +00:00
|
|
|
});
|
2011-04-15 15:29:26 +00:00
|
|
|
element.accordion( "option", "active", false );
|
2011-04-04 19:26:32 +00:00
|
|
|
|
|
|
|
// prevent activation
|
2011-04-15 15:29:26 +00:00
|
|
|
element.one( "accordionbeforeactivate", function( event ) {
|
2011-04-04 19:26:32 +00:00
|
|
|
ok( true );
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
2011-04-15 15:29:26 +00:00
|
|
|
element.one( "accordionactivate", function() {
|
2011-04-04 19:26:32 +00:00
|
|
|
ok( false );
|
|
|
|
});
|
2011-04-15 15:29:26 +00:00
|
|
|
element.accordion( "option", "active", 1 );
|
2009-02-02 14:36:08 +00:00
|
|
|
});
|
|
|
|
|
2015-04-03 19:24:09 +00:00
|
|
|
} );
|