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.
6 /*jshint unused: false */
7 /*globals mw, RLQ: true, NORLQ: true, $VARS, $CODE, performance */
9 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
48 * Other browsers that pass the check are considered Grade X.
50 function isCompatible( str
) {
51 var ua
= str
|| navigator
.userAgent
;
53 // http://caniuse.com/#feat=queryselector
54 'querySelector' in document
56 // http://caniuse.com/#feat=namevalue-storage
57 // https://developer.blackberry.com/html5/apis/v1_0/localstorage.html
58 // https://blog.whatwg.org/this-week-in-html-5-episode-30
59 && 'localStorage' in window
61 // http://caniuse.com/#feat=addeventlistener
62 && 'addEventListener' in window
64 // Hardcoded exceptions for browsers that pass the requirement but we don't want to
65 // support in the modern run-time.
67 ua
.match( /webOS\/1\.[0-4]|SymbianOS|Series60|NetFront|Opera Mini|S40OviBrowser|MeeGo|Android.+Glass/ ) ||
68 ua
.match( /PlayStation/i )
73 // Conditional script injection
76 if ( !isCompatible() ) {
77 // Undo class swapping in case of an unsupported browser.
78 // See ResourceLoaderClientHtml::getDocumentAttributes().
79 document
.documentElement
.className
= document
.documentElement
.className
80 .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
82 NORLQ
= window
.NORLQ
|| [];
83 while ( NORLQ
.length
) {
87 push: function ( fn
) {
92 // Clear and disable the other queue
102 * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
105 mw
.config
= new mw
.Map( $VARS
.wgLegacyJavaScriptGlobals
);
107 $CODE
.registrations();
109 mw
.config
.set( $VARS
.configuration
);
111 // Must be after mw.config.set because these callbacks may use mw.loader which
112 // needs to have values 'skin', 'debug' etc. from mw.config.
113 var RLQ
= window
.RLQ
|| [];
114 while ( RLQ
.length
) {
118 push: function ( fn
) {
123 // Clear and disable the other queue
130 script
= document
.createElement( 'script' );
131 script
.src
= $VARS
.baseModulesUri
;
132 script
.onload
= script
.onreadystatechange = function () {
133 if ( !script
.readyState
|| /loaded|complete/.test( script
.readyState
) ) {
135 script
.onload
= script
.onreadystatechange
= null;
141 document
.getElementsByTagName( 'head' )[ 0 ].appendChild( script
);