PageSourceSearch

https://dacbj.com.cn/wp-content/themes/salient/js/elements/nectar-blog.js?ver=10.5.3

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

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.