Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturmkrtchyan/0a3edd59833cc011f0043f06c0b84914 to your computer and use it in GitHub Desktop.
Save arturmkrtchyan/0a3edd59833cc011f0043f06c0b84914 to your computer and use it in GitHub Desktop.

Part 1 (Start page with hero)

<script>
    document.addEventListener("DOMContentLoaded", function() {
        $('#sw-email-capture-submit-btn').unbind('click');
        $('#sw-email-capture-submit-btn').click(function(event){
            event.preventDefault();
            const domain = window.location.host;
            const searchValue = $('#sw-email-capture-email-input').val();
            const searchStr = '?search=' + searchValue;
            window.location.href= 'https://' + domain + '/platform' + searchStr;
        });
    });
</script>

Part 2 (Listing Page)

<script>
    document.addEventListener("DOMContentLoaded", function() {
        const searchValue = getUrlParam('search');
        if(searchValue) {
            const existCondition = setInterval(function() {
                if ($('.sw-js-list-search-input').length) {
                    $('.sw-js-list-search-input').val(searchValue);
                    $('.sw-js-list-search-input').keyup();
                    clearInterval(existCondition);
                }
            }, 100);
        }

        function getUrlParam(name) {
            const url = new URL(window.location.href);
            return url.searchParams.get(name);
        }
    });
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment