Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- for (var b = 0, a = ["ms", "moz", "webkit", "o"], c = 0; c < a.length && !window.requestAnimationFrame; ++c) window.requestAnimationFrame = window[a[c] + "RequestAnimationFrame"], window.cancelAnimationFrame = window[a[c] + "CancelAnimationFrame"] || window[a[c] + "CancelRequestAnimationFrame"];
- window.requestAnimationFrame || (window.requestAnimationFrame = function(a) {
- var c = (new Date).getTime(),
- f = Math.max(0, 16 - (c - b)),
- h = window.setTimeout(function() {
- a(c + f)
- }, f);
- b = c + f;
- return h
- });
- window.cancelAnimationFrame || (window.cancelAnimationFrame =
- function(a) {
- clearTimeout(a)
- })
- })();
- (function() {
- function b(a, b) {
- a ? "function" != typeof a ? console.warn("rafScroll: Invalid callback type.") : (this._scrolling = !1, this._callback = a, this._args = b || [], this.subscribe()) : console.warn("rafScroll: No callback supplied, not initiating.")
- }
- function a(a) {
- this._mostRecentScrollEvent = a;
- !1 === this._scrolling && (this._scrolling = !0, c.call(this));
- this._scrollTimeout && clearTimeout(this._scrollTimeout);
- var b = this;
- this._scrollTimeout = setTimeout(function() {
- b._scrolling = !1
- }, 100)
- }
- function c() {
- this._args.unshift(this._mostRecentScrollEvent);
- this._callback.apply(window || {}, this._args);
- this._args.shift();
- !0 === this._scrolling && requestAnimationFrame(c.bind(this))
- }
- window.requestAnimationFrame ? (b.prototype = {
- subscribe: function() {
- addEventListener("scroll", a.bind(this), !1)
- },
- unsubscribe: function() {
- removeEventListener("scroll", a.bind(this), !1)
- }
- }, "function" === typeof define && define.amd ? define("rafscroll", b) : "undefined" !== typeof module && "undefined" !== typeof exports ? module.exports = {
- rafscroll: b
- } : window.rafscroll = b) : console.info("Your browser does not support requestAnimationFrame. There is a nice polyfill you can use here.",
- "https://gist.github.com/paulirish/1579671")
- })();
- Y.use(["node", "squarespace-ui-base", "yui-throttle", "squarespace-gallery-ng"], function() {
- window.Site = Singleton.create({
- PARALLAX_FACTOR: 0.8,
- SCROLL_SPEED: 0.6,
- IMAGE_VIEWPORT: null,
- INITIAL_WINDOW_HEIGHT: Y.config.win.innerHeight,
- pageOffsets: {},
- docHeight: 0,
- ready: function() {
- Y.on("domready", this.initialize, this)
- },
- initialize: function() {
- this.parallaxImages = Y.all("#parallax-images .image-container");
- this.parallaxPages = Y.all(".parallax-item");
- this.scrollEl = Y.one(Y.UA.gecko || Y.UA.ie || navigator.userAgent.match(/Trident.*rv.11\./) ?
- "html" : "body");
- this.viewportH = Y.one("body").get("winHeight");
- this.isMobile = !Y.Lang.isUndefined(window.orientation) || 0 < Y.UA.ie && 9 >= Y.UA.ie;
- this.bindUI();
- this.syncUI();
- this.textShrink(".page-title", ".page-title-wrapper");
- this.textShrink(".page-desc p \x3e strong", ".page-desc p");
- this.textShrink(".collection-type-events.view-list .entry-title-wrapper h1.entry-title", ".collection-type-events.view-list .entry-title-wrapper");
- this.textShrink(".collection-type-blog.view-list.blog-layout-columns .entry-title-wrapper h1.entry-title",
- ".collection-type-blog.view-list.blog-layout-columns .entry-title-wrapper");
- Y.one("body.collection-type-index") && this.handleIndex();
- this.listenTweaks();
- Y.one("body").addClass("loaded");
- Y.UA.ie && Y.one("html").addClass("ie" + Y.UA.ie);
- this.isMobile || Y.one("html").removeClass("touch")
- },
- mutationObserver: function(b, a, c) {
- var d = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
- if (d) {
- var e = new d(c);
- e.observe(b, a);
- var f = Y.later(15E3, this, function() {
- e.disconnect();
- f.cancel()
- })
- } else c(null,
- null)
- },
- mutationCallback: function(b) {
- if (b)
- for (var a = 0; a < b.length; a++) {
- if (b[a].addedNodes.length)
- for (var c = 0; c < b[a].addedNodes.length; c++) window.Site.syncUI()
- } else Y.on("io:end", function() {
- var a = Y.later(1200, this, function() {
- window.Site.syncUI();
- a.cancel()
- })
- })
- },
- handleIndex: function() {
- if (Y.config.win.location.hash) this.onHashChange({
- newHash: window.location.hash.replace("#", ""),
- quick: !0
- });
- else this.updateActivePage();
- this.positionImages()
- },
- bindUI: function() {
- if (Y.one("body.collection-type-index")) {
- var b =
- Y.one(".scroll-arrow");
- b.on("click", function() {
- var a = b.ancestor(".title-desc-wrapper").next(".content");
- if (a) {
- var d = new Y.Anim({
- node: Y.one(Y.UA.gecko || Y.UA.ie || navigator.userAgent.match(/Trident.*rv.11\./) ? "html" : "body"),
- to: {
- scrollTop: a.getY()
- },
- duration: 0.5,
- easing: "easeOut"
- });
- d.run();
- d.on("end", function() {
- d.destroy()
- })
- }
- });
- this.mutationObserver(Y.one("#content-wrapper").getDOMNode(), {
- childList: !0,
- subtree: !0
- }, this.mutationCallback);
- new rafscroll(Y.bind(function() {
- this.positionImages();
- Y.one("#parallax-nav") &&
- this.updateActivePage()
- }, this));
- var a = Y.UA.mobile ? "orientationchange" : "resize";
- Y.one(Y.config.win).on("resize", Y.throttle(Y.bind(function() {
- this.syncUI();
- this.positionImages()
- }, this), 50), this);
- Y.on("hashchange", Y.bind(this.onHashChange, this), Y.config.win);
- Y.all("#parallax-nav a").each(function(a) {
- a.on("click", function() {
- if (a.getAttribute("href") === window.location.hash) this.onHashChange({
- newHash: a.getAttribute("href").replace("#", "")
- })
- }, this)
- }, this);
- Y.one(".back-to-top-link a").on("click", function(a) {
- a.halt();
- this.onHashChange({
- newHash: Y.one("[data-url-id]").getAttribute("data-url-id")
- })
- }, this);
- Y.all("#desktopNav .external-link a[href*\x3d#]").each(function(a) {
- a.on("click", function(b) {
- var e = Y.one(a.getAttribute("href"));
- if (e) {
- var f = e.getXY()[1];
- b.preventDefault();
- this.autoScrolling = !0;
- this.scrollEl.anim({}, {
- to: {
- scroll: [0, f]
- },
- duration: this.SCROLL_SPEED,
- easing: Y.Easing.easeBoth
- }).run().on("end", function() {
- this.scrollEl.get("scrollTop") !== f && this.scrollEl.set("scrollTop", f);
- this.autoScrolling = !1;
- this.updateActivePage()
- },
- this)
- }
- }, this)
- }, this)
- } else Y.one(Y.config.win).on("scroll", Y.bind(function() {
- this.positionBackgroundImage()
- }, this), this), a = Y.UA.mobile ? "orientationchange" : "resize", Y.one(Y.config.win).on(a, Y.throttle(Y.bind(function() {
- this.syncUI();
- this.positionBackgroundImage()
- }, this), 50), this);
- this.setupMobileNav();
- this.setScrollArrowColor()
- },
- syncUI: function() {
- var b = Y.one("body"),
- a = Y.one("#header").get("clientHeight"),
- c = b.hasClass("fixed-header"),
- d = b.hasClass("title--description-position-over-image");
- this.parallaxOff =
- "false" == Y.Squarespace.Template.getTweakValue("parallax-scrolling");
- this.viewportH = b.get("winHeight");
- this.docHeight = b.get("docHeight");
- if (Y.one("body.collection-type-index")) {
- this.isMobile ? (this.setupMobileLayout(), Y.one("#header").setStyle("position", "absolute"), Y.one(".sqs-cart-dropzone").setStyle("marginTop", a), Y.one(".parallax-images \x3e .image-container:nth-child(1) \x3e img") && Y.one(".title-desc-wrapper").setStyle("minHeight", "600px"), 0 < Y.UA.ie && 9 >= Y.UA.ie ? Y.one(".title-desc-wrapper").setStyle("paddingTop",
- d ? 80 + a : a) : Y.one(".title-desc-wrapper").setStyle("paddingTop", a)) : (Y.one("#content-wrapper").setStyle("marginTop", c ? a : null), Y.all(".title-desc-wrapper").setStyle("paddingTop", c && d ? 80 + a : null), Y.one(".title-desc-wrapper") && Y.one(".title-desc-wrapper").setStyle("paddingTop", null));
- var e = Y.Squarespace.Template.getTweakValue("index-image-height");
- this.IMAGE_VIEWPORT = "Fullscreen" == e ? 1 : "Half" == e ? 0.5 : 0.66;
- this.firstImageHeight = "true" === Y.Squarespace.Template.getTweakValue("first-index-image-fullscreen") ? this.viewportH :
- parseInt(this.viewportH * this.IMAGE_VIEWPORT);
- this.restImageHeight = parseInt(this.viewportH * this.IMAGE_VIEWPORT);
- var f = new Y.NodeList;
- this.parallaxPages.each(function(b, e) {
- if (!this.isMobile) {
- var j = 0 === e ? this.firstImageHeight - Y.one("#header").get("clientHeight") : this.restImageHeight;
- if (d) {
- var g = c ? a + 160 : 160,
- j = Math.max(j, b.one(".title-desc-inner").height() + g),
- g = 0 === e ? j + a : j;
- this.parallaxImages.item(e).setStyle("height", Math.max(this.viewportH, g) + "px")
- }
- if (g = this.parallaxImages.item(e).one("img")) b.one(".title-desc-wrapper").setStyle("height",
- j + "px"), f.push(g.removeAttribute("data-load"))
- }
- this.pageOffsets[b.getAttribute("data-url-id")] = 0 === e ? 0 : Math.round(b.getXY()[1])
- }, this);
- Y.Squarespace.GalleryManager.addImageQueue(f);
- this.parallaxImages.each(function(a) {
- (a = a.one("img")) && a.getAttribute("src") && ImageLoader.load(a)
- }, this);
- this.stickyCart()
- } else(e = Y.one(".banner-image img")) && ImageLoader.load(e), Y.one(".sqs-cart-dropzone").setStyle("marginTop", a), this.stickyCart(), this.isMobile || Y.one("#header-wrapper").setStyle("paddingTop", c ? a : null);
- this.isMobile || (Y.one(".collection-type-index.title--description-alignment-center.title--description-position-over-image") && Y.all(".title-desc-wrapper.has-main-image").each(function(a) {
- a.one(".title-desc-inner").setStyles({
- top: "50%",
- left: "50%",
- transform: "translatex(-50%) translatey(-50%)"
- })
- }), Y.one(".collection-type-index.title--description-alignment-left") && Y.all(".title-desc-wrapper.over-image.has-main-image .title-desc-inner").setStyles({
- top: null,
- left: null,
- transform: "translatex(0) translatey(0)"
- }),
- Y.one("#parallax-nav") && (e = Y.one("#parallax-nav").get("offsetHeight"), Y.one("#parallax-nav").setStyle("marginTop", -1 * (e / 2))));
- Y.one(".footer-wrapper .sqs-block") || Y.one(".footer-wrapper").addClass("empty");
- Y.one(".nav-wrapper") && b.addClass("has-nav");
- this.headerBgOnScroll()
- },
- textShrink: function(b, a) {
- Y.one(b) && Y.one(b).ancestor(a) && Y.all(b).each(function(b) {
- b.plug(Y.Squarespace.TextShrink, {
- parentEl: b.ancestor(a)
- })
- })
- },
- setupMobileLayout: function() {
- var b = Y.config.win.innerHeight > Y.config.win.innerWidth ?
- screen.height : screen.width,
- a = Y.Squarespace.Template.getTweakValue("index-image-height"),
- c = Y.one("#header").get("clientHeight"),
- d;
- switch (!0) {
- case "Two Thirds" == a:
- d = 0.66666 * b;
- break;
- case "Fullscreen" == a:
- d = 1 * b;
- break;
- default:
- d = 0.5 * b
- }
- Y.all(".parallax-item").each(function(a, b) {
- var h = a.one(".title-desc-wrapper"),
- i = a.one(".title-desc-inner"),
- j = a.one(".title-desc-image");
- if (h.hasClass("has-main-image")) {
- var g;
- 0 === b ? (d -= 118, g = this.INITIAL_WINDOW_HEIGHT - c) : g = d;
- var k = i.get("clientHeight");
- k > g && (g = d = k);
- h.setStyles({
- height: g,
- overflow: "hidden"
- }, this);
- j.setStyles({
- height: d
- })
- } else h.setStyle({
- paddingTop: c
- });
- Y.one(".title--description-alignment-center") && h.hasClass("has-main-image") && (i.get("clientHeight") < h.get("clientHeight") && 0 !== b ? i.setStyles({
- position: "absolute",
- top: "50%",
- left: "50%",
- transform: "translate3d(-50%, -50%, 0)"
- }) : i.setStyles({
- position: "relative"
- }), 0 === b && (a.one(".scroll-arrow").setStyles({
- marginTop: "-78px"
- }), i.get("clientHeight") + 78 < h.get("clientHeight") - Y.one("#header").height() ? i.setStyles({
- position: "absolute",
- top: "50%",
- left: "50%",
- transform: "translate3d(-50%, -50%, 0)"
- }) : i.setStyles({
- position: "relative",
- marginBottom: "78px"
- })))
- }, this);
- !Y.one(".parallax-scrolling") || 0 < Y.UA.ie && 9 >= Y.UA.ie ? (0 < Y.UA.ie && 9 >= Y.UA.ie ? Y.one("body").addClass("crappy-ie-no-parallax") : Y.one("body").addClass("mobile-no-parallax"), Y.all(".title-desc-image").each(function(a, b) {
- 0 === b && a.setStyles({
- minHeight: a.ancestor(".title-desc-wrapper").get("clientHeight") + Y.one("#header").get("clientHeight")
- });
- a.one("img").removeAttribute("data-load");
- ImageLoader.load(a.one("img"), {
- mode: "fill"
- })
- })) : (Y.one("body").addClass("mobile-parallax"), Y.all(".title-desc-image").each(function(a) {
- a.setStyle("height", b);
- a.one("img").removeAttribute("data-load");
- ImageLoader.load(a.one("img"), {
- mode: "fill"
- })
- }))
- },
- setupMobileNav: function() {
- Y.one("#mobileMenu").on("click", function() {
- Y.one("body").hasClass("mobile-nav-open") ? Y.one("body").removeClass("mobile-nav-open") : Y.one("body").addClass("mobile-nav-open")
- });
- Y.all("li.folder").each(function(b) {
- b.on("click", function() {
- var a =
- b.siblings("li.folder.dropdown-open").item(0);
- a && a.toggleClass("dropdown-open");
- b && b.toggleClass("dropdown-open")
- })
- })
- },
- positionBackgroundImage: function() {
- var b = this.scrollEl.get("scrollTop"),
- a = Y.one(Y.config.win).get("region"),
- c = Y.one(".banner-image img");
- !this.parallaxOff && (!this.isMobile && c && !(b > a.height)) && c.setStyle("transform", "translate3d(0," + parseInt(b * this.PARALLAX_FACTOR, 10) + "px,0)")
- },
- onHashChange: function(b) {
- Y.one(".mobile-nav-open") && Y.one("body").removeClass("mobile-nav-open");
- if (Y.one('.parallax-item[data-url-id\x3d"' +
- b.newHash + '"]')) {
- var a = this.pageOffsets[b.newHash];
- b.quick ? (this.scrollEl.set("scrollTop", a), this.updateActivePage()) : (this.autoScrolling = !0, this.scrollEl.anim({}, {
- to: {
- scroll: [0, a]
- },
- duration: this.SCROLL_SPEED,
- easing: Y.Easing.easeBoth
- }).run().on("end", function() {
- this.scrollEl.get("scrollTop") !== a && this.scrollEl.set("scrollTop", a);
- this.autoScrolling = !1;
- this.updateActivePage()
- }, this))
- }
- },
- getPageFromOffset: function(b) {
- if (this.parallaxPages.item(0)) {
- var a = this.parallaxPages.item(0).getAttribute("data-url-id"),
- c;
- for (c in this.pageOffsets) b >= this.pageOffsets[c] && this.pageOffsets[c] > this.pageOffsets[a] && (a = c);
- return a
- }
- },
- setScrollArrowColor: function() {
- var b = Y.one(".scroll-arrow"),
- a = Y.one(".parallax-item .title-desc-wrapper");
- a && (a = a.getAttribute("data-color-suggested"), Y.Lang.isValue(b) && Y.Lang.isValue(a) && (a = "color-weight-" + this._getLightness(a), b.hasClass(a) || b.removeClass("color-weight-dark").removeClass("color-weight-light").addClass(a)))
- },
- updateActivePage: function() {
- if (!this.autoScrolling) {
- var b = this.scrollEl.get("scrollTop"),
- a = this.getPageFromOffset(b),
- c = Y.one("#parallax-nav-item-" + a);
- c && !c.hasClass("active") && (Y.all("#parallax-nav li").removeClass("active"), c.addClass("active"));
- window.location.hash.replace("#", "") != a && window.history && window.history.replaceState && window.history.replaceState({}, "", "#" + a);
- a = this.isMobile ? Y.one('.parallax-item[data-url-id\x3d"' + a + '"] .title-desc-wrapper img') : Y.one('#parallax-images .image-container[data-url-id\x3d"' + a + '"] img');
- Y.Squarespace.GalleryManager.promoteImageQueue(new Y.NodeList(a));
- if (!Y.one("body.hide-parallax-nav")) {
- var a = this.getPageFromOffset(b + this.viewportH / 2),
- d;
- if (b + this.viewportH / 2 <= this.pageOffsets[a] + (0 === this.pageOffsets[a] ? this.firstImageHeight : this.viewportH * this.IMAGE_VIEWPORT)) d = Y.one('.parallax-item[data-url-id\x3d"' + a + '"] .title-desc-wrapper').getAttribute("data-color-suggested");
- if (!d || "#" === d) d = Y.Squarespace.Template.getTweakValue("contentBgColor"), (b = d.match(/rgba\((\d+),(\d+),(\d+),(\d+)/)) && (d = this._rgb2hex(b[1], b[2], b[3]));
- Y.one("#parallax-nav") && (d = "color-weight-" +
- this._getLightness(d), Y.one("#parallax-nav").hasClass(d) || Y.one("#parallax-nav").removeClass("color-weight-dark").removeClass("color-weight-light").addClass(d))
- }
- }
- },
- _rgb2hex: function(b, a, c) {
- b = [b, a, c];
- for (a = 0; 2 >= a; ++a) b[a] = parseInt(b[a], 10).toString(16), 1 == b[a].length && (b[a] = "0" + b[a]);
- return "#" + b.join("")
- },
- _getLightness: function(b) {
- return b && 0 < b.length && 7 >= b.length ? (b = b.replace("#", ""), 8388607.5 < parseInt(b, 16) ? "light" : "dark") : ""
- },
- positionImages: function() {
- if (!this.isMobile) {
- var b = this.scrollEl.get("scrollTop"),
- a = Y.one(Y.config.win).get("region");
- this.parallaxPages.each(function(c, d) {
- var e = this.parallaxImages.item(d);
- if (c.inRegion(a)) {
- var f = this.pageOffsets[c.getAttribute("data-url-id")] - b,
- h = -1 * parseFloat(f * (this.parallaxOff ? 0 : this.PARALLAX_FACTOR)),
- i = e.one("img");
- e.setStyles({
- transform: "translate3d(0, " + f + "px, 0)"
- });
- i && i.setStyle("transform", "translatey(" + h + "px) translatez(0)")
- } else e.setStyle("transform", "translate3d(0, -100%, 0)")
- }, this)
- }
- },
- listenTweaks: function() {
- Y.Global && (Y.Global.on("tweak:change",
- function(b) {
- b.getName().match(/image|parallax|title--description-alignment|fixed-header/i) && this.syncUI()
- }, this), Y.Global.on("tweak:change", function(b) {
- "transparent-header" == b.getName() && Y.one(".fixed-header") && Y.one("#header").setStyle("backgroundColor", null)
- }), Y.Global.on(["tweak:reset", "tweak:close"], function() {
- Y.later(500, this, this.syncUI)
- }, this))
- },
- headerBgOnScroll: function() {
- var b = Y.one(".fixed-header.transparent-header"),
- a = Y.one("#header"),
- c = a.get("clientHeight"),
- d = Y.Squarespace.Template.getTweakValue("headerBgColor");
- if (b) {
- Y.one(window).on("scroll", function() {
- Y.one(".transparent-header") && Y.later(500, this, e)
- });
- var e = function() {
- Y.config.win.scrollY > c ? Y.one("#header").setStyle("backgroundColor", d) : a.setStyle("backgroundColor", "transparent")
- }
- }
- },
- stickyCart: function() {
- if (this.isMobile) return !1;
- var b = Y.one(".sqs-cart-dropzone");
- Y.one("#header").get("clientHeight");
- var a;
- b && b.one(".yui3-widget") && (a = b.one(".yui3-widget").getY(), Y.one(window).on("resize", function() {
- a = b.getY()
- }), Y.one("body.fixed-header") ? b.addClass("fixed-cart").setStyles({
- top: Y.one("#header").get("clientHeight") +
- 10
- }) : new rafscroll(function() {
- b.toggleClass("fixed-cart", Y.config.win.scrollY >= a)
- }))
- }
- })
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement