Sbisson has uploaded a new change for review. https://gerrit.wikimedia.org/r/249095
Change subject: Add jquery.findWithParent to Thanks ...................................................................... Add jquery.findWithParent to Thanks Thanks has an implicit dependency on jquery.findWithParent. It often fails because it is not yet loaded. Adding it locally so it is self-contained. It is not Flow's responsibility to provide such low-level utilities to other extensions. Bug: T116146 Change-Id: Id74e77b5fb81d5da8cb6dd97fd1b90e5d974ae82 --- M Thanks.php A modules/jquery.findWithParent.js 2 files changed, 65 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Thanks refs/changes/95/249095/1 diff --git a/Thanks.php b/Thanks.php index 7db58ae..9f71567 100644 --- a/Thanks.php +++ b/Thanks.php @@ -129,6 +129,13 @@ 'localBasePath' => __DIR__ . '/modules', 'remoteExtPath' => 'Thanks/modules', ); +$wgResourceModules['jquery.findWithParent'] = array( + 'scripts' => array( + 'jquery.findWithParent.js', + ), + 'localBasePath' => __DIR__ . '/modules', + 'remoteExtPath' => 'Thanks/modules', +); $wgResourceModules['ext.thanks.flowthank'] = array( 'scripts' => array( 'ext.thanks.flowthank.js', @@ -139,6 +146,7 @@ 'thanks-error-ratelimited', ), 'dependencies' => array( + 'jquery.findWithParent', 'mediawiki.jqueryMsg', 'mediawiki.api', 'ext.thanks', diff --git a/modules/jquery.findWithParent.js b/modules/jquery.findWithParent.js new file mode 100644 index 0000000..99011a8 --- /dev/null +++ b/modules/jquery.findWithParent.js @@ -0,0 +1,57 @@ +( function ( $ ) { + /** @class jQuery */ + + /** + * Gives support to find parent elements using .closest with less-than selector syntax. + * + * $.findWithParent( $div, "< html div < body" ); // find closest parent of $div "html", find child "div" of it, find closest parent "body" of that, return "body" + * $( '#foo' ).findWithParent( '.bar < .baz' ); // find child ".bar" of "#foo", return closest parent ".baz" from there + * + * @method findWithParent + * @param {jQuery|HTMLElement|string} $context + * @param {string} selector + * @return {jQuery} + */ + function jQueryFindWithParent( $context, selector ) { + var matches; + + $context = $( $context ); + selector = $.trim( selector ); + + while ( selector && ( matches = selector.match( /(.*?(?:^|[>\s+~]))(<\s*[^>\s+~]+)(.*?)$/ ) ) ) { + if ( $.trim( matches[ 1 ] ) ) { + $context = $context.find( matches[ 1 ] ); + } + if ( $.trim( matches[ 2 ] ) ) { + $context = $context.closest( matches[ 2 ].substr( 1 ) ); + } + selector = $.trim( matches[ 3 ] ); + } + + if ( selector ) { + $context = $context.find( selector ); + } + + return $context; + } + + $.findWithParent = jQueryFindWithParent; + + /** @class jQuery.fn */ + /** + * @param {string} selector + * @return {jQuery} + * @see jQuery#findWithParent + */ + $.fn.findWithParent = function ( selector ) { + var selectors = selector.split( ',' ), + $elements = $(), + self = this; + + $.each( selectors, function ( i, selector ) { + $elements = $elements.add( jQueryFindWithParent( self, selector ) ); + } ); + + return $elements; + }; +}( jQuery ) ); -- To view, visit https://gerrit.wikimedia.org/r/249095 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id74e77b5fb81d5da8cb6dd97fd1b90e5d974ae82 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Thanks Gerrit-Branch: master Gerrit-Owner: Sbisson <sbis...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits