Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/123092
Change subject: Don't use unchecked global jQuery variable in non-critical JavaScript ...................................................................... Don't use unchecked global jQuery variable in non-critical JavaScript This code simply relies on jQuery being loaded, but there is no guarantee. I had this error in my developement environment while testing and found it really strange that such a purely cosmetic, completely optional piece of code stops all other scripts on the page. Also: parseInt is a function to parse strings (hence the name), it really should not be used as a math function. A very common way to cast to int in JavaScript is the bitwise or operator. Change-Id: I4b3ea6658c5fdf73da72dd9838d3952b0098c2c7 --- M repo/includes/EntityView.php 1 file changed, 21 insertions(+), 19 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/92/123092/1 diff --git a/repo/includes/EntityView.php b/repo/includes/EntityView.php index 53424b4..44f5fd9 100644 --- a/repo/includes/EntityView.php +++ b/repo/includes/EntityView.php @@ -174,26 +174,28 @@ // the fastest way to show the loading spinner is placing the script right after the // corresponsing html $html .= Html::inlineScript( ' - $( ".wb-entity" ).fadeTo( 0, .3 ).after( function() { - var $div = $( "<div/>" ).addClass( "wb-entity-spinner mw-small-spinner" ); - $div.css( "top", $div.height() + "px" ); - $div.css( - ( "' . $lang->getDir() . '" === "rtl" ) ? "right" : "left", - ( parseInt( $( this ).width() / 2 ) - $div.width() / 2 ) + "px" - ); - return $div; - } ); +if ( $ ) { + $( ".wb-entity" ).fadeTo( 0, .3 ).after( function() { + var $div = $( "<div/>" ).addClass( "wb-entity-spinner mw-small-spinner" ); + $div.css( "top", $div.height() + "px" ); + $div.css( + ( "' . $lang->getDir() . '" === "rtl" ) ? "right" : "left", + ( ( $( this ).width() - $div.width() ) / 2 | 0 ) + "px" + ); + return $div; + } ); - // Remove loading spinner after a couple of seconds in any case. (e.g. some resource - // might not have been loaded silently, so JavaScript is not initialising) - // Additionally attaching to window.error would only make sense before any other - // JavaScript is parsed. Since the JavaScript is loaded in the header, it does not make - // any sense to attach to window.error here. - window.setTimeout( function() { - $( ".wb-entity" ).fadeTo( 0, 1 ); - $( ".wb-entity-spinner" ).remove(); - }, 7000 ); - ' ); + // Remove loading spinner after a couple of seconds in any case. (e.g. some resource + // might not have been loaded silently, so JavaScript is not initialising) + // Additionally attaching to window.error would only make sense before any other + // JavaScript is parsed. Since the JavaScript is loaded in the header, it does not make + // any sense to attach to window.error here. + window.setTimeout( function() { + $( ".wb-entity" ).fadeTo( 0, 1 ); + $( ".wb-entity-spinner" ).remove(); + }, 7000 ); +} +' ); wfProfileOut( __METHOD__ ); return $html; -- To view, visit https://gerrit.wikimedia.org/r/123092 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4b3ea6658c5fdf73da72dd9838d3952b0098c2c7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits