1/** 2 * UpSolution Element: Grid 3 */ 4;( function( $, undefined ) { 5 "use strict"; 6 7 var _document = document, 8 _undefined = undefined, 9 _window = window; 10 11 $us.WGrid = function( container, options ) { 12 this.init( container, options ); 13 }; 14 15 $us.WGrid.prototype = { 16 init: function( container, options ) { 17 18 // Elements 19 this.$container = $( container ); 20 this.$filters = $( '.g-filters-item', this.$container ); // Built-in filters 21 this.$list = $( '.w-grid-list', this.$container ); 22 this.$loadmore = $( '.g-loadmore', this.$container ); 23 this.$pagination = $( '> .pagination', this.$container ); 24 this.$preloader = $( '.w-grid-preloader', this.$container ); 25 this.$style = $( '> style:first', this.$container ); 26 27 // Variables 28 this.loading = false; 29 this.changeUpdateState = false; 30 this.gridFilter = null; 31 32 this.curFilterTaxonomy = ''; 33 this.paginationType = this.$pagination.length 34 ? 'regular' 35 : ( this.$loadmore.length ? 'ajax' : 'none' ); 36 this.filterTaxonomyName = this.$list.data( 'filter_taxonomy_name' ) 37 ? this.$list.data( 'filter_taxonomy_name' ) 38 : 'category'; 39 40 // Prevent double init. 41 if ( this.$container.data( 'gridInit' ) == 1 ) { 42 return; 43 } 44 this.$container.data( 'gridInit', 1 ); 45 46 var $jsonContainer = $( '.w-grid-json', this.$container ); 47 if ( $jsonContainer.length && $jsonContainer.is( '[onclick]' ) ) { 48 this.ajaxData = $jsonContainer[ 0 ].onclick() || {}; 49 // Delete data everywhere except for the preview of the USBuilder, the data may be needed again to restore the elements. 50 if ( ! $us.usbPreview() ) $jsonContainer.remove(); 51 // In case JSON data container isn't present. 52 } else { 53 this.ajaxData = {}; 54 this.ajaxUrl = ''; 55 } 56 57 this.carouselSettings = this.ajaxData.carousel_settings; 58 this.breakpoints = this.ajaxData.carousel_breakpoints || {}; 59 60 if ( this.$list.hasClass( 'owl-carousel' ) ) { 61 this.carouselOptions = { 62 autoHeight: this.carouselSettings.autoHeight, 63 autoplay: this.carouselSettings.autoplay, 64 autoplayHoverPause: true, 65 autoplayTimeout: this.carouselSettings.timeout, 66 center: this.carouselSettings.center, 67 dots: this.carouselSettings.dots, 68 items: parseInt( this.carouselSettings.items ), 69 loop: this.carouselSettings.loop, 70 mouseDrag: ! $.isMobile && ! $us.usbPreview(), 71 nav: this.carouselSettings.nav, 72 navElement: 'button', 73 navText: ['', ''], 74 responsive: {}, 75 rewind: ! this.carouselSettings.loop, 76 rtl: $( '.l-body' ).hasClass( 'rtl' ), 77 slideBy: this.carouselSettings.slideby, 78 slideTransition: this.carouselSettings.transition, 79 smartSpeed: this.carouselSettings.speed 80 }; 81 82 if ( this.carouselSettings.smooth_play == 1 ) { 83 this.carouselOptions.slideTransition = 'linear'; 84 this.carouselOptions.autoplaySpeed = this.carouselSettings.timeout; 85 this.carouselOptions.smartSpeed = this.carouselSettings.timeout; 86 this.carouselOptions.slideBy = 1; 87 } 88 89 if ( this.carouselSettings.carousel_fade ) { 90 // https://owlcarousel2.github.io/OwlCarousel2/demos/animate.html 91 $.extend( this.carouselOptions, { 92 animateOut: 'fadeOut', 93 animateIn: 'fadeIn', 94 } ); 95 } 96 97 // Writing responsive params in a loop to prevent json conversion bugs 98 $.each( this.breakpoints, function( breakpointWidth, breakpointArgs ) { 99 if ( breakpointArgs !== _undefined && breakpointArgs.items !== _undefined ) { 100 this.carouselOptions.responsive[ breakpointWidth ] = breakpointArgs; 101 // Making sure items value is an integer 102 this.carouselOptions.responsive[ breakpointWidth ][ 'items' ] = parseInt( breakpointArgs.items ); 103 } 104 }.bind( this ) ); 105 106 // Re-init containers with show more links or init tabs after carousel init. 107 this.$list 108 .on( 'initialized.owl.carousel', function( e ) { 109 var $list = this.$list, 110 $toggleLinks = $( '[data-content-height]', e.currentTarget ); 111 // Refresh for Toggle Links 112 $toggleLinks.each( function( _, item ) { 113 var $item = $( item ), 114 collapsibleContent = $item.data( 'usCollapsibleContent' ); 115 // Initialization for items that are cloned 116 if ( collapsibleContent === _undefined ) { 117 $item.usCollapsibleContent(); 118 collapsibleContent = $item.data( 'usCollapsibleContent' ); 119 } 120 if ( collapsibleContent instanceof $us.collapsibleContent ) { 121 collapsibleContent.initHeightCheck(); 122 $ush.timeout( function() { 123 $list.trigger( 'refresh.owl.carousel' ); 124 }, 1 ); 125 } 126 } ); 127 // Refresh for active tabs 128 if ( $.isMobile && $list.closest( '.w-tabs-section.active' ).length ) { 129 $ush.timeout( function() { 130 $list.trigger( 'refresh.owl.carousel' ); 131 }, 50 ); 132 } 133 // Update auto height when content changes 134 if ( this.carouselSettings.autoHeight ) { 135 $toggleLinks.on( 'toggleContent', function() { 136 $list.trigger( 'refresh.owl.carousel' ); 137 } ); 138 } 139 }.bind( this ) ) 140 // Disabling mouse Drag if there is a toggle link. 141 .on( 'mousedown.owl.core', function() { 142 var $target = $( this ); 143 if ( $( '[data-content-height]', $target ).length && ! jQuery.isMobile ) { 144 var owlCarousel = $target.data( 'owl.carousel' ); 145 owlCarousel.$stage.off( 'mousedown.owl.core' ); 146 } 147 } ); 148 149 // https://owlcarousel2.github.io/OwlCarousel2/docs/started-welcome.html 150 this.$list.owlCarousel( this.carouselOptions ); 151 152 var owlCarousel = this.$list.data( 'owl.carousel' ); 153 if ( owlCarousel && this.carouselSettings.smooth_play ) { 154 this.$list.trigger( 'next.owl.carousel' ); 155 } 156 157 // Set aria labels for navigation 158 if ( 159 owlCarousel 160 && this.carouselSettings.aria_labels.prev 161 && this.carouselSettings.aria_labels.next 162 ) { 163 owlCarousel.$element.find( '.owl-prev' ).attr( 'aria-label', this.carouselSettings.aria_labels.prev ); 164 owlCarousel.$element.find( '.owl-next' ).attr( 'aria-label', this.carouselSettings.aria_labels.next ); 165 } 166 } 167 168 // Note: Product List has its own handler for displaying products in the popup. 169 if ( 170 this.$container.hasClass( 'open_items_in_popup' ) 171 && ! this.$container.hasClass( 'us_post_list' ) 172 && ! this.$container.hasClass( 'us_product_list' ) 173 && ! $ush.isUndefined( this.ajaxData ) 174 ) { 175 176 // Variables 177 this.lightboxOpened = false; 178 this.lightboxTimer = null; 179 this.originalURL = _window.location.href; 180 181 // Elements 182 this.$popup = $( '.l-popup', this.$container ); 183 this.$popupBox = $( '.l-popup-box', this.$popup ); 184 this.$popupContentPreloader = $( '.l-popup-box-content .g-preloader', this.$popup ); 185 this.$popupContentFrame = $( '.l-popup-box-content-frame', this.$popup ); 186 this.$popupNextArrow = $( '.l-popup-arrow.to_next', this.$popup ); 187 this.$popupPrevArrow = $( '.l-popup-arrow.to_prev', this.$popup ); 188 189 $us.$body.append( this.$popup ); 190 191 // Initializes the lightbox anchors 192 this.initLightboxAnchors();
193 194 // Events 195 this.$popup 196 .on( 'click', '.l-popup-closer', this.hideLightbox.bind( this ) ) 197 .on( 'click', '.l-popup-box', this.hideLightbox.bind( this ) ) 198 .on( 'click', '.l-popup-box-content', function( e ) { 199 e.stopPropagation(); 200 } ); 201 202 $us.$window.on( 'resize', function() { 203 if ( this.lightboxOpened && $us.$window.width() < $us.canvasOptions.disableEffectsWidth ) { 204 this.hideLightbox(); 205 } 206 }.bind( this ) ); 207 } 208 209 if ( this.$list.hasClass( 'owl-carousel' ) ) { 210 return; 211 } 212 213 if ( this.paginationType != 'none' || this.$filters.length ) { 214 if ( this.ajaxData == _undefined ) { 215 return; 216 } 217 218 this.templateVars = this.ajaxData.template_vars || {}; 219 if ( this.filterTaxonomyName ) { 220 this.initialFilterTaxonomy = this.$list.data( 'filter_default_taxonomies' ) 221 ? this.$list.data( 'filter_default_taxonomies' ).toString().split( ',' ) 222 : ''; 223 this.curFilterTaxonomy = this.initialFilterTaxonomy; 224 } 225 226 this.curPage = this.ajaxData.current_page || 1; 227 this.infiniteScroll = this.ajaxData.infinite_scroll || 0; 228 } 229 230 if ( this.$container.hasClass( 'with_isotope' ) ) { 231 this.$list.imagesLoaded( function() { 232 var smallestItemSelector, 233 isotopeOptions = { 234 itemSelector: '.w-grid-item', 235 layoutMode: ( this.$container.hasClass( 'isotope_fit_rows' ) ) ? 'fitRows' : 'masonry', 236 isOriginLeft: ! $( '.l-body' ).hasClass( 'rtl' ), 237 transitionDuration: 0 238 }; 239 240 if ( this.$list.find( '.size_1x1' ).length ) { 241 smallestItemSelector = '.size_1x1'; 242 } else if ( this.$list.find( '.size_1x2' ).length ) { 243 smallestItemSelector = '.size_1x2'; 244 } else if ( this.$list.find( '.size_2x1' ).length ) { 245 smallestItemSelector = '.size_2x1'; 246 } else if ( this.$list.find( '.size_2x2' ).length ) { 247 smallestItemSelector = '.size_2x2'; 248 } 249 if ( smallestItemSelector ) { 250 smallestItemSelector = smallestItemSelector || '.w-grid-item'; 251 isotopeOptions.masonry = { columnWidth: smallestItemSelector }; 252 } 253 254 // Launching CSS animation locally after building elements in isotope. 255 this.$list.on( 'layoutComplete', function() { 256 if ( _window.USAnimate ) { 257 $( '.w-grid-item.off_autostart', this.$list ) 258 .removeClass( 'off_autostart' ); 259 new USAnimate( this.$list ); 260 } 261 // Trigger scroll event to check the positions for $us.waypoints. 262 $us.$window.trigger( 'scroll.waypoints' ); 263 }.bind( this ) ); 264 265 this.$list.isotope( isotopeOptions ); 266 267 if ( this.paginationType == 'ajax' ) { 268 this.initAjaxPagination(); 269 } 270 $us.$canvas.on( 'contentChange', function() { 271 this.$list.imagesLoaded( function() { 272 this.$list.isotope( 'layout' ); 273 }.bind( this ) ); 274 }.bind( this ) ); 275 276 }.bind( this ) ); 277 278 } else if ( this.paginationType == 'ajax' ) { 279 this.initAjaxPagination(); 280 } 281 282 this.$filters.each( function( index, filter ) { 283 var $filter = $( filter ), 284 taxonomy = $filter.data( 'taxonomy' ); 285 $filter.on( 'click', function() { 286 if ( taxonomy != this.curFilterTaxonomy ) { 287 if ( this.loading ) { 288 return; 289 } 290 this.setState( 1, taxonomy ); 291 this.$filters.removeClass( 'active' ); 292 $filter.addClass( 'active' ); 293 } 294 }.bind( this ) ) 295 }.bind( this ) ); 296 297 // This is necessary for interaction from the Grid Filter or Grid Order. 298 if ( this.$container.closest( '.l-main' ).length ) { 299 $us.$body 300 .on( 'us_grid.updateState', this._events.updateState.bind( this ) ) 301 .on( 'us_grid.updateOrderBy', this._events.updateOrderBy.bind( this ) ); 302 } 303 304 // Add events 305 this.$list 306 .on( 'click', '[ref=magnificPopup]', this._events.initMagnificPopup.bind( this ) ); 307 }, 308 /** 309 * Event handlers 310 */ 311 _events: { 312 /** 313 * Update Grid State. 314 * 315 * @param {Event} e 316 * @param {string} queryString Query string containing Grid Filter parameters 317 * @param {number} page 318 * @param {object} gridFilter 319 */ 320 updateState: function( e, queryString, page, gridFilter ) { 321 var $container = this.$container; 322 if ( 323 ! $container.is( '[data-filterable="true"]' ) 324 || ! $container.hasClass( 'used_by_grid_filter' ) 325 || ( 326 ! $container.is( ':visible' ) 327 && ! $container.hasClass( 'hidden' ) 328 ) 329 ) { 330 return; 331 } 332 333 page = page || 1; 334 this.changeUpdateState = true; 335 this.gridFilter = gridFilter; 336 337 // Is load grid content 338 if ( this.ajaxData === _undefined ) { 339 this.ajaxData = {}; 340 } 341 342 if ( ! this.hasOwnProperty( 'templateVars' ) ) { 343 this.templateVars = this.ajaxData.template_vars || { 344 query_args: {} 345 }; 346 } 347 this.templateVars.us_grid_filter_query_string = queryString; 348 if ( this.templateVars.query_args !== false ) { 349 this.templateVars.query_args.paged = page; 350 } 351 352 // Related parameters for getting data, number of records for taxonomy, price range for WooCommerce, 353 // etc. 354 this.templateVars.filters_args = gridFilter.filtersArgs || {}; 355 this.setState( page ); 356 357 // Reset pagination 358 if ( this.paginationType === 'regular' && /page(=|\/)/.test( location.href ) ) { 359 var url = location.href.replace( /(page(=|\/))(\d+)(\/?)/, '$1' + page + '$2' ); 360 if ( history.replaceState ) { 361 history.replaceState( _document.title, _document.title, url ); 362 } 363 } 364 }, 365 /** 366 * Update Grid orderby. 367 * 368 * @param {Event} e 369 * @param string orderby String for order by params. 370 * @param {number} page 371 * @param {object} gridOrder 372 */ 373 updateOrderBy: function( e, orderby, page, gridOrder ) { 374 if ( 375 ! this.$container.is( '[data-filterable="true"]' ) 376 || ! this.$container.hasClass( 'used_by_grid_order' ) 377 ) { 378 return; 379 } 380 381 page = page || 1; 382 this.changeUpdateState = true; 383 if ( ! this.hasOwnProperty( 'templateVars' ) ) { 384 this.templateVars = this.ajaxData.template_vars || { 385 query_args: {} 386 }; 387 } 388 if ( this.templateVars.query_args !== false ) { 389 this.templateVars.query_args.paged = page; 390 } 391 this.templateVars.grid_orderby = orderby; 392 this.setState( page ); 393 }, 394 /** 395 * Initializing MagnificPopup for AJAX loaded items. 396 * 397 * @param {Event} e 398 */ 399 initMagnificPopup: function( e ) { 400 e.stopPropagation(); 401 e.preventDefault(); 402 var $target = $( e.currentTarget ); 403 if ( $target.data( 'magnificPopup' ) === _undefined ) { 404 $target.magnificPopup( { 405 type: 'image', 406 mainClass: 'mfp-fade' 407 } ); 408 $target.trigger( 'click' ); 409 } 410 } 411 }, 412 413 /** 414 * Initializes the lightbox anchors 415 */ 416 initLightboxAnchors: function() { 417 var self = this; 418 $( '.w-grid-item-anchor:not(.lightbox_init)', self.$list ).on( 'click', function( e ) { 419 var $item = $( e.target ).closest( '.w-grid-item' ), 420 url = $( '.w-grid-item-anchor', $item ).attr( 'href' ); 421 if ( ! $item.hasClass( 'custom-link' ) ) { 422 if ( $us.$window.width() >= $us.canvasOptions.disableEffectsWidth ) { 423 e.stopPropagation(); 424 e.preventDefault(); 425 self.openLightboxItem( url, $item ); 426 $item.addClass( 'lightbox_init' ); 427 } 428 } 429 } ); 430 }, 431 432 // Pagination and Filters functions. 433 initAjaxPagination: function() { 434 this.$loadmore.on( 'click', function() { 435 if ( this.curPage < this.ajaxData.max_num_pages ) { 436 this.setState( this.curPage + 1 ); 437 } 438 }.bind( this ) ); 439 440 if ( this.infiniteScroll ) {
441 $us.waypoints.add( this.$loadmore, /* offset */'-70%', function() { 442 if ( ! this.loading ) { 443 this.$loadmore.click(); 444 } 445 }.bind( this ) ); 446 } 447 }, 448 setState: function( page, taxonomy ) { 449 if ( this.loading && ! this.changeUpdateState ) { 450 return; 451 } 452 453 if ( 454 page !== 1 455 && this.paginationType == 'ajax' 456 && this.none !== _undefined 457 && this.none == true 458 ) { 459 return; 460 } 461 462 this.none = false; 463 this.loading = true; 464 465 // Hide element by default 466 this.$container 467 .next( '.w-grid-none' ) 468 .addClass( 'hidden' ); 469 470 // Create params for built-in filter 471 if ( this.$filters.length && ! this.changeUpdateState ) { 472 taxonomy = taxonomy || this.curFilterTaxonomy; 473 if ( taxonomy == '*' ) { 474 taxonomy = this.initialFilterTaxonomy; 475 } 476 477 if ( taxonomy != '' ) { 478 var newTaxArgs = { 479 'taxonomy': this.filterTaxonomyName, 480 'field': 'slug', 481 'terms': taxonomy 482 }, 483 taxQueryFound = false; 484 if ( this.templateVars.query_args.tax_query == _undefined ) { 485 this.templateVars.query_args.tax_query = []; 486 } else { 487 $.each( this.templateVars.query_args.tax_query, function( index, taxArgs ) { 488 if ( taxArgs != null && taxArgs.taxonomy == this.filterTaxonomyName ) { 489 this.templateVars.query_args.tax_query[ index ] = newTaxArgs; 490 taxQueryFound = true; 491 return false; 492 } 493 }.bind( this ) ); 494 } 495 if ( ! taxQueryFound ) { 496 this.templateVars.query_args.tax_query.push( newTaxArgs ); 497 } 498 } else if ( this.templateVars.query_args.tax_query != _undefined ) { 499 $.each( this.templateVars.query_args.tax_query, function( index, taxArgs ) { 500 if ( taxArgs != null && taxArgs.taxonomy == this.filterTaxonomyName ) { 501 this.templateVars.query_args.tax_query[ index ] = null; 502 return false; 503 } 504 }.bind( this ) ); 505 } 506 } 507 508 if ( this.templateVars.query_args !== false ) { 509 this.templateVars.query_args.paged = page; 510 } 511 512 if ( this.paginationType == 'ajax' ) { 513 if ( page == 1 ) { 514 this.$loadmore.addClass( 'done' ); 515 } else { 516 this.$loadmore.addClass( 'loading' ); 517 } 518 if ( ! this.infiniteScroll ) { 519 this.prevScrollTop = $us.$window.scrollTop(); 520 } 521 } 522 523 if ( this.paginationType != 'ajax' || page == 1 ) { 524 this.$preloader.addClass( 'active' ); 525 if ( this.$list.data( 'isotope' ) ) { 526 this.$list.isotope( 'remove', this.$container.find( '.w-grid-item' ) ); 527 this.$list.isotope( 'layout' ); 528 } else { 529 this.$container.find( '.w-grid-item' ).remove(); 530 } 531 } 532 533 this.ajaxData.template_vars = JSON.stringify( this.templateVars ); 534 535 var isotope = this.$list.data( 'isotope' ); 536 // Clear isotope elements on first page load 537 if ( isotope && page == 1 ) { 538 this.$list.html( '' ); 539 isotope.remove( isotope.items ); 540 isotope.reloadItems(); 541 } 542 543 // Abort prev request 544 if ( this.xhr !== _undefined ) { 545 this.xhr.abort(); 546 } 547 548 this.xhr = $.ajax( { 549 type: 'post', 550 url: $us.ajaxUrl, 551 data: this.ajaxData, 552 cache: false, 553 beforeSend: function() { 554 // Display the grid before submitting the request 555 this.$container 556 .removeClass( 'hidden' ); 557 }.bind( this ), 558 success: function( html ) { 559 var $result = $( html ), 560 // Note: Get the `first()` list since there may be several of them due to 561 // the output of grids in `w-grid-none` 562 $container = $( '.w-grid-list', $result ).first(), 563 $pagination = $( '.pagination > *', $result ), 564 $items = $container.children(), 565 smallestItemSelector; 566 567 // Hide the grid if there is no result if action 'Hide this Grid' is enabled 568 this.$container 569 .toggleClass( 'hidden', ! $items.length ); 570 571 $container.imagesLoaded( function() { 572 this.beforeAppendItems( $items ); 573 //isotope.options.hiddenStyle.transform = ''; 574 $items.appendTo( this.$list ); 575 $container.html( '' ); 576 var $sliders = $items.find( '.w-slider' ); 577 578 if ( isotope ) { 579 isotope.insert( $items ); 580 isotope.reloadItems();
581 } 582 583 if ( $sliders.length ) { 584 $sliders.each( function( index, slider ) { 585 $( slider ).wSlider().find( '.royalSlider' ).data( 'royalSlider' ).ev.on( 'rsAfterInit', function() { 586 if ( isotope ) { 587 this.$list.isotope( 'layout' ); 588 } 589 } ); 590 }.bind( this ) ); 591 592 } 593 594 if ( isotope ) { 595 if ( this.$list.find( '.size_1x1' ).length ) { 596 smallestItemSelector = '.size_1x1'; 597 } else if ( this.$list.find( '.size_1x2' ).length ) { 598 smallestItemSelector = '.size_1x2'; 599 } else if ( this.$list.find( '.size_2x1' ).length ) { 600 smallestItemSelector = '.size_2x1'; 601 } else if ( this.$list.find( '.size_2x2' ).length ) { 602 smallestItemSelector = '.size_2x2'; 603 } 604 if ( isotope.options.masonry ) { 605 isotope.options.masonry.columnWidth = smallestItemSelector || '.w-grid-item'; 606 } 607 this.$list.isotope( 'layout' ); 608 this.$list.trigger( 'layoutComplete' ); 609 } 610 611 // Check any tabs in loaded content 612 var $tabs = $( '.w-tabs', $items ); 613 if ( $tabs.length > 0 ) { 614 $tabs.wTabs(); // if post has tabs - init them 615 } 616 617 if ( this.paginationType == 'ajax' ) { 618 619 // Check any videos in loaded content 620 var $video = $( '.w-video', $items ); 621 if ( $video.length > 0 ) { 622 $video.wVideo(); // if post has videos - init them 623 } 624 625 if ( page == 1 ) { 626 var $jsonContainer = $result.find( '.w-grid-json' ); 627 if ( $jsonContainer.length ) { 628 var ajaxData = $jsonContainer[ 0 ].onclick() || {}; 629 this.ajaxData.max_num_pages = ajaxData.max_num_pages || this.ajaxData.max_num_pages; 630 } else { 631 this.ajaxData.max_num_pages = 1; 632 } 633 } 634 635 if ( this.templateVars.query_args.paged >= this.ajaxData.max_num_pages || ! $items.length ) { 636 this.$loadmore.addClass( 'done' ); 637 } else { 638 this.$loadmore 639 .removeClass( 'done' ) 640 .removeClass( 'loading' ); 641 } 642 643 if ( this.infiniteScroll ) {
644 $us.waypoints.add( this.$loadmore, /* offset */'-70%', function() { 645 if ( ! this.loading ) { 646 // check none 647 this.$loadmore.click(); 648 } 649 }.bind( this ) ); 650 651 // If the scroll value has changed, then scroll to the starting position, 652 // as in some browsers this is not true. After loading the data, the scroll is not 653 // calculated correctly. 654 } else if ( Math.round( this.prevScrollTop ) != Math.round( $us.$window.scrollTop() ) ) { 655 $us.$window.scrollTop( this.prevScrollTop ); 656 } 657 658 } else if ( this.paginationType === 'regular' && this.changeUpdateState ) { 659 // Pagination Link Correction 660 $( 'a[href]', $pagination ).each( function( _, item ) { 661 var $item = $( item ), 662 pathname = location.pathname.replace( /((\/page.*)?)\/$/, '' ); 663 $item.attr( 'href', pathname + $item.attr( 'href' ) ); 664 } ); 665 this.$pagination.html( $pagination ); 666 } 667 668 // Initialize all new anchors for lightbox 669 if ( this.$container.hasClass( 'open_items_in_popup' ) ) { 670 this.initLightboxAnchors(); 671 } 672 673 // The display a message in the absence of data. 674 var $result_none = $result.next( '.w-grid-none' ); 675 if ( this.changeUpdateState && $result_none.length ) { 676 var $none = this.$container.next( '.w-grid-none' ); 677 if ( $none.length ) { 678 $none.removeClass( 'hidden' ); 679 } else { 680 this.$container.after( $result_none ); 681 } 682 // If the result contains a grid that can be Reusable Block, then we will initialize 683 var $nextGrid = $( '.w-grid:first', this.$container.next( '.w-grid-none' ) ); 684 if ( $nextGrid.length ) { 685 $nextGrid.wGrid(); 686 } 687 this.none = true; 688 } 689 690 // Send the result to the filter grid. 691 if ( this.changeUpdateState && this.gridFilter ) { 692 var $jsonData = $result.filter( '.w-grid-filter-json-data:first' ); 693 if ( $jsonData.length ) { 694 this.gridFilter 695 .trigger( 'us_grid_filter.update-items-amount', $jsonData[ 0 ].onclick() || {} ); 696 } 697 $jsonData.remove(); 698 } 699 700 // Add custom styles to Grid. 701 var customStyles = $( 'style#grid-post-content-css', $result ).html() || ''; 702 if ( customStyles ) { 703 if ( ! this.$style.length ) { 704 this.$style = $( '<style></style>' ); 705 this.$container.append( this.$style ); 706 } 707 this.$style.text( this.$style.text() + customStyles ); 708 } 709
710 // Resize canvas to avoid Parallax calculation issues. 711 $us.$canvas.resize(); 712 this.$preloader.removeClass( 'active' ); 713 714 // Init load animation 715 if ( _window.USAnimate && this.$container.hasClass( 'with_css_animation' ) ) { 716 new USAnimate( this.$container ); 717 } 718 719 }.bind( this ) ); 720 721 // Scroll to top of grid 722 this._scrollToGrid(); 723 724 this.loading = false; 725 726 // Trigger custom event on success, might be used by 3rd party devs 727 this.$container.trigger( 'USGridItemsLoaded' ); 728 729 }.bind( this ), 730 error: function() { 731 this.$loadmore.removeClass( 'loading' ); 732 }.bind( this ) 733 } ); 734 735 this.curPage = page; 736 this.curFilterTaxonomy = taxonomy; 737 }, 738 // Scroll to top of grid 739 _scrollToGrid: function() { 740 var self = this; 741 // Check, if it's not load more and orderby 742 if ( self.curPage !== 1 ) { 743 return; 744 } 745 var gridPos = $ush.parseInt( this.$container.offset().top ), 746 scrollTop = $us.$window.scrollTop(); 747 if ( 748 scrollTop >= gridPos 749 || gridPos >= ( scrollTop + _window.innerHeight ) 750 ) { 751 $us.$htmlBody 752 .stop( true, false ) 753 .animate( { scrollTop: ( gridPos - $us.header.getCurrentHeight() ) }, 500 ); 754 } 755 }, 756 // Lightbox Functions. 757 _hasScrollbar: function() { 758 return _document.documentElement.scrollHeight > _document.documentElement.clientHeight; 759 }, 760 _getScrollbarSize: function() { 761 if ( $us.scrollbarSize === _undefined ) { 762 var scrollDiv = _document.createElement( 'div' ); 763 scrollDiv.style.cssText = 'width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;'; 764 _document.body.appendChild( scrollDiv ); 765 $us.scrollbarSize = scrollDiv.offsetWidth - scrollDiv.clientWidth; 766 _document.body.removeChild( scrollDiv ); 767 } 768 return $us.scrollbarSize; 769 }, 770 openLightboxItem: function( itemUrl, $item ) { 771 this.showLightbox(); 772 773 var prevIndex, 774 nextIndex, 775 currentIndex = 0, 776 items = $( '.w-grid-item:visible:not(.custom-link)', this.$container ).toArray(); 777 for ( var i in items ) { 778 if ( $item.is( items[ i ] ) ) { 779 currentIndex = parseInt( i ); 780 break; 781 } 782 } 783 // Get prev/next index 784 if ( currentIndex > 0 ) { 785 prevIndex = currentIndex - 1; 786 } 787 if ( currentIndex < items.length ) { 788 nextIndex = currentIndex + 1; 789 } 790 791 var $prevItem = $( $.isNumeric( prevIndex ) ? items[ prevIndex ] : '' ), 792 $nextItem = $( $.isNumeric( nextIndex ) ? items[ nextIndex ] : '' ); 793 794 if ( $nextItem.length > 0 ) { 795 this.$popupNextArrow.removeClass( 'hidden' ); 796 this.$popupNextArrow.attr( 'title', $nextItem.find( '.w-grid-item-title' ).text() ); 797 this.$popupNextArrow.off( 'click' ).click( function( e ) { 798 var $nextItemAnchor = $nextItem.find( '.w-grid-item-anchor' ), 799 nextItemUrl = $nextItemAnchor.attr( 'href' ); 800 e.stopPropagation(); 801 e.preventDefault(); 802 803 this.openLightboxItem( nextItemUrl, $nextItem ); 804 }.bind( this ) ); 805 } else { 806 this.$popupNextArrow.attr( 'title', '' ); 807 this.$popupNextArrow.addClass( 'hidden' ); 808 } 809 810 if ( $prevItem.length > 0 ) { 811 this.$popupPrevArrow.removeClass( 'hidden' ); 812 this.$popupPrevArrow.attr( 'title', $prevItem.find( '.w-grid-item-title' ).text() ); 813 this.$popupPrevArrow.off( 'click' ).on( 'click', function( e ) { 814 var $prevItemAnchor = $prevItem.find( '.w-grid-item-anchor' ), 815 prevItemUrl = $prevItemAnchor.attr( 'href' ); 816 e.stopPropagation(); 817 e.preventDefault(); 818 819 this.openLightboxItem( prevItemUrl, $prevItem ); 820 }.bind( this ) ); 821 } else { 822 this.$popupPrevArrow.attr( 'title', '' ); 823 this.$popupPrevArrow.addClass( 'hidden' ); 824 } 825 826 if ( itemUrl.indexOf( '?' ) !== - 1 ) { 827 this.$popupContentFrame.attr( 'src', itemUrl + '&us_iframe=1' ); 828 } else { 829 this.$popupContentFrame.attr( 'src', itemUrl + '?us_iframe=1' ); 830 } 831 832 // Replace window location with item's URL 833 if ( history.replaceState ) { 834 history.replaceState( null, null, itemUrl ); 835 } 836 this.$popupContentFrame.off( 'load' ).on( 'load', function() { 837 this.lightboxContentLoaded(); 838 }.bind( this ) ); 839 840 }, 841 lightboxContentLoaded: function() { 842 this.$popupContentPreloader.css( 'display', 'none' ); 843 this.$popupContentFrame 844 .contents() 845 .find( 'body' ) 846 .off( 'keyup.usCloseLightbox' ) 847 .on( 'keyup.usCloseLightbox', function( e ) { 848 if ( $ush.toLowerCase( e.key ) === 'escape' ) { 849 this.hideLightbox(); 850 } 851 }.bind( this ) ); 852 }, 853 showLightbox: function() { 854 clearTimeout( this.lightboxTimer ); 855 this.$popup.addClass( 'active' ); 856 this.lightboxOpened = true; 857 858 this.$popupContentPreloader.css( 'display', 'block' ); 859 $us.$html.addClass( 'usoverlay_fixed' ); 860 861 if ( ! $.isMobile ) { 862 // Storing the value for the whole popup visibility session 863 this.windowHasScrollbar = this._hasScrollbar(); 864 if ( this.windowHasScrollbar && this._getScrollbarSize() ) { 865 $us.$html.css( 'margin-right', this._getScrollbarSize() ); 866 } 867 } 868 this.lightboxTimer = setTimeout( function() { 869 this.afterShowLightbox(); 870 }.bind( this ), 25 ); 871 }, 872 afterShowLightbox: function() { 873 clearTimeout( this.lightboxTimer ); 874 875 this.$container.on( 'keyup', function( e ) { 876 if ( this.$container.hasClass( 'open_items_in_popup' ) ) { 877 if ( $ush.toLowerCase( e.key ) === 'escape' ) { 878 this.hideLightbox(); 879 } 880 } 881 }.bind( this ) ); 882 883 this.$popupBox.addClass( 'show' ); 884 $us.$canvas.trigger( 'contentChange' ); 885 $us.$window.trigger( 'resize' ); 886 }, 887 hideLightbox: function() { 888 clearTimeout( this.lightboxTimer ); 889 this.lightboxOpened = false; 890 this.$popupBox.removeClass( 'show' ); 891 892 // Replace window location back to original URL 893 if ( history.replaceState ) { 894 history.replaceState( null, null, this.originalURL ); 895 } 896 897 this.lightboxTimer = setTimeout( function() { 898 this.afterHideLightbox(); 899 }.bind( this ), 500 ); 900 }, 901 afterHideLightbox: function() { 902 this.$container.off( 'keyup' ); 903 clearTimeout( this.lightboxTimer ); 904 this.$popup.removeClass( 'active' ); 905 906 this.$popupContentFrame.attr( 'src', 'about:blank' ); 907 $us.$html.removeClass( 'usoverlay_fixed' ); 908 if ( ! $.isMobile ) { 909 if ( this.windowHasScrollbar ) { 910 $us.$html.css( 'margin-right', '' ); 911 } 912 } 913 }, 914 /** 915 * Overloadable function for themes. 916 * 917 * @param $items 918 */ 919 beforeAppendItems: function( $items ) { 920 // Init `Show More` for grid items loaded by AJAX 921 if ( $( '[data-content-height]', $items ).length ) { 922 var handle = $ush.timeout( function() { 923 $( '[data-content-height]', $items ).usCollapsibleContent(); 924 $ush.clearTimeout( handle ); 925 }, 1 ); 926 } 927 } 928 929 }; 930 931 $.fn.wGrid = function( options ) { 932 return this.each( function() { 933 $( this ).data( 'wGrid', new $us.WGrid( this, options ) ); 934 } ); 935 }; 936 937 $( function() { 938 $( '.w-grid' ).wGrid(); 939 } ); 940 941 $( '.w-grid-list' ).each( function() { 942 var $list = $( this ); 943 if ( ! $list.find( '[ref=magnificPopupGrid]' ).length ) { 944 return; 945 } 946 var delegateStr = 'a[ref=magnificPopupGrid]:visible', 947 popupOptions; 948 if ( $list.hasClass( 'owl-carousel' ) ) { 949 delegateStr = '.owl-item:not(.cloned) a[ref=magnificPopupGrid]'; 950 } 951 popupOptions = { 952 type: 'image', 953 delegate: delegateStr, 954 gallery: { 955 enabled: true, 956 navigateByImgClick: true, 957 preload: [0, 1], 958 tPrev: $us.langOptions.magnificPopup.tPrev, // Alt text on left arrow 959 tNext: $us.langOptions.magnificPopup.tNext, // Alt text on right arrow 960 tCounter: $us.langOptions.magnificPopup.tCounter // Markup for "1 of 7" counter 961 }, 962 image: { 963 titleSrc: 'aria-label' 964 }, 965 removalDelay: 300, 966 mainClass: 'mfp-fade', 967 fixedContentPos: true, 968 callbacks: { 969 beforeOpen: function() { 970 var owlCarousel = $list.data( 'owl.carousel' ); 971 if ( owlCarousel && owlCarousel.settings.autoplay ) { 972 $list.trigger( 'stop.owl.autoplay' ); 973 } 974 }, 975 beforeClose: function() { 976 var owlCarousel = $list.data( 'owl.carousel' ); 977 if ( owlCarousel && owlCarousel.settings.autoplay ) { 978 $list.trigger( 'play.owl.autoplay' ); 979 } 980 } 981 } 982 }; 983 $list.magnificPopup( popupOptions ); 984 if ( $list.hasClass( 'owl-carousel' ) ) { 985 $list.on( 'initialized.owl.carousel', function( initEvent ) { 986 var $currentList = $( initEvent.currentTarget ), 987 items = {}; 988 $( '.owl-item:not(.cloned)', $currentList ).each( function( _, item ) { 989 var $item = $( item ), 990 id = $item.find( '[data-id]' ).data( 'id' ); 991 if ( ! items.hasOwnProperty( id ) ) { 992 items[ id ] = $item; 993 } 994 } ); 995 $currentList.on( 'click', '.owl-item.cloned', function( e ) { 996 e.preventDefault(); 997 e.stopPropagation(); 998 var id = $( '[data-id]', e.currentTarget ).data( 'id' ); 999 if ( items.hasOwnProperty( id ) ) { 1000 $( 'a[ref=magnificPopupGrid]', items[ id ] ) 1001 .trigger( 'click' ); 1002 } 1003 } ); 1004 } ); 1005 } 1006 } ); 1007 1008} )( 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.