Skip to content

Instantly share code, notes, and snippets.

@andreasisaak
Created January 30, 2014 12:56
Show Gist options
  • Save andreasisaak/8707777 to your computer and use it in GitHub Desktop.
Save andreasisaak/8707777 to your computer and use it in GitHub Desktop.
/**
* Powered by parallax - The ultimative parallax script for Contao
*
* Copyright ©2012-2013 by MEN AT WORK <info@men-at-work.de>
* Visit the agency website at http://www.men-at-work.de for more information
*
* @package ParallaxXtend
* @copyright MEN AT WORK
* @link http://www.contao-parallax.com
* @license EULA
* @filesource
*/
(function ($) {
/**
* Class ParallaxXtend
*
* Provide methods to handle parallax functions
* @copyright MEN AT WORK 2013
* @package Frontend
*/
$.ParallaxXtend = {
// INIT ----------------------------------------------------------------
/**
* Initialize
*/
init: function () {
var self = this;
if (this.isParallaxPage()) {
this.addAnimationHelperFunctions();
this.initEvents();
// Register event for reinitializing
objBuilder.bindEvent({
object: window,
type: 'prxReInit',
func: function (e, data) {
self.initEvents();
}
});
}
},
// HEADER MANIPULATION -------------------------------------------------
/**
* Initialize all events
*/
initEvents: function () {
var self = this;
// Register event for updatet
objBuilder.bindEvent({
object: window,
type: 'prxUpdate',
func: function (e, data) {
self.addHeaderManipulation(data);
}
});
// Register event for resize
objBuilder.bindEvent({
object: window,
type: 'prxResize',
func: function (e, data) {
self.addHeaderManipulation(data);
}
});
},
/**
* Manipulate header an set on spezial time small or large classes
*
* @param {object} data
*/
addHeaderManipulation: function (data) {
var intScrollPosition = data.scrollTop,
blnAbort = data.parallax.isAbort();
if (typeof data.scrollTop === 'undefined') {
intScrollPosition = data.parallax.options.scrollTop;
}
if (blnAbort || (intScrollPosition < 280 && !$('body').hasClass('header-large'))) {
$('body').addClass('header-large');
$('body').removeClass('header-small');
if (!blnAbort) {
$(window).trigger('prxCustomerResize');
}
} else if (intScrollPosition > 280 && !$('body').hasClass('header-small')) {
$('body').addClass('header-small');
$('body').removeClass('header-large');
$(window).trigger('prxCustomerResize');
}
},
// ANIMATION HELPER FUNCTIONS ------------------------------------------
/**
* Add animation helper functions
*/
addAnimationHelperFunctions: function () {
$.extend($.ParallaxBuilder.animationHelperFunctions, {
/**
* Set css z-index to -1
*
* @param {object} anim
* @param {object|undefined} opts
* @param {ParallaxBuilder} self
* @param {object} opt
*/
setNegativeZIndex: function (anim, opts, self, opt) {
if (opts === -1) {
$(anim.selector).css('z-index', '-1');
}
},
/**
* Check current value for z-index and toggle it between 1 and -1
*
* @param {object} anim
* @param {object|undefined} opts
* @param {ParallaxBuilder} self
* @param {object} opt
*/
toggleZIndex: function (anim, opts, self, opt) {
if (opts === -1) {
$(anim.selector).css('z-index', '-1');
} else if (opts === 1) {
$(anim.selector).css('z-index', '1');
}
}
});
},
// HELPER --------------------------------------------------------------
/**
* Return if $.ParallaxBuilder exists on this page
*
* @returns {@exp;jQuery@pro;ParallaxBuilder}
*/
isParallaxPage: function () {
return ( !! $.ParallaxBuilder);
}
};
})(jQuery);
jQuery(document).ready(function () {
jQuery.ParallaxXtend.init();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment