<commit_before>/*
 * simple-gallery.js - v1.0.0
 * Author: <NAME> (https://github.com/akalicki)
 *
 * simple-gallery.js is a lightweight jQuery extension for quickly creating
 * highly customizable photo galleries using standard jQuery notation.
 *
 * All work contained in this file is licensed under a Creative Commons Attribution 3.0
 * Unported License.  Please contact the copyright holder with further questions.
*/
;(function($) {
    $.fn.gallery = function(options) {
         
        // merge defaults and user-supplied options
        var options = $.extend($.fn.gallery.defaults, options);
        
        // global plugin variables
        var obj = this;
        var nextImg = options.startImg;
        
        // set the target background CSS, begin cycle
        $.fn.gallery.init = function() {
            $(options.target).css({
                "background-repeat": "no-repeat",
                "background-position": "center",
                "opacity": 0
            });
            $.fn.gallery.fetchImg(nextImg);
        }
        
        // transition out current image, call fetch function to transition in next one
        $.fn.gallery.changeToImg = function(index) {
            $(options.target).animate({"opacity": 0}, options.changeTime, options.easing,
                                      function(){ $.fn.gallery.fetchImg(index); });
        }
        
        // transition in the given image
        $.fn.gallery.fetchImg = function(index) {
            var url = obj.get(index).src;
            $(options.target)
                .css("background-image", "url("+url+")")
                .animate({"opacity": 1}, options.changeTime, options.easing,
                    function(){ cycle = window.setTimeout(loadNext, options.waitTime); });
            nextImg = index + 1;
        }
        
        // switch to given image on click, reset cycle interval
        function onClick() {
            window.clearTimeout(cycle);
            nextImg = obj.index($(this));
            $.fn.gallery.changeToImg(nextImg);
        }
        
        // load the next image in cycle
        function loadNext() {
            if (nextImg < obj.length) {       // more images in cycle
                $.fn.gallery.changeToImg(nextImg);
            }
            else if (options.restartOnEnd) {  // end of cycle, restart
                nextImg = 0;
                $.fn.gallery.changeToImg(nextImg);
            }
        }
        
        // initialize gallery and set click events
        $.fn.gallery.init();
        return this.each(function() {
            $(this).click(onClick);
        });
        
    };
    
    // create public defaults which can be overridden if requested
    $.fn.gallery.defaults = {
        target: "",
        startImg: 0,
        waitTime: 5000,
        changeTime: 700,
        easing: "swing",
        restartOnEnd: true
    };
})(jQuery);<commit_msg>Separated public/private functions completely, added selected image class functionality.<commit_after>/*
 * simple-gallery.js - v1.0.0
 * Author: <NAME> (https://github.com/akalicki)
 *
 * simple-gallery.js is a lightweight jQuery extension for quickly creating
 * highly customizable photo galleries using standard jQuery notation.
 *
 * All work contained in this file is licensed under a Creative Commons Attribution 3.0
 * Unported License.  Please contact the copyright holder with further questions.
*/
;(function($) {
    $.fn.gallery = function(options) {
         
        // merge defaults and user-supplied options
        var options = $.extend($.fn.gallery.defaults, options);
        
        // global plugin variables
        var obj = this;
        var nextImg = options.startImg;
        
        // set the target background CSS, perform any needed initialization
        $.fn.gallery.init = function() {
            $(options.target).css({
                "background-repeat": "no-repeat",
                "background-position": "center",
                "opacity": 0
            });
        }
        
        // perform transition to remove current image from target
        $.fn.gallery.startTransition = function() {
            $(options.target).animate(
                {"opacity": 0}, 
                options.changeTime, 
                options.easing
            );
        }
        
        // perform transition to add new image to target
        $.fn.gallery.endTransition = function() {
            $(options.target).animate(
                {"opacity": 1}, 
                options.changeTime, 
                options.easing
            );
        }
        
        // select a new image to be placed in target
        function selectImg(index) {
            var selected = obj.get(index);
            var url = selected.src;
            $(options.target).css("background-image", "url(" + url + ")");
            $("." + options.selectClass).removeClass(options.selectClass);
            selected.className += options.selectClass;
            nextImg = index + 1;
        }
        
        // transition out, select new image, transition in
        function changeToImg(index) {
            $.fn.gallery.startTransition();
            $(options.target).promise().done(function() {
                selectImg(index);
                $.fn.gallery.endTransition();
                $(options.target).promise().done(function() {
                    cycle = window.setTimeout(loadNext, options.waitTime);
                });
            });
        }
        
        // load the next image in cycle
        function loadNext() {
            if (nextImg < obj.length) {       // more images in cycle
                changeToImg(nextImg);
            }
            else if (options.restartOnEnd) {  // end of cycle, restart
                nextImg = 0;
                changeToImg(nextImg);
            }
        }
        
        // switch to given image on click, reset cycle interval
        function onClick() {
            window.clearTimeout(cycle);
            nextImg = obj.index($(this));
            changeToImg(nextImg);
        }
        
        // initialize gallery and set click events
        $.fn.gallery.init();
        changeToImg(nextImg);
        return this.each(function() {
            $(this).click(onClick);
        });
        
    };
    
    // create public defaults which can be overridden if requested
    $.fn.gallery.defaults = {
        target: "",
        startImg: 0,
        waitTime: 5000,
        changeTime: 700,
        easing: "swing",
        restartOnEnd: true,
        selectClass: "selected"
    };
})(jQuery);
{'fraction_non_alphanumeric': 0.11245648554563342, 'fraction_numerical': 0.005448766459815347, 'mean_word_length': 1.6149584487534625, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1308783', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1622, 'n_words': 444}