Skip to content

Commit

Permalink
cheat-sheet: Copy UTF16 instead of raw hex code
Browse files Browse the repository at this point in the history
[why]
For people using JSON they need the UTF16 codes.

While 4-digit values are no problem the new Material Design Icons code
can not be used.

[how]
Copy the UTF16 values instead of the full codepoint value (as hex
string).

Fixes: #1059

Signed-off-by: Fini Jastrow <[email protected]>
  • Loading branch information
Finii committed Jan 25, 2023
1 parent f360755 commit bae34d3
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions site.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,13 @@ document.addEventListener('DOMContentLoaded', function () {
copyTextNode.innerText = 'Copy';
copyGlyphNode.innerText = 'Icon';
copyClassNode.innerText = 'Class';
copyCodePoint.innerText = 'Hex';
copyCodePoint.innerText = 'UTF';
copyGlyphNode.title = 'Copy Icon to Clipboard';
copyClassNode.title = 'Copy Class Name to Clipboard';
copyCodePoint.title = 'Copy Hex Code Point to Clipboard';
copyCodePoint.title = 'Copy UTF-16 Codes to Clipboard';
copyGlyphNode.className = 'copy-glyph';
copyClassNode.className = 'copy-class';
copyCodePoint.className = 'copy-hex';
copyCodePoint.className = 'copy-utf16';
newNode.appendChild(copyTextNode);
newNode.appendChild(copyGlyphNode);
newNode.appendChild(copyClassNode);
Expand Down Expand Up @@ -325,6 +325,20 @@ document.addEventListener('DOMContentLoaded', function () {
.getComputedStyle(document.querySelector(`.${parent.parentNode.querySelector('.class-name').innerText}`), ':before')
.getPropertyValue('content')
.replace(/"/g, '');
} else if (target.className === 'copy-utf16') {
const glyph = window
.getComputedStyle(document.querySelector(`.${parent.parentNode.querySelector('.class-name').innerText}`), ':before')
.getPropertyValue('content')
.replace(/"/g, '');
textToCopy = '';
let i = 0;
while (i < 10) {
let c = glyph.charCodeAt(i); // js strings are utf16 already :-)
if (!(c > 0)) break;
if (c < 0x32) continue;
if (i) textToCopy += ' ';
textToCopy += glyph.charCodeAt(i++).toString(16);
}
}
gtag('event', event.target.className, {
event_category: 'clipboard-copy',
Expand All @@ -351,4 +365,4 @@ document.addEventListener('DOMContentLoaded', function () {
});
})();

});
});

0 comments on commit bae34d3

Please sign in to comment.