1/** 2 * Salient Blog script file. 3 * 4 * @package Salient 5 * @author ThemeNectar 6 */ 7/* global imagesLoaded */ 8 9(function( $ ) { 10 11 "use strict"; 12 13 function NectarMasonryBlog(el,fullWidthSections,blogLoadIn) { 14 15 this.el = el; 16 this.fullWidthSections = fullWidthSections; 17 this.blogLoadIn = blogLoadIn; 18 this.blogMediaQuerySize = ''; 19 20 if( this.el.find('img.nectar-lazy').length > 0 ) { 21 22 var that = this; 23 setTimeout(function(){ 24 that.init(); 25 that.resizeBind(); 26 },100); 27 28 } else { 29 this.init(); 30 this.resizeBind(); 31 } 32 33 } 34 35 36 NectarMasonryBlog.prototype.init = function() { 37 38 var that = this; 39 40 this.el.find('article').addClass('masonry-blog-item'); 41 42 if(this.el.parent().hasClass('masonry') && this.el.parents('.blog-fullwidth-wrap').length > 0){ 43 44 if( this.el.parents('.wpb_row').length > 0 ) { 45 this.el.parents('.wpb_row').css('z-index',100); 46 } 47 48 if(!this.el.parent().hasClass('meta_overlaid') && 49 !this.el.parent().hasClass('auto_meta_overlaid_spaced')) { 50 51 if(this.el.parent().hasClass('classic_enhanced')) { 52 this.el.parent().parents('.full-width-content').css({ 53 'padding' : '0px 0.2% 0px 2.4%' 54 }); 55 } else { 56 this.el.parent().parents('.full-width-content').css({ 57 'padding' : '0px 0.2% 0px 3.2%' 58 }); 59 } 60 61 } else { 62 this.el.parent().parents('.full-width-content').addClass('meta-overlaid'); 63 $('.container-wrap').addClass('meta_overlaid_blog'); 64 } 65 66 this.fullWidthSections(); 67 } 68 69 var $cols = 3; 70 var $element = this.el; 71 var $rtlLayout = ( $('body.rtl').length > 0 ) ? false : true; 72 73 if( this.el.find('img').length == 0) { 74 $element = $('<img />'); 75 } 76 77 imagesLoaded($element,function(instance) { 78 79 var $multiplier; 80 81 if( $('body').hasClass('mobile') || that.el.parents('.post-area').hasClass('span_9')) { 82 $cols = 2; 83 } 84 85 // Set img as BG if masonry classic enhanced 86 if(that.el.parent().hasClass('classic_enhanced')){ 87 88 that.el.find('.large_featured.has-post-thumbnail .post-featured-img, .wide_tall.has-post-thumbnail .post-featured-img').each(function(){ 89 var $src = $(this).find('img').attr('src'); 90 $(this).css('background-image','url('+$src+')'); 91 }); 92 93 that.el.find('.large_featured .nectar-flickity, .wide_tall .nectar-flickity').each(function(){ 94 95 $(this).find('.cell').each(function(){ 96 var $src = $(this).find('img').attr('src'); 97 $(this).css('background-image','url('+$src+')'); 98 }); 99 100 }); 101 } 102 103 $cols = that.blogColumnNumbCalcs(); 104 that.blogHeightCalcs($cols); 105 106 if(that.el.parents('.post-area.meta_overlaid').length > 0) { 107 that.el.isotope({ 108 itemSelector: 'article', 109 transitionDuration: '0s', 110 layoutMode: 'packery', 111 isOriginLeft: $rtlLayout, 112 packery: { 113 gutter: 0 114 } 115 }).isotope( 'layout' ); 116 117 118 } else { 119 if(that.el.parent().hasClass('classic_enhanced')) { 120 if(that.el.parents('.span_9.masonry').length == 0) { 121 $multiplier = (window.innerWidth >= 1600) ? .015 : .02; 122 } else { 123 $multiplier = .04; 124 } 125 } 126 else { 127 $multiplier = (that.el.parents('.span_9.masonry').length == 0) ? .03: .055; 128 if(that.el.parents('.blog-fullwidth-wrap').length > 0) { 129 $multiplier = .02; 130 } 131 } 132 133 that.el.isotope({ 134 itemSelector: 'article', 135 transitionDuration: '0s', 136 layoutMode: 'packery', 137 isOriginLeft: $rtlLayout, 138 packery: { 139 gutter: that.el.parents('.post-area').width()*$multiplier 140 } 141 }).isotope( 'layout' ); 142 } 143 144 that.blogLoadIn(that.el); 145 that.flickityBlogInit(); 146 147 $(window).trigger('resize'); 148 149 150 });
151 152 153 // Set z-index / animation order only once 154 setTimeout(that.blogMasonryZindex.bind(that),700); 155 156 }; 157 158 159 NectarMasonryBlog.prototype.flickityBlogInit = function() { 160 161 if($('.nectar-flickity.masonry.not-initialized').length == 0 || !$().flickity ) { 162 return false; 163 } 164 165 $('.nectar-flickity.masonry.not-initialized').each(function(){ 166 167 // Move pos for large_featured 168 if( $(this).parents('article').hasClass('large_featured') ) { 169 $(this).insertBefore( $(this).parents('article').find('.content-inner') ); 170 } 171 172 }); 173 174 $('.nectar-flickity.masonry.not-initialized').flickity({ 175 contain: true, 176 draggable: false, 177 lazyLoad: false, 178 imagesLoaded: true, 179 percentPosition: true, 180 prevNextButtons: true, 181 pageDots: false, 182 resize: true, 183 setGallerySize: true, 184 wrapAround: true, 185 accessibility: false 186 }); 187 188 $('.nectar-flickity.masonry').removeClass('not-initialized'); 189 190 // Add count 191 $('.nectar-flickity.masonry:not(.not-initialized)').each(function() { 192 193 if( $(this).find('.item-count').length == 0) { 194 195 $('<div class="item-count"/>').insertBefore($(this).find('.flickity-prev-next-button.next')); 196 197 $(this).find('.item-count') 198 .html('<span class="current">1</span>/<span class="total">' + $(this).find('.flickity-slider .cell').length + '</span>'); 199 200 $(this) 201 .find('.flickity-prev-next-button, .item-count') 202 .wrapAll('<div class="control-wrap" />'); 203 204 // Move pos for wide_tall 205 if($(this).parents('article').hasClass('wide_tall') && $(this).parents('.masonry.material').length == 0) { 206 $(this).find('.control-wrap').insertBefore( $(this) ); 207 } 208 } 209 210 }); 211 212 // Update count 213 $('.masonry .flickity-prev-next-button.previous, .masonry .flickity-prev-next-button.next').on('click',function(){ 214 if($(this).parents('.wide_tall').length > 0) { 215 $(this).parent() 216 .find('.item-count .current') 217 .html($(this).parents('article').find('.nectar-flickity .cell.is-selected').index()+1); 218 } 219 else { 220 $(this).parent() 221 .find('.item-count .current') 222 .html($(this).parents('.nectar-flickity').find('.cell.is-selected').index()+1); 223 } 224 }); 225 226 $('body').on('mouseover','.flickity-prev-next-button.next',function(){ 227 $(this).parent() 228 .find('.flickity-prev-next-button.previous, .item-count') 229 .addClass('next-hovered'); 230 }); 231 232 $('body').on('mouseleave','.flickity-prev-next-button.next',function(){ 233 $(this).parent() 234 .find('.flickity-prev-next-button.previous, .item-count') 235 .removeClass('next-hovered'); 236 }); 237 238 }; 239 240 NectarMasonryBlog.prototype.blogHeightCalcs = function(cols) { 241 242 var tallColHeight; 243 244 if( this.el.parent().hasClass('meta_overlaid') && 245 this.el.find('article[class*="regular"]:not(.format-link):not(.format-quote)').length > 0) { 246 247 // Widths 248 $.each(this.el,function(i,v){ 249 250 var $mult = (cols == 1) ? 1 : 2; 251 252 // Check if higher than IE9 -- bugs out with width calc 253 if($('html.no-csstransitions').length == 0) { 254 255 $(v) 256 .find('article[class*="regular"]') 257 .css('width',Math.floor($(v).width()/cols) +'px'); 258 $(v) 259 .find('article[class*="tall"]') 260 .css('width',Math.floor($(v).width()/cols*$mult) +'px'); 261 } 262 263 else { 264 $('.post-area.masonry').css('width','100%'); 265 } 266 267 268 }); 269 270 // Reset height for calcs 271 this.el.find('article[class*="regular"] img:not([data-nectar-img-src])').css('height','auto'); 272 273 tallColHeight = Math.ceil(this.el.find('article[class*="regular"]:not(".format-link"):not(".format-quote") img').first().height()); 274 var multipler = (window.innerWidth > 690) ? 2 : 1; 275 276 this.el 277 .find('article[class*="tall"] img, .article.wide img, article.regular img') 278 .removeClass('auto-height'); 279 this.el 280 .find('article[class*="tall"] img') 281 .css('height',(tallColHeight*multipler)); 282 this.el 283 .find('article[class*="regular"] img') 284 .css('height',(tallColHeight)); 285 286 // Quote/links 287 this.el.find('article.regular.format-link, article.regular.format-quote').each(function(){ 288 289 if(window.innerWidth > 690) { 290 $(this).css({ 291 'height': tallColHeight 292 }); 293 } else { 294 $(this).css({ 295 'height': 'auto' 296 }); 297 } 298 299 }); 300 301 this.el.find('article.wide_tall.format-link, article.wide_tall.format-quote, article.large_featured.format-link, article.large_featured.format-quote').each(function(){ 302 303 if(window.innerWidth > 690) { 304 $(this).css({ 305 'height': tallColHeight*multipler 306 }); 307 } else { 308 $(this).css({ 309 'height': 'auto' 310 }); 311 } 312 313 }); 314 315 316 } else { 317 this.el.find('article[class*="tall"] img, article.regular img').addClass('auto-height'); 318 319 if(this.el.parent().hasClass('meta_overlaid')) { 320 // Quote/links 321 this.el.find('article.regular.format-link, article.regular.format-quote').each(function(){ 322 323 if(window.innerWidth > 690) { 324 $(this).css({ 325 'height': $(this).width() 326 }); 327 } else { 328 $(this).css({ 329 'height': 'auto' 330 }); 331 } 332 333 }); 334 } 335 336 } 337 338 339 if( this.el.parent().hasClass('classic_enhanced') && this.el.find('article[class*="regular"]').length > 0) { 340 341 if($(window).width() > 690 ) { 342 this.classicEnhancedSizing(this.el.find('article:not(.large_featured):not(.wide_tall)')); 343 } 344 else { 345 this.classicEnhancedSizing(this.el.find('article:not(.wide_tall)')); 346 } 347 348 tallColHeight = (this.el.find('article[class*="regular"]:not(".format-link"):not(".format-quote").has-post-thumbnail').first().length > 0) ? Math.ceil(this.el.find('article[class*="regular"]:not(".format-link"):not(".format-quote").has-post-thumbnail').first().css('height','auto').height()) : 600; 349 350 if($(window).width() > 690 ) { 351 this.el.find('article.large_featured, article.regular, article[class*="wide_tall"]').css('height',(tallColHeight)); 352 } 353 else { 354 this.el.find('article.regular, article[class*="wide_tall"]').css('height',(tallColHeight)); 355 } 356 357 } 358 359 else if( this.el.parent().hasClass('classic_enhanced') && this.el.find('article[class*="regular"]').length == 0) { 360 361 tallColHeight = (this.el.find('article[class*="regular"]:not(".format-link"):not(".format-quote").has-post-thumbnail').first().length > 0) ? Math.ceil(this.el.find('article[class*="regular"]:not(".format-link"):not(".format-quote").has-post-thumbnail').first().css('height','auto').height()) : 600; 362 363 if($(window).width() > 690 ) { 364 this.el.find('article.large_featured, article.regular, article[class*="wide_tall"]').css('height',(tallColHeight)); 365 } 366 else { 367 this.el.find('article.regular, article[class*="wide_tall"]').css('height',(tallColHeight)); 368 } 369 } 370 371 // IE9 fix 372 if($('html.no-csstransitions').length > 0) { 373 $('.post-area.masonry').css('width','100%'); 374 } 375 376 377 }; 378 379 380 381 NectarMasonryBlog.prototype.classicEnhancedSizing = function(elements) { 382 383 var tallestCol = 0; 384 elements.find('.article-content-wrap').css('height','auto'); 385 elements.filter('.has-post-thumbnail').each(function(){ 386 387 ($(this).find('.article-content-wrap').outerHeight(true) > tallestCol) ? tallestCol = $(this).find('.article-content-wrap').outerHeight(true) : tallestCol = tallestCol; 388 389 });
390 391 elements.filter('.has-post-thumbnail').find('.article-content-wrap').css('height',(tallestCol)); 392 393 }; 394 395 NectarMasonryBlog.prototype.resizeBind = function() { 396 397 var that = this; 398 $(window).on( 'resize', function(){ 399 setTimeout(that.resize.bind(that),30); 400 }); 401 402 $(window).on('smartresize', function(){ 403 setTimeout(that.blogMasonryZindex.bind(that),700); 404 }); 405 406 }; 407 408 409 NectarMasonryBlog.prototype.resize = function() { 410 411 var $multiplier; 412 var $cols = this.blogColumnNumbCalcs(); 413 414 this.blogHeightCalcs($cols); 415 416 if(this.el.parents('.post-area.meta_overlaid').length > 0) { 417 418 this.el.isotope({ 419 layoutMode: 'packery', 420 packery: { 421 gutter: 0 422 } 423 }); 424 425 } else { 426 427 if(this.el.parent().hasClass('classic_enhanced')) { 428 429 if(this.el.parents('.span_9.masonry').length == 0) { 430 $multiplier = (window.innerWidth >= 1600) ? .015 : .02; 431 } else { 432 $multiplier = .04; 433 } 434 } 435 436 else { 437 438 $multiplier = (this.el.parents('.span_9.masonry').length == 0) ? .03: .055; 439 if(this.el.parents('.blog-fullwidth-wrap').length > 0) { 440 $multiplier = .02; 441 } 442 } 443 444 this.el.isotope({ 445 layoutMode: 'packery', 446 packery: { 447 gutter: this.el.parents('.post-area').width()*$multiplier 448 } 449 }); 450 } 451 452 453 }; 454 455 NectarMasonryBlog.prototype.removeDuplicates = function(inputArray) { 456 457 var i; 458 var len = inputArray.length; 459 var outputArray = []; 460 var temp = {}; 461 462 for (i = 0; i < len; i++) { 463 temp[inputArray[i]] = 0; 464 } 465 for (i in temp) { 466 outputArray.push(i); 467 } 468 return outputArray; 469 }; 470 471 NectarMasonryBlog.prototype.blogMasonryZindex = function() { 472 473 // Wscape if no browser support 474 if($('body .post-area .masonry-blog-item').length > 0 && 475 $('body .post-area .masonry-blog-item').offset().left) { 476 477 var $coords = {}, 478 $zindexRelation = {}, 479 $that = this.el; 480 481 this.el.find('.masonry-blog-item').each(function(){ 482 483 var $itemOffset = $(this).offset(); 484 $itemOffset = $itemOffset.left; 485 486 $coords[$(this).index()] = $itemOffset; 487 $(this).css('z-index',Math.abs(Math.floor($(this).offset().left/20))); 488 489 }); 490 491 var $corrdsArr = $.map($coords, function (value) { return value; }); 492 493 $corrdsArr = this.removeDuplicates($corrdsArr); 494 $corrdsArr.sort(function(a,b){ return a-b; }); 495 496 for(var i = 0; i < $corrdsArr.length; i++){ 497 $zindexRelation[$corrdsArr[i]] = i*1; 498 } 499 500 $.each($coords,function(k,v){ 501 502 var $zindex; 503 var $coordCache = v; 504 $.each($zindexRelation,function(k,v){ 505 if($coordCache == k) { 506 $zindex = v; 507 } 508 }); 509 510 $that.find('.masonry-blog-item:eq('+k+')') 511 .css('z-index',$zindex) 512 .attr('data-delay-amount',$zindex); 513 514 }); 515 516 } 517 518 }; 519 520 521 522 NectarMasonryBlog.prototype.blogColumnNumbCalcs = function(){ 523 524 var $cols = 3; 525 526 if($('body').hasClass('mobile') && window.innerWidth < 990 || 527 this.el.parents('.post-area').hasClass('span_9') && this.el.parents('.post-area.meta_overlaid').length == 0) { 528 529 $cols = 2; 530 } 531 532 else if( this.el.parents('.post-area').hasClass('full-width-content') || 533 this.el.parents('.post-area').parent().hasClass('full-width-content') && $('#boxed').length == 0 || 534 this.el.parents('.post-area.meta_overlaid').length > 0 ){ 535 536 if(window.innerWidth >= 1600){ 537 this.blogMediaQuerySize = (this.el.parents('.post-area.meta_overlaid').length > 0) ? 'four' :'five'; 538 } else if(window.innerWidth < 1600 && window.innerWidth >= 1300){ 539 this.blogMediaQuerySize = 'four'; 540 } else if(window.innerWidth < 1300 && window.innerWidth >= 990){ 541 this.blogMediaQuerySize = (this.el.parents('.post-area.meta_overlaid').length > 0) ? 'four' :'three'; 542 } else if(window.innerWidth < 990 && window.innerWidth >= 470){ 543 this.blogMediaQuerySize = 'two'; 544 } else if(window.innerWidth < 470){ 545 this.blogMediaQuerySize = (this.el.parents('.post-area.meta_overlaid').length > 0) ? 'two' :'one'; 546 } 547 548 549 //boxed 550 if($('#boxed').length > 0) { 551 if(window.innerWidth > 1300){ 552 this.blogMediaQuerySize = 'four'; 553 } else if(window.innerWidth < 1300 && window.innerWidth > 990){ 554 this.blogMediaQuerySize = (this.el.parents('.post-area.meta_overlaid').length > 0) ? 'four' :'three'; 555 } else if(window.innerWidth < 990){ 556 this.blogMediaQuerySize = (this.el.parents('.post-area.meta_overlaid').length > 0) ? 'two' :'one'; 557 } 558 559 } 560 561 562 switch (this.blogMediaQuerySize) { 563 case 'five': 564 $cols = 5; 565 break; 566 567 case 'four': 568 $cols = 4; 569 break; 570 571 case 'three': 572 $cols = 3; 573 break; 574 575 case 'two': 576 $cols = 2; 577 break; 578 579 case 'one': 580 $cols = 1; 581 break; 582 } 583 584 585 } else { 586 587 $cols = 3; 588 } 589 590 return $cols; 591 592 }; 593 594 window.NectarMasonryBlog = NectarMasonryBlog; 595 596}( jQuery ));
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.