Avoid console warning when hash is empty

Bug: T272844
Change-Id: I82ed4ade24ed9e61e654cc7ea1ce19c7607086e1
This commit is contained in:
Ed Sanders 2021-01-25 22:30:48 +00:00
parent e793626d52
commit 42c97fa448

View file

@ -3,8 +3,10 @@ $( function () {
var $lastLine;
function onHashChange() {
// Don't assume location.hash will be parseable as an ID (T271572)
var $line = $( document.getElementById( location.hash.slice( 1 ) ) || [] );
var id = location.hash.slice( 1 ),
// Don't assume location.hash will be parseable as an ID (T271572)
// and avoid warning when id is empty (T272844)
$line = id ? $( document.getElementById( id ) || [] ) : $( [] );
if ( !$line.closest( '.mw-highlight' ).length ) {
// Matched ID wasn't in a highlight block