2 (function ($, window
, document
, undefined) {
5 var noop = function () {
8 var Orbit = function (el
, settings
) {
9 // Don't reinitialize plugin
10 if (el
.hasClass(settings
.slides_container_class
)) {
16 slides_container
= el
,
24 adjust_height_after
= false;
27 self
.slides = function () {
28 return slides_container
.children(settings
.slide_selector
);
31 self
.slides().first().addClass(settings
.active_slide_class
);
33 self
.update_slide_number = function (index
) {
34 if (settings
.slide_number
) {
35 number_container
.find('span:first').text(parseInt(index
) + 1);
36 number_container
.find('span:last').text(self
.slides().length
);
38 if (settings
.bullets
) {
39 bullets_container
.children().removeClass(settings
.bullets_active_class
);
40 $(bullets_container
.children().get(index
)).addClass(settings
.bullets_active_class
);
44 self
.update_active_link = function (index
) {
45 var link
= $('[data-orbit-link="' + self
.slides().eq(index
).attr('data-orbit-slide') + '"]');
46 link
.siblings().removeClass(settings
.bullets_active_class
);
47 link
.addClass(settings
.bullets_active_class
);
50 self
.build_markup = function () {
51 slides_container
.wrap('<div class="' + settings
.container_class
+ '"></div>');
52 container
= slides_container
.parent();
53 slides_container
.addClass(settings
.slides_container_class
);
55 if (settings
.stack_on_small
) {
56 container
.addClass(settings
.stack_on_small_class
);
59 if (settings
.navigation_arrows
) {
60 container
.append($('<a href="#"><span></span></a>').addClass(settings
.prev_class
));
61 container
.append($('<a href="#"><span></span></a>').addClass(settings
.next_class
));
65 timer_container
= $('<div>').addClass(settings
.timer_container_class
);
66 timer_container
.append('<span>');
67 timer_container
.append($('<div>').addClass(settings
.timer_progress_class
));
68 timer_container
.addClass(settings
.timer_paused_class
);
69 container
.append(timer_container
);
72 if (settings
.slide_number
) {
73 number_container
= $('<div>').addClass(settings
.slide_number_class
);
74 number_container
.append('<span></span> ' + settings
.slide_number_text
+ ' <span></span>');
75 container
.append(number_container
);
78 if (settings
.bullets
) {
79 bullets_container
= $('<ol>').addClass(settings
.bullets_container_class
);
80 container
.append(bullets_container
);
81 bullets_container
.wrap('<div class="orbit-bullets-container"></div>');
82 self
.slides().each(function (idx
, el
) {
83 var bullet
= $('<li>').attr('data-orbit-slide', idx
).on('click', self
.link_bullet
);
85 bullets_container
.append(bullet
);
91 self
._goto = function (next_idx
, start_timer
) {
92 // if (locked) {return false;}
93 if (next_idx
=== idx
) {
96 if (typeof timer
=== 'object') {
99 var slides
= self
.slides();
103 if (next_idx
< idx
) {
106 if (next_idx
>= slides
.length
) {
107 if (!settings
.circular
) return false;
109 } else if (next_idx
< 0) {
110 if (!settings
.circular
) return false;
111 next_idx
= slides
.length
- 1;
114 var current
= $(slides
.get(idx
));
115 var next
= $(slides
.get(next_idx
));
117 current
.css('zIndex', 2);
118 current
.removeClass(settings
.active_slide_class
);
119 next
.css('zIndex', 4).addClass(settings
.active_slide_class
);
121 slides_container
.trigger('before-slide-change.fndtn.orbit');
122 settings
.before_slide_change();
123 self
.update_active_link(next_idx
);
125 var callback = function () {
126 var unlock = function () {
129 if (start_timer
=== true) {
130 timer
= self
.create_timer();
133 self
.update_slide_number(idx
);
134 slides_container
.trigger('after-slide-change.fndtn.orbit', [{
136 total_slides
: slides
.length
138 settings
.after_slide_change(idx
, slides
.length
);
140 if (slides_container
.height() != next
.height() && settings
.variable_height
) {
141 slides_container
.animate({'height': next
.height()}, 250, 'linear', unlock
);
147 if (slides
.length
=== 1) {
152 var start_animation = function () {
153 if (dir
=== 'next') {
154 animate
.next(current
, next
, callback
);
156 if (dir
=== 'prev') {
157 animate
.prev(current
, next
, callback
);
161 if (next
.height() > slides_container
.height() && settings
.variable_height
) {
162 slides_container
.animate({'height': next
.height()}, 250, 'linear', start_animation
);
168 self
.next = function (e
) {
169 e
.stopImmediatePropagation();
174 self
.prev = function (e
) {
175 e
.stopImmediatePropagation();
180 self
.link_custom = function (e
) {
182 var link
= $(this).attr('data-orbit-link');
183 if ((typeof link
=== 'string') && (link
= $.trim(link
)) != '') {
184 var slide
= container
.find('[data-orbit-slide=' + link
+ ']');
185 if (slide
.index() != -1) {
186 self
._goto(slide
.index());
191 self
.link_bullet = function (e
) {
192 var index
= $(this).attr('data-orbit-slide');
193 if ((typeof index
=== 'string') && (index
= $.trim(index
)) != '') {
194 if (isNaN(parseInt(index
))) {
195 var slide
= container
.find('[data-orbit-slide=' + index
+ ']');
196 if (slide
.index() != -1) {
197 self
._goto(slide
.index() + 1);
201 self
._goto(parseInt(index
));
207 self
.timer_callback = function () {
208 self
._goto(idx
+ 1, true);
211 self
.compute_dimensions = function () {
212 var current
= $(self
.slides().get(idx
));
213 var h
= current
.height();
214 if (!settings
.variable_height
) {
215 self
.slides().each(function () {
216 if ($(this).height() > h
) {
217 h
= $(this).height();
221 slides_container
.height(h
);
224 self
.create_timer = function () {
226 container
.find('.' + settings
.timer_container_class
),
233 self
.stop_timer = function () {
234 if (typeof timer
=== 'object') timer
.stop();
237 self
.toggle_timer = function () {
238 var t
= container
.find('.' + settings
.timer_container_class
);
239 if (t
.hasClass(settings
.timer_paused_class
)) {
240 if (typeof timer
=== 'undefined') {
241 timer
= self
.create_timer();
246 if (typeof timer
=== 'object') {
252 self
.init = function () {
254 if (settings
.timer
) {
255 timer
= self
.create_timer();
256 Foundation
.utils
.image_loaded(this.slides().children('img'), timer
.start
);
258 animate
= new FadeAnimation(settings
, slides_container
);
259 if (settings
.animation
=== 'slide')
260 animate
= new SlideAnimation(settings
, slides_container
);
262 container
.on('click', '.' + settings
.next_class
, self
.next
);
263 container
.on('click', '.' + settings
.prev_class
, self
.prev
);
265 if (settings
.next_on_click
) {
266 container
.on('click', '.' + settings
.slides_container_class
+ ' [data-orbit-slide]', self
.link_bullet
);
269 container
.on('click', self
.toggle_timer
);
270 if (settings
.swipe
) {
271 container
.on('touchstart.fndtn.orbit', function (e
) {
276 start_page_x
: e
.touches
[0].pageX
,
277 start_page_y
: e
.touches
[0].pageY
,
278 start_time
: (new Date()).getTime(),
280 is_scrolling
: undefined
282 container
.data('swipe-transition', data
);
285 .on('touchmove.fndtn.orbit', function (e
) {
289 // Ignore pinch/zoom events
290 if (e
.touches
.length
> 1 || e
.scale
&& e
.scale
!== 1) return;
292 var data
= container
.data('swipe-transition');
293 if (typeof data
=== 'undefined') {
297 data
.delta_x
= e
.touches
[0].pageX
- data
.start_page_x
;
299 if (typeof data
.is_scrolling
=== 'undefined') {
300 data
.is_scrolling
= !!( data
.is_scrolling
|| Math
.abs(data
.delta_x
) < Math
.abs(e
.touches
[0].pageY
- data
.start_page_y
) );
303 if (!data
.is_scrolling
&& !data
.active
) {
305 var direction
= (data
.delta_x
< 0) ? (idx
+ 1) : (idx
- 1);
307 self
._goto(direction
);
310 .on('touchend.fndtn.orbit', function (e
) {
311 container
.data('swipe-transition', {});
315 container
.on('mouseenter.fndtn.orbit', function (e
) {
316 if (settings
.timer
&& settings
.pause_on_hover
) {
320 .on('mouseleave.fndtn.orbit', function (e
) {
321 if (settings
.timer
&& settings
.resume_on_mouseout
) {
326 $(document
).on('click', '[data-orbit-link]', self
.link_custom
);
327 $(window
).on('load resize', self
.compute_dimensions
);
328 Foundation
.utils
.image_loaded(this.slides().children('img'), self
.compute_dimensions
);
329 Foundation
.utils
.image_loaded(this.slides().children('img'), function () {
330 container
.prev('.' + settings
.preloader_class
).css('display', 'none');
331 self
.update_slide_number(0);
332 self
.update_active_link(0);
333 slides_container
.trigger('ready.fndtn.orbit');
340 var Timer = function (el
, settings
, callback
) {
342 duration
= settings
.timer_speed
,
343 progress
= el
.find('.' + settings
.timer_progress_class
),
348 this.update_progress = function (w
) {
349 var new_progress
= progress
.clone();
350 new_progress
.attr('style', '');
351 new_progress
.css('width', w
+ '%');
352 progress
.replaceWith(new_progress
);
353 progress
= new_progress
;
356 this.restart = function () {
357 clearTimeout(timeout
);
358 el
.addClass(settings
.timer_paused_class
);
360 self
.update_progress(0);
363 this.start = function () {
364 if (!el
.hasClass(settings
.timer_paused_class
)) {
367 left
= (left
=== -1) ? duration
: left
;
368 el
.removeClass(settings
.timer_paused_class
);
369 start
= new Date().getTime();
370 progress
.animate({'width': '100%'}, left
, 'linear');
371 timeout
= setTimeout(function () {
375 el
.trigger('timer-started.fndtn.orbit')
378 this.stop = function () {
379 if (el
.hasClass(settings
.timer_paused_class
)) {
382 clearTimeout(timeout
);
383 el
.addClass(settings
.timer_paused_class
);
384 var end
= new Date().getTime();
385 left
= left
- (end
- start
);
386 var w
= 100 - ((left
/ duration
) * 100);
387 self
.update_progress(w
);
388 el
.trigger('timer-stopped.fndtn.orbit');
392 var SlideAnimation = function (settings
, container
) {
393 var duration
= settings
.animation_speed
;
394 var is_rtl
= ($('html[dir=rtl]').length
=== 1);
395 var margin
= is_rtl
? 'marginRight' : 'marginLeft';
397 animMargin
[margin
] = '0%';
399 this.next = function (current
, next
, callback
) {
400 current
.animate({marginLeft
: '-100%'}, duration
);
401 next
.animate(animMargin
, duration
, function () {
402 current
.css(margin
, '100%');
407 this.prev = function (current
, prev
, callback
) {
408 current
.animate({marginLeft
: '100%'}, duration
);
409 prev
.css(margin
, '-100%');
410 prev
.animate(animMargin
, duration
, function () {
411 current
.css(margin
, '100%');
417 var FadeAnimation = function (settings
, container
) {
418 var duration
= settings
.animation_speed
;
419 var is_rtl
= ($('html[dir=rtl]').length
=== 1);
420 var margin
= is_rtl
? 'marginRight' : 'marginLeft';
422 this.next = function (current
, next
, callback
) {
423 next
.css({'margin': '0%', 'opacity': '0.01'});
424 next
.animate({'opacity': '1'}, duration
, 'linear', function () {
425 current
.css('margin', '100%');
430 this.prev = function (current
, prev
, callback
) {
431 prev
.css({'margin': '0%', 'opacity': '0.01'});
432 prev
.animate({'opacity': '1'}, duration
, 'linear', function () {
433 current
.css('margin', '100%');
440 Foundation
.libs
= Foundation
.libs
|| {};
442 Foundation
.libs
.orbit
= {
450 pause_on_hover
: true,
451 resume_on_mouseout
: false,
453 animation_speed
: 500,
454 stack_on_small
: false,
455 navigation_arrows
: true,
457 slide_number_text
: 'of',
458 container_class
: 'orbit-container',
459 stack_on_small_class
: 'orbit-stack-on-small',
460 next_class
: 'orbit-next',
461 prev_class
: 'orbit-prev',
462 timer_container_class
: 'orbit-timer',
463 timer_paused_class
: 'paused',
464 timer_progress_class
: 'orbit-progress',
465 slides_container_class
: 'orbit-slides-container',
466 preloader_class
: 'preloader',
468 bullets_container_class
: 'orbit-bullets',
469 bullets_active_class
: 'active',
470 slide_number_class
: 'orbit-slide-number',
471 caption_class
: 'orbit-caption',
472 active_slide_class
: 'active',
473 orbit_transition_class
: 'orbit-transitioning',
477 variable_height
: false,
479 before_slide_change
: noop
,
480 after_slide_change
: noop
483 init: function (scope
, method
, options
) {
485 this.bindings(method
, options
);
488 events: function (instance
) {
489 var orbit_instance
= new Orbit(this.S(instance
), this.S(instance
).data('orbit-init'));
490 this.S(instance
).data(this.name
+ '-instance', orbit_instance
);
493 reflow: function () {
496 if (self
.S(self
.scope
).is('[data-orbit]')) {
497 var $el
= self
.S(self
.scope
);
498 var instance
= $el
.data(self
.name
+ '-instance');
499 instance
.compute_dimensions();
501 self
.S('[data-orbit]', self
.scope
).each(function (idx
, el
) {
502 var $el
= self
.S(el
);
503 var opts
= self
.data_options($el
);
504 var instance
= $el
.data(self
.name
+ '-instance');
505 instance
.compute_dimensions();
512 }(jQuery
, window
, window
.document
));