frontend.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ; (function ($) {
  2. PPCoupon = function (settings) {
  3. this.id = settings.id;
  4. this.couponStyle = settings.coupon_style;
  5. this.couponCode = settings.coupon_code;
  6. this.node = $('.fl-node-' + this.id);
  7. this._init();
  8. };
  9. PPCoupon.prototype = {
  10. _init: function () {
  11. var self = this;
  12. self.node.find('.pp-coupon-code:not(.pp-coupon-style-no_code)').not('.pp-copied').on('click', function(){
  13. if ( $(this).find( '.pp-coupon-code-no-code' ).length > 0 ) {
  14. return;
  15. }
  16. var clicked = $(this);
  17. var tempInput = '<input type="text" value="' + self.couponCode + '" id="ppCouponInput">';
  18. clicked.append(tempInput);
  19. var copyText = document.getElementById("ppCouponInput");
  20. copyText.select();
  21. document.execCommand("copy");
  22. $('#ppCouponInput').remove();
  23. if ('copy' === self.couponStyle) {
  24. clicked.addClass('pp-copied');
  25. clicked.find('.pp-coupon-copy-text').fadeOut().text('Copied').fadeIn();
  26. } else {
  27. clicked.find('.pp-coupon-reveal-wrap').css({
  28. 'transform': 'translate(200px, 0px)',
  29. });
  30. setTimeout(function () {
  31. clicked.find('.pp-coupon-code-text-wrap').removeClass('pp-unreavel');
  32. clicked.find('.pp-coupon-code-text').text(self.couponCode);
  33. clicked.find('.pp-coupon-reveal-wrap').remove();
  34. }, 150);
  35. setTimeout(function () {
  36. clicked.addClass('pp-copied');
  37. clicked.find('.pp-coupon-copy-text').fadeOut().text('Copied').fadeIn();
  38. }, 500);
  39. }
  40. });
  41. },
  42. };
  43. }) (jQuery);