Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

support: Replace common.copy_data_attribute_value with clipboard.js.

Anders Kaseorgeb45eca57b98
diff --git a/corporate/tests/test_support_views.py b/corporate/tests/test_support_views.py
index b0319440d87..12f8595cc09 100644
--- a/corporate/tests/test_support_views.py
+++ b/corporate/tests/test_support_views.py
@@ -729,8 +729,10 @@ class TestSupportEndpoint(ZulipTestCase):
[
f"<b>Admins</b>: {self.example_email('iago')}\n",
f"<b>Owners</b>: {self.example_email('desdemona')}\n",
- 'class="copy-button" data-copytext="{}">'.format(self.example_email("iago")),
- 'class="copy-button" data-copytext="{}">'.format(
+ 'class="copy-button" data-clipboard-text="{}">'.format(
+ self.example_email("iago")
+ ),
+ 'class="copy-button" data-clipboard-text="{}">'.format(
self.example_email("desdemona")
),
],
diff --git a/templates/corporate/support/realm_details.html b/templates/corporate/support/realm_details.html
index 768c43584cb..a277971fe1f 100644
--- a/templates/corporate/support/realm_details.html
+++ b/templates/corporate/support/realm_details.html
@@ -8,7 +8,7 @@
{% set owner_emails_string = get_realm_owner_emails_as_string(realm) %}
<b>Owners</b>: {{ owner_emails_string }}
{% if owner_emails_string %}
- <a title="Copy emails" class="copy-button" data-copytext="{{ owner_emails_string }}">
+ <a title="Copy emails" class="copy-button" data-clipboard-text="{{ owner_emails_string }}">
<i class="fa fa-copy"></i>
</a>
{% endif %}
@@ -16,7 +16,7 @@
{% set admin_emails_string = get_realm_admin_emails_as_string(realm) %}
<b>Admins</b>: {{ admin_emails_string }}
{% if admin_emails_string %}
- <a title="Copy emails" class="copy-button" data-copytext="{{ admin_emails_string }}">
+ <a title="Copy emails" class="copy-button" data-clipboard-text="{{ admin_emails_string }}">
<i class="fa fa-copy"></i>
</a>
{% endif %}
@@ -24,7 +24,7 @@
{% set first_human_user = realm.get_first_human_user() %}
{% if first_human_user %}
<b>First human user</b>: {{ first_human_user.delivery_email }}
- <a title="Copy emails" class="copy-button" data-copytext="{{ first_human_user.delivery_email }}">
+ <a title="Copy emails" class="copy-button" data-clipboard-text="{{ first_human_user.delivery_email }}">
<i class="fa fa-copy"></i>
</a>
{% else %}
diff --git a/templates/corporate/support/remote_realm_details.html b/templates/corporate/support/remote_realm_details.html
index 303e6b03516..e396ceaa6c6 100644
--- a/templates/corporate/support/remote_realm_details.html
+++ b/templates/corporate/support/remote_realm_details.html
@@ -21,7 +21,7 @@
{% set billing_emails_string = get_remote_realm_billing_user_emails(remote_realm) %}
<b>Billing users</b>: {{ billing_emails_string }}
{% if billing_emails_string %}
- <a title="Copy emails" class="copy-button" data-copytext="{{ billing_emails_string }}">
+ <a title="Copy emails" class="copy-button" data-clipboard-text="{{ billing_emails_string }}">
<i class="fa fa-copy"></i>
</a>
{% endif %}
diff --git a/templates/corporate/support/remote_server_support.html b/templates/corporate/support/remote_server_support.html
index a2ff787112b..f1d347c2ed1 100644
--- a/templates/corporate/support/remote_server_support.html
+++ b/templates/corporate/support/remote_server_support.html
@@ -50,14 +50,14 @@
<p class="support-section-header">Has a discount 💸</p>
{% endif %}
<b>Contact email</b>: {{ remote_server.contact_email }}
- <a title="Copy email" class="copy-button" data-copytext="{{ remote_server.contact_email }}">
+ <a title="Copy email" class="copy-button" data-clipboard-text="{{ remote_server.contact_email }}">
<i class="fa fa-copy"></i>
</a>
<br />
{% set billing_emails_string = get_remote_server_billing_user_emails(remote_server) %}
<b>Billing users</b>: {{ billing_emails_string }}
{% if billing_emails_string %}
- <a title="Copy emails" class="copy-button" data-copytext="{{ billing_emails_string }}">
+ <a title="Copy emails" class="copy-button" data-clipboard-text="{{ billing_emails_string }}">
<i class="fa fa-copy"></i>
</a>
{% endif %}
diff --git a/templates/corporate/support/support.html b/templates/corporate/support/support.html
index 1d93a09ed3b..4a176c90c76 100644
--- a/templates/corporate/support/support.html
+++ b/templates/corporate/support/support.html
@@ -100,7 +100,7 @@
<b>Email</b>: {{ email }}<br />
{% endif %}
<b>Link</b>: {{ confirmation.url }}
- <a title="Copy link" class="copy-button" data-copytext="{{ confirmation.url }}">
+ <a title="Copy link" class="copy-button" data-clipboard-text="{{ confirmation.url }}">
<i class="fa fa-copy"></i>
</a><br />
<b>Expires in</b>: {{ confirmation.expires_in }}<br />
diff --git a/web/src/support/support.ts b/web/src/support/support.ts
index 439a3a542de..984a457db6b 100644
--- a/web/src/support/support.ts
+++ b/web/src/support/support.ts
@@ -1,7 +1,6 @@
+import ClipboardJS from "clipboard";
import $ from "jquery";
-import * as common from "../common";
-
$(() => {
$("body").on("click", ".scrub-realm-button", function (e) {
e.preventDefault();
@@ -43,7 +42,5 @@ $(() => {
}
});
- $("a.copy-button").on("click", function () {
- common.copy_data_attribute_value($(this), "copytext");
- });
+ new ClipboardJS("a.copy-button");
});
diff --git a/web/tests/support.test.js b/web/tests/support.test.js
index 5619ed7e601..79dbaaa614b 100644
--- a/web/tests/support.test.js
+++ b/web/tests/support.test.js
@@ -6,7 +6,7 @@ const path = require("path");
const {JSDOM} = require("jsdom");
-const {zrequire} = require("./lib/namespace");
+const {mock_cjs, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const $ = require("./lib/zjquery");
@@ -17,6 +17,8 @@ const template = fs.readFileSync(
const dom = new JSDOM(template, {pretendToBeVisual: true});
const document = dom.window.document;
+mock_cjs("clipboard", class Clipboard {});
+
zrequire("../src/support/support");
run_test("scrub_realm", () => {