NeXTs / Jets.js

Native CSS search engine
https://jets.js.org
MIT License
2.8k stars 108 forks source link

manual search with manual content handling #29

Open taivu opened 7 years ago

taivu commented 7 years ago
var plateFilter = new Jets({
            callSearchManually: true,
            contentTag: '.plates',
            hideBy: 'opacity: 0; height: 0; width: 0; padding: 0; margin: 0; display: none;',
            manualContentHandling: function(filterTag) {
                // console.log(tag.querySelector('.plate-title').textContent);

                console.log('filtering by attribute...');
                console.log(filterTag.getAttribute('data-categories'));
                return filterTag.getAttribute('data-categories');
            }
        });
        $('.plateGallery-filter label').on('click', function() {
            console.log('filtering...');
            var FILTER_INPUT = $(this).find('input');

            if ( FILTER_INPUT.prop('checked') ) {
                var FILTER_CATEGORY = FILTER_INPUT.attr('data-category');

                console.log('filtering for: ' + FILTER_CATEGORY);
                plateFilter.search(FILTER_CATEGORY);
            } else {
                plateFilter.search('');
            }
        });

the "console.log('filtering by attribute...');" doesnt run in the manualContentHandling method.

I couldnt find any documentation on using both, only separately.

taivu commented 7 years ago

nevermind. I had 2 instances of Jets, and the first instance manualContentHandling was okay. The 2nd one never ran, but i moved everything to the first instance. Not sure if this is by design or if its a bug, but figured its worth mentioning.

NeXTs commented 7 years ago

Hey it should not work the way you described, each instance should has own manualContentHandling.. could you please provide example (at least simplified) at codepen?

taivu commented 7 years ago

heres a simplified codepen example. I have 2 instances of Jets, targeting the same class, ".plate". Check the console, i put console.logs in them, and only the 1st one runs.

http://codepen.io/anon/pen/ZBombX