Arlolra has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/204304

Change subject: Consistent use of isElt in DU
......................................................................

Consistent use of isElt in DU

Change-Id: I8a305c719863ef009d6d11aa984d3b5b396e4a83
---
M lib/mediawiki.DOMUtils.js
1 file changed, 30 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/04/204304/1

diff --git a/lib/mediawiki.DOMUtils.js b/lib/mediawiki.DOMUtils.js
index dfe768c..a5f001a 100644
--- a/lib/mediawiki.DOMUtils.js
+++ b/lib/mediawiki.DOMUtils.js
@@ -16,10 +16,6 @@
 // define some constructor shortcuts
 var KV = pd.KV;
 
-var isElt = function(node) {
-       return node.nodeType === 1;
-};
-
 /**
  * @class
  * @singleton
@@ -33,7 +29,9 @@
         * See http://dom.spec.whatwg.org/#dom-node-nodetype
         * @param {Node} node
         */
-       isElt: isElt,
+       isElt: function(node) {
+               return node.nodeType === 1;
+       },
 
        /**
         * Check whether this is a DOM text node.
@@ -246,7 +244,7 @@
        // Direct manipulation of the nodes for load and store.
 
        loadDataAttrib: function(node, name, defaultVal) {
-               if ( !isElt(node) ) {
+               if (!DU.isElt(node)) {
                        return;
                }
                var data = this.getNodeData( node );
@@ -257,7 +255,7 @@
        },
 
        saveDataAttribs: function(node) {
-               if ( !isElt(node) ) {
+               if (!DU.isElt(node)) {
                        return;
                }
                var data = DU.getNodeData( node );
@@ -280,7 +278,7 @@
        // ie. when the serialized nodes will lose their .dataobject's
 
        loadDataAttribs: function(node) {
-               if ( !isElt(node) ) {
+               if (!DU.isElt(node)) {
                        return;
                }
                [ "Parsoid", "Mw" ].forEach(function(attr) {
@@ -290,7 +288,7 @@
        },
 
        loadDataParsoid: function( node ) {
-               if ( !isElt(node) ) {
+               if (!DU.isElt(node)) {
                        return;
                }
 
@@ -361,7 +359,7 @@
         * @param {Mixed} defaultVal What should be returned if we fail to find 
a valid JSON structure
         */
        getJSONAttribute: function(node, name, defaultVal) {
-               if ( !isElt(node) ) {
+               if (!DU.isElt(node)) {
                        return defaultVal !== undefined ? defaultVal : {};
                }
 
@@ -649,7 +647,7 @@
         */
        isNewElt: function(node) {
                // We cannot determine newness on text/comment nodes.
-               if (!this.isElt(node)) {
+               if (!DU.isElt(node)) {
                        return false;
                }
 
@@ -664,7 +662,7 @@
         */
        isLiteralHTMLNode: function(node) {
                return (node &&
-                       isElt(node) &&
+                       DU.isElt(node) &&
                        this.hasLiteralHTMLMarker(this.getDataParsoid(node)));
        },
 
@@ -707,7 +705,7 @@
        },
 
        isGeneratedFigure: function(n) {
-               return this.isElt(n) && 
(/(^|\s)mw:Image(\s|$|\/)/).test(n.getAttribute("typeof"));
+               return DU.isElt(n) && 
(/(^|\s)mw:Image(\s|$|\/)/).test(n.getAttribute("typeof"));
        },
 
        /**
@@ -717,7 +715,7 @@
        getPrevElementSibling: function(node) {
                var sibling = node.previousSibling;
                while (sibling) {
-                       if (isElt(sibling)) {
+                       if (DU.isElt(sibling)) {
                                return sibling;
                        }
                        sibling = sibling.previousSibling;
@@ -732,7 +730,7 @@
        getNextElementSibling: function(node) {
                var sibling = node.nextSibling;
                while (sibling) {
-                       if (isElt(sibling)) {
+                       if (DU.isElt(sibling)) {
                                return sibling;
                        }
                        sibling = sibling.nextSibling;
@@ -746,7 +744,7 @@
        hasElementChild: function(node) {
                var children = node.childNodes;
                for (var i = 0, n = children.length; i < n; i++) {
-                       if (isElt(children[i])) {
+                       if (DU.isElt(children[i])) {
                                return true;
                        }
                }
@@ -761,7 +759,7 @@
                var children = node.childNodes;
                for (var i = 0, n = children.length; i < n; i++) {
                        var child = children[i];
-                       if (isElt(child) &&
+                       if (DU.isElt(child) &&
                                        // Is a block-level node
                                        ( this.isBlockNode(child) ||
                                          // or has a block-level child or 
grandchild or..
@@ -826,7 +824,7 @@
         * @param {Node} node
         */
        isTplOrExtToplevelNode: function(node) {
-               if (this.isElt(node)) {
+               if (DU.isElt(node)) {
                        var about = node.getAttribute('about');
                        // SSS FIXME: Verify that our DOM spec clarifies this
                        // expectation on about-ids and that our clients 
respect this.
@@ -841,7 +839,7 @@
                while ( node ) {
                        next = node.nextSibling;
 
-                       if ( DU.isElt( node ) ) {
+                       if (DU.isElt(node)) {
                                typeOf = node.getAttribute("typeof");
                                // Identify the first template/extension node.
                                // Strictly speaking, the !tplInfo check isn't 
necessary since
@@ -875,7 +873,7 @@
 
                        if ( possibleNext !== undefined ) {
                                next = possibleNext;
-                       } else if ( DU.isElt( node ) ) {
+                       } else if (DU.isElt(node)) {
                                DU.traverseWithTplOrExtInfo( func, 
node.firstChild, env, options, atTopLevel, tplInfo );
                        }
 
@@ -991,7 +989,7 @@
        },
 
        currentDiffMark: function(node, env) {
-               if (!node || !isElt(node)) {
+               if (!node || !DU.isElt(node)) {
                        return null;
                }
                var data = this.getNodeData( node );
@@ -1088,7 +1086,7 @@
         * This annotation is added by the DOMDiff pass
         */
        isDeletedBlockNode: function(node) {
-               return node && this.isElt(node) &&
+               return node && DU.isElt(node) &&
                        this.isMarkerMeta(node, "mw:DiffMarker") &&
                        node.getAttribute("data-is-block");
        },
@@ -1328,7 +1326,7 @@
         * @param {string} someClass
         */
        hasClass: function( ele, someClass ) {
-               if ( !ele || !isElt(ele) ) {
+               if ( !ele || !DU.isElt(ele) ) {
                        return false;
                }
 
@@ -1356,7 +1354,7 @@
        treeHasElement: function(node, tagName) {
                node = node.firstChild;
                while (node) {
-                       if (isElt(node)) {
+                       if (DU.isElt(node)) {
                                if (node.nodeName === tagName || 
this.treeHasElement(node, tagName)) {
                                        return true;
                                }
@@ -1416,7 +1414,7 @@
         * Is node the first wrapper element of encapsulated content?
         */
        isFirstEncapsulationWrapperNode: function(node) {
-               return isElt(node) && 
(/(?:^|\s)mw:(?:Transclusion(?=$|\s)|Param(?=$|\s)|Extension\/[^\s]+)/).test(node.getAttribute('typeof'));
+               return DU.isElt(node) && 
(/(?:^|\s)mw:(?:Transclusion(?=$|\s)|Param(?=$|\s)|Extension\/[^\s]+)/).test(node.getAttribute('typeof'));
        },
 
        /**
@@ -1431,7 +1429,7 @@
                do {
                        node = prev;
                        prev = DU.previousNonDeletedSibling(node);
-               } while (prev && isElt(prev) && prev.getAttribute('about') === 
about);
+               } while (prev && DU.isElt(prev) && prev.getAttribute('about') 
=== about);
                return DU.isFirstEncapsulationWrapperNode(node) ? node : null;
        },
 
@@ -1445,7 +1443,7 @@
                // True if it has an encapsulation type or while walking 
backwards
                // over elts with identical about ids, we run into a node with 
an
                // encapsulation type.
-               if (!isElt(node)) {
+               if (!DU.isElt(node)) {
                        return false;
                }
 
@@ -1475,8 +1473,8 @@
 
                node = node.nextSibling;
                while (node && (
-                               isElt(node) && node.getAttribute('about') === 
about ||
-                               this.isFosterablePosition(node) && !isElt(node) 
&& this.isIEW(node)
+                               DU.isElt(node) && node.getAttribute('about') 
=== about ||
+                               this.isFosterablePosition(node) && 
!DU.isElt(node) && this.isIEW(node)
                        )) {
                        nodes.push(node);
                        node = node.nextSibling;
@@ -1761,28 +1759,23 @@
        },
 
        isDOMFragmentWrapper: function(node) {
-
                function hasRightType(node) {
                        return 
(/(?:^|\s)mw:DOMFragment(?=$|\s)/).test(node.getAttribute("typeof"));
                }
-
                function previousSiblingIsWrapper(sibling, about) {
                        return sibling &&
-                               isElt(sibling) &&
+                               DU.isElt(sibling) &&
                                about === sibling.getAttribute("about") &&
                                hasRightType(sibling);
                }
-
-               if (!isElt(node)) {
+               if (!DU.isElt(node)) {
                        return false;
                }
-
                var about = node.getAttribute("about");
                return about && (
                        hasRightType(node) ||
                        previousSiblingIsWrapper(node.previousSibling, about)
                );
-
        },
 
        /**
@@ -2008,7 +2001,7 @@
                function applyToSiblings( node ) {
                        var id;
                        while ( node ) {
-                               if ( DU.isElt( node ) ) {
+                               if (DU.isElt(node)) {
                                        id = node.getAttribute("id");
                                        if ( dp.ids.hasOwnProperty( id ) ) {
                                                DU.setJSONAttribute( node, 
'data-parsoid', dp.ids[id] );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8a305c719863ef009d6d11aa984d3b5b396e4a83
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <abrea...@wikimedia.org>

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

Reply via email to