MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 228: | Line 228: | ||
/** | /** | ||
* Quick Search — | * Quick Search — DEBUG v2 | ||
* | * Focused on finding the right event for OOUI autocomplete selection | ||
*/ | */ | ||
(function () { | (function () { | ||
| Line 243: | Line 236: | ||
if (mw.config.get('wgPageName') !== 'Main_Page') return; | if (mw.config.get('wgPageName') !== 'Main_Page') return; | ||
function | function init() { | ||
var container = document.getElementById('crt-quick-search'); | |||
if ( | if (!container) return; | ||
var form = container.querySelector('form'); | |||
var | if (!form) return; | ||
if (! | |||
var | // Wait for OOUI to create the input | ||
function trySetup() { | |||
// OOUI creates input with this class | |||
var input = container.querySelector('input.oo-ui-inputWidget-input, .pfFormInputWrapper input:not([type="hidden"])'); | |||
if (!input) return false; | |||
console.log('[QS] Found input:', input, 'classes:', input.className); | |||
// Log ALL events on the input to find the right one | |||
['change', 'input', 'blur', 'focus', 'select'].forEach(function (evt) { | |||
input.addEventListener(evt, function (e) { | |||
console.log('[QS] Native event:', evt, '| value:', JSON.stringify(input.value)); | |||
}); | }); | ||
}); | |||
// jQuery events that PF/OOUI might use | |||
var $input = $(input); | |||
$input.on('change input blur select autocompleteselect autocompleteclose pfautocomplete', function (e) { | |||
console.log('[QS] jQuery event:', e.type, '| value:', JSON.stringify(input.value)); | |||
}); | |||
// Look for OOUI widget instance | |||
// | var $wrapper = $(container).find('.pfFormInputWrapper'); | ||
console.log('[QS] pfFormInputWrapper:', $wrapper.length ? $wrapper[0] : 'not found'); | |||
var | |||
// Check if there's an OOUI widget attached | |||
var widget = OO && OO.ui ? OO.ui.infuse && $wrapper.find('.oo-ui-widget')[0] : null; | |||
console.log('[QS] OO.ui available:', typeof OO !== 'undefined' && !!OO.ui); | |||
// Use event delegation to catch clicks on autocomplete menu items | |||
// OOUI menus are often appended to <body>, not inside the container | |||
$(document.body).on('click', '.oo-ui-menuOptionWidget, .oo-ui-optionWidget, .ui-menu-item, .pf-autocomplete-item, .autocomplete-suggestion', function (e) { | |||
var text = $(this).text().trim(); | |||
console.log('[QS] Autocomplete item clicked! Text:', JSON.stringify(text)); | |||
// After PF updates the input value: | |||
setTimeout(function () { | |||
console.log('[QS] Input value after click:', JSON.stringify(input.value)); | |||
}, 100); | |||
}); | |||
// Also watch for any new elements appearing (the dropdown) | |||
console.log('[QS] Searching for any autocomplete-related elements...'); | |||
setTimeout(function () { | |||
// Log all elements with autocomplete-related classes | |||
var candidates = document.querySelectorAll('[class*="autocomplete"], [class*="menu"], [class*="lookup"], [class*="suggestion"]'); | |||
candidates.forEach(function (el) { | |||
console.log('[QS] Candidate element:', el.tagName, el.className.substring(0, 100)); | |||
}); | |||
}, 3000); | |||
// Form submit still works | |||
form.addEventListener('submit', function (e) { | |||
e.preventDefault(); | |||
e.stopPropagation(); | |||
var value = input.value.trim(); | |||
console.log('[QS] Form submit, value:', JSON.stringify(value)); | |||
if (value) { | |||
window.location.href = mw.util.getUrl(value); | |||
} | |||
}); | |||
console.log('[QS] Debug setup complete. Type something and click a suggestion.'); | |||
return true; | |||
} | |||
if (!trySetup()) { | |||
var observer = new MutationObserver(function (mutations, obs) { | |||
if (trySetup()) obs.disconnect(); | |||
}); | |||
observer.observe(container, { childList: true, subtree: true }); | |||
setTimeout(function () { observer.disconnect(); }, 10000); | |||
} | |||
} | } | ||