2 * Code in this file MUST work on even the most ancient of browsers!
4 * This file is where we decide whether to initialise the modern run-time.
7 /* global mw, $VARS, $CODE */
9 // eslint-disable-next-line no-unused-vars
10 var mediaWikiLoadStart
= ( new Date() ).getTime(),
11 mwPerformance
= ( window
.performance
&& performance
.mark
) ? performance
: {
15 mwPerformance
.mark( 'mwLoadStart' );
18 * See <https://www.mediawiki.org/wiki/Compatibility#Browsers>
20 * Capabilities required for modern run-time:
21 * - DOM Level 4 & Selectors API Level 1
22 * - HTML5 & Web Storage
23 * - DOM Level 2 Events
25 * Browsers we support in our modern run-time (Grade A):
31 * - Mobile Safari (iOS 1+)
34 * Browsers we support in our no-javascript run-time (Grade C):
41 * - Symbian-based browsers
42 * - NetFront-based browser
44 * - Nokia's Ovi Browser
47 * - UC Mini (speed mode on)
49 * Other browsers that pass the check are considered Grade X.
51 * @param {string} [str] User agent, defaults to navigator.userAgent
52 * @return {boolean} User agent is compatible with MediaWiki JS
54 function isCompatible( str
) {
55 var ua
= str
|| navigator
.userAgent
;
57 // http://caniuse.com/#feat=queryselector
58 'querySelector' in document
&&
60 // http://caniuse.com/#feat=namevalue-storage
61 // https://developer.blackberry.com/html5/apis/v1_0/localstorage.html
62 // https://blog.whatwg.org/this-week-in-html-5-episode-30
63 'localStorage' in window
&&
65 // http://caniuse.com/#feat=addeventlistener
66 'addEventListener' in window
&&
68 // Hardcoded exceptions for browsers that pass the requirement but we don't want to
69 // support in the modern run-time.
70 // Note: Please extend the regex instead of adding new ones
72 ua
.match( /webOS\/1\.[0-4]|SymbianOS|Series60|NetFront|Opera Mini|S40OviBrowser|MeeGo|Android.+Glass|^Mozilla\/5\.0 .+ Gecko\/$/ ) ||
73 ua
.match( /PlayStation/i )
78 // Conditional script injection
81 if ( !isCompatible() ) {
82 // Undo class swapping in case of an unsupported browser.
83 // See ResourceLoaderClientHtml::getDocumentAttributes().
84 document
.documentElement
.className
= document
.documentElement
.className
85 .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
87 NORLQ
= window
.NORLQ
|| [];
88 while ( NORLQ
.length
) {
92 push: function ( fn
) {
97 // Clear and disable the other queue
107 * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
110 mw
.config
= new mw
.Map( $VARS
.wgLegacyJavaScriptGlobals
);
112 $CODE
.registrations();
114 mw
.config
.set( $VARS
.configuration
);
116 // Must be after mw.config.set because these callbacks may use mw.loader which
117 // needs to have values 'skin', 'debug' etc. from mw.config.
118 // eslint-disable-next-line vars-on-top
119 var RLQ
= window
.RLQ
|| [];
120 while ( RLQ
.length
) {
124 push: function ( fn
) {
129 // Clear and disable the other queue
136 script
= document
.createElement( 'script' );
137 script
.src
= $VARS
.baseModulesUri
;
138 script
.onload
= script
.onreadystatechange = function () {
139 if ( !script
.readyState
|| /loaded|complete/.test( script
.readyState
) ) {
141 script
.onload
= script
.onreadystatechange
= null;
147 document
.getElementsByTagName( 'head' )[ 0 ].appendChild( script
);