can-attribute-observable
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -422,7 +422,9 @@ 'use strict'; | ||
setAttrOrProp: function(el, attrName, val){ | ||
attrName = attrName.toLowerCase(); | ||
setAttrOrProp: function(el, caseSensitiveAttrName, val){ | ||
var attrName = caseSensitiveAttrName.toLowerCase(); | ||
var special = specialAttributes[attrName]; | ||
if(special && special.isBoolean && !val) { | ||
this.remove(el, attrName); | ||
} else if (!special && caseSensitiveAttrName in el) { | ||
el[caseSensitiveAttrName] = val; | ||
} else { | ||
@@ -458,5 +460,8 @@ this.set(el, attrName, val); | ||
// ## attr.get | ||
// Gets the value of an attribute. First checks if the property is an `specialAttributes` and if so calls the special getter. Otherwise uses `getAttribute` to retrieve the value. | ||
get: function (el, attrName) { | ||
attrName = attrName.toLowerCase(); | ||
// Gets the value of an attribute or property. | ||
// First checks if the property is an `specialAttributes` and if so calls the special getter. | ||
// Then checks if the attribute or property is a property on the element. | ||
// Otherwise uses `getAttribute` to retrieve the value. | ||
get: function (el, caseSensitiveAttrName) { | ||
var attrName = caseSensitiveAttrName.toLowerCase(); | ||
var special = specialAttributes[attrName]; | ||
@@ -468,2 +473,4 @@ var getter = special && special.get; | ||
return getter.call(el); | ||
} else if (caseSensitiveAttrName in el) { | ||
return el[caseSensitiveAttrName]; | ||
} else { | ||
@@ -470,0 +477,0 @@ return el.getAttribute(attrName); |
@@ -67,5 +67,3 @@ var canReflect = require("can-reflect"); | ||
testIfRealDocument("able to read normal attributes", function(assert) { | ||
var div = document.createElement("div"); | ||
@@ -81,2 +79,19 @@ div.setAttribute("foo","bar"); | ||
}); | ||
testIfRealDocument("able to read and write properties when they exist on the element and are not in 'special' list", function(assert) { | ||
var video = document.createElement("video"); | ||
video.currentTime = 5.0; | ||
var ta = this.fixture; | ||
ta.appendChild(video); | ||
var obs = new AttributeObservable(video, "currentTime", {}); | ||
assert.equal(canReflect.getValue(obs), 5.0, "correct default value"); | ||
canReflect.setValue(obs, 10.0); | ||
assert.equal(canReflect.getValue(obs), 10.0, "correct updated value"); | ||
assert.equal(video.currentTime, 10.0, "correct updated property"); | ||
}); | ||
}); |
{ | ||
"name": "can-attribute-observable", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Create observables from HTML attributes.", | ||
@@ -5,0 +5,0 @@ "main": "can-attribute-observable", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33258
809