1(function ($) { 2 3 Drupal.behaviors.captcha = { 4 attach: function (context) { 5 6 // Turn off autocompletion for the CAPTCHA response field. 7 // We do it here with JavaScript (instead of directly in the markup) 8 // because this autocomplete attribute is not standard and 9 // it would break (X)HTML compliance. 10 $("#edit-captcha-response").attr("autocomplete", "off"); 11 12 } 13 }; 14 15 Drupal.behaviors.captchaAdmin = { 16 attach: function (context) { 17 // Add onclick handler to checkbox for adding a CAPTCHA description 18 // so that the textfields for the CAPTCHA description are hidden 19 // when no description should be added. 20 // @todo: div.form-item-captcha-description depends on theming, maybe 21 // it's better to add our own wrapper with id (instead of a class). 22 $("#edit-captcha-add-captcha-description").click(function() { 23 if ($("#edit-captcha-add-captcha-description").is(":checked")) { 24 // Show the CAPTCHA description textfield(s). 25 $("div.form-item-captcha-description").show('slow'); 26 } 27 else { 28 // Hide the CAPTCHA description textfield(s). 29 $("div.form-item-captcha-description").hide('slow'); 30 } 31 }); 32 // Hide the CAPTCHA description textfields if option is disabled on page load. 33 if (!$("#edit-captcha-add-captcha-description").is(":checked")) { 34 $("div.form-item-captcha-description").hide(); 35 } 36 } 37 38 }; 39 40})(jQuery); 41; 42(function ($) { 43 44Drupal.googleanalytics = {}; 45 46$(document).ready(function() { 47 48 // Attach mousedown, keyup, touchstart events to document only and catch 49 // clicks on all elements. 50 $(document.body).bind("mousedown keyup touchstart", function(event) { 51 52 // Catch the closest surrounding link of a clicked element. 53 $(event.target).closest("a,area").each(function() { 54 55 // Is the clicked URL internal? 56 if (Drupal.googleanalytics.isInternal(this.href)) { 57 // Skip 'click' tracking, if custom tracking events are bound. 58 if ($(this).is('.colorbox') && (Drupal.settings.googleanalytics.trackColorbox)) { 59 // Do nothing here. The custom event will handle all tracking. 60 //console.info("Click on .colorbox item has been detected."); 61 } 62 // Is download tracking activated and the file extension configured for download tracking? 63 else if (Drupal.settings.googleanalytics.trackDownload && Drupal.googleanalytics.isDownload(this.href)) { 64 // Download link clicked. 65 ga("send", { 66 "hitType": "event", 67 "eventCategory": "Downloads", 68 "eventAction": Drupal.googleanalytics.getDownloadExtension(this.href).toUpperCase(), 69 "eventLabel": Drupal.googleanalytics.getPageUrl(this.href), 70 "transport": "beacon" 71 }); 72 } 73 else if (Drupal.googleanalytics.isInternalSpecial(this.href)) { 74 // Keep the internal URL for Google Analytics website overlay intact. 75 ga("send", { 76 "hitType": "pageview", 77 "page": Drupal.googleanalytics.getPageUrl(this.href), 78 "transport": "beacon" 79 }); 80 } 81 } 82 else { 83 if (Drupal.settings.googleanalytics.trackMailto && $(this).is("a[href^='mailto:'],area[href^='mailto:']")) { 84 // Mailto link clicked. 85 ga("send", { 86 "hitType": "event", 87 "eventCategory": "Mails", 88 "eventAction": "Click", 89 "eventLabel": this.href.substring(7), 90 "transport": "beacon" 91 }); 92 } 93 else if (Drupal.settings.googleanalytics.trackOutbound && this.href.match(/^\w+:\/\//i)) { 94 if (Drupal.settings.googleanalytics.trackDomainMode !== 2 || (Drupal.settings.googleanalytics.trackDomainMode === 2 && !Drupal.googleanalytics.isCrossDomain(this.hostname, Drupal.settings.googleanalytics.trackCrossDomains))) { 95 // External link clicked / No top-level cross domain clicked. 96 ga("send", { 97 "hitType": "event", 98 "eventCategory": "Outbound links", 99 "eventAction": "Click", 100 "eventLabel": this.href, 101 "transport": "beacon" 102 }); 103 } 104 } 105 } 106 }); 107 }); 108 109 // Track hash changes as unique pageviews, if this option has been enabled. 110 if (Drupal.settings.googleanalytics.trackUrlFragments) { 111 window.onhashchange = function() { 112 ga("send", { 113 "hitType": "pageview", 114 "page": location.pathname + location.search + location.hash 115 }); 116 }; 117 } 118 119 // Colorbox: This event triggers when the transition has completed and the 120 // newly loaded content has been revealed. 121 if (Drupal.settings.googleanalytics.trackColorbox) { 122 $(document).bind("cbox_complete", function () {
123 var href = $.colorbox.element().attr("href"); 124 if (href) { 125 ga("send", { 126 "hitType": "pageview", 127 "page": Drupal.googleanalytics.getPageUrl(href) 128 }); 129 } 130 }); 131 } 132 133}); 134 135/** 136 * Check whether the hostname is part of the cross domains or not. 137 * 138 * @param string hostname 139 * The hostname of the clicked URL. 140 * @param array crossDomains 141 * All cross domain hostnames as JS array. 142 * 143 * @return boolean 144 */ 145Drupal.googleanalytics.isCrossDomain = function (hostname, crossDomains) { 146 /** 147 * jQuery < 1.6.3 bug: $.inArray crushes IE6 and Chrome if second argument is 148 * `null` or `undefined`, http://bugs.jquery.com/ticket/10076, 149 * https://github.com/jquery/jquery/commit/a839af034db2bd934e4d4fa6758a3fed8de74174 150 * 151 * @todo: Remove/Refactor in D8 152 */ 153 if (!crossDomains) { 154 return false; 155 } 156 else { 157 return $.inArray(hostname, crossDomains) > -1 ? true : false; 158 } 159}; 160 161/** 162 * Check whether this is a download URL or not. 163 * 164 * @param string url 165 * The web url to check. 166 * 167 * @return boolean 168 */ 169Drupal.googleanalytics.isDownload = function (url) { 170 var isDownload = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i"); 171 return isDownload.test(url); 172}; 173 174/** 175 * Check whether this is an absolute internal URL or not. 176 * 177 * @param string url 178 * The web url to check. 179 * 180 * @return boolean 181 */ 182Drupal.googleanalytics.isInternal = function (url) { 183 var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i"); 184 return isInternal.test(url); 185}; 186 187/** 188 * Check whether this is a special URL or not. 189 * 190 * URL types: 191 * - gotwo.module /go/* links. 192 * 193 * @param string url 194 * The web url to check. 195 * 196 * @return boolean 197 */ 198Drupal.googleanalytics.isInternalSpecial = function (url) { 199 var isInternalSpecial = new RegExp("(\/go\/.*)$", "i"); 200 return isInternalSpecial.test(url); 201}; 202 203/** 204 * Extract the relative internal URL from an absolute internal URL. 205 * 206 * Examples: 207 * - http://mydomain.com/node/1 -> /node/1 208 * - http://example.com/foo/bar -> http://example.com/foo/bar 209 * 210 * @param string url 211 * The web url to check. 212 * 213 * @return string 214 * Internal website URL 215 */ 216Drupal.googleanalytics.getPageUrl = function (url) { 217 var extractInternalUrl = new RegExp("^(https?):\/\/" + window.location.host, "i"); 218 return url.replace(extractInternalUrl, ''); 219}; 220 221/** 222 * Extract the download file extension from the URL. 223 * 224 * @param string url 225 * The web url to check. 226 * 227 * @return string 228 * The file extension of the passed url. e.g. "zip", "txt" 229 */ 230Drupal.googleanalytics.getDownloadExtension = function (url) { 231 var extractDownloadextension = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i"); 232 var extension = extractDownloadextension.exec(url); 233 return (extension === null) ? '' : extension[1]; 234}; 235 236})(jQuery); 237;
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.