Created
October 18, 2010 23:18
-
-
Save joshwnj/633274 to your computer and use it in GitHub Desktop.
detect text overflow and crop, inserting an ellipsis
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
var TextOverflow = { | |
crop: function(elm) { | |
var w = elm.width(), | |
t = elm.text(), | |
child; | |
elm.html('<span style="overflow: hidden; white-space: nowrap">'+t+'</span>'); | |
child = elm.children(":first-child"); | |
while (t.length > 0 && child.width() > w) { | |
t = t.substr(0, t.length - 1); | |
child.html(t + '<span class="ellipsis">…</span>'); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment