').addClass(args.containerClass);
$prev = $('
prev').addClass(args.prevClass);
$next = $('
next').addClass(args.nextClass);
$container.
append($prev).
append($next);
};
var getContainer = function () {
return $container;
};
var getPrev = function () {
return $prev;
};
var getNext = function () {
return $next;
};
var getPrevKey = function () {
return 'left';
};
var getNextKey = function () {
return 'right';
};
var getType = function () {
return 'standard';
};
init();
// public
that.getType = getType;
that.getContainer = getContainer;
that.getPrev = getPrev;
that.getNext = getNext;
that.getPrevKey = getPrevKey;
that.getNextKey = getNextKey;
return that;
};
classes.noneDirectionNav = function () {
// private
var that = {};
// public
that.getType = function () { return 'none'; };
that.getContainer = function () { return $(); };
that.getPrev = function () { return $(); };
that.getNext = function () { return $(); };
that.getPrevKey = function () { return null; };
that.getNextKey = function () { return null; };
return that;
};
classes.carouFredSelConfig = function (args) {
// private
var that = {};
var config;
var sliderConfig;
var slider;
var coinNav;
var directionNav;
var progressBar;
var selectedSlideIndex;
var init = function () {
slider = args.slider;
sliderConfig = slider.getConfig();
coinNav = slider.getCoinNavigation();
directionNav = slider.getDirectionNavigation();
progressBar = slider.getProgressBar();
selectedSlideIndex = 0 - slider.getSlidesOffset();
buildConfig();
};
var doAction = function (actionName, data, options) {
if (typeof config[actionName] === 'function') {
config[actionName](data, options);
}
};
var getCurrentSlide = function (data, selectedSlideIndex) {
if (typeof data.items.visible[selectedSlideIndex] !== 'undefined') {
return data.items.visible.eq(selectedSlideIndex);
} else {
return data.items.visible;
}
};
var buildConfig = function () {
config = {
responsive: true,
width:'100%',
height:'variable',
items: {
visible: 1,
start: slider.getSlidesOffset()
},
swipe: {
onTouch : true,
onMouse : false
},
scroll: {
items: 1,
onBefore: function (data) {
var options = {
'selectedSlideIndex': selectedSlideIndex
};
doAction('scroll_onBefore_start', data, options);
slider.getContext().addClass('g1-transition');
var $currentSlide = getCurrentSlide(data, selectedSlideIndex);
if ($currentSlide.length > 0) {
slider.getSlides().removeClass('g1-selected');
$currentSlide.addClass('g1-selected');
coinNav.selectItem($currentSlide.data('index'));
}
doAction('scroll_onBefore_end', data, options);
},
onAfter: function (data) {
var options = {
'selectedSlideIndex': selectedSlideIndex
};
doAction('scroll_onAfter_start', data, options);
slider.getContext().removeClass('g1-transition');
doAction('scroll_onAfter_end', data, options);
}
},
prev: {
button: directionNav.getPrev(),
key: directionNav.getPrevKey()
},
next: {
button: directionNav.getNext(),
key: directionNav.getNextKey()
},
onCreate: function (data) {
doAction('onCreate_start', data);
coinNav.selectItem(0);
doAction('onCreate_end', data);
}
};
setUpAutoParam(); // pause time
setUpDirectionAndScrollFxParam(); // transition
setUpScrollDurationParam(); // transition speed
};
var setUpAutoParam = function () {
config.auto = {
play: (sliderConfig.autoplay !== 'none'),
timeoutDuration: sliderConfig.slideshowSpeed ? parseInt(sliderConfig.slideshowSpeed, 10): 0
};
if (sliderConfig.progressBar !== 'none') {
config.auto.progress = {
'bar': progressBar.getContainer(),
'updater': progressBar.update,
'interval': 50
};
}
};
var setUpDirectionAndScrollFxParam = function () {
var animation = sliderConfig.animation ? sliderConfig.animation : 'fade';
switch (animation) {
case 'fade':
config.scroll.fx = 'crossfade';
break;
case 'slide_up':
config.direction = 'up';
config.scroll.fx = 'scroll';
break;
case 'slide_down':
config.direction = 'down';
config.scroll.fx = 'scroll';
break;
case 'slide_left':
config.direction = 'left';
config.scroll.fx = 'scroll';
break;
case 'slide_right':
config.direction = 'right';
config.scroll.fx = 'scroll';
break;
}
};
var setUpScrollDurationParam = function () {
config.scroll.duration = sliderConfig.animationDuration ? parseInt(sliderConfig.animationDuration, 10) : 0;
};
var getJson = function () {
return config;
};
init();
// public
that.getJson = getJson;
return that;
};
handlers.simpleSlider = function ($slider, configObj) {
var slider = factoryMethods.createSlider($slider, configObj);
var $sliderContainer = slider.getContainer();
var config = classes.carouFredSelConfig({
'slider': slider
});
var mainSliderConfig = config.getJson();
var $firstImg = slider.getSlides().find('img:first');
var width = $firstImg.prop('width');
var height = $firstImg.prop('height');
height = Math.round(height/width * 100) + '%';
mainSliderConfig.items.width = width;
mainSliderConfig.items.height = height;
mainSliderConfig.scroll.easing = 'easeInOutExpo';
var pluginOptions = {
wrapper: {
element: 'div',
classname:'g1-carousel'
}
};
// store data in DOM element
$slider.data('g1_simple_slider', slider);
// handle main slider
$sliderContainer.carouFredSel(mainSliderConfig, pluginOptions);
slider.getContainer().after(slider.getDirectionNavigation().getContainer(), slider.getProgressBar().getContainer());
};
handlers.relaySlider = function ($slider, configObj) {
var options = {
coinNavigationItemSelectionHandler: coinNavSelectItem
};
var slider = factoryMethods.createSlider($slider, configObj, options);
var $sliderContainer = slider.getContainer();
var $leftSlider = $slider.find('.g1-slides').clone();
var $rightSlider = $slider.find('.g1-slides').clone();
$leftSlider.prependTo($slider.find('> .g1-inner'));
$rightSlider.appendTo($slider.find('> .g1-inner'));
var config = classes.carouFredSelConfig({
'slider': slider
});
/* ===============
* main slider
/* =============== */
var mainSliderConfig = config.getJson();
// change config
mainSliderConfig.auto.play = false;
mainSliderConfig.next = null;
mainSliderConfig.prev = null;
mainSliderConfig.scroll.duration = mainSliderConfig.scroll.duration/2;
var leftEasing = 'linear';
var centerEasing = 'linear';
var rightEasing = 'linear';
mainSliderConfig.auto.easing = centerEasing;
mainSliderConfig.scroll.easing = centerEasing;
// synchronise carousels
var carouselDelay = mainSliderConfig.scroll.duration/2;
var $prev = slider.getDirectionNavigation().getPrev();
var $next = slider.getDirectionNavigation().getNext();
$prev.click(function (e) {
e.preventDefault();
$leftSlider.trigger('prev');
setTimeout(function() {
$sliderContainer.trigger('prev');
}, carouselDelay);
setTimeout(function() {
$rightSlider.trigger('prev');
}, 2 * carouselDelay);
});
$next.click(function (e) {
e.preventDefault();
$rightSlider.trigger('next');
setTimeout(function() {
$sliderContainer.trigger('next');
}, carouselDelay);
setTimeout(function() {
$leftSlider.trigger('next');
}, 2 * carouselDelay);
});
var pluginOptions = {
wrapper: {
element: 'div',
classname:'g1-carousel'
}
};
// store data in DOM element
$slider.data('g1_simple_slider', slider);
$sliderContainer.carouFredSel(mainSliderConfig, pluginOptions);
slider.getContainer().after(slider.getDirectionNavigation().getContainer(), slider.getProgressBar().getContainer());
$sliderContainer.parent().wrap('
');
// coin nav selection
function coinNavSelectItem (args) {
var nextSlide = args.slideTo;
$rightSlider.trigger('slideTo', nextSlide);
setTimeout(function() {
$sliderContainer.trigger('slideTo', nextSlide);
}, carouselDelay);
setTimeout(function() {
$leftSlider.trigger('slideTo', nextSlide);
}, 2 * carouselDelay);
}
// auto play
var autoplay = configObj.autoplay === 'standard';
var pause = false;
$sliderContainer.mouseover(function () {
pause = true;
});
$sliderContainer.mouseout(function () {
pause = false;
});
if (autoplay) {
var slideshowSpeed = parseInt(configObj.slideshowSpeed, 10);
var showNextSlide = function() {
var isScrolling;
$sliderContainer.trigger('isScrolling', function(scrolling) { isScrolling = scrolling; });
if (!isScrolling && !pause) {
$next.trigger('click');
var $progressBarContainer = slider.getProgressBar().getContainer();
var progressBar = $progressBarContainer.find('> div > div');
progressBar.css('width', '0');
progressBar.animate({
width: '100%'
}, slideshowSpeed - 10, 'linear');
}
setTimeout(showNextSlide, slideshowSpeed);
};
setTimeout(showNextSlide, slideshowSpeed);
}
/* ===============
* left slider
/* =============== */
$leftSlider.find('> li:last').prependTo($leftSlider);
var leftSliderConfig = {
responsive:true,
width:'80%',
height:'variable',
auto: {
play: false,
easing: leftEasing
},
direction: mainSliderConfig.direction,
scroll: {
//fx: mainSliderConfig.scroll.fx,
fx: 'cover',
easing: leftEasing,
duration: mainSliderConfig.scroll.duration
}
};
$leftSlider.carouFredSel(leftSliderConfig, pluginOptions);
$leftSlider.parent().wrap('
');
/* ===============
* right slider
/* =============== */
$rightSlider.find('> li:first').appendTo($rightSlider);
var rightSliderConfig = {
responsive: true,
width:'80%',
height:'variable',
auto: {
play: false,
easing: rightEasing
},
direction: mainSliderConfig.direction,
scroll: {
//fx: mainSliderConfig.scroll.fx,
fx: 'uncover',
easing: rightEasing,
duration: mainSliderConfig.scroll.duration
}
};
$rightSlider.carouFredSel(rightSliderConfig, pluginOptions);
$rightSlider.parent().wrap('
');
};
handlers.viewportSlider = function ($slider, configObj) {
var options = {
'slidesOffset': -1
};
var log = function (content) { if (typeof console !== 'undefined') { console.log(content); } };
var slider = factoryMethods.createSlider($slider, configObj, options);
var $sliderContainer = slider.getContainer();
var config = classes.carouFredSelConfig({
'slider': slider
});
var mainSliderConfig = config.getJson();
mainSliderConfig.items.visible = 3;
mainSliderConfig.scroll.easing = 'easeInOutExpo';
mainSliderConfig.responsive = false;
// store data in DOM element
$slider.data('g1_simple_slider', slider);
var pluginOptions = {
wrapper: {
element: 'div',
classname:'g1-carousel'
}
};
// store data in DOM element
$slider.data('g1_simple_slider', slider);
// handle main slider
$sliderContainer.carouFredSel(mainSliderConfig, pluginOptions);
log(mainSliderConfig);
log(pluginOptions);
// move direction nav after slides container
slider.getContainer().after(slider.getDirectionNavigation().getContainer(), slider.getProgressBar().getContainer());
};
handlers.standoutSlider = function ($slider, configObj) {
var options = {
'slidesOffset': -1
};
var slider = factoryMethods.createSlider($slider, configObj, options);
var $sliderContainer = slider.getContainer();
var config = classes.carouFredSelConfig({
'slider': slider
});
var mainSliderConfig = config.getJson();
var $firstImg = slider.getSlides().find('img:first');
var width = $firstImg.width();
var height = $firstImg.height();
var scale = 2;
var marginVertical = Math.round((height - height/scale)/2);
var defaultCss = {
'width': Math.round(width/scale),
'height': Math.round(height/scale),
marginTop:marginVertical,
marginRight:0,
marginLeft:0,
opacity: 0.5
};
var selectedCss = {
'width': width,
'height': height,
marginTop: 0,
marginRight:0,
marginLeft:0,
opacity: 1
};
var aniOpts = {
queue: false,
duration: 1000, // tyle samo co czas transition
easing: 'easeInOutCirc'
};
$sliderContainer.find('img:gt(0)').css('zIndex', 1).css( defaultCss );
$sliderContainer.find('img:eq(0)').css('zIndex', 2).css( selectedCss );
mainSliderConfig.items.visible = 3;
mainSliderConfig.scroll.easing = 'easeInOutCirc';
mainSliderConfig.responsive = false;
// store data in DOM element
$slider.data('g1_simple_slider', slider);
mainSliderConfig.scroll_onBefore_start = function( data ) {
data.items.old.eq(1).find('img').css('zIndex', 1).animate( defaultCss, aniOpts );
data.items.visible.eq(1).find('img').css('zIndex', 2).animate( selectedCss, aniOpts );
};
mainSliderConfig.scroll_onAfter_start = function() {
//$sliderContainer.trigger('updateSizes');
};
var pluginOptions = {
wrapper: {
element: 'div',
classname:'g1-carousel'
}
};
mainSliderConfig.height = 'auto';
// handle main slider
$sliderContainer.carouFredSel(mainSliderConfig, pluginOptions);
slider.getContainer().after(slider.getDirectionNavigation().getContainer(), slider.getProgressBar().getContainer());
};
handlers.kenburnsSlider = function ($slider, configObj) {
var slider = factoryMethods.createSlider($slider, configObj);
var $sliderContainer = slider.getContainer();
var config = classes.carouFredSelConfig({
'slider': slider
});
var mainSliderConfig = config.getJson();
var $firstImg = slider.getSlides().find('img:first');
var width = $firstImg.prop('width');
var height = $firstImg.prop('height');
height = Math.round(height/width * 100) + '%';
mainSliderConfig.items.width = width;
mainSliderConfig.items.height = height;
var dur = mainSliderConfig.scroll.duration;
var pDur = 3 * dur;
mainSliderConfig.scroll_onBefore_start = function( data ) {
animate( data.items.visible, pDur + ( dur * 3 ) );
};
mainSliderConfig.scroll_onAfter_start = function( data ) {
data.items.old.find( 'img' ).each(function(){
var $this = $(this);
$this.stop();
$this.css({
width:'auto',
height:'auto',
marginTop: 0,
marginLeft: 0
});
});
};
mainSliderConfig.onCreate_start = function( data ) {
animate( data.items, pDur + ( dur *2 ) );
};
var pluginOptions = {
wrapper: {
element: 'div',
classname:'g1-carousel'
}
};
// handle main slider
$sliderContainer.carouFredSel(mainSliderConfig, pluginOptions);
slider.getContainer().after(slider.getDirectionNavigation().getContainer(), slider.getProgressBar().getContainer());
function animate( item, dur ) {
var $img = item.find('img');
var width = $img.prop('width');
var height = $img.prop('height');
var obj = {
width:width * 1.2,
height:height * 1.2
};
switch( Math.ceil( Math.random() * 2 ) ) {
case 1:
obj.marginTop = 0;
break;
case 2:
obj.marginTop = -height * 0.2;
break;
}
switch( Math.ceil( Math.random() * 2 ) ) {
case 1:
obj.marginLeft = 0;
break;
case 2:
obj.marginLeft = -width * 0.2;
break;
}
item.find( 'img' ).animate(obj, dur, 'linear' );
}
};
// expose to public scope
if (typeof themeContext.simpleSliders === 'undefined') {
themeContext.simpleSliders = {};
}
themeContext.simpleSliders.handlers = handlers;
themeContext.simpleSliders.helpers = helpers;
})(jQuery, window, G1.theme);