PluginProbe
Additional Terms Lite for WooCommerce / trunk
Additional Terms Lite for WooCommerce vtrunk
1.7.3 1.7.2.1 trunk 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.6.3 All 35 releases
woo-additional-terms / assets / js / script.js

script.js in Additional Terms Lite for WooCommerce trunk, at assets/js/script.js

84 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global jQuery */
2
3 ( function ( $ ) {
4 'use strict';
5
6 const script = {
7 /**
8 * Cache.
9 *
10 * @since 1.0.0
11 *
12 * @return {void}
13 */
14 cache() {
15 this.vars = {};
16 this.els = {};
17 this.vars.selector = 'woo-additional-terms';
18 this.vars.embed = `${ this.vars.selector }__link[data-action="embed"]`;
19 this.vars.content = `${ script.vars.selector }__content`;
20 this.vars.openClassName = `${ this.vars.selector }__link--open`;
21 this.vars.closeClassName = `${ this.vars.selector }__link--closed`;
22 this.vars.wrapper = `.woocommerce-terms-and-conditions-wrapper.${ this.vars.selector }`;
23 },
24
25 /**
26 * Initialize.
27 *
28 * @since 1.0.0
29 *
30 * @return {void}
31 */
32 init() {
33 this.cache();
34 this.bindEvents();
35 },
36
37 /**
38 * Bind events.
39 *
40 * @since 1.0.0
41 *
42 * @return {void}
43 */
44 bindEvents() {
45 $( document.body ).on( 'click', `a.${ this.vars.embed }`, this.handleEmbedToggle );
46 },
47
48 /**
49 * Handle embed toggle.
50 *
51 * @since 1.0.0
52 *
53 * @param {Event} event Event.
54 *
55 * @return {boolean} False.
56 */
57 handleEmbedToggle( event ) {
58 // Prevent default.
59 event.preventDefault();
60
61 const $this = $( this );
62 const $wrapper = $this.closest( script.vars.wrapper );
63
64 // Exit early if the wrapper doesn't exist.
65 if ( ! $wrapper.length ) {
66 return false;
67 }
68
69 const $content = $wrapper.find( `> .${ script.vars.content }` );
70
71 $content.slideToggle( () => {
72 const isVisible = $content.is( ':visible' );
73
74 $this.toggleClass( script.vars.openClassName, isVisible );
75 $this.toggleClass( script.vars.closeClassName, ! isVisible );
76 } );
77
78 return false;
79 },
80 };
81
82 script.init();
83 } )( jQuery );
84