|
| 1 | +// Internal use only |
| 2 | +var escapeSelector = $.ui.escapeSelector = ( function() { |
| 3 | + var selectorEscape = /([!"#$%&'()*+,./:;<=>?@[\]^`{|}~])/g; |
| 4 | + return function( selector ) { |
| 5 | + return selector.replace( selectorEscape, "\\$1" ); |
| 6 | + }; |
| 7 | +} )(); |
| 8 | + |
| 9 | + |
| 10 | +/*! |
| 11 | + * jQuery UI Labels 1.12.1 |
| 12 | + * http://jqueryui.com |
| 13 | + * |
| 14 | + * Copyright jQuery Foundation and other contributors |
| 15 | + * Released under the MIT license. |
| 16 | + * http://jquery.org/license |
| 17 | + */ |
| 18 | + |
| 19 | +//>>label: labels |
| 20 | +//>>group: Core |
| 21 | +//>>description: Find all the labels associated with a given input |
| 22 | +//>>docs: http://api.jqueryui.com/labels/ |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +var labels = $.fn.labels = function() { |
| 27 | + var ancestor, selector, id, labels, ancestors; |
| 28 | + |
| 29 | + // Check control.labels first |
| 30 | + if ( this[ 0 ].labels && this[ 0 ].labels.length ) { |
| 31 | + return this.pushStack( this[ 0 ].labels ); |
| 32 | + } |
| 33 | + |
| 34 | + // Support: IE <= 11, FF <= 37, Android <= 2.3 only |
| 35 | + // Above browsers do not support control.labels. Everything below is to support them |
| 36 | + // as well as document fragments. control.labels does not work on document fragments |
| 37 | + labels = this.eq( 0 ).parents( "label" ); |
| 38 | + |
| 39 | + // Look for the label based on the id |
| 40 | + id = this.attr( "id" ); |
| 41 | + if ( id ) { |
| 42 | + |
| 43 | + // We don't search against the document in case the element |
| 44 | + // is disconnected from the DOM |
| 45 | + ancestor = this.eq( 0 ).parents().last(); |
| 46 | + |
| 47 | + // Get a full set of top level ancestors |
| 48 | + ancestors = ancestor.add( ancestor.length ? ancestor.siblings() : this.siblings() ); |
| 49 | + |
| 50 | + // Create a selector for the label based on the id |
| 51 | + selector = "label[for='" + $.ui.escapeSelector( id ) + "']"; |
| 52 | + |
| 53 | + labels = labels.add( ancestors.find( selector ).addBack( selector ) ); |
| 54 | + |
| 55 | + } |
| 56 | + |
| 57 | + // Return whatever we have found for labels |
| 58 | + return this.pushStack( labels ); |
| 59 | +}; |
0 commit comments