# woo-additional-terms/1.6.2/assets/js/script.js

Additional Terms Lite for WooCommerce, version 1.6.2. 84 lines.

- Page: https://pluginprobe.com/plugins/woo-additional-terms/1.6.2/code/assets/js/script.js
- Raw: https://pluginprobe.com/plugins/woo-additional-terms/1.6.2/raw/assets/js/script.js
- Modified: 2023-07-27T11:37:04+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/woo-additional-terms/1.6.2/code/assets/js/script.js#L10-L20`.

```javascript
/* global jQuery */

( function ( $ ) {
	'use strict';

	const script = {
		/**
		 * Cache.
		 *
		 * @since 1.0.0
		 *
		 * @return {void}
		 */
		cache() {
			this.vars = {};
			this.els = {};
			this.vars.selector = 'woo-additional-terms';
			this.vars.embed = `${ this.vars.selector }__link[data-action="embed"]`;
			this.vars.content = `${ script.vars.selector }__content`;
			this.vars.openClassName = `${ this.vars.selector }__link--open`;
			this.vars.closeClassName = `${ this.vars.selector }__link--closed`;
			this.vars.wrapper = `.woocommerce-terms-and-conditions-wrapper.${ this.vars.selector }`;
		},

		/**
		 * Initialize.
		 *
		 * @since 1.0.0
		 *
		 * @return {void}
		 */
		init() {
			this.cache();
			this.bindEvents();
		},

		/**
		 * Bind events.
		 *
		 * @since 1.0.0
		 *
		 * @return {void}
		 */
		bindEvents() {
			$( document.body ).on( 'click', `a.${ this.vars.embed }`, this.handleEmbedToggle );
		},

		/**
		 * Handle embed toggle.
		 *
		 * @since 1.0.0
		 *
		 * @param {Event} event Event.
		 *
		 * @return {boolean} False.
		 */
		handleEmbedToggle( event ) {
			// Prevent default.
			event.preventDefault();

			const $this = $( this );
			const $wrapper = $this.closest( script.vars.wrapper );

			// Exit early if the wrapper doesn't exist.
			if ( ! $wrapper.length ) {
				return false;
			}

			const $content = $wrapper.find( `> .${ script.vars.content }` );

			$content.slideToggle( () => {
				const isVisible = $content.is( ':visible' );

				$this.toggleClass( script.vars.openClassName, isVisible );
				$this.toggleClass( script.vars.closeClassName, ! isVisible );
			} );

			return false;
		},
	};

	script.init();
} )( jQuery );

```
