<commit_before>/*!
 * jQuery RadiantScroller
 * Version: 0.0.2 (07/01/2014)
 * Copyright (c) 2013 <NAME> (http://www.radiant-wind.com/plugins/radiant_scroller)
 *
 * Requires: jQuery 1.7.0+
 */

(function($) {
    $.radiantScroller = function(el, options) {
        var scroller = $(el);

        scroller.vars = $.extend({}, $.radiantScroller.defaults, options);

        // Store reference to scroller in data of the object
        scroller.data("radiantscroller", scroller);
        // Set to true when scrolling
        scroller.animating = false;

        var elements = scroller.find('.scroller-el'),
            el_count = elements.size(),
            el_width = scroller.vars.elementWidth + scroller.vars.elementMargin,
            per_row = Math.ceil(el_count / scroller.vars.rows),
            visible_els = 0;

        // Calculating scroller's width with regard to items per row
        scroller.width( (el_width * per_row) - scroller.vars.elementMargin );

        // Grouping elements by rows
        do $(elements.slice(0, per_row)).wrapAll('<div class="radiant_scroller_row" />');
        while((elements = elements.slice(per_row)).length > 0);

        // Wrapper with hidden scrollbars
        scroller.wrap('<div class="radiant_scroller"></div>').wrap('<div class="radiant_scroller_wrapper" />');
        var wrapper = scroller.parent('.radiant_scroller_wrapper');
        var outer_wrapper = wrapper.parent('.radiant_scroller');

        var max_wrapper_width = (scroller.vars.cols * el_width - scroller.vars.elementMargin) + 'px';
        wrapper.css('max-width', max_wrapper_width);
        outer_wrapper.css('max-width', max_wrapper_width);

        // Next/previous buttons
        var nav = $('<div class="radiant-navigation" />').insertAfter(wrapper);
        var prev = nav.append($('<div class="radiant-prev">' + scroller.vars.prevButtonText + '</div>'));
        var next = nav.append($('<div class="radiant-next">' + scroller.vars.nextButtonText + '</div>'));

        // Scroller methods
        scroller.calculateVisibleElements = function() {
            visible_els = Math.floor((wrapper.width() + scroller.vars.elementMargin) / el_width);
        };

        scroller.moveElements = function(direction, scrollBy, page_el) {
            if(!scroller.animating) {
                scroller.animating = true;
                var distance = 0;
                if (typeof scrollBy === 'undefined') {
                    distance = visible_els * el_width;
                } else { distance = visible_els * el_width * scrollBy; }

                var fraction = 0;
                if (direction === 'left') { fraction = -distance ;
                } else { fraction = distance; }

                wrapper.animate(
                    { scrollLeft: wrapper.scrollLeft() + fraction },
                    scroller.vars.animateDuration, scroller.vars.easingType,
                    function() { scroller.animating = false; }
                );

                if (scroller.vars.addPagination) {
                    wrapper.current_page.removeClass('current-page');
                    if (typeof page_el === 'undefined') {
                        if (direction === 'right') {
                            if (wrapper.current_page.next().size() > 0)
                                wrapper.current_page = wrapper.current_page.next();
                        }
                        else {
                            if (wrapper.current_page.prev().size() > 0)
                                wrapper.current_page = wrapper.current_page.prev();
                        }
                    } else {
                        wrapper.current_page = page_el;
                    }
                    wrapper.current_page.addClass('current-page');
                }
            }
        };

        scroller.createPagination = function() {
            // If there is the same number of visible elements we don't have to change anything
            if (typeof this.visible_els === 'undefined' || this.visible_els !== visible_els) {
                this.visible_els = visible_els;
                var pages = Math.ceil(per_row / visible_els);
                if (outer_wrapper.find('.radiant-pagination').size() > 0)
                    outer_wrapper.find('.radiant-pagination').remove();

                var pagination = $('<div class="radiant-pagination" />').insertAfter(wrapper);
                for (var i = 0; i < pages; i++) {
                    pagination.append('<div class="radiant-page" data-page="' + (i + 1) + '"></div>');
                }

                if (typeof wrapper.current_page === 'undefined') {
                    // If current page was not set previously, we set it now
                    wrapper.current_page = pagination.find('.radiant-page').first();
                } else {
                    var new_current_page = Math.ceil(wrapper.scrollLeft() / (visible_els * el_width));
                    wrapper.current_page = $(pagination.find('.radiant-page').get(new_current_page));
                }
                wrapper.current_page.addClass('current-page');
            }
        };

        // Binding events
        $(window).bindWithDelay('resize', function() {
            scroller.calculateVisibleElements();
            if (scroller.vars.addPagination) {
                scroller.createPagination();
            }
        }, 500, true);

        nav.on('click', '.radiant-next', function() {
            scroller.moveElements('right', 1);
        });

        nav.on('click', '.radiant-prev', function() {
            scroller.moveElements('left', 1);
        });

        if (scroller.vars.useMouseWheel) {
            wrapper.on('mousewheel', function(event) {
                event.preventDefault();
                if (event.deltaY > 0) { scroller.moveElements('right'); } else {
                    scroller.moveElements('left'); }
            });
        }

        outer_wrapper.on('click', '.radiant-page', function() {
            var $this = $(this);
            if (wrapper.current_page.get(0) !== $this.get(0)) {
                var current_page_number = wrapper.current_page.data('page');
                var this_page_number = $this.data('page');
                if (current_page_number > this_page_number) {
                    scroller.moveElements('left', current_page_number - this_page_number, $this);
                } else { scroller.moveElements('right', this_page_number - current_page_number, $this); }
            }
        });

        // Init scroller
        scroller.calculateVisibleElements();
        if (scroller.vars.addPagination) {
            scroller.createPagination();
        }
    };

    $.radiantScroller.defaults = {
        cols: 2,
        elementWidth: 200,
        elementMargin: 10,
        easingType: 'swing',
        animateDuration: 700,
        rows: 2,
        useMouseWheel: false,
        addPagination: false,
        nextButtonText: '',
        prevButtonText: ''
    };

    $.fn.radiantScroller = function(options) {
        if (options === undefined) options = {};

        if (typeof options === "object") {
            new $.radiantScroller(this, options);
        } else {
            var $scroller = $(this).data('radiantscroller');
            switch (options) {
                case "next": $scroller.moveElements('right'); break;
                case "prev": $scroller.moveElements('left'); break;
            }
        }<commit_msg>Reworked pagination<commit_after>/*!
 * jQuery RadiantScroller
 * Version: 0.0.2 (07/01/2014)
 * Copyright (c) 2013 <NAME> (http://www.radiant-wind.com/plugins/radiant_scroller)
 *
 * Requires: jQuery 1.7.0+
 */

(function($) {
    $.radiantScroller = function(el, options) {
        var scroller = $(el);

        scroller.vars = $.extend({}, $.radiantScroller.defaults, options);

        // Store reference to scroller in data of the object
        scroller.data("radiantscroller", scroller);
        // Set to true when scrolling
        scroller.animating = false;

        var elements = scroller.find('.scroller-el'),
            el_count = elements.size(),
            el_width = scroller.vars.elementWidth + scroller.vars.elementMargin,
            per_row = Math.ceil(el_count / scroller.vars.rows);

        // Calculating scroller's width with regard to items per row
        scroller.width( (el_width * per_row) - scroller.vars.elementMargin );

        // Grouping elements by rows
        do $(elements.slice(0, per_row)).wrapAll('<div class="radiant_scroller_row" />');
        while((elements = elements.slice(per_row)).length > 0);

        // Wrapper with hidden scrollbars
        scroller.wrap('<div class="radiant_scroller"></div>').wrap('<div class="radiant_scroller_wrapper" />');
        var wrapper = scroller.parent('.radiant_scroller_wrapper');
        var outer_wrapper = wrapper.parent('.radiant_scroller');

        var max_wrapper_width = (scroller.vars.cols * el_width - scroller.vars.elementMargin) + 'px';
        wrapper.css('max-width', max_wrapper_width);
        outer_wrapper.css('max-width', max_wrapper_width);

        // Next/previous buttons
        var nav = $('<div class="radiant-navigation" />').insertAfter(wrapper);
        var prev = nav.append($('<div class="radiant-prev">' + scroller.vars.prevButtonText + '</div>'));
        var next = nav.append($('<div class="radiant-next">' + scroller.vars.nextButtonText + '</div>'));

        // Scroller methods
        scroller.calculateVisibleElements = function() {
            scroller.visible_els = Math.floor((wrapper.width() + scroller.vars.elementMargin) / el_width);
        };

        scroller.moveElements = function(scrollBy) {
            if (!scroller.animating) {
                if (typeof scrollBy === 'undefined')
                    scrollBy = 1;

                var new_current_page = scroller.current_page + scrollBy;
                // The requested page should be between 0 and total number of pages and should not be the same page
                // as the current, otherwise do nothing
                if (new_current_page >= 0 && new_current_page < scroller.total_pages &&
                    new_current_page !== scroller.current_page) {
                    scroller.animating = true;

                    wrapper.animate(
                        { scrollLeft: wrapper.scrollLeft() + scroller.visible_els * el_width * scrollBy },
                        scroller.vars.animateDuration, scroller.vars.easingType,
                        function() { scroller.animating = false; }
                    );

                    scroller.current_page = new_current_page;

                    if (scroller.vars.addPagination)
                        scroller.assignActivePage(true);
                }
            }
        };

        scroller.initializePagination = function() {
            // If there is the same number of visible elements we don't have to change anything
            if (typeof scroller.old_visible_els === 'undefined' || scroller.old_visible_els !== scroller.visible_els) {
                scroller.old_visible_els = scroller.visible_els;
                scroller.total_pages = Math.ceil(per_row / scroller.visible_els);

                if (typeof scroller.current_page === 'undefined') {
                    // If current page was not set previously, we set it now
                    scroller.current_page = 0;
                } else {
                    scroller.current_page = Math.ceil(wrapper.scrollLeft() / (scroller.visible_els * el_width));
                }

                if (scroller.vars.addPagination)
                    scroller.drawPagination();
            }
        };

        scroller.drawPagination = function() {
            if (outer_wrapper.find('.radiant-pagination').size() > 0)
                outer_wrapper.find('.radiant-pagination').remove();

            var pagination = $('<div class="radiant-pagination" />').insertAfter(wrapper);
            for (var i = 0; i < scroller.total_pages; i++) {
                pagination.append('<div class="radiant-page" data-page="' + i + '" />');
            }
            scroller.assignActivePage();
        };

        scroller.assignActivePage = function(remove_old_active) {
            if (remove_old_active === true)
                outer_wrapper.find('.current-page').removeClass('current-page');
            $(outer_wrapper.find('.radiant-page').get(scroller.current_page)).addClass('current-page');
        };

        // Binding events
        $(window).bindWithDelay('resize', function() {
            scroller.calculateVisibleElements();
            scroller.initializePagination();
        }, 500, true);

        nav.on('click', '.radiant-next', function() {
            scroller.moveElements(1);
        });

        nav.on('click', '.radiant-prev', function() {
            scroller.moveElements(-1);
        });

        if (scroller.vars.useMouseWheel) {
            wrapper.on('mousewheel', function(event) {
                event.preventDefault();
                scroller.moveElements(event.deltaY);
            });
        }

        outer_wrapper.on('click', '.radiant-page', function() {
            var this_page = $(this).data('page');
            // If not clicking on the same page
            if (scroller.current_page !== this_page) {
                var current_page_number = scroller.current_page;
                scroller.moveElements(this_page - current_page_number);
            }
        });

        // Init scroller
        scroller.calculateVisibleElements();
        scroller.initializePagination();
    };

    $.radiantScroller.defaults = {
        cols: 2,
        elementWidth: 200,
        elementMargin: 10,
        easingType: 'swing',
        animateDuration: 700,
        rows: 2,
        useMouseWheel: false,
        addPagination: false,
        nextButtonText: '',
        prevButtonText: ''
    };

    $.fn.radiantScroller = function(options, options2) {
        if (options === undefined) options = {};

        if (typeof options === "object") {
            new $.radiantScroller(this, options);
        } else {
            var $scroller = $(this).data('radiantscroller');
            switch (options) {
                case "next": $scroller.moveElements(1); break;
                case "prev": $scroller.moveElements(-1); break;
                // radiantScroller('by', 2) - scroll by 2 pages, not to the 2nd page
                case "by": if (typeof options2 === "number") $scroller.moveElements(options2); break;
                // Default behaviour: radiantScroller(3) means go to 3 page and page numeration starts from 1
                // (whereas plugin has numeration starting from 0, so have to substract 1!!!)
                default: if (typeof options === "number") $scroller.moveElements(options - 1 - $scroller.current_page);
            }
        }
{'fraction_non_alphanumeric': 0.12794364307279438, 'fraction_numerical': 0.006776249580677625, 'mean_word_length': 1.9033891702376315, 'pattern_counts': {'":': 5, '<': 31, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1431348', 'n_tokens_mistral': 4135, 'n_tokens_neox': 3915, 'n_words': 807}