2019-08-27 14:46:46 -04:00
|
|
|
( function ( document, $, undefined ) {
|
2015-02-10 16:54:24 -05:00
|
|
|
'use strict';
|
2014-09-17 22:09:05 -04:00
|
|
|
|
2015-07-27 16:11:01 -04:00
|
|
|
var plugin = {};
|
|
|
|
|
|
2017-02-08 14:41:15 -05:00
|
|
|
plugin.init = function () {
|
2015-07-27 16:11:01 -04:00
|
|
|
_backstretchHandler();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/********************
|
|
|
|
|
* Private Functions
|
|
|
|
|
********************/
|
|
|
|
|
|
2019-08-27 14:46:46 -04:00
|
|
|
function _backstretchHandler () {
|
2015-07-27 16:11:01 -04:00
|
|
|
|
2016-02-23 13:12:43 -05:00
|
|
|
var $el = $( '.big-leader' );
|
2015-07-27 16:11:01 -04:00
|
|
|
|
2015-12-10 09:14:49 -05:00
|
|
|
if ( typeof $el === 'undefined' ) {
|
2015-07-27 16:11:01 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$el.css( {
|
2019-08-27 14:46:46 -04:00
|
|
|
height: ( $( window ).height() ) - ( [ plugin.params.height ] ) + 'px'
|
2015-07-27 16:11:01 -04:00
|
|
|
} );
|
|
|
|
|
|
2019-08-27 14:46:46 -04:00
|
|
|
$el.backstretch( _getSource(), _getArgs() );
|
2016-06-24 13:02:39 -04:00
|
|
|
|
|
|
|
|
var image = $( '.big-leader .backstretch img' );
|
2016-06-24 15:59:30 -04:00
|
|
|
image.attr( 'alt', plugin.params.title ).attr( 'aria-hidden', true );
|
2015-07-27 16:11:01 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-27 14:46:46 -04:00
|
|
|
/**
|
|
|
|
|
* Get the image source based on the screen size and available image sizes.
|
|
|
|
|
*/
|
|
|
|
|
function _getSource () {
|
|
|
|
|
if ( plugin.params.slider ) {
|
|
|
|
|
return plugin.params.slider;
|
|
|
|
|
}
|
2017-02-08 14:41:15 -05:00
|
|
|
var source = plugin.params.source.backstretch,
|
2019-08-27 14:46:46 -04:00
|
|
|
width = window.innerWidth,
|
2017-02-08 14:41:15 -05:00
|
|
|
height = $( '.big-leader' ).height();
|
2016-02-23 13:12:43 -05:00
|
|
|
|
2017-02-08 14:41:15 -05:00
|
|
|
if ( plugin.params.source.large && ( plugin.params.width.large >= width && plugin.params.image_height.large >= height ) ) {
|
2016-02-23 13:12:43 -05:00
|
|
|
source = plugin.params.source.large;
|
|
|
|
|
}
|
2017-02-08 14:41:15 -05:00
|
|
|
if ( plugin.params.source.medium_large && ( plugin.params.width.medium_large >= width && plugin.params.image_height.medium_large >= height ) ) {
|
2016-02-23 13:12:43 -05:00
|
|
|
source = plugin.params.source.medium_large;
|
|
|
|
|
}
|
|
|
|
|
return source;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-27 14:46:46 -04:00
|
|
|
/**
|
|
|
|
|
* Get the backstretch parameters.
|
|
|
|
|
*/
|
|
|
|
|
function _getArgs () {
|
|
|
|
|
var args = {
|
|
|
|
|
alignX: plugin.params.alignX,
|
|
|
|
|
alignY: plugin.params.alignY,
|
|
|
|
|
fade: parseInt( plugin.params.fade ),
|
|
|
|
|
scale: 'cover'
|
|
|
|
|
};
|
|
|
|
|
if ( plugin.params.slider ) {
|
|
|
|
|
args.duration = parseInt( plugin.params.duration );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return args;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-13 10:30:54 -04:00
|
|
|
plugin.params = typeof BackStretchVars === 'undefined' ? '' : BackStretchVars;
|
|
|
|
|
if ( typeof plugin.params !== 'undefined' ) {
|
2016-08-05 13:09:31 -04:00
|
|
|
plugin.init();
|
2019-05-13 10:30:54 -04:00
|
|
|
}
|
2015-02-10 16:54:24 -05:00
|
|
|
|
2019-08-27 14:46:46 -04:00
|
|
|
} )( document, jQuery );
|