-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidetext.min.js
11 lines (7 loc) · 1.25 KB
/
widetext.min.js
1
2
3
4
5
6
7
8
9
10
11
/* WideText
v3.1.1 - 2016-09-27
https://github.com/olets/WideText
Copyright (c) 2016 Henry Bley-Vroman (@olets)
MIT License
*/
function wideText(t){var e={selector:".widetext",leading:.2,align:"",row:"tspan"};"string"==typeof t&&(t={selector:t}),"object"!=typeof t&&(t={});for(var i in e)i in t||(t[i]=e[i]);for(var r=document.querySelectorAll(t.selector),l=0;l<r.length;++l){for(var a=r[l],d=document.createElementNS("http://www.w3.org/2000/svg","svg"),s=document.createElementNS("http://www.w3.org/2000/svg","text"),n=a.getAttribute("data-align")||t.align,o=a.getAttribute("data-leading")||t.leading,g=parseFloat(o,10)+1+"em";a.firstChild;)s.appendChild(a.firstChild);if("center"==n)var w="middle";else if("right"==n)var w="end";w&&s.setAttribute("text-anchor",w),s.classList.add("wideText_text");var c=s.querySelectorAll(t.row);for(j=0;j<c.length;j++){for(var h=c[j],p=document.createElementNS("http://www.w3.org/2000/svg","tspan");h.firstChild;)p.appendChild(h.firstChild);p.setAttribute("x","0"),p.setAttribute("dy",g),s.replaceChild(p,h)}d.appendChild(s),d.style.width="100%",d.style.display="block",d.style["font-size"]="6px",d.classList.add("wideText_svg"),a.appendChild(d);var f=s.getBBox();d.setAttribute("viewBox",[f.x,f.y,f.width,f.height].join(" "))}}