1/** 2 * Behaviors for the 'Today's hours' and 'More hours' functionality. 3 */ 4(function ($, Drupal){ 5 Drupal.behaviors.today_hours = { 6 /** 7 * Used to track the setInveral. 8 */ 9 refreshTimer: false, 10 11 /** 12 * @returns {string} 13 */ 14 getDayOfWeek: function (tz) { 15 // ISO day of week. returns a string of day of week, e.g. Mon, Tue, etc. 16 return moment().tz(tz).format('ddd'); 17 }, 18 19 /** 20 * @returns {string} 21 */ 22 getDate: function (tz) { 23 return moment().tz(tz).format('YYYY-MM-DD'); 24 }, 25 26 /** 27 * Primary method for updating the today hours. 28 */ 29 updateTodayHours: function () { 30 if (typeof drupalSettings.lb_branch_hours_blocks === 'undefined') { 31 drupalSettings.lb_branch_hours_blocks = {}; 32 } 33 34 var $todayHours = $('.hours .today'); 35 var hoursData = drupalSettings.lb_branch_hours_blocks.branch_hours || {}; 36 var tz = drupalSettings.lb_branch_hours_blocks.tz || 'America/New York'; 37 tz = tz.replace(/ /g,"_"); 38 39 if (Object.keys(hoursData).length) { 40 var todayString = Drupal.behaviors.today_hours.getDate(tz); 41 var dayOfWeek = Drupal.behaviors.today_hours.getDayOfWeek(tz); 42 var exceptions = drupalSettings.lb_branch_hours_blocks.exceptions; // Holidays and other day exceptions will come later. 43 44 if (typeof exceptions[todayString] != 'undefined') { 45 $todayHours.html(exceptions[todayString]); 46 } 47 else { 48 $todayHours.html(hoursData[dayOfWeek]); 49 } 50 } 51 }, 52 53 /** 54 * Drupal behavior attach. 55 * 56 * @param context 57 * @param settings 58 */ 59 attach: function (context, settings) { 60 61 var $todayHours = $('.hours .today'); 62 var onceClass = 'refresh-interval-set'; 63 64 // Bail out if there's already refresh action set. 65 if (!$todayHours.hasClass(onceClass)) { 66 67 // This will ensure that if people leave the tab open or the page comes back 68 // into memory on a phone the hour will always be correct. 69 this.refreshTimer = setInterval(this.updateTodayHours, 60 * 1000); 70 71 // Run for the first time. 72 this.updateTodayHours(); 73 $todayHours.addClass(onceClass); 74 } 75 } 76 77 }; 78 Drupal.behaviors.more_hours = { 79 attach: function (context, settings) { 80 $('.more-hours', context).click(function (e){ 81 e.preventDefault(); 82 $('.branch-hours-dropdown').show(); 83 }) 84 $('.branch-hours-dropdown .close', context).click(function (e){ 85 e.preventDefault(); 86 $('.branch-hours-dropdown').hide(); 87 }) 88 } 89 } 90})(jQuery, Drupal);
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.