# copy-the-code/4.0.2/classes/elementor/widgets/coupon/script.js

Copy Anything to Clipboard for WordPress – Copy Button, Copy Text &amp; Copy Code, version 4.0.2. 92 lines.

- Page: https://pluginprobe.com/plugins/copy-the-code/4.0.2/code/classes/elementor/widgets/coupon/script.js
- Raw: https://pluginprobe.com/plugins/copy-the-code/4.0.2/raw/classes/elementor/widgets/coupon/script.js
- Modified: 2024-10-10T19:27:48+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/copy-the-code/4.0.2/code/classes/elementor/widgets/coupon/script.js#L10-L20`.

```javascript
(function ($) {
	const CTCCoupon = {

		/**
		 * Init
		 */
		init: function () {
			this._bind();
		},

		/**
		 * Binds events
		 */
		_bind: function () {
			$( document ).on( 'click', '.ctc-coupon-toggle-link', this.toggleDetails );
			$( document ).on( 'click', '.ctc-coupon-link', this.handleClick );
		},

		/**
		 * Handle click
		 */
		handleClick: function (event) {
			event.preventDefault()

			const self   = $( this )
			const parent = self.parents( '.ctc-coupon' )
			if ( parent.hasClass( 'ctc-coupon-clicked' ) ) {
				return
			}

			const href       = self.attr( 'href' )
			const target     = self.attr( 'target' )
			const couponCode = parent.find( '.ctc-coupon-code' ).text().trim() || ''
			console.log( couponCode )

			parent.addClass( 'ctc-coupon-clicked' )

			CTCWP.copy( couponCode )

			window.open( href, target )
		},

		/**
		 * Handle click
		 */
		oldHandleClick: function (event) {
			event.preventDefault();

			const self   = $( this )
			const href   = self.data( 'href' )
			const target = self.data( 'target' )
			const btn    = self.find( '.ctc-coupon-button' )

			// Clicked then open the link
			if ( ! self.hasClass( 'ctc-coupon-link-clicked' ) ) {
				window.open( href, target )

				self.addClass( 'ctc-coupon-link-clicked' )
				btn.text( 'Copy Code' )
			}

			if ( self.hasClass( 'ctc-coupon-link-clicked' ) ) {
				self.addClass( 'ctc-coupon-link-copied' )
				btn.text( 'Copied' )
			}
		},

		/**
		 * Toggle Details
		 */
		toggleDetails: function (event) {
			event.preventDefault();

			const self    = $( this )
			const coupon  = self.parents( '.ctc-coupon' )
			const details = coupon.find( '.ctc-toggle-details' )

			details.slideToggle( 'fast' )
		}
	};

	/**
	 * Initialization
	 */
	$(
		function () {
			CTCCoupon.init();
		}
	);

})( jQuery );

```
