Merge pull request #1221 from pygy/rewrite-set-style
Overwrite an element's style using cssText (with tests fixed).
This commit is contained in:
commit
88d56cd4ae
3 changed files with 24 additions and 10 deletions
|
|
@ -441,11 +441,11 @@ module.exports = function($window) {
|
|||
|
||||
//style
|
||||
function updateStyle(element, old, style) {
|
||||
if (old === style) element.style = "", old = null
|
||||
if (style == null) element.style = ""
|
||||
else if (typeof style === "string") element.style = style
|
||||
if (old === style) element.cssText = "", old = null
|
||||
if (style == null) element.cssText = ""
|
||||
else if (typeof style === "string") element.cssText = style
|
||||
else {
|
||||
if (typeof old === "string") element.style = ""
|
||||
if (typeof old === "string") element.cssText = ""
|
||||
for (var key in style) {
|
||||
element.style[key] = style[key]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,7 +136,11 @@ module.exports = function() {
|
|||
get style() {
|
||||
return style
|
||||
},
|
||||
set style(value) {
|
||||
set style(_){
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style#Setting_style
|
||||
throw new Error("setting element.style is not portable")
|
||||
},
|
||||
set cssText(value) {
|
||||
if (typeof value === "string") {
|
||||
for (var key in style) style[key] = ""
|
||||
var rules = value.split(";")
|
||||
|
|
|
|||
|
|
@ -474,20 +474,30 @@ o.spec("domMock", function() {
|
|||
|
||||
o(typeof div.style).equals("object")
|
||||
})
|
||||
o("setting style string works", function() {
|
||||
o("setting cssText string works", function() {
|
||||
var div = $document.createElement("div")
|
||||
div.style = "background-color: red; border-bottom: 1px solid red;"
|
||||
div.cssText = "background-color: red; border-bottom: 1px solid red;"
|
||||
|
||||
o(div.style.backgroundColor).equals("red")
|
||||
o(div.style.borderBottom).equals("1px solid red")
|
||||
})
|
||||
o("removing via setting style string works", function() {
|
||||
o("removing via setting cssText string works", function() {
|
||||
var div = $document.createElement("div")
|
||||
div.style = "background: red;"
|
||||
div.style = ""
|
||||
div.cssText = "background: red;"
|
||||
div.cssText = ""
|
||||
|
||||
o(div.style.background).equals("")
|
||||
})
|
||||
o("setting style throws", function () {
|
||||
var err = false
|
||||
try {
|
||||
div.style = ''
|
||||
} catch (e) {
|
||||
err = e
|
||||
}
|
||||
|
||||
o(err instanceof Error).equals(true)
|
||||
})
|
||||
})
|
||||
o.spec("events", function() {
|
||||
o.spec("click", function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue