wp/wp-includes/js/jquery/ui/accordion.js
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
     1 /*!
     1 /*!
     2  * jQuery UI Accordion 1.12.1
     2  * jQuery UI Accordion 1.13.1
     3  * http://jqueryui.com
     3  * http://jqueryui.com
     4  *
     4  *
     5  * Copyright jQuery Foundation and other contributors
     5  * Copyright jQuery Foundation and other contributors
     6  * Released under the MIT license.
     6  * Released under the MIT license.
     7  * http://jquery.org/license
     7  * http://jquery.org/license
     8  */
     8  */
     9 
     9 
    10 //>>label: Accordion
    10 //>>label: Accordion
    11 //>>group: Widgets
    11 //>>group: Widgets
    12 // jscs:disable maximumLineLength
    12 /* eslint-disable max-len */
    13 //>>description: Displays collapsible content panels for presenting information in a limited amount of space.
    13 //>>description: Displays collapsible content panels for presenting information in a limited amount of space.
    14 // jscs:enable maximumLineLength
    14 /* eslint-enable max-len */
    15 //>>docs: http://api.jqueryui.com/accordion/
    15 //>>docs: http://api.jqueryui.com/accordion/
    16 //>>demos: http://jqueryui.com/accordion/
    16 //>>demos: http://jqueryui.com/accordion/
    17 //>>css.structure: ../../themes/base/core.css
    17 //>>css.structure: ../../themes/base/core.css
    18 //>>css.structure: ../../themes/base/accordion.css
    18 //>>css.structure: ../../themes/base/accordion.css
    19 //>>css.theme: ../../themes/base/theme.css
    19 //>>css.theme: ../../themes/base/theme.css
    20 
    20 
    21 ( function( factory ) {
    21 ( function( factory ) {
       
    22 	"use strict";
       
    23 
    22 	if ( typeof define === "function" && define.amd ) {
    24 	if ( typeof define === "function" && define.amd ) {
    23 
    25 
    24 		// AMD. Register as an anonymous module.
    26 		// AMD. Register as an anonymous module.
    25 		define( [
    27 		define( [
    26 			"jquery",
    28 			"jquery",
    29 	} else {
    31 	} else {
    30 
    32 
    31 		// Browser globals
    33 		// Browser globals
    32 		factory( jQuery );
    34 		factory( jQuery );
    33 	}
    35 	}
    34 }( function( $ ) {
    36 } )( function( $ ) {
       
    37 "use strict";
    35 
    38 
    36 return $.widget( "ui.accordion", {
    39 return $.widget( "ui.accordion", {
    37 	version: "1.12.1",
    40 	version: "1.13.1",
    38 	options: {
    41 	options: {
    39 		active: 0,
    42 		active: 0,
    40 		animate: {},
    43 		animate: {},
    41 		classes: {
    44 		classes: {
    42 			"ui-accordion-header": "ui-corner-top",
    45 			"ui-accordion-header": "ui-corner-top",
    43 			"ui-accordion-header-collapsed": "ui-corner-all",
    46 			"ui-accordion-header-collapsed": "ui-corner-all",
    44 			"ui-accordion-content": "ui-corner-bottom"
    47 			"ui-accordion-content": "ui-corner-bottom"
    45 		},
    48 		},
    46 		collapsible: false,
    49 		collapsible: false,
    47 		event: "click",
    50 		event: "click",
    48 		header: "> li > :first-child, > :not(li):even",
    51 		header: function( elem ) {
       
    52 			return elem.find( "> li > :first-child" ).add( elem.find( "> :not(li)" ).even() );
       
    53 		},
    49 		heightStyle: "auto",
    54 		heightStyle: "auto",
    50 		icons: {
    55 		icons: {
    51 			activeHeader: "ui-icon-triangle-1-s",
    56 			activeHeader: "ui-icon-triangle-1-s",
    52 			header: "ui-icon-triangle-1-e"
    57 			header: "ui-icon-triangle-1-e"
    53 		},
    58 		},
   197 			length = this.headers.length,
   202 			length = this.headers.length,
   198 			currentIndex = this.headers.index( event.target ),
   203 			currentIndex = this.headers.index( event.target ),
   199 			toFocus = false;
   204 			toFocus = false;
   200 
   205 
   201 		switch ( event.keyCode ) {
   206 		switch ( event.keyCode ) {
   202 		case keyCode.RIGHT:
   207 			case keyCode.RIGHT:
   203 		case keyCode.DOWN:
   208 			case keyCode.DOWN:
   204 			toFocus = this.headers[ ( currentIndex + 1 ) % length ];
   209 				toFocus = this.headers[ ( currentIndex + 1 ) % length ];
   205 			break;
   210 				break;
   206 		case keyCode.LEFT:
   211 			case keyCode.LEFT:
   207 		case keyCode.UP:
   212 			case keyCode.UP:
   208 			toFocus = this.headers[ ( currentIndex - 1 + length ) % length ];
   213 				toFocus = this.headers[ ( currentIndex - 1 + length ) % length ];
   209 			break;
   214 				break;
   210 		case keyCode.SPACE:
   215 			case keyCode.SPACE:
   211 		case keyCode.ENTER:
   216 			case keyCode.ENTER:
   212 			this._eventHandler( event );
   217 				this._eventHandler( event );
   213 			break;
   218 				break;
   214 		case keyCode.HOME:
   219 			case keyCode.HOME:
   215 			toFocus = this.headers[ 0 ];
   220 				toFocus = this.headers[ 0 ];
   216 			break;
   221 				break;
   217 		case keyCode.END:
   222 			case keyCode.END:
   218 			toFocus = this.headers[ length - 1 ];
   223 				toFocus = this.headers[ length - 1 ];
   219 			break;
   224 				break;
   220 		}
   225 		}
   221 
   226 
   222 		if ( toFocus ) {
   227 		if ( toFocus ) {
   223 			$( event.target ).attr( "tabIndex", -1 );
   228 			$( event.target ).attr( "tabIndex", -1 );
   224 			$( toFocus ).attr( "tabIndex", 0 );
   229 			$( toFocus ).attr( "tabIndex", 0 );
   237 		var options = this.options;
   242 		var options = this.options;
   238 		this._processPanels();
   243 		this._processPanels();
   239 
   244 
   240 		// Was collapsed or no panel
   245 		// Was collapsed or no panel
   241 		if ( ( options.active === false && options.collapsible === true ) ||
   246 		if ( ( options.active === false && options.collapsible === true ) ||
   242 				!this.headers.length ) {
   247 			!this.headers.length ) {
   243 			options.active = false;
   248 			options.active = false;
   244 			this.active = $();
   249 			this.active = $();
   245 
   250 
   246 		// active false only when collapsible is true
   251 			// active false only when collapsible is true
   247 		} else if ( options.active === false ) {
   252 		} else if ( options.active === false ) {
   248 			this._activate( 0 );
   253 			this._activate( 0 );
   249 
   254 
   250 		// was active, but active panel is gone
   255 			// was active, but active panel is gone
   251 		} else if ( this.active.length && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {
   256 		} else if ( this.active.length && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {
   252 
   257 
   253 			// all remaining panel are disabled
   258 			// all remaining panel are disabled
   254 			if ( this.headers.length === this.headers.find( ".ui-state-disabled" ).length ) {
   259 			if ( this.headers.length === this.headers.find( ".ui-state-disabled" ).length ) {
   255 				options.active = false;
   260 				options.active = false;
   256 				this.active = $();
   261 				this.active = $();
   257 
   262 
   258 			// activate previous panel
   263 				// activate previous panel
   259 			} else {
   264 			} else {
   260 				this._activate( Math.max( 0, options.active - 1 ) );
   265 				this._activate( Math.max( 0, options.active - 1 ) );
   261 			}
   266 			}
   262 
   267 
   263 		// was active, active panel still exists
   268 			// was active, active panel still exists
   264 		} else {
   269 		} else {
   265 
   270 
   266 			// make sure active index is correct
   271 			// make sure active index is correct
   267 			options.active = this.headers.index( this.active );
   272 			options.active = this.headers.index( this.active );
   268 		}
   273 		}
   274 
   279 
   275 	_processPanels: function() {
   280 	_processPanels: function() {
   276 		var prevHeaders = this.headers,
   281 		var prevHeaders = this.headers,
   277 			prevPanels = this.panels;
   282 			prevPanels = this.panels;
   278 
   283 
   279 		this.headers = this.element.find( this.options.header );
   284 		if ( typeof this.options.header === "function" ) {
       
   285 			this.headers = this.options.header( this.element );
       
   286 		} else {
       
   287 			this.headers = this.element.find( this.options.header );
       
   288 		}
   280 		this._addClass( this.headers, "ui-accordion-header ui-accordion-header-collapsed",
   289 		this._addClass( this.headers, "ui-accordion-header ui-accordion-header-collapsed",
   281 			"ui-state-default" );
   290 			"ui-state-default" );
   282 
   291 
   283 		this.panels = this.headers.next().filter( ":not(.ui-accordion-content-active)" ).hide();
   292 		this.panels = this.headers.next().filter( ":not(.ui-accordion-content-active)" ).hide();
   284 		this._addClass( this.panels, "ui-accordion-content", "ui-helper-reset ui-widget-content" );
   293 		this._addClass( this.panels, "ui-accordion-content", "ui-helper-reset ui-widget-content" );
   311 					panelId = panel.uniqueId().attr( "id" );
   320 					panelId = panel.uniqueId().attr( "id" );
   312 				header.attr( "aria-controls", panelId );
   321 				header.attr( "aria-controls", panelId );
   313 				panel.attr( "aria-labelledby", headerId );
   322 				panel.attr( "aria-labelledby", headerId );
   314 			} )
   323 			} )
   315 			.next()
   324 			.next()
   316 				.attr( "role", "tabpanel" );
   325 			.attr( "role", "tabpanel" );
   317 
   326 
   318 		this.headers
   327 		this.headers
   319 			.not( this.active )
   328 			.not( this.active )
   320 				.attr( {
   329 			.attr( {
   321 					"aria-selected": "false",
   330 				"aria-selected": "false",
   322 					"aria-expanded": "false",
   331 				"aria-expanded": "false",
   323 					tabIndex: -1
   332 				tabIndex: -1
   324 				} )
   333 			} )
   325 				.next()
   334 			.next()
   326 					.attr( {
   335 			.attr( {
   327 						"aria-hidden": "true"
   336 				"aria-hidden": "true"
   328 					} )
   337 			} )
   329 					.hide();
   338 			.hide();
   330 
   339 
   331 		// Make sure at least one header is in the tab order
   340 		// Make sure at least one header is in the tab order
   332 		if ( !this.active.length ) {
   341 		if ( !this.active.length ) {
   333 			this.headers.eq( 0 ).attr( "tabIndex", 0 );
   342 			this.headers.eq( 0 ).attr( "tabIndex", 0 );
   334 		} else {
   343 		} else {
   336 				"aria-selected": "true",
   345 				"aria-selected": "true",
   337 				"aria-expanded": "true",
   346 				"aria-expanded": "true",
   338 				tabIndex: 0
   347 				tabIndex: 0
   339 			} )
   348 			} )
   340 				.next()
   349 				.next()
   341 					.attr( {
   350 				.attr( {
   342 						"aria-hidden": "false"
   351 					"aria-hidden": "false"
   343 					} );
   352 				} );
   344 		}
   353 		}
   345 
   354 
   346 		this._createIcons();
   355 		this._createIcons();
   347 
   356 
   348 		this._setupEvents( options.event );
   357 		this._setupEvents( options.event );
   443 
   452 
   444 		event.preventDefault();
   453 		event.preventDefault();
   445 
   454 
   446 		if (
   455 		if (
   447 
   456 
   448 				// click on active header, but not collapsible
   457 			// click on active header, but not collapsible
   449 				( clickedIsActive && !options.collapsible ) ||
   458 			( clickedIsActive && !options.collapsible ) ||
   450 
   459 
   451 				// allow canceling activation
   460 			// allow canceling activation
   452 				( this._trigger( "beforeActivate", event, eventData ) === false ) ) {
   461 			( this._trigger( "beforeActivate", event, eventData ) === false ) ) {
   453 			return;
   462 			return;
   454 		}
   463 		}
   455 
   464 
   456 		options.active = collapsing ? false : this.headers.index( clicked );
   465 		options.active = collapsing ? false : this.headers.index( clicked );
   457 
   466 
   523 		}
   532 		}
   524 
   533 
   525 		toShow
   534 		toShow
   526 			.attr( "aria-hidden", "false" )
   535 			.attr( "aria-hidden", "false" )
   527 			.prev()
   536 			.prev()
   528 				.attr( {
   537 			.attr( {
   529 					"aria-selected": "true",
   538 				"aria-selected": "true",
   530 					"aria-expanded": "true",
   539 				"aria-expanded": "true",
   531 					tabIndex: 0
   540 				tabIndex: 0
   532 				} );
   541 			} );
   533 	},
   542 	},
   534 
   543 
   535 	_animate: function( toShow, toHide, data ) {
   544 	_animate: function( toShow, toHide, data ) {
   536 		var total, easing, duration,
   545 		var total, easing, duration,
   537 			that = this,
   546 			that = this,
   605 		}
   614 		}
   606 		this._trigger( "activate", null, data );
   615 		this._trigger( "activate", null, data );
   607 	}
   616 	}
   608 } );
   617 } );
   609 
   618 
   610 } ) );
   619 } );