Add 3D filetype for STL files
[lhc/web/wiklou.git] / resources / src / startup.js
1 /**
2 * Code in this file MUST work on even the most ancient of browsers!
3 *
4 * This file is where we decide whether to initialise the modern run-time.
5 */
6
7 /* global mw, $VARS, $CODE */
8
9 var mwPerformance = ( window.performance && performance.mark ) ? performance : {
10 mark: function () {}
11 },
12 // Define now() here to ensure valid comparison with mediaWikiLoadEnd (T153819).
13 mwNow = ( function () {
14 var perf = window.performance,
15 navStart = perf && perf.timing && perf.timing.navigationStart;
16 return navStart && typeof perf.now === 'function' ?
17 function () { return navStart + perf.now(); } :
18 function () { return Date.now(); };
19 }() ),
20 // eslint-disable-next-line no-unused-vars
21 mediaWikiLoadStart = mwNow();
22
23 mwPerformance.mark( 'mwLoadStart' );
24
25 /**
26 * See <https://www.mediawiki.org/wiki/Compatibility#Browsers>
27 *
28 * Capabilities required for modern run-time:
29 * - ECMAScript 5
30 * - DOM Level 4 & Selectors API Level 1
31 * - HTML5 & Web Storage
32 * - DOM Level 2 Events
33 *
34 * Browsers we support in our modern run-time (Grade A):
35 * - Chrome 13+
36 * - IE 10+
37 * - Firefox 4+
38 * - Safari 5+
39 * - Opera 12.10+
40 * - Mobile Safari 5.1+ (iOS 5+)
41 * - Android 4.1+
42 *
43 * Browsers we support in our no-javascript run-time (Grade C):
44 * - Chrome 1+
45 * - IE 6+
46 * - Firefox 3+
47 * - Safari 3+
48 * - Opera 10+
49 * - Mobile Safari 5.0+ (iOS 4+)
50 * - Android 2.0+
51 * - WebOS < 1.5
52 * - PlayStation
53 * - Symbian-based browsers
54 * - NetFront-based browser
55 * - Opera Mini
56 * - Nokia's Ovi Browser
57 * - MeeGo's browser
58 * - Google Glass
59 * - UC Mini (speed mode on)
60 *
61 * Other browsers that pass the check are considered Grade X.
62 *
63 * @param {string} [str] User agent, defaults to navigator.userAgent
64 * @return {boolean} User agent is compatible with MediaWiki JS
65 */
66 function isCompatible( str ) {
67 var ua = str || navigator.userAgent;
68 return !!(
69 // http://caniuse.com/#feat=es5
70 // http://caniuse.com/#feat=use-strict
71 // http://caniuse.com/#feat=json / https://phabricator.wikimedia.org/T141344#2784065
72 ( function () {
73 'use strict';
74 return !this && !!Function.prototype.bind && !!window.JSON;
75 }() ) &&
76
77 // http://caniuse.com/#feat=queryselector
78 'querySelector' in document &&
79
80 // http://caniuse.com/#feat=namevalue-storage
81 // https://developer.blackberry.com/html5/apis/v1_0/localstorage.html
82 // https://blog.whatwg.org/this-week-in-html-5-episode-30
83 'localStorage' in window &&
84
85 // http://caniuse.com/#feat=addeventlistener
86 'addEventListener' in window &&
87
88 // Hardcoded exceptions for browsers that pass the requirement but we don't want to
89 // support in the modern run-time.
90 // Note: Please extend the regex instead of adding new ones
91 !(
92 ua.match( /webOS\/1\.[0-4]|SymbianOS|Series60|NetFront|Opera Mini|S40OviBrowser|MeeGo|Android.+Glass|^Mozilla\/5\.0 .+ Gecko\/$|googleweblight/ ) ||
93 ua.match( /PlayStation/i )
94 )
95 );
96 }
97
98 // Conditional script injection
99 ( function () {
100 var NORLQ, script;
101 if ( !isCompatible() ) {
102 // Undo class swapping in case of an unsupported browser.
103 // See ResourceLoaderClientHtml::getDocumentAttributes().
104 document.documentElement.className = document.documentElement.className
105 .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
106
107 NORLQ = window.NORLQ || [];
108 while ( NORLQ.length ) {
109 NORLQ.shift()();
110 }
111 window.NORLQ = {
112 push: function ( fn ) {
113 fn();
114 }
115 };
116
117 // Clear and disable the other queue
118 window.RLQ = {
119 // No-op
120 push: function () {}
121 };
122
123 return;
124 }
125
126 /**
127 * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
128 */
129 function startUp() {
130 mw.config = new mw.Map( $VARS.wgLegacyJavaScriptGlobals );
131
132 $CODE.registrations();
133
134 mw.config.set( $VARS.configuration );
135
136 // Must be after mw.config.set because these callbacks may use mw.loader which
137 // needs to have values 'skin', 'debug' etc. from mw.config.
138 // eslint-disable-next-line vars-on-top
139 var RLQ = window.RLQ || [];
140 while ( RLQ.length ) {
141 RLQ.shift()();
142 }
143 window.RLQ = {
144 push: function ( fn ) {
145 fn();
146 }
147 };
148
149 // Clear and disable the other queue
150 window.NORLQ = {
151 // No-op
152 push: function () {}
153 };
154 }
155
156 script = document.createElement( 'script' );
157 script.src = $VARS.baseModulesUri;
158 script.onload = script.onreadystatechange = function () {
159 if ( !script.readyState || /loaded|complete/.test( script.readyState ) ) {
160 // Clean up
161 script.onload = script.onreadystatechange = null;
162 script = null;
163 // Callback
164 startUp();
165 }
166 };
167 document.getElementsByTagName( 'head' )[ 0 ].appendChild( script );
168 }() );