Skip to content

Commit

Permalink
T11831: fix searching (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Universal-Omega authored Feb 9, 2024
1 parent 0bca25d commit 0a3417c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 0 additions & 2 deletions modules/ext.managewiki.oouiform.styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
}

.oo-ui-tabPanelLayout.managewiki-search-matched {
display: block !important;

> fieldset > legend {
max-width: none;
padding: 5px 10px;
Expand Down
22 changes: 15 additions & 7 deletions modules/ext.managewiki.oouiform.tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,23 @@
var index, texts;
function buildIndex() {
index = {};
var $fields = tabs.contentPanel.$element.find(
'[class^=mw-htmlform-field-]:not( .managewiki-search-noindex )'
var $fields = tabs.contentPanel.$element.find( '[class^=mw-htmlform-field-]:not( .managewiki-search-noindex )' );
var $descFields = $fields.filter(
'.oo-ui-fieldsetLayout-group > .oo-ui-widget > .mw-htmlform-field-HTMLInfoField'
);
$fields.each( function () {
$fields.not( $descFields ).each( function () {
var $field = $( this );
var $wrapper = $field.parents( '.managewiki-fieldset-wrapper' );
var $tabPanel = $field.closest( '.oo-ui-tabPanelLayout' );
var $labels = $field.find(
'.oo-ui-labelElement-label, .oo-ui-textInputWidget .oo-ui-inputWidget-input, p'
).add(
$wrapper.find( '> .oo-ui-fieldsetLayout > .oo-ui-fieldsetLayout-header .oo-ui-labelElement-label' )
);
$field = $field.add( $tabPanel.find( $descFields ) );

function addToIndex( $label, $highlight ) {
var text = $label.val() || $label[ 0 ].innerText.toLowerCase().trim().replace( /\s+/, ' ' );
var text = $label.val() || $label[ 0 ].textContent.toLowerCase().trim().replace( /\s+/, ' ' );
if ( text ) {
index[ text ] = index[ text ] || [];
index[ text ].push( {
Expand All @@ -132,9 +139,7 @@
}
}

$field.find( '.oo-ui-labelElement-label, .oo-ui-textInputWidget .oo-ui-inputWidget-input, p' ).add(
$wrapper.find( '> .oo-ui-fieldsetLayout > .oo-ui-fieldsetLayout-header .oo-ui-labelElement-label' )
).each( function () {
$labels.each( function () {
addToIndex( $( this ) );

// Check if there we are in an infusable dropdown and collect other options
Expand All @@ -155,6 +160,7 @@
mw.hook( 'managewiki.search.buildIndex' ).fire( index );
texts = Object.keys( index );
}

function infuseAllPanels() {
tabs.stackLayout.items.forEach( function ( tabPanel ) {
var wasVisible = tabPanel.isVisible();
Expand Down Expand Up @@ -188,6 +194,7 @@
tabs.$element.toggleClass( 'managewiki-tabs-searching', isSearching );
tabs.tabSelectWidget.toggle( !isSearching );
tabs.contentPanel.setContinuous( isSearching );

$( '.managewiki-search-matched' ).removeClass( 'managewiki-search-matched' );
$( '.managewiki-search-highlight' ).removeClass( 'managewiki-search-highlight' );
var hasResults = false;
Expand Down Expand Up @@ -219,5 +226,6 @@
if ( search.getValue() ) {
search.emit( 'change', search.getValue() );
}

} );
}() );

0 comments on commit 0a3417c

Please sign in to comment.