Skip to content

Commit 12e5cba

Browse files
authored
Change size (#16)
* add new line of buttons * change fonSize * fix change size errors
1 parent 92085f6 commit 12e5cba

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

toolbar/test.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
</head>
1313
<body>
1414
<style>
15-
h2 {
16-
margin-bottom: 80px;
17-
}
1815
ul >li {
1916
display: block;
2017
border-bottom: 1px dashed #e8e8e8;

toolbar/toolbar.js

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,41 @@ function loadProvisuToolbar(element, url, file, extra) {
4545
'<div class="tooltip-inner tooltip-wide"></div></div>',
4646
});
4747
$('#toolbar-smaller').click(function() {
48-
setFontSize(getFontSize() - 4);
48+
setFontSize(-4);
4949
});
5050
$('#toolbar-bigger').click(function() {
51-
setFontSize(getFontSize() + 4);
51+
setFontSize(4);
5252
});
5353
});
5454
}
5555
}
5656

57-
function getFontSize() {
58-
var el = document.body;
59-
var style = window.getComputedStyle(el, null).getPropertyValue('font-size');
60-
return parseFloat(style);
61-
}
62-
63-
function setFontSize(size) {
64-
var el = document.body;
65-
el.style.fontSize = size + 'px';
66-
return size;
57+
function setFontSize(variant) {
58+
var tags = ['span', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
59+
var elements = [document.body];
60+
var tmp;
61+
var currentFontSize;
62+
var currentLineHeight;
63+
var newSize;
64+
var newHeight;
65+
for (var i = 0; i < tags.length; i++) {
66+
tmp = Array.prototype.slice.call(
67+
document.body.getElementsByTagName(tags[i]), 0
68+
);
69+
elements = elements.concat(tmp);
70+
}
71+
for (i = 0; i < elements.length; i++) {
72+
currentFontSize = parseFloat(
73+
window.getComputedStyle(elements[i], null).getPropertyValue('font-size')
74+
);
75+
currentLineHeight = parseFloat(
76+
window.getComputedStyle(elements[i], null).getPropertyValue('line-height')
77+
);
78+
newSize = currentFontSize + variant;
79+
newHeight = currentLineHeight + variant;
80+
elements[i].style.fontSize = newSize + 'px';
81+
elements[i].style.lineHeight = newHeight + 'px';
82+
}
6783
}
6884

6985
function generateHTML(element, url, i18n, extra) {
@@ -124,17 +140,16 @@ function generateHTML(element, url, i18n, extra) {
124140
'title="' + i18n.toolbarDescription.message + '">' +
125141
'<i class="fa fa-low-vision fa-2x" aria-hidden="true"></i>' +
126142
'</a>' +
127-
// Remove font-size buttons
128-
// '<button type="button" class="btn btn-default" id="toolbar-smaller" ' +
129-
// 'data-toggle="tooltip" data-placement="bottom" ' +
130-
// 'title="' + i18n.infoSmaller.message + '">' +
131-
// '<i class="fa fa-minus fa-2x" aria-hidden="true"></i>' +
132-
// '</button>' +
133-
// '<button type="button" class="btn btn-default" id="toolbar-bigger" ' +
134-
// 'data-toggle="tooltip" data-placement="bottom" ' +
135-
// 'title="' + i18n.infoBigger.message + '">' +
136-
// '<i class="fa fa-plus fa-2x" aria-hidden="true"></i>' +
137-
// '</button>' +
143+
'<button type="button" class="btn btn-default" id="toolbar-smaller" ' +
144+
'data-toggle="tooltip" data-placement="bottom" ' +
145+
'title="' + i18n.infoSmaller.message + '">' +
146+
'<i class="fa fa-minus fa-2x" aria-hidden="true"></i>' +
147+
'</button>' +
148+
'<button type="button" class="btn btn-default" id="toolbar-bigger" ' +
149+
'data-toggle="tooltip" data-placement="bottom" ' +
150+
'title="' + i18n.infoBigger.message + '">' +
151+
'<i class="fa fa-plus fa-2x" aria-hidden="true"></i>' +
152+
'</button>' +
138153
'</div>';
139154
}
140155
document.getElementById(element).innerHTML = html;

0 commit comments

Comments
 (0)