| OLD | NEW |
| 1 // A test using Ahem font includes this file to ensure that the | 1 // This file is included by tests using Ahem font to ensure that the font is |
| 2 // font is loaded before window.onload fires and test finishes. | 2 // loaded before window.onload fires and the test finishes. |
| 3 // Note: this doesn't work if the test doesn't contain any visible | 3 // Note: this doesn't work if the test doesn't contain any visible element with |
| 4 // element with 'font-family: Ahem' style. | 4 // 'font-family: Ahem' style. |
| 5 (function() { | 5 (function() { |
| 6 var scripts = document.getElementsByTagName('script'); | 6 var scripts = document.getElementsByTagName('script'); |
| 7 var src = scripts[scripts.length - 1].src; | 7 var scriptSrc = scripts[scripts.length - 1].src; |
| 8 var lastSlash = src.lastIndexOf('/'); | 8 var relativePath = scriptSrc.substr(0, scriptSrc.lastIndexOf('/')); |
| 9 var relativePath = src.substr(0, lastSlash); | |
| 10 | 9 |
| 11 window.addEventListener('DOMContentLoad', function() { | 10 window.addEventListener('DOMContentLoaded', function() { |
| 12 var style = document.createElement('style'); | 11 var style = document.createElement('style'); |
| 13 style.appendChild(document.createTextNode( | 12 style.appendChild(document.createTextNode( |
| 14 '@font-face { font-family: Ahem; src: url(' + relativePath + '/Ahem.ttf'))
; | 13 '@font-face { font-family: Ahem; src: url(' + relativePath + '/Ahem.ttf'))
; |
| 15 document.head.appendChild(style); | 14 document.head.appendChild(style); |
| 16 // Force a layout to start loading the font. | 15 // Force a layout to start loading the font. |
| 17 document.documentElement.offsetTop; | 16 document.documentElement.offsetTop; |
| 18 }, true); | 17 }, true); |
| 19 }()); | 18 }()); |
| OLD | NEW |