Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ShopifyMarketing.TabbedCarousel = function() {
- var e = new ShopifyMarketing.Breakpoints,
- t = function(e, t) {
- 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()
- };
- return t.prototype.enable = function() {
- this.accordion = new ShopifyMarketing.Accordion(this.$el), enquire.register([e.tablet, e.desktop].join(","), this.setInitialState), enquire.register(e.phone, this.removeState)
- }, t.prototype.setInitialState = function() {
- this.carousel = new ShopifyMarketing.Carousel(this.$el, this.options), this.$tabNav.attr("role", "tablist");
- for (var e = 0; e < this.carousel.itemsCount; e++) {
- var t = _.uniqueId("TabbedCarousel");
- this.$tabNavItems.eq(e).attr({
- "aria-controls": t,
- role: "tab",
- tabindex: e === this.carousel.currentIndex ? "0" : "-1"
- }), this.$tabItems.eq(e).attr({
- id: t,
- role: "tabpanel",
- tabindex: "0"
- })
- }
- this.$el.on("change", this.updateState), this.$tabNavItems.on("keydown", this._onKeydown), this.updateState()
- }, t.prototype.removeState = function() {
- this.$tabNav.removeAttr("role"), this.$tabNavItems.removeAttr("aria-controls aria-selected role"), this.$tabItems.removeAttr("aria-hidden id role")
- }, t.prototype.updateState = function() {
- 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({
- "aria-selected": "false",
- tabindex: "-1"
- }).eq(this.carousel.currentIndex).attr({
- "aria-selected": "true",
- tabindex: "0"
- }), this.$tabItems.attr("aria-hidden", "true").eq(this.carousel.currentIndex).attr("aria-hidden", "false")
- }, t.prototype._onKeydown = function(e) {
- var t, n = ShopifyMarketing.keyCodes;
- switch (e.keyCode) {
- case n.UP:
- case n.LEFT:
- t = this.carousel.prevIndex;
- break;
- case n.DOWN:
- case n.RIGHT:
- t = this.carousel.nextIndex;
- break;
- case n.HOME:
- t = 0;
- break;
- case n.END:
- t = this.carousel.itemsCount - 1
- }
- return void 0 !== t ? (e.preventDefault(), this.$tabNavItems.eq(t).trigger("click").trigger("focus")) : void 0
- }, t
- }(),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement