Site-CILA/assets/js/main.js

335 lines
6.1 KiB
JavaScript
Raw Normal View History

2019-06-12 12:59:29 +00:00
/*
Forty by HTML5 UP
html5up.net | @ajlkn
2019-06-12 12:59:29 +00:00
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
*/
(function($) {
var $window = $(window),
$body = $('body'),
$wrapper = $('#wrapper'),
$header = $('#header'),
$banner = $('#banner');
// Breakpoints.
breakpoints({
xlarge: ['1281px', '1680px' ],
large: ['981px', '1280px' ],
medium: ['737px', '980px' ],
small: ['481px', '736px' ],
xsmall: ['361px', '480px' ],
xxsmall: [null, '360px' ]
});
/**
* Applies parallax scrolling to an element's background image.
* @return {jQuery} jQuery object.
*/
$.fn._parallax = (browser.name == 'ie' || browser.name == 'edge' || browser.mobile) ? function() { return $(this) } : function(intensity) {
2019-06-12 12:59:29 +00:00
var $window = $(window),
$this = $(this);
2019-06-12 12:59:29 +00:00
if (this.length == 0 || intensity === 0)
return $this;
2019-06-12 12:59:29 +00:00
if (this.length > 1) {
2019-06-12 12:59:29 +00:00
for (var i=0; i < this.length; i++)
$(this[i])._parallax(intensity);
2019-06-12 12:59:29 +00:00
return $this;
2019-06-12 12:59:29 +00:00
}
2019-06-12 12:59:29 +00:00
if (!intensity)
intensity = 0.25;
2019-06-12 12:59:29 +00:00
$this.each(function() {
var $t = $(this),
on, off;
on = function() {
$t.css('background-position', 'center 100%, center 100%, center 0px');
$window
.on('scroll._parallax', function() {
var pos = parseInt($window.scrollTop()) - parseInt($t.position().top);
$t.css('background-position', 'center ' + (pos * (-1 * intensity)) + 'px');
2019-06-12 12:59:29 +00:00
});
};
off = function() {
$t
.css('background-position', '');
$window
.off('scroll._parallax');
};
breakpoints.on('<=medium', off);
breakpoints.on('>medium', on);
});
2019-06-12 12:59:29 +00:00
$window
.off('load._parallax resize._parallax')
.on('load._parallax resize._parallax', function() {
$window.trigger('scroll');
});
return $(this);
};
2019-06-12 12:59:29 +00:00
// Play initial animations on page load.
$window.on('load', function() {
window.setTimeout(function() {
$body.removeClass('is-preload');
}, 100);
});
2019-06-12 12:59:29 +00:00
// Clear transitioning state on unload/hide.
$window.on('unload pagehide', function() {
window.setTimeout(function() {
$('.is-transitioning').removeClass('is-transitioning');
}, 250);
});
2019-06-12 12:59:29 +00:00
// Fix: Enable IE-only tweaks.
if (browser.name == 'ie' || browser.name == 'edge')
$body.addClass('is-ie');
2019-06-12 12:59:29 +00:00
// Scrolly.
$('.scrolly').scrolly({
offset: function() {
return $header.height() - 2;
2019-06-12 12:59:29 +00:00
}
});
2019-06-12 12:59:29 +00:00
// Tiles.
var $tiles = $('.tiles > article');
2019-06-12 12:59:29 +00:00
$tiles.each(function() {
2019-06-12 12:59:29 +00:00
var $this = $(this),
$image = $this.find('.image'), $img = $image.find('img'),
$link = $this.find('.link'),
x;
2019-06-12 12:59:29 +00:00
// Image.
2019-06-12 12:59:29 +00:00
// Set image.
$this.css('background-image', 'url(' + $img.attr('src') + ')');
2019-06-12 12:59:29 +00:00
// Set position.
if (x = $img.data('position'))
$image.css('background-position', x);
2019-06-12 12:59:29 +00:00
// Hide original.
$image.hide();
2019-06-12 12:59:29 +00:00
// Link.
if ($link.length > 0) {
2019-06-12 12:59:29 +00:00
$x = $link.clone()
.text('')
.addClass('primary')
.appendTo($this);
2019-06-12 12:59:29 +00:00
$link = $link.add($x);
2019-06-12 12:59:29 +00:00
$link.on('click', function(event) {
2019-06-12 12:59:29 +00:00
var href = $link.attr('href');
2019-06-12 12:59:29 +00:00
// Prevent default.
event.stopPropagation();
event.preventDefault();
2019-06-12 12:59:29 +00:00
// Target blank?
if ($link.attr('target') == '_blank') {
2019-06-12 12:59:29 +00:00
// Open in new tab.
window.open(href);
2019-06-12 12:59:29 +00:00
}
2019-06-12 12:59:29 +00:00
// Otherwise ...
else {
2019-06-12 12:59:29 +00:00
// Start transitioning.
$this.addClass('is-transitioning');
$wrapper.addClass('is-transitioning');
2019-06-12 12:59:29 +00:00
// Redirect.
window.setTimeout(function() {
location.href = href;
}, 500);
2019-06-12 12:59:29 +00:00
}
2019-06-12 12:59:29 +00:00
});
}
2019-06-12 12:59:29 +00:00
});
2019-06-12 12:59:29 +00:00
// Header.
if ($banner.length > 0
&& $header.hasClass('alt')) {
2019-06-12 12:59:29 +00:00
$window.on('resize', function() {
$window.trigger('scroll');
});
2019-06-12 12:59:29 +00:00
$window.on('load', function() {
2019-06-12 12:59:29 +00:00
$banner.scrollex({
bottom: $header.height() + 10,
terminate: function() { $header.removeClass('alt'); },
enter: function() { $header.addClass('alt'); },
leave: function() { $header.removeClass('alt'); $header.addClass('reveal'); }
});
2019-06-12 12:59:29 +00:00
window.setTimeout(function() {
$window.triggerHandler('scroll');
}, 100);
2019-06-12 12:59:29 +00:00
});
2019-06-12 12:59:29 +00:00
}
2019-06-12 12:59:29 +00:00
// Banner.
$banner.each(function() {
2019-06-12 12:59:29 +00:00
var $this = $(this),
$image = $this.find('.image'), $img = $image.find('img');
2019-06-12 12:59:29 +00:00
// Parallax.
$this._parallax(0.275);
2019-06-12 12:59:29 +00:00
// Image.
if ($image.length > 0) {
2019-06-12 12:59:29 +00:00
// Set image.
$this.css('background-image', 'url(' + $img.attr('src') + ')');
2019-06-12 12:59:29 +00:00
// Hide original.
$image.hide();
2019-06-12 12:59:29 +00:00
}
2019-06-12 12:59:29 +00:00
});
2019-06-12 12:59:29 +00:00
// Menu.
var $menu = $('#menu'),
$menuInner;
2019-06-12 12:59:29 +00:00
$menu.wrapInner('<div class="inner"></div>');
$menuInner = $menu.children('.inner');
$menu._locked = false;
2019-06-12 12:59:29 +00:00
$menu._lock = function() {
2019-06-12 12:59:29 +00:00
if ($menu._locked)
return false;
2019-06-12 12:59:29 +00:00
$menu._locked = true;
2019-06-12 12:59:29 +00:00
window.setTimeout(function() {
$menu._locked = false;
}, 350);
2019-06-12 12:59:29 +00:00
return true;
2019-06-12 12:59:29 +00:00
};
2019-06-12 12:59:29 +00:00
$menu._show = function() {
2019-06-12 12:59:29 +00:00
if ($menu._lock())
$body.addClass('is-menu-visible');
2019-06-12 12:59:29 +00:00
};
2019-06-12 12:59:29 +00:00
$menu._hide = function() {
2019-06-12 12:59:29 +00:00
if ($menu._lock())
$body.removeClass('is-menu-visible');
2019-06-12 12:59:29 +00:00
};
2019-06-12 12:59:29 +00:00
$menu._toggle = function() {
2019-06-12 12:59:29 +00:00
if ($menu._lock())
$body.toggleClass('is-menu-visible');
2019-06-12 12:59:29 +00:00
};
2019-06-12 12:59:29 +00:00
$menuInner
.on('click', function(event) {
event.stopPropagation();
})
.on('click', 'a', function(event) {
2019-06-12 12:59:29 +00:00
var href = $(this).attr('href');
2019-06-12 12:59:29 +00:00
event.preventDefault();
event.stopPropagation();
2019-06-12 12:59:29 +00:00
// Hide.
$menu._hide();
2019-06-12 12:59:29 +00:00
// Redirect.
window.setTimeout(function() {
window.location.href = href;
}, 250);
2019-06-12 12:59:29 +00:00
});
2019-06-12 12:59:29 +00:00
$menu
.appendTo($body)
.on('click', function(event) {
2019-06-12 12:59:29 +00:00
event.stopPropagation();
event.preventDefault();
2019-06-12 12:59:29 +00:00
$body.removeClass('is-menu-visible');
2019-06-12 12:59:29 +00:00
})
.append('<a class="close" href="#menu">Close</a>');
2019-06-12 12:59:29 +00:00
$body
.on('click', 'a[href="#menu"]', function(event) {
2019-06-12 12:59:29 +00:00
event.stopPropagation();
event.preventDefault();
2019-06-12 12:59:29 +00:00
// Toggle.
$menu._toggle();
2019-06-12 12:59:29 +00:00
})
.on('click', function(event) {
2019-06-12 12:59:29 +00:00
// Hide.
$menu._hide();
2019-06-12 12:59:29 +00:00
})
.on('keydown', function(event) {
2019-06-12 12:59:29 +00:00
// Hide on escape.
if (event.keyCode == 27)
$menu._hide();
2019-06-12 12:59:29 +00:00
});
2019-06-12 12:59:29 +00:00
})(jQuery);