| 1 |
/* global jQuery */ |
| 2 |
|
| 3 |
( function ( $ ) { |
| 4 |
'use strict'; |
| 5 |
|
| 6 |
const wat = { |
| 7 |
cache() { |
| 8 |
this.vars = {}; |
| 9 |
this.els = {}; |
| 10 |
this.vars.selector = 'woo-additional-terms'; |
| 11 |
this.vars.embed = `${ this.vars.selector }__link`; |
| 12 |
this.vars.content = `${ wat.vars.selector }__content`; |
| 13 |
this.vars.openClassName = `${ this.vars.selector }__link--open`; |
| 14 |
this.vars.closeClassName = `${ this.vars.selector }__link--closed`; |
| 15 |
this.vars.wrapper = `.woocommerce-terms-and-conditions-wrapper.${ this.vars.selector }`; |
| 16 |
}, |
| 17 |
|
| 18 |
init() { |
| 19 |
this.cache(); |
| 20 |
this.events(); |
| 21 |
}, |
| 22 |
|
| 23 |
events() { |
| 24 |
$( document.body ).on( 'click', `a.${ this.vars.embed }`, this.handleEmbedToggle ); |
| 25 |
}, |
| 26 |
|
| 27 |
handleEmbedToggle( event ) { |
| 28 |
event.preventDefault(); |
| 29 |
|
| 30 |
const $this = $( this ); |
| 31 |
const $wrapper = $this.closest( wat.vars.wrapper ); |
| 32 |
const $content = $wrapper.find( `.${ wat.vars.content }` ); |
| 33 |
|
| 34 |
if ( $wrapper.length ) { |
| 35 |
$content.slideToggle( function () { |
| 36 |
if ( $content.is( ':visible' ) ) { |
| 37 |
$this.addClass( wat.vars.openClassName ); |
| 38 |
$this.removeClass( wat.vars.closeClassName ); |
| 39 |
} else { |
| 40 |
$this.removeClass( wat.vars.openClassName ); |
| 41 |
$this.addClass( wat.vars.closeClassName ); |
| 42 |
} |
| 43 |
} ); |
| 44 |
|
| 45 |
return false; |
| 46 |
} |
| 47 |
}, |
| 48 |
}; |
| 49 |
|
| 50 |
wat.init(); |
| 51 |
} )( jQuery ); |
| 52 |
|