HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers57/topsluchtfilters.nl/wwwroot/public/js/tops_slider_template.js
(function($) {

    $.slider = function(element, options) {

        var defaults = {
            nav : null,
            loop : null,
            speed : 1000
        };

        // Reference to this
        var t = this;

        // Current Index
        var cIndex = 0;

        // Number of images
        var num = 0;

        // Create settings object
        t.set = {};

        // jQuery reference to element
        var $ul = $(element).children('.images');

        // Arrays
        t.images = []; // Image

        // Constructor
        t.init = function ()
        {
            // Extend the defaults with options, save in settings
            t.set = $.extend({}, defaults, options);

            // Set number of images
            num = $ul.children().length;

            // Fill arrays
            fillArrays();

            // Show first item
            t.goto(cIndex,true);

            // Loop ?
            if(t.set.loop != null)
            {
                var intv = t.set.loop;
                t.loop = setTimeout(function(){
                    t.next();
                    t.loop = setInterval(function(){ t.next(); },intv + t.set.speed);
                },intv);
            }

            // Nav ?
            if(t.set.nav != null && num > 1)
            {
                var $nav = $(t.set.nav);
                $('#next').click(function()
                {

                    if( ! $nav.hasClass('disabled'))
                    {
                        // Stop the loop
                        clearInterval(t.loop);

                        t.next();

                        $nav.addClass('disabled');
                        setTimeout(function()
                        {
                            $nav.removeClass('disabled');
                        }, t.set.speed);
                    }
                });
                $('#prev').click(function()
                {
                    if( ! $nav.hasClass('disabled'))
                    {
                        // Stop the loop
                        clearInterval(t.loop);

                        t.previous();

                        $nav.addClass('disabled');
                        setTimeout(function()
                        {
                            $nav.removeClass('disabled');
                        }, t.set.speed);
                    }
                });
            }
            if(num == 1)
            {
                $(t.set.nav).remove();
            }
        };

        // Public method Next
        // Slide to the next image
        t.next = function()
        {
            // Get target
            var tIndex;
            if(cIndex != num-1)
            {
                tIndex = cIndex+1;
            }
            else
            {
                tIndex = 0;
            }

            t.goto(tIndex);
        };

        // Public method Previous
        // Slide to the previous image
        t.previous = function()
        {
            var tIndex;
            if(cIndex != 0)
            {
                tIndex = cIndex-1;
            }
            else
            {
                tIndex = num-1;
            }

            t.goto(tIndex);
        };

        // Public method Goto
        // Slide to the passed index
        t.goto = function(tIndex,first)
        {

            if(cIndex != tIndex || first)
            {
                // Append list item
                addListItem(tIndex,first);

                // Adjust images
                t.adjust();

                // Add classes
                if( ! first)
                {
                    $ul.children('.show').addClass('hide').removeClass('show');
                    $ul.children('.new').addClass('show').removeClass('new');

                    setTimeout(function(){ $ul.children('.hide').remove(); }, t.set.speed);
                }
                // Switch index
                cIndex = tIndex;
            }
        };

        // Public method Adjust
        // Adjust slider size to parent (ul)
        t.adjust = function()
        {
            // Get ul width and height
            var w = $ul.width();
            var h = $ul.height();

            // List item gets height of ul and width of ul
            var $li = $ul.children('li');
            $li.width(w);
            $li.height(h);

            var $img = $('img',$li);
            $($img).one('load', function() {

                // Images adjust in full-width or full-height,
                // depending on ratio and parent dimensions
                var ratioI = $img.width() / $img.height();
                var ratioP = $li.width() / $li.height();
                if(ratioP >= ratioI)
                {
                    // Make image as wide as parent
                    $img.width($li.width());
                    $img.height($li.width() / ratioI);
                }
                else
                {
                    // Make image as high as parent
                    $img.height($li.height());
                    $img.width($li.height() * ratioI);
                }

                var ml = $img.width() / -2;
                var mt = $img.height() / -2;
                $img.css({  display: 'block', marginTop : mt+'px',marginLeft : ml+'px'  });


            }).each(function() {
                if(this.complete) $(this).load();
            });
        };

        // Private method fillArrays
        // Convert Li content to array then clear li's
        var fillArrays = function()
        {
            for(var i=0;i<num;i++)
            {
                var $li = $ul.children('li').eq(i);
                t.images[i] = $li.html();
            }
            // Remove all li
            $ul.children('li').remove();
        };

        // Private method Append
        // Add image to ul
        var addListItem = function(i,first)
        {
            // Create a string of the item
            var $li = $('<li/>');

            // Show the first image without animation
            if(first){
                $li.addClass('show');
            }
            else
            {
                $li.addClass('new');
            }
            var image =  t.images[i] ;

            // Add text to list item
            $li.append(image);

            // Add item to list
            $ul.append($li);
        };

        // Run plugin
        t.init();
    };

    $.fn.slider = function(options)
    {
        return this.each(function()
        {
            // if plugin has not already been attached to the element
            if ($(this).data('slider') == undefined)
            {
                // create a new instance of the plugin
                var slider = new $.slider(this, options);
                $(this).data('slider', slider);
            }
        });
    }

})(jQuery);