Skip to content

Commit 7e3064c

Browse files
committed
pass objects to stylesheet.addRule
1 parent f135ef8 commit 7e3064c

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

core/Item.qml

+23-10
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,31 @@ Object {
7474

7575
///@private
7676
function registerStyle(style, tag) {
77-
var rules = 'position: absolute; visibility: inherit; opacity: 1.0;'
78-
rules += 'border-style: solid; border-width: 0px; border-radius: 0px; box-sizing: border-box; border-color: rgba(0,0,0,1);'
79-
rules += 'white-space: nowrap; transform: none;'
80-
rules += 'left: 0px; top: 0px; width: 0px; height: 0px;'
81-
rules += 'font-family: ' + $manifest$style$font$family + '; '
82-
rules += 'line-height: ' + $manifest$style$font$lineHeight + '; '
83-
rules += 'font-weight: ' + $manifest$style$font$weight + '; '
84-
rules += 'pointer-events: inherit; touch-action: inherit; '
77+
var rules = {
78+
'position': 'absolute',
79+
'visibility': 'inherit',
80+
'opacity': 1.0,
81+
'border-style': 'solid',
82+
'border-width': '0px',
83+
'border-radius': '0px',
84+
'box-sizing': 'border-box',
85+
'border-color': 'rgba(0,0,0,1)',
86+
'white-space': 'nowrap',
87+
'transform': 'none',
88+
'left': '0px',
89+
'top': '0px',
90+
'width': '0px',
91+
'height': '0px',
92+
'font-family': $manifest$style$font$family,
93+
'line-height': $manifest$style$font$lineHeight,
94+
'font-weight': $manifest$style$font$weight,
95+
'pointer-events': 'inherit',
96+
'touch-action': 'inherit'
97+
}
8598
if ($manifest$style$font$pixelSize)
86-
rules += 'font-size: ' + $manifest$style$font$pixelSize + 'px; '
99+
rules['font-size'] = $manifest$style$font$pixelSize + 'px'
87100
else if ($manifest$style$font$pointSize)
88-
rules += 'font-size: ' + $manifest$style$font$pointSize + 'pt; '
101+
rules['font-size'] = $manifest$style$font$pointSize + 'pt'
89102
style.addRule(tag, rules)
90103
}
91104

core/Text.qml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Item {
2424
function getClass() { return 'core-text' }
2525

2626
function registerStyle(style, tag) {
27-
style.addRule(tag, 'width: auto; height: auto;')
27+
style.addRule(tag, {'width': 'auto', 'height': 'auto'})
2828
}
2929

3030
///@private

platform/html5/html.js

+16
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,25 @@ exports.capabilities = {
1111

1212
var imageCache = null
1313

14+
var rulesToStylesheet = function(rules) {
15+
var type = typeof rules;
16+
if (type === 'string') {
17+
return rules
18+
} else if (type === 'object') {
19+
var res = []
20+
for(var name in rules)
21+
res.push(name + ': ' + rules[name].toString())
22+
return res.join(";\n")
23+
} else
24+
rules = rules.toString()
25+
return rules
26+
}
27+
1428
exports.createAddRule = function(style) {
1529
if(! (style.sheet || {}).insertRule) {
1630
var sheet = (style.styleSheet || style.sheet)
1731
return function(name, rules) {
32+
rules = rulesToStylesheet(rules)
1833
try {
1934
sheet.addRule(name, rules)
2035
} catch(e) {
@@ -26,6 +41,7 @@ exports.createAddRule = function(style) {
2641
else {
2742
var sheet = style.sheet
2843
return function(name, rules) {
44+
rules = rulesToStylesheet(rules)
2945
try {
3046
sheet.insertRule(name + '{' + rules + '}', sheet.cssRules.length)
3147
} catch(e) {

0 commit comments

Comments
 (0)