hack envjs element css style parsing

This commit is contained in:
Wouter Groeneveld 2011-06-29 10:24:32 +02:00
parent 9aca411bbd
commit d0a6f2b556
2 changed files with 66 additions and 4 deletions

View File

@ -55,7 +55,8 @@
* Envjs specific hacks
* 1) Fix Envjs relative path system to work with Windows path systems
* 2) Fix window.setTimeout() using Rhino specific functions
* 3) Fix CSS2Properties support: all properties have the same objmaps, wtf?
* 3) Fix CSS2Properties support for parsing style attributes: get from raw node context.
* 4) Fix CSS2Properties support for setting values: all properties have the same objmaps, wtf?
*/
(function() {
@ -74,6 +75,29 @@
});
};
(function(Element) {
var style = "style";
function lookupStyleInNodeAttributes(el) {
if(el.attributes) {
for(var i = 0; i < el.attributes.length; i++) {
if(el.attributes[i].nodeName === style) {
return el.attributes[i].nodeValue;
}
}
}
}
var styleSetFn = Element.__lookupGetter__(style);
Element.__defineGetter__(style, function() {
if(!this.cssText) {
this.cssText = lookupStyleInNodeAttributes(this);
}
return styleSetFn.apply(this);
});
})(HTMLElement.prototype);
(function(css) {
var setCssProperty = css.prototype.setProperty;
@ -82,9 +106,8 @@
if(Object.keys(Object.getPrototypeOf(this.styleIndex)).length === 0) {
this.styleIndex = Object.create(this.styleIndex);
}
return setCssProperty.call(this, name, value);
}
})(CSS2Properties);
})();

View File

@ -1,7 +1,46 @@
importPackage(org.apache.commons.io);
importPackage(java.io);
var loadFixtures = function() {
this.fixturesPath = "src/test/javascript/specs/fixtures";
var read = "";
for(var i = 0; i < arguments.length; i++) {
read += FileUtils.readFileToString(new File(this.fixturesPath, arguments[i]));
}
document.body.innerHTML = document.body.innerHTML + read;
}
var cleanupFixtures = function() {
document.body.innerHTML = "";
}
describe("envjs fixes", function() {
describe("CSS2 style property support", function() {
describe("CSS2 style property support for parsing style attributes", function() {
beforeEach(function() {
loadFixtures("styleAttributes.html");
});
afterEach(cleanupFixtures);
it("should get a style attribute from a static DOM element", function() {
var div = document.getElementById("div");
expect(div.style.color).toBe("blue");
});
it("should get a style attribute with dashes using camelCasing properties", function() {
var spanStyle = document.getElementById("span").style;
expect(spanStyle.backgroundColor).toBe("green");
expect(spanStyle.fontSize).toBe("8pt");
expect(spanStyle.fontFamily).toBe("verdana");
});
});
describe("CSS2 style property support for setting values", function() {
var someColor = "#FFFFFF";
var someFont = "12px 'Bitstream Vera Sans Mono','Courier',monospace";