1/** 2 * @file 3 * Adds Google Custom Search Watermark. 4 */ 5 6(function ($, Drupal, drupalSettings) { 7 'use strict'; 8 9 Drupal.behaviors.googleCSECustomSearch = { 10 attach: function (context, settings) { 11 var getWatermarkBackground = function (value) { 12 var googleCSEBaseUrl = 'https://www.google.com/cse/intl/'; 13 var googleCSEImageUrl = 'images/google_custom_search_watermark.gif'; 14 var language = drupalSettings.googlePSE.language + '/'; 15 return value ? '' : ' url(' + googleCSEBaseUrl + language + googleCSEImageUrl + ') left no-repeat'; 16 }; 17 var removeWatermark = function (e) { 18 $(e.target).css('background', '#ffffff'); 19 }; 20 var addWatermark = function (e) { 21 $(e.target).css('background', '#ffffff' + getWatermarkBackground($(e.target).val())); 22 }; 23 24 var googleCSEWatermark = function (context, query) { 25 // Find any core drupal search inputs on the page. 26 var searchInputs = $(`[data-drupal-selector='${query}']`); 27 28 if (drupalSettings.googlePSE.displayWatermark === 1) { 29 searchInputs.on("blur", addWatermark); 30 searchInputs.each(function () { 31 var event = {}; 32 event.target = this; 33 addWatermark(event); 34 }); 35 } 36 else { 37 searchInputs.on("blur", removeWatermark); 38 searchInputs.each(function () { 39 var event = {}; 40 event.target = this; 41 removeWatermark(event); 42 }); 43 } 44 searchInputs.focus(removeWatermark); 45 46 }; 47 48 googleCSEWatermark('[data-drupal-selector="search-block-form"] [data-drupal-form-fields="edit-keys--2"]', 'edit-keys'); 49 googleCSEWatermark('[data-drupal-selector="search-block-form"] [data-drupal-form-fields="edit-keys"]', 'edit-keys'); 50 googleCSEWatermark('[data-drupal-selector="search-form"]', 'edit-keys'); 51 googleCSEWatermark('[data-drupal-selector="google-cse-search-box-form"]', 'edit-query'); 52 } 53 }; 54})(jQuery, Drupal, drupalSettings);
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.