-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddycomplete-min.js
1 lines (1 loc) · 38.5 KB
/
addycomplete-min.js
1
function AddyUrlSettingFactory(e){function t(e){e=e.replace(/[\[\]]/g,"\\$&");var t=new RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)").exec(n);return t?t[2]?decodeURIComponent(t[2].replace(/\+/g," ")):"":null}this.createOptions=function(){var e={};return e.excludePostBox=t("excludePostBox")||!1,e.exRural=t("excludeRural")||!1,e.exUndeliver=t("excludeUndeliver")||!1,e.exSpelling=t("excludeSpelling")||!1,e.exWord=t("excludeWord")||!1,e.exIp=t("excludeIp")||!1,e.exPostcodes=t("excludePostcodes")||"",e.inPostcode=t("includePostcode")||"",e.exRegion=t("excludeRegion")||"",e.inRegion=t("includeRegion")||"",e.exTerritory=t("excludeTerritory")||"",e.inTerritory=t("includeTerritory")||"",e.tag=t("tag")||"",e.uniqueId=t("uniqueid")||"",e.maxItems=t("maxItems")||10,e.enableLocation=!!t("enableLocation")&&navigator.geolocation,e},this.getKey=function(){return t("key")},this.createCallback=function(){var e=t("callback");return e&&"function"==typeof window[e]?e:null},this.getLoadCssEnabled=function(){var e=t("loadcss");return e&&"true"===e},this.createGuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))};var n=function(){var t=document.getElementsByTagName("script");e=e.toLowerCase();for(var n=0;n<t.length;n++)if(t[n].src&&-1!==t[n].src.toLowerCase().indexOf(e))return t[n].src;return""}()}(function(){var e=[].slice,t=function(e,t){return function(){return e.apply(t,arguments)}},n=function(e,t){function n(){this.constructor=e}for(var s in t)i.call(t,s)&&(e[s]=t[s]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},i={}.hasOwnProperty;!function(e,t){"function"==typeof define&&define.amd?define((function(){return t(e)})):e.NeatComplete=t(e)}(this,(function(i){var s;return(s={}).VERSION="1.5.10",s.addDomEvent=function(e,t,n){var i;return e.addEventListener?e.addEventListener(t,n,!1):(i=function(){return n.apply(e,arguments)},e.attachEvent("on"+t,i))},s.removeDomEvent=function(e,t,n){e.removeEventListener?e.removeEventListener(t,n,!1):e.detachEvent&&e.detachEvent("on"+t,null)},s.addClass=function(e,t){return s.classNameExists(e,t)||(t=" "+t,e.className+=t),e},s.removeClass=function(e,t){var n,i,s,o,r;for(r=[],s=0,o=(i=e.className.split(" ")).length;s<o;s++)(n=i[s])!==t&&r.push(n);return e.className=r.join(" "),e},s.classNameExists=function(e,t){var n,i,s;for(i=0,s=(n=e.className.split(" ")).length;i<s;i++)if(n[i]===t)return!0;return!1},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){var t,n,i,s;if(null==this)throw new TypeError;if(0==(n=(s=Object(this)).length>>>0))return-1;if(i=0,arguments.length>0&&((i=Number(arguments[1]))!=i?i=0:0!==i&&1/0!==i&&-1/0!==i&&(i=(i>0||-1)*Math.floor(Math.abs(i)))),i>=n)return-1;for(t=i>=0?i:Math.max(n-Math.abs(i),0);t<n;){if(t in s&&s[t]===e)return t;t++}return-1}),s.Dispatch=function(){function t(){}return t.prototype.setOption=function(e,t){return this.options[e]=t,this},t.prototype.getOption=function(e){return this.options[e]},t.prototype.on=function(e,t){var n;return null==this.subs&&(this.subs={}),null==(n=this.subs)[e]&&(n[e]=[]),this.subs[e].push(t),this},t.prototype.trigger=function(){var t,n,i,s,o,r;if(n=arguments[0],t=2<=arguments.length?e.call(arguments,1):[],null!=(null!=(o=this.subs)?o[n]:void 0))for(i=0,s=(r=this.subs[n]).length;i<s;i++)r[i].apply(this,t);return this},t}(),s.Widget=function(e){function i(e,n){this.element=e,this.options=null!=n?n:{},this._onPaste=t(this._onPaste,this),this._onBlur=t(this._onBlur,this),this._onKeyDown=t(this._onKeyDown,this),this._onKeyPress=t(this._onKeyPress,this),this._onFocus=t(this._onFocus,this),this.enabled=!0,this.searchQueued=!1,this.element.getAttribute("autocomplete")||this.element.setAttribute("autocomplete","off"),this.services=[],this._applyDefaults(),null==this.getOption("container")&&this.setOption("container",window.document.body),this._addListeners(),this.output=document.createElement("ul"),this.output.className=this.options.list_class,this._applyStyle("display","none"),this._applyStyle("position",this.options.position),this.options.container.appendChild(this.output)}return n(i,e),i.prototype.defaults={max_results:10,list_class:"nc_list",item_class:"nc_item",hover_class:"nc_hover",footer_class:"nc_footer",empty_class:"nc_empty",error_class:"nc_error",icon_class:"nc_icon",hidden_icon_class:"nc_hidden",position:"absolute",timeout:400,ignore_returns:!0},i.prototype.addService=function(e,t,n){var i;return null==n&&(n={}),this.services.push(i=new s.Service(this,e,t,n)),i},i.prototype.disable=function(){return this.enabled=!1,this.icon&&s.addClass(this.icon,this.options.hidden_icon_class),this.output.innerHTML="",this},i.prototype.enable=function(){return this.enabled=!0,this.icon&&s.removeClass(this.icon,this.options.hidden_icon_class),this},i.prototype.destroy=function(){document.body.removeChild(this.output),this.element.removeAttribute("autocomplete"),this.icon&&(document.body.removeChild(this.icon),window.removeEventListener("resize",this._resetIconPosition))},i.prototype._applyDefaults=function(){var e,t,n,i;for(e in n=[],t=this.defaults)i=t[e],null==this.getOption(e)?n.push(this.setOption(e,i)):n.push(void 0);return n},i.prototype._addListeners=function(){return s.addDomEvent(this.element,"focus",this._onFocus),s.addDomEvent(this.element,"keypress",this._onKeyPress),s.addDomEvent(this.element,"keydown",this._onKeyDown),s.addDomEvent(this.element,"blur",this._onBlur),s.addDomEvent(this.element,"paste",this._onPaste)},i.prototype._removeListeners=function(){return s.removeDomEvent(this.element,"focus",this._onFocus),s.removeDomEvent(this.element,"keypress",this._onKeyPress),s.removeDomEvent(this.element,"keydown",this._onKeyDown),s.removeDomEvent(this.element,"blur",this._onBlur),s.removeDomEvent(this.element,"paste",this._onPaste)},i.prototype._onFocus=function(e){return this.focused=!0},i.prototype._onKeyPress=function(e){var t,n,i;if(n=e.which||e.keyCode,this.visible&&13===n)return null!=(i=this.highlighted)&&i.selectItem(),(t=this.getOption("ignore_returns"))&&e.preventDefault?e.preventDefault():t&&(e.returnValue=!1),this.highlighted=null},i.prototype._onKeyDown=function(e){var t;switch(e.which||e.keyCode){case 38:return this.visible&&this._moveHighlight(-1),!1;case 40:return this.visible&&this._moveHighlight(1),!1;case 9:if(this.visible)return null!=(t=this.highlighted)?t.selectItem():void 0;break;case 27:return this._hideResults();case 37:case 39:case 13:break;default:return this._getSuggestionsWithTimeout()}},i.prototype._onBlur=function(e){if(!this.mouseDownOnSelect)return this.focused=!1,this._hideResults()},i.prototype._onPaste=function(e){return this._getSuggestionsWithTimeout()},i.prototype._moveHighlight=function(e){var t,n,i,s;return t=null!=this.highlighted?this.results.indexOf(this.highlighted):-1,null!=(i=this.highlighted)&&i.unhighlight(),(t+=e)<-1?t=this.results.length-1:t>=this.results.length&&(t=-1),null!=(s=this.results[t])&&s.highlight(),n=void 0!==this._val?this._val:"",this.element.value=null!=this.highlighted?this.highlighted.value:n},i.prototype._getSuggestionsWithTimeout=function(){return null!=this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout(function(e){return function(){return e._getSuggestions()}}(this),this.options.timeout)},i.prototype._getSuggestions=function(){var e,t,n,i,s;if(this.enabled){if(!this._servicesReady())return void(this.searchQueued=!0);if(this._val=this.element.value,this.error_content=null,""!==this._val){for(i=[],e=0,t=(n=this.services).length;e<t;e++)s=n[e],i.push(s.search(this._val));return i}return this._hideResults()}},i.prototype._applyStyle=function(e,t){return this.output.style[e]=t},i.prototype._getVerticalOffset=function(){return window.pageYOffset||document.documentElement&&document.documentElement.scrollTop},i.prototype._getPosition=function(){var e;return e=this.element,{top:this._getVerticalOffset()+e.getBoundingClientRect().top+e.offsetHeight,left:e.getBoundingClientRect().left}},i.prototype._hideResults=function(){var e,t,n,i,s;for(this.visible=!1,this._applyStyle("display","none"),this.results=[],i=[],e=0,t=(n=this.services).length;e<t;e++)s=n[e],i.push(s.results=[]);return i},i.prototype._displayResults=function(){var e;return this.visible=!0,e=this._getPosition(),this.options.container===document.body&&(this._applyStyle("left",e.left+"px"),this._applyStyle("top",e.top+"px")),this._applyStyle("display","block")},i.prototype._renderItem=function(e,t){var n;return(n=document.createElement("li")).innerHTML=e,null!=t&&(n.className=t),s.addDomEvent(n,"mousedown",function(e){return function(){return e.mouseDownOnSelect=!0}}(this)),s.addDomEvent(n,"mouseup",function(e){return function(){return e.mouseDownOnSelect=!1}}(this)),n},i.prototype._renderFooter=function(){return this._renderItem(this.options.footer_content,this.options.footer_class)},i.prototype._renderEmpty=function(){return this._renderItem(this.options.empty_content,this.options.empty_class)},i.prototype._servicesReady=function(){var e,t,n,i,s;for(s=[],e=0,t=(n=this.services).length;e<t;e++)i=n[e],s.push(i.ready());return s.indexOf(!1)<0},i.prototype.showResults=function(){var e,t,n,i,s,o,r,a,l;if(this._servicesReady()){for(this.searchQueued&&(this._getSuggestions(),this.searchQueued=!1),this.results=[],this.output.innerHTML="",t=0,i=(o=this.services).length;t<i;t++)l=o[t],this.results=this.results.concat(l.results);if(this.results.length){for(this.results=this.results.sort((function(e,t){return t.score-e.score})),this.results=this.results.slice(0,+(this.getOption("max_results")-1)+1||9e9),n=0,s=(r=this.results).length;n<s;n++)a=r[n],this.output.appendChild(a.render());null!=this.options.footer_content&&""!==(e=this._renderFooter())&&this.output.appendChild(e),this._displayResults()}else this.error_content?(this.output.appendChild(this._renderItem(this.error_content,this.options.error_class)),this._displayResults()):(null!=this.options.empty_content?(this.output.appendChild(this._renderEmpty()),this._displayResults()):this._hideResults(),this.trigger("results:empty"));this.trigger("results:update")}},i.prototype.selectHighlighted=function(){this.element.value=this.highlighted.value,this._hideResults(),this.trigger("result:select",this.highlighted.value,this.highlighted.data),this._dispatchDOMChangeEvent()},i.prototype._dispatchDOMChangeEvent=function(){var e;if("function"==typeof Event)e=new Event("change",{bubbles:!0,cancellable:!0});else{if(void 0===document.createEvent)return;(e=document.createEvent("Event")).initEvent("change",!0,!0)}return this.element.dispatchEvent(e)},i.prototype.setIcon=function(e,t){var n,i,o;return this.removeIcon(e),i=e.class||"nc_icon",n=document.createElement("a"),s.addClass(n,i),o=this._calculateIconPosition(),n.style.top=o.coords.top+"px",n.style.left=o.coords.left+"px",n.style.height=o.size+"px",n.style.width=o.size+"px",n.addEventListener("click",t),this._resetIconPosition=this.setIcon.bind(this,e,t),window.addEventListener("resize",this._resetIconPosition),this.options.container.appendChild(n),this.icon=n},i.prototype.removeIcon=function(e){return this.icon&&(this.icon.parentNode.removeChild(this.icon),window.removeEventListener("resize",this._resetIconPosition)),this.icon=null},i.prototype._calculateIconPosition=function(){var e,t,n,i;return i=this.element.offsetWidth,e=(t=this.element.offsetHeight/2)/2.4,{coords:{top:(n=this._getPosition()).top-t-e,left:n.left+i-t-e},size:t}},i.prototype.setInfoPanel=function(e,t){var n,i;return n=(t=t||{}).class||"af_info_panel",!1===t.persistant?(this.output.innerHTML="",i=this._renderItem(e,n),t.cancellable&&this._addCancelButton(i,t),this.output.appendChild(i),this._displayResults()):(this.infoPanel={},this.infoPanel.content=e,this.infoPanel.options=t)},i.prototype._addCancelButton=function(e,t){var n,i,o;return n=(o=navigator.userAgent).indexOf("MSIE ")>-1||o.indexOf("Trident/")>-1,i=document.createElement("span"),s.addClass(i,"cancel_button"),n&&s.addClass(i,"IE"),i.addEventListener("click",function(){return this.output.innerHTML="",t.cancelHandler()}.bind(this)),e.appendChild(i)},i}(s.Dispatch),s.Service=function(e){function i(e,n,i,s){this.widget=e,this.name=n,this.search_fn=i,this.options=null!=s?s:{},this._response=t(this._response,this),this.ready=t(this.ready,this),this.results=[],this._ready=!0,this.response=function(e){return function(t,n){return e._response.apply(e,arguments)}}(this)}return n(i,e),i.prototype.ready=function(){return this._ready},i.prototype.search=function(e){return this.last_query=e,this._ready=!1,this.search_fn(e,this.response)},i.prototype._response=function(e,t){var n,i,o;if(this.results=[],this.last_query===e){for(this.results=[],i=0,o=t.length;i<o;i++)n=t[i],this.results.push(new s._Result(this,n));return this._ready=!0,this.widget.showResults()}},i}(s.Dispatch),s._Result=function(){function e(e,t){var n,i,s,o;this.service=e,this.options=t,this.widget=this.service.widget,this.renderer=this.service.options.renderer||this.widget.options.renderer,this.value=null!=(n=this.options)?n.value:void 0,this.score=(null!=(i=this.options)?i.score:void 0)||0,this.identifier=null!=(s=this.options)?s.identifier:void 0,this.data=(null!=(o=this.options)?o.data:void 0)||{}}return e.prototype.render=function(){return this.li=document.createElement("li"),this.li.innerHTML=null!=this.renderer?this.renderer(this.value,this.data):this.value,this.li.className=this.widget.options.item_class,this.addEvents(),this.li},e.prototype.addEvents=function(){return s.addDomEvent(this.li,"click",function(e){return function(t){return e.selectItem(),t.preventDefault?t.preventDefault():t.returnValue=!1}}(this)),s.addDomEvent(this.li,"mouseover",function(e){return function(){return e.highlight()}}(this)),s.addDomEvent(this.li,"mouseout",function(e){return function(){return e.unhighlight()}}(this)),s.addDomEvent(this.li,"mousedown",function(e){return function(){return e.widget.mouseDownOnSelect=!0}}(this)),s.addDomEvent(this.li,"mouseup",function(e){return function(){return e.widget.mouseDownOnSelect=!1}}(this))},e.prototype.selectItem=function(){return this.service.trigger("result:select",this.value,this.data),this.widget.highlighted=this,this.widget.selectHighlighted()},e.prototype.highlight=function(){var e;return null!=(e=this.widget.highlighted)&&e.unhighlight(),this.li.className=this.li.className+" "+this.widget.options.hover_class,this.widget.highlighted=this},e.prototype.unhighlight=function(){return this.widget.highlighted=null,this.li.className=this.li.className.replace(new RegExp(this.widget.options.hover_class,"gi"),"")},e}(),s}))}).call(this),function(e,t,n){"undefined"!=typeof module&&module.exports?module.exports=n():"function"==typeof define&&define.amd?define(n):t.reqwest=n()}(0,this,(function(){function succeed(e){var t=protocolRe.exec(e.url);return t=t&&t[1]||context.location.protocol,httpsRe.test(t)?twoHundo.test(e.request.status):!!e.request.response}function handleReadyState(e,t,n){return function(){return e._aborted?n(e.request):e._timedOut?n(e.request,"Request is aborted: timeout"):void(e.request&&4==e.request[readyState]&&(e.request.onreadystatechange=noop,succeed(e)?t(e.request):n(e.request)))}}function setHeaders(e,t){var n,i=t.headers||{};i.Accept=i.Accept||defaultHeaders.accept[t.type]||defaultHeaders.accept["*"];var s="undefined"!=typeof FormData&&t.data instanceof FormData;for(n in!t.crossOrigin&&!i[requestedWith]&&(i[requestedWith]=defaultHeaders.requestedWith),!i[contentType]&&!s&&(i[contentType]=t.contentType||defaultHeaders.contentType),i)i.hasOwnProperty(n)&&"setRequestHeader"in e&&e.setRequestHeader(n,i[n])}function setCredentials(e,t){void 0!==t.withCredentials&&void 0!==e.withCredentials&&(e.withCredentials=!!t.withCredentials)}function generalCallback(e){lastValue=e}function urlappend(e,t){return e+(/\?/.test(e)?"&":"?")+t}function handleJsonp(e,t,n,i){var s=uniqid++,o=e.jsonpCallback||"callback",r=e.jsonpCallbackName||reqwest.getcallbackPrefix(s),a=new RegExp("((^|\\?|&)"+o+")=([^&]+)"),l=i.match(a),u=doc.createElement("script"),d=0,c=-1!==navigator.userAgent.indexOf("MSIE 10.0");return l?"?"===l[3]?i=i.replace(a,"$1="+r):r=l[3]:i=urlappend(i,o+"="+r),context[r]=generalCallback,u.type="text/javascript",u.src=i,u.async=!0,void 0!==u.onreadystatechange&&!c&&(u.htmlFor=u.id="_reqwest_"+s),u.onload=u.onreadystatechange=function(){if(u[readyState]&&"complete"!==u[readyState]&&"loaded"!==u[readyState]||d)return!1;u.onload=u.onreadystatechange=null,u.onclick&&u.onclick(),t(lastValue),lastValue=void 0,head.removeChild(u),d=1},head.appendChild(u),{abort:function(){u.onload=u.onreadystatechange=null,n({},"Request is aborted: timeout",{}),lastValue=void 0,head.removeChild(u),d=1}}}function getRequest(e,t){var n,i=this.o,s=(i.method||"GET").toUpperCase(),o="string"==typeof i?i:i.url,r=!1!==i.processData&&i.data&&"string"!=typeof i.data?reqwest.toQueryString(i.data):i.data||null,a=!1;return("jsonp"==i.type||"GET"==s)&&r&&(o=urlappend(o,r),r=null),"jsonp"==i.type?handleJsonp(i,e,t,o):((n=i.xhr&&i.xhr(i)||xhr(i)).open(s,o,!1!==i.async),setHeaders(n,i),setCredentials(n,i),context[xDomainRequest]&&n instanceof context[xDomainRequest]?(n.onload=e,n.onerror=t,n.onprogress=function(){},a=!0):n.onreadystatechange=handleReadyState(this,e,t),i.before&&i.before(n),a?setTimeout((function(){n.send(r)}),200):n.send(r),n)}function Reqwest(e,t){this.o=e,this.fn=t,init.apply(this,arguments)}function setType(e){if(null!==e)return e.match("json")?"json":e.match("javascript")?"js":e.match("text")?"html":e.match("xml")?"xml":void 0}function init(o,fn){function complete(e){for(o.timeout&&clearTimeout(self.timeout),self.timeout=null;self._completeHandlers.length>0;)self._completeHandlers.shift()(e)}function success(resp){var type=o.type||resp&&setType(resp.getResponseHeader("Content-Type"));resp="jsonp"!==type?self.request:resp;var filteredResponse=globalSetupOptions.dataFilter(resp.responseText,type),r=filteredResponse;try{resp.responseText=r}catch(e){}if(r)switch(type){case"json":try{resp=context.JSON?context.JSON.parse(r):eval("("+r+")")}catch(e){return error(resp,"Could not parse JSON in response",e)}break;case"js":resp=eval(r);break;case"html":resp=r;break;case"xml":resp=resp.responseXML&&resp.responseXML.parseError&&resp.responseXML.parseError.errorCode&&resp.responseXML.parseError.reason?null:resp.responseXML}for(self._responseArgs.resp=resp,self._fulfilled=!0,fn(resp),self._successHandler(resp);self._fulfillmentHandlers.length>0;)resp=self._fulfillmentHandlers.shift()(resp);complete(resp)}function timedOut(){self._timedOut=!0,self.request.abort()}function error(e,t,n){for(e=self.request,self._responseArgs.resp=e,self._responseArgs.msg=t,self._responseArgs.t=n,self._erred=!0;self._errorHandlers.length>0;)self._errorHandlers.shift()(e,t,n);complete(e)}this.url="string"==typeof o?o:o.url,this.timeout=null,this._fulfilled=!1,this._successHandler=function(){},this._fulfillmentHandlers=[],this._errorHandlers=[],this._completeHandlers=[],this._erred=!1,this._responseArgs={};var self=this;fn=fn||function(){},o.timeout&&(this.timeout=setTimeout((function(){timedOut()}),o.timeout)),o.success&&(this._successHandler=function(){o.success.apply(o,arguments)}),o.error&&this._errorHandlers.push((function(){o.error.apply(o,arguments)})),o.complete&&this._completeHandlers.push((function(){o.complete.apply(o,arguments)})),this.request=getRequest.call(this,success,error)}function reqwest(e,t){return new Reqwest(e,t)}function normalize(e){return e?e.replace(/\r?\n/g,"\r\n"):""}function serial(e,t){var n,i,s,o,r=e.name,a=e.tagName.toLowerCase(),l=function(e){e&&!e.disabled&&t(r,normalize(e.attributes.value&&e.attributes.value.specified?e.value:e.text))};if(!e.disabled&&r)switch(a){case"input":/reset|button|image|file/i.test(e.type)||(n=/checkbox/i.test(e.type),i=/radio/i.test(e.type),s=e.value,(!n&&!i||e.checked)&&t(r,normalize(n&&""===s?"on":s)));break;case"textarea":t(r,normalize(e.value));break;case"select":if("select-one"===e.type.toLowerCase())l(e.selectedIndex>=0?e.options[e.selectedIndex]:null);else for(o=0;e.length&&o<e.length;o++)e.options[o].selected&&l(e.options[o])}}function eachFormElement(){var e,t,n=this,i=function(e,t){var i,s,o;for(i=0;i<t.length;i++)for(o=e[byTag](t[i]),s=0;s<o.length;s++)serial(o[s],n)};for(t=0;t<arguments.length;t++)/input|select|textarea/i.test((e=arguments[t]).tagName)&&serial(e,n),i(e,["input","select","textarea"])}function serializeQueryString(){return reqwest.toQueryString(reqwest.serializeArray.apply(null,arguments))}function serializeHash(){var e={};return eachFormElement.apply((function(t,n){t in e?(e[t]&&!isArray(e[t])&&(e[t]=[e[t]]),e[t].push(n)):e[t]=n}),arguments),e}function buildParams(e,t,n,i){var s,o,r,a=/\[\]$/;if(isArray(t))for(o=0;t&&o<t.length;o++)r=t[o],n||a.test(e)?i(e,r):buildParams(e+"["+("object"==typeof r?o:"")+"]",r,n,i);else if(t&&"[object Object]"===t.toString())for(s in t)buildParams(e+"["+s+"]",t[s],n,i);else i(e,t)}var context=this,XHR2;if("window"in context)var doc=document,byTag="getElementsByTagName",head=doc[byTag]("head")[0];else try{XHR2=require("xhr2")}catch(e){throw new Error("Peer dependency `xhr2` required! Please npm install xhr2")}var httpsRe=/^http/,protocolRe=/(^\w+):\/\//,twoHundo=/^(20\d|1223)$/,readyState="readyState",contentType="Content-Type",requestedWith="X-Requested-With",uniqid=0,callbackPrefix="reqwest_"+ +new Date,lastValue,xmlHttpRequest="XMLHttpRequest",xDomainRequest="XDomainRequest",noop=function(){},isArray="function"==typeof Array.isArray?Array.isArray:function(e){return e instanceof Array},defaultHeaders={contentType:"application/x-www-form-urlencoded",requestedWith:xmlHttpRequest,accept:{"*":"text/javascript, text/html, application/xml, text/xml, */*",xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript",js:"application/javascript, text/javascript"}},xhr=function(e){if(!0===e.crossOrigin){var t=context[xmlHttpRequest]?new XMLHttpRequest:null;if(t&&"withCredentials"in t)return t;if(context[xDomainRequest])return new XDomainRequest;throw new Error("Browser does not support cross-origin requests")}return context[xmlHttpRequest]?new XMLHttpRequest:XHR2?new XHR2:new ActiveXObject("Microsoft.XMLHTTP")},globalSetupOptions={dataFilter:function(e){return e}};return Reqwest.prototype={abort:function(){this._aborted=!0,this.request.abort()},retry:function(){init.call(this,this.o,this.fn)},then:function(e,t){return e=e||function(){},t=t||function(){},this._fulfilled?this._responseArgs.resp=e(this._responseArgs.resp):this._erred?t(this._responseArgs.resp,this._responseArgs.msg,this._responseArgs.t):(this._fulfillmentHandlers.push(e),this._errorHandlers.push(t)),this},always:function(e){return this._fulfilled||this._erred?e(this._responseArgs.resp):this._completeHandlers.push(e),this},fail:function(e){return this._erred?e(this._responseArgs.resp,this._responseArgs.msg,this._responseArgs.t):this._errorHandlers.push(e),this},catch:function(e){return this.fail(e)}},reqwest.serializeArray=function(){var e=[];return eachFormElement.apply((function(t,n){e.push({name:t,value:n})}),arguments),e},reqwest.serialize=function(){if(0===arguments.length)return"";var e,t=Array.prototype.slice.call(arguments,0);return(e=t.pop())&&e.nodeType&&t.push(e)&&(e=null),e&&(e=e.type),("map"==e?serializeHash:"array"==e?reqwest.serializeArray:serializeQueryString).apply(null,t)},reqwest.toQueryString=function(e,t){var n,i,s=t||!1,o=[],r=encodeURIComponent,a=function(e,t){t="function"==typeof t?t():null==t?"":t,o[o.length]=r(e)+"="+r(t)};if(isArray(e))for(i=0;e&&i<e.length;i++)a(e[i].name,e[i].value);else for(n in e)e.hasOwnProperty(n)&&buildParams(n,e[n],s,a);return o.join("&").replace(/%20/g,"+")},reqwest.getcallbackPrefix=function(){return callbackPrefix},reqwest.compat=function(e,t){return e&&(e.type&&(e.method=e.type)&&delete e.type,e.dataType&&(e.type=e.dataType),e.jsonpCallback&&(e.jsonpCallbackName=e.jsonpCallback)&&delete e.jsonpCallback,e.jsonp&&(e.jsonpCallback=e.jsonp)),new Reqwest(e,t)},reqwest.ajaxSetup=function(e){for(var t in e=e||{})globalSetupOptions[t]=e[t]},reqwest}));var addySettingsFactory=new AddyUrlSettingFactory("addy");function AddyComplete(e,t){if(e){var n=this;n.urlBase="https://api.addy.co.nz/",n.searchSuffix="",n.requestSuffix="",n.fields=t||{},n.mode="address",n.options=addySettingsFactory.createOptions(),n.key=addySettingsFactory.getKey();var i=addySettingsFactory.createGuid(),s=e.placeholder;n.makeRequest=function(e,t,s,o){reqwest({url:n.urlBase+e+"?key="+n.key+n.requestSuffix+"&v=neat_2_2_0&session="+i+t,crossOrigin:!0,success:function(e){s&&s(e)},error:function(e){o&&o(e)}})},n.searchRequest=function(e,t,i){n.makeRequest(e,t,(function(e){i(e),n.service.endSearch()}),(function(e){n.widget&&(n.widget.error_content='"Request Failed:\n'+(e.message||e),n.service.endSearch())}))},n.widget=new NeatComplete.Widget(e,{empty_content:"<b>Address not found.</b> Please verify the spelling.<br />For brand new addresses, please type it in manually.",location_content:"Addresses near me",location_unavailable:"Location information unavailable. Please type in your address.",location_not_found:"No nearby addresses found. Please type in your address.",location_loading:"Loading your location...",max_results:n.options.maxItems,timeout:50});var o=null;n.service=n.widget.addService("addy",(function(e,t){try{o=new RegExp("("+function(e){return e.replace(/\\/gi,"/").replace(/[^0-9a-z' \/]/gi,"").trim()}(e).split(" ").join("|")+")","gi")}catch(e){o=null}"address"===n.mode?n.searchRequest("search",n.searchSuffix+"&s="+e,(function(n){var i=new Array;if(n)for(var s=0;s<n.addresses.length;s++)i.push({value:n.addresses[s].a,data:n.addresses[s]});t(e,i)})):n.searchRequest("postcode","&max="+n.getMaxResults()+"&s="+e,(function(n){var i=new Array;if(n)for(var s=0;s<n.postcodes.length;s++){var o=n.postcodes[s];i.push({value:o.suburb+(""===o.suburb?"":", ")+o.city+(""===o.city?"":", ")+o.postcode,data:o})}t(e,i)}))}),{renderer:function(e,t){var i=n.widget.getOption("highlight_class");return null===o?e:e.replace(o,'<span class="'+(void 0===i?"nc_highlight":i)+'">$1</span>')}}),n.service.timer=null,n.service.endSearch=function(){this.timer&&clearTimeout(this.timer),this._ready=!0},n.service.search=function(e){if(!(e.length<3))return n.widget.error_content=null,this.last_query=e,this._ready=!1,this.timer=setTimeout((function(){this._ready=!0}),3200),this.search_fn(e,this.response)},n.setOption=function(e,t){e&&"exclude_postbox"===e?n.options.excludePostBox=t:n.widget.setOption(e,t),r()},n.setExcludeRural=function(e){n.options.exRural=e,r()},n.setExcludePostbox=function(e){n.options.excludePostBox=e,r()},n.setExcludeUndeliverable=function(e){n.options.exUndeliver=e,r()},n.setExcludeSpelling=function(e){n.options.exSpelling=e,r()},n.setExcludeWordRemoval=function(e){n.options.exWord=e,r()},n.setExcludeIpOrder=function(e){n.options.exIp=e,r()},n.setExcludePostcodes=function(e){n.options.exPostcodes=Array.isArray(e)?e.join("-"):e,r()},n.setIncludePostcodes=function(e){n.options.inPostcode=Array.isArray(e)?e.join("-"):e,r()},n.setExcludeRegions=function(e){n.options.exRegion=Array.isArray(e)?e.join("-"):e,r()},n.setIncludeRegions=function(e){n.options.inRegion=Array.isArray(e)?e.join("-"):e,r()},n.setExcludeTerritories=function(e){n.options.exTerritory=Array.isArray(e)?e.join("-"):e,r()},n.setIncludeTerritories=function(e){n.options.inTerritory=Array.isArray(e)?e.join("-"):e,r()},n.setTag=function(e){n.options.tag=e,r()},n.setUniqueId=function(e){n.options.uniqueId=e,r()},n.getOption=function(e){return n.widget.getOption(e)},n.getMaxResults=function(){return n.widget.getOption("max_results")},n.enableLocation=function(){n.options.enableLocation=!0},n.disableLocation=function(){n.options.enableLocation=!1},n.enable=function(){n.widget.enable()},n.disable=function(){n.widget.disable()},n.setPostcodeMode=function(e){n.mode="postcode",n.setOption("empty_content","Postcode not found. Please verify the spelling.")},n._onLocationResultsEmpty=function(e){var t=n.widget.getOption("empty_content");n.options.enableLocation=!1,n.setOption("empty_content",e),setTimeout((function(){n.setOption("empty_content",t)}),2e3)},n.handleLocationError=function(t){n.makeRequest("errorlog","&message=GeoFailCode:"+t.code+":"+t.message,(function(e){})),n._onLocationResultsEmpty(n.getOption("location_unavailable")),n.service._response(n.service.last_query,[]),e.placeholder=s},n.reverseGeocode=function(t){n.makeRequest("geocode","&x="+t.coords.longitude+"&y="+t.coords.latitude+"&limit="+n.getMaxResults(),function(t){var i=new Array;if(t)for(var o=0;o<t.addresses.length;o++)i.push({value:t.addresses[o].displayname,data:t.addresses[o]});0===i.length&&n._onLocationResultsEmpty(n.getOption("location_not_found")),e.placeholder=s,n.service._response(n.service.last_query,i)}.bind(this))},n.addressSelected=function(e){},n.postcodeSelected=function(e){},n.assignAddressFields=function(e){n.fields.address&&(n.fields.address.value=e.displayline),n.fields.suburb&&(n.fields.suburb.value=""===e.suburb?""===e.mailtown?e.city:e.mailtown:e.suburb),n.fields.city&&(n.fields.city.value=""===e.mailtown?e.city:e.mailtown),n.fields.territory&&(n.fields.territory.value=e.territory),n.fields.x&&(n.fields.x.value=e.x),n.fields.y&&(n.fields.y.value=e.y),n.fields.dpid&&(n.fields.dpid.value=e.dpid),n.fields.id&&(n.fields.id.value=e.id),n.fields.postcode&&(n.fields.postcode.value=e.postcode),n.fields.line1&&(n.fields.line1.value=e.address1),n.fields.line2&&(n.fields.line2.value=e.address2),n.fields.line3&&(n.fields.line3.value=e.address3),n.fields.line4&&(n.fields.line4.value=e.address4),n.fields.city||!n.fields.suburb||""!==e.suburb||""===e.city&&""===e.mailtown||(n.fields.suburb.value=""===e.mailtown?e.city:e.mailtown),n.fields.address1&&n.fields.address2?(e.address4||0===e.address2.indexOf("RD ")?(n.fields.address1.value=e.address1,n.fields.address2.value=e.address2):(n.fields.address1.value=e.displayline,n.fields.address2.value=""),!n.fields.suburb&&e.suburb&&""!==e.suburb&&(""!==n.fields.address2.value&&(n.fields.address1.value+=", "+n.fields.address2.value),n.fields.address2.value=e.suburb)):n.fields.address1&&!n.fields.address2&&(n.fields.address1.value=e.displayline)},n.assignRegion=function(e){var t=n.fields.region;if(t)if(t.options){e.region=e.region.toUpperCase();for(var i=[e.region,e.region.replace("'",""),e.region.replace("-"," - "),e.region.replace("-"," / "),e.region.replace("-","/")],s=0;s<t.options.length;s++)if(i.indexOf(t.options[s].text.toUpperCase())>-1||i.indexOf(t.options[s].value.toUpperCase())>-1){t.selectedIndex=s;break}}else t.value=e.region},n.loadAddress=function(e){n.makeRequest("address/"+e,"",function(e){e&&(n.assignAddressFields(e),n.assignRegion(e),n.addressSelected(e))}.bind(this))},n.loadLocation=function(){e.value="",e.placeholder=n.getOption("location_loading"),navigator.geolocation.getCurrentPosition(n.reverseGeocode,n.handleLocationError)},n.widget.on("result:select",(function(e,t){"address"===n.mode?"location"===t.id?n.loadLocation():n.loadAddress(t.id):n.postcodeSelected(t)})),n.checkDemo=function(){return!(!n.key||"demo-api-key"!==n.key.toLowerCase()||(n.setOption("footer_content",'<b>Demo Mode:</b> Create a free account at <a href="https://www.addy.co.nz/" class="link-active">addy.co.nz</a>'),0))},n.checkDemo(),r(),n.makeRequest("searchwarmup","")}function r(){n.searchSuffix="&max="+n.getMaxResults(),n.options.excludePostBox&&(n.searchSuffix+="&expostbox=true"),n.options.exUndeliver&&(n.searchSuffix+="&exundeliver=true"),n.options.exRural&&(n.searchSuffix+="&exrural=true"),n.options.exSpelling&&(n.searchSuffix+="&exspelling=true"),n.options.exWord&&(n.searchSuffix+="&exword=true"),n.options.exIp&&(n.searchSuffix+="&exip=true"),n.options.exPostcodes&&""!==n.options.exPostcodes&&(n.searchSuffix+="&expostcode="+n.options.exPostcodes),n.options.inPostcode&&""!==n.options.inPostcode&&(n.searchSuffix+="&inpostcode="+n.options.inPostcode),n.options.exRegion&&""!==n.options.exRegion&&(n.searchSuffix+="&exregion="+n.options.exRegion),n.options.inRegion&&""!==n.options.inRegion&&(n.searchSuffix+="&inregion="+n.options.inRegion),n.options.exTerritory&&""!==n.options.exTerritory&&(n.searchSuffix+="&exterritory="+n.options.exTerritory),n.options.inTerritory&&""!==n.options.inTerritory&&(n.searchSuffix+="&interritory="+n.options.inTerritory),n.requestSuffix="",n.options.tag&&""!==n.options.tag&&(n.requestSuffix+="&tag="+n.options.tag),n.options.uniqueId&&""!==n.options.uniqueId&&(n.requestSuffix+="&uniqueid="+n.options.uniqueId)}}function initAddyByCss(){var e=["","2-","3-","4-"];function t(e){var t=document.getElementsByClassName("addy-"+e);return 1===t.length?t[0]:null}for(var n=0;n<e.length;n++){var i=t(e[n]+"line1");null!==i&&new AddyComplete(i,{address1:i,address2:t(e[n]+"line2"),suburb:t(e[n]+"suburb"),city:t(e[n]+"city"),region:t(e[n]+"region"),territory:t(e[n]+"territory"),postcode:t(e[n]+"postcode"),dpid:t(e[n]+"dpid"),id:t(e[n]+"id"),x:t(e[n]+"x"),y:t(e[n]+"y")})}}function callAddyInit(){var e=addySettingsFactory.createCallback(),t=!1;if(e?(window[e](),t=!0):"function"==typeof initAddy&&(initAddy(),t=!0),t||initAddyByCss(),addySettingsFactory.getLoadCssEnabled()){var n=document.createElement("link");n.setAttribute("rel","stylesheet"),n.setAttribute("type","text/css"),n.setAttribute("href","https://www.addy.co.nz/css/addy.css"),document.getElementsByTagName("head")[0].appendChild(n)}}function getElementByIdVariations(e,t){return document.getElementById(e+"_"+t)||document.getElementById(e+"-"+t)}function initAddy(){if(window.addyConfig&&window.addyConfig.key){var e=[];t("billing"),t("shipping")}function t(t){let n=getElementByIdVariations(t,"address_1");if(n){var i=new AddyComplete(n);i.fields={address1:n,address2:getElementByIdVariations(t,"address_2"),suburb:getElementByIdVariations(t,"suburb"),city:getElementByIdVariations(t,"city"),postcode:getElementByIdVariations(t,"postcode")},e[t]=i,i.key=window.addyConfig.key;var s=window.addyConfig;i.setExcludePostbox(s.hidePostCode&&"yes"===s.hidePostCode),i.setExcludeRural(s.hideRural&&"yes"===s.hideRural),i.setExcludeUndeliverable(s.hideUndeliver&&"yes"===s.hideUndeliver),s.enableLocation&&"yes"===s.enableLocation&&i.enableLocation(),s.filterPostcodes&&""!==s.filterPostcodes&&i.setIncludePostcodes(s.filterPostcodes),s.filterRegions&&""!==s.filterRegions&&i.setIncludeRegions(s.filterRegions),s.notFound&&""!==s.notFound&&i.setOption("empty_content",s.notFound),i.widget._getPosition=function(){const e=n.getBoundingClientRect(),t={top:e.top+window.scrollY,left:e.left+window.scrollX};return t.top+=n.offsetHeight,t},i.checkDemo(),i.customRegion=getElementByIdVariations(t,"state"),i.addressSelected=function(e){if(this.customRegion&&this.customRegion.options&&""!==e.region){var t="";for(let n=0;n<this.customRegion.options.length;n++){const i=this.customRegion.options[n];if(i.text===e.region||i.value===e.region){t=i.value;break}}""!==t&&(this.customRegion.value=t)}var n={first_name:e.first_name||r("#billing_first_name","#billing-first_name"),last_name:e.last_name||r("#billing_last_name","#billing-last_name"),company:e.company||r("#billing_company","#billing-company"),address_1:e.displayline||r("#billing_address_1","#billing-address_1"),address_2:e.address2||r("#billing_address_2","#billing-address_2"),city:e.city||r("#billing_city","#billing-city"),state:e.state||r("#billing_state","#billing-state"),postcode:e.postcode||r("#billing_postcode","#billing-postcode"),country:e.country||r("#billing_country","#billing-country")||"NZ",email:e.email||r("#billing_email","#billing-email"),phone:e.phone||r("#billing_phone","#billing-phone")},s={first_name:e.first_name||r("#shipping_first_name","#shipping-first_name"),last_name:e.last_name||r("#shipping_last_name","#shipping-last_name"),company:e.company||r("#shipping_company","#shipping-company"),address_1:e.displayline||r("#shipping_address_1","#shipping-address_1"),address_2:e.address2||r("#shipping_address_2","#shipping-address_2"),city:e.city||r("#shipping_city","#shipping-city"),state:e.state||r("#shipping_state","#shipping-state"),postcode:e.postcode||r("#shipping_postcode","#shipping-postcode"),country:e.country||r("#shipping_country","#shipping-country")||"NZ",phone:e.phone||r("#shipping_phone","#shipping-phone")};a("#billing_address_1","#billing-address_1",n.address_1),a("#billing_address_2","#billing-address_2",n.address_2),a("#billing_city","#billing-city",n.city),a("#billing_postcode","#billing-postcode",n.postcode),this.customRegion&&(this.customRegion.value=n.state);jQuery(i.fields.address1).closest("form");if(l("#billing_address_1","#billing-address_1"),l("#billing_address_2","#billing-address_2"),l("#billing_city","#billing-city"),l("#billing_postcode","#billing-postcode"),this.customRegion&&this.customRegion.dispatchEvent){let e="function"==typeof Event?new Event("input",{bubbles:!0}):document.createEvent("Event");e instanceof Event||e.initEvent("input",!0,!0),this.customRegion.dispatchEvent(e),e="function"==typeof Event?new Event("change",{bubbles:!0}):document.createEvent("Event"),e instanceof Event||e.initEvent("change",!0,!0),this.customRegion.dispatchEvent(e)}var o={billing_address:n,shipping_address:s};wp.apiFetch({path:"/wc/store/v1/cart/update-customer",method:"POST",data:o,headers:{"X-WP-Nonce":window.wpApiSettings&&window.wpApiSettings.nonce||""}}).then((function(e){e.billing_address.first_name||(e.billing_address=n),e.shipping_address.first_name||(e.shipping_address=s),wp.data&&wp.data.dispatch&&"function"==typeof wp.data.dispatch("wc/store/cart").receiveCart&&wp.data.dispatch("wc/store/cart").receiveCart(e),jQuery(document.body).trigger("update_checkout")})).catch((function(e){}))};var o=getElementByIdVariations(t,"country");o&&o.addEventListener("change",function(){"NZ"===getElementByIdVariations(t,"country").value?e[t].widget.enable():e[t].widget.disable()}.bind(this))}function r(e,t){return jQuery(e).length>0?jQuery(e).val():jQuery(t).length>0?jQuery(t).val():""}function a(e,t,n){jQuery(e).length>0&&jQuery(e).val(n),jQuery(t).length>0&&jQuery(t).val(n)}function l(e,t){let n=document.querySelector(e)||document.querySelector(t);var i;n&&("function"==typeof Event?(i=new Event("input",{bubbles:!0}),n.dispatchEvent(i),i=new Event("change",{bubbles:!0}),n.dispatchEvent(i)):((i=document.createEvent("Event")).initEvent("input",!0,!0),n.dispatchEvent(i),(i=document.createEvent("Event")).initEvent("change",!0,!0),n.dispatchEvent(i)))}}}function updateLabel(e){if(e){const t=document.querySelector(`label[for="${e.id}"]`);t&&(t.textContent=e.value||t.textContent)}}function initAddyDomLoad(e){if(0!==e){if(getElementByIdVariations("billing","address_1")||getElementByIdVariations("shipping","address_1")){const e=["address_1","address_2","city","postcode","shipping-state","country"];return["billing","shipping"].forEach((function(t){e.forEach((function(e){let n=getElementByIdVariations(t,e);n&&(n.setAttribute("autocomplete","off"),n.addEventListener("change",(()=>{const e=n.closest("div");e&&n.value&&!e.classList.contains("is-active")&&e.classList.add("is-active")})))}))})),jQuery(document.body).on("updated_checkout",(function(){})),void initAddy()}setTimeout((function(){initAddyDomLoad(e-1)}),1e3)}else initAddy()}jQuery(document).ready((function(){initAddyDomLoad(6)})),document.addEventListener("DOMContentLoaded",(function(){}));