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/SBogers10/spire.komma-mediadesign.nl/wwwroot/js/filter.js
/*
    Filter.js
*/

var activeTarget = null;

$(document).ready(function(){

    initHiddenTargets();

    var filter = '#filter';

    $(document).keypress(function(e) {
        var code = (e.keyCode ? e.keyCode : e.which);
        if(code == 13) {
            e.preventDefault();
        }
    });

    $(filter+' input').change(function(){
        loadProducts()
    });

    $(filter+ ' input[type="text"]').bind('input propertychange', function() {
        loadProducts()
    });

    $(filter+' select').change(function(){
        loadProducts()
    });

    var searchfield = '.search';
    $(searchfield).focus(
        function() {
            if($(this).val()=='search')
            {
                $(this).val('');
            }
        }
    );
    $(searchfield).blur(
        function()
        {
            if($(this).val()=="")
            {
                $(this).val('search');
            }
        }
    );

    /* Slider */
    // activate slider
    var sliderObj = ".rangeSlider";

    $(sliderObj).each(function(){
        var name = $(this).attr('data-name');

        var rng = Boolean($(this).attr('data-range'));

        var mn = parseInt($(this).attr('data-min'));
        var mx = parseInt($(this).attr('data-max'));
        var step = parseInt($(this).attr('data-step'));

        // get name for Display, Min, Max
        var display = '#display_'+$(this).attr('data-name');
        var inputMin = '#min_'+$(this).attr('data-name');
        var inputMax = '#max_'+$(this).attr('data-name');

        var values = [ mn, mx ];
        var value = false;
        if( ! rng)
        {
            values = false;
            value = mn;
        }

        $(this).slider({
            range: rng,
            min: mn,
            max: mx,
            value : value,
            values: values,
            step: step,
            slide: function( event, ui ) {
                if(rng)
                {
                    // Display value
                    $( display ).html( ui.values[ 0 ] + ' - ' + ui.values[ 1 ] );
                    // Min&Max (hidden input)
                    $( inputMin ).val( ui.values[ 0 ] );
                    $( inputMax ).val( ui.values[ 1 ] );
                }
                else
                {
                    // Display value
                    $( display ).html( ui.value);
                    // Min&Max (hidden input)
                    $( inputMin ).val( ui.value );
                    //$( inputMax ).val( ui.values[ 1 ] );
                }
                loadProducts();
            }
        });
        if( ! rng)
        {
            $( display ).html( mn );
        }
        else
        {
            $( display ).html( mn + ' - ' + mx );
        }
    });

    loadProducts();
});

function loadProducts()
{
    var filter = '#filter';
    var controller = $('#f_controller').val();
    var values = {}; // object

    $(filter+' input[type="text"]').each(function(){
        var disabled = $(this).attr('disabled');
        if (typeof disabled == 'undefined' || disabled == false)
        {
            var name = $(this).attr('name');
            values[name] = ($(this).val());
        }
    });

    $(filter+' input[type="checkbox"]:checked').each(function(){
        var disabled = $(this).attr('disabled');
        if ((typeof disabled == 'undefined' || disabled == false))
        {
            var name = $(this).attr('name');
            values[name] = ($(this).val());
        }
    });

    $(filter+' input[type="radio"]:checked').each(function(){
        var disabled = $(this).attr('disabled');
        if ((typeof disabled == 'undefined' || disabled == false))
        {
            var name = $(this).attr('name');
            values[name] = ($(this).val());
        }
    });

    $(filter+' select').each(function(){
        var disabled = $(this).attr('disabled');
        if (typeof disabled == 'undefined' || disabled == false)
        {
            var name = $(this).attr('name');
            values[name] = ($(this).val());
        }
    });

    $(filter+' input.sliderOutput').each(function(){
        var disabled = $(this).attr('disabled');
        if (typeof disabled == 'undefined' || disabled == false)
        {
            var name = $(this).attr('name');
            values[name] = ($(this).val());
        }
    });


    var loadingFilter = setTimeout(function(){
        $('#filter_loading').stop().animate({ opacity: 1, height: 31+'px' },200);
    },50);

    $.post('/mvc/controllers/c_productLoader_'+controller+'.php', values)
        .done(function(data) {

            clearTimeout(loadingFilter);
            setTimeout(function(){
                $('#filter_loading').stop().animate({ opacity: 0, height: 0 },200);
            },800);


            $('#blockItemList').html(data);
        });
}

function initHiddenTargets()
{
    $('input[type="checkbox"]').change(function()
    {
        var activatorId = $(this).attr('data-activator');
        var checked = $(this).attr('checked');

        if(typeof activatorId != 'undefined' && activatorId != false)
        {
            // check if multiple targets
            var objTargets = null;

            // close active target in group
            if($(this).is(':checked'))
            {
                objTargets = activatorId.split(',');
                for(var i=0;i < objTargets.length;i++)
                {
                    var openObj ='#target_' + objTargets[i];
                    var h = $(openObj).children('.hiddenHolder').height();
                    $(openObj).stop().animate({ height: h+'px'},300);
                    $(openObj+' select').removeAttr('disabled');
                    $(openObj+' input').removeAttr('disabled');
                    console.log(openObj + ' ' + h);
                    // extension:
                    if(objTargets[i] == '4a')
                    {
                        // also open 4b
                        var openObj4b = '#target_' + '4b';
                        $(openObj4b).stop().animate({ height: 80+'px'},300);
                        $(openObj4b+' select').removeAttr('disabled');
                        $(openObj4b+' input').removeAttr('disabled');
                    }
                }
            }
            else
            {
                objTargets = activatorId.split(',');
                // check if multiple targets
                for(var i=0;i < objTargets.length;i++)
                {
                    var closeObj = '#target_' + objTargets[i];
                    $(closeObj).stop().animate({ height: 0 },300);
                    $(closeObj+' select').attr('disabled','');
                    $(closeObj+' input').attr('disabled','');

                    // extension:
                    if(objTargets[i] == '4a')
                    {
                        // also close 4b
                        var closeObj4b = '#target_4b';
                        $(closeObj4b).stop().animate({ height: 0 },300);
                        $(closeObj4b+' select').attr('disabled','');
                        $(closeObj4b+' input').attr('disabled','');
                    }
                }
            }
        }
    });

    $('input[type="radio"]').change(function()
    {
        var activatorId = $(this).attr('data-activator');
        var checked = $(this).attr('checked');

        if(typeof activatorId !== 'undefined' || activatorId !== false)
        {
            // close active target in group
            if(activeTarget != null)
            {
                var closeObj = '#target_' + activeTarget;
                $(closeObj).stop().animate({ height: 0 },300);
                $(closeObj+' select').attr('disabled','');
                $(closeObj+' input').attr('disabled','');

                // extension:
                if(activeTarget == '4a')
                {
                    // also close 4b
                    var closeObj4b = '#target_4b';
                    $(closeObj4b).stop().animate({ height: 0 },300);
                    $(closeObj4b+' select').attr('disabled','');
                    $(closeObj4b+' input').attr('disabled','');
                }
            }

            var openObj ='#target_' + activatorId;
            var h = $(openObj).children('.hiddenHolder').height();
            $(openObj).stop().animate({ height: h+'px'},300);
            $(openObj+' select').removeAttr('disabled');
            $(openObj+' input').removeAttr('disabled');

            // extension:
            if(activatorId == '4a')
            {
                // also open 4b
                var openObj4b = '#target_' + '4b';
                var h = $(openObj4b).children('.hiddenHolder').height();
                $(openObj4b).stop().animate({ height: h+'px'},300);
                $(openObj4b+' select').removeAttr('disabled');
                $(openObj4b+' input').removeAttr('disabled');
            }
            activeTarget = activatorId;
        }
    });
}