').addClass(settings.timer_progress_class));
timer_container.addClass(settings.timer_paused_class);
container.append(timer_container);
}
if (settings.slide_number) {
number_container = $('
').addClass(settings.slide_number_class);
number_container.append('
of
');
container.append(number_container);
}
if (settings.bullets) {
bullets_container = $('
').addClass(settings.bullets_container_class);
container.append(bullets_container);
slides_container.children().each(function(idx, el) {
var bullet = $('- ').attr('data-orbit-slide', idx);
bullets_container.append(bullet);
});
}
if (settings.stack_on_small) {
container.addClass(settings.stack_on_small_class);
}
self.update_slide_number(0);
};
self._goto = function(next_idx, start_timer) {
// if (locked) {return false;}
if (next_idx === idx) {return false;}
if (typeof timer === 'object') {timer.restart();}
var slides = slides_container.children();
var dir = 'next';
locked = true;
if (next_idx < idx) {dir = 'prev';}
if (next_idx >= slides.length) {next_idx = 0;}
else if (next_idx < 0) {next_idx = slides.length - 1;}
var current = $(slides.get(idx));
var next = $(slides.get(next_idx));
current.css('zIndex', 2);
next.css('zIndex', 4).addClass('active');
slides_container.trigger('orbit:before-slide-change');
settings.before_slide_change();
var callback = function() {
var unlock = function() {
idx = next_idx;
locked = false;
if (start_timer === true) {timer = self.create_timer(); timer.start();}
self.update_slide_number(idx);
slides_container.trigger('orbit:after-slide-change',[{slide_number: idx, total_slides: slides.length}]);
settings.after_slide_change(idx, slides.length);
};
if (slides_container.height() != next.height()) {
slides_container.animate({'height': next.height()}, 250, 'linear', unlock);
} else {
unlock();
}
};
if (slides.length === 1) {callback(); return false;}
var start_animation = function() {
if (dir === 'next') {animate.next(current, next, callback);}
if (dir === 'prev') {animate.prev(current, next, callback);}
};
if (next.height() > slides_container.height()) {
slides_container.animate({'height': next.height()}, 250, 'linear', start_animation);
} else {
start_animation();
}
};
self.next = function(e) {
e.stopImmediatePropagation();
e.preventDefault();
self._goto(idx + 1);
};
self.prev = function(e) {
e.stopImmediatePropagation();
e.preventDefault();
self._goto(idx - 1);
};
self.link_custom = function(e) {
e.preventDefault();
var link = $(this).attr('data-orbit-link');
if ((typeof link === 'string') && (link = $.trim(link)) != "") {
var slide = container.find('[data-orbit-slide='+link+']');
if (slide.index() != -1) {self._goto(slide.index());}
}
};
self.link_bullet = function(e) {
var index = $(this).attr('data-orbit-slide');
if ((typeof index === 'string') && (index = $.trim(index)) != "") {
self._goto(index);
}
}
self.timer_callback = function() {
self._goto(idx + 1, true);
}
self.compute_dimensions = function() {
var current = $(slides_container.children().get(idx));
var h = current.height();
if (!settings.variable_height) {
slides_container.children().each(function(){
if ($(this).height() > h) { h = $(this).height(); }
});
}
slides_container.height(h);
};
self.create_timer = function() {
var t = new Timer(
container.find('.'+settings.timer_container_class),
settings,
self.timer_callback
);
return t;
};
self.stop_timer = function() {
if (typeof timer === 'object') timer.stop();
};
self.toggle_timer = function() {
var t = container.find('.'+settings.timer_container_class);
if (t.hasClass(settings.timer_paused_class)) {
if (typeof timer === 'undefined') {timer = self.create_timer();}
timer.start();
}
else {
if (typeof timer === 'object') {timer.stop();}
}
};
self.init = function() {
self.build_markup();
if (settings.timer) {timer = self.create_timer(); timer.start();}
animate = new FadeAnimation(slides_container);
if (settings.animation === 'slide')
animate = new SlideAnimation(slides_container);
container.on('click', '.'+settings.next_class, self.next);
container.on('click', '.'+settings.prev_class, self.prev);
container.on('click', self.toggle_timer);
container.on('touchstart.fndtn.orbit', function(e) {
if (!e.touches) {e = e.originalEvent;}
var data = {
start_page_x: e.touches[0].pageX,
start_page_y: e.touches[0].pageY,
start_time: (new Date()).getTime(),
delta_x: 0,
is_scrolling: undefined
};
container.data('swipe-transition', data);
e.stopPropagation();
})
.on('touchmove.fndtn.orbit', function(e) {
if (!e.touches) { e = e.originalEvent; }
// Ignore pinch/zoom events
if(e.touches.length > 1 || e.scale && e.scale !== 1) return;
var data = container.data('swipe-transition');
if (typeof data === 'undefined') {data = {};}
data.delta_x = e.touches[0].pageX - data.start_page_x;
if ( typeof data.is_scrolling === 'undefined') {
data.is_scrolling = !!( data.is_scrolling || Math.abs(data.delta_x) < Math.abs(e.touches[0].pageY - data.start_page_y) );
}
if (!data.is_scrolling && !data.active) {
e.preventDefault();
var direction = (data.delta_x < 0) ? (idx+1) : (idx-1);
data.active = true;
self._goto(direction);
}
})
.on('touchend.fndtn.orbit', function(e) {
container.data('swipe-transition', {});
e.stopPropagation();
})
.on('mouseenter.fndtn.orbit', function(e) {
if (settings.timer && settings.pause_on_hover) {
self.stop_timer();
}
})
.on('mouseleave.fndtn.orbit', function(e) {
if (settings.timer && settings.resume_on_mouseout) {
timer.start();
}
});
$(document).on('click', '[data-orbit-link]', self.link_custom);
$(document).on('click', '[data-orbit-slide]', self.link_bullet)
$(window).on('resize', self.compute_dimensions);
$(window).on('load', self.compute_dimensions);
slides_container.trigger('orbit:ready');
};
self.init();
};
var Timer = function(el, settings, callback) {
var self = this,
duration = settings.timer_speed,
progress = el.find('.'+settings.timer_progress_class),
start,
timeout,
left = -1;
this.update_progress = function(w) {
var new_progress = progress.clone();
new_progress.attr('style', '');
new_progress.css('width', w+'%');
progress.replaceWith(new_progress);
progress = new_progress;
};
this.restart = function() {
clearTimeout(timeout);
el.addClass(settings.timer_paused_class);
left = -1;
self.update_progress(0);
};
this.start = function() {
if (!el.hasClass(settings.timer_paused_class)) {return true;}
left = (left === -1) ? duration : left;
el.removeClass(settings.timer_paused_class);
start = new Date().getTime();
progress.animate({'width': '100%'}, left, 'linear');
timeout = setTimeout(function() {
self.restart();
callback();
}, left);
el.trigger('orbit:timer-started')
};
this.stop = function() {
if (el.hasClass(settings.timer_paused_class)) {return true;}
clearTimeout(timeout);
el.addClass(settings.timer_paused_class);
var end = new Date().getTime();
left = left - (end - start);
var w = 100 - ((left / duration) * 100);
self.update_progress(w);
el.trigger('orbit:timer-stopped');
};
};
var SlideAnimation = function(container) {
var duration = 400;
this.next = function(current, next, callback) {
next.animate({'marginLeft': '0%'}, duration, 'linear', function() {
current.css('marginLeft', '100%');
callback();
});
};
this.prev = function(current, prev, callback) {
prev.css('marginLeft', '-100%');
prev.animate({'marginLeft':'0%'}, duration, 'linear', function() {
current.css('marginLeft', '100%');
callback();
});
};
};
var FadeAnimation = function(container) {
var duration = 250;
this.next = function(current, next, callback) {
next.css({'marginLeft':'0%', 'opacity':'0.01'});
next.animate({'opacity':'1'}, duration, 'linear', function() {
current.css('marginLeft', '100%');
callback();
});
};
this.prev = function(current, prev, callback) {
prev.css({'marginLeft':'0%', 'opacity':'0.01'});
prev.animate({'opacity':'1'}, duration, 'linear', function() {
current.css('marginLeft', '100%');
callback();
});
};
};
Foundation.libs = Foundation.libs || {};
Foundation.libs.orbit = {
name: 'orbit',
version: '4.3.0',
settings: {
animation: 'slide',
timer_speed: 10000,
pause_on_hover: true,
resume_on_mouseout: false,
animation_speed: 500,
stack_on_small: false,
navigation_arrows: true,
slide_number: true,
container_class: 'orbit-container',
stack_on_small_class: 'orbit-stack-on-small',
next_class: 'orbit-next',
prev_class: 'orbit-prev',
timer_container_class: 'orbit-timer',
timer_paused_class: 'paused',
timer_progress_class: 'orbit-progress',
slides_container_class: 'orbit-slides-container',
bullets_container_class: 'orbit-bullets',
bullets_active_class: 'active',
slide_number_class: 'orbit-slide-number',
caption_class: 'orbit-caption',
active_slide_class: 'active',
orbit_transition_class: 'orbit-transitioning',
bullets: true,
timer: true,
variable_height: false,
before_slide_change: noop,
after_slide_change: noop
},
init: function (scope, method, options) {
var self = this;
Foundation.inherit(self, 'data_options');
if (typeof method === 'object') {
$.extend(true, self.settings, method);
}
if ($(scope).is('[data-orbit]')) {
var $el = $(scope);
var opts = self.data_options($el);
new Orbit($el, $.extend({},self.settings, opts));
}
$('[data-orbit]', scope).each(function(idx, el) {
var $el = $(el);
var opts = self.data_options($el);
new Orbit($el, $.extend({},self.settings, opts));
});
}
};
}(Foundation.zj, this, this.document));