1/** 2 * @file 3 * Used to add a class to the top level element when an external font is ready. 4 */ 5 6/* global Drupal:false */ 7 8/** 9 * Run the check. 10 * 11 * @param {string} key 12 * The class name to add to the html tag. 13 * @param {string} value 14 * The font name. 15 */ 16function advagg_run_check(key, value) { 17 "use strict"; 18 // Only run if window.FontFaceObserver is defined. 19 if (window.FontFaceObserver) { 20 new window.FontFaceObserver(value).check().then(function () { 21 // Only alpha numeric value. 22 key = key.replace(/[^a-zA-Z0-9\-]/g, ''); 23 24 // Set Class. 25 if (Drupal.settings.advagg_font_no_fout != 1) { 26 window.document.documentElement.className += ' ' + key; 27 } 28 29 // Set Cookie for a day. 30 if (Drupal.settings.advagg_font_cookie == 1) { 31 var expire_date = new Date(new Date().getTime() + 86400 * 1000); 32 document.cookie = 'advaggfont_' + key + '=' + value + ';' 33 + ' expires=' + expire_date.toGMTString() + ';' 34 + ' path=/;' 35 + ' domain=.' + document.location.hostname + ';'; 36 } 37 }, function () {} 38 ); 39 } 40 else { 41 // Try again in 100 ms. 42 window.setTimeout(function () { 43 advagg_run_check(key, value); 44 }, 100); 45 } 46} 47 48/** 49 * Get the list of fonts to check for. 50 */ 51function advagg_font_add_font_classes_on_load() { 52 "use strict"; 53 for (var key in Drupal.settings.advagg_font) { 54 var html_class = (' ' + window.document.documentElement.className + ' ').indexOf(' ' + key + ' '); 55 // If the class already exists in the html element do nothing. 56 if (html_class === -1) { 57 // Wait till the font is downloaded, then set cookie & class. 58 advagg_run_check(key, Drupal.settings.advagg_font[key]); 59 } 60 } 61} 62 63/** 64 * Make sure jQuery and Drupal.settings are defined before running. 65 */ 66function advagg_font_check() { 67 "use strict"; 68 if (window.jQuery && window.Drupal && window.Drupal.settings) { 69 advagg_font_add_font_classes_on_load(); 70 } 71 else { 72 // Try again in 20 ms. 73 window.setTimeout(advagg_font_check, 20); 74 } 75} 76 77// Start the process. 78advagg_font_check();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.