Skip to content

Commit

Permalink
String width optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
vitmalina committed Feb 19, 2024
1 parent 402815e commit 19bacf4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/w2utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1493,13 +1493,13 @@ class Utils {
}

getStrWidth(str, styles, raw) {
query('body').append(`
<div id="_tmp_width" style="position: absolute; top: -9000px; ${styles || ''}">
${raw ? str : this.encodeTags(str)}
</div>`)
let width = query('#_tmp_width')[0].clientWidth
query('#_tmp_width').remove()
return width
let div = query('body > #_tmp_width')
if (div.length === 0) {
query('body').append('<div id="_tmp_width" style="position: absolute; top: -9000px;"></div>')
}
div.html(raw ? str : this.encodeTags(str))
.attr('style', `position: absolute; top: -9000px; ${styles || ''}`)
return div[0].clientWidth
}

execTemplate(str, replace_obj) {
Expand Down

0 comments on commit 19bacf4

Please sign in to comment.