{"version":3,"sources":["../../node_modules/js-tools/viewport.js","plugins/prevent-scroll.js","search.js"],"names":["Viewport","breakpoints","this","mediaQuery","breakpoint","type","size","matchMedia","window","matches","customMediaQuery","customMatchMedia","customMatches","resize","callback","windowResizing","addEventListener","clearTimeout","setTimeout","preventScroll","active","on","htmlEl","document","querySelector","bodyScrollTop","body","scrollTop","htmlScrollTop","currentPosition","style","position","currentOverflow","overflowY","currentWidth","width","top","off","classList","add","parseInt","remove","Search","_this","viewport","AndrewMartin","html","search","searchForm","searchInput","searchPageInput","searchToggle","querySelectorAll","header","headertop","headerNavToggle","init","watchToggle","watchSearch","watchPageResize","forEach","toggle","i","toggleSearch","bind","deactivateSearch","e","stopPropagation","id","isSearchActive","isNavActive","deactivateNavItem","deactivateNav","activateSearch","contains","focus","setAttribute","setHeight","removeAttribute","resetHeight","height","innerHeight","getBoundingClientRect"],"mappings":"AAAA,SAAAA,SAAAC,GAGAC,KAAAD,YAAAA,EAGAC,KAAAC,WAAA,SAAAC,GACA,MAAA,IAAAF,KAAAD,YAAAG,GAAAC,KAAA,KAAAH,KAAAD,YAAAG,GAAAE,KAAA,KACA,EAGAJ,KAAAK,WAAA,SAAAH,GACA,OAAAI,OAAAD,WAAAL,KAAAC,WAAAC,GACA,EAGAF,KAAAO,QAAA,SAAAL,GACA,OAAAI,OAAAD,WAAAL,KAAAC,WAAAC,IAAAK,OACA,EAGAP,KAAAQ,iBAAA,SAAAN,GACA,OAAAA,CACA,EAGAF,KAAAS,iBAAA,SAAAP,GACA,OAAAI,OAAAD,WAAAL,KAAAQ,iBAAAN,GACA,EAGAF,KAAAU,cAAA,SAAAR,GACA,OAAAI,OAAAD,WAAAL,KAAAQ,iBAAAN,IAAAK,OACA,EAGAP,KAAAW,OAAA,SAAAC,GACA,IAAAC,EAEAP,OAAAQ,iBAAA,SAAA,WACAC,aAAAF,GACAA,EAAAG,WAAA,WACA,mBAAAJ,GACAA,GAEA,EAAA,IACA,EACA,CACA,CChDA,IAAAK,cA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nC,EAAAI,OAAAT,UAAAG,OAAA,sBACAE,EAAAQ,aAAAS,QAAA,SAAAC,GACAA,EAAAe,aAAA,iBAAA,EACA,GACAjC,EAAAoC,cACA5D,cAAAkB,KACA,EAAA,IACA,EAGAnC,KAAA2E,UAAA,WACAlC,EAAAI,OAAAjB,MAAAkD,OAAAxE,OAAAyE,YAAAtC,EAAAI,OAAAmC,wBAAA9C,IAAA,IACA,EAGAlC,KAAA6E,YAAA,WACApC,EAAAI,OAAAjB,MAAAkD,OAAA,IACA,EAGA9E,KAAAyD,gBAAA,WAEAf,EAAA/B,OAAA,WACA8B,EAAA0B,kBACA1B,EAAAkC,WAEA,EACA,CACA,CAEAhC,aAAAE,OAAA,IAAAL,OAEAG,aAAAE,OAAAS","file":"../../javascript/search.js","sourcesContent":["function Viewport(breakpoints) {\n\n    // Get the breakpoint config\n    this.breakpoints = breakpoints;\n\n    // Constuct the breakpoint for the media query\n    this.mediaQuery = function(breakpoint) {\n        return '(' + this.breakpoints[breakpoint].type + ': ' + this.breakpoints[breakpoint].size + 'px)';\n    }\n\n    // Check if the media query matches\n    this.matchMedia = function(breakpoint) {\n        return window.matchMedia(this.mediaQuery(breakpoint));\n    }\n\n    // Check if the media query matches\n    this.matches = function(breakpoint) {\n        return window.matchMedia(this.mediaQuery(breakpoint)).matches;\n    }\n\n    // Construct the custom media query\n    this.customMediaQuery = function(breakpoint) {\n        return breakpoint;\n    }\n\n    // Check if the custom media query matches\n    this.customMatchMedia = function(breakpoint) {\n        return window.matchMedia(this.customMediaQuery(breakpoint));\n    }\n\n    // Check if the custom media query matches\n    this.customMatches = function(breakpoint) {\n        return window.matchMedia(this.customMediaQuery(breakpoint)).matches;\n    }\n\n    // Watch for viewport resize\n    this.resize = function(callback) {\n        var windowResizing;\n\n        window.addEventListener('resize', function() {\n            clearTimeout(windowResizing);\n            windowResizing = setTimeout(function() {\n                if (typeof callback == 'function') {\n                    callback();\n                }\n            }, 100);\n        });\n    }\n}\n","var preventScroll = {\n    active: false,\n    on: function() {\n        var htmlEl = document.querySelector('html');\n        var body = document.body;\n\n        // Determine the `scrollTop` to use. Some browsers require checking the\n        // `body`, others use `html`.\n        var bodyScrollTop = body.scrollTop;\n        var htmlScrollTop = htmlEl.scrollTop;\n        var scrollTop = bodyScrollTop ? bodyScrollTop : htmlScrollTop;\n\n        // Store the current value of the htmlEl's styles – we're about to override\n        // them.\n        this.currentPosition = htmlEl.style.position;\n        this.currentOverflow = htmlEl.style.overflowY;\n        this.currentWidth = htmlEl.style.width;\n\n        // Fixing the position of the `htmlEl` prevents the page from scrolling\n        // at all.\n        htmlEl.style.position = 'fixed';\n        // Setting `overflowY` to `scroll` ensures that any scrollbars that are\n        // around stick around. Otherwise, there would be a \"jump\" when the page\n        // becomes unscrollable as the bar would vanish.\n        htmlEl.style.overflowY = 'scroll';\n        // This makes sure that the page doesn't collapse (usually your CSS will\n        // prevent this, but it's best to be safe)\n        htmlEl.style.width = '100%';\n        // Scoot down the `htmlEl` to be in the same place that the user had\n        // scrolled to.\n        htmlEl.style.top = (0 - scrollTop) + 'px';\n\n        // Set active state\n        this.active = true;\n    },\n\n    off: function() {\n        var htmlEl = document.querySelector('html');\n        var body = document.body;\n\n        // Reset `htmlEl` to the original styles.\n        htmlEl.style.position = this.currentPosition;\n        htmlEl.style.overflowY = this.currentOverflow;\n        htmlEl.style.width = this.currentWidth;\n\n        // Retrieve our original scrollTop from the htmlEl's top\n\n        htmlEl.classList.add('no-smooth-scroll');\n\n        var scrollTop = -parseInt(htmlEl.style.top);\n        // Return us to the original scroll position. Once again, we set this on\n        // both the `body` and the `htmlEl` to be safe.\n        htmlEl.scrollTop = scrollTop;\n        body.scrollTop = scrollTop;\n\n        htmlEl.classList.remove('no-smooth-scroll');\n\n        // Unset active state\n        this.active = false;\n    }\n}\n","function Viewport(breakpoints) {\n\n    // Get the breakpoint config\n    this.breakpoints = breakpoints;\n\n    // Constuct the breakpoint for the media query\n    this.mediaQuery = function(breakpoint) {\n        return '(' + this.breakpoints[breakpoint].type + ': ' + this.breakpoints[breakpoint].size + 'px)';\n    }\n\n    // Check if the media query matches\n    this.matchMedia = function(breakpoint) {\n        return window.matchMedia(this.mediaQuery(breakpoint));\n    }\n\n    // Check if the media query matches\n    this.matches = function(breakpoint) {\n        return window.matchMedia(this.mediaQuery(breakpoint)).matches;\n    }\n\n    // Construct the custom media query\n    this.customMediaQuery = function(breakpoint) {\n        return breakpoint;\n    }\n\n    // Check if the custom media query matches\n    this.customMatchMedia = function(breakpoint) {\n        return window.matchMedia(this.customMediaQuery(breakpoint));\n    }\n\n    // Check if the custom media query matches\n    this.customMatches = function(breakpoint) {\n        return window.matchMedia(this.customMediaQuery(breakpoint)).matches;\n    }\n\n    // Watch for viewport resize\n    this.resize = function(callback) {\n        var windowResizing;\n\n        window.addEventListener('resize', function() {\n            clearTimeout(windowResizing);\n            windowResizing = setTimeout(function() {\n                if (typeof callback == 'function') {\n                    callback();\n                }\n            }, 100);\n        });\n    }\n}\n\nvar preventScroll = {\n    active: false,\n    on: function() {\n        var htmlEl = document.querySelector('html');\n        var body = document.body;\n\n        // Determine the `scrollTop` to use. Some browsers require checking the\n        // `body`, others use `html`.\n        var bodyScrollTop = body.scrollTop;\n        var htmlScrollTop = htmlEl.scrollTop;\n        var scrollTop = bodyScrollTop ? bodyScrollTop : htmlScrollTop;\n\n        // Store the current value of the htmlEl's styles – we're about to override\n        // them.\n        this.currentPosition = htmlEl.style.position;\n        this.currentOverflow = htmlEl.style.overflowY;\n        this.currentWidth = htmlEl.style.width;\n\n        // Fixing the position of the `htmlEl` prevents the page from scrolling\n        // at all.\n        htmlEl.style.position = 'fixed';\n        // Setting `overflowY` to `scroll` ensures that any scrollbars that are\n        // around stick around. Otherwise, there would be a \"jump\" when the page\n        // becomes unscrollable as the bar would vanish.\n        htmlEl.style.overflowY = 'scroll';\n        // This makes sure that the page doesn't collapse (usually your CSS will\n        // prevent this, but it's best to be safe)\n        htmlEl.style.width = '100%';\n        // Scoot down the `htmlEl` to be in the same place that the user had\n        // scrolled to.\n        htmlEl.style.top = (0 - scrollTop) + 'px';\n\n        // Set active state\n        this.active = true;\n    },\n\n    off: function() {\n        var htmlEl = document.querySelector('html');\n        var body = document.body;\n\n        // Reset `htmlEl` to the original styles.\n        htmlEl.style.position = this.currentPosition;\n        htmlEl.style.overflowY = this.currentOverflow;\n        htmlEl.style.width = this.currentWidth;\n\n        // Retrieve our original scrollTop from the htmlEl's top\n\n        htmlEl.classList.add('no-smooth-scroll');\n\n        var scrollTop = -parseInt(htmlEl.style.top);\n        // Return us to the original scroll position. Once again, we set this on\n        // both the `body` and the `htmlEl` to be safe.\n        htmlEl.scrollTop = scrollTop;\n        body.scrollTop = scrollTop;\n\n        htmlEl.classList.remove('no-smooth-scroll');\n\n        // Unset active state\n        this.active = false;\n    }\n}\n\n\nfunction Search() {\n    let viewport = new Viewport(AndrewMartin.breakpoints);\n\n    this.html = document.querySelector('html');\n    this.search = document.querySelector('.js-search');\n    this.searchForm = document.querySelector('.js-search__form');\n    this.searchInput = document.querySelector('.js-search__input');\n    this.searchPageInput = document.querySelector('.js-search__page-input');\n    this.searchToggle = document.querySelectorAll('.js-search--toggle');\n    this.header = document.querySelector('.header');\n    this.headertop = document.querySelector('.header__top');\n    this.headerNavToggle = document.querySelector('.js-header-nav__toggle');\n\n    this.init = () => {\n        if (!this.search) {\n            return;\n        }\n        this.watchToggle();\n        this.watchSearch();\n        this.watchPageResize();\n    }\n\n    // Watch the toggle for click events\n    this.watchToggle = () => {\n        this.searchToggle.forEach((toggle, i) => {\n            toggle.addEventListener('click', this.toggleSearch.bind(this, i));\n        });\n    }\n\n    // Watch the component toggle for click events\n    this.watchSearch = () => {\n        this.search.addEventListener('click', this.deactivateSearch.bind(this));\n        this.searchForm.addEventListener('click', (e) => {\n            e.stopPropagation();\n        });\n    }\n\n    // Toggle the search component\n    this.toggleSearch = (id) => {\n        if (this.isSearchActive()) {\n            this.deactivateSearch();\n        } else {\n            if (AndrewMartin.header.isNavActive()) {\n                AndrewMartin.header.deactivateNavItem();\n                AndrewMartin.header.deactivateNav();\n            }\n            this.activateSearch(id);\n        }\n    }\n\n    // Is the search active?\n    this.isSearchActive = () => {\n        return this.search.classList.contains('search--active');\n    }\n\n    // Activate the search\n    this.activateSearch = (id) => {\n        if (this.searchPageInput) {\n            this.searchPageInput.focus();\n        } else {\n            setTimeout(() => {\n                this.search.classList.add('search--active');\n                this.searchToggle.forEach((toggle) => {\n                    toggle.classList.add('header-actions__item--search-active');\n                });\n                this.searchInput.focus();\n            }, 1);\n\n            this.html.setAttribute('search-active', true);\n            this.search.setAttribute('search-toggle', id);\n            this.search.classList.add('search--activating');\n            this.searchToggle.forEach((toggle) => {\n                toggle.setAttribute('aria-expanded', true);\n            });\n            this.setHeight();\n            if (!preventScroll.active) {\n                preventScroll.on();\n            }\n        }\n    }\n\n    // Deactivate the search\n    this.deactivateSearch = () => {\n        this.search.classList.remove('search--active');\n        this.searchToggle.forEach((toggle) => {\n            toggle.classList.remove('header-actions__item--search-active');\n        });\n\n        setTimeout(() => {\n            this.html.removeAttribute('search-active');\n            this.search.removeAttribute('search-toggle');\n            this.search.classList.remove('search--activating');\n            this.searchToggle.forEach((toggle) => {\n                toggle.setAttribute('aria-expanded', true);\n            });\n            this.resetHeight();\n            preventScroll.off();\n        }, 300);\n    }\n\n    // Set the height of the search component\n    this.setHeight = () => {\n        this.search.style.height = window.innerHeight - this.search.getBoundingClientRect().top + 'px';\n    }\n\n    // Reset the height of the search component\n    this.resetHeight = () => {\n        this.search.style.height = null;\n    }\n\n    // Watch for the page to resize\n    this.watchPageResize = () => {\n\n        viewport.resize(() => {\n            if (this.isSearchActive()) {\n                this.setHeight();\n            }\n        })\n    }\n}\n\nAndrewMartin.search = new Search();\n\nAndrewMartin.search.init();\n"],"sourceRoot":"../../../../resources/javascript"}