1/* 2 * MAIN SITE JAVASCRIPTS 3 * 4 * To be executed on every page 5 */ 6 7/*==== These Functions are outside of document.ready so they can be called as needed ==== 8=========================================================================================*/ 9 10/* 11 * TURN GET VARIABLES INTO JS VARIABLES 12 * 13 * script that takes GET variables from the url and 14 * converts them to usable js variables 15 * use with var name = $_GET('name') 16 */ 17function $_GET(param) { 18 var vars = {}; 19 window.location.href.replace( location.hash, '' ).replace( 20 /[?&]+([^=&]+)=?([^&]*)?/gi, // regexp 21 function( m, key, value ) { // callback 22 vars[key] = value !== undefined ? value : ''; 23 } 24 ); 25 26 if ( param ) { 27 return vars[param] ? vars[param] : null; 28 } 29 return vars; 30} 31 32/* 33 * JQUERY DATA BAR CHARTS 34 * 35 * script that will create bar charts through data- attributes on html. 36 * to be used when creating some bar charts 37 */ 38function DataValueCharts() { 39 jQuery('.jquery-data-chart .bar').each(function(index, element) { // run for each bar 40 41 /*===== bar adjustments*/ 42 if(jQuery(this).data('adjustment') > 0){ // check if there is a data-adjustment set 43 var value = jQuery(this).data('value')*jQuery(this).data('adjustment'); //adjusts the bars to have more height than the value shown 44 } else{ 45 var value = jQuery(this).data('value'); //if no adjustment then take value as is. 46 } 47 if(value > 100){ var value = 100;} // prevent value from going above 100%
48 /*===== end bar adjustments*/ 49 50 /*== specific bar height for some charts. Older way of adjusting bar heights. Deprecieated, use data-adjustment instead*/ 51 if(jQuery(this).closest('table').hasClass('hydaaohyswtimiir')){ 52 var value = value*2; 53 } 54 if(jQuery(this).closest('table').hasClass('tbltfw')){ 55 var value = value*1.5; 56 } 57 /*== end specific bar graph height adjustments*/ 58 jQuery(this).css('height',value+'%'); // apply the style after all calculations 59 }); 60 if(jQuery('.off')) { 61 setTimeout(function(){ 62 jQuery('.off').removeClass('off'); 63 },500); 64 /* Animate each on a delay 65 var collection = $('.off'); 66 var i = 0; 67 var fn = function(){ 68 var element = $(collection[i]); 69 console.log(i + ' (' + element.text() + ') : %o', element); 70 // Do whatever 71 if( ++i < collection.length ){ 72 element.removeClass('off'); 73 setTimeout(fn, 1000); 74 } 75 }; 76 fn();*/ 77 } 78} 79 80/* 81 * WHITE SPACE REMOVER 82 * 83 * script that removes empty nodes from html. 84 * gets rid of those weird blank spaces caused by the wyswig 85 */ 86function clean(node) 87 { 88 for(var n = 0; n < node.childNodes.length; n ++) 89 { 90 var child = node.childNodes[n]; 91 if 92 ( 93 child.nodeType === 8 94 || 95 (child.nodeType === 3 && !/\S/.test(child.nodeValue)) 96 ) 97 { 98 node.removeChild(child); 99 n --; 100 } 101 else if(child.nodeType === 1) 102 { 103 clean(child); 104 } 105 } 106} 107 108 109jQuery(document).ready(function($) { 110 111 /* 112 * STICKY NAV 113 * 114 * Show separate, smaller nav when scrolled down 115 */ 116 if($('.hero-header ').length == 0){ 117 $('.sticky-nav').prepend($('.desktop-nav').html()); 118 var showSticky = false; 119 $(window).on("scroll load", function() { 120 var $mainNav = $('.main-nav'), 121 $stickyNav = $('#sticky-nav'), 122 bottom = $mainNav.scrollTop() + $mainNav.outerHeight(), 123 pagePosition = $(this).scrollTop() 124 if (!showSticky && pagePosition > bottom) { 125 showSticky = true; 126 $stickyNav.animate({ 127 top: 0 128 }); 129 } else if (showSticky && pagePosition <= bottom) { 130 showSticky = false; 131 $stickyNav.animate({ 132 top: -145 133 }); 134 } 135 }); 136 if (typeof isClient === 'undefined' || typeof heroHeader !== "undefined") 137 $('.main-header-container').addClass('static'); 138 } else { 139 $(window).on("scroll", function() { 140 pagePosition = $(this).scrollTop() 141 if (pagePosition > 20) { 142 $('.main-header-container').addClass('solid'); 143 } else { 144 $('.main-header-container').removeClass('solid'); 145 } 146 }); 147 } 148 149 /* 150 * EXTERNAL LINKS 151 * 152 * Open external links in a new tab by default 153 */ 154 $('a').filter(function() { 155 return this.hostname && this.hostname !== location.hostname; 156 }).attr('target', '_blank'); 157 158 // Remove above behavior from header links 159 // $('nav a').removeAttr('target'); 160 161 // Open all links to PDFs in a new tab 162 $('a[href$=".pdf"]').attr('target', '_blank'); 163 164 165 /* 166 * VIEWPORT SIZE / MEDIA QUERY 167 * 168 * Assign class to body based on viewport width 169 */ 170 171 function updateMedia() { 172 173 // Grab viewport width, and assign breakpoints 174 var viewportWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0), 175 classes = { 176 'lg-size': 1200, 177 'md-size': 992, 178 'sm-size': 767, 179 'xs-size': 480, 180 'xxs-size': 320 181 }, 182 bodyClass = false; 183 184 // Loop through each size/breakpoint 185 for (var key in classes) { 186 187 if (!classes.hasOwnProperty(key)) 188 continue; 189 190 if (viewportWidth >= classes[key] && !bodyClass) { 191 192 bodyClass = true; 193 $('body').addClass(key); 194 195 } else { 196 197 $('body').removeClass(key); 198 199 } 200 201 } 202 203 } 204 205 // Call once on document ready 206 updateMedia(); 207 208 // Update after all assets loaded, and on resize 209 $(window).on("load resize", updateMedia); 210 211 212 /* 213 * INPUT PLACEHOLDERS 214 * 215 * Erase placeholder text on input focus and replace on blur if blank 216 */ 217 218 $('input, textarea').on("focus click", function() { 219 220 if ($(this).val() == $(this).data("placeholder")) 221 $(this).val(''); 222 223 }).on("blur", function() { 224 225 if ($(this).val().trim() == '') 226 $(this).val($(this).data("placeholder")); 227 228 }); 229 230 231 /* 232 * REMOVE EMPTY PARAGRAPHS 233 * 234 * Remove any p tags with no actual content 235 */ 236 237 $('.main-content p').filter(function() { 238 return ($(this).html() == '' || $(this).html() == " "); 239 }).remove(); 240 241 /* 242 * SCROLLING ELEMENT 243 * 244 * Scroll element with page (ex: social buttons) 245 */ 246 function ScrollElement() { 247 248 $('.element-scroll').stick_in_parent({ 249 parent: '.scroll-anchor', 250 offset_top: 100 251 }); 252 253 /* remove on mobile */ 254 if ($('body').hasClass('sm-size') || $('body').hasClass('xs-size') || $('body').hasClass('xxs-size')) 255 $('.element-scroll').trigger('sticky_kit:detach'); 256 257 } 258 if ($('.element-scroll').length > 0){ 259 ScrollElement(); 260 } 261 262 /* 263 * SLICKNAV and Navigation 264 * 265 * Mobile navigation menu functionality 266 */ 267 268 $('.main-menu-nav.desktop-nav').slicknav({ 269 label: '', 270 duration: 500, 271 prependTo: '.mobile-nav .navigation-row' 272 }); 273 $(".search-button a").click(function(e){ 274 $(".main-search").toggleClass('active'); 275 }); 276 //logo to mobile nav. 277 if(!$('.slicknav_nav').hasClass('complete')){ 278 var logo = $('.branding img').attr('src'); 279 $('.slicknav_menu').prepend('<img src="'+logo+'" alt="Investor Economics logo" width="150" style="padding-top:15px; float:left;"/>'); 280 $('.slicknav_nav').addClass('complete'); 281 } 282 283 /* 284 $(".search-button a").fancybox({ 285 helpers : { 286 overlay : { 287 css : { 288 'background' : '#fff' 289 }, 290 closeClick: false 291 } 292 }, 293 tpl : { 294 closeBtn : '<a title="Close" class="fancybox-item fancybox-close" href="javascript:;"> X </a>' 295 }, 296 maxWidth : 800, 297 maxHeight : 100, 298 fitToView : false, 299 width : '70%', 300 height : '70%', 301 autoSize : false, 302 closeClick : false, 303 openEffect : 'none', 304 closeEffect : 'none', 305 type : 'inline', 306 wrapCSS : 'search-box', 307 beforeShow: function(){ 308 $("body").css({'overflow':'hidden'}); 309 $('body').css('position','fixed'); 310 }, 311 afterClose: function(){ 312 $("body").css({'overflow-y':'visible'}); 313 $('body').css('position','initial'); 314 } 315 }); 316 */ 317 /* 318 $('a[href="#search"]').fancybox({ 319 helpers : { 320 overlay : { 321 css : { 322 'background' : '#fff' 323 }, 324 closeClick: false 325 } 326 }, 327 tpl : { 328 closeBtn : '<a title="Close" class="fancybox-item fancybox-close" href="javascript:;"> X </a>' 329 }, 330 maxWidth : 800, 331 maxHeight : 100, 332 fitToView : false, 333 width : '70%', 334 height : '70%', 335 autoSize : false, 336 closeClick : false, 337 openEffect : 'none', 338 closeEffect : 'none', 339 type : 'inline', 340 wrapCSS : 'search-box' 341 }); 342 */ 343 344/* 345 $('.main-header .fa-search').click(function(e) { 346 347 $('.search-bar').toggleClass('active'); 348 349 }); 350*/ 351 352 /* 353 * IMAGE / CAPTION LIGHTBOX 354 * 355 * Add + to captions of images that can be opened in a lightbox 356 */ 357 358 $('article a[href$="jpg"], article a[href$="png"], article a[href$="gif"]').each(function(){ 359 360 var artLink = $(this).attr('href'); 361 362 // Only target images with a caption 363 if ($(this).next().hasClass('wp-caption-text')) { 364 365 $caption = $(this).next(); 366 $caption.html($caption.html() + '<a href="' + artLink + '" class="fancybox" title="' + $(this).next().text().trim() + '"><i class="fa fa-plus-square-o"></i></a>'); 367 368 } 369 370 }); 371 372 373 /* 374 * FANCYBOX 375 * 376 * Lightbox functionality 377 */ 378 379 // Enable fancybox on all images in content that link to the full-size image 380 $('article a[href$=".jpg"], article a[href$=".png"], article a[href$=".gif"]').addClass('fancybox'); 381 382 $('.fancybox').fancybox({ 383 maxWidth : 1000, 384 maxHeight : 1000, 385 fitToView : true, 386 aspectRatio : true, 387 width : '70%', 388 height : '70%', 389 autoSize : true, 390 openEffect : 'elastic', 391 closeEffect : 'elastic', 392 padding : 0, 393 beforeShow : function() { 394 if(this.group.length > 1){ 395 this.title = (this.title ? '' + this.title + '' : '') + ' ' + (this.index + 1) + ' of ' + this.group.length; 396 }//length if 397 } // beforeShow 398 }).each(function() { 399 400 var $caption = $(this).next(); 401 402 if ($caption.hasClass('wp-caption-text')) { 403 404 var caption = $caption.text().trim(); 405 $(this).attr('title', caption); 406 407 } 408 409 }); 410 411 412 /* 413 * DUMMY LINKS IN HEADER 414 * 415 * Prevent # from being appended to URL 416 */ 417 418 $('.main-nav a[href="#"]').on("click", function(e) { 419 e.preventDefault(); 420 }); 421 422 423 /* 424 * SOCIAL MEDIA SHARING 425 * 426 * Add current url to social media links 427 */ 428 429 function socialMediaLinks() { 430 431 var url = window.location.href, 432 title = $('header h1').text(); 433 if (url.match(/\?./)) { 434 emailUrl = url+'&email=t'; 435 } else { 436 emailUrl = url+'?email=t'; 437 } 438 439 if ($('aside.social-media').length > 0 || $('aside.vertical-social-media').length > 0) { 440 $('.facebook-share-link').attr('href','https://www.facebook.com/sharer/sharer.php?u='+url); 441 $('.twitter-share-link').attr('href','http://twitter.com/share?text='+title+'&url='+url); 442 $('.linkedin-share-link').attr('href','https://www.linkedin.com/shareArticle?mini=true&title='+title+'&url='+url); 443 $('.email-share-link').attr('href','mailto:?subject='+title+'&body=From Investoreconomics.com: '+emailUrl); 444 $('.print-share-link').attr('href',url+'?layout=print'); 445 } 446 } 447 socialMediaLinks(); 448 449 450 /* 451 * LIGHTBOX + BUTTON 452 * 453 * Make the + button open nearest lightbox 454 */ 455 $(".lightbox-button").click(function(event){ 456 event.preventDefault(); 457 $("a.fancybox").trigger('click'); 458 }); 459 460 /* 461 * ACCORDION 462 * 463 * Creates a simple accordion 464 */ 465 function close_accordion_section() { 466 jQuery('.accordion .accordion-section-title').removeClass('active'); 467 jQuery('.accordion .accordion-section-content').slideUp(300).removeClass('open'); 468 } 469 470 jQuery('.accordion-section-title').click(function(e) { 471 // Grab current anchor value 472 var currentAttrValue = jQuery(this).attr('href'); 473 474 if(jQuery(e.target).is('.active')) { 475 close_accordion_section(); 476 }else { 477 close_accordion_section(); 478 479 // Add active class to section title 480 jQuery(this).addClass('active'); 481 // Open up the hidden content panel 482 jQuery('.accordion ' + currentAttrValue).slideDown(300).addClass('open'); 483 } 484 485 e.preventDefault(); 486 }); 487 488 489 490 /* 491 * SHOW / HIDE CHECKBOX 492 * 493 * simple show/hide based on a checkbox click. use data-target on the trigger element 494 * with the data-target being the id of the desired target. 495 */ 496 if(jQuery('.conditonal-trigger').length > 0){ 497 jQuery('.conditional-target').css('display','none'); 498 jQuery('.conditonal-trigger').each(function(index, element) { 499 var target = jQuery(this).data('target'); 500 jQuery(this).change(function(){ 501 if(jQuery(this).is(':checked')){ 502 jQuery('#'+target).css('display','block'); 503 } else { 504 jQuery('#'+target).css('display','none'); 505 } 506 }); 507 }); 508 } 509 510 511 /* 512 * REMOVE WHITESPACE NODES 513 * 514 * script that will remove blank whitespace returns from the page 515 * gets rid of those random blank spaces created by wysiwig 516 */ 517 function clean(node) { 518 for(var n = 0; n < node.childNodes.length; n ++) { 519 var child = node.childNodes[n];
520 if (child.nodeType === 8 || (child.nodeType === 3 && !/\S/.test(child.nodeValue))) { 521 node.removeChild(child); 522 n --; 523 } else if(child.nodeType === 1) { 524 clean(child); 525 } 526 } 527 }//clean(document.body); use on specific pages, just in case 528 529 /* 530 * MOST POPULAR SWITCH 531 * 532 * switches between most popular posts and email 533 * in the sidebar 534 */ 535 $('.most-popular-button').click(function(e) { 536 if(!$(this).hasClass('active')){ 537 $('.most-popular-button').toggleClass('active'); 538 $('.most-popular-list').toggleClass('active'); 539 } 540 }); 541 542 543 /* 544 * COLLAPSEABLE BLOCK 545 * 546 * small js for quick collapsebale blocks 547 * defaults to 25px height (one line height) 548 * use .collapse-header to set the collapsed header 549 * collapsed with .closed css class 550 * use load-closed class to close on load 551 */ 552 if($('.collapse-able').length > 0){ 553 $('.collapse-able').each(function(index, element) { 554 var openHeight = $(this).outerHeight(); 555 var closedHeight = $(this).children('.collapse-header').outerHeight(); 556 $(this).css('height',openHeight); 557 $(this).css('min-height',closedHeight); 558 if($(this).hasClass('load-closed')){ 559 $(this).addClass('closed'); 560 } 561 $(this).children('.collapse-header').click(function(){ 562 $(this).parent('.collapse-able').toggleClass('closed'); 563 }); 564 }); 565 } 566 567 if ($('.my-report-single').length > 0) { 568 $(window).on("load resize", function() { 569 $('.my-report-single h4').samesizr({ 570 mobile: 767 571 }).parent().samesizr({ 572 mobile: 767 573 }); 574 $('.support-team-member img').samesizr({ 575 mobile: 767 576 }); 577 }); 578 } 579 580 581 if ($('#all-access-client-container').length > 0) { 582 $('#all-access-client-container > div').samesizr(); 583 $(window).on('load resize', function() { 584 $('#all-access-client-container > div').samesizr(); 585 }); 586 } 587 588}); 589 590// Announcement on top of header 591var announcement = document.getElementById('announcement'), 592 announcementHeight = announcement.offsetHeight; 593 594announcement.style.marginBottom = '-' + announcementHeight + 'px'; 595 596if (!sessionStorage.getItem('hideAnnouncement')) { 597 announcement.classList.add('shown'); 598 document.getElementById('close-announcement').onclick = function() { 599 announcement.classList.remove('shown'); 600 sessionStorage.hideAnnouncement = true; 601 setTimeout(function() { 602 announcement.remove(); 603 }, 200); 604 }; 605} 606
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.