Skip to content

Instantly share code, notes, and snippets.

@x3388638
Created May 21, 2019 02:37
Show Gist options
  • Save x3388638/297b7eecbde0ff75b4e9e965601228b5 to your computer and use it in GitHub Desktop.
Save x3388638/297b7eecbde0ff75b4e9e965601228b5 to your computer and use it in GitHub Desktop.
(function(){Array.prototype.forEach||(Array.prototype.forEach=function(e,t){var s,i;if(null==this)throw new TypeError(" this is null or not defined");var a=Object(this),n=a.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(arguments.length>1&&(s=t),i=0;n>i;){var o;i in a&&(o=a[i],e.call(s,o,i,a)),i++}}),Array.prototype.filter||(Array.prototype.filter=function(e){"use strict";if(void 0===this||null===this)throw new TypeError;var t=Object(this),s=t.length>>>0;if("function"!=typeof e)throw new TypeError;for(var i=[],a=arguments.length>=2?arguments[1]:void 0,n=0;s>n;n++)if(n in t){var o=t[n];e.call(a,o,n,t)&&i.push(o)}return i}),Array.prototype.map||(Array.prototype.map=function(e,t){var s,i,a;if(null==this)throw new TypeError(" this is null or not defined");var n=Object(this),o=n.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(arguments.length>1&&(s=t),i=new Array(o),a=0;o>a;){var r,c;a in n&&(r=n[a],c=e.call(s,r,a,n),i[a]=c),a++}return i}),String.prototype.includes||(String.prototype.includes=function(e,t){"use strict";return"number"!=typeof t&&(t=0),t+e.length>this.length?!1:-1!==this.indexOf(e,t)});var assistJS=function(e,t){function s(e){function t(){}return t.prototype=e,new t}function i(e,t){e.prototype=Object.create?Object.create(t.prototype):s(t.prototype),e.prototype.constructor=e}function a(e,t){for(var s in t)"object"==typeof t[s]&&"object"==typeof e[s]?a(e[s],t[s]):e[s]=t[s]}function n(e,t){var s=[];for(var i in t)t.hasOwnProperty(i)&&s.push(encodeURIComponent(i)+"="+encodeURIComponent(t[i]));return s.length>0&&(e=e+(-1===e.indexOf("?")?"?":"&")+s.join("&")),e}function o(e){c(e),l(e)}function r(e){return"function"==typeof e.trim?e.trim():e.replace(/^\s+|\s+$/gm,"")}function c(e){if(T&&9>T&&"undefined"!=typeof e.createTextRange){var t=e.createTextRange();t.collapse(!1),t.select()}else"number"==typeof e.selectionStart&&(e.selectionStart=e.selectionEnd=e.value.length)}function l(e){"focus"in e&&e.focus()}function h(e,t,s){if(T&&9>T&&"undefined"!=typeof e.createTextRange){var i=e.createTextRange();i.moveStart("character",t),i.moveEnd("character",s),i.select()}else e.selectionStart=t,e.selectionEnd=s,l(e)}function u(e){return e.replace(/[\u00A0-\u9999<>\&]/gim,function(e){return"&#"+e.charCodeAt(0)+";"})}function g(e,t,s,i){if(i||(i=!1),e.addEventListener)e.addEventListener(t,s,i);else{if(!e.attachEvent)return!1;e.attachEvent("on"+t,s)}}function d(e,t,s){if(e.removeEventListener)e.removeEventListener(t,s);else{if(!e.detachEvent)return!1;e.detachEvent("on"+t,s)}}function p(s,i,a){var n;"function"==typeof e.CustomEvent?(n=new e.CustomEvent(i,{detail:a}),s.dispatchEvent(n)):"function"==typeof t.createEvent?(n=t.createEvent("CustomEvent"),n.initCustomEvent(i,!1,!1,a),s.dispatchEvent(n)):document.documentElement[i]=a}function f(e){e.returnValue=!1,e.cancelBubble=!0,e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation()}function m(){return Math.round((new Date).getTime()/1e3)}function y(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\\\$&")}function b(e){return function(t,s,i){return s&&!/\s/.test(i)?t:e.replace(/\{s\}/g,i)}}function w(e,t,s,i){var a,n=i.pattern?i.pattern:"",o=n+"(&[^;\\s]*)?(%needles)";return a=i.exact?[y(s)]:s.split(/[\s|,]+/).filter(function(e){return""!==e}).sort(function(e,t){return t.length-e.length}).map(function(e){return y(e)}),a.length?(o=o.replace("%needles",a.join("|")),t=t.replace(new RegExp(o,"gi"),b(e))):t}function v(){this.config={}}function x(){this.itemList=[],this.selectedItem=!1}function V(e){this.saView=e,this.currentStatus=!1,this.callBackIdx=0,this.cbTable={},this.triggered=!1}function C(e,t){this.saModel=e,this.saView=t}function E(){this.config={searchBoxId:"yschsp",clearButtonId:"sbq-clear",fr2:"sa-gp-search",saBase:"//search.yahoo.com/sugg/gossip/gossip-us-ura/",ylcParam:{_r:2,gprid:"",n_rslt:0,n_sugg:0,pos:0,pqstr:"",pqstrl:0},gossipParam:{l:1,bm:3,output:"sd1",appid:"search.yahoo.com",nresults:10},max:255,clrLog:{},boldTag:"<b></b>",annotation:{},cssClass:{container:"sa-sbx-container",trayContainer:"sa lowlight",tray:"sa-tray",traySub:"sa-tray sub-assist no-wrap",ul:"sa-tray-list-container",liHighlight:"list-item-hover",li:"",span:"",text:"",aria:"sa-aria-live-region",actionContainer:"sa-fd-actn-cont",relatedSearches:"related-title",trendingNow:"trending-title"},text:{relatedSearches:"Related Searches",trendingNow:"Trending Now",ariaShown:"new suggestions shown",ariaClosed:"Suggestion box closed"},customEvent:!1,suppressEmptyQuery:!1,enableAnnotation:!1,enableIpos:!0,subAssist:!0,subTrayDelta:5,trayPadding:12,debug:!1,objectName:"SA",anykey:!1,clearBeaconing:!1,enableYlc:!0,autofocus:!1,highlight:{pattern:"",exact:!1},minQueryLength:0,enableTabRender:!0}}var T=function(){if("Microsoft Internet Explorer"===e.navigator.appName){var t=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})").exec(e.navigator.userAgent);return t&&t[1]&&parseFloat(t[1])}return!1}();return e.YAHOO=e.YAHOO||{},v.prototype={set:function(e,t,s){e.setAttribute(t,s)},get:function(e,t){return e.getAttribute(t)},merge:a,extend:i,buildUrl:n,stopPropagation:f,setFocus:o,cursorEnd:c,select:h,htmlEncode:u,ae:g,de:d,ts:m,bold:w,debug:function(t){this.config.debug&&e.console&&e.console.log&&e.console.log(t)}},i(x,v),x.prototype.init=function(s,i){var a=this;if(this.saModel=i,this.config=s,this.clearButton=this.clearButton||t.getElementById(this.config.clearButtonId),this.searchbox=this.searchbox||t.getElementById(this.config.searchBoxId),!this.searchbox)return!1;this.config.gossipParam.pq=this.searchbox.value;for(var n=this.searchbox;n&&!this.formTag;)n.tagName&&"form"===n.tagName.toLowerCase()&&(this.formTag=n),n=n.parentNode;return this.formTag?(this.container=t.createElement("div"),this.container.className=this.config.cssClass.container,this.trayContainer=t.createElement("div"),this.trayContainer.className=this.config.cssClass.trayContainer,this.container.appendChild(this.trayContainer),this.searchbox.parentNode.insertBefore(this.container,this.searchbox.nextSibling),this.searchbox.setAttribute("role","combobox"),this.searchbox.setAttribute("aria-autocomplete","both"),this.ae(e,"load",function(){a.aria=t.createElement("div"),a.aria.className=a.config.cssClass.aria,a.set(a.aria,"aria-live","polite"),a.aria.style.position="absolute",a.aria.style.left="-9999px",t.body.appendChild(a.aria)}),!0):!1},x.prototype.getWidth=function(e,s){var i,a={p:e,t:this.config.boldTag.replace("",this.htmlEncode(e)),idx:0},n=t.createElement("div");n.className=this.config.cssClass.container;var o=t.createElement("div");o.className=this.config.cssClass.trayContainer,n.appendChild(o);var r=t.createElement("div");r.className=this.config.cssClass.traySub,r.style.left="-9999px",o.appendChild(r);var c=t.createElement("ul");c.className=this.config.cssClass.ul,r.appendChild(c);var l=this.createItem(a);s&&(i=t.createElement("span"),i.innerHTML=s,l.suggestionSpan.appendChild(i)),c.appendChild(l.li),this.searchbox.parentNode.insertBefore(n,this.searchbox.nextSibling);var h=l.suggestionSpan.clientWidth+this.config.subTrayDelta;return n.outerHTML="",h},x.prototype.display=function(e){var s=e.data,i=e.sqpos,a=e.hiddenNeedle,n=this,o={};this.hide(),this.selectedItem=!1,this.tray=t.createElement("div"),this.set(this.tray,"type","normal"),this.tray.className=this.config.cssClass.tray,i&&this.config.subAssist&&(this.tray.className=this.config.cssClass.traySub,this.tray.style.left=this.getWidth(a)+"px"),this.ul=t.createElement("ul"),this.ul.className=this.config.cssClass.ul,this.set(this.ul,"role","listbox"),this.tray.appendChild(this.ul),this.itemList=[],this.config.ylcParam.n_sugg=n.saModel.ylc.n_sugg,s.forEach(function(e){var s;if(e.idx=n.itemList.length,4===e.m&&n.config.text.trendingNow&&!o.trending){var a=t.createElement("span");a.className=n.config.cssClass.trendingNow,a.innerHTML=n.config.text.trendingNow,n.ul.appendChild(a),o.trending=!0}var r=n.createItem(e);!i&&n.config.enableAnnotation&&e.m&&n.config.annotation[e.m]&&e.fd&&(s=n.getItemAnnotation(e,r.suggestionSpan),s&&r.suggestionSpan.appendChild(s)),n.ul.appendChild(r.li),n.itemList.push(r.li),n.ae(r.li,"mouseenter",function(t){n.resetHighlight(),r.li.className=n.config.cssClass.li+" "+n.config.cssClass.liHighlight,n.selectedItem=e.idx}),n.ae(r.li,"mouseleave",function(e){r.li.className=n.config.cssClass.li}),n.ae(r.li,"click",function(t){var s=n.searchbox.value,i=t.target||t.srcElement;n.saModel.ylc.pos=e.idx+1,n.saModel.ylc.pqstr=s,n.saModel.ylc.pqstrl=s.length,n.saModel.ylc.use_case="",n.formTag.fr2&&(n.formTag.fr2.value=n.config.fr2),n.searchbox.value=e.p,i.tagName&&"a"===i.tagName.toLowerCase()&&(n.searchbox.value=n.get(i,"data"),n.saModel.ylc.use_case=i.innerHTML),n.hide(),n.saModel.addYlc(n.saModel.clickTarget),n.config.customEvent?(n.saModel.addYlk(i),p(n.searchbox,"assistSelection",{data:e})):n.suggestionClick(t,e)})}),this.aria&&(this.set(this.aria,"aria-expanded","true"),this.aria.innerHTML="<p>"+n.itemList.length+" "+this.config.text.ariaShown+"</p>"),this.show()},x.prototype.suggestionClick=function(e,t){this.formTag.submit()},x.prototype.show=function(){this.shown=!0,this.resetHighlight(),this.trayContainer.appendChild(this.tray)},x.prototype.hide=function(){this.aria&&(this.set(this.aria,"aria-expanded","false"),this.aria.innerHTML="<p>"+this.config.text.ariaClosed+"</p>"),this.shown=!1,this.resetHighlight(),this.trayContainer.innerHTML=""},x.prototype.resetHighlight=function(){this.selectedItem!==!1&&this.itemList.length&&(this.itemList[this.selectedItem].className=this.config.cssClass.li)},x.prototype.resetHightlight=x.prototype.resetHighlight,x.prototype.tab=function(){if(!this.shown||!this.itemList.length)return!1;if(this.selectedItem!==!1)this.searchbox.value=this.get(this.itemList[this.selectedItem],"data"),this.saModel.fetch();else{if(this.searchbox.value===this.get(this.itemList[0],"data"))return this.saModel.unset(),!1;this.searchbox.value=this.get(this.itemList[0],"data"),this.saModel.fetch()}return!0},x.prototype.moveUpDown=function(e){return this.shown&&this.itemList.length?(this.resetHighlight(),e?this.selectedItem===!1||this.selectedItem<=0?this.selectedItem=this.itemList.length-1:this.selectedItem--:this.selectedItem===!1||this.selectedItem>=this.itemList.length-1?this.selectedItem=0:this.selectedItem++,this.itemList[this.selectedItem].className=this.config.cssClass.li+" "+this.config.cssClass.liHighlight,this.searchbox.value=this.get(this.itemList[this.selectedItem],"data"),!0):!1},x.prototype.createItem=function(e){var s=t.createElement("li"),i=this;if(s.className=this.config.cssClass.li,this.set(s,"pos",e.idx),this.set(s,"role","option"),this.config.formatResult){var a=this.config.ylcVal;a&&(a=a.replace("cposV",e.idx),i.config.ylcParam&&(a=a.replace("t9Val",i.config.ylcParam.n_sugg)),this.set(s,"data-ylk",a)),this.set(s,"data-position",e.idx)}i.set(s,"data",e.p);var n=t.createElement("span");n.className=i.config.cssClass.span,n.style.display="block",s.appendChild(n);var o=t.createElement("span");return o.className=i.config.cssClass.text,o.innerHTML=e.t,n.appendChild(o),{li:s,suggestionSpan:n}},x.prototype.getItemAnnotation=function(e){var s,i,a,n=this.config.annotation[e.m]||{},o=this.config.cssClass,r=e.fd,c="",l="",h=this.searchbox.clientWidth-2*this.config.trayPadding,u=0;if(n.subtitle&&r.subtitle){if(l=n.subtitle.replace("",this.htmlEncode(r.subtitle)),u=this.getWidth(e.p,l),!(h>u))return s;c+=l}if(n.actions&&r.actions&&r.actions.length){for(l="",a=0;a<r.actions.length;a++)if(i=r.actions[a],l&&n.actionsSeparator&&(l+=n.actionsSeparator),l+=n.actions.replace("",this.htmlEncode(i.text)).replace("",this.htmlEncode(i.res)),u=this.getWidth(e.p,c+'<span class="'+o.actionContainer+'">'+l+"</span>"),u>h){l="";break}l&&(c+='<span class="'+o.actionContainer+'">'+l+"</span>")}return c&&(s=t.createElement("span"),s.innerHTML=c),s},i(V,v),V.prototype.unset=function(){this.triggered=!1,this.saView.hide()},V.prototype.jsonp=function(e,s){var i={command:this.saView.searchbox.value,t_stmp:this.ts(),callback:"YAHOO."+this.config.objectName+".cb."+e};this.merge(i,this.config.gossipParam),s&&this.merge(i,s);var a=this.buildUrl(this.config.saBase,i),n=t.getElementsByTagName("head")[0],o=t.createElement("script");this.set(o,"type","text/javascript"),this.set(o,"src",a),n.appendChild(o),this.ae(o,"load",function(){n.removeChild(o)})},V.prototype.read=function(e){var t,s=this,i=[],a=e.sqpos,n=e.q=e.q||"",o="";e&&"object"==typeof e.r&&e.r.length>0?(s.config.subAssist&&a&&(n=e.q.substr(a),o=e.q.substr(0,a),e.r.forEach(function(t){var i=s.saView.getWidth(t.k);i>s.saView.searchbox.clientWidth&&(a=0,n=e.q,o="")})),e.r.forEach(function(e){t=s.config.subAssist&&a?e.k.substr(a):e.k,i.push({p:e.k,t:s.bold(s.config.boldTag,s.htmlEncode(t),s.htmlEncode(n),s.config.highlight),fd:e.fd,m:e.m})}),this.ylc.n_sugg=e.r.length,this.ylc.pos=0,this.saView.display({data:i,sqpos:a,hiddenNeedle:o})):(this.ylc.n_sugg=0,this.ylc.pos=0,this.saView.hide()),e&&e.l&&(this.ylc.gprid=e.l.gprid)},V.prototype.fetch=function(){var e,t=this.saView.searchbox,s=this,i=null,a=s.lastValue===s.saView.searchbox.value;if(s.config.suppressEmptyQuery&&""==r(t.value))return s.unset(),!0;if(s.saView.shown&&a)return!0;if(this.config.enableIpos&&!a&&"undefined"!=typeof s.lastValue&&(e=this.getCursorPosition(),e===t.value.length&&(e=null),null!==e&&(i={ipos:e})),s.lastValue=s.saView.searchbox.value,this.config.minQueryLength&&this.saView.searchbox.value.length<this.config.minQueryLength)return this.unset(),!1;if(this.config.max&&this.saView.searchbox.value.length>this.config.max)return this.unset(),!0;this.triggered=!0,this.callBackIdx++;var n="sacb"+this.callBackIdx;for(var o in s.cbTable)s.cbTable.hasOwnProperty(o)&&(s.cbTable[o]=function(){});this.cbTable[n]=function(e){s.read(e||{}),s.cbTable[n]=function(){}},this.jsonp(n,i)},V.prototype.getCursorPosition=function(){var e,s=this.saView.searchbox,i=null;return"number"==typeof s.selectionStart?i=s.selectionStart:t.selection&&(s.focus(),e=t.selection.createRange(),e.moveStart("character",-t.activeElement.value.length),i=e.text.length),i},V.prototype.addYlc=function(e){var t=encodeURIComponent(this.saView.searchbox.value);return this.ylc.query=t,this.ylc.qstrl=t.length,this.ylc.t_stmp=this.ts(),this.config.enableYlc&&this.ULT?void(this.saView.formTag.action=this.ULT.y64_token("ylc",e,this.ylc)):void this.debug("YLC logging is disabled")},V.prototype.addYlk=function(e){var t=this,s=["gprid","query","pqstr"],i=[];if(s.forEach(function(e){t.ylc[e]&&i.push(e+":"+t.ylc[e])}),t.config.ylcVal=t.config.ylcVal+";"+i.join(";"),e){var a=t.get(e,"data-ylk")+";"+i.join(";");t.set(e,"data-ylk",a)}},V.prototype.init=function(t){return this.config=t,this.ULT=e.YAHOO.ULT,this.ULT||(this.debug("ULT library is missing. Disabling ylc logging"),this.config.enableYlc=!1),this.ylc={},this.merge(this.ylc,this.config.ylcParam),this.clickTarget=this.config.clkLink?this.config.clkLink:this.saView.formTag.action,this.submitTarget=this.saView.formTag.action,!0},i(C,v),C.prototype.init=function(s){var i=this;i.lastValue=null,this.config=s,this.config.autofocus&&this.setFocus(this.saView.searchbox),!T||T>=9?this.ae(this.saView.searchbox,"input",function(e){i.saModel.fetch()}):8===T&&this.ae(this.saView.searchbox,"propertychange",function(e){"value"===e.propertyName&&i.saView.selectedItem===!1&&i.saModel.fetch()}),i.config.anykey&&this.ae(t,"keydown",function(e){var s=t.activeElement;if(!s.tagName||"input"!==s.tagName.toLowerCase()&&"textarea"!==s.tagName.toLowerCase())return 27===e.keyCode&&!i.saView.shown&&i.saView.searchbox.value.length?(i.select(i.saView.searchbox,0,i.saView.searchbox.value.length),void i.stopPropagation(e)):void(e.keyCode<=40||e.ctrlKey||e.metaKey||(i.saView.searchbox.value=r(i.saView.searchbox.value),""!==i.saView.searchbox.value&&(i.saView.searchbox.value+=" "),i.saModel.triggered=!0,i.setFocus(i.saView.searchbox)))}),this.ae(this.saView.searchbox,"keydown",function(e){switch(e.keyCode){case 40:i.saView.moveUpDown(!1),i.stopPropagation(e);break;case 38:i.saView.moveUpDown(!0),i.stopPropagation(e);break;case 27:if(!i.saView.shown)return;return i.cursorEnd(i.saView.searchbox),i.saView.searchbox.blur(),i.saModel.unset(),i.saView.resetHighlight(),i.saView.selectedItem=!1,i.stopPropagation(e),!1;case 9:if(i.saView.searchbox.selectionEnd==i.saView.searchbox.value.length&&i.saView.searchbox.selectionStart==i.saView.searchbox.value.length){if(!i.config.enableTabRender)return i.saModel.unset(),!1;if(i.saView.tab())return i.stopPropagation(e),!1}else i.saView.searchbox.selectionEnd=i.saView.searchbox.selectionStart=i.saView.searchbox.value.length,i.stopPropagation(e);break;case 39:i.saView.searchbox.selectionEnd==i.saView.searchbox.value.length&&i.saView.searchbox.selectionStart==i.saView.searchbox.value.length&&i.saView.tab();break;default:i.saView.resetHighlight(),i.saView.selectedItem=!1}});var a=function(e){if(T&&8>=T&&t.selection){var s,a,n=i.saView.searchbox,o=n.value.replace(/\r\n/g,"\n"),r=t.selection.createRange(),c=n.value.length,l=n.createTextRange();l.moveToBookmark(r.getBookmark());var h=n.createTextRange();h.collapse(!1),l.compareEndPoints("StartToEnd",h)>-1?s=a=c:(s=-l.moveStart("character",-c),s+=o.slice(0,s).split("\n").length-1,l.compareEndPoints("EndToEnd",h)>-1?a=c:(a=-l.moveEnd("character",-c),a+=o.slice(0,a).split("\n").length-1)),n.selectionStart=s,n.selectionEnd=a}i.lastValue!==i.saView.searchbox.value&&i.saView.selectedItem===!1&&i.saModel.fetch()};this.ae(this.saView.searchbox,"focus",function(e){!i.saModel.triggered&&i.saModel.fetch(),T&&9===T&&!i.ie9_attached&&(i.ae(t,"selectionchange",a),i.ie9_attached=!0)}),this.ae(this.saView.searchbox,"blur",function(e){T&&9===T&&i.ie9_attached&&(i.de(t,"selectionchange",a),i.ie9_attached=!1)}),this.ae(this.saView.searchbox,"click",function(e){!i.saModel.triggered&&i.saModel.fetch()});var n=function(e){if(i.saView.shown){for(var t=e.target?e.target:e.srcElement;t;){if(t===i.saView.formTag)return;t=t.parentNode}i.config.touchOriented&&i.stopPropagation(e),i.saModel.unset()}};return"ontouchstart"in e?(this.config.touchOriented=!0,this.ae(t.body,"touchstart",n,!0)):this.ae(t,"click",n),this.ae(this.saView.formTag,"submit",function(e){i.saModel.addYlc(i.saModel.submitTarget)}),this.saView.clearButton&&this.ae(this.saView.clearButton,"click",function(e){if(i.saView.searchbox.value="",i.saModel.triggered=!1,i.setFocus(i.saView.searchbox),i.config.enableYlc&&i.config.clearBeaconing&&i.saModel.ULT){var t={_r:2,actn:"clk",pos:1,sec:"clearsearch",slk:"clear",t1:"hdr",t2:"searchbox",t3:"clear"};i.merge(t,i.config.clrLog),i.saModel.ULT.beacon_click(t)}}),!0},i(E,v),E.prototype.saModelClass=V,E.prototype.saViewClass=x,E.prototype.saControlClass=C,E.prototype.init=function(s){return T&&8>T?!1:("object"==typeof s&&this.merge(this.config,s),this.saView=new this.saViewClass,this.saModel=new this.saModelClass(this.saView),this.saControl=new this.saControlClass(this.saModel,this.saView),this.cb=this.saModel.cbTable,this.config.customEvent&&8===T&&(t.documentElement.assistSelection=null),this.ready=this.saView.init(this.config,this.saModel)&&this.saModel.init(this.config)&&this.saControl.init(this.config),this.ready?(e.YAHOO[this.config.objectName]=this,void(e.performance&&"function"==typeof e.performance.now&&(this.latency=e.performance.now()))):!1)},E};"undefined"!=typeof module&&(module.exports={assistJS:assistJS}),"undefined"!=typeof window&&(window.YAHOO=window.YAHOO||{},window.YAHOO.SAClass=assistJS(window,document));var init=function(e){window.YAHOO&&window.YAHOO.SAClass&&(window.YAHOO.SA=new window.YAHOO.SAClass,window.YAHOO.SA.init(e))}; init({boldTag:"<b>\{s\}</b>",cssClass:{container:"assistjs-tray yui3-aclist ua-ie9_Pos(r)",trayContainer:"",tray:"yui3-aclist-content",ul:"yui3-aclist-list",li:"yui3-aclist-item",liHighlight:"yui3-aclist-item-hover"},enableTabRender:!1,gossipParam:{appid:"fp"},customEvent:!0,searchBoxId:"uh-search-box",highlight:{pattern:"^",exact:!0},saBase:"//uk.search.yahoo.com/sugg/gossip/gossip-uk-ura/",subAssist:!1,minQueryLength:1,formatResult:!0,fr2:"",ylcVal:"cpos:cposV;elm:itm;elmt:srch;itc:0;rspns:nav;sec:srch;slk:srchast;tar:uk.search.yahoo.com;t1:a1;t2:srch;t3:tray;t9:t9Val"}); })();
!function(){var a=function(a){var b,c,d,e,f,g,h,i,j,k=document,l=window,m=13,n=38,o=40,p=!1,q=!1,r="-m",s="assistjs-tray",t="-s",u=/\S/,v="saready",w=l.performance,x=w&&w.now?w.now():void 0,y=a||"/_td_api/beacon/error?",z=0,A=!1,B=function(a,i){return k=a||k,l=i||l,b=k.getElementById("uh-search-form"),d=k.documentElement,!!b&&(e=b.querySelector('input[name="type"]'),f=b.querySelector('input[name="fr"]'),g=k.getElementById("uh-search-button"),h=k.getElementById("uh-search-box"),c=k.getElementsByClassName(s)[0],f?f.value=f.getAttribute("data-fr"):Z("FR INPUT not available in Search form"),e&&(e.value=e.getAttribute("data-type")),X(b,"submit",W,!1),X(h,"assistSelection",E,!1),X(h,"keyup",I,!1),X(h,"keypress",K,!1),X(g,"click",H,!1),C(w,x),void 0)},C=function(a,b){var c=a,d=b;if(c&&c.timing)try{var e=parseInt(c.timing.navigationStart,10),f=parseInt(c.timing.domLoading,10);if(d||c.timing.navigationStart&&(d=Date.now()-e),e>0&&f>0&&d){d=Math.round(d);var g=d,h=e+d-f;return j="/p.gif?beaconType="+v+"&timeFromNavigationStart="+g+"&timeFromDomLoading="+h+"&ns="+e+"&dl="+f+"&bucket=903",i=new Image,i.height=0,i.width=0,i.src=j,!0}Z("Perf API unavailable")}catch(k){return Z("Error in timestamp calculation"),!1}return!1},D=function(a,b){return a.className.split(" ").indexOf(b)>-1},E=function(a,b){a.preventDefault(),F(a,b,M,T,f)},F=function(a,b,c,d,e){if(e&&(e.value+=t),a&&a.detail&&a.detail.data&&"number"==typeof a.detail.data.idx){var f=c(a.detail.data.idx+1);if(f)return d(f,W),!0}return!1},G=function(a,b){for(var c=a.target;a.currentTarget!==c&&(c=c.parentNode,!D(c,b)););return c},H=function(a){if(a.preventDefault(),u.test(h.value)&&!p)return U(g,!1,W)||Z("onBtn click beacon not fired"),!0},I=function(a){return a.keyCode===n||a.keyCode===o?(z++,1):a.keyCode!==m?(z=0,0):-1},J=function(a){var b;return!(z<=0)&&(!(!c||!(b=c.querySelector('li[data="'+a.searchValue+'"]')))&&(a.pos=b.getAttribute("data-position"),"number"==typeof a.pos&&a.pos++,!0))},K=function(a){var b,c=a.target.value,d=l.rapidInstance,e={elm:"kb-ent"},i={};return a.keyCode===m&&c&&(a.preventDefault(),p=!0,i.searchValue=c,J(i)&&(f&&(f.value+=t),e.elm="itm",e.slk="srchast",e.t3="tray",b=L(),b&&(e.t9=b.n_sugg),e.cpos=parseInt(i.pos,10)+1),U(g,e,W)||Z("Enter key Beacon not fired")),!q&&a.keyCode!==m&&d&&d.beaconEvent&&(d.beaconEvent("keybrd",P(h)),q=!0),!0},L=function(a){var b,c=a||YAHOO;return c&&c.SA&&c.SA.config&&c.SA.config.ylcParam&&(b=c.SA.config.ylcParam),b},M=function(a,b){var c,d,e=b||YAHOO;if(e&&e.SA&&e.SA.config&&e.SA.config.ylcVal){var f=e.SA.config.ylcVal;c=f.replace("cposV",a)}return d=L(e),d&&(c=c.replace("t9Val",d.n_sugg)),c},N=function(a,b,c){var d={};return a?(b=b||";",c=c||":",a.split(b).forEach(function(a){if(a.length>0){var b=a.indexOf(c),e=a.substring(0,b).trim(),f=a.substring(b+1).trim();e&&(d[e]=f)}}),d):d},O=function(a,b){return a?N(a.getAttribute(b)):{}},P=function(a,b,c){var d=b?N(b):O(a,"data-ylk");d||(d={}),c&&(d=Q(d,c));var e=document.querySelector('[data-applet-type="td-applet-mega-header"][data-ylk]');return e?Q(O(e,"data-ylk"),d):d},Q=function(){for(var a={},b=0,c=arguments.length;b<c;){for(var d in arguments[b])arguments[b].hasOwnProperty(d)&&(a[d]=arguments[b][d]);b++}return a},R=function(a,b,c){return a&&a.sec?"object"==typeof b&&(b.section=a.sec,delete a.sec,b.linkName=a.slk||"",delete a.slk,b.position=parseInt(a.pos,10),"number"==typeof b.position&&isFinite(b.position)?b.position++:b.position=1,!0):(c&&c('rapid data has no "sec" data'),!1)},S=function(a,b,c,d){var e,f={},g={},h=l.rapidInstance;return f=P(a,b,d),R(f,g,Z)?(e="",h&&h.beaconClick?(h.beaconClick(g.section,g.linkName,g.position,f,e,c),!0):(Z("Rapid not available"),c&&c(),!1)):(c&&c(),!1)},T=function(a,b){return S(null,a,b)},U=function(a,b,c){return a?S(a,null,c,b):(Z('"node" not passed to triggerBeaconClickEvent'),c&&c(),!1)},V=function(){D(d,"Reader-open")&&!A&&(f&&(f.value+=r),e&&(e.value+=r),A=!0)},W=function(){var a=h.value;u.test(a)&&(A||V(),b.submit())},X=function(a,b,c,d){if(d||(d=!1),a.addEventListener)a.addEventListener(b,c,d);else{if(!a.attachEvent)return!1;a.attachEvent("on"+b,c)}},Y=function(){var a;if(l.XMLHttpRequest)try{a=new XMLHttpRequest}catch(b){a=!1}else if(l.ActiveXObject)try{a=new ActiveXObject("Msxml2.XMLHTTP")}catch(b){try{a=new ActiveXObject("Microsoft.XMLHTTP")}catch(b){a=!1}}return a},Z=function(a){var b={code:"error",src:"assistJsBeacon",name:"searchAssistBeacon",message:a},c=Y(),d="";if(c){for(var e in b)b.hasOwnProperty(e)&&(d+=e+"="+b[e]+"&");d=d.substring(0,d.length-1);var f=y+d;return c.open("GET",f,!0),c.send(null),!0}return!1};return{stringParseKV:N,hasClass:D,parseDataAttr:O,parseYLK:P,merge:Q,triggerBeaconClickEvent:U,triggerCustomEventBeaconClickEvent:T,eventHandler:X,init:B,btnClick:H,typeSearchInput:K,sendBeacon:Z,getTargetElement:G,triggerAssistSelection:F,getYLKFromSAConfig:M,getYLCFromSAModel:L,perfBeacon:C,validateAndFixupRapidData:R,arrowTracker:I}};"undefined"!=typeof module&&module.exports?module.exports=a:(new a).init()}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment