/* ------------------------------------------------------------------------------ * Author: DMCWebZone * Author URL: https://web-zone.org * Code snippets Twenty Twenty theme * Source: https://wordpress.org/themes/twenty1twenty/ * @package Airin Blog * Description: Top search * ------------------------------------------------------------------------------ */ "use strict";var airinblog=airinblog||{};airinblog.scrolled=0;if(!Element.prototype.closest){Element.prototype.closest=function(s){var el=this;do{if(el.matches(s)){return el}el=el.parentElement||el.parentNode}while(el!==null&&el.nodeType===1);return null}}if(window.NodeList&&!NodeList.prototype.forEach){NodeList.prototype.forEach=function(callback,thisArg){var i;var len=this.length;thisArg=thisArg||window;for(i=0;i=0&&matches.item(i)!==this){}return i>-1}}airinblog.touchEnabled={init:function(){var matchMedia=function(){var prefixes=['-webkit-','-moz-','-o-','-ms-'];var query=['(',prefixes.join('touch-enabled),('),'heartz',')'].join('');return window.matchMedia&&window.matchMedia(query).matches};if(('ontouchstart'in window)||(window.DocumentTouch&&document instanceof window.DocumentTouch)||matchMedia()){document.body.classList.add('touch-enabled')}}};airinblog.coverModalsSearch={init:function(){if(document.querySelector('.airinblog-css-cover-search')){this.onToggle();this.outsideUntoggle();this.closeOnEscape();this.hideAndShowModals()}},onToggle:function(){document.querySelectorAll('.airinblog-css-cover-search').forEach(function(element){element.addEventListener('toggled-search',function(event){var modal=event.target,body=document.body;if(modal.classList.contains('active-search')){body.classList.add('showing-modal-search')}else{body.classList.remove('showing-modal-search');body.classList.add('hiding-modal-search');setTimeout(function(){body.classList.remove('hiding-modal-search')},500)}})})},outsideUntoggle:function(){document.addEventListener('click',function(event){var target=event.target;var modal=document.querySelector('.airinblog-css-cover-search.active-search');if(event.target.tagName.toLowerCase()==='a'&&event.target.hash.includes('#')&&modal!==null){this.untoggleModal(modal);setTimeout(function(){var anchor=document.getElementById(event.target.hash.slice(1));anchor.scrollIntoView()},550)}if(target===modal){this.untoggleModal(target)}}.bind(this))},closeOnEscape:function(){document.addEventListener('keydown',function(event){if(event.keyCode===27){event.preventDefault();document.querySelectorAll('.airinblog-css-cover-search.active-search').forEach(function(element){this.untoggleModal(element)}.bind(this))}}.bind(this))},hideAndShowModals:function(){var _doc=document,_win=window,modals=_doc.querySelectorAll('.airinblog-css-cover-search'),htmlStyle=_doc.documentElement.style;function htmlStyles(){var overflow=_win.innerHeight>_doc.documentElement.getBoundingClientRect().height;return{'overflow-y':overflow?'hidden':'scroll',position:'fixed',width:'100%',top:0,left:0}}modals.forEach(function(modal){modal.addEventListener('toggle-target-before-inactive-search',function(event){var styles=htmlStyles();if(event.target!==modal){return}Object.keys(styles).forEach(function(styleKey){htmlStyle.setProperty(styleKey,styles[styleKey])});_win.airinblog.scrolled=parseInt(styles.top,10);modal.classList.add('show-search-modal')});modal.addEventListener('toggle-target-after-inactive-search',function(event){if(event.target!==modal){return}setTimeout(function(){var clickedEl=airinblog.togglessearch.clickedEl;modal.classList.remove('show-search-modal');Object.keys(htmlStyles()).forEach(function(styleKey){htmlStyle.removeProperty(styleKey)});if(clickedEl!==false){clickedEl.focus();clickedEl=false}_win.scrollTo(0,Math.abs(_win.airinblog.scrolled));_win.airinblog.scrolled=0},500)})})},untoggleModal:function(modal){var modalTargetClass,modalToggle=false;if(modal.dataset.modalTargetString){modalTargetClass=modal.dataset.modalTargetString;modalToggle=document.querySelector('*[data-toggle-target="'+modalTargetClass+'"]')}if(modalToggle){modalToggle.click()}else{modal.classList.remove('active-search')}}};airinblog.intrinsicRatioVideos={init:function(){this.makeFit();window.addEventListener('resize',function(){this.makeFit()}.bind(this))},makeFit:function(){document.querySelectorAll('iframe, object, video').forEach(function(video){var ratio,iTargetWidth,container=video.parentNode;if(video.classList.contains('intrinsic-ignore')||video.parentNode.classList.contains('intrinsic-ignore')){return true}if(!video.dataset.origwidth){video.setAttribute('data-origwidth',video.width);video.setAttribute('data-origheight',video.height)}iTargetWidth=container.offsetWidth;ratio=iTargetWidth/video.dataset.origwidth;video.style.width=iTargetWidth+'px';video.style.height=(video.dataset.origheight*ratio)+'px'})}};airinblog.modalPlus={init:function(){this.keepFocusInModal()},keepFocusInModal:function(){var _doc=document;_doc.addEventListener('keydown',function(event){var toggleTarget,modal,selectors,elements,activeEl,lastEl,firstEl,tabKey,shiftKey,clickedEl=airinblog.togglessearch.clickedEl;if(clickedEl&&_doc.body.classList.contains('showing-modal-search')){toggleTarget=clickedEl.dataset.toggleTarget;selectors='input, a, button';modal=_doc.querySelector(toggleTarget);elements=modal.querySelectorAll(selectors);elements=Array.prototype.slice.call(elements);lastEl=elements[elements.length-1];firstEl=elements[0];activeEl=_doc.activeElement;tabKey=event.keyCode===9;shiftKey=event.shiftKey;if(!shiftKey&&tabKey&&lastEl===activeEl){event.preventDefault();firstEl.focus()}if(shiftKey&&tabKey&&firstEl===activeEl){event.preventDefault();lastEl.focus()}}})}};airinblog.togglessearch={clickedEl:false,init:function(){this.toggle();this.resizeCheck();this.untoggleOnEscapeKeyPress()},performToggle:function(element,instantly){var target,timeOutTime,classToToggle,self=this,_doc=document,toggle=element,targetString=toggle.dataset.toggleTarget,activeClass='active-search';if(!_doc.querySelectorAll('.show-search-modal').length){self.clickedEl=_doc.activeElement}if(targetString==='next'){target=toggle.nextSibling}else{target=_doc.querySelector(targetString)}if(target.classList.contains(activeClass)){target.dispatchEvent(airinblog.createEvent('toggle-target-before-active-search'))}else{target.dispatchEvent(airinblog.createEvent('toggle-target-before-inactive-search'))}classToToggle=toggle.dataset.classToToggle?toggle.dataset.classToToggle:activeClass;timeOutTime=0;if(target.classList.contains('airinblog-css-cover-search')){timeOutTime=10}setTimeout(function(){var focusElement,subMenued=target.classList.contains('cover-clear'),newTarget=subMenued?toggle.closest('.cover-clear').querySelector('.cover-clear'):target,duration=toggle.dataset.toggleDuration;if(toggle.dataset.toggleType==='slidetoggle'&&!instantly&&duration!=='0'){airinblogMenuToggle(newTarget,duration)}else{newTarget.classList.toggle(classToToggle)}if(targetString==='next'){toggle.classList.toggle(activeClass)}else if(target.classList.contains('cover-clear')){toggle.classList.toggle(activeClass)}else{_doc.querySelector('*[data-toggle-target="'+targetString+'"]').classList.toggle(activeClass)}airinblogToggleAttribute(toggle,'aria-expanded','true','false');if(self.clickedEl&&-1!==toggle.getAttribute('class').indexOf('close-')){airinblogToggleAttribute(self.clickedEl,'aria-expanded','true','false')}if(toggle.dataset.toggleBodyClassSearch){_doc.body.classList.toggle(toggle.dataset.toggleBodyClassSearch)}if(toggle.dataset.setFocus){focusElement=_doc.querySelector(toggle.dataset.setFocus);if(focusElement){if(target.classList.contains(activeClass)){focusElement.focus()}else{focusElement.blur()}}}target.dispatchEvent(airinblog.createEvent('toggled-search'));if(target.classList.contains(activeClass)){target.dispatchEvent(airinblog.createEvent('toggle-target-after-active-search'))}else{target.dispatchEvent(airinblog.createEvent('toggle-target-after-inactive-search'))}},timeOutTime)},toggle:function(){var self=this;document.querySelectorAll('*[data-toggle-target]').forEach(function(element){element.addEventListener('click',function(event){event.preventDefault();self.performToggle(element)})})},resizeCheck:function(){if(document.querySelectorAll('*[data-untoggle-above], *[data-untoggle-below], *[data-toggle-above], *[data-toggle-below]').length){window.addEventListener('resize',function(){var winWidth=window.innerWidth,togglessearch=document.querySelectorAll('.toggle-search');togglessearch.forEach(function(toggle){var unToggleAbove=toggle.dataset.untoggleAbove,unToggleBelow=toggle.dataset.untoggleBelow,toggleAbove=toggle.dataset.toggleAbove,toggleBelow=toggle.dataset.toggleBelow;if(!unToggleAbove&&!unToggleBelow&&!toggleAbove&&!toggleBelow){return}if((((unToggleAbove&&winWidth>unToggleAbove)||(unToggleBelow&&winWidthtoggleAbove)||(toggleBelow&&winWidth