resourceloader: Move queue formatting out of OutputPage
[lhc/web/wiklou.git] / resources / src / startup.js
index e53e5f3..d026cb0 100644 (file)
@@ -1,9 +1,9 @@
 /**
- * This script provides a function which is run to evaluate whether or not to
- * continue loading jQuery and the MediaWiki modules. This code should work on
- * even the most ancient of browsers, so be very careful when editing.
+ * Code in this file MUST work on even the most ancient of browsers!
+ *
+ * This file is where we decide whether to initialise the modern run-time.
  */
-/*jshint unused: false, evil: true */
+/*jshint unused: false */
 /*globals mw, RLQ: true, NORLQ: true, $VARS, $CODE, performance */
 
 var mediaWikiLoadStart = ( new Date() ).getTime(),
@@ -15,53 +15,60 @@ var mediaWikiLoadStart = ( new Date() ).getTime(),
 mwPerformance.mark( 'mwLoadStart' );
 
 /**
- * Returns false for Grade C supported browsers.
+ * See <https://www.mediawiki.org/wiki/Compatibility#Browsers>
+ *
+ * Capabilities required for modern run-time:
+ * - DOM Level 4 & Selectors API Level 1
+ * - HTML5 & Web Storage
+ * - DOM Level 2 Events
+ *
+ * Browsers we support in our modern run-time (Grade A):
+ * - Chrome
+ * - IE 9+
+ * - Firefox 3.5+
+ * - Safari 4+
+ * - Opera 10.5+
+ * - Mobile Safari (iOS 1+)
+ * - Android 2.0+
  *
- * This function should only be used by the Startup module, do not expand it to
- * be generally useful beyond startup.
+ * Browsers we support in our no-javascript run-time (Grade C):
+ * - IE 6+
+ * - Firefox 3+
+ * - Safari 3+
+ * - Opera 10+
+ * - WebOS < 1.5
+ * - PlayStation
+ * - Symbian-based browsers
+ * - NetFront-based browser
+ * - Opera Mini
+ * - Nokia's Ovi Browser
+ * - MeeGo's browser
+ * - Google Glass
  *
- * See also:
- * - https://www.mediawiki.org/wiki/Compatibility#Browsers
- * - https://jquery.com/browser-support/
+ * Other browsers that pass the check are considered Grade X.
  */
-function isCompatible( ua ) {
-       if ( ua === undefined ) {
-               ua = navigator.userAgent;
-       }
+function isCompatible( str ) {
+       var ua = str || navigator.userAgent;
+       return !!(
+               // http://caniuse.com/#feat=queryselector
+               'querySelector' in document
+
+               // http://caniuse.com/#feat=namevalue-storage
+               // https://developer.blackberry.com/html5/apis/v1_0/localstorage.html
+               // https://blog.whatwg.org/this-week-in-html-5-episode-30
+               && 'localStorage' in window
+
+               // http://caniuse.com/#feat=addeventlistener
+               && 'addEventListener' in window
 
-       // Browsers with outdated or limited JavaScript engines get the no-JS experience
-       return !(
-               // Internet Explorer < 9
-               ( ua.indexOf( 'MSIE' ) !== -1 && parseFloat( ua.split( 'MSIE' )[ 1 ] ) < 9 ) ||
-               // Firefox < 3
-               ( ua.indexOf( 'Firefox/' ) !== -1 && parseFloat( ua.split( 'Firefox/' )[ 1 ] ) < 3 ) ||
-               // Opera < 12
-               ( ua.indexOf( 'Opera/' ) !== -1 && ( ua.indexOf( 'Version/' ) === -1 ?
-                       // "Opera/x.y"
-                       parseFloat( ua.split( 'Opera/' )[ 1 ] ) < 10 :
-                       // "Opera/9.80 ... Version/x.y"
-                       parseFloat( ua.split( 'Version/' )[ 1 ] ) < 12
-               ) ) ||
-               // "Mozilla/0.0 ... Opera x.y"
-               ( ua.indexOf( 'Opera ' ) !== -1 && parseFloat( ua.split( ' Opera ' )[ 1 ] ) < 10 ) ||
-               // BlackBerry < 6
-               ua.match( /BlackBerry[^\/]*\/[1-5]\./ ) ||
-               // Open WebOS < 1.5
-               ua.match( /webOS\/1\.[0-4]/ ) ||
-               // Anything PlayStation based.
-               ua.match( /PlayStation/i ) ||
-               // Any Symbian based browsers
-               ua.match( /SymbianOS|Series60/ ) ||
-               // Any NetFront based browser
-               ua.match( /NetFront/ ) ||
-               // Opera Mini, all versions
-               ua.match( /Opera Mini/ ) ||
-               // Nokia's Ovi Browser
-               ua.match( /S40OviBrowser/ ) ||
-               // MeeGo's browser
-               ua.match( /MeeGo/ ) ||
-               // Google Glass browser groks JS but UI is too limited
-               ( ua.match( /Glass/ ) && ua.match( /Android/ ) )
+               // Hardcoded exceptions for browsers that pass the requirement but we don't want to
+               // support in the modern run-time.
+               && !(
+                       ua.match( /webOS\/1\.[0-4]/ ) ||
+                       ua.match( /PlayStation/i ) ||
+                       ua.match( /SymbianOS|Series60|NetFront|Opera Mini|S40OviBrowser|MeeGo/ ) ||
+                       ( ua.match( /Glass/ ) && ua.match( /Android/ ) )
+               )
        );
 }
 
@@ -70,7 +77,7 @@ function isCompatible( ua ) {
        var NORLQ, script;
        if ( !isCompatible() ) {
                // Undo class swapping in case of an unsupported browser.
-               // See OutputPage::getHeadScripts().
+               // See ResourceLoaderClientHtml::getDocumentAttributes().
                document.documentElement.className = document.documentElement.className
                        .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );