diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/point_of_sale/static/lib/waitfont.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/point_of_sale/static/lib/waitfont.js')
| -rw-r--r-- | addons/point_of_sale/static/lib/waitfont.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/addons/point_of_sale/static/lib/waitfont.js b/addons/point_of_sale/static/lib/waitfont.js new file mode 100644 index 00000000..e9359896 --- /dev/null +++ b/addons/point_of_sale/static/lib/waitfont.js @@ -0,0 +1,59 @@ +// http://stackoverflow.com/questions/4383226/using-jquery-to-know-when-font-face-fonts-are-loaded +(function(){ + function waitForWebfonts(fonts, callback) { + var loadedFonts = 0; + for(var i = 0, l = fonts.length; i < l; ++i) { + (function(font) { + var node = document.createElement('span'); + // Characters that vary significantly among different fonts + node.innerHTML = 'giItT1WQy@!-/#'; + // Visible - so we can measure it - but not on the screen + node.style.position = 'absolute'; + node.style.left = '-10000px'; + node.style.top = '-10000px'; + // Large font size makes even subtle changes obvious + node.style.fontSize = '300px'; + // Reset any font properties + node.style.fontFamily = 'sans-serif'; + node.style.fontVariant = 'normal'; + node.style.fontStyle = 'normal'; + node.style.fontWeight = 'normal'; + node.style.letterSpacing = '0'; + document.body.appendChild(node); + + // Remember width with no applied web font + var width = node.offsetWidth; + + node.style.fontFamily = font; + + var interval; + function checkFont() { + // Compare current width with original width + if(node && node.offsetWidth != width) { + ++loadedFonts; + node.parentNode.removeChild(node); + node = null; + } + + // If all fonts have been loaded + if(loadedFonts >= fonts.length) { + if(interval) { + clearInterval(interval); + } + if(loadedFonts == fonts.length) { + callback(); + return true; + } + } + }; + + if(!checkFont()) { + interval = setInterval(checkFont, 50); + } + })(fonts[i]); + } + } + window.waitForWebfonts = waitForWebfonts; +})(); + + |
