/*! reflection.js for jquery v1.12 */ ; (function($) { $.fn.reflect = function(options) { options = $.extend({ height: 1 / 3, opacity: 0.5 }, options); return this.unreflect().each(function() { var img = this; if (/^img$/i.test(img.tagname)) { function doreflect() { var imagewidth = img.width, imageheight = img.height, reflection, reflectionheight, wrapper, context, gradient; reflectionheight = math.floor((options.height > 1) ? math.min(imageheight, options.height) : imageheight * options.height); reflection = $("")[0]; if (reflection.getcontext) { context = reflection.getcontext("2d"); try { $(reflection).attr({ width: imagewidth, height: reflectionheight }); context.save(); context.translate(0, imageheight - 1); context.scale(1, -1); context.drawimage(img, 0, 0, imagewidth, imageheight); context.restore(); context.globalcompositeoperation = "destination-out"; gradient = context.createlineargradient(0, 0, 0, reflectionheight); gradient.addcolorstop(0, "rgba(255, 255, 255, " + (1 - options.opacity) + ")"); gradient.addcolorstop(1, "rgba(255, 255, 255, 1.0)"); context.fillstyle = gradient; context.rect(0, 0, imagewidth, reflectionheight); context.fill(); } catch (e) { return; } } else { if (!window.activexobject) return; reflection = $("").attr("src", img.src).css({ width: imagewidth, height: imageheight, marginbottom: reflectionheight - imageheight, filter: "flipv progid:dximagetransform.microsoft.alpha(opacity=" + (options.opacity * 100) + ", finishopacity=0, style=1, startx=0, starty=0, finishx=0, finishy=" + (reflectionheight / imageheight * 100) + ")" })[0]; } $(reflection).css({ display: "block", border: 0 }); wrapper = $(/^a$/i.test(img.parentnode.tagname) ? "" : "
").insertafter(img).append([img, reflection])[0]; wrapper.classname = img.classname; $(img).data("reflected", wrapper.style.csstext = img.style.csstext); $(wrapper).css({ width: imagewidth, height: imageheight + reflectionheight, overflow: "hidden" }); img.style.csstext = "display: block; border: 0px"; img.classname = "reflected"; } if (img.complete) doreflect(); else $(img).load(doreflect); } }); } $.fn.unreflect = function() { return this.unbind("load").each(function() { var img = this, reflected = $(this).data("reflected"), wrapper; if (reflected !== undefined) { wrapper = img.parentnode; img.classname = wrapper.classname; img.style.csstext = reflected; $(img).data("reflected", null); wrapper.parentnode.replacechild(img, wrapper); } }); } })(window.jquery || window.zepto); (function($) { var transform = (function() { var vendors = ['webkit', 'moz', 'ms']; var style = document.createelement("div").style; var trans = 'transform' in style ? 'transform' : undefined; for (var i = 0, count = vendors.length; i < count; i++) { var prop = vendors[i] + 'transform'; if (prop in style) { trans = prop; break; } } return trans; })(); var item = function(element, options) { element.item = this; this.element = element; if (element.tagname === 'img') { this.fullwidth = element.width; this.fullheight = element.height; } else { element.style.display = "inline-block"; this.fullwidth = element.offsetwidth; this.fullheight = element.offsetheight; } element.style.position = 'absolute'; if (options.mirror && this.element.tagname === 'img') { this.reflection = $(element).reflect(options.mirror).next()[0]; var $reflection = $(this.reflection); this.reflection.fullheight = $reflection.height(); $reflection.css('margin-top', options.mirror.gap + 'px'); $reflection.css('width', '100%'); element.style.width = "100%"; this.element = this.element.parentnode; this.element.item = this; this.element.alt = element.alt; this.element.title = element.title; } if (transform && options.transforms) this.element.style[transform + "origin"] = "0 0"; this.moveto = function(x, y, scale) { this.width = this.fullwidth * scale; this.height = this.fullheight * scale; this.x = x; this.y = y; this.scale = scale; var style = this.element.style; style.zindex = "" + (scale * 100) | 0; if (transform && options.transforms) { style[transform] = "translate(" + x + "px, " + y + "px) scale(" + scale + ")"; } else { if (options.mirror && this.element.tagname === 'img') this.reflection.style.margintop = (options.mirror.gap * scale) + "px"; style.width = this.width + "px"; style.left = x + "px"; style.top = y + "px"; } } } var time = !window.performance || !window.performance.now ? function() { return +new date() } : function() { return performance.now() }; var cancelframe = window.cancelanimationframe || window.cancelrequestanimationframe; var requestframe = window.requestanimationframe; (function() { var vendors = ['webkit', 'moz', 'ms']; for (var i = 0, count = vendors.length; i < count && !cancelframe; i++) { cancelframe = window[vendors[i] + 'cancelanimationframe'] || window[vendors[i] + 'cancelrequestanimationframe']; requestframe = requestframe && window[vendors[i] + 'requestanimationframe']; } }()); var carousel = function(element, options) { var self = this; var $container = $(element); this.items = []; this.xorigin = (options.xorigin === null) ? $container.width() * 0.5 : options.xorigin; this.yorigin = (options.yorigin === null) ? $container.height() * 0.1 : options.yorigin; this.xradius = (options.xradius === null) ? $container.width() / 2.3 : options.xradius; this.yradius = (options.yradius === null) ? $container.height() / 6 : options.yradius; this.farscale = options.farscale; this.rotation = this.destrotation = math.pi / 2; this.speed = options.speed; this.smooth = options.smooth; this.fps = options.fps; this.timer = 0; this.autoplayamount = options.autoplay; this.autoplaydelay = options.autoplaydelay; this.autoplaytimer = 0; this.frontitemclass = options.frontitemclass; this.onloaded = options.onloaded; this.onrendered = options.onrendered; this.onanimationfinished = options.onanimationfinished; this.itemoptions = { transforms: options.transforms } if (options.mirror) { this.itemoptions.mirror = $.extend({ gap: 2 }, options.mirror); } $container.css({ position: 'relative', overflow: 'hidden' }); this.renderitem = function(itemindex, rotation) { var item = this.items[itemindex]; var sin = math.sin(rotation); var farscale = this.farscale; var scale = farscale + ((1 - farscale) * (sin + 1) * 0.5); item.moveto(this.xorigin + (scale * ((math.cos(rotation) * this.xradius) - (item.fullwidth * 0.5))), this.yorigin + (scale * sin * this.yradius), scale); return item; } this.render = function() { var count = this.items.length; var spacing = 2 * math.pi / count; var radians = this.rotation; var nearest = this.nearestindex(); for (var i = 0; i < count; i++) { var item = this.renderitem(i, radians); if (i === nearest) $(item.element).addclass(this.frontitemclass); else $(item.element).removeclass(this.frontitemclass); radians += spacing; } if (typeof this.onrendered === 'function') this.onrendered(this); } this.playframe = function() { var rem = self.destrotation - self.rotation; var now = time(); var dt = (now - self.lasttime) * 0.002; self.lasttime = now; if (math.abs(rem) < 0.003) { self.rotation = self.destrotation; self.pause(); if (typeof self.onanimationfinished === 'function') self.onanimationfinished(); } else { self.rotation = self.destrotation - rem / (1 + (self.speed * dt)); self.schedulenextframe(); } self.render(); } this.schedulenextframe = function() { this.lasttime = time(); this.timer = this.smooth && cancelframe ? requestframe(self.playframe) : settimeout(self.playframe, 1000 / this.fps); } this.itemsrotated = function() { return this.items.length * ((math.pi / 2) - this.rotation) / (2 * math.pi); } this.floatindex = function() { var count = this.items.length; var floatindex = this.itemsrotated() % count; return (floatindex < 0) ? floatindex + count : floatindex; } this.nearestindex = function() { return math.round(this.floatindex()) % this.items.length; } this.nearestitem = function() { return this.items[this.nearestindex()]; } this.play = function() { if (this.timer === 0) this.schedulenextframe(); } this.pause = function() { this.smooth && cancelframe ? cancelframe(this.timer) : cleartimeout(this.timer); this.timer = 0; } this.go = function(count) { this.destrotation += (2 * math.pi / this.items.length) * count; this.play(); } this.goto = function(index) { var count = this.items.length; var diff = index - (this.floatindex() % count); if (2 * math.abs(diff) > count) diff -= (diff > 0) ? count : -count; this.destrotation = this.rotation; this.go(-diff); return diff; } this.deactivate = function() { this.pause(); clearinterval(this.autoplaytimer); if (options.buttonleft) options.buttonleft.unbind('click'); if (options.buttonright) options.buttonright.unbind('click'); $container.unbind('.cloud9'); } this.autoplay = function() { this.autoplaytimer = setinterval(function() { self.go(self.autoplayamount) }, this.autoplaydelay); } this.enableautoplay = function() { $container.bind('mouseover.cloud9', function() { clearinterval(self.autoplaytimer); }); $container.bind('mouseout.cloud9', function() { self.autoplay(); }); this.autoplay(); } this.bindcontrols = function() { if (options.buttonleft) { options.buttonleft.bind('click', function() { self.go(-1); return false; }); } if (options.buttonright) { options.buttonright.bind('click', function() { self.go(1); return false; }); } if (options.mousewheel) { $container.bind('mousewheel.cloud9', function(event, delta) { self.go((delta > 0) ? 1 : -1); return false; }); } if (options.bringtofront) { $container.bind('click.cloud9', function(event) { var hits = $(event.target).closest('.' + options.itemclass); if (hits.length !== 0) { var diff = self.goto(self.items.indexof(hits[0].item)); if (math.abs(diff) > 0.5) event.preventdefault(); } }); } } var items = $container.find('.' + options.itemclass); this.finishinit = function() { for (var i = 0; i < items.length; i++) { var item = items[i]; if ((item.tagname === 'img') && ((item.width === undefined) || ((item.complete !== undefined) && !item.complete))) return; } clearinterval(this.inittimer); for (i = 0; i < items.length; i++) this.items.push(new item(items[i], this.itemoptions)); $container.bind('mousedown onselectstart', function() { return false }); if (this.autoplayamount !== 0) this.enableautoplay(); this.bindcontrols(); this.render(); if (typeof this.onloaded === 'function') this.onloaded(this); }; this.inittimer = setinterval(function() { self.finishinit() }, 50); } $.fn.cloud9carousel = function(options) { return this.each(function() { options = $.extend({ xorigin: null, yorigin: null, xradius: null, yradius: null, farscale: 0.3, transforms: true, smooth: true, fps: 30, speed: 4, autoplay: 0, autoplaydelay: 3000, bringtofront: true, itemclass: 'cloud9-item', frontitemclass: 'active', handle: 'carousel' }, options); $(this).data(options.handle, new carousel(this, options)); }); } })(window.jquery || window.zepto);