<?php
/**
 * Plumrocket Inc.
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the End-user License Agreement
 * that is available through the world-wide-web at this URL:
 * http://wiki.plumrocket.net/wiki/EULA
 * If you are unable to obtain it through the world-wide-web, please
 * send an email to support@plumrocket.com so we can send you a copy immediately.
 *
 * @package     Plumrocket Product Filter v3.x.x
 * @copyright   Copyright (c) 2019 Plumrocket Inc. (http://www.plumrocket.com)
 * @license     http://wiki.plumrocket.net/wiki/EULA  End-user License Agreement
 */
?>
<?php /** @var \Plumrocket\ProductFilter\Block\Init $block */ ?>
<div id="product-filter-init"></div>

<script type="text/x-magento-init">
    {
        "#product-filter-init": {
            "Plumrocket_ProductFilter/js/init": {
                "filterItemSelector": "#narrow-by-list .item a, #narrow-by-list .swatch-option-link-layered",
                "actionsSelector": ".pages-items .item a",
                "clearButton": "#product-filter-clear",
                "removeFilterLink": ".filter-current .item a.action",
                "productlistSelector": ".column.main",
                "auto": "<?php echo $block->isAutoMode(); ?>",
                "filterSelector": "#layered-filter-block",
                "filterParamSeparator": "<?php echo $block->getFilterParamSeparator(); ?>",
                "isSeoFriendly": "<?php echo $block->useSeoFriendlyUrl(); ?>",
                "_currentUrl": "<?php echo $block->getCurrentUrl(); ?>",
                "realParams": <?php echo $block->getRealParams(); ?>,
                "selected": <?php echo $block->getSelectedParams(); ?>,
                "categoryUrlSufix": "<?php echo $block->getCategoryUrlSufix(); ?>"
            }
        }
    }
</script>

<?php /*Fix for browser history after ajax-queries */?>
<script type="text/javascript">
    require([
        "Plumrocket_ProductFilter/js/model/prproductfilter",
        "domReady!"
    ], function(processor){
        var oldOnpopstate = window.onpopstate;
        window.onpopstate = function(event) {
            if (typeof oldOnpopstate === 'function') oldOnpopstate();
            processor.pushState = false;
            if (event.state !== null) {
                processor.run(window.location.href);
            }
        };
    });
</script>