PluginProbe
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code / 3.8.2
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code v3.8.2
5.5.3 3.1.0 3.2.0 3.2.1 3.3.0 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.6.0 3.7.0 3.8.0 3.8.1 3.8.2 3.8.3 4.0.0 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 All 78 releases
copy-the-code / classes / elementor / widgets / coupon / script.js

script.js in Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code 3.8.2, at classes/elementor/widgets/coupon/script.js

89 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function ($) {
2 const CTCCoupon = {
3
4 /**
5 * Init
6 */
7 init: function () {
8 this._bind();
9 },
10
11 /**
12 * Binds events
13 */
14 _bind: function () {
15 $( document ).on( 'click', '.ctc-coupon-toggle-link', this.toggleDetails );
16 $( document ).on( 'click', '.ctc-coupon-link', this.handleClick );
17 },
18
19 /**
20 * Handle click
21 */
22 handleClick: function (event) {
23 event.preventDefault()
24
25 const self = $( this )
26 const parent = self.parents( '.ctc-coupon' )
27 if ( parent.hasClass( 'ctc-coupon-clicked' ) ) {
28 return
29 }
30
31 const href = self.attr( 'href' )
32 const target = self.attr( 'target' )
33 const couponCode = parent.find( '.ctc-coupon-code' ).text().trim() || ''
34 console.log( couponCode )
35
36 parent.addClass( 'ctc-coupon-clicked' )
37
38 CTCWP.copy( couponCode )
39
40 window.open( href, target )
41 },
42
43 /**
44 * Handle click
45 */
46 oldHandleClick: function (event) {
47 event.preventDefault();
48
49 const self = $( this )
50 const href = self.data( 'href' )
51 const target = self.data( 'target' )
52 const btn = self.find( '.ctc-coupon-button' )
53
54 // Clicked then open the link
55 if ( ! self.hasClass( 'ctc-coupon-link-clicked' ) ) {
56 window.open( href, target )
57
58 self.addClass( 'ctc-coupon-link-clicked' )
59 btn.text( 'Copy Code' )
60 }
61
62 if ( self.hasClass( 'ctc-coupon-link-clicked' ) ) {
63 self.addClass( 'ctc-coupon-link-copied' )
64 btn.text( 'Copied' )
65 }
66 },
67
68 /**
69 * Toggle Details
70 */
71 toggleDetails: function (event) {
72 event.preventDefault();
73
74 const self = $( this )
75 const coupon = self.parents( '.ctc-coupon' )
76 const details = coupon.find( '.ctc-toggle-details' )
77
78 details.slideToggle( 'fast' )
79 }
80 };
81
82 /**
83 * Initialization
84 */
85 $(function () {
86 CTCCoupon.init();
87 });
88
89 })(jQuery);