Files
pomysloweprezenty.pl/libraries/functions-front.js
2024-10-23 12:55:46 +02:00

76 lines
2.1 KiB
JavaScript

var user_agent = navigator.userAgent.toLowerCase();
var click_event = user_agent.match(/(iphone|ipod|ipad)/) ? "touchend" : "click";
var windowsize = $(window).width();
function shopAlert( title, content, buttons )
{
$( 'body' ).append( '<div class="shop-alert-overlay"></div>' );
var out = '<div class="shop-alert">'
+ '<div class="shop-alert-title">' + title + '<a href="#" onclick="shopAlertClose(); return false;"><i class="fa fa-times"></i></a></div>'
+ '<div class="shop-alert-content">' + content + '</div>';
if ( buttons.length > 0 )
{
out += '<div class="shop-alert-buttons">';
$.each( buttons, function(index, value) {
out += value;
});
out += '</div>';
}
out += '</div>';
$( '.shop-alert-overlay' ).append( out );
}
function shopAlertClose()
{
$( '.shop-alert-overlay' ).remove();
}
$( function()
{
function hasWebP() {
var rv = $.Deferred(), img = new Image();
img.onload = function() { rv.resolve(); };
img.onerror = function() { rv.reject(); };
img.src = "/libraries/webp.webp";
return rv.promise();
}
hasWebP().then(function() {
}, function() {
$('body').addClass('nowebp');
$( 'img' ).each( function()
{
if ( $( this ).attr( 'src-nowebp' ) )
{
$( this ).attr( 'src', $( this ).attr( 'src-nowebp' ) );
$( this ).attr( 'data-src', $( this ).attr( 'src-nowebp' ) );
}
});
});
});
$( function()
{
$( 'body' ).on( click_event, '#mobile-menu-btn', function()
{
if ( windowsize <= 767 )
{
if ( $( this ).hasClass( 'active' ) )
{
$( this ).removeClass( 'active' );
$( '#main-menu' ).removeClass( 'visible' );
$( '#mobile-menu-btn i' ).addClass( 'fa-bars' ).removeClass( 'fa-times' );
$( 'body' ).removeClass( 'disable-scroll' );
}
else
{
$( this ).addClass( 'active' );
$( '#main-menu' ).addClass( 'visible' );
$( '#mobile-menu-btn i' ).removeClass( 'fa-bars' ).addClass( 'fa-times' );
$( 'body' ).addClass( 'disable-scroll' );
}
}
});
});