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

Allow items to be in multiple groups #159

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dmorgan81
Copy link

@dmorgan81 dmorgan81 commented Aug 9, 2017

If items are in multiple groups interesting custom function
possibilities are opened up. For example, a section could have a toggle
that shows/hides all other items in that section. With multiple groups
attaching that behavior to all special toggles becomes something like
this:

Clay.getItemsByGroup('section-toggle').forEach(function(toggle) {
    var groups = toggle.config.groups;
    if (!groups) return;
    groups = groups.filter(function(group) { return group !== 'section-toggle'; });
    toggle.on('change', function() {
        var enabled = this.get();
        groups.forEach(function(group) {
            Clay.getItemsByGroup(group)
                .filter(function(item) { return item !== toggle; })
                .forEach(function(item) {
                    if (enabled) item.show();
                    else item.hide();
            });
        });
    }).trigger('change');
});

Resolves #160

If items are in multiple groups interesting custom function
possibilities are opened up. For example, a section could have a toggle
that shows/hides all other items in that section. With multiple groups
attaching that behavior to all special toggles becomes something like
this:

Clay.getItemsByGroup('section-toggle').forEach(function(toggle) {
    var groups = toggle.config.groups;
    if (!groups) return;
    groups = groups.filter(function(group) { return group !== 'section-toggle'; });
    toggle.on('change', function() {
        var enabled = this.get();
        groups.forEach(function(group) {
            Clay.getItemsByGroup(group)
                .filter(function(item) { return item !== toggle; })
                .forEach(function(item) {
                    if (enabled) item.show();
                    else item.hide();
            });
        });
    }).trigger('change');
});
Array.includes() isn't supported on versions of Chrome older than 47.
Travis CI uses Chrome 37.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant