Polyfill node types in browsers without DOM level 2
authorStephane Bisson <sbisson@wikimedia.org>
Thu, 16 Apr 2015 14:06:30 +0000 (10:06 -0400)
committerStephane Bisson <sbisson@wikimedia.org>
Mon, 20 Apr 2015 19:05:47 +0000 (15:05 -0400)
mediawiki.jqueryMsg.js:1144 was blowing up on Node.TEXT_NODE
because window.Node is undefined in IE8. The exception was ignored
and this was causing a message containing {{PLURAL...}} or
{{GENDER...}} to be rendered as is.

Bug: T87118
Change-Id: I8c5c2ae74b68eeabd93bb5b81a3061bcb31f6549

resources/Resources.php
resources/src/dom-level2-skip.js [new file with mode: 0644]
resources/src/polyfill-nodeTypes.js [new file with mode: 0644]

index ec5a9a0..e2f05b6 100644 (file)
@@ -1269,6 +1269,7 @@ return array(
                'dependencies' => array(
                        'mediawiki.util',
                        'mediawiki.language',
+                       'dom-level2-shim',
                ),
                'targets' => array( 'desktop', 'mobile' ),
        ),
@@ -1695,6 +1696,14 @@ return array(
                'skipFunction' => 'resources/src/es5-skip.js',
        ),
 
+       /* dom-level2-shim */
+       // IE 8
+       'dom-level2-shim' => array(
+               'scripts' => 'resources/src/polyfill-nodeTypes.js',
+               'targets' => array( 'desktop', 'mobile' ),
+               'skipFunction' => 'resources/src/dom-level2-skip.js',
+       ),
+
        /* OOjs */
        'oojs' => array(
                'scripts' => array(
diff --git a/resources/src/dom-level2-skip.js b/resources/src/dom-level2-skip.js
new file mode 100644 (file)
index 0000000..484c295
--- /dev/null
@@ -0,0 +1,6 @@
+/*!
+ * Skip function for dom-level2-shim module.
+ *
+ * Tests for window.Node because that's the only thing that this shim is adding.
+ */
+return !!window.Node;
diff --git a/resources/src/polyfill-nodeTypes.js b/resources/src/polyfill-nodeTypes.js
new file mode 100644 (file)
index 0000000..556b51b
--- /dev/null
@@ -0,0 +1,19 @@
+/**
+ * Adds window.Node with node types according to:
+ * http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247
+ */
+
+window.Node = window.Node || {
+       ELEMENT_NODE:                1,
+       ATTRIBUTE_NODE:              2,
+       TEXT_NODE:                   3,
+       CDATA_SECTION_NODE:          4,
+       ENTITY_REFERENCE_NODE:       5,
+       ENTITY_NODE:                 6,
+       PROCESSING_INSTRUCTION_NODE: 7,
+       COMMENT_NODE:                8,
+       DOCUMENT_NODE:               9,
+       DOCUMENT_TYPE_NODE:          10,
+       DOCUMENT_FRAGMENT_NODE:      11,
+       NOTATION_NODE:               12
+};