[Pkg-javascript-commits] [ltx] 371/469: Code tidy

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:28 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit ec3a9955ddca0bcbfe740ad84f300a52a36b5c3b
Author: Lloyd Watkin <lloyd at evilprofessor.co.uk>
Date:   Sun Feb 15 18:34:36 2015 +0000

    Code tidy
---
 lib/element.js | 46 +++++++++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/lib/element.js b/lib/element.js
index a062a56..e565b74 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -25,10 +25,11 @@ Element.prototype.is = function(name, xmlns) {
 
 /* without prefix */
 Element.prototype.getName = function() {
-    if (this.name.indexOf(':') >= 0)
+    if (this.name.indexOf(':') >= 0) {
         return this.name.substr(this.name.indexOf(':') + 1)
-    else
+    } else {
         return this.name
+    }
 }
 
 /**
@@ -38,9 +39,8 @@ Element.prototype.getNS = function() {
     if (this.name.indexOf(':') >= 0) {
         var prefix = this.name.substr(0, this.name.indexOf(':'))
         return this.findNS(prefix)
-    } else {
-        return this.findNS()
     }
+    return this.findNS()
 }
 
 /**
@@ -49,17 +49,19 @@ Element.prototype.getNS = function() {
 Element.prototype.findNS = function(prefix) {
     if (!prefix) {
         /* default namespace */
-        if (this.attrs.xmlns)
+        if (this.attrs.xmlns) {
             return this.attrs.xmlns
-        else if (this.parent)
+        } else if (this.parent) {
             return this.parent.findNS()
+        }
     } else {
         /* prefixed namespace */
         var attr = 'xmlns:' + prefix
-        if (this.attrs[attr])
+        if (this.attrs[attr]) {
             return this.attrs[attr]
-        else if (this.parent)
+        } else if (this.parent) {
             return this.parent.findNS(prefix)
+        }
     }
 }
 
@@ -69,8 +71,9 @@ Element.prototype.findNS = function(prefix) {
 Element.prototype.getXmlns = function() {
     var namespaces = {}
 
-    if (this.parent)
+    if (this.parent) {
         namespaces = this.parent.getXmlns()
+    }
 
     for (var attr in this.attrs) {
         var m = attr.match('xmlns:?(.*)')
@@ -92,13 +95,15 @@ Element.prototype.setAttrs = function(attrs) {
  * xmlns can be null, returns the matching attribute.
  **/
 Element.prototype.getAttr = function(name, xmlns) {
-    if (!xmlns)
+    if (!xmlns) {
         return this.attrs[name]
+    }
 
     var namespaces = this.getXmlns()
 
-    if (!namespaces[xmlns])
+    if (!namespaces[xmlns]) {
         return null
+    }
 
     return this.attrs[[namespaces[xmlns], name].join(':')]
 }
@@ -147,7 +152,9 @@ Element.prototype.getChildrenByAttr = function(attr, val, xmlns, recursive) {
             result.push(child.getChildrenByAttr(attr, val, xmlns, true))
         }
     }
-    if (recursive) result = [].concat.apply([], result)
+    if (recursive) {
+        result = [].concat.apply([], result)
+    }
     return result
 }
 
@@ -198,19 +205,19 @@ Element.prototype.getChildElements = function() {
 
 /** returns uppermost parent */
 Element.prototype.root = function() {
-    if (this.parent)
+    if (this.parent) {
         return this.parent.root()
-    else
-        return this
+    }
+    return this
 }
 Element.prototype.tree = Element.prototype.root
 
 /** just parent or itself */
 Element.prototype.up = function() {
-    if (this.parent)
+    if (this.parent) {
         return this.parent
-    else
-        return this
+    }
+    return this
 }
 
 Element.prototype._getElement = function(name, attrs) {
@@ -225,8 +232,9 @@ Element.prototype.c = function(name, attrs) {
 
 Element.prototype.cnode = function(child) {
     this.children.push(child)
-    if (typeof child === 'object')
+    if (typeof child === 'object') {
         child.parent = this
+    }
     return child
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list