announcement-test/app/assets/javascripts/bulletin/wpex.js

10015 lines
269 KiB
JavaScript
Raw Normal View History

2022-10-24 08:38:47 +00:00
/**
* Project: Total WordPress Theme
* Description: Initialize all scripts and add custom js
* Author: WPExplorer
* Theme URI: http://www.wpexplorer.com
* Author URI: http://www.wpexplorer.com
* License: Custom
* License URI: http://themeforest.net/licenses
* Version 4.7
*/
var wpex = {};
$.fn.wpexEqualHeights = function (options) {
var $items = this,
$window = $(window), $targets = null;
var $settings = $.extend({ children: '', mobileBreakPoint: '', reset: false }, options);
if (!$($settings.children).length) { return }
function setHeights(el, reset) {
var $tallest = 0; if ($settings.children) {
var $children = el.find($settings.children).not('.vc_row.vc_inner .vc_column-inner');
$children.each(function () {
var $child = $(this); if (reset) { $child.css('height', '') }
$height = $child.outerHeight(true);
if($child.children().length != 0){
$height = 0;
var childs = $child.children();
for(var i = 0;i<childs.length;i++){
$height = $height + childs.eq(i).outerHeight(true);
}
}
if ($height > $tallest) { $tallest = $height }
if(!window.wpexAnimsition.equal_height){
$child.css("height", $height + 'px');
}
});
if(window.wpexAnimsition.equal_height){
$children.css('height', $tallest + 'px')
}
}
}
$items.each(function () {
var $this = $(this);
if ($this.is(window.wpexAnimsition.container_block)) {
setHeights($this, false)
} else {
$this.imagesLoaded(function () {
setHeights($this, false) })
}
});
$window.resize(function () {
$items.each(function () {
setHeights($(this), true)
})
})
};
( function( $ ) {
'use strict';
wpex = {
/**
* Main init function
*
* @since 2.0.0
*/
init : function() {
this.config();
this.bindEvents();
},
/**
* Define vars for caching
*
* @since 2.0.0
*/
config : function() {
this.config = {
// General
$window : $( window ),
$document : $( document ),
$head : $( 'head' ),
windowWidth : $( window ).width(),
windowHeight : $( window ).height(),
windowTop : $( window ).scrollTop(),
$body : $( 'body' ),
viewportWidth : '',
$wpAdminBar : null,
isRetina : false,
heightChanged : false,
widthChanged : false,
isRTL : false,
iLightboxSettings : {},
// VC
vcActive : false,
// Mobile
isMobile : false,
mobileMenuStyle : null,
mobileMenuToggleStyle : null,
mobileMenuBreakpoint : 960,
// Main Divs
$siteWrap : null,
$siteMain : null,
// Header
$siteHeader : null,
siteHeaderStyle : null,
siteHeaderHeight : 0,
siteHeaderTop : 0,
siteHeaderBottom : 0,
verticalHeaderActive : false,
hasHeaderOverlay : false,
hasStickyHeader : false,
stickyHeaderStyle : null,
hasStickyMobileHeader : false,
hasStickyNavbar : false,
// Logo
$siteLogo : null,
siteLogoHeight : 0,
siteLogoSrc : null,
// Nav
$siteNavWrap : null,
$siteNav : null,
$siteNavDropdowns : null,
// Local Scroll
$localScrollTargets : 'li.local-scroll a, a.local-scroll, .local-scroll-link, .local-scroll-link > a',
localScrollOffset : 0,
localScrollSpeed : 600,
localScrollEasing : 'easeInOutCubic',
localScrollSections : [],
// Topbar
hasTopBar : false,
hasStickyTopBar : false,
$stickyTopBar : null,
hasStickyTopBarMobile : false,
// Footer
hasFixedFooter : false
};
},
/**
* Bind Events
*
* @since 2.0.0
*/
bindEvents : function() {
var self = this;
/*** Run on Document Ready ***/
self.config.$document.ready(function() {
self.initUpdateConfig();
self.responsiveText();
self.superfish();
self.mobileMenu();
self.navNoClick();
self.hideEditLink();
self.menuWidgetAccordion();
self.inlineHeaderLogo(); // Header 5 logo
self.menuSearch();
self.headerCart();
self.backTopLink();
self.smoothCommentScroll();
self.tipsyTooltips();
self.customHovers();
self.toggleBar();
self.localScrollLinks();
self.customSelects();
self.wpexOwlCarousel();
self.autoLightbox();
self.iLightbox();
self.overlayHovers();
self.skillbar();
self.milestone();
self.countdown();
self.typedText();
self.equalHeights();
self.archiveMasonryGrids();
self.isotopeGrids();
self.responsiveCSS();
self.vcexFilterNav();
self.ctf7Preloader();
self.vcAccessability();
self.vcPageEditable();
self.wooGallery();
self.twentytwenty();
} );
/*** Run on Window Load ***/
self.config.$window.on( 'load', function() {
self.config.$body.addClass( 'wpex-window-loaded' );
self.windowLoadUpdateConfig();
self.megaMenusWidth();
self.megaMenusTop();
self.flushDropdownsTop();
self.fadeIn();
self.parallax();
self.cartDropdownRelocate();
self.sliderPro();
self.stickyTopBar();
self.vcTabsTogglesJS();
self.headerOverlayOffset(); // Add before sticky header ( important )
// Sticky Header
if ( self.config.hasStickyHeader ) {
self.stickyHeaderStyle = wpexLocalize.stickyHeaderStyle;
if ( 'standard' == self.stickyHeaderStyle || 'shrink' == self.stickyHeaderStyle || 'shrink_animated' == self.stickyHeaderStyle ) {
self.stickyHeader();
}
}
self.stickyHeaderMenu();
self.stickyVcexNavbar();
self.footerReveal(); // Footer Reveal => Must run before fixed footer!!!
self.fixedFooter();
self.titleBreadcrumbsFix();
// Infinite scroll
if ( $.fn.infinitescroll !== undefined && $( 'div.infinite-scroll-nav' ).length ) {
self.infiniteScrollInit();
}
// Load more
self.loadMore();
// Scroll to hash
if ( wpexLocalize.scrollToHash ) {
window.setTimeout( function() {
self.scrollToHash( self );
}, parseInt( wpexLocalize.scrollToHashTimeout ) );
}
} );
/*** Run on Window Resize ***/
self.config.$window.resize( function() {
// Reset
self.config.widthChanged = false;
self.config.heightChanged = false;
// Window width change
if ( self.config.$window.width() != self.config.windowWidth ) {
self.config.widthChanged = true;
self.widthResizeUpdateConfig();
}
// Height changes
if ( self.config.$window.height() != self.config.windowHeight ) {
self.config.windowHeight = self.config.$window.height(); // update height
self.config.heightChanged = true;
}
} );
/*** Run on Window Scroll ***/
self.config.$window.scroll( function() {
// Reset
self.config.$hasScrolled = false;
// Yes we actually scrolled
if ( self.config.$window.scrollTop() != self.config.windowTop ) {
self.config.$hasScrolled = true;
self.config.windowTop = self.config.$window.scrollTop();
self.localScrollHighlight();
}
} );
/*** Run on Orientation Change ***/
self.config.$window.on( 'orientationchange', function() {
self.widthResizeUpdateConfig();
self.isotopeGrids();
self.vcexFilterNav();
self.archiveMasonryGrids();
} );
},
/**
* Updates config on doc ready
*
* @since 3.0.0
*/
initUpdateConfig: function() {
var self = this;
self.config.$body.addClass( 'wpex-docready' );
// Check if VC is enabled
self.config.vcActive = this.config.$body.hasClass( 'wpb-js-composer' );
// Get Viewport width
self.config.viewportWidth = self.viewportWidth();
// Check if retina
self.config.isRetina = self.retinaCheck();
if ( self.config.isRetina ) {
self.config.$body.addClass( 'wpex-is-retina' );
}
// Mobile check & add mobile class to the header
if ( self.mobileCheck() ) {
self.config.isMobile = true;
self.config.$body.addClass( 'wpex-is-mobile-device' );
}
// Define Wp admin bar
var $wpAdminBar = $( '#wpadminbar' );
if ( $wpAdminBar.length ) {
self.config.$wpAdminBar = $wpAdminBar;
}
// Define wrap
var $siteWrap = $( '#wrap' );
if ( $siteWrap ) {
self.config.$siteWrap = $siteWrap;
}
// Define main
var $siteMain = $( '#main' );
if ( $siteMain ) {
self.config.$siteMain = $siteMain;
}
// Define header
var $siteHeader = $( '#site-header' );
if ( $siteHeader.length ) {
self.config.siteHeaderStyle = wpexLocalize.siteHeaderStyle;
self.config.$siteHeader = $( '#site-header' );
}
// Define logo
var $siteLogo = $( '#site-logo img.logo-img' );
if ( $siteLogo.length ) {
self.config.$siteLogo = $siteLogo;
self.config.siteLogoSrc = self.config.$siteLogo.attr( 'src' );
}
// Menu Stuff
var $siteNavWrap = $( '#site-navigation-wrap' );
if ( $siteNavWrap.length ) {
// Define menu
self.config.$siteNavWrap = $siteNavWrap;
var $siteNav = $( '#site-navigation', $siteNavWrap );
if ( $siteNav.length ) {
self.config.$siteNav = $siteNav;
}
// Check if sticky menu is enabled
if ( wpexLocalize.hasStickyNavbar ) {
self.config.hasStickyNavbar = true;
}
// Store dropdowns
var $siteNavDropdowns = $( '.dropdown-menu > .menu-item-has-children > ul', $siteNavWrap );
if ( $siteNavWrap.length ) {
self.config.$siteNavDropdowns = $siteNavDropdowns;
}
}
// Mobile menu settings
if ( wpexLocalize.hasMobileMenu ) {
self.config.mobileMenuStyle = wpexLocalize.mobileMenuStyle;
self.config.mobileMenuToggleStyle = wpexLocalize.mobileMenuToggleStyle;
self.config.mobileMenuBreakpoint = wpexLocalize.mobileMenuBreakpoint;
}
// Check if fixed footer is enabled
if ( self.config.$body.hasClass( 'wpex-has-fixed-footer' ) ) {
self.config.hasFixedFooter = true;
}
// Footer reveal
self.config.$footerReveal = $( '.footer-reveal-visible' );
if ( self.config.$footerReveal.length && self.config.$siteWrap && self.config.$siteMain ) {
self.config.$hasFooterReveal = true;
}
// Header overlay
if ( self.config.$siteHeader && self.config.$body.hasClass( 'has-overlay-header' ) ) {
self.config.hasHeaderOverlay = true;
}
// Top bar enabled
var $topBarWrap = $( '#top-bar-wrap' );
if ( $topBarWrap.length ) {
self.config.hasTopBar = true;
if ( $topBarWrap.hasClass( 'wpex-top-bar-sticky' ) ) {
self.config.$stickyTopBar = $topBarWrap;
if ( self.config.$stickyTopBar.length ) {
self.config.hasStickyTopBar = true;
self.config.hasStickyTopBarMobile = wpexLocalize.hasStickyTopBarMobile;
}
}
}
// Sticky Header => Mobile Check (must check first)
self.config.hasStickyMobileHeader = wpexLocalize.hasStickyMobileHeader;
// Check if sticky header is enabled
if ( self.config.$siteHeader && wpexLocalize.hasStickyHeader ) {
self.config.hasStickyHeader = true;
}
// Vertical header
if ( this.config.$body.hasClass( 'wpex-has-vertical-header' ) ) {
self.config.verticalHeaderActive = true;
}
// Local scroll speed
if ( wpexLocalize.localScrollSpeed ) {
self.config.localScrollSpeed = parseInt( wpexLocalize.localScrollSpeed );
}
// Local scroll easing
if ( wpexLocalize.localScrollEasing ) {
self.config.localScrollEasing = wpexLocalize.localScrollEasing;
if ( 'false' == self.config.localScrollEasing ) {
self.config.localScrollEasing = 'swing';
}
}
// Get local scrolling sections
self.config.localScrollSections = self.localScrollSections();
},
/**
* Updates config on window load
*
* @since 3.0.0
*/
windowLoadUpdateConfig: function() {
// Header bottom position
if ( this.config.$siteHeader ) {
var siteHeaderTop = this.config.$siteHeader.offset().top;
this.config.windowHeight = this.config.$window.height();
this.config.siteHeaderHeight = this.config.$siteHeader.outerHeight();
this.config.siteHeaderBottom = siteHeaderTop + this.config.siteHeaderHeight;
this.config.siteHeaderTop = siteHeaderTop;
if ( this.config.$siteLogo ) {
this.config.siteLogoHeight = this.config.$siteLogo.height();
}
}
// Set localScrollOffset after site is loaded to make sure it includes dynamic items
this.config.localScrollOffset = this.parseLocalScrollOffset( 'init' );
},
/**
* Updates config whenever the window is resized
*
* @since 3.0.0
*/
widthResizeUpdateConfig: function() {
// Update main configs
this.config.windowHeight = this.config.$window.height();
this.config.windowWidth = this.config.$window.width();
this.config.windowTop = this.config.$window.scrollTop();
this.config.viewportWidth = this.viewportWidth();
// Update header height
if ( this.config.$siteHeader ) {
this.config.siteHeaderHeight = this.config.$siteHeader.outerHeight();
}
// Get logo height
if ( this.config.$siteLogo ) {
this.config.siteLogoHeight = this.config.$siteLogo.height();
}
// Vertical Header
if ( this.config.windowWidth < 960 ) {
this.config.verticalHeaderActive = false;
} else if ( this.config.$body.hasClass( 'wpex-has-vertical-header' ) ) {
this.config.verticalHeaderActive = true;
}
// Local scroll offset => update last
this.config.localScrollOffset = this.parseLocalScrollOffset( 'resize' );
// Re-run functions
this.megaMenusWidth();
this.inlineHeaderLogo();
this.cartDropdownRelocate();
this.overlayHovers();
this.responsiveText();
},
/**
* Retina Check
*
* @since 3.4.0
*/
retinaCheck: function() {
var mediaQuery = '(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)';
if ( window.devicePixelRatio > 1 ) {
return true;
}
if ( window.matchMedia && window.matchMedia( mediaQuery ).matches ) {
return true;
}
return false;
},
/**
* Mobile Check
*
* @since 2.1.0
*/
mobileCheck: function() {
if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent ) ) {
return true;
}
},
/**
* Viewport width
*
* @since 3.4.0
*/
viewportWidth: function() {
var e = window, a = 'inner';
if ( ! ( 'innerWidth' in window ) ) {
a = 'client';
e = document.documentElement || document.body;
}
return e[ a+'Width' ];
},
/**
* Superfish menus
*
* @since 2.0.0
*/
superfish: function() {
if ( ! this.config.$siteNav || undefined === $.fn.superfish ) {
return;
}
$( 'ul.sf-menu', this.config.$siteNav ).superfish( {
delay : wpexLocalize.superfishDelay,
speed : wpexLocalize.superfishSpeed,
speedOut : wpexLocalize.superfishSpeedOut,
cssArrows : false,
disableHI : false,
animation : {
opacity : 'show'
},
animationOut : {
opacity : 'hide'
}
} );
},
/**
* MegaMenus Width
*
* @since 2.0.0
*/
megaMenusWidth: function() {
if ( ! wpexLocalize.megaMenuJS
|| 'one' != this.config.siteHeaderStyle
|| ! this.config.$siteNavDropdowns
|| ! this.config.$siteNavWrap.is( ':visible' )
) {
return;
}
// Define megamenu
var $megamenu = $( '.megamenu > ul', this.config.$siteNavWrap );
// Don't do anything if there isn't any megamenu
if ( ! $megamenu.length ) {
return;
}
var $headerContainerWidth = this.config.$siteHeader.find( '.container' ).outerWidth(),
$navWrapWidth = this.config.$siteNavWrap.outerWidth(),
$siteNavigationWrapPosition = parseInt( this.config.$siteNavWrap.css( 'right' ) );
if ( 'auto' == $siteNavigationWrapPosition ) {
$siteNavigationWrapPosition = 0;
}
var $megaMenuNegativeMargin = $headerContainerWidth-$navWrapWidth-$siteNavigationWrapPosition;
$megamenu.css( {
'width' : $headerContainerWidth,
'margin-left' : -$megaMenuNegativeMargin
} );
},
/**
* MegaMenus Top Position
*
* @since 2.0.0
*/
megaMenusTop: function() {
var self = this;
if ( ! self.config.$siteNavDropdowns || 'one' != self.config.siteHeaderStyle ) {
return;
}
var $megamenu = $( '.megamenu > ul', self.config.$siteNavWrap );
if ( ! $megamenu.length ) return; // Don't do anything if there isn't any megamenu
function setPosition() {
if ( self.config.$siteNavWrap.is( ':visible' ) ) {
var $headerHeight = self.config.$siteHeader.outerHeight();
var $navHeight = self.config.$siteNavWrap.outerHeight();
var $megaMenuTop = $headerHeight - $navHeight;
$megamenu.css( {
'top' : $megaMenuTop/2 + $navHeight
} );
}
}
setPosition();
// update on scroll
this.config.$window.scroll( function() {
setPosition();
} );
// Update on resize
this.config.$window.resize( function() {
setPosition();
} );
// Update on hover just incase
$( '.megamenu > a', self.config.$siteNav ).hover( function() {
setPosition();
} );
},
/**
* FlushDropdowns top positioning
*
* @since 2.0.0
*/
flushDropdownsTop: function() {
var self = this;
if ( ! self.config.$siteNavDropdowns || ! self.config.$siteNavWrap.hasClass( 'wpex-flush-dropdowns' ) ) {
return;
}
// Set position
function setPosition() {
if ( self.config.$siteNavWrap.is( ':visible' ) ) {
var $headerHeight = self.config.$siteHeader.outerHeight();
var $siteNavWrapHeight = self.config.$siteNavWrap.outerHeight();
var $dropTop = $headerHeight - $siteNavWrapHeight;
self.config.$siteNavDropdowns.css( 'top', $dropTop/2 + $siteNavWrapHeight );
}
}
setPosition();
// Update on scroll
this.config.$window.scroll( function() {
setPosition();
} );
// Update on resize
this.config.$window.resize( function() {
setPosition();
} );
// Update on hover
$( '.wpex-flush-dropdowns li.menu-item-has-children > a' ).hover( function() {
setPosition();
} );
},
/**
* Mobile Menu
*
* @since 2.0.0
*/
mobileMenu: function() {
if ( 'sidr' == this.config.mobileMenuStyle && typeof wpexLocalize.sidrSource !== 'undefined' ) {
this.mobileMenuSidr();
} else if ( 'toggle' == this.config.mobileMenuStyle ) {
this.mobileMenuToggle();
} else if ( 'full_screen' == this.config.mobileMenuStyle ) {
this.mobileMenuFullScreen();
}
},
/**
* Mobile Menu
*
* @since 3.6.0
*/
mobileMenuSidr: function() {
var self = this,
$toggleBtn = $( 'a.mobile-menu-toggle, li.mobile-menu-toggle > a' );
// Add dark overlay to content
self.config.$body.append( '<div class="wpex-sidr-overlay wpex-hidden"></div>' );
var $sidrOverlay = $( '.wpex-sidr-overlay' );
// Add active class to toggle button
$toggleBtn.click( function() {
$( this ).toggleClass( 'wpex-active' );
} );
// Add sidr
$toggleBtn.sidr( {
name : 'sidr-main',
source : wpexLocalize.sidrSource,
side : wpexLocalize.sidrSide,
displace : wpexLocalize.sidrDisplace,
speed : parseInt( wpexLocalize.sidrSpeed ),
renaming : true,
bind : 'click',
// Callbacks
onOpen: function() {
// Add extra classname
$( '#sidr-main' ).addClass( 'wpex-mobile-menu' );
// Prevent body scroll
if ( wpexLocalize.sidrBodyNoScroll ) {
self.config.$body.addClass( 'wpex-noscroll' );
}
// FadeIn Overlay
$sidrOverlay.fadeIn( wpexLocalize.sidrSpeed, function() {
$sidrOverlay.addClass( 'wpex-custom-cursor' );
} );
// Close sidr when clicking on overlay
$( '.wpex-sidr-overlay' ).on( 'click', function( event ) {
$.sidr( 'close', 'sidr-main' );
return false;
} );
},
onClose: function() {
// Remove active class
$toggleBtn.removeClass( 'wpex-active' );
// Remove body noscroll class
if ( wpexLocalize.sidrBodyNoScroll ) {
self.config.$body.removeClass( 'wpex-noscroll' );
}
// FadeOut overlay
$sidrOverlay.removeClass( 'wpex-custom-cursor' ).fadeOut( wpexLocalize.sidrSpeed );
},
onCloseEnd: function() {
// Remove active dropdowns
$( '.sidr-class-menu-item-has-children.active' ).removeClass( 'active' ).find( 'ul' ).hide();
// Re-trigger stretched rows to prevent issues if browser was resized while
// sidr was open
if ( $.fn.vc_rowBehaviour !== undefined ) {
vc_rowBehaviour();
}
}
} );
// Cache main sidebar var
var $sidrMain = $( '#sidr-main' );
// Sidr dropdown toggles
var $sidrMenu = $( '.sidr-class-dropdown-menu', $sidrMain ),
$sidrDropdownTargetEl = $( '.sidr-class-menu-item-has-children > a', $sidrMenu );
// Add dropdown toggle (arrow)
$( '.sidr-class-menu-item-has-children', $sidrMenu )
.children( 'a' )
.append( '<span class="sidr-class-dropdown-toggle"></span>' );
// Add toggle click event
$sidrDropdownTargetEl.on( 'click', function( event ) {
var $parentEl = $( this ).parent( 'li' );
if ( ! $parentEl.hasClass( 'active' ) ) {
var $allParentLis = $parentEl.parents( 'li' );
$( '.sidr-class-menu-item-has-children', $sidrMenu )
.not( $allParentLis )
.removeClass( 'active' )
.children( 'ul' )
.stop( true, true )
.slideUp( 'fast' );
$parentEl.addClass( 'active' ).children( 'ul' ).stop( true, true ).slideDown( 'fast' );
} else {
$parentEl.removeClass( 'active' );
$parentEl.find( 'li' ).removeClass( 'active' ); // Remove active from sub-drops
$parentEl.find( 'ul' ).stop( true, true ).slideUp( 'fast' ); // Hide all drops
}
return false;
} );
// Loop through parent items and add to dropdown if they have a link
var $parents = $( 'li.sidr-class-menu-item-has-children > a', $sidrMenu );
$parents.each( function() {
var $this = $( this );
if ( $this && $this.attr( 'href' ) && '#' != $this.attr( 'href' ) ) {
var $parent = $this.parent( 'li' ),
el = $parent.clone();
$this.removeAttr( 'data-ls_linkto' );
$parent.removeClass( 'sidr-class-local-scroll' );
el.removeClass( 'sidr-class-menu-item-has-children sidr-class-dropdown' );
el.find( 'a' ).removeClass();
el.find( 'ul, .sidr-class-dropdown-toggle' ).remove().end().prependTo( $this.next( 'ul' ) );
}
} );
// Re-name font Icons to correct classnames
$( "[class*='sidr-class-fa']", $sidrMain ).attr( 'class',
function( i, c ) {
c = c.replace( 'sidr-class-fa', 'fa' );
c = c.replace( 'sidr-class-fa-', 'fa-' );
return c;
} );
// Close sidr when clicking toggle
$( '.sidr-class-wpex-close > a', $sidrMain ).on( 'click', function( e ) {
e.preventDefault();
$.sidr( 'close', 'sidr-main' );
} );
// Close on resize past mobile menu breakpoint
self.config.$window.resize( function() {
if ( self.config.viewportWidth >= self.config.mobileMenuBreakpoint ) {
$.sidr( 'close', 'sidr-main' );
}
} );
// Close sidr when clicking local scroll link
$( 'li.sidr-class-local-scroll > a', $sidrMain ).click( function() {
var $hash = this.hash;
if ( $.inArray( $hash, self.config.localScrollSections ) > -1 ) {
$.sidr( 'close', 'sidr-main' );
self.scrollTo( $hash );
return false;
}
} );
// Remove mobile menu alternative if on page to prevent duplicate links
if ( $( '#mobile-menu-alternative' ).length ) {
$( '#mobile-menu-alternative' ).remove();
}
},
/**
* Toggle Mobile Menu
*
* @since 3.6.0
*/
mobileMenuToggle: function() {
var self = this,
$position = wpexLocalize.mobileToggleMenuPosition,
$classes = 'mobile-toggle-nav wpex-mobile-menu wpex-clr wpex-togglep-'+ $position,
$mobileMenuContents = '',
$mobileSearch = $( '#mobile-menu-search' ),
$appendTo = self.config.$siteHeader,
$toggleBtn = $( 'a.mobile-menu-toggle, li.mobile-menu-toggle > a' );
// Insert nav in fixed_top mobile menu
if ( 'fixed_top' == self.config.mobileMenuToggleStyle ) {
$appendTo = $( '#wpex-mobile-menu-fixed-top' );
if ( $appendTo.length ) {
$appendTo.append( '<nav class="'+ $classes +'" aria-label="Mobile menu"></nav>' );
}
}
// Absolute position
else if ( 'absolute' == $position ) {
if ( 'navbar' == self.config.mobileMenuToggleStyle ) {
$appendTo = $( '#wpex-mobile-menu-navbar' );
if ( $appendTo.length ) {
$appendTo.append( '<nav class="'+ $classes +'" aria-label="Mobile menu"></nav>' );
}
} else if ( $appendTo ) {
$appendTo.append( '<nav class="'+ $classes +'" aria-label="Mobile menu"></nav>' );
}
}
// Insert afterSelf
else if ( 'afterself' == $position ) {
$appendTo = $( '#wpex-mobile-menu-navbar' );
$( '<nav class="'+ $classes +'" aria-label="Mobile menu"></nav>' ).insertAfter( $appendTo );
// Normal toggle insert (static)
} else {
$( '<nav class="'+ $classes +'" aria-label="Mobile menu"></nav>' ).insertAfter( $appendTo );
}
// Store Nav in cache
var $mobileToggleNav = $( '.mobile-toggle-nav' );
// Grab all content from menu and add into mobile-toggle-nav element
if ( $( '#mobile-menu-alternative' ).length ) {
$mobileMenuContents = $( '#mobile-menu-alternative .dropdown-menu' ).html();
$( '#mobile-menu-alternative' ).remove();
} else {
$mobileMenuContents = $( '.dropdown-menu', self.config.$siteNav ).html();
}
$mobileToggleNav.html( '<ul class="mobile-toggle-nav-ul">' + $mobileMenuContents + '</ul>' );
// Remove all styles
$( '.mobile-toggle-nav-ul, .mobile-toggle-nav-ul *' ).children().each( function() {
$( this ).removeAttr( 'style' );
} );
// Add classes where needed
$( '.mobile-toggle-nav-ul' ).addClass( 'container' );
// Loop through parent items and add to dropdown if they have a link
var parseDropParents = false;
if ( ! parseDropParents ) {
var $parents = $mobileToggleNav.find( 'li.menu-item-has-children > a' );
$parents.each( function() {
var $this = $( this );
if ( $this && $this.attr( 'href' ) && '#' != $this.attr( 'href' ) ) {
var $parent = $this.parent( 'li' ),
el = $parent.clone();
$parent.removeClass( 'local-scroll' );
$this.removeAttr( 'data-ls_linkto' );
el.removeClass( 'menu-item-has-children' );
el.find( 'ul, .wpex-open-submenu' ).remove().end().prependTo( $this.next( 'ul' ) );
}
} );
parseDropParents = true;
}
// Add toggles
var dropDownParents = $mobileToggleNav.find( '.menu-item-has-children' );
dropDownParents.children( 'a' ).append( '<span class="wpex-open-submenu" aria-haspopup="true"></span>' );
// Add toggle click event
var $dropdownTargetEl = $dropdownTargetEl = $( '.menu-item-has-children > a', $mobileToggleNav );
$dropdownTargetEl.on( 'click', function( event ) {
var $parentEl = $( this ).parent( 'li' );
if ( ! $parentEl.hasClass( 'active' ) ) {
var $allParentLis = $parentEl.parents( 'li' );
$( '.menu-item-has-children', $mobileToggleNav )
.not( $allParentLis )
.removeClass( 'active' )
.children( 'ul' )
.stop( true, true )
.slideUp( 'fast' );
$parentEl.addClass( 'active' ).children( 'ul' ).stop( true, true ).slideDown( 'fast' );
} else {
$parentEl.removeClass( 'active' );
$parentEl.find( 'li' ).removeClass( 'active' ); // Remove active from sub-drops
$parentEl.find( 'ul' ).stop( true, true ).slideUp( 'fast' ); // Hide all drops
}
return false;
} );
// On Show
function openToggle( $button ) {
if ( wpexLocalize.animateMobileToggle ) {
$mobileToggleNav.stop( true, true ).slideDown( 'fast' ).addClass( 'visible' );
} else {
$mobileToggleNav.addClass( 'visible' );
}
$button.addClass( 'wpex-active' );
}
// On Close
function closeToggle( $button ) {
if ( wpexLocalize.animateMobileToggle ) {
$mobileToggleNav.stop( true, true ).slideUp( 'fast' ).removeClass( 'visible' );
} else {
$mobileToggleNav.removeClass( 'visible' );
}
$mobileToggleNav.find( 'li.active > ul' ).stop( true, true ).slideUp( 'fast' );
$mobileToggleNav.find( '.active' ).removeClass( 'active' );
$button.removeClass( 'wpex-active' );
}
// Show/Hide
$toggleBtn.on( 'click', function( e ) {
if ( $mobileToggleNav.hasClass( 'visible' ) ) {
closeToggle( $( this ) );
} else {
openToggle( $( this ) );
}
return false;
} );
// Close on resize
self.config.$window.resize( function() {
if ( self.config.viewportWidth >= self.config.mobileMenuBreakpoint && $mobileToggleNav.hasClass( 'visible' ) ) {
closeToggle( $toggleBtn );
}
} );
// Add search to toggle menu
if ( $mobileSearch.length ) {
$mobileToggleNav.append( '<div class="mobile-toggle-nav-search container"></div>' );
$( '.mobile-toggle-nav-search' ).append( $mobileSearch );
}
},
/**
* Overlay Mobile Menu
*
* @since 3.6.0
*/
mobileMenuFullScreen: function() {
var self = this,
$style = wpexLocalize.fullScreenMobileMenuStyle ? wpexLocalize.fullScreenMobileMenuStyle : false, // prevent undefined class
$mobileSearch = $( '#mobile-menu-search' ),
$menuHTML = '';
// Insert new nav
self.config.$body.append( '<div class="full-screen-overlay-nav wpex-mobile-menu wpex-clr ' + $style + '"><span class="full-screen-overlay-nav-close">&times;</span><nav class="full-screen-overlay-nav-ul-wrapper"><ul class="full-screen-overlay-nav-ul"></ul></nav></div>' );
var $navUL = $( '.full-screen-overlay-nav-ul' );
// Grab all content from menu and add into mobile-toggle-nav element
if ( $( '#mobile-menu-alternative' ).length ) {
$menuHTML = $( '#mobile-menu-alternative .dropdown-menu' ).html();
$( '#mobile-menu-alternative' ).remove();
} else {
$menuHTML = $( '#site-navigation .dropdown-menu' ).html();
}
$navUL.html( $menuHTML );
// Cache element
var $nav = $( '.full-screen-overlay-nav' );
// Remove all styles
$( '.full-screen-overlay-nav, .full-screen-overlay-nav *' ).children().each( function() {
$( this ).removeAttr( 'style' );
} );
// Loop through parent items and add to dropdown if they have a link
var parseDropParents = false;
if ( ! parseDropParents ) {
var $parents = $nav.find( 'li.menu-item-has-children > a' );
$parents.each( function() {
var $this = $( this );
if ( $this && $this.attr( 'href' ) && '#' != $this.attr( 'href' ) ) {
var $parent = $this.parent( 'li' ),
el = $parent.clone();
$parent.removeClass( 'local-scroll' );
$this.removeAttr( 'data-ls_linkto' );
el.removeClass( 'menu-item-has-children' );
el.find( 'ul' ).remove().end().prependTo( $this.next( 'ul' ) );
}
} );
parseDropParents = true;
}
// Add toggle click event
var $dropdownTargetEl = $nav.find( 'li.menu-item-has-children > a' );
$dropdownTargetEl.on( 'click', function( event ) {
var $parentEl = $( this ).parent( 'li' );
if ( ! $parentEl.hasClass( 'wpex-active' ) ) {
var $allParentLis = $parentEl.parents( 'li' );
$nav.find( '.menu-item-has-children' )
.not( $allParentLis )
.removeClass( 'wpex-active' )
.children( 'ul' )
.stop( true, true )
.slideUp( 'fast' );
$parentEl.addClass( 'wpex-active' ).children( 'ul' ).stop( true, true ).slideDown( {
duration: 'normal',
easing: 'easeInQuad'
} );
} else {
$parentEl.removeClass( 'wpex-active' );
$parentEl.find( 'li' ).removeClass( 'wpex-active' ); // Remove active from sub-drops
$parentEl.find( 'ul' ).stop( true, true ).slideUp( 'fast' ); // Hide all drops
}
// Return false
return false;
} );
// Show
$( '.mobile-menu-toggle' ).on( 'click', function() {
$nav.addClass( 'visible' );
self.config.$body.addClass( 'wpex-noscroll' );
return false;
} );
// Hide overlay when clicking local scroll links
$( '.local-scroll > a', $nav ).click( function() {
var $hash = this.hash;
if ( $.inArray( $hash, self.config.localScrollSections ) > -1 ) {
$nav.removeClass( 'visible' );
self.config.$body.removeClass( 'wpex-noscroll' );
return false;
}
} );
// Hide when clicking close button
$( '.full-screen-overlay-nav-close' ).on( 'click', function() {
$nav.removeClass( 'visible' );
$nav.find( 'li.wpex-active > ul' ).stop( true, true ).slideUp( 'fast' );
$nav.find( '.wpex-active' ).removeClass( 'wpex-active' );
self.config.$body.removeClass( 'wpex-noscroll' );
return false;
} );
// Add search to toggle menu
if ( $mobileSearch.length ) {
$navUL.append( $mobileSearch );
$( '#mobile-menu-search' ).wrap( '<li class="wpex-search"></li>' );
}
},
/**
* Prevent clickin on links
*
* @since 2.0.0
*/
navNoClick: function() {
$( 'li.nav-no-click > a, li.sidr-class-nav-no-click > a' ).on( 'click', function() {
return false;
} );
},
/**
* Header Search
*
* @since 2.0.0
*/
menuSearch: function() {
var self = this;
var $toggleEl = '';
var $wrapEl = $( '.header-searchform-wrap' );
// Alter search placeholder & autocomplete
if ( $wrapEl.length ) {
if ( $wrapEl.data( 'placeholder' ) ) {
$wrapEl.find( 'input[type="search"]' ).attr( 'placeholder', $wrapEl.data( 'placeholder' ) );
}
if ( $wrapEl.data( 'disable-autocomplete' ) ) {
$wrapEl.find( 'input[type="search"]' ).attr( 'autocomplete', 'off' )
}
}
/**** Menu Search > Dropdown ****/
if ( 'drop_down' == wpexLocalize.menuSearchStyle ) {
$toggleEl = $( 'a.search-dropdown-toggle, a.mobile-menu-search' );
var $searchDropdownForm = $( '#searchform-dropdown' );
$toggleEl.click( function( event ) {
// Display search form
$searchDropdownForm.toggleClass( 'show' );
// Active menu item
$( this ).parent( 'li' ).toggleClass( 'active' );
// Focus
var $transitionDuration = $searchDropdownForm.css( 'transition-duration' );
$transitionDuration = $transitionDuration.replace( 's', '' ) * 1000;
if ( $transitionDuration ) {
setTimeout( function() {
$searchDropdownForm.find( 'input[type="search"]' ).focus();
}, $transitionDuration );
}
// Hide other things
$( 'div#current-shop-items-dropdown' ).removeClass( 'show' );
$( 'li.wcmenucart-toggle-dropdown' ).removeClass( 'active' );
// Return false
return false;
} );
// Close on doc click
self.config.$document.on( 'click', function( event ) {
if ( ! $( event.target ).closest( '#searchform-dropdown.show' ).length ) {
$toggleEl.parent( 'li' ).removeClass( 'active' );
$searchDropdownForm.removeClass( 'show' );
}
} );
}
/**** Menu Search > Overlay Modal ****/
else if ( 'overlay' == wpexLocalize.menuSearchStyle ) {
$toggleEl = $( 'a.search-overlay-toggle, a.mobile-menu-search, li.search-overlay-toggle > a' );
var $overlayEl = $( '#wpex-searchform-overlay' );
var $inner = $overlayEl.find( '.wpex-inner' );
$toggleEl.on( 'click', function( event ) {
$overlayEl.toggleClass( 'active' );
$overlayEl.find( 'input[type="search"]' ).val( '' );
if ( $overlayEl.hasClass( 'active' ) ) {
var $overlayElTransitionDuration = $overlayEl.css( 'transition-duration' );
$overlayElTransitionDuration = $overlayElTransitionDuration.replace( 's', '' ) * 1000;
setTimeout( function() {
$overlayEl.find( 'input[type="search"]' ).focus();
}, $overlayElTransitionDuration );
}
return false;
} );
// Close searchforms
$inner.click( function( event ) {
event.stopPropagation();
} );
$overlayEl.click( function() {
$overlayEl.removeClass( 'active' );
} );
}
/**** Menu Search > Header Replace ****/
else if ( 'header_replace' == wpexLocalize.menuSearchStyle ) {
$toggleEl = $( 'a.search-header-replace-toggle, a.mobile-menu-search' );
var $headerReplace = $( '#searchform-header-replace' );
// Show
$toggleEl.click( function( event ) {
// Display search form
$headerReplace.toggleClass( 'show' );
// Focus
var $transitionDuration = $headerReplace.css( 'transition-duration' );
$transitionDuration = $transitionDuration.replace( 's', '' ) * 1000;
if ( $transitionDuration ) {
setTimeout( function() {
$headerReplace.find( 'input[type="search"]' ).focus();
}, $transitionDuration );
}
// Return false
return false;
} );
// Close on click
$( '#searchform-header-replace-close' ).click( function() {
$headerReplace.removeClass( 'show' );
return false;
} );
// Close on doc click
self.config.$document.on( 'click', function( event ) {
if ( ! $( event.target ).closest( $( '#searchform-header-replace.show' ) ).length ) {
$headerReplace.removeClass( 'show' );
}
} );
}
},
/**
* Header Cart
*
* @since 2.0.0
*/
headerCart: function() {
if ( $( 'a.wcmenucart' ).hasClass( 'go-to-shop' ) ) {
return;
}
var $toggle = $( '.toggle-cart-widget, li.toggle-header-cart > a' );
if ( ! $toggle.length ) return;
// Drop-down
if ( 'drop_down' == wpexLocalize.wooCartStyle ) {
var $dropdown = $( 'div#current-shop-items-dropdown' );
if ( ! $dropdown.length ) return;
// Display cart dropdown
$toggle.click( function() {
$( '#searchform-dropdown' ).removeClass( 'show' );
$( 'a.search-dropdown-toggle' ).parent( 'li' ).removeClass( 'active' );
$dropdown.toggleClass( 'show' );
$( this ).toggleClass( 'active' );
return false;
} );
// Hide cart dropdown
$dropdown.click( function( event ) {
event.stopPropagation();
} );
this.config.$document.click( function() {
$dropdown.removeClass( 'show' );
$toggle.removeClass( 'active' );
} );
/* Prevent body scroll on current shop dropdown - seems buggy...
$( '#current-shop-items-dropdown' ).bind( 'mousewheel DOMMouseScroll', function ( e ) {
var e0 = e.originalEvent,
delta = e0.wheelDelta || -e0.detail;
this.scrollTop += ( delta < 0 ? 1 : -1 ) * 30;
e.preventDefault();
} );*/
}
// Modal
else if ( 'overlay' == wpexLocalize.wooCartStyle ) {
var $overlayEl = $( '#wpex-cart-overlay' );
var $inner = $overlayEl.find( '.wpex-inner' );
$toggle.on( 'click', function( event ) {
$overlayEl.toggleClass( 'active' );
return false;
} );
// Close searchforms
$inner.click( function( event ) {
event.stopPropagation();
} );
$overlayEl.click( function() {
$overlayEl.removeClass( 'active' );
} );
}
},
/**
* Automatically add padding to row to offset header
*
* @since 3.6.0
*/
headerOverlayOffset: function() {
var $offset_element = $( '.add-overlay-header-offset' );
if ( $offset_element.length ) {
var self = this;
var $height = self.config.siteHeaderHeight;
if ( ! $height ) return;
var $offset = $( '<div class="overlay-header-offset-div" style="height:'+ $height +'px"></div>' );
$offset_element.prepend( $offset );
self.config.$window.resize( function() {
$offset.css( 'height', self.config.siteHeaderHeight );
} );
}
},
/**
* Relocate the cart for specific header styles
*
* @todo remove if possible
* @since 2.0.0
*/
cartDropdownRelocate: function() {
// Validate first
if ( this.config.hasHeaderOverlay
|| ! this.config.$siteHeader
|| ! this.config.$siteHeader.hasClass( 'wpex-reposition-cart-search-drops' )
) {
return;
}
// Get last menu item
var $lastMenuItem = $( '.dropdown-menu > li:nth-last-child(1)', this.config.$siteNav );
if ( ! $lastMenuItem.length ) {
return;
}
// Define vars
var $shopDrop = $( '#current-shop-items-dropdown' );
var $lastMenuItemOffset = $lastMenuItem.position();
var $leftPosition = '';
// Position Woo dropdown
if ( $shopDrop.length ) {
if ( wpexLocalize.isRTL ) {
$leftPosition = $lastMenuItemOffset.left;
} else {
$leftPosition = $lastMenuItemOffset.left - $shopDrop.outerWidth() + $lastMenuItem.width();
}
$shopDrop.css( {
'right' : 'auto',
'left' : $leftPosition
} );
}
},
/**
* Hide post edit link
*
* @since 2.0.0
*/
hideEditLink: function() {
$( 'a.hide-post-edit', $( '#content' ) ).click( function() {
$( 'div.post-edit' ).hide();
return false;
} );
},
/**
* Custom menu widget accordion
*
* @since 4.5.4.2
*/
menuWidgetAccordion: function() {
if ( ! wpexLocalize.menuWidgetAccordion ) {
return;
}
var self = this;
// Open toggle for active page
$( '#sidebar .widget_nav_menu .current-menu-ancestor, .widget_nav_menu_accordion .widget_nav_menu .current-menu-ancestor', self.config.$siteMain ).addClass( 'active' ).children( 'ul' ).show();
// Toggle items
$( '#sidebar .widget_nav_menu, .widget_nav_menu_accordion .widget_nav_menu', self.config.$siteMain ).each( function() {
var $hasChildren = $( this ).find( '.menu-item-has-children' );
$hasChildren.each( function() {
$( this ).addClass( 'parent' );
var $links = $( this ).children( 'a' );
$links.on( 'click', function( event ) {
var $linkParent = $( this ).parent( 'li' );
var $allParents = $linkParent.parents( 'li' );
if ( ! $linkParent.hasClass( 'active' ) ) {
$hasChildren.not( $allParents ).removeClass( 'active' ).children( '.sub-menu' ).slideUp( 'fast' );
$linkParent.addClass( 'active' ).children( '.sub-menu' ).stop( true, true ).slideDown( 'fast' );
} else {
$linkParent.removeClass( 'active' ).children( '.sub-menu' ).stop( true, true ).slideUp( 'fast' );
}
return false;
} );
} );
} );
},
/**
* Header 5 - Inline Logo
*
* @since 2.0.0
*/
inlineHeaderLogo: function() {
var self = this;
// For header 5 only
if ( 'five' != self.config.siteHeaderStyle ) return;
// Define vars
var $headerLogo = $( '#site-header-inner > .header-five-logo', self.config.$siteHeader );
var $headerNav = $( '.navbar-style-five', self.config.$siteHeader );
var $navLiCount = $headerNav.children( '#site-navigation' ).children( 'ul' ).children( 'li' ).size();
var $navBeforeMiddleLi = Math.round( $navLiCount / 2 ) - parseInt( wpexLocalize.headerFiveSplitOffset );
var $centeredLogo = $( '.menu-item-logo .header-five-logo' );
// Add logo into menu
if ( this.config.viewportWidth > this.config.mobileMenuBreakpoint && $headerLogo.length && $headerNav.length ) {
$( '<li class="menu-item-logo"></li>' ).insertAfter( $headerNav.find( '#site-navigation > ul > li:nth( '+ $navBeforeMiddleLi +' )' ) );
$headerLogo.appendTo( $headerNav.find( '.menu-item-logo' ) );
}
// Remove logo from menu and add to header
if ( this.config.viewportWidth < this.config.mobileMenuBreakpoint && $centeredLogo.length ) {
$centeredLogo.prependTo( $( '#site-header-inner' ) );
$( '.menu-item-logo' ).remove();
}
// Add display class to logo (hidden by default)
$headerLogo.addClass( 'display' );
},
/**
* Back to top link
*
* @since 2.0.0
*/
backTopLink: function() {
var self = this;
var $scrollTopLink = $( 'a#site-scroll-top' );
if ( $scrollTopLink.length ) {
var $speed = wpexLocalize.scrollTopSpeed ? parseInt( wpexLocalize.scrollTopSpeed ) : 1000;
var $offset = wpexLocalize.scrollTopOffset ? parseInt( wpexLocalize.scrollTopOffset ) : 100;
self.config.$window.scroll( function() {
if ( $( this ).scrollTop() > $offset ) {
$scrollTopLink.addClass( 'show' );
} else {
$scrollTopLink.removeClass( 'show' );
}
} );
$scrollTopLink.on( 'click', function( event ) {
$( 'html, body' ).stop( true, true ).animate( {
scrollTop : 0
}, $speed, self.config.localScrollEasing );
return false;
} );
}
},
/**
* Smooth Comment Scroll
*
* @since 2.0.0
*/
smoothCommentScroll: function() {
var self = this;
$( '.single li.comment-scroll a' ).click( function( event ) {
var $target = $( '#comments' );
var $offset = $target.offset().top - self.config.localScrollOffset - 20;
self.scrollTo( $target, $offset );
return false;
} );
},
/**
* Tooltips
*
* @since 2.0.0
*/
tipsyTooltips: function() {
$( 'a.tooltip-left' ).tipsy( {
fade : true,
gravity : 'e'
} );
$( 'a.tooltip-right' ).tipsy( {
fade : true,
gravity : 'w'
} );
$( 'a.tooltip-up' ).tipsy( {
fade : true,
gravity : 's'
} );
$( 'a.tooltip-down' ).tipsy( {
fade : true,
gravity : 'n'
} );
},
/**
* Responsive Text
* Inspired by FlowType.JS
*
* @since 3.2.0
*/
responsiveText: function() {
var self = this;
var $responsiveText = $( '.wpex-responsive-txt' );
$responsiveText.each( function() {
var $this = $( this );
var $thisWidth = $this.width();
var $data = $this.data();
var $minFont = self.parseData( $data.minFontSize, 13 );
var $maxFont = self.parseData( $data.maxFontSize, 40 );
var $ratio = self.parseData( $data.responsiveTextRatio, 10 );
var $fontBase = $thisWidth / $ratio;
var $fontSize = $fontBase > $maxFont ? $maxFont : $fontBase < $minFont ? $minFont : $fontBase;
$this.css( 'font-size', $fontSize + 'px' );
} );
},
/**
* Togglebar toggle
*
* @since 2.0.0
*/
toggleBar: function() {
var self = this;
var $toggleBtn = $( 'a.toggle-bar-btn, a.togglebar-toggle, .togglebar-toggle > a' );
var $toggleBarWrap = $( '#toggle-bar-wrap' );
if ( $toggleBtn.length && $toggleBarWrap.length ) {
$toggleBtn.on( 'click', function( event ) {
var $fa = $( '.toggle-bar-btn' ).find( '.fa' );
if ( $fa.length ) {
$fa.toggleClass( $toggleBtn.data( 'icon' ) );
$fa.toggleClass( $toggleBtn.data( 'icon-hover' ) );
}
$toggleBarWrap.toggleClass( 'active-bar' );
return false;
} );
// Close on doc click
self.config.$document.on( 'click', function( event ) {
if ( ! $( event.target ).closest( '#toggle-bar-wrap.active-bar' ).length ) {
$toggleBarWrap.removeClass( 'active-bar' );
var $fa = $toggleBtn.children( '.fa' );
if ( $fa.length ) {
$fa.removeClass( $toggleBtn.data( 'icon-hover' ) ).addClass( $toggleBtn.data( 'icon' ) );
}
}
} );
}
},
/**
* Skillbar
*
* @since 2.0.0
*/
skillbar: function( $context ) {
if ( undefined === $.fn.appear ) {
return;
}
$( '.vcex-skillbar', $context ).each( function() {
var $this = $( this );
$this.appear( function() {
$this.find( '.vcex-skillbar-bar' ).animate( {
width: $( this ).attr( 'data-percent' )
}, 800 );
} );
}, {
accX : 0,
accY : 0
} );
},
/**
* Milestones
*
* @since 2.0.0
*/
milestone: function( $context ) {
if ( typeof CountUp !== 'function' || undefined === $.fn.appear ) {
return;
}
$( '.vcex-countup', $context ).each( function() {
var $this = $( this ),
data = $this.data( 'options' ),
startVal = data.startVal,
endVal = data.endVal,
decimals = data.decimals,
duration = data.duration;
var options = {
useEasing : true,
useGrouping : true,
separator : data.separator,
decimal : data.decimal,
prefix : '',
suffix : ''
};
var numAnim = new CountUp( this, startVal, endVal, decimals, duration, options );
// No need to show on appear when in context
if ( $context ) {
numAnim.start();
return;
}
$this.appear( function() {
numAnim.start();
} );
} );
},
/**
* Before/After Image (twenty twenty)
*
* @since 4.3
*/
twentytwenty: function( $context ) {
if ( undefined === $.fn.twentytwenty || undefined === $.fn.imagesLoaded ) {
return;
}
$( '.vcex-image-ba', $context ).each( function() {
var $this = $( this );
$this.imagesLoaded( function() {
$this.twentytwenty( $this.data( 'options' ) );
} );
} );
},
/**
* Countdown
*
* @since 2.0.0
*/
countdown: function( $context ) {
if ( undefined === $.fn.countdown ) {
return;
}
$( '.vcex-countdown', $context ).each( function() {
var $this = $( this ),
endDate = $this.data( 'countdown' ),
days = $this.data( 'days' ),
hours = $this.data( 'hours' ),
minutes = $this.data( 'minutes' ),
seconds = $this.data( 'seconds' ),
timezone = $this.data( 'timezone' );
if ( timezone && typeof moment.tz !== 'undefined' && $.isFunction( moment.tz ) ) {
endDate = moment.tz( endDate, timezone ).toDate();
}
if ( ! endDate ) {
return;
}
$this.countdown( endDate, function( event ) {
$this.html( event.strftime( '<div class="wpex-days"><span>%-D</span> <small>' + days + '</small></div> <div class="wpex-hours"><span>%-H</span> <small>' + hours + '</small></div class="wpex-months"> <div class="wpex-minutes"><span>%-M</span> <small>' + minutes + '</small></div> <div class="wpex-seconds"><span>%-S</span> <small>' + seconds + '</small></div>' ) );
} );
} );
},
/**
* Typed Text
*
* @since 2.0.0
*/
typedText: function( $context ) {
if ( typeof Typed !== 'function' || undefined === $.fn.appear ) {
return;
}
$( '.vcex-typed-text', $context ).each( function() {
var $this = $( this );
var $settings = $this.data( 'settings' );
$this.appear( function() {
$settings.typeSpeed = parseInt( $settings.typeSpeed );
$settings.backDelay = parseInt( $settings.backDelay );
$settings.backSpeed = parseInt( $settings.backSpeed );
$settings.startDelay = parseInt( $settings.startDelay );
$settings.strings = $this.data( 'strings' );
var typed = new Typed( this, $settings );
} );
} );
},
/**
* Advanced Parallax
*
* @since 2.0.0
*/
parallax: function( $context ) {
$( '.wpex-parallax-bg', $context ).each( function() {
var $this = $( this );
$this.scrolly2().trigger( 'scroll' );
$this.css( {
'opacity' : 1
} );
} );
},
/**
* Local Scroll Offset
*
* @since 2.0.0
*/
parseLocalScrollOffset: function( instance ) {
var self = this;
var $offset = 0;
// Return custom offset
if ( wpexLocalize.localScrollOffset ) {
return wpexLocalize.localScrollOffset;
}
// Adds extra offset via filter
if ( wpexLocalize.localScrollExtraOffset ) {
$offset = $offset + parseInt( wpexLocalize.localScrollExtraOffset );
}
// Add wp toolbar
if ( $( '#wpadminbar' ).is( ':visible' ) ) {
$offset = parseInt( $offset ) + parseInt( $( '#wpadminbar' ).outerHeight() );
}
// Fixed Mobile menu
if ( 'fixed_top' == self.config.mobileMenuToggleStyle ) {
var $mmFixed = $( '#wpex-mobile-menu-fixed-top' );
if ( $mmFixed.length && $mmFixed.is( ':visible' ) ) {
$offset = parseInt( $offset ) + parseInt( $mmFixed.outerHeight() );
}
}
// Add sticky topbar height offset
if ( self.config.hasStickyTopBar ) {
$offset = parseInt( $offset ) + parseInt( self.config.$stickyTopBar.outerHeight() );
}
// Fixed header
if ( self.config.hasStickyHeader ) {
// Return 0 for small screens if mobile fixed header is disabled
if ( ! self.config.hasStickyMobileHeader && self.config.windowWidth <= wpexLocalize.stickyHeaderBreakPoint ) {
$offset = parseInt( $offset ) + 0;
}
// Return header height
else {
// Shrink header
if ( self.config.$siteHeader.hasClass( 'shrink-sticky-header' ) ) {
if ( 'init' == instance || self.config.$siteHeader.is( ':visible' ) ) {
$offset = parseInt( $offset ) + parseInt( wpexLocalize.shrinkHeaderHeight );
}
}
// Standard header
else {
$offset = parseInt( $offset ) + parseInt( self.config.siteHeaderHeight );
}
}
}
// Fixed Nav
if ( self.config.hasStickyNavbar ) {
if ( self.config.viewportWidth >= wpexLocalize.stickyNavbarBreakPoint ) {
$offset = parseInt( $offset ) + parseInt( self.config.$siteNavWrap.outerHeight() );
}
}
// VCEX Navbar module
var $vcexNavbarSticky = $( '.vcex-navbar-sticky' );
if ( $vcexNavbarSticky.length ) {
$offset = parseInt( $offset ) + parseInt( $vcexNavbarSticky.outerHeight() );
}
// Add 1 extra decimal to prevent cross browser rounding issues (mostly firefox)
$offset = $offset ? $offset - 1 : 0;
//console.log( $offset );
// Return offset
return $offset;
},
/**
* Scroll to function
*
* @since 2.0.0
*/
scrollTo: function( hash, offset, callback ) {
// Hash is required
if ( ! hash ) {
return;
}
// Define important vars
var self = this;
var $target = null;
var $page = $( 'html, body' );
var $isLsDataLink = false;
// Check for target in data attributes
var $lsTarget = $( '[data-ls_id="'+ hash +'"]' );
if ( $lsTarget.length ) {
$target = $lsTarget;
$isLsDataLink = true;
}
// Check for straight up element with ID
else {
if ( typeof hash == 'string' ) {
$target = $( hash );
} else {
$target = hash;
}
}
// Target check
if ( $target.length ) {
// LocalScroll vars
var $lsSpeed = self.config.localScrollSpeed ? parseInt( self.config.localScrollSpeed ) : 1000,
$lsOffset = self.config.localScrollOffset,
$lsEasing = self.config.localScrollEasing;
// Sanitize offset
offset = offset ? offset : $target.offset().top - $lsOffset;
// Update hash
if ( hash && $isLsDataLink && wpexLocalize.localScrollUpdateHash ) {
window.location.hash = hash;
}
/* Remove hash on site top click
if ( '#site_top' == hash && wpexLocalize.localScrollUpdateHash && window.location.hash ) {
history.pushState( '', document.title, window.location.pathname);
}*/
// Mobile toggle Menu needs it's own code so it closes before the event fires
// to make sure we end up in the right place
var $mobileToggleNav = $( '.mobile-toggle-nav' );
if ( $mobileToggleNav.hasClass( 'visible' ) ) {
$( 'a.mobile-menu-toggle, li.mobile-menu-toggle > a' ).removeClass( 'wpex-active' );
if ( wpexLocalize.animateMobileToggle ) {
$mobileToggleNav.slideUp( 'fast', function() {
$mobileToggleNav.removeClass( 'visible' );
$page.stop( true, true ).animate( {
scrollTop: $target.offset().top - $lsOffset
}, $lsSpeed );
} );
} else {
$mobileToggleNav.hide().removeClass( 'visible' );
$page.stop( true, true ).animate( {
scrollTop: $target.offset().top - $lsOffset
}, $lsSpeed );
}
}
// Scroll to target
else {
$page.stop( true, true ).animate( {
scrollTop: offset
}, $lsSpeed, $lsEasing );
}
}
},
/**
* Scroll to Hash
*
* @since 2.0.0
*/
scrollToHash: function( self ) {
var hash = location.hash;
var $target = '';
var $offset = '';
// Hash needed
if ( ! hash ) {
return;
}
// Scroll to comments
if ( '#view_comments' == hash || '#comments_reply' == hash ) {
$target = $( '#comments' );
$offset = $target.offset().top - self.config.localScrollOffset - 20;
if ( $target.length ) {
self.scrollTo( $target, $offset );
}
return;
}
// Scroll to specific comment, fix for sticky header
if ( self.config.hasStickyHeader && hash.indexOf( 'comment-' ) != -1 ) {
$target = $( hash );
$offset = $target.offset().top - self.config.localScrollOffset - 20;
self.scrollTo( $target, $offset );
return;
}
// Scroll to hash for localscroll links
if ( hash.indexOf( 'localscroll-' ) != -1 ) {
self.scrollTo( hash.replace( 'localscroll-', '' ) );
return;
}
// Check elements with data attributes
if ( $( '[data-ls_id="'+ hash +'"]' ).length ) {
self.scrollTo( hash );
return;
}
},
/**
* Local scroll links array
*
* @since 2.0.0
*/
localScrollSections: function() {
var self = this;
// Add local-scroll class to links in menu with localscroll- prefix (if on same page)
// And add to $localScrollTargets
// And add data-ls_linkto attr
if ( self.config.$siteNav ) {
var $navLinks = $( 'a', this.config.$siteNav );
var $location = location;
var $currentPage = $location.href;
// Sanitize current page var
$currentPage = $location.hash ? $currentPage.substr( 0, $currentPage.indexOf( '#' ) ) : $currentPage;
// Loop through nav links
$navLinks.each( function() {
var $this = $( this );
var $ref = $this.attr( 'href' );
if ( $ref && $ref.indexOf( 'localscroll-' ) != -1 ) {
$this.parent( 'li' ).addClass( 'local-scroll' );
var $withoutHash = $ref.substr( 0, $ref.indexOf( '#' ) );
if ( $withoutHash == $currentPage ) {
var $hash = $ref.substring( $ref.indexOf( '#' ) + 1 );
var $parseHash = $hash.replace( 'localscroll-', '' );
$this.attr( 'data-ls_linkto', '#' + $parseHash );
}
}
} );
}
// Define main vars
var $array = [];
var $links = $( self.config.$localScrollTargets );
// Loop through links
for ( var i=0; i < $links.length; i++ ) {
// Add to array and save hash
var $link = $links[i];
var $linkDom = $( $link );
var $href = $( $link ).attr( 'href' );
var $hash = $href ? '#' + $href.replace( /^.*?(#|$)/, '' ) : null;
// Hash required
if ( $hash && '#' != $hash ) {
// Add custom data attribute to each
if ( ! $linkDom.attr( 'data-ls_linkto' ) ) {
$linkDom.attr( 'data-ls_linkto', $hash );
}
// Data attribute targets
if ( $( '[data-ls_id="'+ $hash +'"]' ).length ) {
if ( $.inArray( $hash, $array ) == -1 ) {
$array.push( $hash );
}
}
// Standard ID targets
else if ( $( $hash ).length ) {
if ( $.inArray( $hash, $array ) == -1 ) {
$array.push( $hash );
}
}
}
}
// Return array of local scroll links
return $array;
},
/**
* Local Scroll link
*
* @since 2.0.0
*/
localScrollLinks: function() {
var self = this;
// Local Scroll - Menus
$( self.config.$localScrollTargets ).on( 'click', function() {
var $this = $( this );
var $hash = $this.attr( 'data-ls_linkto' );
$hash = $hash ? $hash : this.hash; // Fallback
if ( $.inArray( $hash, self.config.localScrollSections ) > -1 ) {
$this.parent().removeClass( 'sfHover' );
self.scrollTo( $hash );
return false;
}
} );
// Local Scroll - Logo
$( 'a.wpex-scroll-top, .wpex-scroll-top a' ).on( 'click', function() {
self.scrollTo( '#site_top' );
return false;
} );
// Local Scroll - Woocommerce Reviews
$( 'a.woocommerce-review-link', $( 'body.single div.entry-summary' ) ).click( function() {
var $target = $( '.woocommerce-tabs' );
if ( $target.length ) {
$( '.reviews_tab a' ).click();
var $offset = $target.offset().top - self.config.localScrollOffset;
self.scrollTo( $target, $offset );
}
return false;
} );
},
/**
* Local Scroll Highlight on scroll
*
* @since 2.0.0
*/
localScrollHighlight: function() {
// Return if disabled
if ( ! wpexLocalize.localScrollHighlight ) {
return;
}
// Define main vars
var self = this,
localScrollSections = self.config.localScrollSections;
// Return if there aren't any local scroll items
if ( ! localScrollSections.length ) {
return;
}
// Define vars
var $windowPos = this.config.$window.scrollTop(),
$divPos,
$divHeight,
$higlight_link;
// Highlight active items
for ( var i=0; i < localScrollSections.length; i++ ) {
// Get section
var $section = localScrollSections[i];
// Data attribute targets
if ( $( '[data-ls_id="'+ $section +'"]' ).length ) {
var $targetDiv = $( '[data-ls_id="'+ $section +'"]' );
$divPos = $targetDiv.offset().top - self.config.localScrollOffset - 1;
$divHeight = $targetDiv.outerHeight();
$higlight_link = $( '[data-ls_linkto="'+ $section +'"]' );
}
// Standard element targets
else if ( $( $section ).length ) {
$divPos = $( $section ).offset().top - self.config.localScrollOffset - 1;
$divHeight = $( $section ).outerHeight();
$higlight_link = $( '[data-ls_linkto="'+ $section +'"]' );
}
// Higlight items
if ( $windowPos >= $divPos && $windowPos < ( $divPos + $divHeight ) ) {
$( '.local-scroll.menu-item' ).removeClass( 'current-menu-item' ); // prevent any sort of duplicate local scroll active links
$higlight_link.addClass( 'active' );
$higlight_link.parent( 'li' ).addClass( 'current-menu-item' );
} else {
$higlight_link.removeClass( 'active' );
$higlight_link.parent( 'li' ).removeClass( 'current-menu-item' );
}
}
/* @todo: Highlight last item if at bottom of page or last item clicked - needs major testing now.
var $docHeight = this.config.$document.height();
var windowHeight = this.config.windowHeight;
var $lastLink = localScrollSections[localScrollSections.length-1];
if ( $windowPos + windowHeight == $docHeight ) {
$( '.local-scroll.current-menu-item' ).removeClass( 'current-menu-item' );
$( "li.local-scroll a[href='" + $lastLink + "']" ).parent( 'li' ).addClass( 'current-menu-item' );
}*/
},
/**
* Equal heights function => Must run before isotope method
*
* @since 2.0.0
*/
equalHeights: function( $context ) {
if ($.fn.wpexEqualHeights !== undefined) {
var container_block = $(window.wpexAnimsition.linkElement).parents(window.wpexAnimsition.container_block);
$(container_block, $context).wpexEqualHeights({ children: window.wpexAnimsition.children_text_block });
}
},
/**
* Footer Reveal Display on Load
*
* @since 2.0.0
*/
footerReveal: function() {
var self = this;
// Return if disabled
if ( ! self.config.$hasFooterReveal ) {
return;
}
// Footer reveal
var $footerReveal = self.config.$footerReveal;
function showHide() {
// Disabled under 960
if ( self.config.viewportWidth < 960 ) {
if ( $footerReveal.hasClass( 'footer-reveal' ) ) {
$footerReveal.toggleClass( 'footer-reveal footer-reveal-visible' );
self.config.$siteWrap.css( 'margin-bottom', '' );
}
return;
}
var $hideFooter = false,
$footerRevealHeight = $footerReveal.outerHeight(),
windowHeight = self.config.windowHeight,
$heightCheck = 0;
if ( $footerReveal.hasClass( 'footer-reveal' ) ) {
$heightCheck = self.config.$siteWrap.outerHeight() + self.config.localScrollOffset;
} else {
$heightCheck = self.config.$siteWrap.outerHeight() + self.config.localScrollOffset - $footerRevealHeight;
}
// Check window height
if ( ( windowHeight > $footerRevealHeight ) && ( $heightCheck > windowHeight ) ) {
$hideFooter = true;
}
// Footer Reveal
if ( $hideFooter && $footerReveal.hasClass( 'footer-reveal-visible' ) ) {
self.config.$siteWrap.css( {
'margin-bottom': $footerRevealHeight
} );
$footerReveal.removeClass( 'footer-reveal-visible' );
$footerReveal.addClass( 'footer-reveal' );
}
// Visible Footer
if ( ! $hideFooter && $footerReveal.hasClass( 'footer-reveal' ) ) {
self.config.$siteWrap.css( 'margin-bottom', '' );
$footerReveal.removeClass( 'footer-reveal' );
$footerReveal.removeClass( 'wpex-visible' );
$footerReveal.addClass( 'footer-reveal-visible' );
}
}
function reveal() {
if ( $footerReveal.hasClass( 'footer-reveal' ) ) {
if ( self.scrolledToBottom( self.config.$siteMain ) ) {
$footerReveal.addClass( 'wpex-visible' );
} else {
$footerReveal.removeClass( 'wpex-visible' );
}
}
}
// Fire on init
showHide();
// Fire onscroll event
self.config.$window.scroll( function() {
reveal();
} );
// Fire onResize
self.config.$window.resize( function() {
if ( self.config.widthChanged || self.config.heightChanged ) {
showHide();
}
} );
},
/**
* Set min height on main container to prevent issue with extra space below footer
*
* @since 3.1.1
*/
fixedFooter: function() {
var self = this;
// Checks
if ( ! self.config.$siteMain || ! self.config.hasFixedFooter ) {
return;
}
function run() {
// Set main vars
var $mainHeight = self.config.$siteMain.outerHeight();
var $htmlHeight = $( 'html' ).height();
// Generate min Height
var $minHeight = $mainHeight + ( self.config.$window.height() - $htmlHeight );
// Add min height
self.config.$siteMain.css( 'min-height', $minHeight );
}
// Run on doc ready
run();
// Run on resize
self.config.$window.resize( function() {
if ( self.config.widthChanged || self.config.heightChanged ) {
run();
}
} );
},
/**
* If title and breadcrumbs don't both fit in the header switch breadcrumb style
*
* @since 3.5.0
*/
titleBreadcrumbsFix: function() {
var self = this;
// Return if disabled
if ( ! self.config.$body.hasClass( 'has-breadcrumbs' ) ) {
return;
}
var $pageHeader = $( '.page-header' );
var $crumbs = $( '.site-breadcrumbs.position-absolute', $pageHeader );
if ( ! $crumbs.length || ! $crumbs.hasClass( 'has-js-fix' ) ) {
return;
}
var $crumbsTrail = $( '.breadcrumb-trail', $crumbs );
if ( ! $crumbsTrail.length ) {
return;
}
var $headerInner = $( '.page-header-inner', $pageHeader );
if ( ! $headerInner.length ) {
return;
}
var $title = $( '.page-header-title > span', $headerInner );
if ( ! $title.length ) {
return;
}
function tweak_classes() {
if ( ( $title.width() + $crumbsTrail.width() + 20 ) >= $headerInner.width() ) {
if ( $crumbs.hasClass( 'position-absolute' ) ) {
$crumbs.removeClass( 'position-absolute' );
$crumbs.addClass( 'position-under-title' );
}
} else {
$crumbs.removeClass( 'position-under-title' );
$crumbs.addClass( 'position-absolute' );
}
}
// Run on init
tweak_classes();
// Run on resize
self.config.$window.resize( function() {
tweak_classes();
} );
},
/**
* Custom Selects
*
* @since 2.0.0
*/
customSelects: function( $context ) {
$( wpexLocalize.customSelects, $context ).each( function() {
var $this = $( this );
var elID = $this.attr( 'id' );
var elClass = elID ? ' wpex-' + elID : '';
if ( $this.is( ':visible' ) ) {
2022-11-01 05:19:10 +00:00
var wpex_wrap = $('<div></div>');
wpex_wrap.insertBefore($this);
wpex_wrap.append($this);
2022-10-24 08:38:47 +00:00
if ( $this.attr( 'multiple' ) ) {
2022-11-01 05:19:10 +00:00
wpex_wrap.attr('class', 'wpex-multiselect-wrap' + elClass);
2022-10-24 08:38:47 +00:00
} else {
2022-11-01 05:19:10 +00:00
wpex_wrap.attr('class', 'wpex-select-wrap' + elClass);
2022-10-24 08:38:47 +00:00
}
}
} );
$( '.wpex-select-wrap', $context ).append( '<span class="fa fa-angle-down" aria-hidden="true"></span>' );
if ( $.fn.select2 !== undefined ) {
$( '#calc_shipping_country' ).select2();
}
},
/**
* FadeIn Elements
*
* @since 2.0.0
*/
fadeIn: function() {
$( '.fade-in-image, .wpex-show-on-load' ).addClass( 'no-opacity' );
},
/**
* OwlCarousel
*
* @since 2.0.0
*/
wpexOwlCarousel: function( $context ) {
// Make sure scripts are loaded
if ( undefined === $.fn.wpexOwlCarousel || undefined === $.fn.imagesLoaded ) {
return;
}
var self = this;
// Loop through carousels
$( '.wpex-carousel', $context ).each( function() {
var $this = $( this ),
$data = $this.data();
$this.imagesLoaded( function() {
var owl = $this.wpexOwlCarousel( {
animateIn : false,
animateOut : false,
lazyLoad : false,
smartSpeed : $data.smartSpeed ? $data.smartSpeed : wpexLocalize.carouselSpeed,
rtl : wpexLocalize.isRTL ? true : false,
dots : $data.dots,
nav : $data.nav,
items : $data.items,
slideBy : $data.slideby,
center : $data.center,
loop : $data.loop,
margin : $data.margin,
autoplay : $data.autoplay,
autoplayTimeout : $data.autoplayTimeout,
autoHeight : $data.autoHeight,
autoWidth : $data.autoWidth,
autoplayHoverPause : true,
navText : [ '<span class="fa fa-chevron-left"><span>', '<span class="fa fa-chevron-right"></span>' ],
responsive : {
0: {
items : $data.itemsMobilePortrait
},
480: {
items : $data.itemsMobileLandscape
},
768: {
items : $data.itemsTablet
},
960: {
items : $data.items
}
},
} );
} );
} );
},
/**
* SliderPro
*
* @since 2.0.0
*/
sliderPro: function( $context ) {
var self = this;
// Make sure functions are defined
if ( undefined === $.fn.sliderPro ) {
return;
}
// Loop through each slider
$( '.wpex-slider', $context ).each( function() {
// Declare vars
var $slider = $( this );
var $data = $slider.data();
var $slides = $slider.find( '.sp-slide' );
// Lets show things that were hidden to prevent flash
$slider.find( '.wpex-slider-slide, .wpex-slider-thumbnails.sp-thumbnails' ).css( {
'opacity' : 1,
'display' : 'block'
} );
// Main checks
var $autoHeight = self.parseData( $data.autoHeight, true );
var $preloader = $slider.prev( '.wpex-slider-preloaderimg' );
var $height = ( $preloader.length && $autoHeight ) ? $preloader.outerHeight() : null;
var $heightAnimationDuration = self.parseData( $data.heightAnimationDuration, 600 );
var $loop = self.parseData( $data.loop, false );
var $autoplay = self.parseData( $data.autoPlay, true );
// Get height based on tallest item if autoHeight is disabled
if ( ! $autoHeight && $slides.length ) {
var $tallest = self.getTallestEl( $slides );
$height = $tallest.height();
}
// Run slider
$slider.sliderPro( {
//supportedAnimation : 'JavaScript', //(CSS3 2D, CSS3 3D or JavaScript)
aspectRatio : -1,
width : '100%',
height : $height,
responsive : true,
fade : self.parseData( $data.fade, 600 ),
touchSwipe : self.parseData( $data.touchSwipe, true ),
fadeDuration : self.parseData( $data.animationSpeed, 600 ),
slideAnimationDuration : self.parseData( $data.animationSpeed, 600 ),
autoHeight : $autoHeight,
heightAnimationDuration : parseInt( $heightAnimationDuration ),
arrows : self.parseData( $data.arrows, true ),
fadeArrows : self.parseData( $data.fadeArrows, true ),
autoplay : $autoplay,
autoplayDelay : self.parseData( $data.autoPlayDelay, 5000 ),
buttons : self.parseData( $data.buttons, true ),
shuffle : self.parseData( $data.shuffle, false ),
orientation : self.parseData( $data.direction, 'horizontal' ),
loop : $loop,
keyboard : false,
fullScreen : self.parseData( $data.fullscreen, false ),
slideDistance : self.parseData( $data.slideDistance, 0 ),
thumbnailsPosition : 'bottom',
thumbnailHeight : self.parseData( $data.thumbnailHeight, 70 ),
thumbnailWidth : self.parseData( $data.thumbnailWidth, 70 ),
thumbnailPointer : self.parseData( $data.thumbnailPointer, false ),
updateHash : self.parseData( $data.updateHash, false ),
thumbnailArrows : false,
fadeThumbnailArrows : false,
thumbnailTouchSwipe : true,
fadeCaption : self.parseData( $data.fadeCaption, true ),
captionFadeDuration : 600,
waitForLayers : true,
autoScaleLayers : true,
forceSize : 'none',
reachVideoAction : self.parseData( $data.reachVideoAction, 'playVideo' ),
leaveVideoAction : self.parseData( $data.leaveVideoAction, 'pauseVideo' ),
endVideoAction : self.parseData( $data.leaveVideoAction, 'nextSlide' ),
fadeOutPreviousSlide : true, // If disabled testimonial/content slides are bad
autoplayOnHover : self.parseData( $data.autoplayOnHover, 'pause' ),
init: function( event ) {
$slider.prev( '.wpex-slider-preloaderimg' ).remove();
},
gotoSlide: function( event ) {
if ( ! $loop && $autoplay && event.index === $slider.find( '.sp-slide' ).length - 1 ) {
$slider.data( 'sliderPro' ).stopAutoplay();
}
}
} );
} );
// WooCommerce: Prevent clicking on Woo entry slider
$( '.woo-product-entry-slider' ).click( function() {
return false;
} );
// Make sure functions are defined
if ( undefined === $.fn.imagesLoaded ) {
return;
}
// Show no carousel thumbs
var $sliderProThumbsNC = $( '.wpex-slider-thumbnails.sp-nc-thumbnails', $context );
$sliderProThumbsNC.each( function() {
var $this = $( this );
$this.imagesLoaded( function() {
$this.css( {
'opacity' : 1,
'display' : 'block'
} );
} );
} );
},
/**
* Isotope Grids
*
* @since 2.0.0
*/
isotopeGrids: function ($context) {
var self = this;
// Make sure scripts are loaded
if ( undefined === $.fn.imagesLoaded || undefined === $.fn.isotope ) {
return;
}
var containers = $(window.wpexAnimsition.linkElement).parents(window.wpexAnimsition.container_block);
function get_filter_constraint(filterLink){
var filter_attr = window.wpexAnimsition.filter_attr;
var filter_constraint = filterLink.attr(filter_attr);
var filter_attrs = filter_attr.split(",");
if(filter_attrs.length != 1){
filter_constraint = [];
filter_attr = "";
filter_attrs.forEach(function(fa){
var tmp_filter_constraint = filterLink.attr(fa);
if( tmp_filter_constraint != undefined){
if(window.wpexAnimsition.use_attr_filter){
if(tmp_filter_constraint == "all"){
filter_constraint.push("["+fa+"]");
}else{
filter_constraint.push("["+fa+(fa[fa.length-1] == "s" ? '*' : '')+"=\""+tmp_filter_constraint+"\"]");
}
}else{
filter_constraint.push(tmp_filter_constraint);
}
}
})
if(window.wpexAnimsition.use_attr_filter){
filter_constraint = filter_constraint.join("],[");
}else{
filter_constraint = filter_constraint.join(",");
}
}else{
if(window.wpexAnimsition.use_attr_filter){
if(filter_constraint == "all"){
filter_constraint = "["+filter_attr+"]";
}else{
filter_constraint = "["+filter_attr+(filter_attr[filter_attr.length-1] == "s" ? '*' : '')+"=\""+filter_constraint+"\"]";
}
}
}
if(filterLink.data("count_limit") != undefined){
filter_constraint = filter_constraint+":nth-child(-n+"+filterLink.data("count_limit")+")";
}
return filter_constraint;
}
var container_text_arr = window.wpexAnimsition.container_block.split(",");
if(window.already_changes == undefined)
window.already_changes = container_text_arr.map(function(){return false});
// Loop through isotope grids
$(containers).each(function (i,v) {
var $container = $(v);
if(container_text_arr[i] == undefined){
return;
}
if($(container_text_arr[i]).parents(window.wpexAnimsition.need_fix_containers).length != 0){
if(!window.already_changes[i]){
2023-04-28 01:42:24 +00:00
var $filter = $container.parents(window.wpexAnimsition.parent_block).find(window.wpexAnimsition.filter_bar);
2022-10-24 08:38:47 +00:00
var $filterLinks = $filter.find(window.wpexAnimsition.filter_option);
var $divs = [];
$filterLinks.each(function (i,v) {
var filter_constraint = get_filter_constraint($(v));
var $div = $("<div></div>");
var filter_constraints = filter_constraint.split(",")
filter_constraints.forEach(function(vv){
var rm_attr = "";
var clone_mode = false;
var max_count = -1;
if(vv[0] == "["){
if(vv.search('=') != -1){
var attr_pair = vv.slice(1,-1).split("=");
attr_pair = attr_pair.map(function(v){ return v.match(/[^"^']+/)[0]});
attr_pair[0] = attr_pair[0].replace("*","");
$div.attr(attr_pair[0],attr_pair[1]);
rm_attr = attr_pair[0];
}else{
clone_mode = true;
var attr_pair = [vv.split(/\[|\]/)[1],"All"];
$(v).attr(attr_pair[0],attr_pair[1]);
$div.attr(attr_pair[0],attr_pair[1]);
var match_max_count = vv.match(/:nth-child\(-n\+(\d+)\)/)
if(match_max_count && match_max_count.length == 2){
max_count = match_max_count[1];
}
rm_attr = attr_pair[0];
}
}else if(vv[0] == "."){
$div.attr('class',vv.slice(1));
rm_attr = 'class';
}else if(vv[0] == "#"){
$div.attr('id',vv.slice(1));
rm_attr = 'id';
}
2023-04-28 01:42:24 +00:00
var linkElements = $container.parents(window.wpexAnimsition.parent_block).find(window.wpexAnimsition.linkElement).filter(vv);
2022-10-24 08:38:47 +00:00
if(linkElements.length != 0){
var parents_elements = window.wpexAnimsition.linkElement.split(/>| /).slice(0,-1).filter(function(v){return v!=""});
parents_elements = parents_elements.reverse();
var parent_el = null;
parents_elements.forEach(function(vvv){
if(parent_el == null){
parent_el = linkElements.parents(vvv)
}else{
parent_el = parent_el.parents(vvv)
}
})
$div.append(parent_el.eq(0).prop("outerHTML"));
if(!clone_mode){
$div.find(window.wpexAnimsition.linkElement).remove();
linkElements.removeAttr(rm_attr);
linkElements.appendTo($div.find("*").eq(-1));
}else if(max_count != -1){
$(v).removeAttr("data-count_limit");
$(v).removeData("count_limit");
$div.find(window.wpexAnimsition.linkElement).not(":lt("+max_count+")").remove();
$div.find(window.wpexAnimsition.linkElement).removeAttr(rm_attr);
}
}
})
$divs.push($div.prop("outerHTML"));
})
$(v).before($divs.join(""));
var parents_text = window.wpexAnimsition.container_block.split(',').map(function(t){
var str_arr = t.split(/>| /);
return ((str_arr.length <= 1) ? "*" : str_arr[0]);
}).join(",");
var parent_node = $(v).parents(parents_text);
$(v).remove();
var activeItems;
var $filter = parent_node.find(window.wpexAnimsition.filter_bar);
if ($filter.length) {
var $filterLinks = $filter.find(window.wpexAnimsition.filter_option);
activeItems = '';
if($filterLinks.length != 0){
var filter_constraint = get_filter_constraint($filterLinks.eq(0));
$filterLinks.each(function(){
var filter_constraint = get_filter_constraint($(this));
var inactive_node = parent_node.find(filter_constraint).not(window.wpexAnimsition.filter_option);
inactive_node.css("display","none");
inactive_node.find("> *").addClass("hidden_item");
inactive_node.find("> *").removeClass("active");
})
var active_node = parent_node.find(filter_constraint).not(window.wpexAnimsition.filter_option)
active_node.css("display","");
active_node.find("> *").removeClass("hidden_item");
active_node.find("> *").eq(0).addClass("active");
active_node.find("> *").eq(0).css("display","");
active_node.find(window.wpexAnimsition.linkElement).css("display","");
}
$filterLinks.click(function () {
var filter_constraint = get_filter_constraint($(this));
$filterLinks.each(function(){
var filter_constraint = get_filter_constraint($(this));
var inactive_node = parent_node.find(filter_constraint).not(window.wpexAnimsition.filter_option);
inactive_node.css("display","none");
inactive_node.find("> *").addClass("hidden_item");
inactive_node.find("> *").removeClass("active");
})
var active_node = parent_node.find(filter_constraint).not(window.wpexAnimsition.filter_option)
active_node.css("display","");
active_node.find("> *").removeClass("hidden_item");
active_node.find("> *").eq(0).addClass("active");
active_node.find("> *").eq(0).css("display","");
active_node.find(window.wpexAnimsition.linkElement).css("display","");
active_node.find(window.wpexAnimsition.children_text_block).css("height","");
return false;
})
}
}
window.already_changes[i] = true;
return;
}
$container.imagesLoaded(function () {
// Check filter
var activeItems;
// Filter links
2023-04-28 01:42:24 +00:00
var $filter = $container.parents(window.wpexAnimsition.parent_block).find(window.wpexAnimsition.filter_bar);
2022-10-24 08:38:47 +00:00
if ($filter.length) {
var $filterLinks = $filter.find(window.wpexAnimsition.filter_option);
activeItems = '';
if($filterLinks.length != 0){
var filter_constraint = get_filter_constraint($filterLinks.eq(0));
activeItems = filter_constraint;
}
$filterLinks.click(function () {
var filter_constraint = get_filter_constraint($(this));
$grid.isotope({ filter: filter_constraint});
self.equalHeights();
return false;
})
}
// Crete the isotope layout
var $grid = $container.isotope({
itemSelector: window.wpexAnimsition.linkElement,
transformsEnabled: true,
isOriginLeft: wpexLocalize.isRTL ? false : true,
transitionDuration: $container.data('transition-duration') ? $container.data('transition-duration') + 's' : '0.4s',
layoutMode: $container.data('layout-mode') ? $container.data('layout-mode') : 'masonry',
filter: activeItems
})
// $grid.on( 'layoutComplete', function(){
// //Something to call after animation
// });
})
})
},
/**
* Custom hovers using data attributes
*
* @since 4.5.4.2
*/
customHovers: function() {
var headCSS = '';
var cssObj = {};
$( '.wpex-hover-data' ).remove(); // prevent dups / front-end editor fix
// Newer Total 4.5.4.2 method
$( '[data-wpex-hover]' ).each( function( index, value ) {
var $this = $( this );
var data = $this.data( 'wpex-hover' );
var uniqueClass = 'wpex-dhover-' + index;
var hoverCSS = '';
var target = '';
if ( data.parent ) {
$this.parents( data.parent ).addClass( uniqueClass + '-p' );
$this.addClass( uniqueClass );
target = '.' + uniqueClass + '-p:hover .' + uniqueClass;
} else {
$this.addClass( uniqueClass );
target = '.' + uniqueClass + ':hover';
}
$.each( data, function( attribute, value ) {
if ( 'target' == attribute ) {
return true;
}
hoverCSS += attribute + ':' + value + '!important;';
} );
if ( hoverCSS ) {
if ( hoverCSS in cssObj ) {
cssObj[hoverCSS] = cssObj[hoverCSS] + ',' + target
} else {
cssObj[hoverCSS] = target;
}
}
} );
if ( cssObj ) {
$.each( cssObj, function( css, elements ) {
headCSS += elements + '{' + css + '}';
} );
}
if ( headCSS ) {
this.config.$head.append( '<style class="wpex-hover-data">/** CUSTOM HOVERS **/' + headCSS + '</style>' );
}
},
/**
* Responsive CSS
*
* @since 4.0
*/
responsiveCSS: function() {
var headCSS = '';
var mediaObj = {};
var bkPoints = {};
$( '.wpex-vc-rcss' ).remove(); // Prevent duplicates when editing the VC
// Get breakpoints
bkPoints.d = '';
bkPoints = $.extend( bkPoints, wpexLocalize.responsiveDataBreakpoints );
// Loop through breakpoints to create mediaObj
$.each( bkPoints, function( key ) {
mediaObj[key] = ''; // Create empty array of media breakpoints
} );
// loop through all modules and add CSS to mediaObj
$( '[data-wpex-rcss]' ).each( function( index, value ) {
var $this = $( this );
var uniqueClass = 'wpex-rcss-' + index;
var data = $this.data( 'wpex-rcss' );
$this.addClass( uniqueClass );
$.each( data, function( key, val ) {
var thisVal = val;
var target = key;
$.each( bkPoints, function( key ) {
if ( thisVal[key] ) {
mediaObj[key] += '.' + uniqueClass + '{' + target + ':' + thisVal[key] + '!important;}';
}
} );
} );
} );
$.each( mediaObj, function( key, val ) {
if ( 'd' == key ) {
headCSS += val;
} else {
if ( val ) {
headCSS += '@media (max-width: ' + bkPoints[key] + ') { ' + val + ' }';
}
}
} );
if ( headCSS ) {
headCSS = '<style class="wpex-vc-rcss">/** RESPONSIVE VC PARAMS **/' + headCSS + '</style>';
this.config.$head.append( headCSS );
}
},
/**
* VCEX Filter Nav
*
* @since 2.0.0
*/
vcexFilterNav: function( $context ) {
// Make sure scripts are loaded
if ( undefined === $.fn.imagesLoaded || undefined === $.fn.isotope ) {
return;
}
// Filter Navs
$( '.vcex-filter-nav', $context ).each( function() {
var $nav = $( this ),
$filterGrid = $( '#' + $nav.data( 'filter-grid' ) ),
$grid;
if ( ! $filterGrid.hasClass( 'wpex-row' ) ) {
$filterGrid = $filterGrid.find( '.wpex-row' );
}
if ( $filterGrid.length ) {
// Remove isotope class
$filterGrid.removeClass( 'vcex-isotope-grid' );
// Run functions after images are loaded for grid
$filterGrid.imagesLoaded( function() {
// Create Isotope
if ( ! $filterGrid.hasClass( 'vcex-navbar-filter-grid' ) ) {
$filterGrid.addClass( 'vcex-navbar-filter-grid' );
var activeItems = $nav.data( 'filter' );
if ( activeItems && ! $nav.find( '[data-filter="' + activeItems + '"]').length ) {
activeItems = '';
}
$grid = $filterGrid.isotope( {
itemSelector : '.col',
transformsEnabled : true,
isOriginLeft : wpexLocalize.isRTL ? false : true,
transitionDuration : $nav.data( 'transition-duration' ) ? $nav.data( 'transition-duration' ) + 's' : '0.4s',
layoutMode : $nav.data( 'layout-mode' ) ? $nav.data( 'layout-mode' ) : 'masonry',
filter : activeItems
} );
} else {
// Add isotope only, the filter grid already
$grid = $filterGrid.isotope();
}
// Loop through filter links for filtering items
var $filterLinks = $nav.find( 'a' );
$filterLinks.click( function() {
// Define link
var $link = $( this );
// Filter items
$grid.isotope( {
filter : $( this ).attr( 'data-filter' )
} );
// Remove all active class
$filterLinks.removeClass( 'active' );
// Add active class
$link.addClass( 'active' );
// Return false
return false;
} );
} );
}
} );
},
/**
* Archive Masonry Grids
*
* @since 2.0.0
*/
archiveMasonryGrids: function() {
// Make sure scripts are loaded
if ( undefined === $.fn.imagesLoaded || undefined === $.fn.isotope ) {
return;
}
// Define main vars
var self = this,
$archives = $( '.blog-masonry-grid,div.wpex-row.portfolio-masonry,div.wpex-row.portfolio-no-margins,div.wpex-row.staff-masonry,div.wpex-row.staff-no-margins' );
// Loop through archives
$archives.each( function() {
var $this = $( this );
var $data = $this.data();
// Load isotope after images loaded
$this.imagesLoaded( function() {
var $grid = $this.isotope( {
itemSelector : '.isotope-entry',
transformsEnabled : true,
isOriginLeft : wpexLocalize.isRTL ? false : true,
transitionDuration : self.parseData( $data.transitionDuration, '0.0' ) + 's',
layoutMode : self.parseData( $data.layoutMode, 'masonry' )
} );
} );
} );
},
/**
* Automatic Lightbox for images
*
* @version 4.5
*/
autoLightbox: function() {
if ( ! wpexLocalize.iLightbox.auto ) {
return;
}
var self = this,
imageExt = ['bmp', 'gif', 'jpeg', 'jpg', 'png', 'tiff', 'tif', 'jfif', 'jpe'];
$( '.wpb_text_column a:has(img), body.no-composer .entry a:has(img)' ).each( function() {
var $this = $( this );
var href = $this.attr( 'href' );
var ext = self.getUrlExtension( href );
if ( href && imageExt.indexOf( ext ) !== -1 ) {
if ( ! $this.parents( '.woocommerce-product-gallery' ).length ) {
$this.addClass( 'wpex-lightbox' );
}
}
} );
},
/**
* iLightbox
*
* @since 2.0.0
*/
iLightbox: function( $context ) {
var self = this;
// Store lightbox settings in object
self.iLightboxSettings = wpexLocalize.iLightbox;
// Sanitize data
self.iLightboxSettings.show.speed = parseInt( self.iLightboxSettings.show.speed );
self.iLightboxSettings.hide.speed = parseInt( self.iLightboxSettings.hide.speed );
self.iLightboxSettings.effects.repositionSpeed = parseInt( self.iLightboxSettings.effects.repositionSpeed );
self.iLightboxSettings.effects.switchSpeed = parseInt( self.iLightboxSettings.effects.switchSpeed );
self.iLightboxSettings.effects.loadedFadeSpeed = parseInt( self.iLightboxSettings.effects.loadedFadeSpeed );
self.iLightboxSettings.effects.fadeSpeed = parseInt( self.iLightboxSettings.effects.fadeSpeed );
// Lightbox Galleries
// @todo change lightbox-group class to .wpex-lightbox-group in theme template parts
$( '.lightbox-group, .wpex-lightbox-group', $context ).each( function() {
// Get lightbox data
var $this = $( this );
var $item = $this.find( '.wpex-lightbox-group-item' );
var $iLightboxData = $this.data( 'ilightbox' );
// Destroy if lightbox has already been added and re-add
// Prevents build-up in AJAX functions
if ( $iLightboxData ) {
$iLightboxData.destroy();
}
// Prevent conflicts (can't be a group item and a lightbox item)
$item.removeClass( 'wpex-lightbox' );
// Set item to it's child link if not a link itself
if ( ! $item.is( 'a' ) ) {
$item = $item.find( 'a' );
$item.removeClass( 'wpex-lightbox' ); // prevent conflicts
}
// Start up lightbox
var $ilightbox = $item.iLightBox( $.extend( true, {}, self.iLightboxSettings, {
skin: self.parseData( $this.data( 'skin' ), wpexLocalize.iLightbox.skin ),
path: self.parseData( $this.data( 'path' ), wpexLocalize.iLightbox.path ),
infinite: self.parseData( $this.data( 'infinite' ), wpexLocalize.iLightbox.infinite ),
show: {
title: self.parseData( $this.data( 'show_title' ), wpexLocalize.iLightbox.show.title )
},
controls: {
arrows: self.parseData( $this.data( 'arrows' ), wpexLocalize.iLightbox.controls.arrows ),
thumbnail: self.parseData( $this.data( 'thumbnails' ), wpexLocalize.iLightbox.controls.thumbnail )
},
} ) );
// Save lightbox instance
$this.data( 'ilightbox', $ilightbox );
} );
// Lightbox Standard => SINGLE LIGHTBOX
$( '.wpex-lightbox', $context ).each( function() {
var $this = $( this );
if ( ! $this.is( 'a' ) ) {
$this = $this.find( 'a' );
}
if ( ! $this.hasClass( 'wpex-lightbox-group-item' ) ) {
var $ilightbox = $this.iLightBox( $.extend( true, {}, self.iLightboxSettings, {
skin: self.parseData( $this.data( 'skin' ), wpexLocalize.iLightbox.skin ),
show: {
title: self.parseData( $this.data( 'show_title' ), wpexLocalize.iLightbox.show.title )
},
controls: {
arrows: false,
thumbnail: false,
mousewheel: false
}
} ) );
$this.data( 'ilightbox', $ilightbox );
}
} );
// Lightbox Gallery with custom imgs
$( '.wpex-lightbox-gallery', $context ).on( 'click', function( event ) {
var $this = $( this ),
data = $this.data( 'gallery' ),
imagesArray = '';
if ( ! data ) {
return;
}
if ( typeof data == 'string' || data instanceof String ) {
imagesArray = data.split( ',' );
} else {
imagesArray = data;
}
// console.log ( imagesArray );
//return false;
$.iLightBox( imagesArray, $.extend( true, {}, self.iLightboxSettings, {
skin: self.parseData( $this.data( 'skin' ), wpexLocalize.iLightbox.skin ),
path: self.parseData( $this.data( 'path' ), wpexLocalize.iLightbox.path ),
infinite: self.parseData( $this.data( 'skin' ), wpexLocalize.iLightbox.infinite ),
controls: {
arrows: self.parseData( $this.data( 'arrows' ), wpexLocalize.iLightbox.controls.arrows ),
thumbnail: self.parseData( $this.data( 'thumbnails' ), wpexLocalize.iLightbox.controls.thumbnail )
}
} ) );
return false;
} );
// Lightbox Videos => OLD SCHOOL STUFF, keep for old customers
$( '.wpex-lightbox-video, .wpb_single_image.video-lightbox a, .wpex-lightbox-autodetect, .wpex-lightbox-autodetect a', $context ).each( function() {
var $this = $( this ),
$data = $this.data();
$this.iLightBox( {
smartRecognition : true,
skin : self.parseData( $data.skin, wpexLocalize.iLightbox.skin ),
path : 'horizontal',
controls : {
fullscreen : wpexLocalize.iLightbox.controls.fullscreen
},
show : {
title : self.parseData( $data.show_title, wpexLocalize.iLightbox.show.title ),
speed : parseInt( wpexLocalize.iLightbox.show.speed )
},
hide : {
speed : parseInt( wpexLocalize.iLightbox.hide.speed )
},
effects : {
reposition : true,
repositionSpeed : 200,
switchSpeed : 300,
loadedFadeSpeed : wpexLocalize.iLightbox.effects.loadedFadeSpeed,
fadeSpeed : wpexLocalize.iLightbox.effects.fadeSpeed
},
overlay : wpexLocalize.iLightbox.overlay,
social : wpexLocalize.iLightbox.social
} );
} );
// Custom Lightbox for Carousels
$( '.wpex-carousel', $context ).on( 'click', '.wpex-carousel-lightbox-item', function( e ) {
e.preventDefault();
var $this = $( this ),
$parent = $this.parents( '.wpex-carousel' ),
$parentOwl = $this.parents( '.owl-item' ),
$owlItems = $parent.find( '.owl-item' ),
$data = $this.data(),
$imagesArray = [];
$owlItems.each( function() {
if ( ! $( this ).hasClass( 'cloned' ) ) {
var $image = $( this ).find( '.wpex-carousel-lightbox-item' );
if ( $image.length > 0 ) {
$imagesArray.push( {
URL : $image.attr( 'href' ),
title : $image.attr( 'data-title' ),
caption : $image.attr( 'data-caption' )
} );
}
}
} );
if ( $imagesArray.length > 0 ) {
// Define where to start lightbox from
var $startFrom = $this.data( 'count' ) - 1;
$startFrom = $startFrom ? $startFrom : 0;
$.iLightBox( $imagesArray, $.extend( true, {}, self.iLightboxSettings, {
startFrom: parseInt( $startFrom ),
skin: self.parseData( $data.skin, wpexLocalize.iLightbox.skin ),
path: self.parseData( $data.path, wpexLocalize.iLightbox.path ),
infinite: self.parseData( $data.skin, wpexLocalize.iLightbox.infinite ),
show: {
title: self.parseData( $data.show_title, wpexLocalize.iLightbox.show.title )
},
controls: {
arrows: self.parseData( $data.arrows, wpexLocalize.iLightbox.controls.arrows ),
thumbnail: self.parseData( $data.thumbnails, wpexLocalize.iLightbox.controls.thumbnail )
}
} ) );
}
} );
},
/**
* Overlay Hovers
*
* @since 2.0.0
*/
overlayHovers: function() {
// Mobile Hovers if enabled
if ( this.config.isMobile ) {
// Remove overlays completely if mobile support is disabled
$( '.overlay-parent.overlay-hh' ).each( function() {
if ( ! $( this ).hasClass( 'overlay-ms' ) ) {
$( this ).find( '.theme-overlay' ).remove();
}
} );
// Prevent click on touchstart
$( 'a.overlay-parent.overlay-ms.overlay-h, .overlay-parent.overlay-ms.overlay-h > a' ).on( 'touchstart', function( e ) {
var $this = $( this );
var $overlayParent = $this.hasClass( 'overlay-parent' ) ? $this : $this.parent( '.overlay-parent' );
if ( $overlayParent.hasClass( 'wpex-touched' ) ) {
return true;
} else {
$overlayParent.addClass( 'wpex-touched' );
$( '.overlay-parent' ).not($overlayParent).removeClass( 'wpex-touched' );
e.preventDefault();
return false;
}
} );
// Hide overlay when clicking outside
this.config.$document.on( 'touchstart', function( e ) {
if ( ! $( e.target ).closest( '.wpex-touched' ).length ) {
$( '.wpex-touched' ).removeClass( 'wpex-touched' );
}
} );
}
// Title Push Up
$( '.overlay-parent-title-push-up' ).each( function() {
// Define vars
var $this = $( this ),
$title = $this.find( '.overlay-title-push-up' ),
$child = $this.find( 'a' ),
$img = $child.find( 'img' ),
$titleHeight = $title.outerHeight();
// Create overlay after image is loaded to prevent issues
$this.imagesLoaded( function() {
// Position title
$title.css( {
'bottom' : - $titleHeight
} );
// Add height to child
$child.css( {
'height' : $img.outerHeight()
} );
// Position image
$img.css( {
'position' : 'absolute',
'top' : '0',
'left' : '0',
'width' : 'auto',
'height' : 'auto'
} );
// Animate image on hover
$this.hover( function() {
$img.css( {
'top' : -20
} );
$title.css( {
'bottom' : 0
} );
}, function() {
$img.css( {
'top' : '0'
} );
$title.css( {
'bottom' : - $titleHeight
} );
} );
} );
} );
},
/**
* Sticky Topbar
*
* @since 3.4.0
*/
stickyTopBar: function() {
var self = this;
// Return if disabled or not found
if ( ! self.config.hasStickyTopBar || ! self.config.$stickyTopBar ) {
return;
}
// Define vars
var $isSticky = false,
$offset = 0,
$window = self.config.$window,
$stickyTopbar = self.config.$stickyTopBar,
$mobileSupport = self.config.hasStickyTopBarMobile,
$brkPoint = wpexLocalize.stickyTopBarBreakPoint,
$mobileMenu = $( '#wpex-mobile-menu-fixed-top' ),
$stickyWrap = $( '<div id="top-bar-wrap-sticky-wrapper" class="wpex-sticky-top-bar-holder not-sticky"></div>' );
// Set sticky wrap to new wrapper
$stickyTopbar.wrapAll( $stickyWrap );
$stickyWrap = $( '#top-bar-wrap-sticky-wrapper' );
// Get offset
function getOffset() {
$offset = 0; // Reset offset for resize
if ( self.config.$wpAdminBar ) {
$offset = $offset + self.config.$wpAdminBar.outerHeight();
}
if ( $mobileMenu.is( ':visible' ) ) {
$offset = $offset + $mobileMenu.outerHeight();
}
return $offset;
}
// Stick the TopBar
function setSticky() {
// Already stuck
if ( $isSticky ) {
return;
}
// Add wrap class and toggle sticky class
$stickyWrap
.css( 'height', $stickyTopbar.outerHeight() )
.removeClass( 'not-sticky' )
.addClass( 'is-sticky' );
// Add CSS to topbar
$stickyTopbar.css( {
'top' : getOffset(),
'width' : $stickyWrap.width()
} );
// Set sticky to true
$isSticky = true;
}
// Unstick the TopBar
function destroySticky() {
if ( ! $isSticky ) {
return;
}
// Remove sticky wrap height and toggle sticky class
$stickyWrap
.css( 'height', '' )
.removeClass( 'is-sticky' )
.addClass( 'not-sticky' );
// Remove topbar css
$stickyTopbar.css( {
'width' : '',
'top' : '',
} );
// Set sticky to false
$isSticky = false;
}
// On load check
function initSetSticky() {
// Disable on mobile devices
if ( ! $mobileSupport && ( self.config.viewportWidth < $brkPoint ) ) {
return;
}
// Set sticky based on original offset
$offset = $stickyWrap.offset().top - getOffset();
// Set or destroy sticky
if ( self.config.windowTop > $offset ) {
setSticky();
}
}
// On scroll actions for sticky topbar
function onScroll() {
// Disable on mobile devices
if ( ! $mobileSupport && ( self.config.viewportWidth < $brkPoint ) ) {
return;
}
// Destroy sticky at top and prevent sticky at top (since its already at top)
if ( 0 === self.config.windowTop ) {
if ( $isSticky ) {
destroySticky();
}
return;
}
// Get correct start position for sticky to start
var $stickyWrapTop = $stickyWrap.offset().top;
var $setStickyPos = $stickyWrapTop - getOffset();
// Set or destroy sticky based on offset
if ( self.config.windowTop >= $setStickyPos ) {
setSticky();
} else {
destroySticky();
}
}
// On resize actions for sticky topbar
function onResize() {
// Check if header is disabled on mobile if not destroy on resize
if ( ! $mobileSupport && ( self.config.viewportWidth < $brkPoint ) ) {
destroySticky();
} else {
// Set correct width and top value
if ( $isSticky ) {
$stickyWrap.css( 'height', $stickyTopbar.outerHeight() );
$stickyTopbar.css( {
'top' : getOffset(),
'width' : $stickyWrap.width()
} );
} else {
onScroll();
}
}
}
// Fire on init
initSetSticky();
// Fire onscroll event
$window.scroll( function() {
onScroll();
} );
// Fire onResize
$window.resize( function() {
onResize();
} );
// Fire resize on flip
// Destroy and re-calculate
$window.on( 'orientationchange' , function( e ) {
destroySticky();
initSetSticky();
} );
},
/**
* Get correct offSet for the sticky header and sticky header menu.
*
* @since 3.4.0
*/
stickyOffset: function() {
var self = this;
var $offset = 0;
var $mobileMenu = $( '#wpex-mobile-menu-fixed-top' );
var $stickyTopbar = self.config.$stickyTopBar;
// Offset sticky topbar
if ( $stickyTopbar && $stickyTopbar.is( ':visible' ) ) {
if ( self.config.hasStickyTopBarMobile
|| self.config.viewportWidth >= wpexLocalize.stickyTopBarBreakPoint
) {
$offset = $offset + $stickyTopbar.outerHeight();
}
}
// Offset mobile menu
if ( $mobileMenu.is( ':visible' ) ) {
$offset = $offset + $mobileMenu.outerHeight();
}
// Offset adminbar
if ( this.config.$wpAdminBar && this.config.$wpAdminBar.is( ':visible' ) ) {
$offset = $offset + this.config.$wpAdminBar.outerHeight();
}
// Added offset via child theme
if ( wpexLocalize.addStickyHeaderOffset ) {
$offset = $offset + wpexLocalize.addStickyHeaderOffset;
}
// Return correct offset
return $offset;
},
/**
* New Sticky Header
*
* @since 4.6.5
*/
stickyHeaderCustomStartPoint: function() {
var $startPosition = wpexLocalize.stickyHeaderStartPosition;
if ( $.isNumeric( $startPosition ) ) {
$startPosition = $startPosition;
} else if ( $( $startPosition ).length ) {
$startPosition = $( $startPosition ).offset().top;
} else {
$startPosition = 0;
}
return $startPosition;
},
/**
* New Sticky Header
*
* @since 3.4.0
*/
stickyHeader: function() {
var self = this,
$isSticky = false,
$isShrunk = false,
$isLogoSwapped = false;
// Return if sticky is disabled
if ( ! self.config.hasStickyHeader ) {
return;
}
// Define header
var $header = self.config.$siteHeader;
var $headerHeight = self.config.siteHeaderHeight;
var $headerBottom = $header.offset().top + $header.outerHeight();
// Add sticky wrap
var $stickyWrap = $( '<div id="site-header-sticky-wrapper" class="wpex-sticky-header-holder not-sticky"></div>' );
$header.wrapAll( $stickyWrap );
$stickyWrap = $( '#site-header-sticky-wrapper' ); // Cache newly added element as dom object
// Define main vars for sticky function
var $window = self.config.$window;
var $brkPoint = wpexLocalize.stickyHeaderBreakPoint;
var $mobileSupport = self.config.hasStickyMobileHeader;
var $customStart = self.stickyHeaderCustomStartPoint();
// Custom sticky logo
var $headerLogo = self.config.$siteLogo;
var $headerLogoSrc = self.config.siteLogoSrc;
// Shrink support
var maybeShrink = ( 'shrink' == self.stickyHeaderStyle || 'shrink_animated' == self.stickyHeaderStyle ) ? true : false;
// Custom shrink logo
var $stickyLogo = wpexLocalize.stickyheaderCustomLogo;
if ( $stickyLogo
&& wpexLocalize.stickyheaderCustomLogoRetina
&& self.config.isRetina
) {
$stickyLogo = wpexLocalize.stickyheaderCustomLogoRetina;
}
// Load images to be used for the custom sticky logo
if ( $stickyLogo ) {
$( '<img src="' + $stickyLogo + '">' ).appendTo( 'body' ).css( 'display', 'none' );
}
// Check if we are on mobile size
function pastBreakPoint() {
return ( self.config.viewportWidth < $brkPoint ) ? true : false;
}
// Check if we are past the header
function pastheader() {
var bottomCheck = 0;
if ( self.config.hasHeaderOverlay ) {
bottomCheck = $headerBottom;
} else {
bottomCheck = $stickyWrap.offset().top + $stickyWrap.outerHeight();
}
if ( self.config.windowTop > $headerBottom ) {
return true;
}
return false;
}
// Check start position
function start_position() {
var $startPosition = $customStart;
$startPosition = $startPosition ? $startPosition : $stickyWrap.offset().top;
return $startPosition - self.stickyOffset();
}
// Transform
function transformPrepare() {
if ( $isSticky ) {
$header.addClass( 'transform-go' ); // prevent issues when scrolling
}
if ( 0 === self.config.windowTop ) {
$header.removeClass( 'transform-prepare' );
} else if ( pastheader() ) {
$header.addClass( 'transform-prepare' );
} else {
$header.removeClass( 'transform-prepare' );
}
}
// Swap logo
function swapLogo() {
if ( ! $stickyLogo || ! $headerLogo ) {
return;
}
if ( $isLogoSwapped ) {
$headerLogo.attr( 'src', $headerLogoSrc );
self.config.siteLogoHeight = self.config.$siteLogo.height();
$isLogoSwapped = false;
} else {
$headerLogo.attr( 'src', $stickyLogo );
self.config.siteLogoHeight = self.config.$siteLogo.height();
$isLogoSwapped = true;
}
}
// Shrink/unshrink header
function shrink() {
var checks = maybeShrink;
if ( pastBreakPoint() ) {
if ( $mobileSupport && ( 'icon_buttons' == self.config.mobileMenuToggleStyle || 'fixed_top' == self.config.mobileMenuToggleStyle ) ) {
checks = true
} else {
checks = false;
}
}
if ( checks && pastheader() ) {
if ( ! $isShrunk && $isSticky ) {
$header.addClass( 'sticky-header-shrunk' );
$isShrunk = true;
}
} else {
$header.removeClass( 'sticky-header-shrunk' );
$isShrunk = false;
}
}
// Set sticky
function setSticky() {
// Already stuck
if ( $isSticky ) {
return;
}
// Custom Sticky logo
swapLogo();
// Add wrap class and toggle sticky class
$stickyWrap
.css( 'height', $headerHeight )
.removeClass( 'not-sticky' )
.addClass( 'is-sticky' );
// Tweak header
$header.removeClass( 'dyn-styles' ).css( {
'top' : self.stickyOffset(),
'width' : $stickyWrap.width()
} );
// Add transform go class
if ( $header.hasClass( 'transform-prepare' ) ) {
$header.addClass( 'transform-go' );
}
// Set sticky to true
$isSticky = true;
}
// Destroy actions
function destroyActions() {
// Reset logo
swapLogo();
// Remove sticky wrap height and toggle sticky class
$stickyWrap.removeClass( 'is-sticky' ).addClass( 'not-sticky' );
// Do not remove height on sticky header for shrink header incase animation isn't done yet
if ( ! $header.hasClass( 'shrink-sticky-header' ) ) {
$stickyWrap.css( 'height', '' );
}
// Reset header
$header.addClass( 'dyn-styles' ).css( {
'width' : '',
'top' : ''
} ).removeClass( 'transform-go' );
// Set sticky to false
$isSticky = false;
// Make sure shrink header is removed
$header.removeClass( 'sticky-header-shrunk' ); // Fixes some bugs with really fast scrolling
$isShrunk = false;
}
// Destroy sticky
function destroySticky() {
// Already unstuck
if ( ! $isSticky ) {
return;
}
if ( $customStart ) {
$header.removeClass( 'transform-go' );
if ( $isShrunk ) {
$header.removeClass( 'sticky-header-shrunk' );
$isShrunk = false;
}
} else {
$header.removeClass( 'transform-prepare' );
}
destroyActions();
}
// On load check
function initResizeSetSticky() {
if ( ! $mobileSupport && pastBreakPoint() ) {
return;
}
//$header.addClass( 'transform-go' );
if ( self.config.windowTop > start_position() && 0 !== self.config.windowTop ) {
setSticky();
}
if ( maybeShrink ) {
shrink();
}
}
// On scroll function
function onScroll() {
// Disable on mobile devices
if ( ! $mobileSupport && pastBreakPoint() ) {
return;
}
// Animate scroll with custom start
if ( $customStart ) {
transformPrepare();
}
// Destroy sticky at top
if ( 0 === self.config.windowTop ) {
destroySticky();
return;
}
// Set or destroy sticky
if ( self.config.windowTop >= start_position() ) {
setSticky();
} else {
destroySticky();
}
// Shrink
if ( maybeShrink ) {
shrink();
}
}
// On resize function
function onResize() {
// Check if header is disabled on mobile if not destroy on resize
if ( ! $mobileSupport && pastBreakPoint() ) {
destroySticky();
$header.removeClass( 'transform-prepare' ); // important!
} else {
// Update sticky
if ( $isSticky ) {
// Update wrapper height
if ( ! $header.hasClass( 'shrink-sticky-header' ) ) {
$stickyWrap.css( 'height', self.config.siteHeaderHeight );
}
// Update sticky width and top offset
$header.css( {
'top' : self.stickyOffset(),
'width' : $stickyWrap.width()
} );
}
// Add sticky
else {
initResizeSetSticky();
}
}
// Shrink
if ( maybeShrink ) {
shrink();
}
} // End onResize
// Fire on init
initResizeSetSticky();
// Fire onscroll event
$window.scroll( function() {
if ( self.config.$hasScrolled ) {
onScroll();
}
} );
// Fire onResize
$window.resize( function() {
if ( self.config.widthChanged || self.config.heightChanged ) {
onResize();
}
} );
// Destroy and run onResize function on orientation change
$window.on( 'orientationchange' , function() {
destroySticky();
initResizeSetSticky();
} );
},
/**
* Sticky Header Menu
*
* @since 3.4.0
*/
stickyHeaderMenu: function() {
var self = this;
// Return if disabled
if ( ! self.config.hasStickyNavbar ) {
return;
}
// Main vars
var $navWrap = self.config.$siteNavWrap,
$isSticky = false,
$window = self.config.$window,
elIndex = $( $navWrap ).index(),
//$mobileSupport = wpexLocalize.hasStickyNavbarMobile,
$stickyWrap = $( '<div id="site-navigation-sticky-wrapper" class="wpex-sticky-navigation-holder not-sticky"></div>' );
// Define sticky wrap
$navWrap.wrapAll( $stickyWrap );
$stickyWrap = $( '#site-navigation-sticky-wrapper' );
// Add offsets
var $stickyWrapTop = $stickyWrap.offset().top,
$stickyOffset = self.stickyOffset(),
$setStickyPos = $stickyWrapTop - $stickyOffset;
// Shrink header function
function setSticky() {
// Already sticky
if ( $isSticky ) {
return;
}
// Add wrap class and toggle sticky class
$stickyWrap
.css( 'height', self.config.$siteNavWrap.outerHeight() )
.removeClass( 'not-sticky' )
.addClass( 'is-sticky' );
// Add CSS to topbar
$navWrap.css( {
'top' : self.stickyOffset(),
'width' : $stickyWrap.width()
} );
// Remove header dynamic styles
self.config.$siteHeader.removeClass( 'dyn-styles' );
// Update shrunk var
$isSticky = true;
}
// Un-Shrink header function
function destroySticky() {
// Not shrunk
if ( ! $isSticky ) {
return;
}
// Remove sticky wrap height and toggle sticky class
$stickyWrap
.css( 'height', '' )
.removeClass( 'is-sticky' )
.addClass( 'not-sticky' );
// Remove navbar width
$navWrap.css( {
'width' : '',
'top' : ''
} );
// Re-add dynamic header styles
self.config.$siteHeader.addClass( 'dyn-styles' );
// Update shrunk var
$isSticky = false;
}
// On load check
function initResizeSetSticky() {
// Disable on mobile devices
if ( self.config.viewportWidth <= wpexLocalize.stickyNavbarBreakPoint ) {
return;
}
// Sticky menu
if ( self.config.windowTop >= $setStickyPos && 0 !== self.config.windowTop ) {
setSticky();
} else {
destroySticky();
}
}
// Sticky check / enable-disable
function onScroll() {
// Disable on mobile devices
if ( self.config.viewportWidth <= wpexLocalize.stickyNavbarBreakPoint ) {
return;
}
// Destroy sticky at top and prevent sticky at top (since its already at top)
if ( 0 === self.config.windowTop ) {
if ( $isSticky ) {
destroySticky();
}
return;
}
// Sticky menu
if ( self.config.windowTop >= $setStickyPos ) {
setSticky();
} else {
destroySticky();
}
}
// On resize function
function onResize() {
// Check if sticky is disabled on mobile if not destroy on resize
if ( self.config.viewportWidth <= wpexLocalize.stickyNavbarBreakPoint ) {
destroySticky();
}
// Update width
if ( $isSticky ) {
$navWrap.css( 'width', $stickyWrap.width() );
} else {
initResizeSetSticky();
}
}
// Fire on init
initResizeSetSticky();
// Fire onscroll event
$window.scroll( function() {
if ( self.config.$hasScrolled ) {
onScroll();
}
} );
// Fire onResize
$window.resize( function() {
onResize();
} );
// Fire resize on flip
$window.on( 'orientationchange' , function() {
destroySticky();
initResizeSetSticky();
} );
},
/**
* Sticky Visual Composer Navbar
*
* @since 3.3.2
*/
stickyVcexNavbar: function() {
var self = this;
var $nav = $( '.vcex-navbar-sticky' );
if ( ! $nav.length ) {
return;
}
$nav.each( function() {
var $this = $( this );
var $isSticky = false;
var $window = self.config.$window;
var $stickyEndPoint = $this.data( 'sticky-endpoint' ) ? $( $this.data( 'sticky-endpoint' ) ) : '';
// Add sticky wrap
var $stickyWrap = $( '<div class="vcex-navbar-sticky-wrapper not-sticky"></div>' );
$this.wrapAll( $stickyWrap );
$stickyWrap = $this.parent( '.vcex-navbar-sticky-wrapper' );
// Set sticky
function setSticky( $offset ) {
// Already sticky or hidden
if ( $isSticky || ! $this.is( ':visible' ) ) {
return;
}
// Set placeholder
$stickyWrap
.css( 'height', $this.outerHeight() )
.removeClass( 'not-sticky' )
.addClass( 'is-sticky' );
// Position Fixed nav
$this.css( {
'top' : $offset,
'width' : $stickyWrap.width()
} );
// Update sticky var
$isSticky = true;
}
// Check sticky offSet based on other sticky elements
function getStickyOffset() {
var offset = 0;
var $stickyTopbar = $( '#top-bar-wrap-sticky-wrapper' );
var $stickyHeader = $( '#site-header-sticky-wrapper' );
var $stickyHeaderNavbar = $( '#site-navigation-sticky-wrapper' );
var $mobileMenu = $( '#wpex-mobile-menu-fixed-top' );
if ( $stickyTopbar.is( ':visible' ) ) {
if ( self.config.hasStickyTopBarMobile
|| self.config.viewportWidth >= wpexLocalize.stickyTopBarBreakPoint
) {
offset = offset + $stickyTopbar.outerHeight();
}
}
if ( $stickyHeader.is( ':visible' ) ) {
if ( self.config.hasStickyMobileHeader
|| self.config.viewportWidth >= wpexLocalize.stickyHeaderBreakPoint
) {
if ( self.config.$siteHeader.hasClass( 'shrink-sticky-header' ) ) {
offset = offset + parseInt( wpexLocalize.shrinkHeaderHeight );
} else {
offset = offset + $stickyHeader.outerHeight();
}
}
}
if ( self.config.hasStickyNavbar && $stickyHeaderNavbar.is( ':visible' ) ) {
if ( self.config.hasStickyMobileHeader
|| ( self.config.viewportWidth >= wpexLocalize.stickyNavbarBreakPoint )
) {
offset = offset + $stickyHeaderNavbar.outerHeight();
}
}
if ( $mobileMenu.is( ':visible' ) ) {
offset = offset + $mobileMenu.outerHeight();
}
if ( self.config.$wpAdminBar && self.config.$wpAdminBar.is( ':visible' ) ) {
offset = offset + self.config.$wpAdminBar.outerHeight();
}
return offset;
}
// Un-Shrink header function
function destroySticky() {
// Not shrunk
if ( ! $isSticky ) {
return;
}
// Remove sticky wrap height and toggle sticky class
$stickyWrap
.css( 'height', '' )
.removeClass( 'is-sticky' )
.addClass( 'not-sticky' );
// Remove navbar width
$this.css( {
'width' : '',
'top' : ''
} );
// Update shrunk var
$isSticky = false;
}
// On scroll function
function stickyCheck() {
var stickyOffset = getStickyOffset();
var stickyWrapTop = $stickyWrap.offset().top;
var setStickyPos = stickyWrapTop - stickyOffset;
if ( self.config.windowTop > setStickyPos && 0 !== self.config.windowTop ) {
setSticky( stickyOffset );
if ( $stickyEndPoint.length && $stickyEndPoint.is( ':visible' ) ) {
if ( self.config.windowTop > ( $stickyEndPoint.offset().top - stickyOffset - $this.outerHeight() ) ) {
$stickyWrap.addClass( 'sticky-hidden' );
} else {
$stickyWrap.removeClass( 'sticky-hidden' );
}
}
} else {
destroySticky();
}
}
// On resize function
function onResize() {
// Should it be sticky?
stickyCheck();
// Sticky fixes
if ( $isSticky ) {
// Destroy if hidden
if ( ! $this.is( ':visible' ) ) {
destroySticky();
}
// Set correct height on wrapper
$stickyWrap.css( 'height', $this.outerHeight() );
// Set correct width and offset value on sticky element
$this.css( {
'top' : getStickyOffset(),
'width' : $stickyWrap.width()
} );
}
// Should it become sticky?
else {
stickyCheck();
}
}
// Fire on init
stickyCheck();
// Fire onscroll event
$window.scroll( function() {
if ( self.config.$hasScrolled ) {
stickyCheck();
}
} );
// Fire onResize
$window.resize( function() {
onResize();
} );
// Fire resize on flip
$window.on( 'orientationchange' , function( e ) {
destroySticky();
stickyCheck();
} );
} ); // End each
},
/**
* Infinite Scroll
*
* @since 3.5.0
*/
infiniteScrollInit: function() {
var self = this;
var $container = $( '#blog-entries' );
$container.infinitescroll( wpexInfiniteScroll, function( newElements ) {
var $newElems = $( newElements ).css( 'opacity', 0 );
$newElems.imagesLoaded( function() {
if ( $container.hasClass( 'blog-masonry-grid' ) ) {
$container.isotope( 'appended', $newElems );
$newElems.css( 'opacity', 0 );
}
if ( typeof retinajs !== 'undefined' && $.isFunction( retinajs ) ) {
retinajs();
}
$newElems.animate( {
opacity: 1
} );
$container.trigger( 'wpexinfiniteScrollLoaded', [$newElems] );
self.sliderPro( $newElems );
self.iLightbox( $newElems );
if ( $.fn.wpexEqualHeights !== undefined ) {
$( '.blog-equal-heights' ).wpexEqualHeights( {
children : '.blog-entry-inner'
} );
}
if ( typeof( $.fn.mediaelementplayer ) !== 'undefined' ) {
$newElems.find( 'audio, video' ).mediaelementplayer();
}
} );
} );
},
/**
* Load More pagination
*
* @since 4.4.1
*/
loadMore: function() {
var self = this;
var $loadMore = $( '.wpex-load-more' );
if ( ! $loadMore.length ) {
return;
}
$loadMore.each( function() {
var $button = $( this );
var $buttonInner = $button.find( '.theme-button-inner' );
var loading = false;
var text = wpexLocalize.loadMore.text;
var ajaxUrl = wpexLocalize.ajaxurl;
var loadingText = wpexLocalize.loadMore.loadingText;
var failedText = wpexLocalize.loadMore.failedText;
var buttonData = $button.data( 'loadmore' );
var $grid = $( buttonData.grid );
var page = 2;
if ( 1 != buttonData.maxPages ) {
$button.addClass( 'wpex-visible' );
}
var loadmoreData = buttonData;
$button.on( 'click', function() {
if ( ! loading ) {
loading = true;
$button.addClass( 'loading' );
$buttonInner.text( loadingText );
var data = {
action : 'wpex_ajax_load_more',
nonce : buttonData.nonce,
page : page,
loadmore : loadmoreData
};
$.post( ajaxUrl, data, function( res ) {
// Ajax request successful
if ( res.success ) {
//console.log( res.data );
// Increase page
page = page + 1;
// Define vars
var $newElements = $( res.data );
$newElements.css( 'opacity', 0 ); // hide until images are loaded
// Remove duplicate posts (sticky)
$newElements.each( function() {
var $this = $( this );
if ( $this.hasClass( 'sticky' ) ) {
$this.addClass( 'wpex-duplicate' );
}
} );
$grid.append( $newElements ).imagesLoaded( function() {
if ( $.fn.wpexEqualHeights !== undefined ) {
$( '.blog-equal-heights' ).wpexEqualHeights( {
children : '.blog-entry-inner'
} );
}
if ( $grid.hasClass( 'blog-masonry-grid' ) ) {
$grid.isotope( 'appended', $newElements );
//$grid.isotope( 'appended', $( $newElements ) ).isotope( 'layout' );
}
self.iLightbox( $newElements );
self.overlayHovers( $newElements );
$grid.trigger( 'wpexLoadMoreAddedHidden', [$newElements] );
$newElements.css( 'opacity', 1 );
if ( typeof retinajs !== 'undefined' && $.isFunction( retinajs ) ) {
retinajs();
}
self.sliderPro( $newElements );
if ( typeof( $.fn.mediaelementplayer ) !== 'undefined' ) {
$newElements.find( 'audio, video' ).mediaelementplayer();
}
$grid.trigger( 'wpexLoadMoreAddedVisible', [$newElements] );
// Reset button
$button.removeClass( 'loading' );
$buttonInner.text( text );
// Hide button
if ( ( page - 1 ) == buttonData.maxPages ) {
$button.hide();
}
// Set loading to false
loading = false;
} ); // End images loaded
} // End success
else {
$buttonInner.text( failedText );
console.log( res );
}
} ).fail( function( xhr, textGridster, e ) {
console.log( xhr.responseText );
} );
} // end loading check
} );
} );
},
/**
* Contact form 7 switch preloader for txt
*
* @since 3.6.0
*/
ctf7Preloader: function() {
// Return if disabled
if ( ! wpexLocalize.altercf7Prealoader ) {
return;
}
// Forms
var $forms = $( 'form.wpcf7-form' );
// Loop through forms
$forms.each( function() {
var $this = $( this );
// Find button
var $button = $this.find( '.wpcf7-submit' );
// Hide loader if button found
if ( $button.length ) {
// Hide preLoader
$this.find( '.ajax-loader' ).remove();
// Add font awesome spinner
var $customLoader = $( '<span class="fa fa-refresh fa-spin wpex-wpcf7-loader"></span>' );
$button.after( $customLoader );
// Show new spinner on Send button click
$button.on( 'click', function() {
$customLoader.addClass( 'visible' );
} );
// Hide new spinner on result
$( 'div.wpcf7' ).on( 'wpcf7:invalid wpcf7:spam wpcf7:mailsent wpcf7:mailfailed', function() {
$customLoader.removeClass( 'visible' );
} );
}
} );
},
/**
* Visual Composer Slider & Accordions
*
* @since 4.2.1
*/
vcTabsTogglesJS: function() {
var self = this;
// Only needed when VC is enabled
if ( ! this.config.$body.hasClass( 'wpb-js-composer' ) ) {
return;
}
function onShow() {
var $this = $( this );
// Sliders
$this.find( '.wpex-slider' ).each( function() {
$( this ).sliderPro( 'update' );
} );
// Grids
$this.find( '.vcex-isotope-grid' ).each( function() {
$( this ).isotope( 'layout' );
} );
// Milestones
$this.find( '.vcex-milestone' ).each( function() {
self.milestone( $( this ) );
} );
}
// Re-trigger/update things when opening VC tabs
$( '.vc_tta-tabs' ).on( 'show.vc.tab', onShow );
// Re-trigger slider on tabs change
$( '.vc_tta-accordion' ).on( 'show.vc.accordion', onShow );
// Tab clicks custom checks - due to issues with show.vc.tab not triggering on click in v5.4.3
// Front-end only (breaks back-end tabs and not needed there apparently)
self.config.$document.on( 'click.vc.tabs.data-api', '[data-vc-tabs]', function( e ) {
if ( self.config.$body.hasClass( 'vc_editor' ) ) {
return;
}
var tab = $( $( this ).attr( 'href' ) );
if ( tab.length ) {
// Sliders
tab.find( '.wpex-slider' ).each( function() {
$( this ).sliderPro( 'update' );
} );
// Grids
tab.find( '.vcex-isotope-grid' ).each( function() {
$( this ).isotope( 'layout' );
} );
}
} );
},
/**
* Visual Composer Accessability fixes
*
* @since 4.5
*/
vcAccessability: function() {
if ( ! this.config.vcActive ) {
return;
}
// Add tab index to toggles and toggle on enter
var $toggles = $( '.vc_toggle .vc_toggle_title' );
$toggles.each( function( index ) {
var $this = $( this );
$this.attr( 'tabindex', 0 );
$this.on( 'keydown', function( e ) {
if ( 13 == e.which ) {
$this.trigger( 'click' );
}
} );
} );
// Tabs
var $tabContainers = $( '.vc_tta-container' );
var tabClick = function( $thisTab, $allTabs, $tabPanels, i ) {
$allTabs.attr( 'tabindex', -1 );
$thisTab.attr( 'tabindex', 0 ).focus().click();
}
$tabContainers.each( function() {
var $tabContainer = $( this ),
$tabs = $tabContainer.find( '.vc_tta-tab > a' ),
$panels = $tabContainer.find( '.vc_tta-panels' );
$tabs.each( function( index ) {
var $tab = $( this );
if ( 0 == index ) {
$tab.attr( 'tabindex', 0 );
} else {
$tab.attr( 'tabindex', -1 );
}
$tab.on( 'keydown', function( e ) {
var $this = $( this ),
keyCode = e.which,
$nextTab = $this.parent().next().is( 'li.vc_tta-tab' ) ? $this.parent().next().find( 'a' ) : false,
$previousTab = $this.parent().prev().is( 'li.vc_tta-tab' ) ? $this.parent().prev().find( 'a' ) : false,
$firstTab = $this.parent().parent().find( 'li.vc_tta-tab:first' ).find( 'a' ),
$lastTab = $this.parent().parent().find( 'li.vc_tta-tab:last' ).find( 'a' );
switch( keyCode ) {
// Left/Up
case 37 :
case 38 :
e.preventDefault();
e.stopPropagation();
if ( ! $previousTab) {
tabClick( $lastTab, $tabs, $panels );
} else {
tabClick( $previousTab, $tabs, $panels );
}
break;
// Right/Down
case 39 :
case 40 :
e.preventDefault();
e.stopPropagation();
if ( ! $nextTab ) {
tabClick( $firstTab, $tabs, $panels );
} else {
tabClick( $nextTab, $tabs, $panels );
}
break;
// Home
case 36 :
e.preventDefault();
e.stopPropagation();
tabClick( $firstTab, $tabs, $panels );
break;
// End
case 35 :
e.preventDefault();
e.stopPropagation();
tabClick( $lastTab, $tabs, $panels );
break;
// Enter/Space
case 13 :
case 32 :
e.preventDefault();
e.stopPropagation();
break;
} // end switch
} );
} );
} );
},
/**
* Removes duplicate VC elements added by Total (overlays, parallax)
*
* @since 4.0
*/
vcexRemoveiFrameDups: function( $context ) {
var $this = $context;
var $module = $this.children( ':first' );
if ( ! $module.length ) {
return;
}
// Overlays
var $overlays = $module.find( '> .wpex-bg-overlay-wrap' );
if ( $module.hasClass( 'wpex-has-overlay' ) ) {
$overlays.not( ':first' ).remove();
} else if ( $overlays.length ) {
$overlays.remove();
}
// Self-hosted Videos
var $videos = $module.find( '> .wpex-video-bg-wrap' );
if ( $module.hasClass( 'wpex-has-video-bg' ) ) {
$videos.not( ':first' ).remove();
} else if ( $videos.length ) {
$videos.remove();
}
// Parallax
var $parallax = $module.find( '> .wpex-parallax-bg' );
if ( $module.hasClass( 'wpex-parallax-bg-wrap' ) ) {
$parallax.not( ':first' ).remove();
} else if ( $parallax.length ) {
$parallax.remove();
}
// Video Backgrounds
// Deprecated? @todo Remove & test
var $videoOverlays = $module.find( '> .wpex-video-bg-overlay' );
if ( $videoOverlays.length ) {
$videoOverlays.not( ':first' ).remove();
}
},
/**
* Visual Composer Updates/Adding
*
* @since 3.6.0
*/
vcPageEditable: function() {
var self = this,
$modelId = '';
// Only needed in composer mode
if ( ! self.config.$body.hasClass( 'compose-mode' ) ) {
return;
}
// Store model ID when events change
parent.vc.events.on( 'shortcodes:add shortcodes:update shortcodes:clone', function( model ) {
$modelId = model.id;
} );
// Re-run functions on each VC reload
self.config.$window.on( 'vc_reload', function() {
self.equalHeights();
self.sliderPro();
self.wpexOwlCarousel();
self.vcexFilterNav();
self.customHovers();
self.responsiveCSS();
if ( $modelId ) {
var $context = $( '[data-model-id=' + $modelId + ']' );
self.isotopeGrids( $context );
self.vcPageEditableFuncs( $context );
self.vcexRemoveiFrameDups( $context );
} else {
self.isotopeGrids();
}
} );
},
/**
* Visual Composer Trigger JS
*
* @since 3.6.0
*/
vcPageEditableFuncs: function( $context ) {
// Globals in context
this.parallax( $context );
this.responsiveText( $context );
this.overlayHovers( $context );
this.iLightbox( $context );
// Module dependent
if ( $context.hasClass( 'vc_vcex_skillbar' ) ) {
this.skillbar( $context );
return;
}
if ( $context.hasClass( 'vc_vc_wp_custommenu' ) ) {
this.menuWidgetAccordion( $context );
return;
}
if ( $context.hasClass( 'vc_vcex_form_shortcode' ) ) {
this.customSelects( $context );
return;
}
if ( $context.hasClass( 'vc_vcex_milestone' ) ) {
this.milestone( $context );
return;
}
if ( $context.hasClass( 'vc_vcex_image_ba' ) ) {
this.twentytwenty( $context );
return;
}
if ( $context.hasClass( 'vc_vcex_animated_text' ) ) {
this.typedText( $context );
return;
}
if ( $context.hasClass( 'vc_vcex_countdown' ) ) {
this.countdown( $context );
return;
}
},
/**
* WooCommerce Gallery functions
*
* @since 4.1
*/
wooGallery: function() {
if ( typeof wc_single_product_params === 'undefined' || ! wc_single_product_params.flexslider.directionNav ) {
return;
}
var self = this;
var $wooGallery = $( '.woocommerce-product-gallery--with-images' );
if ( ! $wooGallery.length ) {
return;
}
function setWooSliderArrows() {
$wooGallery.each( function() {
var $this = $( this );
var $nav = $( this ).find( '.flex-direction-nav' );
var $thumbsNav = $( this ).find( '.flex-control-thumbs' );
if ( $nav.length && $thumbsNav.length ) {
var thumbsNavHeight = $thumbsNav.outerHeight();
var arrowHeight = $nav.find( 'a' ).outerHeight();
var arrowTopoffset = - ( thumbsNavHeight + arrowHeight ) / 2;
if ( arrowTopoffset ) {
$this.find( '.flex-direction-nav a' ).css( 'margin-top', arrowTopoffset );
}
}
} );
}
self.config.$window.on( 'load', function() {
setWooSliderArrows();
} );
self.config.$window.resize( function() {
if ( self.config.widthChanged || self.config.heightChanged ) {
setWooSliderArrows();
}
} );
},
/**
* Parses data to check if a value is defined in the data attribute and if not returns the fallback
*
* @since 2.0.0
*/
parseData: function( val, fallback ) {
return ( typeof val !== 'undefined' ) ? val : fallback;
},
/**
* Returns extension from URL
*/
getUrlExtension: function( url ) {
var ext = url.split( '.' ).pop().toLowerCase();
var extra = ext.indexOf( '?' ) !== -1 ? ext.split( '?' ).pop() : '';
ext = ext.replace( extra, '' );
return ext.replace( '?', '' );
},
/**
* Check if window has scrolled to bottom of element
*/
scrolledToBottom: function( elem ) {
return this.config.windowTop >= elem.offset().top + elem.outerHeight() - window.innerHeight;
},
/**
* Check if an element is currently in the window view
*/
isElementInWindowView: function( elem ) {
var docViewTop = this.config.$window.scrollTop();
var docViewBottom = docViewTop + this.config.windowHeight;
var elemTop = $(elem).offset().top;
var elemBottom = elemTop + $(elem).height();
return ( ( elemBottom <= docViewBottom) && (elemTop >= docViewTop ) );
},
/**
* Return tallest element
*/
getTallestEl: function( el ) {
var tallest;
var first = 1;
el.each( function() {
var $this = $( this );
if ( first == 1 ) {
tallest = $this;
first = 0;
} else {
if ( tallest.height() < $this.height()) {
tallest = $this;
}
}
} );
return tallest;
}
}; // END totalTheme
// Start things up
wpex.init();
} ) ( jQuery );
/*!
* Isotope PACKAGED v2.2.2
*
* Licensed GPLv3 for open source use
* or Isotope Commercial License for commercial use
*
* http://isotope.metafizzy.co
* Copyright 2015 Metafizzy
*/
/**
* Bridget makes jQuery widgets
* v1.1.0
* MIT license
*/
( function( window ) {
// -------------------------- utils -------------------------- //
var slice = Array.prototype.slice;
function noop() {}
// -------------------------- definition -------------------------- //
function defineBridget( $ ) {
// bail if no jQuery
if ( !$ ) {
return;
}
// -------------------------- addOptionMethod -------------------------- //
/**
* adds option method -> $().plugin('option', {...})
* @param {Function} PluginClass - constructor class
*/
function addOptionMethod( PluginClass ) {
// don't overwrite original option method
if ( PluginClass.prototype.option ) {
return;
}
// option setter
PluginClass.prototype.option = function( opts ) {
// bail out if not an object
if ( !$.isPlainObject( opts ) ){
return;
}
this.options = $.extend( true, this.options, opts );
};
}
// -------------------------- plugin bridge -------------------------- //
// helper function for logging errors
// $.error breaks jQuery chaining
var logError = typeof console === 'undefined' ? noop :
function( message ) {
console.error( message );
};
/**
* jQuery plugin bridge, access methods like $elem.plugin('method')
* @param {String} namespace - plugin name
* @param {Function} PluginClass - constructor class
*/
function bridge( namespace, PluginClass ) {
// add to jQuery fn namespace
$.fn[ namespace ] = function( options ) {
if ( typeof options === 'string' ) {
// call plugin method when first argument is a string
// get arguments for method
var args = slice.call( arguments, 1 );
for ( var i=0, len = this.length; i < len; i++ ) {
var elem = this[i];
var instance = $.data( elem, namespace );
if ( !instance ) {
logError( "cannot call methods on " + namespace + " prior to initialization; " +
"attempted to call '" + options + "'" );
continue;
}
if ( !$.isFunction( instance[options] ) || options.charAt(0) === '_' ) {
logError( "no such method '" + options + "' for " + namespace + " instance" );
continue;
}
// trigger method with arguments
var returnValue = instance[ options ].apply( instance, args );
// break look and return first value if provided
if ( returnValue !== undefined ) {
return returnValue;
}
}
// return this if no return value
return this;
} else {
return this.each( function() {
var instance = $.data( this, namespace );
if ( instance ) {
// apply options & init
instance.option( options );
instance._init();
} else {
// initialize new instance
instance = new PluginClass( this, options );
$.data( this, namespace, instance );
}
});
}
};
}
// -------------------------- bridget -------------------------- //
/**
* converts a Prototypical class into a proper jQuery plugin
* the class must have a ._init method
* @param {String} namespace - plugin name, used in $().pluginName
* @param {Function} PluginClass - constructor class
*/
$.bridget = function( namespace, PluginClass ) {
addOptionMethod( PluginClass );
bridge( namespace, PluginClass );
};
return $.bridget;
}
// transport
if ( typeof define === 'function' && define.amd ) {
// AMD
define( 'jquery-bridget/jquery.bridget',[ 'jquery' ], defineBridget );
} else if ( typeof exports === 'object' ) {
defineBridget( require('jquery') );
} else {
// get jquery from browser global
defineBridget( window.jQuery );
}
})( window );
/*!
* eventie v1.0.6
* event binding helper
* eventie.bind( elem, 'click', myFn )
* eventie.unbind( elem, 'click', myFn )
* MIT license
*/
/*jshint browser: true, undef: true, unused: true */
/*global define: false, module: false */
( function( window ) {
var docElem = document.documentElement;
var bind = function() {};
function getIEEvent( obj ) {
var event = window.event;
// add event.target
event.target = event.target || event.srcElement || obj;
return event;
}
if ( docElem.addEventListener ) {
bind = function( obj, type, fn ) {
obj.addEventListener( type, fn, false );
};
} else if ( docElem.attachEvent ) {
bind = function( obj, type, fn ) {
obj[ type + fn ] = fn.handleEvent ?
function() {
var event = getIEEvent( obj );
fn.handleEvent.call( fn, event );
} :
function() {
var event = getIEEvent( obj );
fn.call( obj, event );
};
obj.attachEvent( "on" + type, obj[ type + fn ] );
};
}
var unbind = function() {};
if ( docElem.removeEventListener ) {
unbind = function( obj, type, fn ) {
obj.removeEventListener( type, fn, false );
};
} else if ( docElem.detachEvent ) {
unbind = function( obj, type, fn ) {
obj.detachEvent( "on" + type, obj[ type + fn ] );
try {
delete obj[ type + fn ];
} catch ( err ) {
// can't delete window object properties
obj[ type + fn ] = undefined;
}
};
}
var eventie = {
bind: bind,
unbind: unbind
};
// ----- module definition ----- //
if ( typeof define === 'function' && define.amd ) {
// AMD
define( 'eventie/eventie',eventie );
} else if ( typeof exports === 'object' ) {
// CommonJS
module.exports = eventie;
} else {
// browser global
window.eventie = eventie;
}
})( window );
/*!
* EventEmitter v4.2.11 - git.io/ee
* Unlicense - http://unlicense.org/
* Oliver Caldwell - http://oli.me.uk/
* @preserve
*/
;(function () {
'use strict';
/**
* Class for managing events.
* Can be extended to provide event functionality in other classes.
*
* @class EventEmitter Manages event registering and emitting.
*/
function EventEmitter() {}
// Shortcuts to improve speed and size
var proto = EventEmitter.prototype;
var exports = this;
var originalGlobalValue = exports.EventEmitter;
/**
* Finds the index of the listener for the event in its storage array.
*
* @param {Function[]} listeners Array of listeners to search through.
* @param {Function} listener Method to look for.
* @return {Number} Index of the specified listener, -1 if not found
* @api private
*/
function indexOfListener(listeners, listener) {
var i = listeners.length;
while (i--) {
if (listeners[i].listener === listener) {
return i;
}
}
return -1;
}
/**
* Alias a method while keeping the context correct, to allow for overwriting of target method.
*
* @param {String} name The name of the target method.
* @return {Function} The aliased method
* @api private
*/
function alias(name) {
return function aliasClosure() {
return this[name].apply(this, arguments);
};
}
/**
* Returns the listener array for the specified event.
* Will initialise the event object and listener arrays if required.
* Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.
* Each property in the object response is an array of listener functions.
*
* @param {String|RegExp} evt Name of the event to return the listeners from.
* @return {Function[]|Object} All listener functions for the event.
*/
proto.getListeners = function getListeners(evt) {
var events = this._getEvents();
var response;
var key;
// Return a concatenated array of all matching events if
// the selector is a regular expression.
if (evt instanceof RegExp) {
response = {};
for (key in events) {
if (events.hasOwnProperty(key) && evt.test(key)) {
response[key] = events[key];
}
}
}
else {
response = events[evt] || (events[evt] = []);
}
return response;
};
/**
* Takes a list of listener objects and flattens it into a list of listener functions.
*
* @param {Object[]} listeners Raw listener objects.
* @return {Function[]} Just the listener functions.
*/
proto.flattenListeners = function flattenListeners(listeners) {
var flatListeners = [];
var i;
for (i = 0; i < listeners.length; i += 1) {
flatListeners.push(listeners[i].listener);
}
return flatListeners;
};
/**
* Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.
*
* @param {String|RegExp} evt Name of the event to return the listeners from.
* @return {Object} All listener functions for an event in an object.
*/
proto.getListenersAsObject = function getListenersAsObject(evt) {
var listeners = this.getListeners(evt);
var response;
if (listeners instanceof Array) {
response = {};
response[evt] = listeners;
}
return response || listeners;
};
/**
* Adds a listener function to the specified event.
* The listener will not be added if it is a duplicate.
* If the listener returns true then it will be removed after it is called.
* If you pass a regular expression as the event name then the listener will be added to all events that match it.
*
* @param {String|RegExp} evt Name of the event to attach the listener to.
* @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.addListener = function addListener(evt, listener) {
var listeners = this.getListenersAsObject(evt);
var listenerIsWrapped = typeof listener === 'object';
var key;
for (key in listeners) {
if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {
listeners[key].push(listenerIsWrapped ? listener : {
listener: listener,
once: false
});
}
}
return this;
};
/**
* Alias of addListener
*/
proto.on = alias('addListener');
/**
* Semi-alias of addListener. It will add a listener that will be
* automatically removed after its first execution.
*
* @param {String|RegExp} evt Name of the event to attach the listener to.
* @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.addOnceListener = function addOnceListener(evt, listener) {
return this.addListener(evt, {
listener: listener,
once: true
});
};
/**
* Alias of addOnceListener.
*/
proto.once = alias('addOnceListener');
/**
* Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.
* You need to tell it what event names should be matched by a regex.
*
* @param {String} evt Name of the event to create.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.defineEvent = function defineEvent(evt) {
this.getListeners(evt);
return this;
};
/**
* Uses defineEvent to define multiple events.
*
* @param {String[]} evts An array of event names to define.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.defineEvents = function defineEvents(evts) {
for (var i = 0; i < evts.length; i += 1) {
this.defineEvent(evts[i]);
}
return this;
};
/**
* Removes a listener function from the specified event.
* When passed a regular expression as the event name, it will remove the listener from all events that match it.
*
* @param {String|RegExp} evt Name of the event to remove the listener from.
* @param {Function} listener Method to remove from the event.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.removeListener = function removeListener(evt, listener) {
var listeners = this.getListenersAsObject(evt);
var index;
var key;
for (key in listeners) {
if (listeners.hasOwnProperty(key)) {
index = indexOfListener(listeners[key], listener);
if (index !== -1) {
listeners[key].splice(index, 1);
}
}
}
return this;
};
/**
* Alias of removeListener
*/
proto.off = alias('removeListener');
/**
* Adds listeners in bulk using the manipulateListeners method.
* If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.
* You can also pass it a regular expression to add the array of listeners to all events that match it.
* Yeah, this function does quite a bit. That's probably a bad thing.
*
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.
* @param {Function[]} [listeners] An optional array of listener functions to add.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.addListeners = function addListeners(evt, listeners) {
// Pass through to manipulateListeners
return this.manipulateListeners(false, evt, listeners);
};
/**
* Removes listeners in bulk using the manipulateListeners method.
* If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
* You can also pass it an event name and an array of listeners to be removed.
* You can also pass it a regular expression to remove the listeners from all events that match it.
*
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.
* @param {Function[]} [listeners] An optional array of listener functions to remove.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.removeListeners = function removeListeners(evt, listeners) {
// Pass through to manipulateListeners
return this.manipulateListeners(true, evt, listeners);
};
/**
* Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.
* The first argument will determine if the listeners are removed (true) or added (false).
* If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
* You can also pass it an event name and an array of listeners to be added/removed.
* You can also pass it a regular expression to manipulate the listeners of all events that match it.
*
* @param {Boolean} remove True if you want to remove listeners, false if you want to add.
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.
* @param {Function[]} [listeners] An optional array of listener functions to add/remove.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {
var i;
var value;
var single = remove ? this.removeListener : this.addListener;
var multiple = remove ? this.removeListeners : this.addListeners;
// If evt is an object then pass each of its properties to this method
if (typeof evt === 'object' && !(evt instanceof RegExp)) {
for (i in evt) {
if (evt.hasOwnProperty(i) && (value = evt[i])) {
// Pass the single listener straight through to the singular method
if (typeof value === 'function') {
single.call(this, i, value);
}
else {
// Otherwise pass back to the multiple function
multiple.call(this, i, value);
}
}
}
}
else {
// So evt must be a string
// And listeners must be an array of listeners
// Loop over it and pass each one to the multiple method
i = listeners.length;
while (i--) {
single.call(this, evt, listeners[i]);
}
}
return this;
};
/**
* Removes all listeners from a specified event.
* If you do not specify an event then all listeners will be removed.
* That means every event will be emptied.
* You can also pass a regex to remove all events that match it.
*
* @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.removeEvent = function removeEvent(evt) {
var type = typeof evt;
var events = this._getEvents();
var key;
// Remove different things depending on the state of evt
if (type === 'string') {
// Remove all listeners for the specified event
delete events[evt];
}
else if (evt instanceof RegExp) {
// Remove all events matching the regex.
for (key in events) {
if (events.hasOwnProperty(key) && evt.test(key)) {
delete events[key];
}
}
}
else {
// Remove all listeners in all events
delete this._events;
}
return this;
};
/**
* Alias of removeEvent.
*
* Added to mirror the node API.
*/
proto.removeAllListeners = alias('removeEvent');
/**
* Emits an event of your choice.
* When emitted, every listener attached to that event will be executed.
* If you pass the optional argument array then those arguments will be passed to every listener upon execution.
* Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.
* So they will not arrive within the array on the other side, they will be separate.
* You can also pass a regular expression to emit to all events that match it.
*
* @param {String|RegExp} evt Name of the event to emit and execute listeners for.
* @param {Array} [args] Optional array of arguments to be passed to each listener.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.emitEvent = function emitEvent(evt, args) {
var listeners = this.getListenersAsObject(evt);
var listener;
var i;
var key;
var response;
for (key in listeners) {
if (listeners.hasOwnProperty(key)) {
i = listeners[key].length;
while (i--) {
// If the listener returns true then it shall be removed from the event
// The function is executed either with a basic call or an apply if there is an args array
listener = listeners[key][i];
if (listener.once === true) {
this.removeListener(evt, listener.listener);
}
response = listener.listener.apply(this, args || []);
if (response === this._getOnceReturnValue()) {
this.removeListener(evt, listener.listener);
}
}
}
}
return this;
};
/**
* Alias of emitEvent
*/
proto.trigger = alias('emitEvent');
/**
* Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.
* As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.
*
* @param {String|RegExp} evt Name of the event to emit and execute listeners for.
* @param {...*} Optional additional arguments to be passed to each listener.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.emit = function emit(evt) {
var args = Array.prototype.slice.call(arguments, 1);
return this.emitEvent(evt, args);
};
/**
* Sets the current value to check against when executing listeners. If a
* listeners return value matches the one set here then it will be removed
* after execution. This value defaults to true.
*
* @param {*} value The new value to check for when executing listeners.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.setOnceReturnValue = function setOnceReturnValue(value) {
this._onceReturnValue = value;
return this;
};
/**
* Fetches the current value to check against when executing listeners. If
* the listeners return value matches this one then it should be removed
* automatically. It will return true by default.
*
* @return {*|Boolean} The current value to check for or the default, true.
* @api private
*/
proto._getOnceReturnValue = function _getOnceReturnValue() {
if (this.hasOwnProperty('_onceReturnValue')) {
return this._onceReturnValue;
}
else {
return true;
}
};
/**
* Fetches the events object and creates one if required.
*
* @return {Object} The events storage object.
* @api private
*/
proto._getEvents = function _getEvents() {
return this._events || (this._events = {});
};
/**
* Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version.
*
* @return {Function} Non conflicting EventEmitter class.
*/
EventEmitter.noConflict = function noConflict() {
exports.EventEmitter = originalGlobalValue;
return EventEmitter;
};
// Expose the class either via AMD, CommonJS or the global object
if (typeof define === 'function' && define.amd) {
define('eventEmitter/EventEmitter',[],function () {
return EventEmitter;
});
}
else if (typeof module === 'object' && module.exports){
module.exports = EventEmitter;
}
else {
exports.EventEmitter = EventEmitter;
}
}.call(this));
/*!
* getStyleProperty v1.0.4
* original by kangax
* http://perfectionkills.com/feature-testing-css-properties/
* MIT license
*/
/*jshint browser: true, strict: true, undef: true */
/*global define: false, exports: false, module: false */
( function( window ) {
var prefixes = 'Webkit Moz ms Ms O'.split(' ');
var docElemStyle = document.documentElement.style;
function getStyleProperty( propName ) {
if ( !propName ) {
return;
}
// test standard property first
if ( typeof docElemStyle[ propName ] === 'string' ) {
return propName;
}
// capitalize
propName = propName.charAt(0).toUpperCase() + propName.slice(1);
// test vendor specific properties
var prefixed;
for ( var i=0, len = prefixes.length; i < len; i++ ) {
prefixed = prefixes[i] + propName;
if ( typeof docElemStyle[ prefixed ] === 'string' ) {
return prefixed;
}
}
}
// transport
if ( typeof define === 'function' && define.amd ) {
// AMD
define( 'get-style-property/get-style-property',[],function() {
return getStyleProperty;
});
} else if ( typeof exports === 'object' ) {
// CommonJS for Component
module.exports = getStyleProperty;
} else {
// browser global
window.getStyleProperty = getStyleProperty;
}
})( window );
/*!
* getSize v1.2.2
* measure size of elements
* MIT license
*/
/*jshint browser: true, strict: true, undef: true, unused: true */
/*global define: false, exports: false, require: false, module: false, console: false */
( function( window, undefined ) {
// -------------------------- helpers -------------------------- //
// get a number from a string, not a percentage
function getStyleSize( value ) {
var num = parseFloat( value );
// not a percent like '100%', and a number
var isValid = value.indexOf('%') === -1 && !isNaN( num );
return isValid && num;
}
function noop() {}
var logError = typeof console === 'undefined' ? noop :
function( message ) {
console.error( message );
};
// -------------------------- measurements -------------------------- //
var measurements = [
'paddingLeft',
'paddingRight',
'paddingTop',
'paddingBottom',
'marginLeft',
'marginRight',
'marginTop',
'marginBottom',
'borderLeftWidth',
'borderRightWidth',
'borderTopWidth',
'borderBottomWidth'
];
function getZeroSize() {
var size = {
width: 0,
height: 0,
innerWidth: 0,
innerHeight: 0,
outerWidth: 0,
outerHeight: 0
};
for ( var i=0, len = measurements.length; i < len; i++ ) {
var measurement = measurements[i];
size[ measurement ] = 0;
}
return size;
}
function defineGetSize( getStyleProperty ) {
// -------------------------- setup -------------------------- //
var isSetup = false;
var getStyle, boxSizingProp, isBoxSizeOuter;
/**
* setup vars and functions
* do it on initial getSize(), rather than on script load
* For Firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=548397
*/
function setup() {
// setup once
if ( isSetup ) {
return;
}
isSetup = true;
var getComputedStyle = window.getComputedStyle;
getStyle = ( function() {
var getStyleFn = getComputedStyle ?
function( elem ) {
return getComputedStyle( elem, null );
} :
function( elem ) {
return elem.currentStyle;
};
return function getStyle( elem ) {
var style = getStyleFn( elem );
if ( !style ) {
logError( 'Style returned ' + style +
'. Are you running this code in a hidden iframe on Firefox? ' +
'See http://bit.ly/getsizebug1' );
}
return style;
};
})();
// -------------------------- box sizing -------------------------- //
boxSizingProp = getStyleProperty('boxSizing');
/**
* WebKit measures the outer-width on style.width on border-box elems
* IE & Firefox measures the inner-width
*/
if ( boxSizingProp ) {
var div = document.createElement('div');
div.style.width = '200px';
div.style.padding = '1px 2px 3px 4px';
div.style.borderStyle = 'solid';
div.style.borderWidth = '1px 2px 3px 4px';
div.style[ boxSizingProp ] = 'border-box';
var body = document.body || document.documentElement;
body.appendChild( div );
var style = getStyle( div );
isBoxSizeOuter = getStyleSize( style.width ) === 200;
body.removeChild( div );
}
}
// -------------------------- getSize -------------------------- //
function getSize( elem ) {
setup();
// use querySeletor if elem is string
if ( typeof elem === 'string' ) {
elem = document.querySelector( elem );
}
// do not proceed on non-objects
if ( !elem || typeof elem !== 'object' || !elem.nodeType ) {
return;
}
var style = getStyle( elem );
// if hidden, everything is 0
if ( style.display === 'none' ) {
return getZeroSize();
}
var size = {};
size.width = elem.offsetWidth;
size.height = elem.offsetHeight;
var isBorderBox = size.isBorderBox = !!( boxSizingProp &&
style[ boxSizingProp ] && style[ boxSizingProp ] === 'border-box' );
// get all measurements
for ( var i=0, len = measurements.length; i < len; i++ ) {
var measurement = measurements[i];
var value = style[ measurement ];
value = mungeNonPixel( elem, value );
var num = parseFloat( value );
// any 'auto', 'medium' value will be 0
size[ measurement ] = !isNaN( num ) ? num : 0;
}
var paddingWidth = size.paddingLeft + size.paddingRight;
var paddingHeight = size.paddingTop + size.paddingBottom;
var marginWidth = size.marginLeft + size.marginRight;
var marginHeight = size.marginTop + size.marginBottom;
var borderWidth = size.borderLeftWidth + size.borderRightWidth;
var borderHeight = size.borderTopWidth + size.borderBottomWidth;
var isBorderBoxSizeOuter = isBorderBox && isBoxSizeOuter;
// overwrite width and height if we can get it from style
var styleWidth = getStyleSize( style.width );
if ( styleWidth !== false ) {
size.width = styleWidth +
// add padding and border unless it's already including it
( isBorderBoxSizeOuter ? 0 : paddingWidth + borderWidth );
}
var styleHeight = getStyleSize( style.height );
if ( styleHeight !== false ) {
size.height = styleHeight +
// add padding and border unless it's already including it
( isBorderBoxSizeOuter ? 0 : paddingHeight + borderHeight );
}
size.innerWidth = size.width - ( paddingWidth + borderWidth );
size.innerHeight = size.height - ( paddingHeight + borderHeight );
size.outerWidth = size.width + marginWidth;
size.outerHeight = size.height + marginHeight;
return size;
}
// IE8 returns percent values, not pixels
// taken from jQuery's curCSS
function mungeNonPixel( elem, value ) {
// IE8 and has percent value
if ( window.getComputedStyle || value.indexOf('%') === -1 ) {
return value;
}
var style = elem.style;
// Remember the original values
var left = style.left;
var rs = elem.runtimeStyle;
var rsLeft = rs && rs.left;
// Put in the new values to get a computed value out
if ( rsLeft ) {
rs.left = elem.currentStyle.left;
}
style.left = value;
value = style.pixelLeft;
// Revert the changed values
style.left = left;
if ( rsLeft ) {
rs.left = rsLeft;
}
return value;
}
return getSize;
}
// transport
if ( typeof define === 'function' && define.amd ) {
// AMD for RequireJS
define( 'get-size/get-size',[ 'get-style-property/get-style-property' ], defineGetSize );
} else if ( typeof exports === 'object' ) {
// CommonJS for Component
module.exports = defineGetSize( require('desandro-get-style-property') );
} else {
// browser global
window.getSize = defineGetSize( window.getStyleProperty );
}
})( window );
/*!
* docReady v1.0.4
* Cross browser DOMContentLoaded event emitter
* MIT license
*/
/*jshint browser: true, strict: true, undef: true, unused: true*/
/*global define: false, require: false, module: false */
( function( window ) {
var document = window.document;
// collection of functions to be triggered on ready
var queue = [];
function docReady( fn ) {
// throw out non-functions
if ( typeof fn !== 'function' ) {
return;
}
if ( docReady.isReady ) {
// ready now, hit it
fn();
} else {
// queue function when ready
queue.push( fn );
}
}
docReady.isReady = false;
// triggered on various doc ready events
function onReady( event ) {
// bail if already triggered or IE8 document is not ready just yet
var isIE8NotReady = event.type === 'readystatechange' && document.readyState !== 'complete';
if ( docReady.isReady || isIE8NotReady ) {
return;
}
trigger();
}
function trigger() {
docReady.isReady = true;
// process queue
for ( var i=0, len = queue.length; i < len; i++ ) {
var fn = queue[i];
fn();
}
}
function defineDocReady( eventie ) {
// trigger ready if page is ready
if ( document.readyState === 'complete' ) {
trigger();
} else {
// listen for events
eventie.bind( document, 'DOMContentLoaded', onReady );
eventie.bind( document, 'readystatechange', onReady );
eventie.bind( window, 'load', onReady );
}
return docReady;
}
// transport
if ( typeof define === 'function' && define.amd ) {
// AMD
define( 'doc-ready/doc-ready',[ 'eventie/eventie' ], defineDocReady );
} else if ( typeof exports === 'object' ) {
module.exports = defineDocReady( require('eventie') );
} else {
// browser global
window.docReady = defineDocReady( window.eventie );
}
})( window );
/**
* matchesSelector v1.0.3
* matchesSelector( element, '.selector' )
* MIT license
*/
/*jshint browser: true, strict: true, undef: true, unused: true */
/*global define: false, module: false */
( function( ElemProto ) {
'use strict';
var matchesMethod = ( function() {
// check for the standard method name first
if ( ElemProto.matches ) {
return 'matches';
}
// check un-prefixed
if ( ElemProto.matchesSelector ) {
return 'matchesSelector';
}
// check vendor prefixes
var prefixes = [ 'webkit', 'moz', 'ms', 'o' ];
for ( var i=0, len = prefixes.length; i < len; i++ ) {
var prefix = prefixes[i];
var method = prefix + 'MatchesSelector';
if ( ElemProto[ method ] ) {
return method;
}
}
})();
// ----- match ----- //
function match( elem, selector ) {
return elem[ matchesMethod ]( selector );
}
// ----- appendToFragment ----- //
function checkParent( elem ) {
// not needed if already has parent
if ( elem.parentNode ) {
return;
}
var fragment = document.createDocumentFragment();
fragment.appendChild( elem );
}
// ----- query ----- //
// fall back to using QSA
// thx @jonathantneal https://gist.github.com/3062955
function query( elem, selector ) {
// append to fragment if no parent
checkParent( elem );
// match elem with all selected elems of parent
var elems = elem.parentNode.querySelectorAll( selector );
for ( var i=0, len = elems.length; i < len; i++ ) {
// return true if match
if ( elems[i] === elem ) {
return true;
}
}
// otherwise return false
return false;
}
// ----- matchChild ----- //
function matchChild( elem, selector ) {
checkParent( elem );
return match( elem, selector );
}
// ----- matchesSelector ----- //
var matchesSelector;
if ( matchesMethod ) {
// IE9 supports matchesSelector, but doesn't work on orphaned elems
// check for that
var div = document.createElement('div');
var supportsOrphans = match( div, 'div' );
matchesSelector = supportsOrphans ? match : matchChild;
} else {
matchesSelector = query;
}
// transport
if ( typeof define === 'function' && define.amd ) {
// AMD
define( 'matches-selector/matches-selector',[],function() {
return matchesSelector;
});
} else if ( typeof exports === 'object' ) {
module.exports = matchesSelector;
}
else {
// browser global
window.matchesSelector = matchesSelector;
}
})( Element.prototype );
/**
* Fizzy UI utils v1.0.1
* MIT license
*/
/*jshint browser: true, undef: true, unused: true, strict: true */
( function( window, factory ) {
/*global define: false, module: false, require: false */
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'fizzy-ui-utils/utils',[
'doc-ready/doc-ready',
'matches-selector/matches-selector'
], function( docReady, matchesSelector ) {
return factory( window, docReady, matchesSelector );
});
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
window,
require('doc-ready'),
require('desandro-matches-selector')
);
} else {
// browser global
window.fizzyUIUtils = factory(
window,
window.docReady,
window.matchesSelector
);
}
}( window, function factory( window, docReady, matchesSelector ) {
var utils = {};
// ----- extend ----- //
// extends objects
utils.extend = function( a, b ) {
for ( var prop in b ) {
a[ prop ] = b[ prop ];
}
return a;
};
// ----- modulo ----- //
utils.modulo = function( num, div ) {
return ( ( num % div ) + div ) % div;
};
// ----- isArray ----- //
var objToString = Object.prototype.toString;
utils.isArray = function( obj ) {
return objToString.call( obj ) == '[object Array]';
};
// ----- makeArray ----- //
// turn element or nodeList into an array
utils.makeArray = function( obj ) {
var ary = [];
if ( utils.isArray( obj ) ) {
// use object if already an array
ary = obj;
} else if ( obj && typeof obj.length == 'number' ) {
// convert nodeList to array
for ( var i=0, len = obj.length; i < len; i++ ) {
ary.push( obj[i] );
}
} else {
// array of single index
ary.push( obj );
}
return ary;
};
// ----- indexOf ----- //
// index of helper cause IE8
utils.indexOf = Array.prototype.indexOf ? function( ary, obj ) {
return ary.indexOf( obj );
} : function( ary, obj ) {
for ( var i=0, len = ary.length; i < len; i++ ) {
if ( ary[i] === obj ) {
return i;
}
}
return -1;
};
// ----- removeFrom ----- //
utils.removeFrom = function( ary, obj ) {
var index = utils.indexOf( ary, obj );
if ( index != -1 ) {
ary.splice( index, 1 );
}
};
// ----- isElement ----- //
// http://stackoverflow.com/a/384380/182183
utils.isElement = ( typeof HTMLElement == 'function' || typeof HTMLElement == 'object' ) ?
function isElementDOM2( obj ) {
return obj instanceof HTMLElement;
} :
function isElementQuirky( obj ) {
return obj && typeof obj == 'object' &&
obj.nodeType == 1 && typeof obj.nodeName == 'string';
};
// ----- setText ----- //
utils.setText = ( function() {
var setTextProperty;
function setText( elem, text ) {
// only check setTextProperty once
setTextProperty = setTextProperty || ( document.documentElement.textContent !== undefined ? 'textContent' : 'innerText' );
elem[ setTextProperty ] = text;
}
return setText;
})();
// ----- getParent ----- //
utils.getParent = function( elem, selector ) {
while ( elem != document.body ) {
elem = elem.parentNode;
if ( matchesSelector( elem, selector ) ) {
return elem;
}
}
};
// ----- getQueryElement ----- //
// use element as selector string
utils.getQueryElement = function( elem ) {
if ( typeof elem == 'string' ) {
return document.querySelector( elem );
}
return elem;
};
// ----- handleEvent ----- //
// enable .ontype to trigger from .addEventListener( elem, 'type' )
utils.handleEvent = function( event ) {
var method = 'on' + event.type;
if ( this[ method ] ) {
this[ method ]( event );
}
};
// ----- filterFindElements ----- //
utils.filterFindElements = function( elems, selector ) {
// make array of elems
elems = utils.makeArray( elems );
var ffElems = [];
for ( var i=0, len = elems.length; i < len; i++ ) {
var elem = elems[i];
// check that elem is an actual element
if ( !utils.isElement( elem ) ) {
continue;
}
// filter & find items if we have a selector
if ( selector ) {
// filter siblings
if ( matchesSelector( elem, selector ) ) {
ffElems.push( elem );
}
// find children
var childElems = elem.querySelectorAll( selector );
// concat childElems to filterFound array
for ( var j=0, jLen = childElems.length; j < jLen; j++ ) {
ffElems.push( childElems[j] );
}
} else {
ffElems.push( elem );
}
}
return ffElems;
};
// ----- debounceMethod ----- //
utils.debounceMethod = function( _class, methodName, threshold ) {
// original method
var method = _class.prototype[ methodName ];
var timeoutName = methodName + 'Timeout';
_class.prototype[ methodName ] = function() {
var timeout = this[ timeoutName ];
if ( timeout ) {
clearTimeout( timeout );
}
var args = arguments;
var _this = this;
this[ timeoutName ] = setTimeout( function() {
method.apply( _this, args );
delete _this[ timeoutName ];
}, threshold || 100 );
};
};
// ----- htmlInit ----- //
// http://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/
utils.toDashed = function( str ) {
return str.replace( /(.)([A-Z])/g, function( match, $1, $2 ) {
return $1 + '-' + $2;
}).toLowerCase();
};
var console = window.console;
/**
* allow user to initialize classes via .js-namespace class
* htmlInit( Widget, 'widgetName' )
* options are parsed from data-namespace-option attribute
*/
utils.htmlInit = function( WidgetClass, namespace ) {
docReady( function() {
var dashedNamespace = utils.toDashed( namespace );
var elems = document.querySelectorAll( '.js-' + dashedNamespace );
var dataAttr = 'data-' + dashedNamespace + '-options';
for ( var i=0, len = elems.length; i < len; i++ ) {
var elem = elems[i];
var attr = elem.getAttribute( dataAttr );
var options;
try {
options = attr && JSON.parse( attr );
} catch ( error ) {
// log error, do not initialize
if ( console ) {
console.error( 'Error parsing ' + dataAttr + ' on ' +
elem.nodeName.toLowerCase() + ( elem.id ? '#' + elem.id : '' ) + ': ' +
error );
}
continue;
}
// initialize
var instance = new WidgetClass( elem, options );
// make available via $().data('layoutname')
var jQuery = window.jQuery;
if ( jQuery ) {
jQuery.data( elem, namespace, instance );
}
}
});
};
// ----- ----- //
return utils;
}));
/**
* Outlayer Item
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define === 'function' && define.amd ) {
// AMD
define( 'outlayer/item',[
'eventEmitter/EventEmitter',
'get-size/get-size',
'get-style-property/get-style-property',
'fizzy-ui-utils/utils'
],
function( EventEmitter, getSize, getStyleProperty, utils ) {
return factory( window, EventEmitter, getSize, getStyleProperty, utils );
}
);
} else if (typeof exports === 'object') {
// CommonJS
module.exports = factory(
window,
require('wolfy87-eventemitter'),
require('get-size'),
require('desandro-get-style-property'),
require('fizzy-ui-utils')
);
} else {
// browser global
window.Outlayer = {};
window.Outlayer.Item = factory(
window,
window.EventEmitter,
window.getSize,
window.getStyleProperty,
window.fizzyUIUtils
);
}
}( window, function factory( window, EventEmitter, getSize, getStyleProperty, utils ) {
'use strict';
// ----- helpers ----- //
var getComputedStyle = window.getComputedStyle;
var getStyle = getComputedStyle ?
function( elem ) {
return getComputedStyle( elem, null );
} :
function( elem ) {
return elem.currentStyle;
};
function isEmptyObj( obj ) {
for ( var prop in obj ) {
return false;
}
prop = null;
return true;
}
// -------------------------- CSS3 support -------------------------- //
var transitionProperty = getStyleProperty('transition');
var transformProperty = getStyleProperty('transform');
var supportsCSS3 = transitionProperty && transformProperty;
var is3d = !!getStyleProperty('perspective');
var transitionEndEvent = {
WebkitTransition: 'webkitTransitionEnd',
MozTransition: 'transitionend',
OTransition: 'otransitionend',
transition: 'transitionend'
}[ transitionProperty ];
// properties that could have vendor prefix
var prefixableProperties = [
'transform',
'transition',
'transitionDuration',
'transitionProperty'
];
// cache all vendor properties
var vendorProperties = ( function() {
var cache = {};
for ( var i=0, len = prefixableProperties.length; i < len; i++ ) {
var prop = prefixableProperties[i];
var supportedProp = getStyleProperty( prop );
if ( supportedProp && supportedProp !== prop ) {
cache[ prop ] = supportedProp;
}
}
return cache;
})();
// -------------------------- Item -------------------------- //
function Item( element, layout ) {
if ( !element ) {
return;
}
this.element = element;
// parent layout class, i.e. Masonry, Isotope, or Packery
this.layout = layout;
this.position = {
x: 0,
y: 0
};
this._create();
}
// inherit EventEmitter
utils.extend( Item.prototype, EventEmitter.prototype );
Item.prototype._create = function() {
// transition objects
this._transn = {
ingProperties: {},
clean: {},
onEnd: {}
};
2022-11-01 05:18:35 +00:00
var el = $(this.element);
if(el.hasClass("row")){
el.css("width","100%");
}else if(el.filter("[class*='col-md']").length == 0){
el.css("width","100%");
}
2022-10-24 08:38:47 +00:00
this.css({
position: 'absolute'
});
};
// trigger specified handler for event type
Item.prototype.handleEvent = function( event ) {
var method = 'on' + event.type;
if ( this[ method ] ) {
this[ method ]( event );
}
};
Item.prototype.getSize = function() {
this.size = getSize( this.element );
};
/**
* apply CSS styles to element
* @param {Object} style
*/
Item.prototype.css = function( style ) {
var elemStyle = this.element.style;
for ( var prop in style ) {
// use vendor property if available
var supportedProp = vendorProperties[ prop ] || prop;
elemStyle[ supportedProp ] = style[ prop ];
}
};
// measure position, and sets it
Item.prototype.getPosition = function() {
var style = getStyle( this.element );
var layoutOptions = this.layout.options;
var isOriginLeft = layoutOptions.isOriginLeft;
var isOriginTop = layoutOptions.isOriginTop;
var xValue = style[ isOriginLeft ? 'left' : 'right' ];
var yValue = style[ isOriginTop ? 'top' : 'bottom' ];
// convert percent to pixels
var layoutSize = this.layout.size;
var x = xValue.indexOf('%') != -1 ?
( parseFloat( xValue ) / 100 ) * layoutSize.width : parseInt( xValue, 10 );
var y = yValue.indexOf('%') != -1 ?
( parseFloat( yValue ) / 100 ) * layoutSize.height : parseInt( yValue, 10 );
// clean up 'auto' or other non-integer values
x = isNaN( x ) ? 0 : x;
y = isNaN( y ) ? 0 : y;
// remove padding from measurement
x -= isOriginLeft ? layoutSize.paddingLeft : layoutSize.paddingRight;
y -= isOriginTop ? layoutSize.paddingTop : layoutSize.paddingBottom;
this.position.x = x;
this.position.y = y;
};
// set settled position, apply padding
Item.prototype.layoutPosition = function() {
var layoutSize = this.layout.size;
var layoutOptions = this.layout.options;
var style = {};
// x
var xPadding = layoutOptions.isOriginLeft ? 'paddingLeft' : 'paddingRight';
var xProperty = layoutOptions.isOriginLeft ? 'left' : 'right';
var xResetProperty = layoutOptions.isOriginLeft ? 'right' : 'left';
var x = this.position.x + layoutSize[ xPadding ];
// set in percentage or pixels
style[ xProperty ] = this.getXValue( x );
// reset other property
style[ xResetProperty ] = '';
// y
var yPadding = layoutOptions.isOriginTop ? 'paddingTop' : 'paddingBottom';
var yProperty = layoutOptions.isOriginTop ? 'top' : 'bottom';
var yResetProperty = layoutOptions.isOriginTop ? 'bottom' : 'top';
var y = this.position.y + layoutSize[ yPadding ];
// set in percentage or pixels
style[ yProperty ] = this.getYValue( y );
// reset other property
style[ yResetProperty ] = '';
this.css( style );
this.emitEvent( 'layout', [ this ] );
};
Item.prototype.getXValue = function( x ) {
var layoutOptions = this.layout.options;
return layoutOptions.percentPosition && !layoutOptions.isHorizontal ?
( ( x / this.layout.size.width ) * 100 ) + '%' : x + 'px';
};
Item.prototype.getYValue = function( y ) {
var layoutOptions = this.layout.options;
return layoutOptions.percentPosition && layoutOptions.isHorizontal ?
( ( y / this.layout.size.height ) * 100 ) + '%' : y + 'px';
};
Item.prototype._transitionTo = function( x, y ) {
this.getPosition();
// get current x & y from top/left
var curX = this.position.x;
var curY = this.position.y;
var compareX = parseInt( x, 10 );
var compareY = parseInt( y, 10 );
var didNotMove = compareX === this.position.x && compareY === this.position.y;
// save end position
this.setPosition( x, y );
// if did not move and not transitioning, just go to layout
if ( didNotMove && !this.isTransitioning ) {
this.layoutPosition();
return;
}
var transX = x - curX;
var transY = y - curY;
var transitionStyle = {};
transitionStyle.transform = this.getTranslate( transX, transY );
this.transition({
to: transitionStyle,
onTransitionEnd: {
transform: this.layoutPosition
},
isCleaning: true
});
};
Item.prototype.getTranslate = function( x, y ) {
// flip cooridinates if origin on right or bottom
var layoutOptions = this.layout.options;
x = layoutOptions.isOriginLeft ? x : -x;
y = layoutOptions.isOriginTop ? y : -y;
if ( is3d ) {
return 'translate3d(' + x + 'px, ' + y + 'px, 0)';
}
return 'translate(' + x + 'px, ' + y + 'px)';
};
// non transition + transform support
Item.prototype.goTo = function( x, y ) {
this.setPosition( x, y );
this.layoutPosition();
};
// use transition and transforms if supported
Item.prototype.moveTo = supportsCSS3 ?
Item.prototype._transitionTo : Item.prototype.goTo;
Item.prototype.setPosition = function( x, y ) {
this.position.x = parseInt( x, 10 );
this.position.y = parseInt( y, 10 );
};
// ----- transition ----- //
/**
* @param {Object} style - CSS
* @param {Function} onTransitionEnd
*/
// non transition, just trigger callback
Item.prototype._nonTransition = function( args ) {
this.css( args.to );
if ( args.isCleaning ) {
this._removeStyles( args.to );
}
for ( var prop in args.onTransitionEnd ) {
args.onTransitionEnd[ prop ].call( this );
}
};
/**
* proper transition
* @param {Object} args - arguments
* @param {Object} to - style to transition to
* @param {Object} from - style to start transition from
* @param {Boolean} isCleaning - removes transition styles after transition
* @param {Function} onTransitionEnd - callback
*/
Item.prototype._transition = function( args ) {
// redirect to nonTransition if no transition duration
if ( !parseFloat( this.layout.options.transitionDuration ) ) {
this._nonTransition( args );
return;
}
var _transition = this._transn;
// keep track of onTransitionEnd callback by css property
for ( var prop in args.onTransitionEnd ) {
_transition.onEnd[ prop ] = args.onTransitionEnd[ prop ];
}
// keep track of properties that are transitioning
for ( prop in args.to ) {
_transition.ingProperties[ prop ] = true;
// keep track of properties to clean up when transition is done
if ( args.isCleaning ) {
_transition.clean[ prop ] = true;
}
}
// set from styles
if ( args.from ) {
this.css( args.from );
// force redraw. http://blog.alexmaccaw.com/css-transitions
var h = this.element.offsetHeight;
// hack for JSHint to hush about unused var
h = null;
}
// enable transition
this.enableTransition( args.to );
// set styles that are transitioning
this.css( args.to );
this.isTransitioning = true;
};
// dash before all cap letters, including first for
// WebkitTransform => -webkit-transform
function toDashedAll( str ) {
return str.replace( /([A-Z])/g, function( $1 ) {
return '-' + $1.toLowerCase();
});
}
var transitionProps = 'opacity,' +
toDashedAll( vendorProperties.transform || 'transform' );
Item.prototype.enableTransition = function(/* style */) {
// HACK changing transitionProperty during a transition
// will cause transition to jump
if ( this.isTransitioning ) {
return;
}
// make `transition: foo, bar, baz` from style object
// HACK un-comment this when enableTransition can work
// while a transition is happening
// var transitionValues = [];
// for ( var prop in style ) {
// // dash-ify camelCased properties like WebkitTransition
// prop = vendorProperties[ prop ] || prop;
// transitionValues.push( toDashedAll( prop ) );
// }
// enable transition styles
this.css({
transitionProperty: transitionProps,
transitionDuration: this.layout.options.transitionDuration
});
// listen for transition end event
this.element.addEventListener( transitionEndEvent, this, false );
};
Item.prototype.transition = Item.prototype[ transitionProperty ? '_transition' : '_nonTransition' ];
// ----- events ----- //
Item.prototype.onwebkitTransitionEnd = function( event ) {
this.ontransitionend( event );
};
Item.prototype.onotransitionend = function( event ) {
this.ontransitionend( event );
};
// properties that I munge to make my life easier
var dashedVendorProperties = {
'-webkit-transform': 'transform',
'-moz-transform': 'transform',
'-o-transform': 'transform'
};
Item.prototype.ontransitionend = function( event ) {
// disregard bubbled events from children
if ( event.target !== this.element ) {
return;
}
var _transition = this._transn;
// get property name of transitioned property, convert to prefix-free
var propertyName = dashedVendorProperties[ event.propertyName ] || event.propertyName;
// remove property that has completed transitioning
delete _transition.ingProperties[ propertyName ];
// check if any properties are still transitioning
if ( isEmptyObj( _transition.ingProperties ) ) {
// all properties have completed transitioning
this.disableTransition();
}
// clean style
if ( propertyName in _transition.clean ) {
// clean up style
this.element.style[ event.propertyName ] = '';
delete _transition.clean[ propertyName ];
}
// trigger onTransitionEnd callback
if ( propertyName in _transition.onEnd ) {
var onTransitionEnd = _transition.onEnd[ propertyName ];
onTransitionEnd.call( this );
delete _transition.onEnd[ propertyName ];
}
this.emitEvent( 'transitionEnd', [ this ] );
};
Item.prototype.disableTransition = function() {
this.removeTransitionStyles();
this.element.removeEventListener( transitionEndEvent, this, false );
this.isTransitioning = false;
};
/**
* removes style property from element
* @param {Object} style
**/
Item.prototype._removeStyles = function( style ) {
// clean up transition styles
var cleanStyle = {};
for ( var prop in style ) {
cleanStyle[ prop ] = '';
}
this.css( cleanStyle );
};
var cleanTransitionStyle = {
transitionProperty: '',
transitionDuration: ''
};
Item.prototype.removeTransitionStyles = function() {
// remove transition
this.css( cleanTransitionStyle );
};
// ----- show/hide/remove ----- //
// remove element from DOM
Item.prototype.removeElem = function() {
this.element.parentNode.removeChild( this.element );
// remove display: none
this.css({ display: '' });
this.emitEvent( 'remove', [ this ] );
};
Item.prototype.remove = function() {
// just remove element if no transition support or no transition
if ( !transitionProperty || !parseFloat( this.layout.options.transitionDuration ) ) {
this.removeElem();
return;
}
// start transition
var _this = this;
this.once( 'transitionEnd', function() {
_this.removeElem();
});
this.hide();
};
Item.prototype.reveal = function() {
delete this.isHidden;
// remove display: none
this.css({ display: '' });
var options = this.layout.options;
var onTransitionEnd = {};
var transitionEndProperty = this.getHideRevealTransitionEndProperty('visibleStyle');
onTransitionEnd[ transitionEndProperty ] = this.onRevealTransitionEnd;
this.transition({
from: options.hiddenStyle,
to: options.visibleStyle,
isCleaning: true,
onTransitionEnd: onTransitionEnd
});
};
Item.prototype.onRevealTransitionEnd = function() {
// check if still visible
// during transition, item may have been hidden
if ( !this.isHidden ) {
this.emitEvent('reveal');
}
};
/**
* get style property use for hide/reveal transition end
* @param {String} styleProperty - hiddenStyle/visibleStyle
* @returns {String}
*/
Item.prototype.getHideRevealTransitionEndProperty = function( styleProperty ) {
var optionStyle = this.layout.options[ styleProperty ];
// use opacity
if ( optionStyle.opacity ) {
return 'opacity';
}
// get first property
for ( var prop in optionStyle ) {
return prop;
}
};
Item.prototype.hide = function() {
// set flag
this.isHidden = true;
// remove display: none
this.css({ display: '' });
var options = this.layout.options;
var onTransitionEnd = {};
var transitionEndProperty = this.getHideRevealTransitionEndProperty('hiddenStyle');
onTransitionEnd[ transitionEndProperty ] = this.onHideTransitionEnd;
this.transition({
from: options.visibleStyle,
to: options.hiddenStyle,
// keep hidden stuff hidden
isCleaning: true,
onTransitionEnd: onTransitionEnd
});
};
Item.prototype.onHideTransitionEnd = function() {
// check if still hidden
// during transition, item may have been un-hidden
if ( this.isHidden ) {
this.css({ display: 'none' });
this.emitEvent('hide');
}
};
Item.prototype.destroy = function() {
this.css({
position: '',
left: '',
right: '',
top: '',
bottom: '',
transition: '',
transform: ''
});
};
return Item;
}));
/*!
* Outlayer v1.4.2
* the brains and guts of a layout library
* MIT license
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'outlayer/outlayer',[
'eventie/eventie',
'eventEmitter/EventEmitter',
'get-size/get-size',
'fizzy-ui-utils/utils',
'./item'
],
function( eventie, EventEmitter, getSize, utils, Item ) {
return factory( window, eventie, EventEmitter, getSize, utils, Item);
}
);
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
window,
require('eventie'),
require('wolfy87-eventemitter'),
require('get-size'),
require('fizzy-ui-utils'),
require('./item')
);
} else {
// browser global
window.Outlayer = factory(
window,
window.eventie,
window.EventEmitter,
window.getSize,
window.fizzyUIUtils,
window.Outlayer.Item
);
}
}( window, function factory( window, eventie, EventEmitter, getSize, utils, Item ) {
'use strict';
// ----- vars ----- //
var console = window.console;
var jQuery = window.jQuery;
var noop = function() {};
// -------------------------- Outlayer -------------------------- //
// globally unique identifiers
var GUID = 0;
// internal store of all Outlayer intances
var instances = {};
/**
* @param {Element, String} element
* @param {Object} options
* @constructor
*/
function Outlayer( element, options ) {
var queryElement = utils.getQueryElement( element );
if ( !queryElement ) {
if ( console ) {
console.error( 'Bad element for ' + this.constructor.namespace +
': ' + ( queryElement || element ) );
}
return;
}
this.element = queryElement;
// add jQuery
if ( jQuery ) {
this.$element = jQuery( this.element );
}
// options
this.options = utils.extend( {}, this.constructor.defaults );
this.option( options );
// add id for Outlayer.getFromElement
var id = ++GUID;
this.element.outlayerGUID = id; // expando
instances[ id ] = this; // associate via id
// kick it off
this._create();
if ( this.options.isInitLayout ) {
this.layout();
}
}
// settings are for internal use only
Outlayer.namespace = 'outlayer';
Outlayer.Item = Item;
// default options
Outlayer.defaults = {
containerStyle: {
position: 'relative'
},
isInitLayout: true,
isOriginLeft: true,
isOriginTop: true,
isResizeBound: true,
isResizingContainer: true,
// item options
transitionDuration: '0.4s',
hiddenStyle: {
opacity: 0,
transform: 'scale(0.001)'
},
visibleStyle: {
opacity: 1,
transform: 'scale(1)'
}
};
// inherit EventEmitter
utils.extend( Outlayer.prototype, EventEmitter.prototype );
/**
* set options
* @param {Object} opts
*/
Outlayer.prototype.option = function( opts ) {
utils.extend( this.options, opts );
};
Outlayer.prototype._create = function() {
// get items from children
this.reloadItems();
// elements that affect layout, but are not laid out
this.stamps = [];
this.stamp( this.options.stamp );
// set container style
utils.extend( this.element.style, this.options.containerStyle );
// bind resize method
if ( this.options.isResizeBound ) {
this.bindResize();
}
};
// goes through all children again and gets bricks in proper order
Outlayer.prototype.reloadItems = function() {
// collection of item elements
this.items = this._itemize( this.element.children );
};
/**
* turn elements into Outlayer.Items to be used in layout
* @param {Array or NodeList or HTMLElement} elems
* @returns {Array} items - collection of new Outlayer Items
*/
Outlayer.prototype._itemize = function( elems ) {
var itemElems = this._filterFindItemElements( elems );
var Item = this.constructor.Item;
// create new Outlayer Items for collection
var items = [];
for ( var i=0, len = itemElems.length; i < len; i++ ) {
var elem = itemElems[i];
var item = new Item( elem, this );
items.push( item );
}
return items;
};
/**
* get item elements to be used in layout
* @param {Array or NodeList or HTMLElement} elems
* @returns {Array} items - item elements
*/
Outlayer.prototype._filterFindItemElements = function( elems ) {
return utils.filterFindElements( elems, this.options.itemSelector );
};
/**
* getter method for getting item elements
* @returns {Array} elems - collection of item elements
*/
Outlayer.prototype.getItemElements = function() {
var elems = [];
for ( var i=0, len = this.items.length; i < len; i++ ) {
elems.push( this.items[i].element );
}
return elems;
};
// ----- init & layout ----- //
/**
* lays out all items
*/
Outlayer.prototype.layout = function() {
this._resetLayout();
this._manageStamps();
// don't animate first layout
var isInstant = this.options.isLayoutInstant !== undefined ?
this.options.isLayoutInstant : !this._isLayoutInited;
this.layoutItems( this.items, isInstant );
// flag for initalized
this._isLayoutInited = true;
};
// _init is alias for layout
Outlayer.prototype._init = Outlayer.prototype.layout;
/**
* logic before any new layout
*/
Outlayer.prototype._resetLayout = function() {
this.getSize();
};
Outlayer.prototype.getSize = function() {
this.size = getSize( this.element );
};
/**
* get measurement from option, for columnWidth, rowHeight, gutter
* if option is String -> get element from selector string, & get size of element
* if option is Element -> get size of element
* else use option as a number
*
* @param {String} measurement
* @param {String} size - width or height
* @private
*/
Outlayer.prototype._getMeasurement = function( measurement, size ) {
var option = this.options[ measurement ];
var elem;
if ( !option ) {
// default to 0
this[ measurement ] = 0;
} else {
// use option as an element
if ( typeof option === 'string' ) {
elem = this.element.querySelector( option );
} else if ( utils.isElement( option ) ) {
elem = option;
}
// use size of element, if element
this[ measurement ] = elem ? getSize( elem )[ size ] : option;
}
};
/**
* layout a collection of item elements
* @api public
*/
Outlayer.prototype.layoutItems = function( items, isInstant ) {
items = this._getItemsForLayout( items );
this._layoutItems( items, isInstant );
this._postLayout();
};
/**
* get the items to be laid out
* you may want to skip over some items
* @param {Array} items
* @returns {Array} items
*/
Outlayer.prototype._getItemsForLayout = function( items ) {
var layoutItems = [];
for ( var i=0, len = items.length; i < len; i++ ) {
var item = items[i];
if ( !item.isIgnored ) {
layoutItems.push( item );
}
}
return layoutItems;
};
/**
* layout items
* @param {Array} items
* @param {Boolean} isInstant
*/
Outlayer.prototype._layoutItems = function( items, isInstant ) {
this._emitCompleteOnItems( 'layout', items );
if ( !items || !items.length ) {
// no items, emit event with empty array
return;
}
var queue = [];
for ( var i=0, len = items.length; i < len; i++ ) {
var item = items[i];
// get x/y object from method
var position = this._getItemLayoutPosition( item );
// enqueue
position.item = item;
position.isInstant = isInstant || item.isLayoutInstant;
queue.push( position );
}
this._processLayoutQueue( queue );
};
/**
* get item layout position
* @param {Outlayer.Item} item
* @returns {Object} x and y position
*/
Outlayer.prototype._getItemLayoutPosition = function( /* item */ ) {
return {
x: 0,
y: 0
};
};
/**
* iterate over array and position each item
* Reason being - separating this logic prevents 'layout invalidation'
* thx @paul_irish
* @param {Array} queue
*/
Outlayer.prototype._processLayoutQueue = function( queue ) {
for ( var i=0, len = queue.length; i < len; i++ ) {
var obj = queue[i];
this._positionItem( obj.item, obj.x, obj.y, obj.isInstant );
}
};
/**
* Sets position of item in DOM
* @param {Outlayer.Item} item
* @param {Number} x - horizontal position
* @param {Number} y - vertical position
* @param {Boolean} isInstant - disables transitions
*/
Outlayer.prototype._positionItem = function( item, x, y, isInstant ) {
if ( isInstant ) {
// if not transition, just set CSS
item.goTo( x, y );
} else {
item.moveTo( x, y );
}
};
/**
* Any logic you want to do after each layout,
* i.e. size the container
*/
Outlayer.prototype._postLayout = function() {
this.resizeContainer();
};
Outlayer.prototype.resizeContainer = function() {
if ( !this.options.isResizingContainer ) {
return;
}
var size = this._getContainerSize();
if ( size ) {
this._setContainerMeasure( size.width, true );
this._setContainerMeasure( size.height, false );
}
};
/**
* Sets width or height of container if returned
* @returns {Object} size
* @param {Number} width
* @param {Number} height
*/
Outlayer.prototype._getContainerSize = noop;
/**
* @param {Number} measure - size of width or height
* @param {Boolean} isWidth
*/
Outlayer.prototype._setContainerMeasure = function( measure, isWidth ) {
if ( measure === undefined ) {
return;
}
var elemSize = this.size;
// add padding and border width if border box
if ( elemSize.isBorderBox ) {
measure += isWidth ? elemSize.paddingLeft + elemSize.paddingRight +
elemSize.borderLeftWidth + elemSize.borderRightWidth :
elemSize.paddingBottom + elemSize.paddingTop +
elemSize.borderTopWidth + elemSize.borderBottomWidth;
}
measure = Math.max( measure, 0 );
this.element.style[ isWidth ? 'width' : 'height' ] = measure + 'px';
};
/**
* emit eventComplete on a collection of items events
* @param {String} eventName
* @param {Array} items - Outlayer.Items
*/
Outlayer.prototype._emitCompleteOnItems = function( eventName, items ) {
var _this = this;
function onComplete() {
_this.dispatchEvent( eventName + 'Complete', null, [ items ] );
}
var count = items.length;
if ( !items || !count ) {
onComplete();
return;
}
var doneCount = 0;
function tick() {
doneCount++;
if ( doneCount === count ) {
onComplete();
}
}
// bind callback
for ( var i=0, len = items.length; i < len; i++ ) {
var item = items[i];
item.once( eventName, tick );
}
};
/**
* emits events via eventEmitter and jQuery events
* @param {String} type - name of event
* @param {Event} event - original event
* @param {Array} args - extra arguments
*/
Outlayer.prototype.dispatchEvent = function( type, event, args ) {
// add original event to arguments
var emitArgs = event ? [ event ].concat( args ) : args;
this.emitEvent( type, emitArgs );
if ( jQuery ) {
// set this.$element
this.$element = this.$element || jQuery( this.element );
if ( event ) {
// create jQuery event
var $event = jQuery.Event( event );
$event.type = type;
this.$element.trigger( $event, args );
} else {
// just trigger with type if no event available
this.$element.trigger( type, args );
}
}
};
// -------------------------- ignore & stamps -------------------------- //
/**
* keep item in collection, but do not lay it out
* ignored items do not get skipped in layout
* @param {Element} elem
*/
Outlayer.prototype.ignore = function( elem ) {
var item = this.getItem( elem );
if ( item ) {
item.isIgnored = true;
}
};
/**
* return item to layout collection
* @param {Element} elem
*/
Outlayer.prototype.unignore = function( elem ) {
var item = this.getItem( elem );
if ( item ) {
delete item.isIgnored;
}
};
/**
* adds elements to stamps
* @param {NodeList, Array, Element, or String} elems
*/
Outlayer.prototype.stamp = function( elems ) {
elems = this._find( elems );
if ( !elems ) {
return;
}
this.stamps = this.stamps.concat( elems );
// ignore
for ( var i=0, len = elems.length; i < len; i++ ) {
var elem = elems[i];
this.ignore( elem );
}
};
/**
* removes elements to stamps
* @param {NodeList, Array, or Element} elems
*/
Outlayer.prototype.unstamp = function( elems ) {
elems = this._find( elems );
if ( !elems ){
return;
}
for ( var i=0, len = elems.length; i < len; i++ ) {
var elem = elems[i];
// filter out removed stamp elements
utils.removeFrom( this.stamps, elem );
this.unignore( elem );
}
};
/**
* finds child elements
* @param {NodeList, Array, Element, or String} elems
* @returns {Array} elems
*/
Outlayer.prototype._find = function( elems ) {
if ( !elems ) {
return;
}
// if string, use argument as selector string
if ( typeof elems === 'string' ) {
elems = this.element.querySelectorAll( elems );
}
elems = utils.makeArray( elems );
return elems;
};
Outlayer.prototype._manageStamps = function() {
if ( !this.stamps || !this.stamps.length ) {
return;
}
this._getBoundingRect();
for ( var i=0, len = this.stamps.length; i < len; i++ ) {
var stamp = this.stamps[i];
this._manageStamp( stamp );
}
};
// update boundingLeft / Top
Outlayer.prototype._getBoundingRect = function() {
// get bounding rect for container element
var boundingRect = this.element.getBoundingClientRect();
var size = this.size;
this._boundingRect = {
left: boundingRect.left + size.paddingLeft + size.borderLeftWidth,
top: boundingRect.top + size.paddingTop + size.borderTopWidth,
right: boundingRect.right - ( size.paddingRight + size.borderRightWidth ),
bottom: boundingRect.bottom - ( size.paddingBottom + size.borderBottomWidth )
};
};
/**
* @param {Element} stamp
**/
Outlayer.prototype._manageStamp = noop;
/**
* get x/y position of element relative to container element
* @param {Element} elem
* @returns {Object} offset - has left, top, right, bottom
*/
Outlayer.prototype._getElementOffset = function( elem ) {
var boundingRect = elem.getBoundingClientRect();
var thisRect = this._boundingRect;
var size = getSize( elem );
var offset = {
left: boundingRect.left - thisRect.left - size.marginLeft,
top: boundingRect.top - thisRect.top - size.marginTop,
right: thisRect.right - boundingRect.right - size.marginRight,
bottom: thisRect.bottom - boundingRect.bottom - size.marginBottom
};
return offset;
};
// -------------------------- resize -------------------------- //
// enable event handlers for listeners
// i.e. resize -> onresize
Outlayer.prototype.handleEvent = function( event ) {
var method = 'on' + event.type;
if ( this[ method ] ) {
this[ method ]( event );
}
};
/**
* Bind layout to window resizing
*/
Outlayer.prototype.bindResize = function() {
// bind just one listener
if ( this.isResizeBound ) {
return;
}
eventie.bind( window, 'resize', this );
this.isResizeBound = true;
};
/**
* Unbind layout to window resizing
*/
Outlayer.prototype.unbindResize = function() {
if ( this.isResizeBound ) {
eventie.unbind( window, 'resize', this );
}
this.isResizeBound = false;
};
// original debounce by John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
// this fires every resize
Outlayer.prototype.onresize = function() {
if ( this.resizeTimeout ) {
clearTimeout( this.resizeTimeout );
}
var _this = this;
function delayed() {
_this.resize();
delete _this.resizeTimeout;
}
this.resizeTimeout = setTimeout( delayed, 100 );
};
// debounced, layout on resize
Outlayer.prototype.resize = function() {
// don't trigger if size did not change
// or if resize was unbound. See #9
if ( !this.isResizeBound || !this.needsResizeLayout() ) {
return;
}
this.layout();
};
/**
* check if layout is needed post layout
* @returns Boolean
*/
Outlayer.prototype.needsResizeLayout = function() {
var size = getSize( this.element );
// check that this.size and size are there
// IE8 triggers resize on body size change, so they might not be
var hasSizes = this.size && size;
return hasSizes && size.innerWidth !== this.size.innerWidth;
};
// -------------------------- methods -------------------------- //
/**
* add items to Outlayer instance
* @param {Array or NodeList or Element} elems
* @returns {Array} items - Outlayer.Items
**/
Outlayer.prototype.addItems = function( elems ) {
var items = this._itemize( elems );
// add items to collection
if ( items.length ) {
this.items = this.items.concat( items );
}
return items;
};
/**
* Layout newly-appended item elements
* @param {Array or NodeList or Element} elems
*/
Outlayer.prototype.appended = function( elems ) {
var items = this.addItems( elems );
if ( !items.length ) {
return;
}
// layout and reveal just the new items
this.layoutItems( items, true );
this.reveal( items );
};
/**
* Layout prepended elements
* @param {Array or NodeList or Element} elems
*/
Outlayer.prototype.prepended = function( elems ) {
var items = this._itemize( elems );
if ( !items.length ) {
return;
}
// add items to beginning of collection
var previousItems = this.items.slice(0);
this.items = items.concat( previousItems );
// start new layout
this._resetLayout();
this._manageStamps();
// layout new stuff without transition
this.layoutItems( items, true );
this.reveal( items );
// layout previous items
this.layoutItems( previousItems );
};
/**
* reveal a collection of items
* @param {Array of Outlayer.Items} items
*/
Outlayer.prototype.reveal = function( items ) {
this._emitCompleteOnItems( 'reveal', items );
var len = items && items.length;
for ( var i=0; len && i < len; i++ ) {
var item = items[i];
item.reveal();
}
};
/**
* hide a collection of items
* @param {Array of Outlayer.Items} items
*/
Outlayer.prototype.hide = function( items ) {
this._emitCompleteOnItems( 'hide', items );
var len = items && items.length;
for ( var i=0; len && i < len; i++ ) {
var item = items[i];
item.hide();
}
};
/**
* reveal item elements
* @param {Array}, {Element}, {NodeList} items
*/
Outlayer.prototype.revealItemElements = function( elems ) {
var items = this.getItems( elems );
this.reveal( items );
};
/**
* hide item elements
* @param {Array}, {Element}, {NodeList} items
*/
Outlayer.prototype.hideItemElements = function( elems ) {
var items = this.getItems( elems );
this.hide( items );
};
/**
* get Outlayer.Item, given an Element
* @param {Element} elem
* @param {Function} callback
* @returns {Outlayer.Item} item
*/
Outlayer.prototype.getItem = function( elem ) {
// loop through items to get the one that matches
for ( var i=0, len = this.items.length; i < len; i++ ) {
var item = this.items[i];
if ( item.element === elem ) {
// return item
return item;
}
}
};
/**
* get collection of Outlayer.Items, given Elements
* @param {Array} elems
* @returns {Array} items - Outlayer.Items
*/
Outlayer.prototype.getItems = function( elems ) {
elems = utils.makeArray( elems );
var items = [];
for ( var i=0, len = elems.length; i < len; i++ ) {
var elem = elems[i];
var item = this.getItem( elem );
if ( item ) {
items.push( item );
}
}
return items;
};
/**
* remove element(s) from instance and DOM
* @param {Array or NodeList or Element} elems
*/
Outlayer.prototype.remove = function( elems ) {
var removeItems = this.getItems( elems );
this._emitCompleteOnItems( 'remove', removeItems );
// bail if no items to remove
if ( !removeItems || !removeItems.length ) {
return;
}
for ( var i=0, len = removeItems.length; i < len; i++ ) {
var item = removeItems[i];
item.remove();
// remove item from collection
utils.removeFrom( this.items, item );
}
};
// ----- destroy ----- //
// remove and disable Outlayer instance
Outlayer.prototype.destroy = function() {
// clean up dynamic styles
var style = this.element.style;
style.height = '';
style.position = '';
style.width = '';
// destroy items
for ( var i=0, len = this.items.length; i < len; i++ ) {
var item = this.items[i];
item.destroy();
}
this.unbindResize();
var id = this.element.outlayerGUID;
delete instances[ id ]; // remove reference to instance by id
delete this.element.outlayerGUID;
// remove data for jQuery
if ( jQuery ) {
jQuery.removeData( this.element, this.constructor.namespace );
}
};
// -------------------------- data -------------------------- //
/**
* get Outlayer instance from element
* @param {Element} elem
* @returns {Outlayer}
*/
Outlayer.data = function( elem ) {
elem = utils.getQueryElement( elem );
var id = elem && elem.outlayerGUID;
return id && instances[ id ];
};
// -------------------------- create Outlayer class -------------------------- //
/**
* create a layout class
* @param {String} namespace
*/
Outlayer.create = function( namespace, options ) {
// sub-class Outlayer
function Layout() {
Outlayer.apply( this, arguments );
}
// inherit Outlayer prototype, use Object.create if there
if ( Object.create ) {
Layout.prototype = Object.create( Outlayer.prototype );
} else {
utils.extend( Layout.prototype, Outlayer.prototype );
}
// set contructor, used for namespace and Item
Layout.prototype.constructor = Layout;
Layout.defaults = utils.extend( {}, Outlayer.defaults );
// apply new options
utils.extend( Layout.defaults, options );
// keep prototype.settings for backwards compatibility (Packery v1.2.0)
Layout.prototype.settings = {};
Layout.namespace = namespace;
Layout.data = Outlayer.data;
// sub-class Item
Layout.Item = function LayoutItem() {
Item.apply( this, arguments );
};
Layout.Item.prototype = new Item();
// -------------------------- declarative -------------------------- //
utils.htmlInit( Layout, namespace );
// -------------------------- jQuery bridge -------------------------- //
// make into jQuery plugin
if ( jQuery && jQuery.bridget ) {
jQuery.bridget( namespace, Layout );
}
return Layout;
};
// ----- fin ----- //
// back in global
Outlayer.Item = Item;
return Outlayer;
}));
/**
* Isotope Item
**/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'isotope/js/item',[
'outlayer/outlayer'
],
factory );
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
require('outlayer')
);
} else {
// browser global
window.Isotope = window.Isotope || {};
window.Isotope.Item = factory(
window.Outlayer
);
}
}( window, function factory( Outlayer ) {
'use strict';
// -------------------------- Item -------------------------- //
// sub-class Outlayer Item
function Item() {
Outlayer.Item.apply( this, arguments );
}
Item.prototype = new Outlayer.Item();
Item.prototype._create = function() {
// assign id, used for original-order sorting
this.id = this.layout.itemGUID++;
Outlayer.Item.prototype._create.call( this );
this.sortData = {};
};
Item.prototype.updateSortData = function() {
if ( this.isIgnored ) {
return;
}
// default sorters
this.sortData.id = this.id;
// for backward compatibility
this.sortData['original-order'] = this.id;
this.sortData.random = Math.random();
// go thru getSortData obj and apply the sorters
var getSortData = this.layout.options.getSortData;
var sorters = this.layout._sorters;
for ( var key in getSortData ) {
var sorter = sorters[ key ];
this.sortData[ key ] = sorter( this.element, this );
}
};
var _destroy = Item.prototype.destroy;
Item.prototype.destroy = function() {
// call super
_destroy.apply( this, arguments );
// reset display, #741
this.css({
display: ''
});
};
return Item;
}));
/**
* Isotope LayoutMode
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'isotope/js/layout-mode',[
'get-size/get-size',
'outlayer/outlayer'
],
factory );
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
require('get-size'),
require('outlayer')
);
} else {
// browser global
window.Isotope = window.Isotope || {};
window.Isotope.LayoutMode = factory(
window.getSize,
window.Outlayer
);
}
}( window, function factory( getSize, Outlayer ) {
'use strict';
// layout mode class
function LayoutMode( isotope ) {
this.isotope = isotope;
// link properties
if ( isotope ) {
this.options = isotope.options[ this.namespace ];
this.element = isotope.element;
this.items = isotope.filteredItems;
this.size = isotope.size;
}
}
/**
* some methods should just defer to default Outlayer method
* and reference the Isotope instance as `this`
**/
( function() {
var facadeMethods = [
'_resetLayout',
'_getItemLayoutPosition',
'_manageStamp',
'_getContainerSize',
'_getElementOffset',
'needsResizeLayout'
];
for ( var i=0, len = facadeMethods.length; i < len; i++ ) {
var methodName = facadeMethods[i];
LayoutMode.prototype[ methodName ] = getOutlayerMethod( methodName );
}
function getOutlayerMethod( methodName ) {
return function() {
return Outlayer.prototype[ methodName ].apply( this.isotope, arguments );
};
}
})();
// ----- ----- //
// for horizontal layout modes, check vertical size
LayoutMode.prototype.needsVerticalResizeLayout = function() {
// don't trigger if size did not change
var size = getSize( this.isotope.element );
// check that this.size and size are there
// IE8 triggers resize on body size change, so they might not be
var hasSizes = this.isotope.size && size;
return hasSizes && size.innerHeight != this.isotope.size.innerHeight;
};
// ----- measurements ----- //
LayoutMode.prototype._getMeasurement = function() {
this.isotope._getMeasurement.apply( this, arguments );
};
LayoutMode.prototype.getColumnWidth = function() {
this.getSegmentSize( 'column', 'Width' );
};
LayoutMode.prototype.getRowHeight = function() {
this.getSegmentSize( 'row', 'Height' );
};
/**
* get columnWidth or rowHeight
* segment: 'column' or 'row'
* size 'Width' or 'Height'
**/
LayoutMode.prototype.getSegmentSize = function( segment, size ) {
var segmentName = segment + size;
var outerSize = 'outer' + size;
// columnWidth / outerWidth // rowHeight / outerHeight
this._getMeasurement( segmentName, outerSize );
// got rowHeight or columnWidth, we can chill
if ( this[ segmentName ] ) {
return;
}
// fall back to item of first element
var firstItemSize = this.getFirstItemSize();
this[ segmentName ] = firstItemSize && firstItemSize[ outerSize ] ||
// or size of container
this.isotope.size[ 'inner' + size ];
};
LayoutMode.prototype.getFirstItemSize = function() {
var firstItem = this.isotope.filteredItems[0];
return firstItem && firstItem.element && getSize( firstItem.element );
};
// ----- methods that should reference isotope ----- //
LayoutMode.prototype.layout = function() {
this.isotope.layout.apply( this.isotope, arguments );
};
LayoutMode.prototype.getSize = function() {
this.isotope.getSize();
this.size = this.isotope.size;
};
// -------------------------- create -------------------------- //
LayoutMode.modes = {};
LayoutMode.create = function( namespace, options ) {
function Mode() {
LayoutMode.apply( this, arguments );
}
Mode.prototype = new LayoutMode();
// default options
if ( options ) {
Mode.options = options;
}
Mode.prototype.namespace = namespace;
// register in Isotope
LayoutMode.modes[ namespace ] = Mode;
return Mode;
};
return LayoutMode;
}));
/*!
* Masonry v3.3.1
* Cascading grid layout library
* http://masonry.desandro.com
* MIT License
* by David DeSandro
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define === 'function' && define.amd ) {
// AMD
define( 'masonry/masonry',[
'outlayer/outlayer',
'get-size/get-size',
'fizzy-ui-utils/utils'
],
factory );
} else if ( typeof exports === 'object' ) {
// CommonJS
module.exports = factory(
require('outlayer'),
require('get-size'),
require('fizzy-ui-utils')
);
} else {
// browser global
window.Masonry = factory(
window.Outlayer,
window.getSize,
window.fizzyUIUtils
);
}
}( window, function factory( Outlayer, getSize, utils ) {
// -------------------------- masonryDefinition -------------------------- //
// create an Outlayer layout class
var Masonry = Outlayer.create('masonry');
Masonry.prototype._resetLayout = function() {
this.getSize();
this._getMeasurement( 'columnWidth', 'outerWidth' );
this._getMeasurement( 'gutter', 'outerWidth' );
this.measureColumns();
// reset column Y
var i = this.cols;
this.colYs = [];
while (i--) {
this.colYs.push( 0 );
}
this.maxY = 0;
};
Masonry.prototype.measureColumns = function() {
this.getContainerWidth();
// if columnWidth is 0, default to outerWidth of first item
if ( !this.columnWidth ) {
var firstItem = this.items[0];
var firstItemElem = firstItem && firstItem.element;
// columnWidth fall back to item of first element
this.columnWidth = firstItemElem && getSize( firstItemElem ).outerWidth ||
// if first elem has no width, default to size of container
this.containerWidth;
}
var columnWidth = this.columnWidth += this.gutter;
// calculate columns
var containerWidth = this.containerWidth + this.gutter;
var cols = containerWidth / columnWidth;
// fix rounding errors, typically with gutters
var excess = columnWidth - containerWidth % columnWidth;
// if overshoot is less than a pixel, round up, otherwise floor it
var mathMethod = excess && excess < 1 ? 'round' : 'floor';
cols = Math[ mathMethod ]( cols );
this.cols = Math.max( cols, 1 );
};
Masonry.prototype.getContainerWidth = function() {
// container is parent if fit width
var container = this.options.isFitWidth ? this.element.parentNode : this.element;
// check that this.size and size are there
// IE8 triggers resize on body size change, so they might not be
var size = getSize( container );
this.containerWidth = size && size.innerWidth;
};
Masonry.prototype._getItemLayoutPosition = function( item ) {
item.getSize();
// how many columns does this brick span
var remainder = item.size.outerWidth % this.columnWidth;
var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
// round if off by 1 pixel, otherwise use ceil
var colSpan = Math[ mathMethod ]( item.size.outerWidth / this.columnWidth );
colSpan = Math.min( colSpan, this.cols );
var colGroup = this._getColGroup( colSpan );
// get the minimum Y value from the columns
var minimumY = Math.min.apply( Math, colGroup );
var shortColIndex = utils.indexOf( colGroup, minimumY );
// position the brick
var position = {
x: this.columnWidth * shortColIndex,
y: minimumY
};
// apply setHeight to necessary columns
var setHeight = minimumY + item.size.outerHeight;
var setSpan = this.cols + 1 - colGroup.length;
for ( var i = 0; i < setSpan; i++ ) {
this.colYs[ shortColIndex + i ] = setHeight;
}
return position;
};
/**
* @param {Number} colSpan - number of columns the element spans
* @returns {Array} colGroup
*/
Masonry.prototype._getColGroup = function( colSpan ) {
if ( colSpan < 2 ) {
// if brick spans only one column, use all the column Ys
return this.colYs;
}
var colGroup = [];
// how many different places could this brick fit horizontally
var groupCount = this.cols + 1 - colSpan;
// for each group potential horizontal position
for ( var i = 0; i < groupCount; i++ ) {
// make an array of colY values for that one group
var groupColYs = this.colYs.slice( i, i + colSpan );
// and get the max value of the array
colGroup[i] = Math.max.apply( Math, groupColYs );
}
return colGroup;
};
Masonry.prototype._manageStamp = function( stamp ) {
var stampSize = getSize( stamp );
var offset = this._getElementOffset( stamp );
// get the columns that this stamp affects
var firstX = this.options.isOriginLeft ? offset.left : offset.right;
var lastX = firstX + stampSize.outerWidth;
var firstCol = Math.floor( firstX / this.columnWidth );
firstCol = Math.max( 0, firstCol );
var lastCol = Math.floor( lastX / this.columnWidth );
// lastCol should not go over if multiple of columnWidth #425
lastCol -= lastX % this.columnWidth ? 0 : 1;
lastCol = Math.min( this.cols - 1, lastCol );
// set colYs to bottom of the stamp
var stampMaxY = ( this.options.isOriginTop ? offset.top : offset.bottom ) +
stampSize.outerHeight;
for ( var i = firstCol; i <= lastCol; i++ ) {
this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
}
};
Masonry.prototype._getContainerSize = function() {
this.maxY = Math.max.apply( Math, this.colYs );
var size = {
height: this.maxY
};
if ( this.options.isFitWidth ) {
size.width = this._getContainerFitWidth();
}
return size;
};
Masonry.prototype._getContainerFitWidth = function() {
var unusedCols = 0;
// count unused columns
var i = this.cols;
while ( --i ) {
if ( this.colYs[i] !== 0 ) {
break;
}
unusedCols++;
}
// fit container to columns that have been used
return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
};
Masonry.prototype.needsResizeLayout = function() {
var previousWidth = this.containerWidth;
this.getContainerWidth();
return previousWidth !== this.containerWidth;
};
return Masonry;
}));
/*!
* Masonry layout mode
* sub-classes Masonry
* http://masonry.desandro.com
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'isotope/js/layout-modes/masonry',[
'../layout-mode',
'masonry/masonry'
],
factory );
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
require('../layout-mode'),
require('masonry-layout')
);
} else {
// browser global
factory(
window.Isotope.LayoutMode,
window.Masonry
);
}
}( window, function factory( LayoutMode, Masonry ) {
'use strict';
// -------------------------- helpers -------------------------- //
// extend objects
function extend( a, b ) {
for ( var prop in b ) {
a[ prop ] = b[ prop ];
}
return a;
}
// -------------------------- masonryDefinition -------------------------- //
// create an Outlayer layout class
var MasonryMode = LayoutMode.create('masonry');
// save on to these methods
var _getElementOffset = MasonryMode.prototype._getElementOffset;
var layout = MasonryMode.prototype.layout;
var _getMeasurement = MasonryMode.prototype._getMeasurement;
// sub-class Masonry
extend( MasonryMode.prototype, Masonry.prototype );
// set back, as it was overwritten by Masonry
MasonryMode.prototype._getElementOffset = _getElementOffset;
MasonryMode.prototype.layout = layout;
MasonryMode.prototype._getMeasurement = _getMeasurement;
var measureColumns = MasonryMode.prototype.measureColumns;
MasonryMode.prototype.measureColumns = function() {
// set items, used if measuring first item
this.items = this.isotope.filteredItems;
measureColumns.call( this );
};
// HACK copy over isOriginLeft/Top options
var _manageStamp = MasonryMode.prototype._manageStamp;
MasonryMode.prototype._manageStamp = function() {
this.options.isOriginLeft = this.isotope.options.isOriginLeft;
this.options.isOriginTop = this.isotope.options.isOriginTop;
_manageStamp.apply( this, arguments );
};
return MasonryMode;
}));
/**
* fitRows layout mode
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'isotope/js/layout-modes/fit-rows',[
'../layout-mode'
],
factory );
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
require('../layout-mode')
);
} else {
// browser global
factory(
window.Isotope.LayoutMode
);
}
}( window, function factory( LayoutMode ) {
'use strict';
var FitRows = LayoutMode.create('fitRows');
FitRows.prototype._resetLayout = function() {
this.x = 0;
this.y = 0;
this.maxY = 0;
this._getMeasurement( 'gutter', 'outerWidth' );
};
FitRows.prototype._getItemLayoutPosition = function( item ) {
item.getSize();
var itemWidth = item.size.outerWidth + this.gutter;
// if this element cannot fit in the current row
var containerWidth = this.isotope.size.innerWidth + this.gutter;
if ( this.x !== 0 && itemWidth + this.x > containerWidth ) {
this.x = 0;
this.y = this.maxY;
}
var position = {
x: this.x,
y: this.y
};
this.maxY = Math.max( this.maxY, this.y + item.size.outerHeight );
this.x += itemWidth;
return position;
};
FitRows.prototype._getContainerSize = function() {
return { height: this.maxY };
};
return FitRows;
}));
/**
* vertical layout mode
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'isotope/js/layout-modes/vertical',[
'../layout-mode'
],
factory );
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
require('../layout-mode')
);
} else {
// browser global
factory(
window.Isotope.LayoutMode
);
}
}( window, function factory( LayoutMode ) {
'use strict';
var Vertical = LayoutMode.create( 'vertical', {
horizontalAlignment: 0
});
Vertical.prototype._resetLayout = function() {
this.y = 0;
};
Vertical.prototype._getItemLayoutPosition = function( item ) {
item.getSize();
var x = ( this.isotope.size.innerWidth - item.size.outerWidth ) *
this.options.horizontalAlignment;
var y = this.y;
this.y += item.size.outerHeight;
return { x: x, y: y };
};
Vertical.prototype._getContainerSize = function() {
return { height: this.y };
};
return Vertical;
}));
/*!
* Isotope v2.2.2
*
* Licensed GPLv3 for open source use
* or Isotope Commercial License for commercial use
*
* http://isotope.metafizzy.co
* Copyright 2015 Metafizzy
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( [
'outlayer/outlayer',
'get-size/get-size',
'matches-selector/matches-selector',
'fizzy-ui-utils/utils',
'isotope/js/item',
'isotope/js/layout-mode',
// include default layout modes
'isotope/js/layout-modes/masonry',
'isotope/js/layout-modes/fit-rows',
'isotope/js/layout-modes/vertical'
],
function( Outlayer, getSize, matchesSelector, utils, Item, LayoutMode ) {
return factory( window, Outlayer, getSize, matchesSelector, utils, Item, LayoutMode );
});
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
window,
require('outlayer'),
require('get-size'),
require('desandro-matches-selector'),
require('fizzy-ui-utils'),
require('./item'),
require('./layout-mode'),
// include default layout modes
require('./layout-modes/masonry'),
require('./layout-modes/fit-rows'),
require('./layout-modes/vertical')
);
} else {
// browser global
window.Isotope = factory(
window,
window.Outlayer,
window.getSize,
window.matchesSelector,
window.fizzyUIUtils,
window.Isotope.Item,
window.Isotope.LayoutMode
);
}
}( window, function factory( window, Outlayer, getSize, matchesSelector, utils,
Item, LayoutMode ) {
// -------------------------- vars -------------------------- //
var jQuery = window.jQuery;
// -------------------------- helpers -------------------------- //
var trim = String.prototype.trim ?
function( str ) {
return str.trim();
} :
function( str ) {
return str.replace( /^\s+|\s+$/g, '' );
};
var docElem = document.documentElement;
var getText = docElem.textContent ?
function( elem ) {
return elem.textContent;
} :
function( elem ) {
return elem.innerText;
};
// -------------------------- isotopeDefinition -------------------------- //
// create an Outlayer layout class
var Isotope = Outlayer.create( 'isotope', {
layoutMode: "masonry",
isJQueryFiltering: true,
sortAscending: true
});
Isotope.Item = Item;
Isotope.LayoutMode = LayoutMode;
Isotope.prototype._create = function() {
this.itemGUID = 0;
// functions that sort items
this._sorters = {};
this._getSorters();
// call super
Outlayer.prototype._create.call( this );
// create layout modes
this.modes = {};
// start filteredItems with all items
this.filteredItems = this.items;
// keep of track of sortBys
this.sortHistory = [ 'original-order' ];
// create from registered layout modes
for ( var name in LayoutMode.modes ) {
this._initLayoutMode( name );
}
};
Isotope.prototype.reloadItems = function() {
// reset item ID counter
this.itemGUID = 0;
// call super
Outlayer.prototype.reloadItems.call( this );
};
Isotope.prototype._itemize = function() {
var items = Outlayer.prototype._itemize.apply( this, arguments );
// assign ID for original-order
for ( var i=0, len = items.length; i < len; i++ ) {
var item = items[i];
item.id = this.itemGUID++;
}
this._updateItemsSortData( items );
return items;
};
// -------------------------- layout -------------------------- //
Isotope.prototype._initLayoutMode = function( name ) {
var Mode = LayoutMode.modes[ name ];
// set mode options
// HACK extend initial options, back-fill in default options
var initialOpts = this.options[ name ] || {};
this.options[ name ] = Mode.options ?
utils.extend( Mode.options, initialOpts ) : initialOpts;
// init layout mode instance
this.modes[ name ] = new Mode( this );
};
Isotope.prototype.layout = function() {
// if first time doing layout, do all magic
if ( !this._isLayoutInited && this.options.isInitLayout ) {
this.arrange();
return;
}
this._layout();
};
// private method to be used in layout() & magic()
Isotope.prototype._layout = function() {
// don't animate first layout
var isInstant = this._getIsInstant();
// layout flow
this._resetLayout();
this._manageStamps();
this.layoutItems( this.filteredItems, isInstant );
// flag for initalized
this._isLayoutInited = true;
};
// filter + sort + layout
Isotope.prototype.arrange = function( opts ) {
// set any options pass
this.option( opts );
this._getIsInstant();
// filter, sort, and layout
// filter
var filtered = this._filter( this.items );
this.filteredItems = filtered.matches;
var _this = this;
function hideReveal() {
_this.reveal( filtered.needReveal );
_this.hide( filtered.needHide );
}
this._bindArrangeComplete();
if ( this._isInstant ) {
this._noTransition( hideReveal );
} else {
hideReveal();
}
this._sort();
this._layout();
};
// alias to _init for main plugin method
Isotope.prototype._init = Isotope.prototype.arrange;
// HACK
// Don't animate/transition first layout
// Or don't animate/transition other layouts
Isotope.prototype._getIsInstant = function() {
var isInstant = this.options.isLayoutInstant !== undefined ?
this.options.isLayoutInstant : !this._isLayoutInited;
this._isInstant = isInstant;
return isInstant;
};
// listen for layoutComplete, hideComplete and revealComplete
// to trigger arrangeComplete
Isotope.prototype._bindArrangeComplete = function() {
// listen for 3 events to trigger arrangeComplete
var isLayoutComplete, isHideComplete, isRevealComplete;
var _this = this;
function arrangeParallelCallback() {
if ( isLayoutComplete && isHideComplete && isRevealComplete ) {
_this.dispatchEvent( 'arrangeComplete', null, [ _this.filteredItems ] );
}
}
this.once( 'layoutComplete', function() {
isLayoutComplete = true;
arrangeParallelCallback();
});
this.once( 'hideComplete', function() {
isHideComplete = true;
arrangeParallelCallback();
});
this.once( 'revealComplete', function() {
isRevealComplete = true;
arrangeParallelCallback();
});
};
// -------------------------- filter -------------------------- //
Isotope.prototype._filter = function( items ) {
var filter = this.options.filter;
filter = filter || '*';
var matches = [];
var hiddenMatched = [];
var visibleUnmatched = [];
var test = this._getFilterTest( filter );
// test each item
for ( var i=0, len = items.length; i < len; i++ ) {
var item = items[i];
if ( item.isIgnored ) {
continue;
}
// add item to either matched or unmatched group
var isMatched = test( item );
// item.isFilterMatched = isMatched;
// add to matches if its a match
if ( isMatched ) {
matches.push( item );
}
// add to additional group if item needs to be hidden or revealed
if ( isMatched && item.isHidden ) {
hiddenMatched.push( item );
} else if ( !isMatched && !item.isHidden ) {
visibleUnmatched.push( item );
}
}
// return collections of items to be manipulated
return {
matches: matches,
needReveal: hiddenMatched,
needHide: visibleUnmatched
};
};
// get a jQuery, function, or a matchesSelector test given the filter
Isotope.prototype._getFilterTest = function( filter ) {
if ( jQuery && this.options.isJQueryFiltering ) {
// use jQuery
return function( item ) {
return jQuery( item.element ).is( filter );
};
}
if ( typeof filter == 'function' ) {
// use filter as function
return function( item ) {
return filter( item.element );
};
}
// default, use filter as selector string
return function( item ) {
return matchesSelector( item.element, filter );
};
};
// -------------------------- sorting -------------------------- //
/**
* @params {Array} elems
* @public
*/
Isotope.prototype.updateSortData = function( elems ) {
// get items
var items;
if ( elems ) {
elems = utils.makeArray( elems );
items = this.getItems( elems );
} else {
// update all items if no elems provided
items = this.items;
}
this._getSorters();
this._updateItemsSortData( items );
};
Isotope.prototype._getSorters = function() {
var getSortData = this.options.getSortData;
for ( var key in getSortData ) {
var sorter = getSortData[ key ];
this._sorters[ key ] = mungeSorter( sorter );
}
};
/**
* @params {Array} items - of Isotope.Items
* @private
*/
Isotope.prototype._updateItemsSortData = function( items ) {
// do not update if no items
var len = items && items.length;
for ( var i=0; len && i < len; i++ ) {
var item = items[i];
item.updateSortData();
}
};
// ----- munge sorter ----- //
// encapsulate this, as we just need mungeSorter
// other functions in here are just for munging
var mungeSorter = ( function() {
// add a magic layer to sorters for convienent shorthands
// `.foo-bar` will use the text of .foo-bar querySelector
// `[foo-bar]` will use attribute
// you can also add parser
// `.foo-bar parseInt` will parse that as a number
function mungeSorter( sorter ) {
// if not a string, return function or whatever it is
if ( typeof sorter != 'string' ) {
return sorter;
}
// parse the sorter string
var args = trim( sorter ).split(' ');
var query = args[0];
// check if query looks like [an-attribute]
var attrMatch = query.match( /^\[(.+)\]$/ );
var attr = attrMatch && attrMatch[1];
var getValue = getValueGetter( attr, query );
// use second argument as a parser
var parser = Isotope.sortDataParsers[ args[1] ];
// parse the value, if there was a parser
sorter = parser ? function( elem ) {
return elem && parser( getValue( elem ) );
} :
// otherwise just return value
function( elem ) {
return elem && getValue( elem );
};
return sorter;
}
// get an attribute getter, or get text of the querySelector
function getValueGetter( attr, query ) {
var getValue;
// if query looks like [foo-bar], get attribute
if ( attr ) {
getValue = function( elem ) {
return elem.getAttribute( attr );
};
} else {
// otherwise, assume its a querySelector, and get its text
getValue = function( elem ) {
var child = elem.querySelector( query );
return child && getText( child );
};
}
return getValue;
}
return mungeSorter;
})();
// parsers used in getSortData shortcut strings
Isotope.sortDataParsers = {
'parseInt': function( val ) {
return parseInt( val, 10 );
},
'parseFloat': function( val ) {
return parseFloat( val );
}
};
// ----- sort method ----- //
// sort filteredItem order
Isotope.prototype._sort = function() {
var sortByOpt = this.options.sortBy;
if ( !sortByOpt ) {
return;
}
// concat all sortBy and sortHistory
var sortBys = [].concat.apply( sortByOpt, this.sortHistory );
// sort magic
var itemSorter = getItemSorter( sortBys, this.options.sortAscending );
this.filteredItems.sort( itemSorter );
// keep track of sortBy History
if ( sortByOpt != this.sortHistory[0] ) {
// add to front, oldest goes in last
this.sortHistory.unshift( sortByOpt );
}
};
// returns a function used for sorting
function getItemSorter( sortBys, sortAsc ) {
return function sorter( itemA, itemB ) {
// cycle through all sortKeys
for ( var i = 0, len = sortBys.length; i < len; i++ ) {
var sortBy = sortBys[i];
var a = itemA.sortData[ sortBy ];
var b = itemB.sortData[ sortBy ];
if ( a > b || a < b ) {
// if sortAsc is an object, use the value given the sortBy key
var isAscending = sortAsc[ sortBy ] !== undefined ? sortAsc[ sortBy ] : sortAsc;
var direction = isAscending ? 1 : -1;
return ( a > b ? 1 : -1 ) * direction;
}
}
return 0;
};
}
// -------------------------- methods -------------------------- //
// get layout mode
Isotope.prototype._mode = function() {
var layoutMode = this.options.layoutMode;
var mode = this.modes[ layoutMode ];
if ( !mode ) {
// TODO console.error
throw new Error( 'No layout mode: ' + layoutMode );
}
// HACK sync mode's options
// any options set after init for layout mode need to be synced
mode.options = this.options[ layoutMode ];
return mode;
};
Isotope.prototype._resetLayout = function() {
// trigger original reset layout
Outlayer.prototype._resetLayout.call( this );
this._mode()._resetLayout();
};
Isotope.prototype._getItemLayoutPosition = function( item ) {
return this._mode()._getItemLayoutPosition( item );
};
Isotope.prototype._manageStamp = function( stamp ) {
this._mode()._manageStamp( stamp );
};
Isotope.prototype._getContainerSize = function() {
return this._mode()._getContainerSize();
};
Isotope.prototype.needsResizeLayout = function() {
return this._mode().needsResizeLayout();
};
// -------------------------- adding & removing -------------------------- //
// HEADS UP overwrites default Outlayer appended
Isotope.prototype.appended = function( elems ) {
var items = this.addItems( elems );
if ( !items.length ) {
return;
}
// filter, layout, reveal new items
var filteredItems = this._filterRevealAdded( items );
// add to filteredItems
this.filteredItems = this.filteredItems.concat( filteredItems );
};
// HEADS UP overwrites default Outlayer prepended
Isotope.prototype.prepended = function( elems ) {
var items = this._itemize( elems );
if ( !items.length ) {
return;
}
// start new layout
this._resetLayout();
this._manageStamps();
// filter, layout, reveal new items
var filteredItems = this._filterRevealAdded( items );
// layout previous items
this.layoutItems( this.filteredItems );
// add to items and filteredItems
this.filteredItems = filteredItems.concat( this.filteredItems );
this.items = items.concat( this.items );
};
Isotope.prototype._filterRevealAdded = function( items ) {
var filtered = this._filter( items );
this.hide( filtered.needHide );
// reveal all new items
this.reveal( filtered.matches );
// layout new items, no transition
this.layoutItems( filtered.matches, true );
return filtered.matches;
};
/**
* Filter, sort, and layout newly-appended item elements
* @param {Array or NodeList or Element} elems
*/
Isotope.prototype.insert = function( elems ) {
var items = this.addItems( elems );
if ( !items.length ) {
return;
}
// append item elements
var i, item;
var len = items.length;
for ( i=0; i < len; i++ ) {
item = items[i];
this.element.appendChild( item.element );
}
// filter new stuff
var filteredInsertItems = this._filter( items ).matches;
// set flag
for ( i=0; i < len; i++ ) {
items[i].isLayoutInstant = true;
}
this.arrange();
// reset flag
for ( i=0; i < len; i++ ) {
delete items[i].isLayoutInstant;
}
this.reveal( filteredInsertItems );
};
var _remove = Isotope.prototype.remove;
Isotope.prototype.remove = function( elems ) {
elems = utils.makeArray( elems );
var removeItems = this.getItems( elems );
// do regular thing
_remove.call( this, elems );
// bail if no items to remove
var len = removeItems && removeItems.length;
if ( !len ) {
return;
}
// remove elems from filteredItems
for ( var i=0; i < len; i++ ) {
var item = removeItems[i];
// remove item from collection
utils.removeFrom( this.filteredItems, item );
}
};
Isotope.prototype.shuffle = function() {
// update random sortData
for ( var i=0, len = this.items.length; i < len; i++ ) {
var item = this.items[i];
item.sortData.random = Math.random();
}
this.options.sortBy = 'random';
this._sort();
this._layout();
};
/**
* trigger fn without transition
* kind of hacky to have this in the first place
* @param {Function} fn
* @returns ret
* @private
*/
Isotope.prototype._noTransition = function( fn ) {
// save transitionDuration before disabling
var transitionDuration = this.options.transitionDuration;
// disable transition
this.options.transitionDuration = 0;
// do it
var returnValue = fn.call( this );
// re-enable transition for reveal
this.options.transitionDuration = transitionDuration;
return returnValue;
};
// ----- helper methods ----- //
/**
* getter method for getting filtered item elements
* @returns {Array} elems - collection of item elements
*/
Isotope.prototype.getFilteredItemElements = function() {
var elems = [];
for ( var i=0, len = this.filteredItems.length; i < len; i++ ) {
elems.push( this.filteredItems[i].element );
}
return elems;
};
// ----- ----- //
return Isotope;
}));
/*!
* imagesLoaded PACKAGED v5.0.0
* JavaScript is all like "You images are done yet or what?"
* MIT License
*/
/**
* EvEmitter v2.1.1
* Lil' event emitter
* MIT License
*/
( function( global, factory ) {
// universal module definition
if ( typeof module == 'object' && module.exports ) {
// CommonJS - Browserify, Webpack
module.exports = factory();
} else {
// Browser globals
global.EvEmitter = factory();
}
}( typeof window != 'undefined' ? window : this, function() {
function EvEmitter() {}
let proto = EvEmitter.prototype;
proto.on = function( eventName, listener ) {
if ( !eventName || !listener ) return this;
// set events hash
let events = this._events = this._events || {};
// set listeners array
let listeners = events[ eventName ] = events[ eventName ] || [];
// only add once
if ( !listeners.includes( listener ) ) {
listeners.push( listener );
}
return this;
};
proto.once = function( eventName, listener ) {
if ( !eventName || !listener ) return this;
// add event
this.on( eventName, listener );
// set once flag
// set onceEvents hash
let onceEvents = this._onceEvents = this._onceEvents || {};
// set onceListeners object
let onceListeners = onceEvents[ eventName ] = onceEvents[ eventName ] || {};
// set flag
onceListeners[ listener ] = true;
return this;
};
proto.off = function( eventName, listener ) {
let listeners = this._events && this._events[ eventName ];
if ( !listeners || !listeners.length ) return this;
let index = listeners.indexOf( listener );
if ( index != -1 ) {
listeners.splice( index, 1 );
}
return this;
};
proto.emitEvent = function( eventName, args ) {
let listeners = this._events && this._events[ eventName ];
if ( !listeners || !listeners.length ) return this;
// copy over to avoid interference if .off() in listener
listeners = listeners.slice( 0 );
args = args || [];
// once stuff
let onceListeners = this._onceEvents && this._onceEvents[ eventName ];
for ( let listener of listeners ) {
let isOnce = onceListeners && onceListeners[ listener ];
if ( isOnce ) {
// remove listener
// remove before trigger to prevent recursion
this.off( eventName, listener );
// unset once flag
delete onceListeners[ listener ];
}
// trigger listener
listener.apply( this, args );
}
return this;
};
proto.allOff = function() {
delete this._events;
delete this._onceEvents;
return this;
};
return EvEmitter;
} ) );
/*!
* imagesLoaded v5.0.0
* JavaScript is all like "You images are done yet or what?"
* MIT License
*/
( function( window, factory ) {
// universal module definition
if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory( window, require('ev-emitter') );
} else {
// browser global
window.imagesLoaded = factory( window, window.EvEmitter );
}
} )( typeof window !== 'undefined' ? window : this,
function factory( window, EvEmitter ) {
let $ = window.jQuery;
let console = window.console;
// -------------------------- helpers -------------------------- //
// turn element or nodeList into an array
function makeArray( obj ) {
// use object if already an array
if ( Array.isArray( obj ) ) return obj;
let isArrayLike = typeof obj == 'object' && typeof obj.length == 'number';
// convert nodeList to array
if ( isArrayLike ) return [ ...obj ];
// array of single index
return [ obj ];
}
// -------------------------- imagesLoaded -------------------------- //
/**
* @param {[Array, Element, NodeList, String]} elem
* @param {[Object, Function]} options - if function, use as callback
* @param {Function} onAlways - callback function
* @returns {ImagesLoaded}
*/
function ImagesLoaded( elem, options, onAlways ) {
// coerce ImagesLoaded() without new, to be new ImagesLoaded()
if ( !( this instanceof ImagesLoaded ) ) {
return new ImagesLoaded( elem, options, onAlways );
}
// use elem as selector string
let queryElem = elem;
if ( typeof elem == 'string' ) {
queryElem = document.querySelectorAll( elem );
}
// bail if bad element
if ( !queryElem ) {
console.error(`Bad element for imagesLoaded ${queryElem || elem}`);
return;
}
this.elements = makeArray( queryElem );
this.options = {};
// shift arguments if no options set
if ( typeof options == 'function' ) {
onAlways = options;
} else {
Object.assign( this.options, options );
}
if ( onAlways ) this.on( 'always', onAlways );
this.getImages();
// add jQuery Deferred object
if ( $ ) this.jqDeferred = new $.Deferred();
// HACK check async to allow time to bind listeners
setTimeout( this.check.bind( this ) );
}
ImagesLoaded.prototype = Object.create( EvEmitter.prototype );
ImagesLoaded.prototype.getImages = function() {
this.images = [];
// filter & find items if we have an item selector
this.elements.forEach( this.addElementImages, this );
};
const elementNodeTypes = [ 1, 9, 11 ];
/**
* @param {Node} elem
*/
ImagesLoaded.prototype.addElementImages = function( elem ) {
// filter siblings
if ( elem.nodeName === 'IMG' ) {
this.addImage( elem );
}
// get background image on element
if ( this.options.background === true ) {
this.addElementBackgroundImages( elem );
}
// find children
// no non-element nodes, #143
let { nodeType } = elem;
if ( !nodeType || !elementNodeTypes.includes( nodeType ) ) return;
let childImgs = elem.querySelectorAll('img');
// concat childElems to filterFound array
for ( let img of childImgs ) {
this.addImage( img );
}
// get child background images
if ( typeof this.options.background == 'string' ) {
let children = elem.querySelectorAll( this.options.background );
for ( let child of children ) {
this.addElementBackgroundImages( child );
}
}
};
const reURL = /url\((['"])?(.*?)\1\)/gi;
ImagesLoaded.prototype.addElementBackgroundImages = function( elem ) {
let style = getComputedStyle( elem );
// Firefox returns null if in a hidden iframe https://bugzil.la/548397
if ( !style ) return;
// get url inside url("...")
let matches = reURL.exec( style.backgroundImage );
while ( matches !== null ) {
let url = matches && matches[2];
if ( url ) {
this.addBackground( url, elem );
}
matches = reURL.exec( style.backgroundImage );
}
};
/**
* @param {Image} img
*/
ImagesLoaded.prototype.addImage = function( img ) {
let loadingImage = new LoadingImage( img );
this.images.push( loadingImage );
};
ImagesLoaded.prototype.addBackground = function( url, elem ) {
let background = new Background( url, elem );
this.images.push( background );
};
ImagesLoaded.prototype.check = function() {
this.progressedCount = 0;
this.hasAnyBroken = false;
// complete if no images
if ( !this.images.length ) {
this.complete();
return;
}
/* eslint-disable-next-line func-style */
let onProgress = ( image, elem, message ) => {
// HACK - Chrome triggers event before object properties have changed. #83
setTimeout( () => {
this.progress( image, elem, message );
} );
};
this.images.forEach( function( loadingImage ) {
loadingImage.once( 'progress', onProgress );
loadingImage.check();
} );
};
ImagesLoaded.prototype.progress = function( image, elem, message ) {
this.progressedCount++;
this.hasAnyBroken = this.hasAnyBroken || !image.isLoaded;
// progress event
this.emitEvent( 'progress', [ this, image, elem ] );
if ( this.jqDeferred && this.jqDeferred.notify ) {
this.jqDeferred.notify( this, image );
}
// check if completed
if ( this.progressedCount === this.images.length ) {
this.complete();
}
if ( this.options.debug && console ) {
console.log( `progress: ${message}`, image, elem );
}
};
ImagesLoaded.prototype.complete = function() {
let eventName = this.hasAnyBroken ? 'fail' : 'done';
this.isComplete = true;
this.emitEvent( eventName, [ this ] );
this.emitEvent( 'always', [ this ] );
if ( this.jqDeferred ) {
let jqMethod = this.hasAnyBroken ? 'reject' : 'resolve';
this.jqDeferred[ jqMethod ]( this );
}
};
// -------------------------- -------------------------- //
function LoadingImage( img ) {
this.img = img;
}
LoadingImage.prototype = Object.create( EvEmitter.prototype );
LoadingImage.prototype.check = function() {
// If complete is true and browser supports natural sizes,
// try to check for image status manually.
let isComplete = this.getIsImageComplete();
if ( isComplete ) {
// report based on naturalWidth
this.confirm( this.img.naturalWidth !== 0, 'naturalWidth' );
return;
}
// If none of the checks above matched, simulate loading on detached element.
this.proxyImage = new Image();
// add crossOrigin attribute. #204
if ( this.img.crossOrigin ) {
this.proxyImage.crossOrigin = this.img.crossOrigin;
}
this.proxyImage.addEventListener( 'load', this );
this.proxyImage.addEventListener( 'error', this );
// bind to image as well for Firefox. #191
this.img.addEventListener( 'load', this );
this.img.addEventListener( 'error', this );
this.proxyImage.src = this.img.currentSrc || this.img.src;
};
LoadingImage.prototype.getIsImageComplete = function() {
// check for non-zero, non-undefined naturalWidth
// fixes Safari+InfiniteScroll+Masonry bug infinite-scroll#671
return this.img.complete && this.img.naturalWidth;
};
LoadingImage.prototype.confirm = function( isLoaded, message ) {
this.isLoaded = isLoaded;
let { parentNode } = this.img;
// emit progress with parent <picture> or self <img>
let elem = parentNode.nodeName === 'PICTURE' ? parentNode : this.img;
this.emitEvent( 'progress', [ this, elem, message ] );
};
// ----- events ----- //
// trigger specified handler for event type
LoadingImage.prototype.handleEvent = function( event ) {
let method = 'on' + event.type;
if ( this[ method ] ) {
this[ method ]( event );
}
};
LoadingImage.prototype.onload = function() {
this.confirm( true, 'onload' );
this.unbindEvents();
};
LoadingImage.prototype.onerror = function() {
this.confirm( false, 'onerror' );
this.unbindEvents();
};
LoadingImage.prototype.unbindEvents = function() {
this.proxyImage.removeEventListener( 'load', this );
this.proxyImage.removeEventListener( 'error', this );
this.img.removeEventListener( 'load', this );
this.img.removeEventListener( 'error', this );
};
// -------------------------- Background -------------------------- //
function Background( url, element ) {
this.url = url;
this.element = element;
this.img = new Image();
}
// inherit LoadingImage prototype
Background.prototype = Object.create( LoadingImage.prototype );
Background.prototype.check = function() {
this.img.addEventListener( 'load', this );
this.img.addEventListener( 'error', this );
this.img.src = this.url;
// check if image is already complete
let isComplete = this.getIsImageComplete();
if ( isComplete ) {
this.confirm( this.img.naturalWidth !== 0, 'naturalWidth' );
this.unbindEvents();
}
};
Background.prototype.unbindEvents = function() {
this.img.removeEventListener( 'load', this );
this.img.removeEventListener( 'error', this );
};
Background.prototype.confirm = function( isLoaded, message ) {
this.isLoaded = isLoaded;
this.emitEvent( 'progress', [ this, this.element, message ] );
};
// -------------------------- jQuery -------------------------- //
ImagesLoaded.makeJQueryPlugin = function( jQuery ) {
jQuery = jQuery || window.jQuery;
if ( !jQuery ) return;
// set local variable
$ = jQuery;
// $().imagesLoaded()
$.fn.imagesLoaded = function( options, onAlways ) {
let instance = new ImagesLoaded( this, options, onAlways );
return instance.jqDeferred.promise( $( this ) );
};
};
// try making plugin
ImagesLoaded.makeJQueryPlugin();
// -------------------------- -------------------------- //
return ImagesLoaded;
} );
// tipsy, facebook style tooltips for jquery
// version 1.0.0a
// (c) 2008-2010 jason frame [jason@onehackoranother.com]
// releated under the MIT license
(function($) {
function fixTitle($ele) {
if ($ele.attr('title') || typeof($ele.attr('original-title')) != 'string') {
$ele.attr('original-title', $ele.attr('title') || '').removeAttr('title');
}
}
function Tipsy(element, options) {
this.$element = $(element);
this.options = options;
this.enabled = true;
fixTitle(this.$element);
}
Tipsy.prototype = {
show: function() {
var title = this.getTitle();
if (title && this.enabled) {
var $tip = this.tip();
$tip.find('.tipsy-inner')[this.options.html ? 'html' : 'text'](title);
$tip[0].className = 'tipsy'; // reset classname in case of dynamic gravity
$tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);
var pos = $.extend({}, this.$element.offset(), {
width: this.$element[0].offsetWidth,
height: this.$element[0].offsetHeight
});
var actualWidth = $tip[0].offsetWidth, actualHeight = $tip[0].offsetHeight;
var gravity = (typeof this.options.gravity == 'function')
? this.options.gravity.call(this.$element[0])
: this.options.gravity;
var tp;
switch (gravity.charAt(0)) {
case 'n':
tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
break;
case 's':
tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
break;
case 'e':
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset};
break;
case 'w':
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset};
break;
}
if (gravity.length == 2) {
if (gravity.charAt(1) == 'w') {
tp.left = pos.left + pos.width / 2 - 15;
} else {
tp.left = pos.left + pos.width / 2 - actualWidth + 15;
}
}
$tip.css(tp).addClass('tipsy-' + gravity);
if (this.options.fade) {
$tip.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: this.options.opacity});
} else {
$tip.css({visibility: 'visible', opacity: this.options.opacity});
}
}
},
hide: function() {
if (this.options.fade) {
this.tip().stop().fadeOut(function() { $(this).remove(); });
} else {
this.tip().remove();
}
},
getTitle: function() {
var title, $e = this.$element, o = this.options;
fixTitle($e);
var title, o = this.options;
if (typeof o.title == 'string') {
title = $e.attr(o.title == 'title' ? 'original-title' : o.title);
} else if (typeof o.title == 'function') {
title = o.title.call($e[0]);
}
title = ('' + title).replace(/(^\s*|\s*$)/, "");
return title || o.fallback;
},
tip: function() {
if (!this.$tip) {
this.$tip = $('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"/></div>');
}
return this.$tip;
},
validate: function() {
if (!this.$element[0].parentNode) {
this.hide();
this.$element = null;
this.options = null;
}
},
enable: function() { this.enabled = true; },
disable: function() { this.enabled = false; },
toggleEnabled: function() { this.enabled = !this.enabled; }
};
$.fn.tipsy = function(options) {
if (options === true) {
return this.data('tipsy');
} else if (typeof options == 'string') {
return this.data('tipsy')[options]();
}
options = $.extend({}, $.fn.tipsy.defaults, options);
function get(ele) {
var tipsy = $.data(ele, 'tipsy');
if (!tipsy) {
tipsy = new Tipsy(ele, $.fn.tipsy.elementOptions(ele, options));
$.data(ele, 'tipsy', tipsy);
}
return tipsy;
}
function enter() {
var tipsy = get(this);
tipsy.hoverState = 'in';
if (options.delayIn == 0) {
tipsy.show();
} else {
setTimeout(function() { if (tipsy.hoverState == 'in') tipsy.show(); }, options.delayIn);
}
};
function leave() {
var tipsy = get(this);
tipsy.hoverState = 'out';
if (options.delayOut == 0) {
tipsy.hide();
} else {
setTimeout(function() { if (tipsy.hoverState == 'out') tipsy.hide(); }, options.delayOut);
}
};
if (!options.live) this.each(function() { get(this); });
if (options.trigger != 'manual') {
var binder = options.live ? 'live' : 'bind',
eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus',
eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
this[binder](eventIn, enter)[binder](eventOut, leave);
}
return this;
};
$.fn.tipsy.defaults = {
delayIn: 0,
delayOut: 0,
fade: false,
fallback: '',
gravity: 'n',
html: false,
live: false,
offset: 0,
opacity: 0.8,
title: 'title',
trigger: 'hover'
};
// Overwrite this method to provide options on a per-element basis.
// For example, you could store the gravity in a 'tipsy-gravity' attribute:
// return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' });
// (remember - do not modify 'options' in place!)
$.fn.tipsy.elementOptions = function(ele, options) {
return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
};
$.fn.tipsy.autoNS = function() {
return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
};
$.fn.tipsy.autoWE = function() {
return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
};
})(jQuery);