Skip to content

Instantly share code, notes, and snippets.

@danbeam
Created April 9, 2011 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danbeam/911037 to your computer and use it in GitHub Desktop.
Save danbeam/911037 to your computer and use it in GitHub Desktop.
Feature test for text-overflow: ellipsis; with YUI3
YUI().use('gallery-ellipsis', function (Y) {
// must wait to append hidden node
Y.on('domready', function () {
// create a hidden node and try to style it
var cloned,
hidden = Y.Node.create('<div style="visibility:hidden;position:absolute;white-space:nowrap;overflow:hidden;"></div>'),
rules = ['textOverflow', 'OTextOverflow'];
Y.each(rules, function (rule) {
hidden.setStyle(rule, 'ellipsis');
});
// add to DOM
Y.one('body').appendChild(hidden);
// deep clone the node (include attributes)
cloned = hidden.cloneNode(true);
Y.some(rules, function (rule) {
if ('ellipsis' === cloned.getStyle(rule)) {
Y.DOM.ellipsis.nativeRule = rule;
Y.DOM.ellipsis.nativeSupport = true;
return true;
}
});
// clean-up
hidden.remove();
hidden = cloned = null;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment