Created
November 21, 2012 12:22
-
-
Save janantala/4124601 to your computer and use it in GitHub Desktop.
Engadget carousel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var eng = {}; | |
eng.carousel = function() { | |
function o() { | |
var e = t.activeIndex + 1; | |
if (!t.cycle) | |
return; | |
e >= t.items.length && (e = 0); | |
u(e) | |
} | |
function u(e) { | |
if (!t.cycle) | |
return; | |
d(); | |
r.stop().fadeOut(); | |
r.eq(e).stop().fadeIn(); | |
s.removeClass("active"); | |
s.eq(e).addClass("active"); | |
t.activeIndex = e; | |
p(); | |
r.eq(t.activeIndex).find("img").loadImage() | |
} | |
function a() { | |
var e = t.items, n, r = e.length, i = [], s = []; | |
for (n = 0; n < r; n += 1) { | |
i.push("<li class='" + (n === 0 ? "active" : "") + "' style='" + "left: " + (1 / r * 100 | 0) * n + "%; " + "width: " + (1 / r * 100 | 0) + "%" + "'>" + "<b></b>" + "<a href=#>" + e[n].tab + "</a>" + "<div class=ribbon><div class=progress></div></div>" + "</li>"); | |
s.push("<li class='" + (n === 0 ? "active" : "") + "'><a href='" + e[n].url + "' style='background: " + e[n].bg + "'>" + "<img " + "src='http://o.aolcdn.com/js/x.gif' " + "data-src='" + e[n].image + "'>" + "<span class=headline>" + e[n].headline + "</span>" + "</a></li>") | |
} | |
s.splice(0, 0, s[s.length - 1]); | |
s.push(s[1]); | |
return ["<div class=slides>", "<div class=scroller>", "<ul>", s.join(""), "</ul>", "</div>", "<div class=s-arrow-white-left></div>", "<div class=s-arrow-white-right></div>", "</div>", "<div class=tabs>", "<ul>", i.join(""), "</ul>", "</div>"].join("") | |
} | |
function f() { | |
h(); | |
if (t.cycle) | |
return; | |
t.cycle = !0; | |
u(t.activeIndex); | |
v() | |
} | |
function l() { | |
t.cycle = !1 | |
} | |
function c() { | |
var e, n; | |
h(); | |
l(); | |
e = t.items.length; | |
$("#carousel div.scroller").width($("#carousel div.scroller li:first").width() * (e + 2)); | |
r.show(); | |
n = new window.iScroll($("#carousel div.scroller")[0], {disableTouchEvents: !1,snap: !0,momentum: !1,hScrollbar: !1,overflow: "hidden",onScrollEnd: function(r) { | |
var o = n.pageX - 1; | |
i.eq(n.pageX).find("img").loadImage(); | |
i.eq(n.pageX + 1).find("img").loadImage(); | |
if (n.pageX === 0) { | |
o = 0; | |
return n.scrollToPage(e, 0, "0ms") | |
} | |
if (n.pageX === e + 1) { | |
o = e; | |
return n.scrollToPage(1, 0, "0ms") | |
} | |
s.removeClass("active").eq(o).addClass("active"); | |
t.activeIndex = o | |
}}); | |
n.scrollToPage(t.activeIndex + 1, 0, "0ms"); | |
t.swipe = n | |
} | |
function h() { | |
if (!t.swipe) | |
return; | |
t.swipe.destroy() | |
} | |
function p() { | |
if (!t.cycle) | |
return; | |
if (n) | |
return; | |
s.eq(t.activeIndex).find("div.progress").stop().animate({width: "100%"}, t.delay, "linear", o) | |
} | |
function d() { | |
if (!t.cycle) | |
return; | |
s.eq(t.activeIndex).find("div.progress").stop().animate({width: 0}, 300) | |
} | |
function v() { | |
s.eq(t.activeIndex).find("div.progress").stop().css("width", 0); | |
p() | |
} | |
function m(t) { | |
if (t >= 768) { | |
e(); | |
f() | |
} else if (t >= 320) { | |
if (!window.Modernizr.cssanimations) { | |
h(); | |
$("#carousel").hide(); | |
return | |
} | |
e(); | |
c() | |
} else { | |
h(); | |
$("#carousel").hide() | |
} | |
} | |
var e, t = {activeIndex: 0,cycle: !1,delay: 1e4,timer: !1}, n, r, i, s; | |
e = function() { | |
var e; | |
return function() { | |
if (e) | |
return e.show(); | |
e = $("#carousel"); | |
e.html(a()); | |
e.find("div.s-arrow-white-left").on("click", function() { | |
t.swipe.scrollToPage("prev", 0) | |
}); | |
e.find("div.s-arrow-white-right").on("click", function() { | |
t.swipe.scrollToPage("next", 0) | |
}); | |
i = e.find("div.slides").find("li"); | |
r = $(i.slice(1, t.items.length + 1)); | |
s = e.find("div.tabs").find("li"); | |
s.find("a").on("click", function() { | |
u(s.index($(this).closest("li")[0])); | |
return !1 | |
}); | |
e.hover(function() { | |
n = !0; | |
d() | |
}, function() { | |
n = !1; | |
p() | |
}) | |
} | |
}(); | |
return {init: function(e) { | |
$.extend(t, e); | |
$.Topic("breakpoint").subscribe(m) | |
},options: t,setBreakpoint: m} | |
}(); | |
</script> | |
<!-- M:header-carousel. --> | |
<div id="carousel"></div> | |
<script>when.eng("eng.carousel.init", {items: [ | |
{ | |
bg: "#4292D9", | |
image: "http://www.blogcdn.com/www.engadget.com/media/2012/11/hero-win8.jpg", | |
tab: "Windows 8", | |
headline: "Windows 8: All you need to know about Microsoft's next big OS", | |
url: "http://www.engadget.com/2012/10/30/windows-8-review/" | |
}, | |
{ | |
bg: "#2c1f5c", | |
image: "http://www.blogcdn.com/www.engadget.com/media/2012/11/nexus-10-slide.jpg", | |
tab: "Nexus 10 review", | |
headline: "Can Google's Nexus 10 live up to the family name?", | |
url: "http://www.engadget.com/2012/11/02/nexus-10-review/" | |
}, | |
{ | |
bg: "#e7f5f9", | |
image: "http://www.blogcdn.com/www.engadget.com/media/2012/11/hgg2.png", | |
tab: "Holiday Gift Guide 2012", | |
headline: "Engadget's list of must-have gear for this holiday season", | |
url: "http://www.engadget.com/holidaygiftguide2012" | |
}, | |
{ | |
bg: "#2a6082", | |
image: "http://www.blogcdn.com/www.engadget.com/media/2012/11/ipad-mini-slide.jpg", | |
tab: "iPad mini review", | |
headline: "For Apple's iPad mini, is smaller really better?", | |
url: "http://www.engadget.com/2012/10/30/apple-ipad-mini-review/" | |
}, | |
{ | |
bg: "#990000", | |
image: "http://www.blogcdn.com/www.engadget.com/media/2012/11/droid-dna-slide.jpg", | |
tab: "Droid DNA review", | |
headline: "HTC's Droid DNA: the new five-inch jewel in Verizon's smartphone crown", | |
url: "http://www.engadget.com/2012/11/16/htc-droid-dna-review/" | |
} | |
]})</script> | |
<!-- /M --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment