Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.40 KB | None | 0 0
  1.  
  2. (function() {
  3. 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"];
  4. window.requestAnimationFrame || (window.requestAnimationFrame = function(a) {
  5. var c = (new Date).getTime(),
  6. f = Math.max(0, 16 - (c - b)),
  7. h = window.setTimeout(function() {
  8. a(c + f)
  9. }, f);
  10. b = c + f;
  11. return h
  12. });
  13. window.cancelAnimationFrame || (window.cancelAnimationFrame =
  14. function(a) {
  15. clearTimeout(a)
  16. })
  17. })();
  18. (function() {
  19. function b(a, b) {
  20. 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.")
  21. }
  22.  
  23. function a(a) {
  24. this._mostRecentScrollEvent = a;
  25. !1 === this._scrolling && (this._scrolling = !0, c.call(this));
  26. this._scrollTimeout && clearTimeout(this._scrollTimeout);
  27. var b = this;
  28. this._scrollTimeout = setTimeout(function() {
  29. b._scrolling = !1
  30. }, 100)
  31. }
  32.  
  33. function c() {
  34. this._args.unshift(this._mostRecentScrollEvent);
  35. this._callback.apply(window || {}, this._args);
  36. this._args.shift();
  37. !0 === this._scrolling && requestAnimationFrame(c.bind(this))
  38. }
  39. window.requestAnimationFrame ? (b.prototype = {
  40. subscribe: function() {
  41. addEventListener("scroll", a.bind(this), !1)
  42. },
  43. unsubscribe: function() {
  44. removeEventListener("scroll", a.bind(this), !1)
  45. }
  46. }, "function" === typeof define && define.amd ? define("rafscroll", b) : "undefined" !== typeof module && "undefined" !== typeof exports ? module.exports = {
  47. rafscroll: b
  48. } : window.rafscroll = b) : console.info("Your browser does not support requestAnimationFrame. There is a nice polyfill you can use here.",
  49. "https://gist.github.com/paulirish/1579671")
  50. })();
  51. Y.use(["node", "squarespace-ui-base", "yui-throttle", "squarespace-gallery-ng"], function() {
  52. window.Site = Singleton.create({
  53. PARALLAX_FACTOR: 0.8,
  54. SCROLL_SPEED: 0.6,
  55. IMAGE_VIEWPORT: null,
  56. INITIAL_WINDOW_HEIGHT: Y.config.win.innerHeight,
  57. pageOffsets: {},
  58. docHeight: 0,
  59. ready: function() {
  60. Y.on("domready", this.initialize, this)
  61. },
  62. initialize: function() {
  63. this.parallaxImages = Y.all("#parallax-images .image-container");
  64. this.parallaxPages = Y.all(".parallax-item");
  65. this.scrollEl = Y.one(Y.UA.gecko || Y.UA.ie || navigator.userAgent.match(/Trident.*rv.11\./) ?
  66. "html" : "body");
  67. this.viewportH = Y.one("body").get("winHeight");
  68. this.isMobile = !Y.Lang.isUndefined(window.orientation) || 0 < Y.UA.ie && 9 >= Y.UA.ie;
  69. this.bindUI();
  70. this.syncUI();
  71. this.textShrink(".page-title", ".page-title-wrapper");
  72. this.textShrink(".page-desc p \x3e strong", ".page-desc p");
  73. this.textShrink(".collection-type-events.view-list .entry-title-wrapper h1.entry-title", ".collection-type-events.view-list .entry-title-wrapper");
  74. this.textShrink(".collection-type-blog.view-list.blog-layout-columns .entry-title-wrapper h1.entry-title",
  75. ".collection-type-blog.view-list.blog-layout-columns .entry-title-wrapper");
  76. Y.one("body.collection-type-index") && this.handleIndex();
  77. this.listenTweaks();
  78. Y.one("body").addClass("loaded");
  79. Y.UA.ie && Y.one("html").addClass("ie" + Y.UA.ie);
  80. this.isMobile || Y.one("html").removeClass("touch")
  81. },
  82. mutationObserver: function(b, a, c) {
  83. var d = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  84. if (d) {
  85. var e = new d(c);
  86. e.observe(b, a);
  87. var f = Y.later(15E3, this, function() {
  88. e.disconnect();
  89. f.cancel()
  90. })
  91. } else c(null,
  92. null)
  93. },
  94. mutationCallback: function(b) {
  95. if (b)
  96. for (var a = 0; a < b.length; a++) {
  97. if (b[a].addedNodes.length)
  98. for (var c = 0; c < b[a].addedNodes.length; c++) window.Site.syncUI()
  99. } else Y.on("io:end", function() {
  100. var a = Y.later(1200, this, function() {
  101. window.Site.syncUI();
  102. a.cancel()
  103. })
  104. })
  105. },
  106. handleIndex: function() {
  107. if (Y.config.win.location.hash) this.onHashChange({
  108. newHash: window.location.hash.replace("#", ""),
  109. quick: !0
  110. });
  111. else this.updateActivePage();
  112. this.positionImages()
  113. },
  114. bindUI: function() {
  115. if (Y.one("body.collection-type-index")) {
  116. var b =
  117. Y.one(".scroll-arrow");
  118. b.on("click", function() {
  119. var a = b.ancestor(".title-desc-wrapper").next(".content");
  120. if (a) {
  121. var d = new Y.Anim({
  122. node: Y.one(Y.UA.gecko || Y.UA.ie || navigator.userAgent.match(/Trident.*rv.11\./) ? "html" : "body"),
  123. to: {
  124. scrollTop: a.getY()
  125. },
  126. duration: 0.5,
  127. easing: "easeOut"
  128. });
  129. d.run();
  130. d.on("end", function() {
  131. d.destroy()
  132. })
  133. }
  134. });
  135. this.mutationObserver(Y.one("#content-wrapper").getDOMNode(), {
  136. childList: !0,
  137. subtree: !0
  138. }, this.mutationCallback);
  139. new rafscroll(Y.bind(function() {
  140. this.positionImages();
  141. Y.one("#parallax-nav") &&
  142. this.updateActivePage()
  143. }, this));
  144. var a = Y.UA.mobile ? "orientationchange" : "resize";
  145. Y.one(Y.config.win).on("resize", Y.throttle(Y.bind(function() {
  146. this.syncUI();
  147. this.positionImages()
  148. }, this), 50), this);
  149. Y.on("hashchange", Y.bind(this.onHashChange, this), Y.config.win);
  150. Y.all("#parallax-nav a").each(function(a) {
  151. a.on("click", function() {
  152. if (a.getAttribute("href") === window.location.hash) this.onHashChange({
  153. newHash: a.getAttribute("href").replace("#", "")
  154. })
  155. }, this)
  156. }, this);
  157. Y.one(".back-to-top-link a").on("click", function(a) {
  158. a.halt();
  159. this.onHashChange({
  160. newHash: Y.one("[data-url-id]").getAttribute("data-url-id")
  161. })
  162. }, this);
  163. Y.all("#desktopNav .external-link a[href*\x3d#]").each(function(a) {
  164. a.on("click", function(b) {
  165. var e = Y.one(a.getAttribute("href"));
  166. if (e) {
  167. var f = e.getXY()[1];
  168. b.preventDefault();
  169. this.autoScrolling = !0;
  170. this.scrollEl.anim({}, {
  171. to: {
  172. scroll: [0, f]
  173. },
  174. duration: this.SCROLL_SPEED,
  175. easing: Y.Easing.easeBoth
  176. }).run().on("end", function() {
  177. this.scrollEl.get("scrollTop") !== f && this.scrollEl.set("scrollTop", f);
  178. this.autoScrolling = !1;
  179. this.updateActivePage()
  180. },
  181. this)
  182. }
  183. }, this)
  184. }, this)
  185. } else Y.one(Y.config.win).on("scroll", Y.bind(function() {
  186. this.positionBackgroundImage()
  187. }, this), this), a = Y.UA.mobile ? "orientationchange" : "resize", Y.one(Y.config.win).on(a, Y.throttle(Y.bind(function() {
  188. this.syncUI();
  189. this.positionBackgroundImage()
  190. }, this), 50), this);
  191. this.setupMobileNav();
  192. this.setScrollArrowColor()
  193. },
  194. syncUI: function() {
  195. var b = Y.one("body"),
  196. a = Y.one("#header").get("clientHeight"),
  197. c = b.hasClass("fixed-header"),
  198. d = b.hasClass("title--description-position-over-image");
  199. this.parallaxOff =
  200. "false" == Y.Squarespace.Template.getTweakValue("parallax-scrolling");
  201. this.viewportH = b.get("winHeight");
  202. this.docHeight = b.get("docHeight");
  203. if (Y.one("body.collection-type-index")) {
  204. 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",
  205. 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));
  206. var e = Y.Squarespace.Template.getTweakValue("index-image-height");
  207. this.IMAGE_VIEWPORT = "Fullscreen" == e ? 1 : "Half" == e ? 0.5 : 0.66;
  208. this.firstImageHeight = "true" === Y.Squarespace.Template.getTweakValue("first-index-image-fullscreen") ? this.viewportH :
  209. parseInt(this.viewportH * this.IMAGE_VIEWPORT);
  210. this.restImageHeight = parseInt(this.viewportH * this.IMAGE_VIEWPORT);
  211. var f = new Y.NodeList;
  212. this.parallaxPages.each(function(b, e) {
  213. if (!this.isMobile) {
  214. var j = 0 === e ? this.firstImageHeight - Y.one("#header").get("clientHeight") : this.restImageHeight;
  215. if (d) {
  216. var g = c ? a + 160 : 160,
  217. j = Math.max(j, b.one(".title-desc-inner").height() + g),
  218. g = 0 === e ? j + a : j;
  219. this.parallaxImages.item(e).setStyle("height", Math.max(this.viewportH, g) + "px")
  220. }
  221. if (g = this.parallaxImages.item(e).one("img")) b.one(".title-desc-wrapper").setStyle("height",
  222. j + "px"), f.push(g.removeAttribute("data-load"))
  223. }
  224. this.pageOffsets[b.getAttribute("data-url-id")] = 0 === e ? 0 : Math.round(b.getXY()[1])
  225. }, this);
  226. Y.Squarespace.GalleryManager.addImageQueue(f);
  227. this.parallaxImages.each(function(a) {
  228. (a = a.one("img")) && a.getAttribute("src") && ImageLoader.load(a)
  229. }, this);
  230. this.stickyCart()
  231. } 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);
  232. 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) {
  233. a.one(".title-desc-inner").setStyles({
  234. top: "50%",
  235. left: "50%",
  236. transform: "translatex(-50%) translatey(-50%)"
  237. })
  238. }), Y.one(".collection-type-index.title--description-alignment-left") && Y.all(".title-desc-wrapper.over-image.has-main-image .title-desc-inner").setStyles({
  239. top: null,
  240. left: null,
  241. transform: "translatex(0) translatey(0)"
  242. }),
  243. Y.one("#parallax-nav") && (e = Y.one("#parallax-nav").get("offsetHeight"), Y.one("#parallax-nav").setStyle("marginTop", -1 * (e / 2))));
  244. Y.one(".footer-wrapper .sqs-block") || Y.one(".footer-wrapper").addClass("empty");
  245. Y.one(".nav-wrapper") && b.addClass("has-nav");
  246. this.headerBgOnScroll()
  247. },
  248. textShrink: function(b, a) {
  249. Y.one(b) && Y.one(b).ancestor(a) && Y.all(b).each(function(b) {
  250. b.plug(Y.Squarespace.TextShrink, {
  251. parentEl: b.ancestor(a)
  252. })
  253. })
  254. },
  255. setupMobileLayout: function() {
  256. var b = Y.config.win.innerHeight > Y.config.win.innerWidth ?
  257. screen.height : screen.width,
  258. a = Y.Squarespace.Template.getTweakValue("index-image-height"),
  259. c = Y.one("#header").get("clientHeight"),
  260. d;
  261. switch (!0) {
  262. case "Two Thirds" == a:
  263. d = 0.66666 * b;
  264. break;
  265. case "Fullscreen" == a:
  266. d = 1 * b;
  267. break;
  268. default:
  269. d = 0.5 * b
  270. }
  271. Y.all(".parallax-item").each(function(a, b) {
  272. var h = a.one(".title-desc-wrapper"),
  273. i = a.one(".title-desc-inner"),
  274. j = a.one(".title-desc-image");
  275. if (h.hasClass("has-main-image")) {
  276. var g;
  277. 0 === b ? (d -= 118, g = this.INITIAL_WINDOW_HEIGHT - c) : g = d;
  278. var k = i.get("clientHeight");
  279. k > g && (g = d = k);
  280. h.setStyles({
  281. height: g,
  282. overflow: "hidden"
  283. }, this);
  284. j.setStyles({
  285. height: d
  286. })
  287. } else h.setStyle({
  288. paddingTop: c
  289. });
  290. Y.one(".title--description-alignment-center") && h.hasClass("has-main-image") && (i.get("clientHeight") < h.get("clientHeight") && 0 !== b ? i.setStyles({
  291. position: "absolute",
  292. top: "50%",
  293. left: "50%",
  294. transform: "translate3d(-50%, -50%, 0)"
  295. }) : i.setStyles({
  296. position: "relative"
  297. }), 0 === b && (a.one(".scroll-arrow").setStyles({
  298. marginTop: "-78px"
  299. }), i.get("clientHeight") + 78 < h.get("clientHeight") - Y.one("#header").height() ? i.setStyles({
  300. position: "absolute",
  301. top: "50%",
  302. left: "50%",
  303. transform: "translate3d(-50%, -50%, 0)"
  304. }) : i.setStyles({
  305. position: "relative",
  306. marginBottom: "78px"
  307. })))
  308. }, this);
  309. !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) {
  310. 0 === b && a.setStyles({
  311. minHeight: a.ancestor(".title-desc-wrapper").get("clientHeight") + Y.one("#header").get("clientHeight")
  312. });
  313. a.one("img").removeAttribute("data-load");
  314. ImageLoader.load(a.one("img"), {
  315. mode: "fill"
  316. })
  317. })) : (Y.one("body").addClass("mobile-parallax"), Y.all(".title-desc-image").each(function(a) {
  318. a.setStyle("height", b);
  319. a.one("img").removeAttribute("data-load");
  320. ImageLoader.load(a.one("img"), {
  321. mode: "fill"
  322. })
  323. }))
  324. },
  325. setupMobileNav: function() {
  326. Y.one("#mobileMenu").on("click", function() {
  327. Y.one("body").hasClass("mobile-nav-open") ? Y.one("body").removeClass("mobile-nav-open") : Y.one("body").addClass("mobile-nav-open")
  328. });
  329. Y.all("li.folder").each(function(b) {
  330. b.on("click", function() {
  331. var a =
  332. b.siblings("li.folder.dropdown-open").item(0);
  333. a && a.toggleClass("dropdown-open");
  334. b && b.toggleClass("dropdown-open")
  335. })
  336. })
  337. },
  338. positionBackgroundImage: function() {
  339. var b = this.scrollEl.get("scrollTop"),
  340. a = Y.one(Y.config.win).get("region"),
  341. c = Y.one(".banner-image img");
  342. !this.parallaxOff && (!this.isMobile && c && !(b > a.height)) && c.setStyle("transform", "translate3d(0," + parseInt(b * this.PARALLAX_FACTOR, 10) + "px,0)")
  343. },
  344. onHashChange: function(b) {
  345. Y.one(".mobile-nav-open") && Y.one("body").removeClass("mobile-nav-open");
  346. if (Y.one('.parallax-item[data-url-id\x3d"' +
  347. b.newHash + '"]')) {
  348. var a = this.pageOffsets[b.newHash];
  349. b.quick ? (this.scrollEl.set("scrollTop", a), this.updateActivePage()) : (this.autoScrolling = !0, this.scrollEl.anim({}, {
  350. to: {
  351. scroll: [0, a]
  352. },
  353. duration: this.SCROLL_SPEED,
  354. easing: Y.Easing.easeBoth
  355. }).run().on("end", function() {
  356. this.scrollEl.get("scrollTop") !== a && this.scrollEl.set("scrollTop", a);
  357. this.autoScrolling = !1;
  358. this.updateActivePage()
  359. }, this))
  360. }
  361. },
  362. getPageFromOffset: function(b) {
  363. if (this.parallaxPages.item(0)) {
  364. var a = this.parallaxPages.item(0).getAttribute("data-url-id"),
  365. c;
  366. for (c in this.pageOffsets) b >= this.pageOffsets[c] && this.pageOffsets[c] > this.pageOffsets[a] && (a = c);
  367. return a
  368. }
  369. },
  370. setScrollArrowColor: function() {
  371. var b = Y.one(".scroll-arrow"),
  372. a = Y.one(".parallax-item .title-desc-wrapper");
  373. 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)))
  374. },
  375. updateActivePage: function() {
  376. if (!this.autoScrolling) {
  377. var b = this.scrollEl.get("scrollTop"),
  378. a = this.getPageFromOffset(b),
  379. c = Y.one("#parallax-nav-item-" + a);
  380. c && !c.hasClass("active") && (Y.all("#parallax-nav li").removeClass("active"), c.addClass("active"));
  381. window.location.hash.replace("#", "") != a && window.history && window.history.replaceState && window.history.replaceState({}, "", "#" + a);
  382. 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');
  383. Y.Squarespace.GalleryManager.promoteImageQueue(new Y.NodeList(a));
  384. if (!Y.one("body.hide-parallax-nav")) {
  385. var a = this.getPageFromOffset(b + this.viewportH / 2),
  386. d;
  387. 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");
  388. 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]));
  389. Y.one("#parallax-nav") && (d = "color-weight-" +
  390. this._getLightness(d), Y.one("#parallax-nav").hasClass(d) || Y.one("#parallax-nav").removeClass("color-weight-dark").removeClass("color-weight-light").addClass(d))
  391. }
  392. }
  393. },
  394. _rgb2hex: function(b, a, c) {
  395. b = [b, a, c];
  396. for (a = 0; 2 >= a; ++a) b[a] = parseInt(b[a], 10).toString(16), 1 == b[a].length && (b[a] = "0" + b[a]);
  397. return "#" + b.join("")
  398. },
  399. _getLightness: function(b) {
  400. return b && 0 < b.length && 7 >= b.length ? (b = b.replace("#", ""), 8388607.5 < parseInt(b, 16) ? "light" : "dark") : ""
  401. },
  402. positionImages: function() {
  403. if (!this.isMobile) {
  404. var b = this.scrollEl.get("scrollTop"),
  405. a = Y.one(Y.config.win).get("region");
  406. this.parallaxPages.each(function(c, d) {
  407. var e = this.parallaxImages.item(d);
  408. if (c.inRegion(a)) {
  409. var f = this.pageOffsets[c.getAttribute("data-url-id")] - b,
  410. h = -1 * parseFloat(f * (this.parallaxOff ? 0 : this.PARALLAX_FACTOR)),
  411. i = e.one("img");
  412. e.setStyles({
  413. transform: "translate3d(0, " + f + "px, 0)"
  414. });
  415. i && i.setStyle("transform", "translatey(" + h + "px) translatez(0)")
  416. } else e.setStyle("transform", "translate3d(0, -100%, 0)")
  417. }, this)
  418. }
  419. },
  420. listenTweaks: function() {
  421. Y.Global && (Y.Global.on("tweak:change",
  422. function(b) {
  423. b.getName().match(/image|parallax|title--description-alignment|fixed-header/i) && this.syncUI()
  424. }, this), Y.Global.on("tweak:change", function(b) {
  425. "transparent-header" == b.getName() && Y.one(".fixed-header") && Y.one("#header").setStyle("backgroundColor", null)
  426. }), Y.Global.on(["tweak:reset", "tweak:close"], function() {
  427. Y.later(500, this, this.syncUI)
  428. }, this))
  429. },
  430. headerBgOnScroll: function() {
  431. var b = Y.one(".fixed-header.transparent-header"),
  432. a = Y.one("#header"),
  433. c = a.get("clientHeight"),
  434. d = Y.Squarespace.Template.getTweakValue("headerBgColor");
  435. if (b) {
  436. Y.one(window).on("scroll", function() {
  437. Y.one(".transparent-header") && Y.later(500, this, e)
  438. });
  439. var e = function() {
  440. Y.config.win.scrollY > c ? Y.one("#header").setStyle("backgroundColor", d) : a.setStyle("backgroundColor", "transparent")
  441. }
  442. }
  443. },
  444. stickyCart: function() {
  445. if (this.isMobile) return !1;
  446. var b = Y.one(".sqs-cart-dropzone");
  447. Y.one("#header").get("clientHeight");
  448. var a;
  449. b && b.one(".yui3-widget") && (a = b.one(".yui3-widget").getY(), Y.one(window).on("resize", function() {
  450. a = b.getY()
  451. }), Y.one("body.fixed-header") ? b.addClass("fixed-cart").setStyles({
  452. top: Y.one("#header").get("clientHeight") +
  453. 10
  454. }) : new rafscroll(function() {
  455. b.toggleClass("fixed-cart", Y.config.win.scrollY >= a)
  456. }))
  457. }
  458. })
  459. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement