| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
( function( factory ) { |
| 16 |
"use strict"; |
| 17 |
|
| 18 |
if ( typeof define === "function" && define.amd ) { |
| 19 |
|
| 20 |
|
| 21 |
define( [ "jquery", "./version" ], factory ); |
| 22 |
} else { |
| 23 |
|
| 24 |
|
| 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 |
|
| 38 |
if ( this[ 0 ].labels && this[ 0 ].labels.length ) { |
| 39 |
return this.pushStack( this[ 0 ].labels ); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
labels = this.eq( 0 ).parents( "label" ); |
| 45 |
|
| 46 |
|
| 47 |
id = this.attr( "id" ); |
| 48 |
if ( id ) { |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
ancestor = this.eq( 0 ).parents().last(); |
| 53 |
|
| 54 |
|
| 55 |
ancestors = ancestor.add( ancestor.length ? ancestor.siblings() : this.siblings() ); |
| 56 |
|
| 57 |
|
| 58 |
selector = "label[for='" + CSS.escape( id ) + "']"; |
| 59 |
|
| 60 |
labels = labels.add( ancestors.find( selector ).addBack( selector ) ); |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
return this.pushStack( labels ); |
| 66 |
}; |
| 67 |
|
| 68 |
} ); |