1/** 2 * @file 3 * axis_advertisement.js 4 * 5 */ 6 7(function ($, Drupal, drupalSettings) { 8 9 'use strict'; 10 11 function getRandomInt(min, max) { 12 min = Math.ceil(min); 13 max = Math.floor(max); 14 return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive 15 } 16 17 Drupal.behaviors.axisAdvertisementShow = { 18 attach: function (context) { 19 var adSettings = [ 20 { 21 type: 'banner', 22 url: '/advertisement/banner' 23 }, 24 { 25 type: 'sidebar', 26 url: '/advertisement/sidebar' 27 }, 28 { 29 type: 'footer', 30 url: '/advertisement/footer' 31 } 32 ]; 33 Object.keys(adSettings).forEach(function (key) { 34 $.ajax({ 35 url: adSettings[key].url, 36 data: { 37 format: 'json' 38 }, 39 error: function() { 40 console.log('there was an error'); 41 }, 42 success: function(data) { 43 var aid = 0; 44 var adNumber = getRandomInt(0, data.length - 1); 45 var adType = adSettings[key].type; 46 if (data.length > 0) { 47 var $placeholder = $(once("adv"+ adType, "#advertisement--" + adType)); 48 $placeholder.each(function () { 49 var link = $('<a class="advertisement--link">'); 50 aid = data[adNumber].aid; 51 link.attr('href', data[adNumber].redirect_url); 52 link.attr('data-aid', aid); 53 if (data[adNumber].new_window) { 54 link.attr('target', '_blank'); 55 } 56 var img = $('<img class="advertisement--image">'); 57 img.attr('src', data[adNumber].image); 58 if (data[adNumber].image_alt_text !== false) { 59 img.attr('alt', data[adNumber].image_alt_text); 60 } 61 img.appendTo(link); 62 link.appendTo($placeholder); 63 link.on('click', function () { 64 $.ajax({ 65 url: Drupal.url('advertisement/log'), 66 type: 'POST', 67 data: { 68 'aid': aid, 69 'event': 'click', 70 'location': window.location.href, 71 'placement': adType, 72 }, 73 dataType: 'json', 74 }); 75 }); 76 77 }); 78 } 79 }, 80 type: 'GET' 81 }); 82 }); 83 } 84 }; 85 86})(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.