/**
* Returns the transform styles for all browsers
*/
function getTransforms(translate3d){
return {
'-webkit-transform': translate3d,
'-moz-transform': translate3d,
'-ms-transform':translate3d,
'transform': translate3d
};
}
/**
* Activating the website navigation dots according to the given slide name.
*/
function activateNavDots(name, sectionIndex){
if(options.navigation){
$('#multiscroll-nav').find('.active').removeClass('active');
if(name){
$('#multiscroll-nav').find('a[href="#' + name + '"]').addClass('active');
}else{
$('#multiscroll-nav').find('li').eq(sectionIndex).find('a').addClass('active');
}
}
}
/**
* Activating the website main menu elements according to the given slide name.
*/
function activateMenuElement(name){
if(options.menu){
$(options.menu).find('.active').removeClass('active');
$(options.menu).find('[data-menuanchor="'+name+'"]').addClass('active');
}
}
/**
* Retuns `up` or `down` depending on the scrolling movement to reach its destination
* from the current section.
*/
function getYmovement(destiny){
var fromIndex = $('.ms-left .ms-section.active').index();
var toIndex = destiny.index();
if(fromIndex > toIndex){
return 'up';
}
return 'down';
}
/**
* Sets the URL hash for a section with slides
*/
function setURLHash(anchorLink){
if(options.anchors.length){
location.hash = anchorLink;
}
}
/**
* Checks for translate3d support
* @return boolean
* http://stackoverflow.com/questions/5661671/detecting-transform-translate3d-support
*/
function support3d() {
var el = document.createElement('p'),
has3d,
transforms = {
'webkitTransform':'-webkit-transform',
'OTransform':'-o-transform',
'msTransform':'-ms-transform',
'MozTransform':'-moz-transform',
'transform':'transform'
};
// Add it to the body to get the computed style.
document.body.insertBefore(el, null);
for (var t in transforms) {
if (el.style[t] !== undefined) {
el.style[t] = "translate3d(1px,1px,1px)";
has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
}
}
document.body.removeChild(el);
return (has3d !== undefined && has3d.length > 0 && has3d !== "none");
}
/**
* Wraps an element in order to center it vertically by using a class style.
*/
function addTableClass(element){
element.addClass('ms-table').wrapInner('<div class="ms-tableCell" style="height: ' + getTableHeight(element) + 'px" />');
}
/**
* Gets the height of the section after removing the paddings.
*/
function getTableHeight(section){
var sectionHeight = windowHeight;
if(options.paddingTop || options.paddingBottom){
var paddings = parseInt(section.css('padding-top')) + parseInt(section.css('padding-bottom'));
sectionHeight = (windowHeight - paddings);
}
return sectionHeight;
}
/**
* Scrolls the page to the existent anchor in the URL
*/
function scrollToAnchor(){
//getting the anchor link in the URL and deleting the `#`
var sectionAnchor = window.location.hash.replace('#', '');
var section = $('.ms-left .ms-section[data-anchor="'+sectionAnchor+'"]');
if(sectionAnchor.length){ //if theres any #
scrollPage(section);
}
}
/**
* Adds or remove the possiblity of scrolling through sections by using the keyboard arrow keys
*/
$.fn.multiscroll.setKeyboardScrolling = function (value){
options.keyboardScrolling = value;
};
/**
* Adds or remove the possiblity of scrolling through sections by using the mouse wheel or the trackpad.
*/
$.fn.multiscroll.setMouseWheelScrolling = function (value){
if(value){
addMouseWheelHandler();
}else{
removeMouseWheelHandler();
}
};
/**
* Defines the scrolling speed
*/
$.fn.multiscroll.setScrollingSpeed = function(value){
options.scrollingSpeed = value;
};
var touchStartY = 0;
var touchStartX = 0;
var touchEndY = 0;
var touchEndX = 0;
/* Detecting touch events
* As we are changing the top property of the page on scrolling, we can not use the traditional way to detect it.
* This way, the touchstart and the touch moves shows an small difference between them which is the
* used one to determine the direction.
*/
function touchMoveHandler(event){
var e = event.originalEvent;
//preventing the easing on iOS devices
event.preventDefault();
var activeSection = $('.ms-left .ms-section.active');
if (!isMoving) { //if theres any #
var touchEvents = getEventsPage(e);
touchEndY = touchEvents['y'];
touchEndX = touchEvents['x'];
//is the movement greater than the minimum resistance to scroll?
if (Math.abs(touchStartY - touchEndY) > ($(window).height() / 100 * options.touchSensitivity)) {
if (touchStartY > touchEndY) {
$.fn.multiscroll.moveSectionDown();
} else if (touchEndY > touchStartY) {
$.fn.multiscroll.moveSectionUp();
}
}
}
}
/**
* Handler to get he coordinates of the starting touch
*/
function touchStartHandler(event){
var e = event.originalEvent;
var touchEvents = getEventsPage(e);
touchStartY = touchEvents['y'];
touchStartX = touchEvents['x'];
}
/**
* Adds the possibility to auto scroll through sections on touch devices.
*/
function addTouchHandler(){
$(document).off('touchstart MSPointerDown').on('touchstart MSPointerDown', touchStartHandler);
$(document).off('touchmove MSPointerMove').on('touchmove MSPointerMove', touchMoveHandler);
}
/**
* Removes the auto scrolling for touch devices.
*/
function removeTouchHandler(){
$(document).off('touchstart MSPointerDown');
$(document).off('touchmove MSPointerMove');
}
/**
* Gets the pageX and pageY properties depending on the browser.
* https://github.com/alvarotrigo/fullPage.js/issues/194#issuecomment-34069854
*/
function getEventsPage(e){
var events = new Array();
if (window.navigator.msPointerEnabled){
events['y'] = e.pageY;
events['x'] = e.pageX;
}else{
events['y'] = e.touches[0].pageY;
events['x'] = e.touches[0].pageX;
}
return events;
}
};
})(jQuery);