/*! Superslides - v0.6.2 - 2013-07-10
* https://github.com/nicinabox/superslides
* Copyright (c) 2013 Nic Aitch; Licensed MIT */
(function(window, $) {
var Superslides, plugin = 'superslides';
Superslides = function(el, options) {
this.options = $.extend({
play: 4000,
animation_speed: 600,
animation_easing: 'swing',
animation: 'slide',
inherit_width_from: window,
inherit_height_from: window,
pagination: false,
hashchange: false,
scrollable: false,
elements: {
preserve: '.preserve',
nav: '.slides-navigation',
container: '.slides-container',
pagination: '.slides-pagination'
}
}, options);
var that = this,
$control = $('
', { "class": 'slides-control' }),
multiplier = 1;
this.$el = $(el);
this.$container = this.$el.find(this.options.elements.container);
// Private Methods
var initialize = function() {
multiplier = that._findMultiplier();
that.$el.on('click', that.options.elements.nav + " a", function(e) {
e.preventDefault();
that.stop();
if ($(this).hasClass('next')) {
that.animate('next', function() {
that.start();
});
} else {
that.animate('prev', function() {
that.start();
});
}
});
$(document).on('keyup', function(e) {
if (e.keyCode === 37) {
that.animate('prev');
}
if (e.keyCode === 39) {
that.animate('next');
}
});
$(window).on('resize', function() {
setTimeout(function() {
var $children = that.$container.children();
that.width = that._findWidth();
that.height = that._findHeight();
$children.css({
width: that.width,
left: that.width
});
that.css.containers();
that.css.images();
}, 10);
});
$(window).on('hashchange', function() {
var hash = that._parseHash(), index;
if (hash && !isNaN(hash)) {
// Minus 1 here because we don't want the url
// to be zero-indexed
index = that._upcomingSlide(hash - 1);
} else {
index = that._upcomingSlide(hash);
}
if (index >= 0 && index !== that.current) {
that.animate(index);
}
});
that.pagination._events();
that.start();
return that;
};
var css = {
containers: function() {
if (that.init) {
that.$el.css({
height: that.height
});
that.$control.css({
width: that.width * multiplier,
left: -that.width
});
that.$container.css({
});
} else {
$('body').css({
margin: 0
});
that.$el.css({
position: 'relative',
overflow: 'hidden',
width: '100%',
height: that.height
});
that.$control.css({
position: 'relative',
transform: 'translate3d(0)',
height: '100%',
width: that.width * multiplier,
left: -that.width
});
that.$container.css({
display: 'none',
margin: '0',
padding: '0',
listStyle: 'none',
position: 'relative',
height: '100%'
});
}
if (that.size() === 1) {
that.$el.find(that.options.elements.nav).hide();
}
},
images: function() {
var $images = that.$container.find('img')
.not(that.options.elements.preserve)
$images.removeAttr('width').removeAttr('height')
.css({
"-webkit-backface-visibility": 'hidden',
"-ms-interpolation-mode": 'bicubic',
"position": 'absolute',
"left": '0',
"top": '0',
"z-index": '-1',
"max-width": 'none'
});
$images.each(function() {
var image_aspect_ratio = that.image._aspectRatio(this),
image = this;
if (!$.data(this, 'processed')) {
var img = new Image();
img.onload = function() {
that.image._scale(image, image_aspect_ratio);
that.image._center(image, image_aspect_ratio);
$.data(image, 'processed', true);
};
img.src = this.src;
} else {
that.image._scale(image, image_aspect_ratio);
that.image._center(image, image_aspect_ratio);
}
});
},
children: function() {
var $children = that.$container.children();
if ($children.is('img')) {
$children.each(function() {
if ($(this).is('img')) {
$(this).wrap('
');
// move id attribute
var id = $(this).attr('id');
$(this).removeAttr('id');
$(this).parent().attr('id', id);
}
});
$children = that.$container.children();
}
if (!that.init) {
$children.css({
display: 'none',
left: that.width * 2
});
}
$children.css({
position: 'absolute',
overflow: 'hidden',
height: '100%',
width: that.width,
top: 0,
zIndex: 0
});
}
}
var fx = {
slide: function(orientation, complete) {
var $children = that.$container.children(),
$target = $children.eq(orientation.upcoming_slide);
$target.css({
left: orientation.upcoming_position,
display: 'block'
});
that.$control.animate({
left: orientation.offset
},
that.options.animation_speed,
that.options.animation_easing,
function() {
if (that.size() > 1) {
that.$control.css({
left: -that.width
});
$children.eq(orientation.upcoming_slide).css({
left: that.width,
zIndex: 2
});
if (orientation.outgoing_slide >= 0) {
$children.eq(orientation.outgoing_slide).css({
left: that.width,
display: 'none',
zIndex: 0
});
}
}
complete();
});
},
fade: function(orientation, complete) {
var that = this,
$children = that.$container.children(),
$outgoing = $children.eq(orientation.outgoing_slide),
$target = $children.eq(orientation.upcoming_slide);
$target.css({
left: this.width,
opacity: 1,
display: 'block'
});
if (orientation.outgoing_slide >= 0) {
$outgoing.animate({
opacity: 0
},
that.options.animation_speed,
that.options.animation_easing,
function() {
if (that.size() > 1) {
$children.eq(orientation.upcoming_slide).css({
zIndex: 2
});
if (orientation.outgoing_slide >= 0) {
$children.eq(orientation.outgoing_slide).css({
opacity: 1,
display: 'none',
zIndex: 0
});
}
}
complete();
});
} else {
$target.css({
zIndex: 2
});
complete();
}
}
};
fx = $.extend(fx, $.fn.superslides.fx);
var image = {
_centerY: function(image) {
var $img = $(image);
$img.css({
top: (that.height - $img.height()) / 2
});
},
_centerX: function(image) {
var $img = $(image);
$img.css({
left: (that.width - $img.width()) / 2
});
},
_center: function(image) {
that.image._centerX(image);
that.image._centerY(image);
},
_aspectRatio: function(image) {
if (!image.naturalHeight && !image.naturalWidth) {
var img = new Image();
img.src = image.src;
image.naturalHeight = img.height;
image.naturalWidth = img.width;
}
return image.naturalHeight / image.naturalWidth;
},
_scale: function(image, image_aspect_ratio) {
image_aspect_ratio = image_aspect_ratio || that.image._aspectRatio(image);
var container_aspect_ratio = that.height / that.width,
$img = $(image);
if (container_aspect_ratio > image_aspect_ratio) {
$img.css({
height: that.height,
width: that.height / image_aspect_ratio
});
} else {
$img.css({
height: that.width * image_aspect_ratio,
width: that.width
});
}
}
};
var pagination = {
_setCurrent: function(i) {
if (!that.$pagination) { return; }
var $pagination_children = that.$pagination.children();
$pagination_children.removeClass('current');
$pagination_children.eq(i)
.addClass('current');
},
_addItem: function(i) {
var slide_number = i + 1,
href = slide_number,
$slide = that.$container.children().eq(i),
slide_id = $slide.attr('id');
if (slide_id) {
href = slide_id;
}
var $item = $("
", {
'href': "#" + href,
'text': href
});
$item.appendTo(that.$pagination);
},
_setup: function() {
if (!that.options.pagination || that.size() === 1) { return; }
var $pagination = $("