All files / src/init ve.init.SupportCheck.js

90% Statements 9/10
88.88% Branches 8/9
100% Functions 4/4
90% Lines 9/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62            1x                     1x 3x     3x   3x 3x                                       3x 3x   3x                            
/*!
 * VisualEditor initialization support checker.
 *
 * @copyright See AUTHORS.txt
 */
 
( 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.
	 *
	 * @method VisualEditorSupportCheck
	 * @member global
	 * @return {boolean} True if the environment should support VisualEditor.
	 */
	window.VisualEditorSupportCheck = function () {
		return (
			/* ES6 */
			( function () {
				try {
					// eslint-disable-next-line no-new, no-new-func
					new Function( '(a = 0) => a' );
					return true;
				} catch ( e ) {
					return false;
				}
			}() ) &&
 
			/* ES6 RegExp.prototype.flags */
			/./g.flags === 'g' &&
 
			// TODO: Most of the below checks can probably be removed as they are supported in all ES6 browsers.
 
			/* contentEditable */
			!!( 'contentEditable' in document.createElement( 'div' ) ) &&
 
			/* createElementNS */
			!!document.createElementNS &&
 
			/* DOMParser */
			( function () {
				var doc;
				try {
					doc = new DOMParser().parseFromString( '<body></body>', 'text/html' );
				} catch ( e ) {}
				return doc instanceof HTMLDocument;
			}() ) &&
 
			/* classList */
			!!(
				( 'classList' in document.createElement( '_' ) ) ||
				( 'classList' in document.createElementNS( 'http://www.w3.org/2000/svg ', 'g' ) )
			) &&
 
			/* SVG */
			!!( 'createSVGRect' in document.createElementNS( 'http://www.w3.org/2000/svg', 'svg' ) )
		);
	};
}() );