<commit_before>M.wrap('github/IonicaBizau/bind-table-crud/dev/sort.js', function (require, module, exports) {


function init (module, config) {
    var self = module;

    (function (mod) {

        mod.sortCache = { "sort": [] };
        mod.sortCount = 1;
        mod.sortClass = "sort"
        mod.sortSelector = "th span." + mod.sortClass;

        $(mod.dom).on("click", "th", function (e) {

            if ($(this).attr('data-nosort')) { return; }

            var $current = $(this);
            $current = $current.find("." + mod.sortClass);
            var $th = $current.parent();

            var $current = $th.find("." + mod.sortClass + ":visible");
            var $next = $current.next();
            if (!$next.length) { $next = $th.find("." + mod.sortClass).first(); }

            var sort = $next.data(mod.sortClass);
            if (!sort) { return; }


            var options = mod.sortCache;
            var infScroll = mod.config.options.infiniteScroll;
            if (infScroll) {
                options.limit = infScroll.skip + infScroll.count;
                options.skip = 0;
                mod.clearList = true;
            }

            setSort.call(mod, sort, !e.ctrlKey, true);
            updateUI.call(mod);
        });
    })(self);
}

/*
 * Sets the sort and emits "setOptions" sending the sortCache
 * */

function setSort (sort, reset, callFind) {

    // get self
    var self = this;

    // if reset
    if (reset) {

        // clear sort
        clear.call(this);

        // and call again this function with reset false
        setSort.call(this, sort, false, callFind);

    } else {

        // return if no sort
        if (!sort.length) { return; }

        // remove existing sorts
        for (var i = 0; i < self.sortCache.sort.length; ++i) {
            if (sort[0] === self.sortCache.sort[i][0]) {
                self.sortCache.sort.splice(i, 1);
                break;
            }
        }

        // no sort
        if (sort[1] === 0) { return; }

        // remove first sort when sort length is higher than sortCount
        if (self.sortCache.sort.length >= self.sortCount) {
            self.sortCache.sort.splice(0, 1);
        }

        // push the new sort array in the sortCache.sort array
        self.sortCache.sort.push(sort);

        // and emit setOptions:
        // sort, reset: false, callFind: true/false
        self.emit("setOptions", self.sortCache, false, callFind);
    }<commit_msg>Fixed #14. Use pushSort variable to be sure that the new sort must be pushed.<commit_after>M.wrap('github/IonicaBizau/bind-table-crud/dev/sort.js', function (require, module, exports) {


function init (module, config) {
    var self = module;

    (function (mod) {

        mod.sortCache = { "sort": [] };
        mod.sortCount = 1;
        mod.sortClass = "sort"
        mod.sortSelector = "th span." + mod.sortClass;

        $(mod.dom).on("click", "th", function (e) {

            if ($(this).attr('data-nosort')) { return; }

            var $current = $(this);
            $current = $current.find("." + mod.sortClass);
            var $th = $current.parent();

            var $current = $th.find("." + mod.sortClass + ":visible");
            var $next = $current.next();
            if (!$next.length) { $next = $th.find("." + mod.sortClass).first(); }

            var sort = $next.data(mod.sortClass);
            if (!sort) { return; }


            var options = mod.sortCache;
            var infScroll = mod.config.options.infiniteScroll;
            if (infScroll) {
                options.limit = infScroll.skip + infScroll.count;
                options.skip = 0;
                mod.clearList = true;
            }

            setSort.call(mod, sort, !e.ctrlKey, true);
            updateUI.call(mod);
        });
    })(self);
}

/*
 * Sets the sort and emits "setOptions" sending the sortCache
 * */

function setSort (sort, reset, callFind) {

    // get self
    var self = this;

    // if reset
    if (reset) {

        // clear sort
        clear.call(this);

        // and call again this function with reset false
        setSort.call(this, sort, false, callFind);

    } else {

        // return if no sort
        if (!sort.length) { return; }

        // remove existing sorts
        for (var i = 0; i < self.sortCache.sort.length; ++i) {
            if (sort[0] === self.sortCache.sort[i][0]) {
                self.sortCache.sort.splice(i, 1);
                break;
            }
        }

        // pushSort is set to false when there is no sort
        var pushSort = true;

        // no sort
        if (sort[1] === 0) {
            // so, pushSort must be false
            pushSort = false;
        }

        // remove first sort when sort length is higher than sortCount
        if (self.sortCache.sort.length >= self.sortCount) {
            self.sortCache.sort.splice(0, 1);
        }

        // push the new sort array in the sortCache.sort array
        if (pushSort) {
            // only if pushSort is true
            self.sortCache.sort.push(sort);
        }

        // and emit setOptions:
        // sort, reset: false, callFind: true/false
        self.emit("setOptions", self.sortCache, false, callFind);
    }
{'fraction_non_alphanumeric': 0.14032749428789032, 'fraction_numerical': 0.004188880426504189, 'mean_word_length': 1.6760061130922057, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4448880', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1531, 'n_words': 410}