Skip to content

Commit

Permalink
Merge pull request #11 from kkwiatkowski/master
Browse files Browse the repository at this point in the history
Support for IE11, Edge and Firefox
  • Loading branch information
CezaryDanielNowak committed Oct 21, 2016
2 parents 89772aa + e41748a commit bb9888d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/clamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,26 @@
if (elem.lastChild.children && elem.lastChild.children.length > 0) {
return getLastChild(Array.prototype.slice.call(elem.children).pop());
}
//This is the absolute last child, a text node, but something's wrong with it. Remove it and keep trying
//Handle scenario where the last child is white-space node
else if (!elem.lastChild || !elem.lastChild.nodeValue || elem.lastChild.nodeValue === '' || elem.lastChild.nodeValue == opt.truncationChar) {
elem.lastChild.parentNode.removeChild(elem.lastChild);
return getLastChild(element);
var sibling = elem.lastChild;
do {
if (!sibling) {
return;
}
//TEXT_NODE
if (sibling.nodeType === 3 && ['', opt.truncationChar].indexOf(sibling.nodeValue) === -1) {
return sibling;
}
if (sibling.lastChild) {
var lastChild = getLastChild(sibling);
if (lastChild) {
return lastChild;
}
}
//Current sibling is pretty useless
sibling.parentNode.removeChild(sibling);
} while (sibling = sibling.previousSibling);
}
//This is the last child we want, return it
else {
Expand Down
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ function Dotdotdot() {
if(!(this instanceof Dotdotdot)) {
throw new TypeError("Cannot call a class as a function");
}
this.update = this.update.bind(this);
}

Dotdotdot.prototype = Object.create(React.Component.prototype);
Dotdotdot.prototype.componentDidMount = function() {
this.dotdotdot(ReactDOM.findDOMNode(this.refs.container));
window.addEventListener('resize', this.update, false);
};
Dotdotdot.prototype.componentWillUnmount = function() {
window.removeEventListener('resize', this.update, false);
};
Dotdotdot.prototype.componentDidUpdate = function() {
this.dotdotdot(ReactDOM.findDOMNode(this.refs.container));
Expand All @@ -31,6 +36,9 @@ Dotdotdot.prototype.dotdotdot = function(container) {
});
}
};
Dotdotdot.prototype.update = function() {
this.forceUpdate();
};

Dotdotdot.prototype.render = function() {
return React.createElement(
Expand Down

0 comments on commit bb9888d

Please sign in to comment.