<commit_before>/**
 * HATCHD DIGITAL SLIDE
 *
 * The slide hatchdling allows for simple carousel action in your browser in
 * a way that works for RWD. We've taken a look at the requirements for the
 * slider to change depending on the width of the page as possible.
 *
 * This code has been developed in house at HATCHD DIGITAL.
 * @see http://hatchd.com.au/
 *
 * FOR DEVELOPERS:
 *
 * The code in this file should always be well formatted and never be
 * used in production systems. Your site should always use disc/*-.min.js
 * which contains a packed and minified version of the script
 * prepended with all dependencies.
 *
 * REQUIRED FRAMEWORKS
 *
 * @required jquery (v1.8.0+)
 * -- (http://jquery.com)
 *
 * VALIDATION
 *
 * All code must validate with JSHint (http://www.jshint.com/) before
 * commiting this repo. NO debug code should remain in your final
 * versions. Ensure to remove every reference to console.log.
 *
 * STYLE
 *
 * All code should be within 79 characters WIDE to meet standard Hatchd
 * protocol. Reformat code cleanly to fit within this tool.
 *
 * CONTRIBUTORS
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 */

/* global define */

(function (factory) {
    'use strict';

    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define(['jquery'], factory);
    }
    else {
        // Browser globals
        window.Slide = factory(window.jQuery);
    }

}(function ($) {
    'use strict';

    /**
     * Helper methods.
     */
    var getTime = (Date.now || function() {
        return new Date().getTime();
    });

    /**
     * Base object for storing requried information about each Slide module
     * on any given page.
     *
     * @param {selector} The element wrapping the Slide
     * @param {object} Default initialization options
     * @return Slide
     */
    var Slide = function Slide(element, options) {

        var item_count;

        // Set and extend default options with user provided
        this.options = $.extend({
            'loop': false,
            'onChange': null,
            'onInit': null,
            'grouping': 4,
            'breakpoints': null
        }, options);

        // Set event listeners
        this.onChange = this.options.onChange;
        this.onInit = this.options.onInit;

        // Set local private variables for managing the current state
        this._element = $(element);
        this._items = this._element.find('.slide-item');
        this._translate = 0;

        // Find the initial current image
        this._current = $(this._items.filter('.state-current'));
        if (!this._current.length) {
            this._current = this._items.first();
            this._current.addClass('state-current');
        }

        // Initialize grouping based on breakpoint or provided grouping
        if (this.options.breakpoints !== null) {
            this._bindBreakpoints(this.options.breakpoints);
            $(window).trigger('resize');
        }
        else {
            this.setGrouping(this.options.grouping);
        }

        // Bind all events for next/previous/specific
        this._bind();

        // Draw the slideshow
        this._draw();

        // Trigger that we are built and ready to roll
        this._element.trigger('init', this._current);

        return this;
    };

    /**
     * Draw the current slideshow. Generate the correct sizing and widths
     * for each element to respond correctly at the current breakpoint.
     * Also updates the controller state based on any changes.
     *
     * @return {Slide}
     */
    Slide.prototype._draw = function () {
        // Set correct state on controls
        this._updateControls();
        // Initialize sizes for each slide for responsive nature
        this._element.find('.slide-items').css(
            'width', (100 * (this._items.length / this._grouping)).toString() + '%');
        this._items.css('width', (100 / this._items.length).toString() + '%');
        return this;
    };

    /**
     * Setup breakpoint support for the slider. This will only be called
     * if breakpoints are provided to the slider. Polling function to
     * update the current draw state on browser width changes.
     *
     * @return void
     */
    Slide.prototype._bindBreakpoints = function () {
        var that = this;
        var breakpoints = this.options.breakpoints;
        $(window).on('resize', function () {
            var width = $(window).width();
            for (var i = breakpoints.length - 1; i >= 0; i--) {
                var breakpoint = breakpoints[i];
                if (breakpoint.width > width) {
                    that.setGrouping(breakpoint.grouping);
                    that.setCurrent(that._current);
                    return;
                }
            }
        });
    };

    /**
     * Update the current "grouping" of list items within the slideshow.<commit_msg>Ensure order of breakpoints is correct before moving through loop. Set fallback for when outside the breakpoint list<commit_after>/**
 * HATCHD DIGITAL SLIDE
 *
 * The slide hatchdling allows for simple carousel action in your browser in
 * a way that works for RWD. We've taken a look at the requirements for the
 * slider to change depending on the width of the page as possible.
 *
 * This code has been developed in house at HATCHD DIGITAL.
 * @see http://hatchd.com.au/
 *
 * FOR DEVELOPERS:
 *
 * The code in this file should always be well formatted and never be
 * used in production systems. Your site should always use disc/*-.min.js
 * which contains a packed and minified version of the script
 * prepended with all dependencies.
 *
 * REQUIRED FRAMEWORKS
 *
 * @required jquery (v1.8.0+)
 * -- (http://jquery.com)
 *
 * VALIDATION
 *
 * All code must validate with JSHint (http://www.jshint.com/) before
 * commiting this repo. NO debug code should remain in your final
 * versions. Ensure to remove every reference to console.log.
 *
 * STYLE
 *
 * All code should be within 79 characters WIDE to meet standard Hatchd
 * protocol. Reformat code cleanly to fit within this tool.
 *
 * CONTRIBUTORS
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 */

/* global define */

(function (factory) {
    'use strict';

    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define(['jquery'], factory);
    }
    else {
        // Browser globals
        window.Slide = factory(window.jQuery);
    }

}(function ($) {
    'use strict';

    /**
     * Helper methods.
     */
    var getTime = (Date.now || function() {
        return new Date().getTime();
    });

    /**
     * Base object for storing requried information about each Slide module
     * on any given page.
     *
     * @param {selector} The element wrapping the Slide
     * @param {object} Default initialization options
     * @return Slide
     */
    var Slide = function Slide(element, options) {

        var item_count;

        // Set and extend default options with user provided
        this.options = $.extend({
            'loop': false,
            'onChange': null,
            'onInit': null,
            'grouping': 4,
            'breakpoints': null
        }, options);

        // Set event listeners
        this.onChange = this.options.onChange;
        this.onInit = this.options.onInit;

        // Set local private variables for managing the current state
        this._element = $(element);
        this._items = this._element.find('.slide-item');
        this._translate = 0;

        // Find the initial current image
        this._current = $(this._items.filter('.state-current'));
        if (!this._current.length) {
            this._current = this._items.first();
            this._current.addClass('state-current');
        }

        // Initialize grouping based on breakpoint or provided grouping
        if (this.options.breakpoints !== null) {
            // Ensure breakpoints are ordered correctly and bind the
            // to a listner event
            this._bindBreakpoints(this.options.breakpoints.sort(function (a, b) {
                return a.width > b.width;
            }));
            $(window).trigger('resize');
        }
        else {
            this.setGrouping(this.options.grouping);
        }

        // Bind all events for next/previous/specific
        this._bind();

        // Draw the slideshow
        this._draw();

        // Trigger that we are built and ready to roll
        this._element.trigger('init', this._current);

        return this;
    };

    /**
     * Draw the current slideshow. Generate the correct sizing and widths
     * for each element to respond correctly at the current breakpoint.
     * Also updates the controller state based on any changes.
     *
     * @return {Slide}
     */
    Slide.prototype._draw = function () {
        // Set correct state on controls
        this._updateControls();
        // Initialize sizes for each slide for responsive nature
        this._element.find('.slide-items').css(
            'width', (100 * (this._items.length / this._grouping)).toString() + '%');
        this._items.css('width', (100 / this._items.length).toString() + '%');
        return this;
    };

    /**
     * Setup breakpoint support for the slider. This will only be called
     * if breakpoints are provided to the slider. Polling function to
     * update the current draw state on browser width changes.
     *
     * @return void
     */
    Slide.prototype._bindBreakpoints = function () {
        var that = this;
        var breakpoints = this.options.breakpoints;
        $(window).on('resize', function () {
            var width = $(window).width();
            var breakpoint;
            for (var i = breakpoints.length - 1; i >= 0; i--) {
                breakpoint = breakpoints[i];
                if (breakpoint.width < width) {
                    that.setGrouping(breakpoint.grouping);
                    that.setCurrent(that._current);
                    return;
                }
            }
            breakpoint = breakpoints[0];
            that.setGrouping(breakpoint.grouping);
            that.setCurrent(that._current);
            return;
        });
    };

    /**
     * Update the current "grouping" of list items within the slideshow.
{'fraction_non_alphanumeric': 0.1088337182448037, 'fraction_numerical': 0.00298306389530408, 'mean_word_length': 2.0648776172220584, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 19, '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': '4572865', 'n_tokens_mistral': 2830, 'n_tokens_neox': 2721, 'n_words': 939}