1(function (Drupal, $, cookies, once) { 2 Drupal.behaviors.uspto_alerts = { 3 attach: function (context, settings) { 4 // Var to hold alert message from JSON. 5 var jsonMessage = ""; 6 7 $.ajax({ 8 async: false, 9 url: "/alerts.json", 10 dataType: "json", 11 success: function (data) { 12 // Store alert message in global variable for later use. 13 jsonMessage = data.alert; 14 }, 15 error: function (jqXHR, textStatus, errorThrown) { 16 console.log(errorThrown); 17 }, 18 }); 19 20 $(".wrapper-alert", context).each(function (index, block) { 21 const alertWrapper = $(block).parents(".uspto-alert"); 22 const alertWrapperId = alertWrapper.attr("id"); 23 24 // Show alert only if alertWrapperId is not in the cookie and not set to "closed". 25 if (cookies.get(alertWrapperId) !== "closed") { 26 // Add global alert message from JSON. 27 $(alertWrapper) 28 .find(".block .container .field--name-field-global-alert") 29 .html(jsonMessage); 30 31 // Show alert element which by default set to display:none look at uspto_alerts.module. 32 if ($('.alert-content').length) { 33 $(alertWrapper).show(); 34 } 35 36 // Add close button and functionality. 37 // Global alerts have their own close button. All buttons need listeners. 38 if (!/global/.test(alertWrapperId)) { 39 Drupal.behaviors.uspto_alerts.addClose($(block).children('.alert')); 40 } 41 Drupal.behaviors.uspto_alerts.addCloseListener($(block).children('.alert')); 42 43 } 44 }); 45 46 // If a link exists in global alert text, clicking on link should dismiss the alert. 47 $( 48 once( 49 "global-alert-link", 50 ".header-highlighted-global .field--name-field-global-alert a", 51 context 52 ) 53 ).on("click", function () { 54 var alert_wrp = $(this).closest(".alert"); 55 if (alert_wrp.length && alert_wrp.find(".close").length) { 56 alert_wrp.find(".close").trigger("click"); 57 } 58 }); 59 60 // Alerts change the height of the header. Need to adjust the background height. 61 let bg_height = $('section.banner').height() + $('.region-header-top').height() + ($('.region-header-highlighted').height() || 0) + $('.region-header-middle').height(); 62 $('.dialog-off-canvas-main-canvas').css('background-size', '100% ' + String(bg_height) + 'px'); 63 64 }, 65 addClose: function (element) { 66 // Add close button. 67 var parentWrp = $(element).parents(".uspto-alert"); 68 if ( 69 parentWrp.length == 0 || 70 (parentWrp && parentWrp.data("disable-close") != true) 71 ) { 72 if (!document.body.classList.contains("ds-2")) { 73 $(element).prepend( 74 '<button type="button" class="btn-close"><span class="sr-only">Close</span></button>' 75 ); 76 } else { 77 $(element).append( 78 '<div class="alert-close-button"><button type="button" class="btn-close ml-3"><span class="sr-only">Close</span></button></div>' 79 ); 80 } 81 } 82 }, 83 addCloseListener: function(element) { 84 // Add event listener for close button. 85 $(element) 86 .find(".btn-close") 87 .click(function (event) { 88 event.preventDefault(); 89 90 // Get the id of the alert wrapper. alertWrapperId contains node id and alert version. 91 const alertWrapperId = $(element).parents(".uspto-alert").attr("id"); 92 // Smooth fade out close. 93 $(element).fadeOut("slow", function () { 94 $(element).remove(); 95 96 // Set 'closed' as cookie value for alertWrapperId contains node id and alert version. 97 cookies.set(alertWrapperId, "closed", { 98 expires: 7, 99 path: "/", 100 }); 101 }); 102 }); 103 } 104 105 }; 106})(Drupal, jQuery, window.Cookies, once);
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.