Created
March 14, 2019 09:17
-
-
Save maxcelos/7cc5b1aa56e3a787c379a225db72c4a9 to your computer and use it in GitHub Desktop.
Automatically creates a initials placeholder from user's name like Trello
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Trello's-like Name Initials</title> | |
<style> | |
[data-letters]:before { | |
content:attr(data-letters); | |
display:inline-block; | |
font-size:1em; | |
width:2.5em; | |
height:2.5em; | |
line-height:2.5em; | |
text-align:center; | |
border-radius:50%; | |
background: #eeeeee; | |
vertical-align:middle; | |
margin-right:0.2em; | |
color: #515151; | |
} | |
</style> | |
</head> | |
<body> | |
<span data-letters="" id="navUserInitials"> | |
<span id="navUserName">Marcelo Barros</span> | |
</span> | |
<script> | |
let name = document.getElementById('navUserName').innerHTML; | |
let initialSpot = document.getElementById('navUserInitials'); | |
let initials = name.match(/\b\w/g) || []; | |
initials = ((initials.shift() || '') + (initials.pop() || '')).toUpperCase(); | |
initialSpot.setAttribute('data-letters', initials) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Muito bom!!