PageSourceSearch

https://thisissalient.com/wp-content/themes/salient/js/elements/nectar-blog.js?ver=12.1.2

js thisissalient.com collected 2026-10-02 18:40:30 UTC 18,099 bytes, 591 lines download raw bytes

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

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.