PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 2.4.0
Subscriptions for WooCommerce with Stripe Recurring Payments v2.4.0
2.4.0 2.3.0 2.2.0 2.1.0 2.0.0 1.11.2 1.11.1 1.11.0 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.6 1.9.5 trunk 1.3.0 1.3.1 1.3.2 1.4.0 All 65 releases
subscription / assets / js / gateway.js

gateway.js in Subscriptions for WooCommerce with Stripe Recurring Payments 2.4.0, at assets/js/gateway.js

107 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function ($) {
2 function addPasswordToggle(inputId) {
3 const $input = $("#" + inputId);
4 if (!$input.length) return;
5
6 // Default value.
7 let isPassword = $input.attr("type") === "password";
8
9 // Create Dashicon toggle button
10 const $toggleBtn = $("<button>")
11 .attr("type", "button")
12 .addClass("dashicons")
13 .addClass(isPassword ? "dashicons-visibility" : "dashicons-hidden")
14 .css({
15 border: $input.css("border"),
16 borderRadius: $input.css("border-radius"),
17 background: $input.css("background-color"),
18 height: $input.height(),
19 minHeight: "30px",
20 width: "35px",
21 margin: "0px 8px",
22 fontSize: "18px",
23 cursor: "pointer",
24 lineHeight: 1,
25 })
26 .attr("title", wp.i18n.__("Show password", "subscription"));
27
28 // Toggle functionality
29 $toggleBtn.on("click", function () {
30 isPassword = $input.attr("type") === "password";
31 $input.attr("type", isPassword ? "text" : "password");
32 $toggleBtn
33 .removeClass("dashicons-visibility dashicons-hidden")
34 .addClass(isPassword ? "dashicons-hidden" : "dashicons-visibility")
35 .attr(
36 "title",
37 isPassword ? wp.i18n.__("Hide password", "subscription") : wp.i18n.__("Show password", "subscription"),
38 );
39 });
40
41 // Insert button
42 $input.after($toggleBtn);
43 }
44
45 // Add copy button
46 function addCopyButton(inputId) {
47 const $input = $("#" + inputId);
48 if (!$input.length) return;
49
50 // Create Dashicon copy button
51 const $copyBtn = $("<button>")
52 .attr("type", "button")
53 .addClass("dashicons dashicons-admin-page")
54 .css({
55 border: $input.css("border"),
56 borderRadius: $input.css("border-radius"),
57 background: $input.css("background-color"),
58 height: $input.height(),
59 minHeight: "30px",
60 width: "35px",
61 margin: "0px 8px",
62 fontSize: "18px",
63 cursor: "pointer",
64 lineHeight: 1,
65 })
66 .attr("title", wp.i18n.__("Copy to clipboard", "subscription"));
67
68 // Copy functionality
69 $copyBtn.on("click", function (event) {
70 event.preventDefault();
71 const text = $input.val();
72
73 try {
74 if (navigator.clipboard && navigator.clipboard.writeText) {
75 navigator.clipboard.writeText(text);
76 } else {
77 const tempInput = document.createElement("textarea");
78 tempInput.value = text;
79 document.body.appendChild(tempInput);
80 tempInput.select();
81 document.execCommand("copy");
82 document.body.removeChild(tempInput);
83 }
84 alert(wp.i18n.__("Copied to clipboard.", "subscription"));
85 } catch (err) {
86 alert(wp.i18n.__("Could not copy. Please copy it manually.", "subscription"));
87 console.error("Failed to the data. ", err);
88 }
89 });
90
91 // Insert button
92 $input.after($copyBtn);
93 }
94
95 // Add toggles
96 addPasswordToggle("woocommerce_wp_subscription_paypal_client_id");
97 addPasswordToggle("woocommerce_wp_subscription_paypal_client_secret");
98 addPasswordToggle("woocommerce_wp_subscription_paypal_webhook_id");
99
100 addPasswordToggle("woocommerce_wp_subscription_paypal_sandbox_client_id");
101 addPasswordToggle("woocommerce_wp_subscription_paypal_sandbox_client_secret");
102 addPasswordToggle("woocommerce_wp_subscription_paypal_sandbox_webhook_id");
103
104 // Add copy buttons
105 addCopyButton("woocommerce_wp_subscription_paypal_webhook_url");
106 });
107