Debian Codegraph @

extensions/VisualEditor/lib/ve/src/init/ve.init.SupportCheck.js

raw symbols SCIP
1 /*!
2 * VisualEditor initialization support checker.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 ( function () {
8 /**
9 * Check whether the environment has the needed features to load VisualEditor.
10 * This considers every ES5 feature, support for contentEditable itself, those
11 * specific DOM features we use, and SVG support for the user interface. As we
12 * use this to check for feature compatibility this file must be ES3-parsable.
13 *
14 * @method VisualEditorSupportCheck
15 * @memberof ve
16 * @return {boolean} True if the environment should support VisualEditor.
17 */
18 window.VisualEditorSupportCheck = function () {
19 return (
20 /* ES6 */
21 ( function () {
22 try {
23 // eslint-disable-next-line no-new, no-new-func
24 new Function( '(a = 0) => a' );
25 return true;
26 } catch ( e ) {
27 return false;
28 }
29 }() ) &&
30
31 /* ES6 RegExp.prototype.flags */
32 /./g.flags === 'g' &&
33
34 // TODO: Most of the below checks can probably be removed as they are supported in all ES6 browsers.
35
36 /* contentEditable */
37 !!( 'contentEditable' in document.createElement( 'div' ) ) &&
38
39 /* createElementNS */
40 !!document.createElementNS &&
41
42 /* DOMParser */
43 ( function () {
44 let doc;
45 try {
46 doc = new DOMParser().parseFromString( '<body></body>', 'text/html' );
47 } catch ( e ) {}
48 return doc instanceof HTMLDocument;
49 }() ) &&
50
51 /* classList */
52 !!(
53 ( 'classList' in document.createElement( '_' ) ) ||
54 ( 'classList' in document.createElementNS( 'http://www.w3.org/2000/svg ', 'g' ) )
55 ) &&
56
57 /* SVG */
58 !!( 'createSVGRect' in document.createElementNS( 'http://www.w3.org/2000/svg', 'svg' ) )
59 );
60 };
61 }() );