1(function ($) { 2 3"use strict"; 4 5 /** 6 * Attaches menu styles to menu blocks. Currently only the "dropdown" style. 7 */ 8Backdrop.behaviors.menuStyles = { 9 attach: function(context, settings) { 10 var $menus = $(context).find('[data-menu-style]').once('menu-style'); 11 $menus.each(function() { 12 var element = this; 13 var $menu = $(element); 14 var style = $menu.data('menuStyle'); 15 var menuSettings = $menu.data('menuSettings'); 16 if ($menu.data('clickdown')) { 17 menuSettings = $.extend(menuSettings, { 18 noMouseOver: true 19 }); 20 } 21 menuSettings = $.extend(menuSettings, { 22 collapsibleBehavior: ($menu.data('collapse')) ? ($menu.data('collapse')) : 'default' 23 }); 24 if (Backdrop.menuStyles[style]) { 25 Backdrop.menuStyles[style].attach(element, menuSettings); 26 } 27 }); 28 }, 29 detach: function(context, settings) { 30 var $menus = $(context).find('[data-menu-style]').once('menu-style'); 31 $menus.each(function() { 32 var element = this; 33 var $menu = $(element); 34 var style = $menu.data('menuStyle'); 35 var menuSettings = $menu.data('menuSettings'); 36 if (Backdrop.menuStyles[style] && Backdrop.menuStyles[style].detach) { 37 Backdrop.menuStyles[style].detach(element, menuSettings); 38 } 39 }); 40 } 41}; 42 43Backdrop.menuStyles = {}; 44Backdrop.menuStyles.dropdown = { 45 attach: function(element, settings) { 46 // Set defaults for the settings. 47 settings = $.extend(settings, { 48 subIndicatorsPos: 'append', 49 subIndicatorsText: '' 50 }); 51 $(element).addClass('sm').smartmenus(settings); 52 } 53}; 54 55/** 56 * Adds a collapsible "hamburger" button to toggle links if enabled on a menu. 57 */ 58Backdrop.behaviors.menuToggles = { 59 attach: function(context, settings) { 60 var $menus = $(context).find('[data-menu-toggle-id]').once('menu-toggles'); 61 $menus.each(function() { 62 var element = this; 63 var $menu = $(element); 64 var id = $menu.data('menuToggleId'); 65 var $menuToggleState = $('#' + id); 66 $menuToggleState.on('change', function(e) { 67 // Animate mobile menu. 68 if (this.checked) { 69 $menu.hide().slideDown(250, function() { $menu.css('display', ''); }); 70 } else { 71 $menu.show().slideUp(250, function() { $menu.css('display', ''); }); 72 } 73 }); 74 // Hide mobile menu beforeunload. 75 $(window).on('beforeunload unload', function() { 76 if ($menuToggleState[0].checked) { 77 $menuToggleState[0].click(); 78 } 79 }); 80 }); 81 } 82}; 83 84})(jQuery); 85; 86(function ($) { 87 88"use strict"; 89 90Backdrop.googleanalytics = {}; 91 92$(document).ready(function() { 93 94 // Attach mousedown, keyup, touchstart events to document only and catch 95 // clicks on all elements. 96 $(document.body).bind("mousedown keyup touchstart", function(event) { 97 98 // Catch the closest surrounding link of a clicked element. 99 $(event.target).closest("a,area").each(function() { 100 101 // Is the clicked URL internal? 102 if (Backdrop.googleanalytics.isInternal(this.href)) { 103 // Skip 'click' tracking, if custom tracking events are bound. 104 if ($(this).is('.colorbox') && (Backdrop.settings.googleanalytics.trackColorbox)) { 105 // Do nothing here. The custom event will handle all tracking. 106 //console.info("Click on .colorbox item has been detected."); 107 } 108 // Is download tracking activated and the file extension configured for download tracking? 109 else if (Backdrop.settings.googleanalytics.trackDownload && Backdrop.googleanalytics.isDownload(this.href)) { 110 // Download link clicked. 111 gtag('event', Backdrop.googleanalytics.getDownloadExtension(this.href).toUpperCase(), { 112 event_category: 'Downloads', 113 event_label: Backdrop.googleanalytics.getPageUrl(this.href), 114 transport_type: 'beacon' 115 }); 116 } 117 else if (Backdrop.googleanalytics.isInternalSpecial(this.href)) { 118 // Keep the internal URL for Google Analytics website overlay intact. 119 // @todo: May require tracking ID 120 var target = this; 121 $.each(Backdrop.settings.google_analytics.account, function () { 122 gtag('config', this, { 123 page_path: Backdrop.googleanalytics.getPageUrl(target.href), 124 transport_type: 'beacon' 125 }); 126 }); 127 } 128 } 129 else { 130 if (Backdrop.settings.googleanalytics.trackMailto && $(this).is("a[href^='mailto:'],area[href^='mailto:']")) { 131 // Mailto link clicked. 132 gtag('event', 'Click', { 133 event_category: 'Mails', 134 event_label: this.href.substring(7), 135 transport_type: 'beacon' 136 }); 137 } 138 else if (Backdrop.settings.googleanalytics.trackOutbound && this.href.match(/^\w+:\/\//i)) { 139 if (Backdrop.settings.googleanalytics.trackDomainMode !== 2 || (Backdrop.settings.googleanalytics.trackDomainMode === 2 && !Backdrop.googleanalytics.isCrossDomain(this.hostname, Backdrop.settings.googleanalytics.trackCrossDomains))) { 140 // External link clicked / No top-level cross domain clicked. 141 gtag('event', 'Click', { 142 event_category: 'Outbound links', 143 event_label: this.href, 144 transport_type: 'beacon' 145 }); 146 } 147 } 148 } 149 }); 150 }); 151 152 // Track hash changes as unique pageviews, if this option has been enabled. 153 if (Backdrop.settings.googleanalytics.trackUrlFragments) { 154 window.onhashchange = function() { 155 $.each(Backdrop.settings.google_analytics.account, function () { 156 gtag('config', this, { 157 page_path: location.pathname + location.search + location.hash 158 }); 159 }); 160 }; 161 } 162 163 // Colorbox: This event triggers when the transition has completed and the 164 // newly loaded content has been revealed. 165 if (Backdrop.settings.googleanalytics.trackColorbox) { 166 $(document).bind("cbox_complete", function () {
167 var href = $.colorbox.element().attr("href"); 168 if (href) { 169 $.each(Backdrop.settings.google_analytics.account, function () { 170 gtag('config', this, { 171 page_path: Backdrop.googleanalytics.getPageUrl(href) 172 }); 173 }); 174 } 175 }); 176 } 177 178}); 179 180/** 181 * Check whether the hostname is part of the cross domains or not. 182 * 183 * @param string hostname 184 * The hostname of the clicked URL. 185 * @param array crossDomains 186 * All cross domain hostnames as JS array. 187 * 188 * @return boolean 189 */ 190Backdrop.googleanalytics.isCrossDomain = function (hostname, crossDomains) { 191 /** 192 * jQuery < 1.6.3 bug: $.inArray crushes IE6 and Chrome if second argument is 193 * `null` or `undefined`, https://bugs.jquery.com/ticket/10076, 194 * https://github.com/jquery/jquery/commit/a839af034db2bd934e4d4fa6758a3fed8de74174 195 * 196 * @todo: Remove/Refactor in D8 197 */ 198 if (!crossDomains) { 199 return false; 200 } 201 else { 202 return $.inArray(hostname, crossDomains) > -1 ? true : false; 203 } 204}; 205 206/** 207 * Check whether this is a download URL or not. 208 * 209 * @param string url 210 * The web url to check. 211 * 212 * @return boolean 213 */ 214Backdrop.googleanalytics.isDownload = function (url) { 215 var isDownload = new RegExp("\\.(" + Backdrop.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i"); 216 return isDownload.test(url); 217}; 218 219/** 220 * Check whether this is an absolute internal URL or not. 221 * 222 * @param string url 223 * The web url to check. 224 * 225 * @return boolean 226 */ 227Backdrop.googleanalytics.isInternal = function (url) { 228 var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i"); 229 return isInternal.test(url); 230}; 231 232/** 233 * Check whether this is a special URL or not. 234 * 235 * URL types: 236 * - gotwo.module /go/* links. 237 * 238 * @param string url 239 * The web url to check. 240 * 241 * @return boolean 242 */ 243Backdrop.googleanalytics.isInternalSpecial = function (url) { 244 var isInternalSpecial = new RegExp("(\/go\/.*)$", "i"); 245 return isInternalSpecial.test(url); 246}; 247 248/** 249 * Extract the relative internal URL from an absolute internal URL. 250 * 251 * Examples: 252 * - https://mydomain.com/node/1 -> /node/1 253 * - https://example.com/foo/bar -> https://example.com/foo/bar 254 * 255 * @param string url 256 * The web url to check. 257 * 258 * @return string 259 * Internal website URL 260 */ 261Backdrop.googleanalytics.getPageUrl = function (url) { 262 var extractInternalUrl = new RegExp("^(https?):\/\/" + window.location.host, "i"); 263 return url.replace(extractInternalUrl, ''); 264}; 265 266/** 267 * Extract the download file extension from the URL. 268 * 269 * @param string url 270 * The web url to check. 271 * 272 * @return string 273 * The file extension of the passed url. e.g. "zip", "txt" 274 */ 275Backdrop.googleanalytics.getDownloadExtension = function (url) { 276 var extractDownloadextension = new RegExp("\\.(" + Backdrop.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i"); 277 var extension = extractDownloadextension.exec(url); 278 return (extension === null) ? '' : extension[1]; 279}; 280 281})(jQuery); 282;
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.