1/* 2* Based on the work of 3* Copyright (C) 2009 Joel Sutherland 4* Licenced under the MIT license 5* http://www.newmediacampaigns.com/page/jcaption-a-jquery-plugin-for-simple-image-captions 6*/ 7Drupal.behaviors.jcaption = { 8 attach: function(context, settings) { 9 (function($) { 10 11 var captionSelectors = Drupal.settings.jcaption.jcaption_selectors; 12 13 $.fn.jcaption = function(settings) { 14 settings = $.extend({ 15 wrapperElement: 'span', 16 wrapperClass: 'caption', 17 captionElement: 'p', 18 imageAttr: Drupal.settings.jcaption.jcaption_alt_title, 19 requireText: Drupal.settings.jcaption.jcaption_requireText, 20 copyStyle: Drupal.settings.jcaption.jcaption_copyStyle, 21 removeStyle: Drupal.settings.jcaption.jcaption_removeStyle, 22 removeClass: Drupal.settings.jcaption.jcaption_removeClass, 23 removeAlign: Drupal.settings.jcaption.jcaption_removeAlign, 24 copyAlignmentToClass: Drupal.settings.jcaption.jcaption_copyAlignmentToClass, 25 copyFloatToClass: Drupal.settings.jcaption.jcaption_copyFloatToClass, 26 copyClassToClass: Drupal.settings.jcaption.jcaption_copyClassToClass, 27 autoWidth: Drupal.settings.jcaption.jcaption_autoWidth, 28 keepLink: Drupal.settings.jcaption.jcaption_keepLink, 29 styleMarkup: Drupal.settings.jcaption.jcaption_styleMarkup, 30 animate: Drupal.settings.jcaption.jcaption_animate, 31 show: {opacity: 'show'}, 32 showDuration: Drupal.settings.jcaption.jcaption_showDuration, 33 hide: {opacity: 'hide'}, 34 hideDuration: Drupal.settings.jcaption.jcaption_hideDuration 35 }, settings); 36 37 return $(this).each(function(){ 38 //Only add the caption after the image has been loaded. This makes sure we can know the width of the caption. 39 40 $(this).bind('load', function(){ 41 42 //Make sure the captioning isn't applied twice when the IE fix at the bottom is applied 43 if($(this).data('loaded')) return false; 44 $(this).data('loaded', true); 45 46 //Shorthand for the image we will be applying the caption to 47 if($(this).parent("a").length > 0 && !settings.keepLink) { 48 var image = $(this).parent("a"); 49 var cleanimage = $(this); 50 } 51 else { 52 var image = $(this); 53 var cleanimage = $(this); 54 } 55 56 //Only create captions if there is content for the caption 57 if(cleanimage.attr(settings.imageAttr) != undefined && (cleanimage.attr(settings.imageAttr).length > 0 || !settings.requireText)){ 58 59 //Wrap the image with the caption span 60 image.wrap("<" + settings.wrapperElement + " class='" + settings.wrapperClass + "'></" + settings.wrapperElement + ">"); 61 62 //Save Image Float 63 var imageFloat = cleanimage.css('float') 64 65 //Save Image Class 66 var imageClass = cleanimage.attr('class'); 67 if(settings.removeClass) cleanimage.removeAttr('class'); 68 69 //Save Image Style 70 var imageStyle = cleanimage.attr('style'); 71 if(settings.removeStyle) cleanimage.removeAttr('style'); 72 73 //Save Image Align 74 var imageAlign = cleanimage.attr('align'); 75 if(settings.removeAlign) cleanimage.removeAttr('align'); 76 77 //Put Caption in the Wrapper span 78 var span = image.parent().append('<' + settings.captionElement + '>' + cleanimage.attr(settings.imageAttr) + '</' + settings.captionElement + '>'); 79 80 //Add css if there is style markup for the paragraph in the settings 81 //if(settings.styleMarkup) 82 83 if(settings.styleMarkup) { 84 $('.caption p').attr('style', function() { 85 return settings.styleMarkup; 86 }); 87 } 88 89 if(settings.animate){ 90 $(this).next().hide(); 91 $(this).parent().hover( 92 function(){ 93 $(this).find('p').animate(settings.show, settings.showDuration); 94 }, 95 function(){
96 $(this).find('p').animate(settings.hide, settings.hideDuration); 97 }); 98 } 99 100 //Copy Image Style to span 101 if(settings.copyStyle) span.attr('style',imageStyle); 102 103 //If there is an alignment on the image (for example align="left") add "left" as a class on the caption. This helps deal with older Text Editors like TinyMCE 104 if(settings.copyAlignmentToClass) span.addClass(imageAlign); 105 106 //Transfers the float style from the image to the caption container 107 if(settings.copyFloatToClass) span.addClass(imageFloat); 108 109 //Transfers the class from the image to the caption container 110 if(settings.copyClassToClass) span.addClass(imageClass); 111 112 //Properly size the caption span based on the loaded image's size 113 if(settings.autoWidth) span.width(image.width()); 114 } 115 }); 116 117 // Thanks to Captify for this bit! 118 //if the image has already loaded (due to being cached), force the load function to be called 119 if (this.complete || this.naturalWidth > 0){ 120 $(this).trigger('load'); 121 } 122 }); 123 } 124 125 $(captionSelectors.join(",")).each(function(index, elem){ 126 $(elem).jcaption(); 127 }); 128 129 })(jQuery); 130 } 131}; 132 133(function ($) { 134 $(document).ready(function(){ 135 136 }); 137})(jQuery);; 138(function ($) { 139 140Drupal.googleanalytics = {}; 141 142$(document).ready(function() { 143 144 // Attach mousedown, keyup, touchstart events to document only and catch 145 // clicks on all elements. 146 $(document.body).bind("mousedown keyup touchstart", function(event) { 147 148 // Catch the closest surrounding link of a clicked element. 149 $(event.target).closest("a,area").each(function() { 150 151 // Is the clicked URL internal? 152 if (Drupal.googleanalytics.isInternal(this.href)) { 153 // Skip 'click' tracking, if custom tracking events are bound. 154 if ($(this).is('.colorbox') && (Drupal.settings.googleanalytics.trackColorbox)) { 155 // Do nothing here. The custom event will handle all tracking. 156 //console.info("Click on .colorbox item has been detected."); 157 } 158 // Is download tracking activated and the file extension configured for download tracking? 159 else if (Drupal.settings.googleanalytics.trackDownload && Drupal.googleanalytics.isDownload(this.href)) { 160 // Download link clicked. 161 gtag('event', Drupal.googleanalytics.getDownloadExtension(this.href).toUpperCase(), { 162 event_category: 'Downloads', 163 event_label: Drupal.googleanalytics.getPageUrl(this.href), 164 transport_type: 'beacon' 165 }); 166 } 167 else if (Drupal.googleanalytics.isInternalSpecial(this.href)) { 168 // Keep the internal URL for Google Analytics website overlay intact. 169 // @todo: May require tracking ID 170 var target = this; 171 $.each(Drupal.settings.googleanalytics.account, function () { 172 gtag('config', this, { 173 page_path: Drupal.googleanalytics.getPageUrl(target.href), 174 transport_type: 'beacon' 175 }); 176 }); 177 } 178 } 179 else { 180 if (Drupal.settings.googleanalytics.trackMailto && $(this).is("a[href^='mailto:'],area[href^='mailto:']")) { 181 // Mailto link clicked. 182 gtag('event', 'Click', { 183 event_category: 'Mails', 184 event_label: this.href.substring(7), 185 transport_type: 'beacon' 186 }); 187 } 188 else if (Drupal.settings.googleanalytics.trackOutbound && this.href.match(/^\w+:\/\//i)) { 189 if (Drupal.settings.googleanalytics.trackDomainMode !== 2 || (Drupal.settings.googleanalytics.trackDomainMode === 2 && !Drupal.googleanalytics.isCrossDomain(this.hostname, Drupal.settings.googleanalytics.trackCrossDomains))) { 190 // External link clicked / No top-level cross domain clicked. 191 gtag('event', 'Click', { 192 event_category: 'Outbound links', 193 event_label: this.href, 194 transport_type: 'beacon' 195 }); 196 } 197 } 198 } 199 }); 200 }); 201 202 // Track hash changes as unique pageviews, if this option has been enabled. 203 if (Drupal.settings.googleanalytics.trackUrlFragments) { 204 window.onhashchange = function() { 205 $.each(Drupal.settings.googleanalytics.account, function () { 206 gtag('config', this, { 207 page_path: location.pathname + location.search + location.hash 208 }); 209 }); 210 }; 211 } 212 213 // Colorbox: This event triggers when the transition has completed and the 214 // newly loaded content has been revealed. 215 if (Drupal.settings.googleanalytics.trackColorbox) { 216 $(document).bind("cbox_complete", function () {
217 var href = $.colorbox.element().attr("href"); 218 if (href) { 219 $.each(Drupal.settings.googleanalytics.account, function () { 220 gtag('config', this, { 221 page_path: Drupal.googleanalytics.getPageUrl(href) 222 }); 223 }); 224 } 225 }); 226 } 227 228}); 229 230/** 231 * Check whether the hostname is part of the cross domains or not. 232 * 233 * @param string hostname 234 * The hostname of the clicked URL. 235 * @param array crossDomains 236 * All cross domain hostnames as JS array. 237 * 238 * @return boolean 239 */ 240Drupal.googleanalytics.isCrossDomain = function (hostname, crossDomains) { 241 /** 242 * jQuery < 1.6.3 bug: $.inArray crushes IE6 and Chrome if second argument is 243 * `null` or `undefined`, https://bugs.jquery.com/ticket/10076, 244 * https://github.com/jquery/jquery/commit/a839af034db2bd934e4d4fa6758a3fed8de74174 245 * 246 * @todo: Remove/Refactor in D8 247 */ 248 if (!crossDomains) { 249 return false; 250 } 251 else { 252 return $.inArray(hostname, crossDomains) > -1 ? true : false; 253 } 254}; 255 256/** 257 * Check whether this is a download URL or not. 258 * 259 * @param string url 260 * The web url to check. 261 * 262 * @return boolean 263 */ 264Drupal.googleanalytics.isDownload = function (url) { 265 var isDownload = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i"); 266 return isDownload.test(url); 267}; 268 269/** 270 * Check whether this is an absolute internal URL or not. 271 * 272 * @param string url 273 * The web url to check. 274 * 275 * @return boolean 276 */ 277Drupal.googleanalytics.isInternal = function (url) { 278 var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i"); 279 return isInternal.test(url); 280}; 281 282/** 283 * Check whether this is a special URL or not. 284 * 285 * URL types: 286 * - gotwo.module /go/* links. 287 * 288 * @param string url 289 * The web url to check. 290 * 291 * @return boolean 292 */ 293Drupal.googleanalytics.isInternalSpecial = function (url) { 294 var isInternalSpecial = new RegExp("(\/go\/.*)$", "i"); 295 return isInternalSpecial.test(url); 296}; 297 298/** 299 * Extract the relative internal URL from an absolute internal URL. 300 * 301 * Examples: 302 * - https://mydomain.com/node/1 -> /node/1 303 * - https://example.com/foo/bar -> https://example.com/foo/bar 304 * 305 * @param string url 306 * The web url to check. 307 * 308 * @return string 309 * Internal website URL 310 */ 311Drupal.googleanalytics.getPageUrl = function (url) { 312 var extractInternalUrl = new RegExp("^(https?):\/\/" + window.location.host, "i"); 313 return url.replace(extractInternalUrl, ''); 314}; 315 316/** 317 * Extract the download file extension from the URL. 318 * 319 * @param string url 320 * The web url to check. 321 * 322 * @return string 323 * The file extension of the passed url. e.g. "zip", "txt" 324 */ 325Drupal.googleanalytics.getDownloadExtension = function (url) { 326 var extractDownloadextension = new RegExp("\\.(" + Drupal.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i"); 327 var extension = extractDownloadextension.exec(url); 328 return (extension === null) ? '' : extension[1]; 329}; 330 331})(jQuery); 332;
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.