Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue when elem.lastChild is not defined #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion clamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@
* Gets an element's last child. That may be another node or a node's contents.
*/
function getLastChild(elem) {
if (!elem.lastChild) {
return;
}
//Current element has children, need to go deeper and get last child as a text node
if (elem.lastChild.children && elem.lastChild.children.length > 0) {
return getLastChild(Array.prototype.slice.call(elem.children).pop());
Expand All @@ -133,7 +136,7 @@
* height is beneath the passed-in max param.
*/
function truncate(target, maxHeight) {
if (!maxHeight) {return;}
if (!target || !maxHeight) {return;}

/**
* Resets global variables.
Expand Down
13 changes: 1 addition & 12 deletions clamp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.