fastdom.write(() => { // add/remove rolled class this.$container[ this.state === 'displayed' ? 'removeClass' : 'addClass' ]('fc-container--rolled-up'); // data-link-name is inverted, as happens before clickstream this.$button.attr( 'data-link-name', toggleText[this.state === 'displayed' ? 'hidden' : 'displayed'] ); this.buttonText().text(toggleText[this.state]); });
addToggle(): void { // append toggle button const id = this.$container.attr('data-id'); const $containerHeader = $('.js-container__header', this.$container[0]); fastdom.write(() => { $containerHeader.append(this.$button); this.$container .removeClass('js-container--toggle') .removeClass('fc-container--will-have-toggle') .addClass('fc-container--has-toggle'); this.readPrefs(id); }); mediator.on('module:clickstream:click', clickSpec => { if (clickSpec.target === this.$button[0]) { this.setState( this.state === 'displayed' ? 'hidden' : 'displayed' ); this.updatePref(id); } }); }