'use strict'; (function($) { /** * Accordion_ctm: アコーディオン */ var Accordion_ctm = function(element, options) { this.$element = $(element); this.$trigger = this.$element.find('.accordion-ttl-ctm'); this.init(options); }; Accordion_ctm.prototype = { init: function(options) { this.options = $.extend({}, this.defaults, options); this.initializeEvent(); }, initializeEvent: function() { var _this = this; _this.$trigger.on('keypress', $.proxy(_this.keyHandler, _this)); _this.$trigger.on('click', $.proxy(_this.clickHandler, _this)); }, keyHandler: function(e) { var _this = this; if(e.keyCode === 13) { $.proxy(_this.clickHandler, _this)(e); } }, clickHandler: function(e) { var _this = this, $target = $(e.currentTarget).next(), $close = $(e.currentTarget).next().find('.accordion-close'); var $toggleButton = $(e.currentTarget).find('.ml3 .button'); const isExpanded = $toggleButton.attr('aria-expanded') === 'true'; // $target.slideToggle(); $(e.currentTarget).toggleClass('is-opened'); $target.toggleClass('is-opened'); // aria属性の反転 $toggleButton.attr('aria-expanded', !isExpanded); $close.on('click', function() { $(e.currentTarget).removeClass('is-opened'); $target.removeClass('is-opened'); // aria属性を閉じるに変更 $toggleButton.attr('aria-expanded', 'false'); }); } }; $.fn.Accordion_ctm = function(options) { return this.each(function() { new Accordion_ctm(this, options); }); }; $(function() { $('.js-accordion-ctm').Accordion_ctm(); }); })(jQuery, window, document);