File: /var/www/html/wpbiancoarte/wp-content/plugins/hiroshi-core/assets/js/parts/global.js
(function ( $ ) {
'use strict';
// This case is important when theme is not active
if ( typeof qodef !== 'object' ) {
window.qodef = {};
}
window.qodefCore = {};
qodefCore.shortcodes = {};
qodefCore.listShortcodesScripts = {
qodefSwiper: qodef.qodefSwiper,
qodefPagination: qodef.qodefPagination,
qodefFilter: qodef.qodefFilter,
qodefMasonryLayout: qodef.qodefMasonryLayout,
qodefJustifiedGallery: qodef.qodefJustifiedGallery,
qodefDragCursor: qodefCore.qodefDragCursor,
};
qodefCore.body = $( 'body' );
qodefCore.html = $( 'html' );
qodefCore.windowWidth = $( window ).width();
qodefCore.windowHeight = $( window ).height();
qodefCore.scroll = 0;
$( document ).ready(
function () {
qodefCore.scroll = $( window ).scrollTop();
qodefInlinePageStyle.init();
qodefDynamicBackground.init();
qodefScrollableColumns.init();
}
);
$( window ).resize(
function () {
qodefCore.windowWidth = $( window ).width();
qodefCore.windowHeight = $( window ).height();
}
);
$( window ).scroll(
function () {
qodefCore.scroll = $( window ).scrollTop();
}
);
$( window ).load(
function () {
qodefParallaxItem.init();
qodefAppear.init();
}
);
/**
* Check element to be in the viewport
*/
var qodefIsInViewport = {
check: function ( $element, callback, onlyOnce ) {
if ( $element.length ) {
var offset = typeof $element.data( 'viewport-offset' ) !== 'undefined' ? $element.data( 'viewport-offset' ) : 0.15; // When item is 15% in the viewport
var observer = new IntersectionObserver(
function ( entries ) {
// isIntersecting is true when element and viewport are overlapping
// isIntersecting is false when element and viewport don't overlap
if ( entries[0].isIntersecting === true ) {
callback.call( $element );
// Stop watching the element when it's initialize
if ( onlyOnce !== false ) {
observer.disconnect();
}
}
},
{ threshold: [offset] }
);
observer.observe( $element[0] );
}
},
};
qodefCore.qodefIsInViewport = qodefIsInViewport;
var qodefScroll = {
disable: function () {
if ( window.addEventListener ) {
window.addEventListener(
'wheel',
qodefScroll.preventDefaultValue,
{ passive: false }
);
}
// window.onmousewheel = document.onmousewheel = qodefScroll.preventDefaultValue;
document.onkeydown = qodefScroll.keyDown;
},
enable: function () {
if ( window.removeEventListener ) {
window.removeEventListener(
'wheel',
qodefScroll.preventDefaultValue,
{ passive: false }
);
}
window.onmousewheel = document.onmousewheel = document.onkeydown = null;
},
preventDefaultValue: function ( e ) {
e = e || window.event;
if ( e.preventDefault ) {
e.preventDefault();
}
e.returnValue = false;
},
keyDown: function ( e ) {
var keys = [37, 38, 39, 40];
for ( var i = keys.length; i--; ) {
if ( e.keyCode === keys[i] ) {
qodefScroll.preventDefaultValue( e );
return;
}
}
}
};
qodefCore.qodefScroll = qodefScroll;
var qodefPerfectScrollbar = {
init: function ( $holder ) {
if ( $holder.length ) {
qodefPerfectScrollbar.qodefInitScroll( $holder );
}
},
qodefInitScroll: function ( $holder ) {
var $defaultParams = {
wheelSpeed: 0.6,
suppressScrollX: true
};
var $ps = new PerfectScrollbar(
$holder[0],
$defaultParams
);
$( window ).resize(
function () {
$ps.update();
}
);
}
};
qodefCore.qodefPerfectScrollbar = qodefPerfectScrollbar;
var qodefInlinePageStyle = {
init: function () {
this.holder = $( '#hiroshi-core-page-inline-style' );
if ( this.holder.length ) {
var style = this.holder.data( 'style' );
if ( style.length ) {
$( 'head' ).append( '<style type="text/css">' + style + '</style>' );
}
}
}
};
/**
* Init parallax item
*/
var qodefParallaxItem = {
init: function () {
var $items = $( '.qodef-parallax-item' );
if ( $items.length ) {
$items.each(
function () {
var $currentItem = $( this ),
$y = Math.floor( Math.random() * (-100 - (-25)) + (-25) );
if ( $currentItem.hasClass( 'qodef-grid-item' ) ) {
$currentItem.children( '.qodef-e-inner' ).attr(
'data-parallax',
'{"y": ' + $y + ', "smoothness": ' + '30' + '}'
);
} else {
$currentItem.attr(
'data-parallax',
'{"y": ' + $y + ', "smoothness": ' + '30' + '}'
);
}
}
);
}
qodefParallaxItem.initParallax();
},
initParallax: function () {
var parallaxInstances = $( '[data-parallax]' );
if ( parallaxInstances.length && ! qodefCore.html.hasClass( 'touchevents' ) && typeof ParallaxScroll === 'object' ) {
ParallaxScroll.init(); //initialization removed from plugin js file to have it run only on non-touch devices
}
},
};
qodefCore.qodefParallaxItem = qodefParallaxItem;
/**
* Init dynamic background
*/
var qodefDynamicBackground = {
init: function () {
var backgroundIntances = $("[data-dynamic-background-color]");
if (qodef.body.hasClass('qodef-dynamic-background-color') && backgroundIntances.length) {
$('#qodef-page-inner').append('<div id="qodef-dynamic-background"></div>');
var holder = $('#qodef-dynamic-background'),
scrollBuffer = qodef.scroll,
scrollingDown = true,
page = $('#qodef-page-outer'),
footer = $('#qodef-page-footer'),
currentScroll, instancesInView, activeEl;
//add bgrnd divs
backgroundIntances.each(function () {
qodefDynamicBackground.elementInView($(this) );
});
//calculate scroll direction
var scrollDirection = function() {
currentScroll = qodef.scroll;
if (currentScroll > scrollBuffer){
scrollingDown = true;
} else {
scrollingDown = false;
}
scrollBuffer = currentScroll;
};
holder.css('background-color', backgroundIntances.first().attr('data-dynamic-background-color'));
//colors change logic
$(window).on('scroll', function() {
scrollDirection();
instancesInView = backgroundIntances.filter('.qodef-in-view');
if ( footer.hasClass('qodef--uncover') ) {
if ( qodef.scroll + footer.height() < ( page.height() + page.position().top + page.offset().top ) - footer.height() ) {
holder.removeClass('qodef--display');
} else {
holder.addClass('qodef--display');
}
}
if (instancesInView.length) {
if (scrollingDown) {
activeEl = instancesInView.last();
} else {
activeEl = instancesInView.first();
}
holder.css('background-color') !== activeEl.attr('data-dynamic-background-color') &&
holder.css('background-color', activeEl.attr('data-dynamic-background-color'));
}
});
}
},
elementInView: function (element) {
var toggleClasses = function() {
if (qodef.scroll > element.offset().top - qodef.windowHeight && qodef.scroll < element.offset().top + element.height()) {
if (!element.hasClass('qodef-in-view')) {
element.addClass('qodef-in-view');
}
} else {
if (element.hasClass('qodef-in-view')) {
element.removeClass('qodef-in-view');
}
}
}
$(window).on('scroll', function(){
toggleClasses();
});
toggleClasses();
}
};
qodefCore.qodefDynamicBackground = qodefDynamicBackground;
/**
* Init parallax item
*/
var qodefScrollableColumns = {
init: function () {
var scrollableColumn = $('.qodef-elementor-column-scrollable > .elementor-container > .elementor-column');
if ( scrollableColumn.length && $('body').hasClass('qodef-browser--firefox') && typeof qodefCore.qodefPerfectScrollbar === 'object' ) {
scrollableColumn.each(
function () {
qodefCore.qodefPerfectScrollbar.init( $( this ) );
}
);
}
},
};
qodefCore.qodefScrollableColumns = qodefScrollableColumns;
/**
* Init animation on appear
*/
var qodefAppear = {
init: function () {
this.holder = $('.qodef--has-appear:not(.qodef--appeared), .qodef--custom-section-appear:not(.qodef--appeared)');
if (this.holder.length) {
this.holder.each(
function () {
var holder = $(this),
randomNum = gsap.utils.random(10, 300, 130),
appearDelay = $(this).attr('data-appear-delay');
appearDelay = appearDelay ? appearDelay : randomNum;
qodefCore.qodefIsInViewport.check(
holder,
()=>{
qodef.qodefWaitForImages.check(
holder,
function(){
setTimeout (
function () {
holder.addClass( 'qodef--appeared' );
},
appearDelay
)
}
)
}
);
}
);
}
},
};
qodefCore.qodefAppear = qodefAppear;
})( jQuery );