Debian Codegraph @

ui/labels.js

raw symbols SCIP
1 /*!
2 * jQuery UI Labels 1.14.2
3 * https://jqueryui.com
4 *
5 * Copyright OpenJS Foundation and other contributors
6 * Released under the MIT license.
7 * https://jquery.org/license
8 */
9
10 //>>label: labels
11 //>>group: Core
12 //>>description: Find all the labels associated with a given input
13 //>>docs: https://api.jqueryui.com/labels/
14
15 ( function( factory ) {
16 "use strict";
17
18 if ( typeof define === "function" && define.amd ) {
19
20 // AMD. Register as an anonymous module.
21 define( [ "jquery", "./version" ], factory );
22 } else {
23
24 // Browser globals
25 factory( jQuery );
26 }
27 } )( function( $ ) {
28 "use strict";
29
30 return $.fn.labels = function() {
31 var ancestor, selector, id, labels, ancestors;
32
33 if ( !this.length ) {
34 return this.pushStack( [] );
35 }
36
37 // Check control.labels first
38 if ( this[ 0 ].labels && this[ 0 ].labels.length ) {
39 return this.pushStack( this[ 0 ].labels );
40 }
41
42 // If `control.labels` is empty - e.g. inside of document fragments - find
43 // the labels manually
44 labels = this.eq( 0 ).parents( "label" );
45
46 // Look for the label based on the id
47 id = this.attr( "id" );
48 if ( id ) {
49
50 // We don't search against the document in case the element
51 // is disconnected from the DOM
52 ancestor = this.eq( 0 ).parents().last();
53
54 // Get a full set of top level ancestors
55 ancestors = ancestor.add( ancestor.length ? ancestor.siblings() : this.siblings() );
56
57 // Create a selector for the label based on the id
58 selector = "label[for='" + CSS.escape( id ) + "']";
59
60 labels = labels.add( ancestors.find( selector ).addBack( selector ) );
61
62 }
63
64 // Return whatever we have found for labels
65 return this.pushStack( labels );
66 };
67
68 } );