1(function ($) { 2 Drupal.behaviors.rate = { 3 attach: function(context) { 4 $('.rate-widget:not(.rate-processed)', context).addClass('rate-processed').each(function () { 5 var widget = $(this); 6 // as we use drupal_html_id() to generate unique ids 7 // we have to truncate the '--<id>' 8 var ids = widget.attr('id').split('--'); 9 ids = ids[0].match(/^rate\-([a-z]+)\-([0-9]+)\-([0-9]+)\-([0-9])$/); 10 var data = { 11 content_type: ids[1], 12 content_id: ids[2], 13 widget_id: ids[3], 14 widget_mode: ids[4] 15 }; 16 17 $('a.rate-button', widget).click(function() { 18 var token = this.getAttribute('href').match(/rate\=([a-zA-Z0-9\-_]{32,64})/)[1]; 19 return Drupal.rateVote(widget, data, token); 20 }); 21 }); 22 } 23 }; 24 25 Drupal.rateVote = function(widget, data, token) { 26 // Invoke JavaScript hook. 27 widget.trigger('eventBeforeRate', [data]); 28 29 $(".rate-info", widget).text(Drupal.t('Saving vote...')); 30 31 // Random number to prevent caching, see http://drupal.org/node/1042216#comment-4046618 32 var random = Math.floor(Math.random() * 99999); 33 34 var q = (Drupal.settings.rate.basePath.match(/\?/) ? '&' : '?') + 'widget_id=' + data.widget_id + '&content_type=' + data.content_type + '&content_id=' + data.content_id + '&widget_mode=' + data.widget_mode + '&token=' + token + '&destination=' + encodeURIComponent(Drupal.settings.rate.destination) + '&r=' + random; 35 if (data.value) { 36 q = q + '&value=' + data.value; 37 } 38 39 // fetch all widgets with this id as class 40 widget = $('.' + widget.attr('id')); 41 42 $.get(Drupal.settings.rate.basePath + q, function(response) { 43 if (response.match(/^https?\:\/\/[^\/]+\/(.*)$/)) { 44 // We got a redirect. 45 document.location = response; 46 } 47 else { 48 // get parent object 49 var p = widget.parent(); 50 51 // Invoke JavaScript hook. 52 widget.trigger('eventAfterRate', [data]); 53 54 widget.before(response); 55 56 // remove widget 57 widget.remove(); 58 widget = undefined; 59 60 Drupal.attachBehaviors(p); 61 } 62 }); 63 64 return false; 65 } 66})(jQuery); 67; 68(function ($) { 69 70Drupal.googleanalytics = {}; 71 72$(document).ready(function() { 73 74 // Attach mousedown, keyup, touchstart events to document only and catch 75 // clicks on all elements. 76 $(document.body).bind("mousedown keyup touchstart", function(event) { 77 78 // Catch the closest surrounding link of a clicked element. 79 $(event.target).closest("a,area").each(function() { 80 81 // Is the clicked URL internal? 82 if (Drupal.googleanalytics.isInternal(this.href)) { 83 // Skip 'click' tracking, if custom tracking events are bound. 84 if ($(this).is('.colorbox') && (Drupal.settings.googleanalytics.trackColorbox)) { 85 // Do nothing here. The custom event will handle all tracking. 86 //console.info("Click on .colorbox item has been detected."); 87 } 88 // Is download tracking activated and the file extension configured for download tracking? 89 else if (Drupal.settings.googleanalytics.trackDownload && Drupal.googleanalytics.isDownload(this.href)) { 90 // Download link clicked. 91 ga("send", { 92 "hitType": "event", 93 "eventCategory": "Downloads", 94 "eventAction": Drupal.googleanalytics.getDownloadExtension(this.href).toUpperCase(), 95 "eventLabel": Drupal.googleanalytics.getPageUrl(this.href), 96 "transport": "beacon" 97 }); 98 } 99 else if (Drupal.googleanalytics.isInternalSpecial(this.href)) { 100 // Keep the internal URL for Google Analytics website overlay intact. 101 ga("send", { 102 "hitType": "pageview", 103 "page": Drupal.googleanalytics.getPageUrl(this.href), 104 "transport": "beacon" 105 }); 106 } 107 } 108 else { 109 if (Drupal.settings.googleanalytics.trackMailto && $(this).is("a[href^='mailto:'],area[href^='mailto:']")) { 110 // Mailto link clicked. 111 ga("send", { 112 "hitType": "event", 113 "eventCategory": "Mails", 114 "eventAction": "Click", 115 "eventLabel": this.href.substring(7), 116 "transport": "beacon" 117 }); 118 } 119 else if (Drupal.settings.googleanalytics.trackOutbound && this.href.match(/^\w+:\/\//i)) { 120 if (Drupal.settings.googleanalytics.trackDomainMode !== 2 || (Drupal.settings.googleanalytics.trackDomainMode === 2 && !Drupal.googleanalytics.isCrossDomain(this.hostname, Drupal.settings.googleanalytics.trackCrossDomains))) { 121 // External link clicked / No top-level cross domain clicked. 122 ga("send", { 123 "hitType": "event", 124 "eventCategory": "Outbound links", 125 "eventAction": "Click", 126 "eventLabel": this.href, 127 "transport": "beacon" 128 }); 129 } 130 } 131 } 132 }); 133 }); 134 135 // Track hash changes as unique pageviews, if this option has been enabled. 136 if (Drupal.settings.googleanalytics.trackUrlFragments) { 137 window.onhashchange = function() { 138 ga("send", { 139 "hitType": "pageview", 140 "page": location.pathname + location.search + location.hash 141 }); 142 }; 143 } 144 145 // Colorbox: This event triggers when the transition has completed and the 146 // newly loaded content has been revealed. 147 if (Drupal.settings.googleanalytics.trackColorbox) { 148 $(document).bind("cbox_complete", function () {
149 var href = $.colorbox.element().attr("href"); 150 if (href) { 151 ga("send", { 152 "hitType": "pageview", 153 "page": Drupal.googleanalytics.getPageUrl(href) 154 }); 155 } 156 }); 157 } 158 159}); 160 161/** 162 * Check whether the hostname is part of the cross domains or not. 163 * 164 * @param string hostname 165 * The hostname of the clicked URL. 166 * @param array crossDomains 167 * All cross domain hostnames as JS array. 168 * 169 * @return boolean 170 */ 171Drupal.googleanalytics.isCrossDomain = function (hostname, crossDomains) { 172 /** 173 * jQuery < 1.6.3 bug: $.inArray crushes IE6 and Chrome if second argument is 174 * `null` or `undefined`, http://bugs.jquery.com/ticket/10076, 175 * https://github.com/jquery/jquery/commit/a839af034db2bd934e4d4fa6758a3fed8de74174 176 * 177 * @todo: Remove/Refactor in D8 178 */ 179 if (!crossDomains) { 180 return false; 181 } 182 else { 183 return $.inArray(hostname, crossDomains) > -1 ? true : false; 184 } 185}; 186 187/** 188 * Check whether this is a download URL or not. 189 * 190 * @param string url 191 * The web url to check. 192 * 193 * @return boolean 194 */ 195Drupal.googleanalytics.isDownload = function (url) { 196 var isDownload = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i"); 197 return isDownload.test(url); 198}; 199 200/** 201 * Check whether this is an absolute internal URL or not. 202 * 203 * @param string url 204 * The web url to check. 205 * 206 * @return boolean 207 */ 208Drupal.googleanalytics.isInternal = function (url) { 209 var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i"); 210 return isInternal.test(url); 211}; 212 213/** 214 * Check whether this is a special URL or not. 215 * 216 * URL types: 217 * - gotwo.module /go/* links. 218 * 219 * @param string url 220 * The web url to check. 221 * 222 * @return boolean 223 */ 224Drupal.googleanalytics.isInternalSpecial = function (url) { 225 var isInternalSpecial = new RegExp("(\/go\/.*)$", "i"); 226 return isInternalSpecial.test(url); 227}; 228 229/** 230 * Extract the relative internal URL from an absolute internal URL. 231 * 232 * Examples: 233 * - http://mydomain.com/node/1 -> /node/1 234 * - http://example.com/foo/bar -> http://example.com/foo/bar 235 * 236 * @param string url 237 * The web url to check. 238 * 239 * @return string 240 * Internal website URL 241 */ 242Drupal.googleanalytics.getPageUrl = function (url) { 243 var extractInternalUrl = new RegExp("^(https?):\/\/" + window.location.host, "i"); 244 return url.replace(extractInternalUrl, ''); 245}; 246 247/** 248 * Extract the download file extension from the URL. 249 * 250 * @param string url 251 * The web url to check. 252 * 253 * @return string 254 * The file extension of the passed url. e.g. "zip", "txt" 255 */ 256Drupal.googleanalytics.getDownloadExtension = function (url) { 257 var extractDownloadextension = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i"); 258 var extension = extractDownloadextension.exec(url); 259 return (extension === null) ? '' : extension[1]; 260}; 261 262})(jQuery); 263;
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.