yui / yui3

A library for building richly interactive web applications.
http://yuilibrary.com/
Other
4.12k stars 1.29k forks source link

[DOM] Improve some methods #1821

Open brunocoelho opened 10 years ago

brunocoelho commented 10 years ago

I was wondering if it is a good idea to make some methods accept regex to do queries instead of only strings.

I have some nodes using bootstrap grid column class, which could be different according to some situations, for example: col-xs-3, col-sm-2, col-md-10 or col-lg-1. As you can see it changes only the part on the middle of it.

At some time I want to do a query to know if some node has a class of that type, something like this:

node.hasClass(/col-(?:xs|sm|md|lg)-(\d+)/);

Is it a good idea to support regex in this case?

I thought in something like this:

hasClass: function(node, className) {
    var re;

    if (typeof className === 'string') {
        re = Y.DOM._getRegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
    }
    else {
        re = className;
    }

    return re.test(node.className);
}
okuryu commented 10 years ago

I would like to bring Selectors Level 4 Polyfills for these use cases in the future. I believe this will be a standard spec. It will be able to landed many new features such as :matches(), :has() selectors.

brunocoelho commented 10 years ago

Yeah, it would be nice. So, today there's nothing we can do, right?

clarle commented 10 years ago

@okuryu :+1: on that initiative. I would definitely like to see that happen.

okuryu commented 10 years ago

I'll try to work for that.

brunocoelho commented 10 years ago

I would love to help with it, but things could be easier if there were a kind of roadmap. Let me know when you start to plan it.

triptych commented 10 years ago

this would be an excellent thing to start as a thread in https://groups.google.com/forum/#!forum/yui-contrib to get interested parties discussing it, etc.