smartxml: removing node attributes by setting undefined as their value
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 13 Aug 2014 08:06:56 +0000 (10:06 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 14 Aug 2014 14:26:15 +0000 (16:26 +0200)
Before this change calling Node.setAttr(undefined) was a noop.

src/smartxml/core.js

index b60bc2e..7326507 100644 (file)
@@ -169,7 +169,11 @@ var elementNodeTransformations = {
 
     setAttr: function(name, value, silent) {
         var oldVal = this.getAttr(name);
-        this._$.attr(name, value);
+        if(_.isUndefined(value)) {
+            this._$.removeAttr(name);
+        } else {
+            this._$.attr(name, value);
+        }
         if(!silent) {
             this.triggerChangeEvent('nodeAttrChange', {attr: name, oldVal: oldVal, newVal: value});
         }