Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T11831: fix searching #450

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() );
}

} );
}() );
Loading