-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddycomplete.min.js
More file actions
1 lines (1 loc) · 40.3 KB
/
addycomplete.min.js
File metadata and controls
1 lines (1 loc) · 40.3 KB
1
function AddyUrlSettingFactory(e){function t(e){e=e.replace(/[\[\]]/g,"\\$&");var t=new RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)").exec(i);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 i=function(){var t=document.getElementsByTagName("script");e=e.toLowerCase();for(var i=0;i<t.length;i++)if(t[i].src&&-1!==t[i].src.toLowerCase().indexOf(e))return t[i].src;return""}()}(function(){var e=[].slice,t=function(e,t){return function(){return e.apply(t,arguments)}},i=function(e,t){function i(){this.constructor=e}for(var s in t)n.call(t,s)&&(e[s]=t[s]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e},n={}.hasOwnProperty;!function(e,t){"function"==typeof define&&define.amd?define((function(){return t(e)})):e.NeatComplete=t(e)}(this,(function(n){var s;return(s={}).VERSION="1.5.10",s.addDomEvent=function(e,t,i){var n;return e.addEventListener?e.addEventListener(t,i,!1):(n=function(){return i.apply(e,arguments)},e.attachEvent("on"+t,n))},s.removeDomEvent=function(e,t,i){e.removeEventListener?e.removeEventListener(t,i,!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 i,n,s,o,r;for(r=[],s=0,o=(n=e.className.split(" ")).length;s<o;s++)(i=n[s])!==t&&r.push(i);return e.className=r.join(" "),e},s.classNameExists=function(e,t){var i,n,s;for(n=0,s=(i=e.className.split(" ")).length;n<s;n++)if(i[n]===t)return!0;return!1},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){var t,i,n,s;if(null==this)throw new TypeError;if(0==(i=(s=Object(this)).length>>>0))return-1;if(n=0,arguments.length>0&&((n=Number(arguments[1]))!=n?n=0:0!==n&&1/0!==n&&-1/0!==n&&(n=(n>0||-1)*Math.floor(Math.abs(n)))),n>=i)return-1;for(t=n>=0?n:Math.max(i-Math.abs(n),0);t<i;){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 i;return null==this.subs&&(this.subs={}),null==(i=this.subs)[e]&&(i[e]=[]),this.subs[e].push(t),this},t.prototype.trigger=function(){var t,i,n,s,o,r;if(i=arguments[0],t=2<=arguments.length?e.call(arguments,1):[],null!=(null!=(o=this.subs)?o[i]:void 0))for(n=0,s=(r=this.subs[i]).length;n<s;n++)r[n].apply(this,t);return this},t}(),s.Widget=function(e){function n(e,i){this.element=e,this.options=null!=i?i:{},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 i(n,e),n.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},n.prototype.addService=function(e,t,i){var n;return null==i&&(i={}),this.services.push(n=new s.Service(this,e,t,i)),n},n.prototype.disable=function(){return this.enabled=!1,this.icon&&s.addClass(this.icon,this.options.hidden_icon_class),this.output.innerHTML="",this},n.prototype.enable=function(){return this.enabled=!0,this.icon&&s.removeClass(this.icon,this.options.hidden_icon_class),this},n.prototype.destroy=function(){document.body.removeChild(this.output),this.element.removeAttribute("autocomplete"),this.icon&&(document.body.removeChild(this.icon),window.removeEventListener("resize",this._resetIconPosition))},n.prototype._applyDefaults=function(){var e,t,i,n;for(e in i=[],t=this.defaults)n=t[e],null==this.getOption(e)?i.push(this.setOption(e,n)):i.push(void 0);return i},n.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)},n.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)},n.prototype._onFocus=function(e){return this.focused=!0},n.prototype._onKeyPress=function(e){var t,i,n;if(i=e.which||e.keyCode,this.visible&&13===i)return null!=(n=this.highlighted)&&n.selectItem(),(t=this.getOption("ignore_returns"))&&e.preventDefault?e.preventDefault():t&&(e.returnValue=!1),this.highlighted=null},n.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()}},n.prototype._onBlur=function(e){if(!this.mouseDownOnSelect)return this.focused=!1,this._hideResults()},n.prototype._onPaste=function(e){return this._getSuggestionsWithTimeout()},n.prototype._moveHighlight=function(e){var t,i,n,s;return t=null!=this.highlighted?this.results.indexOf(this.highlighted):-1,null!=(n=this.highlighted)&&n.unhighlight(),(t+=e)<-1?t=this.results.length-1:t>=this.results.length&&(t=-1),null!=(s=this.results[t])&&s.highlight(),i=void 0!==this._val?this._val:"",this.element.value=null!=this.highlighted?this.highlighted.value:i},n.prototype._getSuggestionsWithTimeout=function(){return null!=this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout(function(e){return function(){return e._getSuggestions()}}(this),this.options.timeout)},n.prototype._getSuggestions=function(){var e,t,i,n,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(n=[],e=0,t=(i=this.services).length;e<t;e++)s=i[e],n.push(s.search(this._val));return n}return this._hideResults()}},n.prototype._applyStyle=function(e,t){return this.output.style[e]=t},n.prototype._getVerticalOffset=function(){return window.pageYOffset||document.documentElement&&document.documentElement.scrollTop},n.prototype._getPosition=function(){var e;return e=this.element,{top:this._getVerticalOffset()+e.getBoundingClientRect().top+e.offsetHeight,left:e.getBoundingClientRect().left}},n.prototype._hideResults=function(){var e,t,i,n,s;for(this.visible=!1,this._applyStyle("display","none"),this.results=[],n=[],e=0,t=(i=this.services).length;e<t;e++)s=i[e],n.push(s.results=[]);return n},n.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")},n.prototype._renderItem=function(e,t){var i;return(i=document.createElement("li")).innerHTML=e,null!=t&&(i.className=t),s.addDomEvent(i,"mousedown",function(e){return function(){return e.mouseDownOnSelect=!0}}(this)),s.addDomEvent(i,"mouseup",function(e){return function(){return e.mouseDownOnSelect=!1}}(this)),i},n.prototype._renderFooter=function(){return this._renderItem(this.options.footer_content,this.options.footer_class)},n.prototype._renderEmpty=function(){return this._renderItem(this.options.empty_content,this.options.empty_class)},n.prototype._servicesReady=function(){var e,t,i,n,s;for(s=[],e=0,t=(i=this.services).length;e<t;e++)n=i[e],s.push(n.ready());return s.indexOf(!1)<0},n.prototype.showResults=function(){var e,t,i,n,s,o,r,a,l;if(this._servicesReady()){for(this.searchQueued&&(this._getSuggestions(),this.searchQueued=!1),this.results=[],this.output.innerHTML="",t=0,n=(o=this.services).length;t<n;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),i=0,s=(r=this.results).length;i<s;i++)a=r[i],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")}},n.prototype.selectHighlighted=function(){this.element.value=this.highlighted.value,this._hideResults(),this.trigger("result:select",this.highlighted.value,this.highlighted.data),this._dispatchDOMChangeEvent()},n.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)},n.prototype.setIcon=function(e,t){var i,n,o;return this.removeIcon(e),n=e.class||"nc_icon",i=document.createElement("a"),s.addClass(i,n),o=this._calculateIconPosition(),i.style.top=o.coords.top+"px",i.style.left=o.coords.left+"px",i.style.height=o.size+"px",i.style.width=o.size+"px",i.addEventListener("click",t),this._resetIconPosition=this.setIcon.bind(this,e,t),window.addEventListener("resize",this._resetIconPosition),this.options.container.appendChild(i),this.icon=i},n.prototype.removeIcon=function(e){return this.icon&&(this.icon.parentNode.removeChild(this.icon),window.removeEventListener("resize",this._resetIconPosition)),this.icon=null},n.prototype._calculateIconPosition=function(){var e,t,i,n;return n=this.element.offsetWidth,e=(t=this.element.offsetHeight/2)/2.4,{coords:{top:(i=this._getPosition()).top-t-e,left:i.left+n-t-e},size:t}},n.prototype.setInfoPanel=function(e,t){var i,n;return i=(t=t||{}).class||"af_info_panel",!1===t.persistant?(this.output.innerHTML="",n=this._renderItem(e,i),t.cancellable&&this._addCancelButton(n,t),this.output.appendChild(n),this._displayResults()):(this.infoPanel={},this.infoPanel.content=e,this.infoPanel.options=t)},n.prototype._addCancelButton=function(e,t){var i,n,o;return i=(o=navigator.userAgent).indexOf("MSIE ")>-1||o.indexOf("Trident/")>-1,n=document.createElement("span"),s.addClass(n,"cancel_button"),i&&s.addClass(n,"IE"),n.addEventListener("click",function(){return this.output.innerHTML="",t.cancelHandler()}.bind(this)),e.appendChild(n)},n}(s.Dispatch),s.Service=function(e){function n(e,i,n,s){this.widget=e,this.name=i,this.search_fn=n,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,i){return e._response.apply(e,arguments)}}(this)}return i(n,e),n.prototype.ready=function(){return this._ready},n.prototype.search=function(e){return this.last_query=e,this._ready=!1,this.search_fn(e,this.response)},n.prototype._response=function(e,t){var i,n,o;if(this.results=[],this.last_query===e){for(this.results=[],n=0,o=t.length;n<o;n++)i=t[n],this.results.push(new s._Result(this,i));return this._ready=!0,this.widget.showResults()}},n}(s.Dispatch),s._Result=function(){function e(e,t){var i,n,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!=(i=this.options)?i.value:void 0,this.score=(null!=(n=this.options)?n.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,i){"undefined"!=typeof module&&module.exports?module.exports=i():"function"==typeof define&&define.amd?define(i):t.reqwest=i()}(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,i){return function(){return e._aborted?i(e.request):e._timedOut?i(e.request,"Request is aborted: timeout"):void(e.request&&4==e.request[readyState]&&(e.request.onreadystatechange=noop,succeed(e)?t(e.request):i(e.request)))}}function setHeaders(e,t){var i,n=t.headers||{};n.Accept=n.Accept||defaultHeaders.accept[t.type]||defaultHeaders.accept["*"];var s="undefined"!=typeof FormData&&t.data instanceof FormData;for(i in!t.crossOrigin&&!n[requestedWith]&&(n[requestedWith]=defaultHeaders.requestedWith),!n[contentType]&&!s&&(n[contentType]=t.contentType||defaultHeaders.contentType),n)n.hasOwnProperty(i)&&"setRequestHeader"in e&&e.setRequestHeader(i,n[i])}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,i,n){var s=uniqid++,o=e.jsonpCallback||"callback",r=e.jsonpCallbackName||reqwest.getcallbackPrefix(s),a=new RegExp("((^|\\?|&)"+o+")=([^&]+)"),l=n.match(a),d=doc.createElement("script"),u=0,c=-1!==navigator.userAgent.indexOf("MSIE 10.0");return l?"?"===l[3]?n=n.replace(a,"$1="+r):r=l[3]:n=urlappend(n,o+"="+r),context[r]=generalCallback,d.type="text/javascript",d.src=n,d.async=!0,void 0!==d.onreadystatechange&&!c&&(d.htmlFor=d.id="_reqwest_"+s),d.onload=d.onreadystatechange=function(){if(d[readyState]&&"complete"!==d[readyState]&&"loaded"!==d[readyState]||u)return!1;d.onload=d.onreadystatechange=null,d.onclick&&d.onclick(),t(lastValue),lastValue=void 0,head.removeChild(d),u=1},head.appendChild(d),{abort:function(){d.onload=d.onreadystatechange=null,i({},"Request is aborted: timeout",{}),lastValue=void 0,head.removeChild(d),u=1}}}function getRequest(e,t){var i,n=this.o,s=(n.method||"GET").toUpperCase(),o="string"==typeof n?n:n.url,r=!1!==n.processData&&n.data&&"string"!=typeof n.data?reqwest.toQueryString(n.data):n.data||null,a=!1;return("jsonp"==n.type||"GET"==s)&&r&&(o=urlappend(o,r),r=null),"jsonp"==n.type?handleJsonp(n,e,t,o):((i=n.xhr&&n.xhr(n)||xhr(n)).open(s,o,!1!==n.async),setHeaders(i,n),setCredentials(i,n),context[xDomainRequest]&&i instanceof context[xDomainRequest]?(i.onload=e,i.onerror=t,i.onprogress=function(){},a=!0):i.onreadystatechange=handleReadyState(this,e,t),n.before&&n.before(i),a?setTimeout((function(){i.send(r)}),200):i.send(r),i)}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,i){for(e=self.request,self._responseArgs.resp=e,self._responseArgs.msg=t,self._responseArgs.t=i,self._erred=!0;self._errorHandlers.length>0;)self._errorHandlers.shift()(e,t,i);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 i,n,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)||(i=/checkbox/i.test(e.type),n=/radio/i.test(e.type),s=e.value,(!i&&!n||e.checked)&&t(r,normalize(i&&""===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,i=this,n=function(e,t){var n,s,o;for(n=0;n<t.length;n++)for(o=e[byTag](t[n]),s=0;s<o.length;s++)serial(o[s],i)};for(t=0;t<arguments.length;t++)/input|select|textarea/i.test((e=arguments[t]).tagName)&&serial(e,i),n(e,["input","select","textarea"])}function serializeQueryString(){return reqwest.toQueryString(reqwest.serializeArray.apply(null,arguments))}function serializeHash(){var e={};return eachFormElement.apply((function(t,i){t in e?(e[t]&&!isArray(e[t])&&(e[t]=[e[t]]),e[t].push(i)):e[t]=i}),arguments),e}function buildParams(e,t,i,n){var s,o,r,a=/\[\]$/;if(isArray(t))for(o=0;t&&o<t.length;o++)r=t[o],i||a.test(e)?n(e,r):buildParams(e+"["+("object"==typeof r?o:"")+"]",r,i,n);else if(t&&"[object Object]"===t.toString())for(s in t)buildParams(e+"["+s+"]",t[s],i,n);else n(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,i){e.push({name:t,value:i})}),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 i,n,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(n=0;e&&n<e.length;n++)a(e[n].name,e[n].value);else for(i in e)e.hasOwnProperty(i)&&buildParams(i,e[i],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 i=this;i.urlBase="https://api.addy.co.nz/",i.searchSuffix="",i.requestSuffix="",i.fields=t||{},i.mode="address",i.options=addySettingsFactory.createOptions(),i.key=addySettingsFactory.getKey();var n=addySettingsFactory.createGuid(),s=e.placeholder;i.makeRequest=function(e,t,s,o){reqwest({url:i.urlBase+e+"?key="+i.key+i.requestSuffix+"&v=neat_2_2_0&session="+n+t,crossOrigin:!0,success:function(e){s&&s(e)},error:function(e){o&&o(e)}})},i.searchRequest=function(e,t,n){i.makeRequest(e,t,(function(e){n(e),i.service.endSearch()}),(function(e){i.widget&&(i.widget.error_content='"Request Failed:\n'+(e.message||e),i.service.endSearch())}))},i.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:i.options.maxItems,timeout:50});var o=null;i.service=i.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"===i.mode?i.searchRequest("search",i.searchSuffix+"&s="+e,(function(i){var n=new Array;if(i)for(var s=0;s<i.addresses.length;s++)n.push({value:i.addresses[s].a,data:i.addresses[s]});t(e,n)})):i.searchRequest("postcode","&max="+i.getMaxResults()+"&s="+e,(function(i){var n=new Array;if(i)for(var s=0;s<i.postcodes.length;s++){var o=i.postcodes[s];n.push({value:o.suburb+(""===o.suburb?"":", ")+o.city+(""===o.city?"":", ")+o.postcode,data:o})}t(e,n)}))}),{renderer:function(e,t){var n=i.widget.getOption("highlight_class");return null===o?e:e.replace(o,'<span class="'+(void 0===n?"nc_highlight":n)+'">$1</span>')}}),i.service.timer=null,i.service.endSearch=function(){this.timer&&clearTimeout(this.timer),this._ready=!0},i.service.search=function(e){if(!(e.length<3))return i.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)},i.setOption=function(e,t){e&&"exclude_postbox"===e?i.options.excludePostBox=t:i.widget.setOption(e,t),r()},i.setExcludeRural=function(e){i.options.exRural=e,r()},i.setExcludePostbox=function(e){i.options.excludePostBox=e,r()},i.setExcludeUndeliverable=function(e){i.options.exUndeliver=e,r()},i.setExcludeSpelling=function(e){i.options.exSpelling=e,r()},i.setExcludeWordRemoval=function(e){i.options.exWord=e,r()},i.setExcludeIpOrder=function(e){i.options.exIp=e,r()},i.setExcludePostcodes=function(e){i.options.exPostcodes=Array.isArray(e)?e.join("-"):e,r()},i.setIncludePostcodes=function(e){i.options.inPostcode=Array.isArray(e)?e.join("-"):e,r()},i.setExcludeRegions=function(e){i.options.exRegion=Array.isArray(e)?e.join("-"):e,r()},i.setIncludeRegions=function(e){i.options.inRegion=Array.isArray(e)?e.join("-"):e,r()},i.setExcludeTerritories=function(e){i.options.exTerritory=Array.isArray(e)?e.join("-"):e,r()},i.setIncludeTerritories=function(e){i.options.inTerritory=Array.isArray(e)?e.join("-"):e,r()},i.setTag=function(e){i.options.tag=e,r()},i.setUniqueId=function(e){i.options.uniqueId=e,r()},i.getOption=function(e){return i.widget.getOption(e)},i.getMaxResults=function(){return i.widget.getOption("max_results")},i.enableLocation=function(){i.options.enableLocation=!0},i.disableLocation=function(){i.options.enableLocation=!1},i.enable=function(){i.widget.enable()},i.disable=function(){i.widget.disable()},i.setPostcodeMode=function(e){i.mode="postcode",i.setOption("empty_content","Postcode not found. Please verify the spelling.")},i._onLocationResultsEmpty=function(e){var t=i.widget.getOption("empty_content");i.options.enableLocation=!1,i.setOption("empty_content",e),setTimeout((function(){i.setOption("empty_content",t)}),2e3)},i.handleLocationError=function(t){i.makeRequest("errorlog","&message=GeoFailCode:"+t.code+":"+t.message,(function(e){})),i._onLocationResultsEmpty(i.getOption("location_unavailable")),i.service._response(i.service.last_query,[]),e.placeholder=s},i.reverseGeocode=function(t){i.makeRequest("geocode","&x="+t.coords.longitude+"&y="+t.coords.latitude+"&limit="+i.getMaxResults(),function(t){var n=new Array;if(t)for(var o=0;o<t.addresses.length;o++)n.push({value:t.addresses[o].displayname,data:t.addresses[o]});0===n.length&&i._onLocationResultsEmpty(i.getOption("location_not_found")),e.placeholder=s,i.service._response(i.service.last_query,n)}.bind(this))},i.addressSelected=function(e){},i.postcodeSelected=function(e){},i.assignAddressFields=function(e){i.fields.address&&(i.fields.address.value=e.displayline),i.fields.suburb&&(i.fields.suburb.value=""===e.suburb?""===e.mailtown?e.city:e.mailtown:e.suburb),i.fields.city&&(i.fields.city.value=""===e.mailtown?e.city:e.mailtown),i.fields.territory&&(i.fields.territory.value=e.territory),i.fields.x&&(i.fields.x.value=e.x),i.fields.y&&(i.fields.y.value=e.y),i.fields.dpid&&(i.fields.dpid.value=e.dpid),i.fields.id&&(i.fields.id.value=e.id),i.fields.postcode&&(i.fields.postcode.value=e.postcode),i.fields.line1&&(i.fields.line1.value=e.address1),i.fields.line2&&(i.fields.line2.value=e.address2),i.fields.line3&&(i.fields.line3.value=e.address3),i.fields.line4&&(i.fields.line4.value=e.address4),i.fields.city||!i.fields.suburb||""!==e.suburb||""===e.city&&""===e.mailtown||(i.fields.suburb.value=""===e.mailtown?e.city:e.mailtown),i.fields.address1&&i.fields.address2?(e.address4||0===e.address2.indexOf("RD ")?(i.fields.address1.value=e.address1,i.fields.address2.value=e.address2):(i.fields.address1.value=e.displayline,i.fields.address2.value=""),!i.fields.suburb&&e.suburb&&""!==e.suburb&&(""!==i.fields.address2.value&&(i.fields.address1.value+=", "+i.fields.address2.value),i.fields.address2.value=e.suburb)):i.fields.address1&&!i.fields.address2&&(i.fields.address1.value=e.displayline)},i.assignRegion=function(e){var t=i.fields.region;if(t)if(t.options){e.region=e.region.toUpperCase();for(var n=[e.region,e.region.replace("'",""),e.region.replace("-"," - "),e.region.replace("-"," / "),e.region.replace("-","/")],s=0;s<t.options.length;s++)if(n.indexOf(t.options[s].text.toUpperCase())>-1||n.indexOf(t.options[s].value.toUpperCase())>-1){t.selectedIndex=s;break}}else t.value=e.region},i.loadAddress=function(e){i.makeRequest("address/"+e,"",function(e){e&&(i.assignAddressFields(e),i.assignRegion(e),i.addressSelected(e))}.bind(this))},i.loadLocation=function(){e.value="",e.placeholder=i.getOption("location_loading"),navigator.geolocation.getCurrentPosition(i.reverseGeocode,i.handleLocationError)},i.widget.on("result:select",(function(e,t){"address"===i.mode?"location"===t.id?i.loadLocation():i.loadAddress(t.id):i.postcodeSelected(t)})),i.checkDemo=function(){return!(!i.key||"demo-api-key"!==i.key.toLowerCase()||(i.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))},i.checkDemo(),r(),i.makeRequest("searchwarmup","")}function r(){i.searchSuffix="&max="+i.getMaxResults(),i.options.excludePostBox&&(i.searchSuffix+="&expostbox=true"),i.options.exUndeliver&&(i.searchSuffix+="&exundeliver=true"),i.options.exRural&&(i.searchSuffix+="&exrural=true"),i.options.exSpelling&&(i.searchSuffix+="&exspelling=true"),i.options.exWord&&(i.searchSuffix+="&exword=true"),i.options.exIp&&(i.searchSuffix+="&exip=true"),i.options.exPostcodes&&""!==i.options.exPostcodes&&(i.searchSuffix+="&expostcode="+i.options.exPostcodes),i.options.inPostcode&&""!==i.options.inPostcode&&(i.searchSuffix+="&inpostcode="+i.options.inPostcode),i.options.exRegion&&""!==i.options.exRegion&&(i.searchSuffix+="&exregion="+i.options.exRegion),i.options.inRegion&&""!==i.options.inRegion&&(i.searchSuffix+="&inregion="+i.options.inRegion),i.options.exTerritory&&""!==i.options.exTerritory&&(i.searchSuffix+="&exterritory="+i.options.exTerritory),i.options.inTerritory&&""!==i.options.inTerritory&&(i.searchSuffix+="&interritory="+i.options.inTerritory),i.requestSuffix="",i.options.tag&&""!==i.options.tag&&(i.requestSuffix+="&tag="+i.options.tag),i.options.uniqueId&&""!==i.options.uniqueId&&(i.requestSuffix+="&uniqueid="+i.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 i=0;i<e.length;i++){var n=t(e[i]+"line1");null!==n&&new AddyComplete(n,{address1:n,address2:t(e[i]+"line2"),suburb:t(e[i]+"suburb"),city:t(e[i]+"city"),region:t(e[i]+"region"),territory:t(e[i]+"territory"),postcode:t(e[i]+"postcode"),dpid:t(e[i]+"dpid"),id:t(e[i]+"id"),x:t(e[i]+"x"),y:t(e[i]+"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 i=document.createElement("link");i.setAttribute("rel","stylesheet"),i.setAttribute("type","text/css"),i.setAttribute("href","https://www.addy.co.nz/css/addy.css"),document.getElementsByTagName("head")[0].appendChild(i)}}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 i=getElementByIdVariations(t,"address_1");if(i){var n=new AddyComplete(i);n.fields={address1:i,address2:getElementByIdVariations(t,"address_2"),suburb:getElementByIdVariations(t,"suburb"),city:getElementByIdVariations(t,"city"),postcode:getElementByIdVariations(t,"postcode")},e[t]=n,n.key=window.addyConfig.key;var s=window.addyConfig;n.setExcludePostbox(s.hidePostCode&&"yes"===s.hidePostCode),n.setExcludeRural(s.hideRural&&"yes"===s.hideRural),n.setExcludeUndeliverable(s.hideUndeliver&&"yes"===s.hideUndeliver),s.enableLocation&&"yes"===s.enableLocation&&n.enableLocation(),s.filterPostcodes&&""!==s.filterPostcodes&&n.setIncludePostcodes(s.filterPostcodes),s.filterRegions&&""!==s.filterRegions&&n.setIncludeRegions(s.filterRegions),s.notFound&&""!==s.notFound&&n.setOption("empty_content",s.notFound),n.widget._getPosition=function(){const e=i.getBoundingClientRect(),t={top:e.top+window.scrollY,left:e.left+window.scrollX};return t.top+=i.offsetHeight,t},n.checkDemo(),n.customRegion=getElementByIdVariations(t,"state"),n.addressSelected=function(e){if(this.customRegion&&this.customRegion.options&&""!==e.region){var t="";for(let i=0;i<this.customRegion.options.length;i++){const n=this.customRegion.options[i];if(n.text===e.region||n.value===e.region){t=n.value;break}}""!==t&&(this.customRegion.value=t)}var i=n.widget.element.id.startsWith("billing"),s={first_name:a(i,e.first_name||r("#billing_first_name","#billing-first_name"),r("#billing_first_name","#billing-first_name")),last_name:a(i,e.last_name||r("#billing_last_name","#billing-last_name"),r("#billing_last_name","#billing-last_name")),company:a(i,e.company||r("#billing_company","#billing-company"),r("#billing_company","#billing-company")),address_1:a(i,e.displayline||r("#billing_address_1","#billing-address_1"),r("#billing_address_1","#billing-address_1")),address_2:a(i,e.address2||r("#billing_address_2","#billing-address_2"),r("#billing_address_2","#billing-address_2")),city:a(i,e.city||r("#billing_city","#billing-city"),r("#billing_city","#billing-city")),state:a(i,e.state||r("#billing_state","#billing-state"),r("#billing_state","#billing-state")),postcode:a(i,e.postcode||r("#billing_postcode","#billing-postcode"),r("#billing_postcode","#billing-postcode")),country:a(i,e.country||r("#billing_country","#billing-country")||"NZ",r("#billing_country","#billing-country")||"NZ"),email:a(i,e.email||r("#billing_email","#billing-email"),r("#billing_email","#billing-email")),phone:a(i,e.phone||r("#billing_phone","#billing-phone"),r("#billing_phone","#billing-phone"))},o=n.widget.element.id.startsWith("shipping"),u={first_name:a(o,e.first_name||r("#shipping_first_name","#shipping-first_name"),r("#shipping_first_name","#shipping-first_name")),last_name:a(o,e.last_name||r("#shipping_last_name","#shipping-last_name"),r("#shipping_last_name","#shipping-last_name")),company:a(o,e.company||r("#shipping_company","#shipping-company"),r("#shipping_company","#shipping-company")),address_1:a(o,e.displayline||r("#shipping_address_1","#shipping-address_1"),r("#shipping_address_1","#shipping-address_1")),address_2:a(o,e.address2||r("#shipping_address_2","#shipping-address_2"),r("#shipping_address_2","#shipping-address_2")),city:a(o,e.city||r("#shipping_city","#shipping-city"),r("#shipping_city","#shipping-city")),state:a(o,e.state||r("#shipping_state","#shipping-state"),r("#shipping_state","#shipping-state")),postcode:a(o,e.postcode||r("#shipping_postcode","#shipping-postcode"),r("#shipping_postcode","#shipping-postcode")),country:a(o,e.country||r("#shipping_country","#shipping-country")||"NZ",r("#shipping_country","#shipping-country")||"NZ"),phone:a(o,e.phone||r("#shipping_phone","#shipping-phone"),r("#shipping_phone","#shipping-phone"))};i&&(l("#billing_address_1","#billing-address_1",s.address_1),l("#billing_address_2","#billing-address_2",s.address_2),l("#billing_city","#billing-city",s.city),l("#billing_postcode","#billing-postcode",s.postcode)),this.customRegion&&(this.customRegion.value=i?s.state:u.state);jQuery(n.fields.address1).closest("form");if(i&&(d("#billing_address_1","#billing-address_1"),d("#billing_address_2","#billing-address_2"),d("#billing_city","#billing-city"),d("#billing_postcode","#billing-postcode")),o&&(d("#shipping_address_1","#shipping-address_1"),d("#shipping_address_2","#shipping-address_2"),d("#shipping_city","#shipping-city"),d("#shipping_postcode","#shipping-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 c={billing_address:s,shipping_address:u};wp.apiFetch({path:"/wc/store/v1/cart/update-customer",method:"POST",data:c,headers:{"X-WP-Nonce":window.wpApiSettings&&window.wpApiSettings.nonce||""}}).then((function(e){e.billing_address.first_name||(e.billing_address=s),e.shipping_address.first_name||(e.shipping_address=u),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,i){return e?t:i}function l(e,t,i){jQuery(e).length>0&&jQuery(e).val(i),jQuery(t).length>0&&jQuery(t).val(i)}function d(e,t){let i=document.querySelector(e)||document.querySelector(t);var n;i&&("function"==typeof Event?(n=new Event("input",{bubbles:!0}),i.dispatchEvent(n),n=new Event("change",{bubbles:!0}),i.dispatchEvent(n)):((n=document.createEvent("Event")).initEvent("input",!0,!0),i.dispatchEvent(n),(n=document.createEvent("Event")).initEvent("change",!0,!0),i.dispatchEvent(n)))}}}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 i=getElementByIdVariations(t,e);i&&(i.setAttribute("autocomplete","off"),i.addEventListener("change",(()=>{const e=i.closest("div");e&&i.value&&!e.classList.contains("is-active")&&e.classList.add("is-active")})))}))})),void initAddy()}setTimeout((function(){initAddyDomLoad(e-1)}),1e3)}else initAddy()}function loadAddyWidget(e){let t=getElementByIdVariations(e,"address_1");t&&"1"!==t.dataset.addyInitialised&&(t.dataset.addyInitialised="1",initAddy())}function observeCheckoutRerenders(){var e=document.querySelector(".wp-block-woocommerce-checkout")||document.querySelector(".wc-block-checkout");e&&new MutationObserver((function(e){var t=getElementByIdVariations("billing","address_1");t&&"1"!==t.dataset.addyInitialised&&loadAddyWidget("billing")})).observe(e,{childList:!0,subtree:!0})}jQuery(document).ready((function(){initAddyDomLoad(6),observeCheckoutRerenders()})),document.addEventListener("DOMContentLoaded",(function(){}));