jmenglis / clamp-js-main

Clamps an HTML element by adding ellipsis to it if the content inside is too long - Originally from both xavi160 & josephschmitt
https://github.com/josephschmitt/Clamp.js/
26 stars 18 forks source link

Clamping in IE #8

Closed AngKov closed 6 years ago

AngKov commented 6 years ago

I'm having an issue with clamping in IE to 2 lines only. Have the same function with 3 line, and it works perfectly, and it clamps the full component to ellipsis if $clamp(element, { clamp: 2});

Would appreciate any suggestions

AngKov commented 6 years ago

found what was wrong. need to change children to ChildNode

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.childNodes && elem.lastChild.childNodes.length > 0) { return getLastChild(Array.prototype.slice.call(elem.childNodes).pop()); } //This is the absolute last child, a text node, but something's wrong with it. Remove it and keep trying else if (!elem.lastChild || !elem.lastChild.nodeValue || elem.lastChild.nodeValue === '' || elem.lastChild.nodeValue == opt.truncationChar) { elem.lastChild.parentNode.removeChild(elem.lastChild); return getLastChild(element); } //This is the last child we want, return it else { return elem.lastChild; } }

jmenglis commented 6 years ago

Fixed by f00ba8701e42212b0e3ff568a55e547944275e3c