| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
function jQueryFindWithParent( $context, selector ) { |
| 16 |
$context = $( $context ); |
| 17 |
selector = selector.trim(); |
| 18 |
|
| 19 |
let matches; |
| 20 |
while ( selector && ( matches = selector.match( /(.*?(?:^|[>\s+~]))(<\s*[^>\s+~]+)(.*?)$/ ) ) ) { |
| 21 |
if ( matches[ 1 ].trim() ) { |
| 22 |
$context = $context.find( matches[ 1 ] ); |
| 23 |
} |
| 24 |
if ( matches[ 2 ].trim() ) { |
| 25 |
$context = $context.closest( matches[ 2 ].slice( 1 ) ); |
| 26 |
} |
| 27 |
selector = matches[ 3 ].trim(); |
| 28 |
} |
| 29 |
|
| 30 |
if ( selector ) { |
| 31 |
$context = $context.find( selector ); |
| 32 |
} |
| 33 |
|
| 34 |
return $context; |
| 35 |
} |
| 36 |
|
| 37 |
$.findWithParent = jQueryFindWithParent; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
$.fn.findWithParent = function ( selector ) { |
| 46 |
const selectors = selector.split( ',' ); |
| 47 |
let $elements = $(); |
| 48 |
|
| 49 |
selectors.forEach( ( sel ) => { |
| 50 |
$elements = $elements.add( jQueryFindWithParent( this, sel ) ); |
| 51 |
} ); |
| 52 |
|
| 53 |
return $elements; |
| 54 |
}; |
| 55 |
}() ); |