sermon-notes/public/theme/assets/js/main.js

262 lines
6.8 KiB
JavaScript
Raw Normal View History

2024-05-13 21:09:41 -04:00
/*
2024-05-15 22:40:13 -04:00
Editorial by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
2024-05-13 21:09:41 -04:00
*/
2024-05-15 22:40:13 -04:00
(function ($) {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
var $window = $(window),
$head = $('head'),
$body = $('body');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Breakpoints.
breakpoints({
xlarge: ['1281px', '1680px'],
large: ['981px', '1280px'],
medium: ['737px', '980px'],
small: ['481px', '736px'],
xsmall: ['361px', '480px'],
xxsmall: [null, '360px'],
'xlarge-to-max': '(min-width: 1681px)',
'small-to-xlarge': '(min-width: 481px) and (max-width: 1680px)'
});
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Stops animations/transitions until the page has ...
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// ... loaded.
$window.on('load', function () {
window.setTimeout(function () {
$body.removeClass('is-preload');
}, 100);
});
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// ... stopped resizing.
var resizeTimeout;
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
$window.on('resize', function () {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Mark as resizing.
$body.addClass('is-resizing');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Unmark after delay.
clearTimeout(resizeTimeout);
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
resizeTimeout = setTimeout(function () {
$body.removeClass('is-resizing');
}, 100);
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
});
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Fixes.
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Object fit images.
if (!browser.canUse('object-fit')
|| browser.name == 'safari')
$('.image.object').each(function () {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
var $this = $(this),
$img = $this.children('img');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Hide original image.
$img.css('opacity', '0');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Set background.
$this
.css('background-image', 'url("' + $img.attr('src') + '")')
.css('background-size', $img.css('object-fit') ? $img.css('object-fit') : 'cover')
.css('background-position', $img.css('object-position') ? $img.css('object-position') : 'center');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
});
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Sidebar.
var $sidebar = $('#sidebar'),
$sidebar_inner = $sidebar.children('.inner');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Inactive by default on <= large.
breakpoints.on('<=large', function () {
$sidebar.addClass('inactive');
});
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
breakpoints.on('>large', function () {
$sidebar.removeClass('inactive');
});
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Hack: Workaround for Chrome/Android scrollbar position bug.
if (browser.os == 'android'
&& browser.name == 'chrome')
$('<style>#sidebar .inner::-webkit-scrollbar { display: none; }</style>')
.appendTo($head);
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Toggle.
$('<a href="#sidebar" class="toggle">Toggle</a>')
.appendTo($sidebar)
.on('click', function (event) {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Prevent default.
event.preventDefault();
event.stopPropagation();
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Toggle.
$sidebar.toggleClass('inactive');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
});
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Events.
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Link clicks.
$sidebar.on('click', 'a', function (event) {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// >large? Bail.
if (breakpoints.active('>large'))
return;
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Vars.
var $a = $(this),
href = $a.attr('href'),
target = $a.attr('target');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Prevent default.
event.preventDefault();
event.stopPropagation();
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Check URL.
if (!href || href == '#' || href == '')
return;
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Hide sidebar.
$sidebar.addClass('inactive');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Redirect to href.
setTimeout(function () {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
if (target == '_blank')
window.open(href);
else
window.location.href = href;
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
}, 500);
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
});
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Prevent certain events inside the panel from bubbling.
$sidebar.on('click touchend touchstart touchmove', function (event) {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// >large? Bail.
if (breakpoints.active('>large'))
return;
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Prevent propagation.
event.stopPropagation();
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
});
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Hide panel on body click/tap.
$body.on('click touchend', function (event) {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// >large? Bail.
if (breakpoints.active('>large'))
return;
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Deactivate.
$sidebar.addClass('inactive');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
});
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Scroll lock.
// Note: If you do anything to change the height of the sidebar's content, be sure to
// trigger 'resize.sidebar-lock' on $window so stuff doesn't get out of sync.
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
$window.on('load.sidebar-lock', function () {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
var sh, wh, st;
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Reset scroll position to 0 if it's 1.
if ($window.scrollTop() == 1)
$window.scrollTop(0);
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
$window
.on('scroll.sidebar-lock', function () {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
var x, y;
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// <=large? Bail.
if (breakpoints.active('<=large')) {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
$sidebar_inner
.data('locked', 0)
.css('position', '')
.css('top', '');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
return;
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
}
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Calculate positions.
x = Math.max(sh - wh, 0);
y = Math.max(0, $window.scrollTop() - x);
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Lock/unlock.
if ($sidebar_inner.data('locked') == 1) {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
if (y <= 0)
$sidebar_inner
.data('locked', 0)
.css('position', '')
.css('top', '');
else
$sidebar_inner
.css('top', -1 * x);
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
}
else {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
if (y > 0)
$sidebar_inner
.data('locked', 1)
.css('position', 'fixed')
.css('top', -1 * x);
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
}
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
})
.on('resize.sidebar-lock', function () {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Calculate heights.
wh = $window.height();
sh = $sidebar_inner.outerHeight() + 30;
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Trigger scroll.
$window.trigger('scroll.sidebar-lock');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
})
.trigger('resize.sidebar-lock');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
});
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Menu.
var $menu = $('#menu'),
$menu_openers = $menu.children('ul').find('.opener');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Openers.
$menu_openers.each(function () {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
var $this = $(this);
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
$this.on('click', function (event) {
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Prevent default.
event.preventDefault();
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Toggle.
$menu_openers.not($this).removeClass('active');
$this.toggleClass('active');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
// Trigger resize (sidebar lock).
$window.triggerHandler('resize.sidebar-lock');
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
});
2024-05-13 21:09:41 -04:00
2024-05-15 22:40:13 -04:00
});
2024-05-13 21:09:41 -04:00
})(jQuery);