Skip to content

Commit f73d421

Browse files
committed
Accordion: Split out navigation options into an extension. Fixes #5869 - Accordion: Deprecate navigation options.
1 parent ca0ac5a commit f73d421

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

ui/jquery.ui.accordion.js

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ $.widget( "ui.accordion", {
2626
icons: {
2727
header: "ui-icon-triangle-1-e",
2828
headerSelected: "ui-icon-triangle-1-s"
29-
},
30-
navigation: false,
31-
navigationFilter: function() {
32-
return this.href.toLowerCase() === location.href.toLowerCase();
3329
}
3430
},
3531

@@ -77,20 +73,6 @@ $.widget( "ui.accordion", {
7773
.addClass( "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" );
7874
self.headers.find( ":first-child" ).addClass( "ui-accordion-heading" );
7975

80-
if ( options.navigation ) {
81-
var current = self.element.find( "a" ).filter( options.navigationFilter ).eq( 0 );
82-
if ( current.length ) {
83-
var header = current.closest( ".ui-accordion-header" );
84-
if ( header.length ) {
85-
// anchor within header
86-
self.active = header;
87-
} else {
88-
// anchor within content
89-
self.active = current.closest( ".ui-accordion-content" ).prev();
90-
}
91-
}
92-
}
93-
9476
self.active = self._findActive( self.active || options.active )
9577
.addClass( "ui-state-default ui-state-active" )
9678
.toggleClass( "ui-corner-all" )
@@ -598,4 +580,40 @@ $.extend( $.ui.accordion, {
598580
}
599581
});
600582

583+
584+
585+
// DEPRECATED
586+
587+
// navigation options
588+
(function( $, prototype ) {
589+
$.extend( prototype.options, {
590+
navigation: false,
591+
navigationFilter: function() {
592+
return this.href.toLowerCase() === location.href.toLowerCase();
593+
}
594+
});
595+
596+
var _create = prototype._create;
597+
prototype._create = function() {
598+
if ( this.options.navigation ) {
599+
var self = this,
600+
headers = this.element.find( this.options.header ),
601+
content = headers.next();
602+
current = headers.add( content )
603+
.find( "a" )
604+
.filter( this.options.navigationFilter )
605+
[ 0 ];
606+
if ( current ) {
607+
headers.add( content ).each( function( index ) {
608+
if ( $.contains( this, current ) ) {
609+
self.options.active = Math.floor( index / 2 );
610+
return false;
611+
}
612+
});
613+
}
614+
}
615+
_create.call( this );
616+
};
617+
}( jQuery, jQuery.ui.accordion.prototype ));
618+
601619
})( jQuery );

0 commit comments

Comments
 (0)