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

quichsearch.js #6830

Closed
ShashikantMaurya opened this issue Jan 27, 2016 · 9 comments
Closed

quichsearch.js #6830

ShashikantMaurya opened this issue Jan 27, 2016 · 9 comments
Assignees
Labels
🏷 Library Request A request to add a new library to cdnjs

Comments

@ShashikantMaurya
Copy link

(function ($, window, document, undefined) {
$.fn.quicksearch = function (target, opt) {

    var timeout, cache, rowcache, jq_results, val = '', e = this, options = $.extend({
        delay: 100,
        selector: null,
        stripeRows: null,
        loader: null,
        noResults: '',
        matchedResultsCount: 0,
        bind: 'keyup',
        onBefore: function () {
            return;
        },
        onAfter: function () {
            return;
        },
        show: function () {
            this.style.display = "";
        },
        hide: function () {
            this.style.display = "none";
        },
        prepareQuery: function (val) {
            return val.toLowerCase().split(' ');
        },
        testQuery: function (query, txt, _row) {
            for (var i = 0; i < query.length; i += 1) {
                if (txt.indexOf(query[i]) === -1) {
                    return false;
                }
            }
            return true;
        }
    }, opt);

    this.go = function () {

        var i = 0,
            numMatchedRows = 0,
            noresults = true,
            query = options.prepareQuery(val),
            val_empty = (val.replace(' ', '').length === 0);

        for (var i = 0, len = rowcache.length; i < len; i++) {
            if (val_empty || options.testQuery(query, cache[i], rowcache[i])) {
                options.show.apply(rowcache[i]);
                noresults = false;
                numMatchedRows++;
            } else {
                options.hide.apply(rowcache[i]);
            }
        }

        if (noresults) {
            this.results(false);
        } else {
            this.results(true);
            this.stripe();
        }

        this.matchedResultsCount = numMatchedRows;
        this.loader(false);
        options.onAfter();

        return this;
    };

    /*
    * External API so that users can perform search programatically. 
    * */
    this.search = function (submittedVal) {
        val = submittedVal;
        e.trigger();
    };

    /*
    * External API to get the number of matched results as seen in 
    * https://github.com/ruiz107/quicksearch/commit/f78dc440b42d95ce9caed1d087174dd4359982d6
    * */
    this.currentMatchedResults = function () {
        return this.matchedResultsCount;
    };

    this.stripe = function () {

        if (typeof options.stripeRows === "object" && options.stripeRows !== null) {
            var joined = options.stripeRows.join(' ');
            var stripeRows_length = options.stripeRows.length;

            jq_results.not(':hidden').each(function (i) {
                $(this).removeClass(joined).addClass(options.stripeRows[i % stripeRows_length]);
            });
        }

        return this;
    };

    this.strip_html = function (input) {
        var output = input.replace(new RegExp('<[^<]+\>', 'g'), "");
        output = $.trim(output.toLowerCase());
        return output;
    };

    this.results = function (bool) {
        if (typeof options.noResults === "string" && options.noResults !== "") {
            if (bool) {
                $(options.noResults).hide();
            } else {
                $(options.noResults).show();
            }
        }
        return this;
    };

    this.loader = function (bool) {
        if (typeof options.loader === "string" && options.loader !== "") {
            (bool) ? $(options.loader).show() : $(options.loader).hide();
        }
        return this;
    };

    this.cache = function () {

        jq_results = $(target);

        if (typeof options.noResults === "string" && options.noResults !== "") {
            jq_results = jq_results.not(options.noResults);
        }

        var t = (typeof options.selector === "string") ? jq_results.find(options.selector) : $(target).not(options.noResults);
        cache = t.map(function () {
            return e.strip_html(this.innerHTML);
        });

        rowcache = jq_results.map(function () {
            return this;
        });

        /*
        * Modified fix for sync-ing "val". 
        * Original fix https://github.com/michaellwest/quicksearch/commit/4ace4008d079298a01f97f885ba8fa956a9703d1
        * */
        val = val || this.val() || "";

        return this.go();
    };

    this.trigger = function () {
        this.loader(true);
        options.onBefore();

        window.clearTimeout(timeout);
        timeout = window.setTimeout(function () {
            e.go();
        }, options.delay);

        return this;
    };

    this.cache();
    this.results(true);
    this.stripe();
    this.loader(false);

    return this.each(function () {

        /*
        * Changed from .bind to .on.
        * */
        $(this).on(options.bind, function () {

            val = $(this).val();
            e.trigger();
        });
    });

};

} (jQuery, this, document));

@PeterDaveHello
Copy link
Contributor

What's is this for?

@ShashikantMaurya
Copy link
Author

The above script is use to make search in HTML Table or Grid Record based on search keyword.

@PeterDaveHello
Copy link
Contributor

We need detail info to host a lib, not the code.

@ShashikantMaurya
Copy link
Author

Refer below link
https://github.com/riklomas/quicksearch

@Amomo Amomo added the 🏷 Library Request A request to add a new library to cdnjs label Jan 31, 2016
@PeterDaveHello PeterDaveHello assigned sufuf3 and unassigned Amomo Sep 12, 2017
@sashberd
Copy link
Contributor

@PeterDaveHello here the maintained and updated version of this repo
https://github.com/DeuxHuitHuit/quicksearch

@sashberd sashberd self-assigned this Oct 24, 2017
@sashberd
Copy link
Contributor

sashberd commented Oct 25, 2017

@PeterDaveHello
@sufuf3
Guys I found that this lib package.json was already updated with new maintained repository
image
Strange that the issue was not closed by this update.
However, I suggest to change from npm update to git auto-update because git has more version releases.
For you discretion
Otherwise, the issue should be closed
image

@PeterDaveHello
Copy link
Contributor

Let's close this one.

@sashberd I think you misunderstand the link, it's the homepage of a library, in the Link/Tag area, it shows we are using npm auto-update on it, you can also see its package. BTW, it's better not to use many screenshot in the discussion unless necessary, I don't want to waste GitHub's resource :) Take a look at the API example and see if it fits your need in this case: necessary: https://api.cdnjs.com/libraries/jquery.quicksearch?output=human

@sashberd
Copy link
Contributor

@PeterDaveHello No problem man
But as I said I suggest to change from npm update to git auto-update because git has more version releases.
If you agree I will open new issue and take care of it

@PeterDaveHello
Copy link
Contributor

@sashberd the sure thing we can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷 Library Request A request to add a new library to cdnjs
Projects
None yet
Development

No branches or pull requests

5 participants