jenkins-bot has submitted this change and it was merged.

Change subject: Move initialisation browser support checking from downstream
......................................................................


Move initialisation browser support checking from downstream

These checks were written in VisualEditor-MediaWiki but apply to all clients
and so are moved here.

Change-Id: I27a8e7b4376647f01cee648de987dc3ca6a060d5
---
M .jsduck/categories.json
M build/modules.json
M demos/ve/demo.minimal.js
M demos/ve/desktop.html
M demos/ve/mobile.html
M src/init/sa/ve.init.sa.Platform.js
M src/init/ve.init.Platform.js
A src/init/ve.init.SupportCheck.js
M tests/index.html
9 files changed, 103 insertions(+), 19 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/.jsduck/categories.json b/.jsduck/categories.json
index 5f01180..cd1ddf9 100644
--- a/.jsduck/categories.json
+++ b/.jsduck/categories.json
@@ -25,7 +25,12 @@
                "groups": [
                        {
                                "name": "General",
-                               "classes": ["ve.init", "ve.init.Platform", 
"ve.init.Target"]
+                               "classes": [
+                                       "ve.init",
+                                       "ve.init.Platform",
+                                       "ve.init.Target",
+                                       "window.VisualEditorSupportCheck"
+                               ]
                        },
                        {
                                "name": "Stand-alone",
diff --git a/build/modules.json b/build/modules.json
index 181e0db..e72d77b 100644
--- a/build/modules.json
+++ b/build/modules.json
@@ -175,6 +175,11 @@
                        "papaparse"
                ]
        },
+       "visualEditor.supportCheck": {
+               "scripts": [
+                       "src/init/ve.init.SupportCheck.js"
+               ]
+       },
        "visualEditor.base": {
                "dependencies": [
                        "baselibs",
@@ -193,6 +198,7 @@
                        "src/init/ve.init.Target.js"
                ],
                "dependencies": [
+                       "visualEditor.supportCheck",
                        "unicodejs",
                        "rangefix"
                ]
diff --git a/demos/ve/demo.minimal.js b/demos/ve/demo.minimal.js
index 57bcd72..9ee070f 100644
--- a/demos/ve/demo.minimal.js
+++ b/demos/ve/demo.minimal.js
@@ -5,25 +5,28 @@
  */
 
 // Set up the platform and wait for i18n messages to load
-new ve.init.sa.Platform( ve.messagePaths ).initialize().done( function () {
+new ve.init.sa.Platform( ve.messagePaths ).initialize()
+       .fail( function () {
+               $( '.ve-instance' ).text( 'Sorry, this browser is not 
supported.' );
+       } )
+       .done( function () {
+               // Create the target
+               var target = new ve.init.sa.Target();
 
-       // Create the target
-       var target = new ve.init.sa.Target();
+               // Create a document model for a new surface
+               target.addSurface(
+                       ve.dm.converter.getModelFromDom(
+                               ve.createDocumentFromHtml( '<p><b>Hello,</b> 
<i>World!</i></p>' ),
+                               // Optional: Document language, directionality 
(ltr/rtl)
+                               { lang: $.i18n().locale, dir: $( 'body' ).css( 
'direction' ) }
+                       )
+               );
 
-       // Create a document model for a new surface
-       target.addSurface(
-               ve.dm.converter.getModelFromDom(
-                       ve.createDocumentFromHtml( '<p><b>Hello,</b> 
<i>World!</i></p>' ),
-                       // Optional: Document language, directionality (ltr/rtl)
-                       { lang: $.i18n().locale, dir: $( 'body' ).css( 
'direction' ) }
-               )
-       );
+               // Append the target to the document
+               $( '.ve-instance' ).append( target.$element );
 
-       // Append the target to the document
-       $( '.ve-instance' ).append( target.$element );
-
-       $( '.ve-demo-convert' ).on( 'click', function () {
-               // Get the current HTML from the surface and display
-               $( '.ve-demo-html' ).val( target.getSurface().getHtml() );
+               $( '.ve-demo-convert' ).on( 'click', function () {
+                       // Get the current HTML from the surface and display
+                       $( '.ve-demo-html' ).val( target.getSurface().getHtml() 
);
+               } );
        } );
-} );
diff --git a/demos/ve/desktop.html b/demos/ve/desktop.html
index c5f9940..fdf0876 100644
--- a/demos/ve/desktop.html
+++ b/demos/ve/desktop.html
@@ -142,6 +142,9 @@
                <!-- papaparse -->
                <script src="../../lib/papaparse/papaparse.js"></script>
 
+               <!-- visualEditor.supportCheck -->
+               <script src="../../src/init/ve.init.SupportCheck.js"></script>
+
                <!-- unicodejs -->
                <script src="../../lib/unicodejs/unicodejs.js"></script>
 
diff --git a/demos/ve/mobile.html b/demos/ve/mobile.html
index bb35c37..d8d83b8 100644
--- a/demos/ve/mobile.html
+++ b/demos/ve/mobile.html
@@ -144,6 +144,9 @@
                <!-- papaparse -->
                <script src="../../lib/papaparse/papaparse.js"></script>
 
+               <!-- visualEditor.supportCheck -->
+               <script src="../../src/init/ve.init.SupportCheck.js"></script>
+
                <!-- unicodejs -->
                <script src="../../lib/unicodejs/unicodejs.js"></script>
 
diff --git a/src/init/sa/ve.init.sa.Platform.js 
b/src/init/sa/ve.init.sa.Platform.js
index ab48c9f..ddf79ee 100644
--- a/src/init/sa/ve.init.sa.Platform.js
+++ b/src/init/sa/ve.init.sa.Platform.js
@@ -178,6 +178,10 @@
                promises = [],
                fallbacks = $.i18n.fallbacks[ locale ];
 
+       if ( !window.VisualEditorSupportCheck() ) {
+               return $.Deferred().reject().promise();
+       }
+
        if ( !fallbacks ) {
                // Try to find something that has fallbacks (which means it's a 
language we know about)
                // by stripping things from the end. But collect all the 
intermediate ones in case we
diff --git a/src/init/ve.init.Platform.js b/src/init/ve.init.Platform.js
index 4eb9c19..3fcb5b8 100644
--- a/src/init/ve.init.Platform.js
+++ b/src/init/ve.init.Platform.js
@@ -249,6 +249,7 @@
 /**
  * Initialize the platform. The default implementation is to do nothing and 
return a resolved
  * promise. Subclasses should override this if they have asynchronous 
initialization work to do.
+ * The promise rejects if the platform is incompatible.
  *
  * External callers should not call this. Instead, call #getInitializedPromise.
  *
@@ -256,6 +257,9 @@
  * @return {jQuery.Promise} Promise that will be resolved once initialization 
is done
  */
 ve.init.Platform.prototype.initialize = function () {
+       if ( !window.VisualEditorSupportCheck() ) {
+               return $.Deferred().reject().promise();
+       }
        return $.Deferred().resolve().promise();
 };
 
diff --git a/src/init/ve.init.SupportCheck.js b/src/init/ve.init.SupportCheck.js
new file mode 100644
index 0000000..1d2eafa
--- /dev/null
+++ b/src/init/ve.init.SupportCheck.js
@@ -0,0 +1,53 @@
+/*!
+ * VisualEditor initialization support checker.
+ *
+ * @copyright 2011-2016 VisualEditor Team and others; see 
http://ve.mit-license.org
+ */
+
+// jshint esversion: 3
+
+( function () {
+       /**
+        * Check whether the environment has the needed features to load 
VisualEditor.
+        * This considers every ES5 feature, support for contentEditable 
itself, those
+        * specific DOM features we use, and SVG support for the user 
interface. As we
+        * use this to check for feature compatibility this file must be 
ES3-parsable.
+        *
+        * @return {boolean} True if the environment should support 
VisualEditor.
+        */
+       window.VisualEditorSupportCheck = function () {
+               return (
+                       /* ES5 */
+                       !!(
+                               // It would be much easier to do a quick inline 
function that asserts "use strict"
+                               // works, but since IE9 doesn't support strict 
mode (and we don't use strict mode)
+                               // we have to instead list all the ES5 features 
individually.
+                               Array.isArray &&
+                               Array.prototype.filter &&
+                               Array.prototype.indexOf &&
+                               Array.prototype.map &&
+                               Date.now &&
+                               Date.prototype.toJSON &&
+                               Object.create &&
+                               Object.keys &&
+                               String.prototype.trim &&
+                               window.JSON &&
+                               JSON.parse &&
+                               JSON.stringify &&
+                               Function.prototype.bind
+                       ) &&
+
+                       /* contentEditable */
+                       !!( 'contentEditable' in document.createElement( 'div' 
) ) &&
+
+                       /* DOM */
+                       !!document.documentElement.classList &&
+
+                       /* SVG */
+                       !!(
+                               document.createElementNS &&
+                               document.createElementNS( 
'http://www.w3.org/2000/svg', 'svg' ).createSVGRect
+                       )
+               );
+       };
+}() );
diff --git a/tests/index.html b/tests/index.html
index 0a8b091..d0f9f14 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -70,6 +70,9 @@
                <!-- papaparse -->
                <script src="../lib/papaparse/papaparse.js"></script>
 
+               <!-- visualEditor.supportCheck -->
+               <script src="../src/init/ve.init.SupportCheck.js"></script>
+
                <!-- unicodejs -->
                <script src="../lib/unicodejs/unicodejs.js"></script>
 

-- 
To view, visit https://gerrit.wikimedia.org/r/271030
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I27a8e7b4376647f01cee648de987dc3ca6a060d5
Gerrit-PatchSet: 5
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to