Advertisement
srikat

Untitled

Feb 8th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. ShopifyMarketing.TabbedCarousel = function() {
  2. var e = new ShopifyMarketing.Breakpoints,
  3. t = function(e, t) {
  4. this.$el = $(e), this.$tabNav = this.$el.find(".tabbed-carousel__nav"), this.$tabNavItems = this.$el.find(".tabbed-carousel__nav-item"), this.$tabItems = this.$el.find(".tabbed-carousel__item"), this.$nextLabel = this.$el.find(".carousel-arrow-right .tab-label"), this.$prevLabel = this.$el.find(".carousel-arrow-left .tab-label"), this.options = t || {}, this.setInitialState = _.bind(this.setInitialState, this), this.removeState = _.bind(this.removeState, this), this.updateState = _.bind(this.updateState, this), this._onKeydown = _.bind(this._onKeydown, this), this.enable()
  5. };
  6. return t.prototype.enable = function() {
  7. this.accordion = new ShopifyMarketing.Accordion(this.$el), enquire.register([e.tablet, e.desktop].join(","), this.setInitialState), enquire.register(e.phone, this.removeState)
  8. }, t.prototype.setInitialState = function() {
  9. this.carousel = new ShopifyMarketing.Carousel(this.$el, this.options), this.$tabNav.attr("role", "tablist");
  10. for (var e = 0; e < this.carousel.itemsCount; e++) {
  11. var t = _.uniqueId("TabbedCarousel");
  12. this.$tabNavItems.eq(e).attr({
  13. "aria-controls": t,
  14. role: "tab",
  15. tabindex: e === this.carousel.currentIndex ? "0" : "-1"
  16. }), this.$tabItems.eq(e).attr({
  17. id: t,
  18. role: "tabpanel",
  19. tabindex: "0"
  20. })
  21. }
  22. this.$el.on("change", this.updateState), this.$tabNavItems.on("keydown", this._onKeydown), this.updateState()
  23. }, t.prototype.removeState = function() {
  24. this.$tabNav.removeAttr("role"), this.$tabNavItems.removeAttr("aria-controls aria-selected role"), this.$tabItems.removeAttr("aria-hidden id role")
  25. }, t.prototype.updateState = function() {
  26. this.$nextLabel.text($.trim(this.carousel.$navItems.eq(this.carousel.nextIndex).text())), this.$prevLabel.text($.trim(this.carousel.$navItems.eq(this.carousel.prevIndex).text())), this.$tabNavItems.attr({
  27. "aria-selected": "false",
  28. tabindex: "-1"
  29. }).eq(this.carousel.currentIndex).attr({
  30. "aria-selected": "true",
  31. tabindex: "0"
  32. }), this.$tabItems.attr("aria-hidden", "true").eq(this.carousel.currentIndex).attr("aria-hidden", "false")
  33. }, t.prototype._onKeydown = function(e) {
  34. var t, n = ShopifyMarketing.keyCodes;
  35. switch (e.keyCode) {
  36. case n.UP:
  37. case n.LEFT:
  38. t = this.carousel.prevIndex;
  39. break;
  40. case n.DOWN:
  41. case n.RIGHT:
  42. t = this.carousel.nextIndex;
  43. break;
  44. case n.HOME:
  45. t = 0;
  46. break;
  47. case n.END:
  48. t = this.carousel.itemsCount - 1
  49. }
  50. return void 0 !== t ? (e.preventDefault(), this.$tabNavItems.eq(t).trigger("click").trigger("focus")) : void 0
  51. }, t
  52. }(),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement