2015-07-15 22:14:26 +00:00
|
|
|
/*!
|
|
|
|
* jQuery UI Labels @VERSION
|
2024-04-26 14:25:34 +00:00
|
|
|
* https://jqueryui.com
|
2015-07-15 22:14:26 +00:00
|
|
|
*
|
2022-07-19 07:36:55 +00:00
|
|
|
* Copyright OpenJS Foundation and other contributors
|
2015-07-15 22:14:26 +00:00
|
|
|
* Released under the MIT license.
|
2024-04-26 14:25:34 +00:00
|
|
|
* https://jquery.org/license
|
2015-07-15 22:14:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
//>>label: labels
|
|
|
|
//>>group: Core
|
|
|
|
//>>description: Find all the labels associated with a given input
|
2024-04-26 14:25:34 +00:00
|
|
|
//>>docs: https://api.jqueryui.com/labels/
|
2015-07-15 22:14:26 +00:00
|
|
|
|
|
|
|
( function( factory ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
|
|
|
|
2015-07-15 22:14:26 +00:00
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
2021-05-14 21:37:19 +00:00
|
|
|
define( [ "jquery", "./version" ], factory );
|
2015-07-15 22:14:26 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
2021-06-06 22:58:12 +00:00
|
|
|
} )( function( $ ) {
|
|
|
|
"use strict";
|
2015-07-15 22:14:26 +00:00
|
|
|
|
|
|
|
return $.fn.labels = function() {
|
|
|
|
var ancestor, selector, id, labels, ancestors;
|
|
|
|
|
2017-05-02 16:42:49 +00:00
|
|
|
if ( !this.length ) {
|
|
|
|
return this.pushStack( [] );
|
|
|
|
}
|
|
|
|
|
2015-07-15 22:14:26 +00:00
|
|
|
// Check control.labels first
|
|
|
|
if ( this[ 0 ].labels && this[ 0 ].labels.length ) {
|
|
|
|
return this.pushStack( this[ 0 ].labels );
|
|
|
|
}
|
|
|
|
|
2024-04-30 22:54:19 +00:00
|
|
|
// If `control.labels` is empty - e.g. inside of document fragments - find
|
|
|
|
// the labels manually
|
2015-07-15 22:14:26 +00:00
|
|
|
labels = this.eq( 0 ).parents( "label" );
|
|
|
|
|
|
|
|
// Look for the label based on the id
|
|
|
|
id = this.attr( "id" );
|
|
|
|
if ( id ) {
|
|
|
|
|
|
|
|
// We don't search against the document in case the element
|
|
|
|
// is disconnected from the DOM
|
|
|
|
ancestor = this.eq( 0 ).parents().last();
|
|
|
|
|
|
|
|
// Get a full set of top level ancestors
|
|
|
|
ancestors = ancestor.add( ancestor.length ? ancestor.siblings() : this.siblings() );
|
|
|
|
|
|
|
|
// Create a selector for the label based on the id
|
2024-05-10 12:45:59 +00:00
|
|
|
selector = "label[for='" + CSS.escape( id ) + "']";
|
2015-07-15 22:14:26 +00:00
|
|
|
|
|
|
|
labels = labels.add( ancestors.find( selector ).addBack( selector ) );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return whatever we have found for labels
|
|
|
|
return this.pushStack( labels );
|
|
|
|
};
|
|
|
|
|
2021-06-06 22:58:12 +00:00
|
|
|
} );
|