Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions spec/domeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,35 @@ describe("dome", function () {
});
});

describe("addStyle", function () {
beforeEach(function () {
this.d = dome.get(".two");
});
afterEach(function () {
this.d.forEach(function (el) {
el.style.removeProperty('color');
el.style.removeProperty('padding-top');
});
});
it("can set inline element styles", function () {
this.d.addStyle({"color":"rgb(255, 0, 0)","padding-top":"5px"});
expect(this.d[0].style.getPropertyValue("color")).toEqual("rgb(255, 0, 0)");
expect(this.d[0].style.getPropertyValue("padding-top")).toEqual("5px");
});
});

describe("removeStyle", function () {
beforeEach(function () {
this.d = dome.get(".two");
this.d.addStyle({"color":"rgb(255, 0, 0)","padding-top":"5px"});
});
it("can remove inline element styles", function () {
this.d.removeStyle(['color','padding-top']);
expect(this.d[0].style.getPropertyValue("color")).toEqual(null);
expect(this.d[0].style.getPropertyValue("padding-top")).toEqual(null);
});
});

describe("create", function () {
it("can create elements", function () {
expect(dome.create("p")[0].tagName).toEqual("P");
Expand Down
22 changes: 22 additions & 0 deletions src/dome.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,28 @@ window.dome = (function () {
}
};

Dome.prototype.addStyle = function (val) {
return this.forEach(function(el) {
for (var prop in val) {
el.style[prop] = val[prop];
}
});
};

Dome.prototype.removeStyle = function (val) {
if(typeof val !== 'string') {
return this.forEach(function(el) {
for (var i = 0; i < val.length; i++) {
el.style.removeProperty(val[i]);
}
});
} else {
return this.forEach(function(el) {
el.style.removeProperty(val);
});
}
};

Dome.prototype.append = function (els) {
return this.forEach(function (parEl, i) {
els.forEach(function (childEl) {
Expand Down