Skip to content

Commit e628bdf

Browse files
authored
Merge pull request #48958 from apoorvapendse/main
web: Improve UX for copyCode animation
2 parents 620d7f2 + f56cf73 commit e628bdf

File tree

7 files changed

+71
-14
lines changed

7 files changed

+71
-14
lines changed

assets/js/sweetalert-2.1.2.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

assets/js/toastr-2.1.4.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/scss/_custom.scss

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1947,14 +1947,24 @@ body.td-search #search {
19471947

19481948
.code-sample > .copy-code-icon {
19491949
cursor: pointer;
1950-
text-align: right;
1950+
display: flex;
1951+
gap:1rem;
1952+
justify-content: right;
19511953
padding: 0.2rem;
19521954
}
19531955

19541956
.includecode .highlight {
19551957
margin-top: 0;
19561958
margin-bottom: 0;
19571959
}
1960+
#toast-container > *{
1961+
background: $primary;
1962+
}
1963+
1964+
.toast-success {
1965+
background-color: $primary !important;
1966+
color: #ffffff !important;
1967+
}
19581968

19591969
// handle main page features on narrow viewports
19601970
@media screen and (max-width: 768px) {

data/i18n/en/en.toml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ other = "Show More Posts..."
1818
[banner_acknowledgement]
1919
other = "Hide this notice"
2020

21+
[browser_clipboard_support_warning]
22+
other = "Sorry, your browser doesn't support copying this example to your clipboard."
23+
2124
[case_study_prefix]
2225
other = "Case study:"
2326

@@ -158,6 +161,9 @@ other = "Environment variables"
158161
[error_404_were_you_looking_for]
159162
other = "Were you looking for:"
160163

164+
[error_copy_to_clipboard]
165+
other = "Error"
166+
161167
[examples_heading]
162168
other = "Examples"
163169

@@ -603,6 +609,9 @@ other = "Toggle section navigation"
603609
[subscribe_button]
604610
other = "Subscribe"
605611

612+
[success_copy_to_clipboard]
613+
other = "Success"
614+
606615
[synopsis_heading]
607616
other = "Synopsis"
608617

@@ -621,6 +630,12 @@ other = """<p>Items on this page refer to third party products or projects that
621630
[thirdparty_message_vendor]
622631
other = """Items on this page refer to vendors external to Kubernetes. The Kubernetes project authors aren't responsible for those third-party products or projects. To add a vendor, product or project to this list, read the <a href="/docs/contribute/style/content-guide/#third-party-content">content guide</a> before submitting a change. <a href="#third-party-content-disclaimer">More information.</a>"""
623632

633+
[toast_failure_copycode]
634+
other="Failed to copy to clipboard: "
635+
636+
[toast_success_copycode]
637+
other = "Copied to clipboard: "
638+
624639
[translated_by]
625640
other = "Translated By"
626641

@@ -642,7 +657,8 @@ other = "Versions"
642657
[warning]
643658
other = "Warning:"
644659

645-
[whatsnext_heading]
646-
other = "What's next"
647-
660+
[warning_copy_to_clipboard]
661+
other = "Warning"
648662

663+
[whatsnext_heading]
664+
other = "What's next"

layouts/partials/hooks/body-end.html

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,54 @@
66
{{ end }}
77
{{/* copy-and-paste helper for codenew shortcode */}}
88
{{- if or (.HasShortcode "code_sample") (.HasShortcode "code") (.HasShortcode "codenew") -}}
9+
{{- $toastrJs := resources.Get "js/toastr-2.1.4.min.js" | minify | fingerprint -}}
910
{{- if hugo.IsProduction -}}
10-
{{- $sweetAlert := resources.Get "js/sweetalert-2.1.2.min.js" | minify | fingerprint -}}
11-
<script async src="{{ $sweetAlert.RelPermalink }}" integrity="{{ $sweetAlert.Data.Integrity }}" crossorigin="anonymous"></script>
11+
<script async src="{{ $toastrJs.RelPermalink }}"></script>
1212
{{- else -}}
13-
{{- $sweetAlert := resources.Get "js/sweetalert-2.1.2.min.js" -}}
14-
<script async src="{{ $sweetAlert.RelPermalink }}"></script>
13+
<script async src="{{ $toastrJs.RelPermalink }}"></script>
1514
{{- end -}}
15+
1616
<script type="text/javascript">
17-
function copyCode(elem){
17+
function copyCode(elem) {
1818
if (document.getElementById(elem)) {
1919
if (navigator.clipboard) {
2020
navigator.clipboard.writeText(document.getElementById(elem).textContent).then(
2121
function () {
22-
swal("Copied to clipboard: ",elem);
22+
toastr.options = {
23+
closeButton: true,
24+
progressBar: true,
25+
positionClass: "toast-bottom-center",
26+
timeOut: 2000,
27+
preventDuplicates: true,
28+
newestOnTop: true
29+
};
30+
toastr.success("{{i18n "toast_success_copycode"}}" + elem, "{{i18n "success_copy_to_clipboard"}}");
2331
},
2432
function () {
25-
swal("Oh, no…","Failed to copy to clipboard: ",elem);
26-
},
33+
toastr.options = {
34+
closeButton: true,
35+
progressBar: true,
36+
positionClass: "toast-bottom-center",
37+
timeOut: 2000,
38+
preventDuplicates: true,
39+
newestOnTop: true
40+
};
41+
toastr.error("{{i18n "toast_failure_copycode"}}" + elem, "{{i18n "error_copy_to_clipboard"}}");
42+
}
2743
);
2844
} else {
29-
swal("Oh, no…","Sorry, your browser doesn't support copying this example to your clipboard.");
45+
toastr.options = {
46+
closeButton: true,
47+
progressBar: true,
48+
positionClass: "toast-bottom-center",
49+
timeOut: 2000,
50+
preventDuplicates: true,
51+
newestOnTop: true
52+
};
53+
toastr.warning("{{i18n "browser_clipboard_support_warning"}}", "{{i18n "warning_copy_to_clipboard"}}");
3054
}
3155
}
3256
}
3357
</script>
58+
3459
{{- end -}}

layouts/partials/hooks/head-end.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@
6161
{{- $bannerDismissJs := resources.Get "js/banner-dismiss.js" -}}
6262
<script defer src="{{ $bannerDismissJs.RelPermalink }}"></script>
6363
{{- end -}}
64+
65+
{{- if or (.HasShortcode "code_sample") (.HasShortcode "code") (.HasShortcode "codenew") -}}
66+
<link rel="stylesheet" href="/css/toastr-2.1.4.min.css">
67+
{{- end -}}

static/css/toastr-2.1.4.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)