// create a test node off the browser screen to calculate high contrast mode var testNode = document.createElement("div"); testNode.className = "highContrastTestNode"; document.body.appendChild(testNode); // look at the computed style for the test node var styles = null; try { styles = document.defaultView.getComputedStyle(testNode, ""); } catch(e) { styles = testNode.currentStyle; } var testImg = styles.backgroundImage; if ((styles.borderTopColor == styles.borderRightColor) || (testImg != null && (testImg == "none" || testImg == "url(invalid-url:)" ))) { document.getElementsByTagName("body")[0].className+=" lotusImagesOff"; } document.body.removeChild(testNode);(function(){ var _1=ibmCfg.portalConfig.contentHandlerURI+((ibmCfg.portalConfig.contentHandlerURI.indexOf("?")<0)?"?":"&")+"uri=menu:${id}"; var _2=false; var _3=function(){ return i$.hasClass(document.getElementsByTagName("body")[0],"edit-mode"); }; if(typeof wptheme==="undefined"||!wptheme){ wptheme={}; } i$.mash(wptheme,{getWindowIDFromSkin:function(_4){ while((_4=_4.parentNode)!=null){ if(i$.hasClass(_4,"component-control")){ var m=_4&&(_4.className||"").match(/id-([\S]+)/); return m&&m[1]; } } return null; },getPortletState:function(_5){ var _6=i$.byId("portletState"); if(_6){ if(!_6._cache){ _6._cache=i$.fromJson(_6.innerHTML); _6._cache._defaults={"windowState":"normal","portletMode":"view"}; } if(_6._cache[_5]){ return _6._cache[_5]; }else{ return _6._cache._defaults; } } return {}; },isValidOp:function(_7){ if(_7.visibility===false){ return false; } var _8=_7.metadata||{}; switch(_7.id){ case "ibm.portal.operations.changePortletMode": return wptheme.getPortletState(_8.wid).portletMode!=_8.portletMode; case "ibm.portal.operations.changeWindowState": return wptheme.getPortletState(_8.wid).windowState!=_8.windowState; default: } return true; },operation:{changeToHelpMode:function(_9){ var _a=window.location.href; if(_9.actionUrl){ if(_9.actionUrl.indexOf("?")==0){ var _b=_a.indexOf("#"); if(_b!=-1){ var _c=_a.substring(0,_b); var _d=_a.substring(_b); _a=_c+(_c.indexOf("?")==-1?"?":"&")+_9.actionUrl.substring(1); _a+=_d; }else{ _a+=(_a.indexOf("?")==-1?"?":"&")+_9.actionUrl.substring(1); } }else{ _a=_9.actionUrl; } } window.open(_a,"","resizable=yes,scrollbars=yes,menubar=no,toolbar=no,status=no,width=800,height=600,screenX=10,screenY=10,top=10,left=10"); }},canImpersonate:function(){ return ibmCfg.portalConfig.canImpersonate; },contextMenu:{cache:{},css:{focus:"wpthemeMenuFocus",disabled:"wpthemeMenuDisabled",show:"wpthemeMenuShow",error:"wpthemeMenuError",menuTemplate:"wpthemeTemplateMenu",submenuTemplate:"wpthemeTemplateSubmenu",loadingTemplate:"wpthemeTemplateLoading"},init:function(_e,_f,_10){ _e._contextMenu=_e._contextMenu||{}; _e._contextMenu.id=_e._contextMenu.id||Math.round(Math.random()*1000000000); _e.setAttribute("id",_e._contextMenu.id); _e._contextMenu.menuId=_f; _e._contextMenu.jsonQuery=_10; var _11=_e._contextMenu; var _12=function(_13){ if(_13.displayMenu){ i$.fireEvent("wptheme/contextMenu/close/all"); if(!_11._submenu){ i$.fireEvent("wptheme/contextMenu/close/all"); wptheme.contextMenu._updateAbsolutePosition(i$.byId(_11.id)); } var _14=wptheme.contextMenu._adjustScreenPositionStart(); i$.addClass((_11.shadowNode)?_11.shadowNode:i$.byId(_11.id),wptheme.contextMenu.css.show); wptheme.contextMenu._adjustScreenPositionEnd(_14); var _15=i$.byId(_11.id)._firstSelectable; if(_15){ _15.focus(); i$.byId(_11.id)._currentSelected=_15; } i$.addListener("wptheme/contextMenu/close/all",function(){ var _16=i$.byId(_11.id); }); } }; wptheme.contextMenu._initialize(_e).then(_12,_12); _e=null; },initSubmenu:function(_17,_18,_19){ _17._contextMenu=_17._contextMenu||{}; _17._contextMenu._submenu=true; _17._contextMenu._menuitemTemplate=_19._menuitemTemplate; _17._contextMenu._subMenuTemplate=_19._subMenuTemplate; _17._contextMenu._loadingTemplate=_19._loadingTemplate; wptheme.contextMenu.init(_17,_18,_19.jsonQuery); },_findFocusNode:function(_1a){ var _1b,i,_1c; var _1d=function(_1e,_1f){ var l=_1e.childNodes.length; for(i=0;i=0;i--){ _24=_26.childNodes[i]; if(i$.hasClass(_24,wptheme.contextMenu.css.menuTemplate)){ _21=_24; continue; } if(i$.hasClass(_24,wptheme.contextMenu.css.submenuTemplate)){ _22=_24; continue; } if(i$.hasClass(_24,wptheme.contextMenu.css.loadingTemplate)){ _23=_24; continue; } if(_24.childNodes){ i=_25(_24,i); } } return _27; }; _25(_20); return {"menu":_21,"submenu":_22,"loading":_23}; },_invalidateCallback:function(){ wptheme.contextMenu.cache={}; },_initialize:function(_28){ var _29=true; var _2a=_28._contextMenu; if(wptheme.contextMenu.cache[_2a.id]||_2a._inProgress){ return i$.promise.resolved({displayMenu:_29}); } _2a._inProgress=true; i$.addListener("wptheme/contextMenu/invalidate/all",wptheme.contextMenu._invalidateCallback); var _2b,_2c,tmp=i$.createDom("div"); if(_2a._submenu){ tmp.innerHTML=_2a._subMenuTemplate.replace(/\$\{submenu-id\}/g,_2a.id+"_menu"); _28.appendChild(tmp.firstChild); _2b=i$.byId(_2a.id+"_menu"); _2c=i$.createDom("div"); _2c.innerHTML=_2a._loadingTemplate; }else{ var _2d=wptheme.contextMenu._findNodes((_2a.shadowNode)?_2a.shadowNode:_28); _2b=_2d.menu; if(!_2a._menuitemTemplate){ _2a._menuitemTemplate=i$.trim(_2b.innerHTML); } if(!_2a._loadingTemplate){ _2c=i$.createDom("div"); _2c.appendChild(_2d.loading); _2a._loadingTemplate=i$.trim(_2c.innerHTML); _2c=null; } _2c=i$.createDom("div"); _2c.innerHTML=_2a._loadingTemplate; tmp.appendChild(_2d.submenu.cloneNode(true)); if(!_2a._subMenuTemplate){ _2a._subMenuTemplate=i$.trim(tmp.innerHTML); } } while(_2b.firstChild){ _2b.removeChild(_2b.firstChild); } _2b.appendChild(_2c); var _2e; if(_2a._submenu){ _2e=_2a.shadowNode; }else{ if(_2a.shadowNode){ _2e=_2a.shadowNode; }else{ _2e=wptheme.contextMenu._transformIntoAbsolutePosition(_28); } } i$.addClass((_2e)?_2e:_28,wptheme.contextMenu.css.show); i$.bindDomEvt((_2e)?_2e:_28,"onmouseleave",function(){ if(_2a._inProgress){ _29=false; } var _2f=i$.byId(_2a.id); i$.removeClass((_2a.shadowNode)?_2a.shadowNode:_2f,wptheme.contextMenu.css.show); if(!_2a.activeAction){ var _30=_2f._currentSelected; if(_30){ _30.blur(); } var _31=wptheme.contextMenu._findFocusNode(_2f); ((_31)?_31:_2f).focus(); } }); return wptheme.contextMenu._load(_2a).then(function(_32){ var _33=wptheme.contextMenu._parseData(_32).then(function(_34){ _34=wptheme.contextMenu._filterMenu(_34); if(!_34||_34.length==0){ var tmp=i$.createDom("div"); tmp.innerHTML=wptheme.contextMenu._fromTemplate(_2a._menuitemTemplate,wptheme.contextMenu.css.error,wptheme.contextMenu.nls.NO_ITEMS_0); while(_2b.firstChild){ _2b.removeChild(_2b.firstChild); } _2b.appendChild(tmp); }else{ wptheme.contextMenu._buildMenu(_2a,_2b,_34); } _2a._inProgress=false; wptheme.contextMenu.cache[_2a.id]=true; return {displayMenu:_29}; }); return _33; },function(){ var tmp=i$.createDom("div"); tmp.innerHTML=wptheme.contextMenu._fromTemplate(_2a._menuitemTemplate,wptheme.contextMenu.css.error,wptheme.contextMenu.nls.ERROR_LOADING_0); while(_2b.firstChild){ _2b.removeChild(_2b.firstChild); } _2b.appendChild(tmp); _2a._inProgress=false; wptheme.contextMenu.cache[_2a.id]=true; return {displayMenu:_29}; }); },_load:function(_35){ var _36=_1.replace(/\$\{id\}/g,_35.menuId); if(_35.jsonQuery){ _36+=(_36.indexOf("?")==-1?"?":"&")+i$.toQuery(_35.jsonQuery); } return i$.xhrGet({url:_36,headers:{"X-IBM-XHR":"true"},responseType:"json"}).then(function(_37){ return _37.data; },function(_38){ var _39=_38.xhr.getResponseHeader("Content-Type")||""; if((_39.indexOf("text/html")==0)||(_38.xhr.status==401)){ window.setTimeout(function(){ document.location.reload(); },0); } console.log("Error trying to load the context menu feed for '"+_35.menuId+"': "+_38); return null; }); },_parseData:function(_3a){ var _3b=[]; i$.each(_3a,function(_3c){ var _3d=i$.fromPath("moduleInfo.deferred",false,_3c)?i$.modules.loadDeferred():i$.promise.resolved(true); _3b.push(_3d.then(function(){ var _3e=wptheme.contextMenu._checkFunction(_3c,_3c.visibilityFn,_3c,(typeof _3c.visibility!="undefined")?_3c.visibility:true); var _3f=wptheme.contextMenu._checkFunction(_3c,_3c.enableFn,_3c,(typeof _3c.enabled!="undefined")?_3c.enabled:true); return i$.whenAll(_3e,_3f).then(function(_40){ _3c._visible=_40[0]; _3c._enabled=_40[1]; return _3c; }); })); }); return i$.whenAll.apply(i$,_3b); },_filterMenu:function(_41){ var _42=[],_43,_44={"type":"Separator"}; for(var i=_41.length-1;i>=0;i--){ _43=_41[i]; if(!_43._visible){ continue; } if(_43.type=="Separator"){ if(_44.type=="Separator"){ continue; } }else{ if(_43.type=="Header"){ if((_44.type=="Separator")||(_44.type=="Header")){ continue; } } } _44=_43; _42.unshift(_43); } while(_42.length>0&&_42[0].type=="Separator"){ _42=_42.slice(1); } return _42; },_buildMenu:function(_45,_46,_47){ var _48=document.createDocumentFragment(),tmp=i$.createDom("div"),_49,_4a,_4b,_4c; for(var i=0,l=_47.length;i
  • "+$('#ID_pps_lbl_DetectMyDevice_ChromeStep2').val()+"
  • "+$('#ID_pps_lbl_DetectMyDevice_ChromeStep3').val()+"
  • "; } // In Microsoft internet explorer else if (!!(navigator.userAgent.match(/Trident/))||(objOffsetVersion=objAgent.indexOf("MSIE"))!=-1) { objbrowserName = "Microsoft Internet Explorer"; objfullVersion = objAgent.substring(objOffsetVersion+5); if (document.all && document.querySelector && !document.addEventListener) { document.getElementById("showContent").innerHTML=""; } else{ document.getElementById("showContent").innerHTML=""; } } // In Firefox else if ((objOffsetVersion=objAgent.indexOf("Firefox"))!=-1) { objbrowserName = "Firefox"; document.getElementById("showContent").innerHTML=""; } // In Safari else if ((objOffsetVersion=objAgent.indexOf("Safari"))!=-1) { objbrowserName = "Safari"; objfullVersion = objAgent.substring(objOffsetVersion+7); if ((objOffsetVersion=objAgent.indexOf("Version"))!=-1) objfullVersion = objAgent.substring(objOffsetVersion+8); } // For other browser "name/version" is at the end of userAgent else if ( (objOffsetName=objAgent.lastIndexOf(' ')+1) < (objOffsetVersion=objAgent.lastIndexOf('/')) ) { objbrowserName = objAgent.substring(objOffsetName,objOffsetVersion); objfullVersion = objAgent.substring(objOffsetVersion+1); if (objbrowserName.toLowerCase()==objbrowserName.toUpperCase()) { objbrowserName = navigator.appName; } } // trimming the fullVersion string at semicolon/space if present if ((ix=objfullVersion.indexOf(";"))!=-1) objfullVersion=objfullVersion.substring(0,ix); if ((ix=objfullVersion.indexOf(" "))!=-1) objfullVersion=objfullVersion.substring(0,ix); objBrMajorVersion = parseInt(''+objfullVersion,10); if (isNaN(objBrMajorVersion)) { objfullVersion = ''+parseFloat(navigator.appVersion); objBrMajorVersion = parseInt(navigator.appVersion,10); } } }); /* Global variable declaration*/ var typeAheadTimeout; // to clear Timeout var currentValue; var ajaxParam = { // to hold paramaters to send to ajax url1 : '', //for 1st IDOL call url2 : '', // for second IDOL call url : '', paramData : {} }; var countEachBind = 0; var KEY = { UP : 38, DOWN : 40, TAB : 9, ENTER : 27 }; var comingFromPFinder = false; var urlCreationFilteredData; $(document).ready(function() { typeAheadInit(); }); function checkValidity(val) { if (typeof val !== "undefined" && val != null) { return true; } return false; } /* Initialise the typeahead and attach event handlers */ function typeAheadInit() { $("input[type='text']").each(function() { if ($(this).hasClass("reqTypeAhead")) { var typeAheadObjClass = $(this).data("predectivecontainer"); handleEvents(typeAheadObjClass, $(this)); } }); } /* Event handler for keyboard and mouse events */ function handleEvents(typeAheadObjClass, reqTypeaheadBox) { // close typeahead on outside click - start - Richa $(document).click(function(e) { if (e.target.id != "search-input") { $('.predictive-results.search-predictive-results').hide(); } }); // close typeahead on outside click - end - Richa // call the typeahead function on input - insert or delete (reqTypeaheadBox).on("input", function() { callTypeAhead(reqTypeaheadBox, typeAheadObjClass); }); // call the typeahead function on input - IE8 if ($("body").hasClass("ie8")) { (reqTypeaheadBox).on("keydown", function(event) { if ((event.which != KEY.DOWN) && (event.which != KEY.UP) && (currentValue != (reqTypeaheadBox).attr("ghostText"))) { callTypeAhead(reqTypeaheadBox, typeAheadObjClass); } }); (reqTypeaheadBox).on("paste", function(event) { setTimeout(function() { callTypeAhead(reqTypeaheadBox, typeAheadObjClass) }, 1); }); jQuery(document).on("dragend",reqTypeaheadBox, function(event) { callTypeAhead(reqTypeaheadBox, typeAheadObjClass); }); } // handle arrow keys , enter, tab on typeahead box (reqTypeaheadBox).on("keydown", function(event) { if ($("." + typeAheadObjClass).length > 0) { if ((event.which != KEY.DOWN) && (event.which != KEY.UP)) { } else if ((event.which == KEY.DOWN)) { event.stopPropagation(); event.preventDefault(); $("." + typeAheadObjClass + " li a").first().focus(); $("." + typeAheadObjClass + " li a").removeClass("hover"); $("." + typeAheadObjClass + " li a").first().addClass("hover"); (reqTypeaheadBox).val($(document.activeElement).text()); // $(".typeAheadBox").val($(document.activeElement).text()); } /* else if(event.which == KEY.TAB){ var clearIcon = (reqTypeaheadBox).parents(".search-bg").find(".clear-search"); if($(clearIcon).length > 0 ){ $(clearIcon).focus(); } }*/ else if ((event.which == KEY.UP)) { event.stopPropagation(); event.preventDefault(); $("." + typeAheadObjClass + " li a").last().focus(); $("." + typeAheadObjClass + " li a").removeClass("hover"); $("." + typeAheadObjClass + " li a").last().addClass("hover"); (reqTypeaheadBox).val($(document.activeElement).text()); // $(".typeAheadBox").val($(document.activeElement).text()); } } /* else{ if(event.which == KEY.TAB){ var clearIcon = (reqTypeaheadBox).parents(".search-bg").find(".clear-search"); if($(clearIcon).length > 0 ){ $(clearIcon).focus(); } } }*/ if ((event.which == KEY.ENTER)) { event.preventDefault(); (reqTypeaheadBox).val(""); $("." + typeAheadObjClass).remove(); } }); // handle blur on typeahead box $(reqTypeaheadBox).on("blurTypeahead", function(event) { isHidePrediction(typeAheadObjClass, reqTypeaheadBox); }); $(document).on("blur","." + typeAheadObjClass + " li a", function(event) { isHidePrediction(typeAheadObjClass, reqTypeaheadBox); }); // Click on the predictive results $(document).on("click", "." + typeAheadObjClass + " li a", function(event) { (reqTypeaheadBox).val($(this).text()); // If mobile device then check the type ahead behaviour if(isMobileDevice()){ //Since this is mobile & if the key is not true then we need to stop type ahead if(typeAheadClickBehaviorMobile && typeAheadClickBehaviorMobile != "true"){ $(this).parents(".predictive-results").remove(); (reqTypeaheadBox).focus(); //Also we are force returning the event here to stop the ajax call return; } } else { //Now this is not Mobile //Checking if the in Desktop/Tablet if the type ahead behaviour is disabled. if(typeAheadClickBehaviorDesktop && typeAheadClickBehaviorDesktop != "true"){ //Since it is set to something other than true, we are stoping this action $(this).parents(".predictive-results").remove(); (reqTypeaheadBox).focus(); //Also we are force returning the event here to stop the ajax call return; } } (reqTypeaheadBox).data("productid",$(this).data("productid")); $(this).parents(".predictive-results").remove(); (reqTypeaheadBox).focus(); /* 6523 - pFinder( SWD) with typeahead functionality if it is pfinder then navigate to SWD step 2 page series = us-en/drivers/selfservice/hp-deskjet-d2600-printer-series/3742933 model = us-en/drivers/selfservice/hp-deskjet-d2600-printer-series/3742933/model/3742935 nodeDepth = 4 for SKU = 6 for product = 2 for series */ //https://g9t0144.houston.hp.com/apps/Nav?h_client=s-a-r11839-1&h_product=5436977&h_lang=en&h_cc=us&h_pagetype=s-017 var searchQuery = $("input[name='searchQuery']"); if(searchQuery && reqTypeaheadBox.hasClass("pfinder-search") && comingFromPFinder ) { var prodIdSelectedTypeahead = $(this).data("productid"); var separator = "/"; var url = document.location.origin + separator; var cCode = getCCLC("cc") ; var lCode = getCCLC("lc"); //Checking for special cc lc conditions /*if(cCode == "gb" && lCode == "en"){ cCode = "uk" ; } else{ lCode = localeConversion(cCode,lCode); } */ url += cCode + "-"; url += lCode + separator; var pageIdentifier = $('#pageIdentifier').val().toLowerCase(); var urlIdentifier = document.location.href; //adding url creation code for contact-hp /*if(pageIdentifier == "contact hp - anonymous" || urlIdentifier.indexOf("contact-hp") != -1){ url += "contact-hp/product" + separator; }*/ if(pageIdentifier == "swdselfservice" || urlIdentifier.indexOf("drivers") != -1){ url += "drivers/selfservice" + separator; // has to come from SSC - TBD } /*else if(pageIdentifier == "identifyproduct" || urlIdentifier.indexOf("products") != -1 ){ url += "product" + separator; }*/ var productIDContact; var seriesIDContact; var skuIDContact; console.log(urlCreationFilteredData); if(urlCreationFilteredData) { var title; if(urlCreationFilteredData.length >= 1) { $.each(urlCreationFilteredData, function(index, obj) { var data = urlCreationFilteredData[index]; if(data.id == prodIdSelectedTypeahead) { // looping each prod id from response json to match with prod id of clicked typeahead selection // url for series /*6594 - url creation using seofriendlyname*/ if(data.seoFriendlyName!=undefined) { title = data.seoFriendlyName; } else { title = data.seriesName; title = title.replace(/ /g,"-"); } url += title + separator; url += data.seriesId + separator; seriesIDContact = data.seriesId; if(data.classType == 3 || data.classType == 4) { url += "model" + separator; url += data.productId; productIDContact = data.productId; } if(data.classType == 4) { url += "?sku="; url += data.skuId; skuIDContact = data.skuId; } return false; } }); } else { /*6594 - url creation using seofriendlyname*/ if(urlCreationFilteredData.seoFriendlyName!=undefined) { title = urlCreationFilteredData.seoFriendlyName; } else { title = urlCreationFilteredData.seriesName; title = title.replace(/ /g,"-"); } url += title + separator; url += urlCreationFilteredData.seriesId + separator; seriesIDContact = urlCreationFilteredData.seriesId; if(urlCreationFilteredData.classType == 3 || urlCreationFilteredData.classType == 4) { url += "model" + separator; url += urlCreationFilteredData.productId; productIDContact = urlCreationFilteredData.productId; } if(urlCreationFilteredData.classType == 4) { url += "&sku="; url += urlCreationFilteredData.skuId; skuIDContact = urlCreationFilteredData.skuId; } } //adding url creation code for contact-hp //var pageIdentifier = $('#pageIdentifier').val().toLowerCase(); //var redirectHubUrl = ''; //var redirectHubUrl = "http://g9t0144.houston.hp.com/apps/Nav?h_client=s-a-r11839-1" ; var redirectHubUrl = hubNavigationBaseUrl ; if(productIDContact != undefined){ //no product oid is returned by Idol redirectHubUrl += "&h_product=" + productIDContact; } else{ redirectHubUrl += "&h_product=" + seriesIDContact; } //Checking for special cc lc conditions if(cCode == "gb" && lCode == "en"){ cCode = "uk" ; } else{ lCode = localeConversion(cCode,lCode); } redirectHubUrl += "&h_lang=" + lCode +"&h_cc=" + cCode ; if(pageIdentifier == "contact hp - anonymous" || urlIdentifier.indexOf("contact-hp")!= -1){ redirectHubUrl += "&h_pagetype=s-017"; if (skuIDContact!= undefined){ redirectHubUrl += "&sku=" + skuIDContact; } console.log(redirectHubUrl); window.location.href = redirectHubUrl; }else if(pageIdentifier == "identifyproduct" || urlIdentifier.indexOf("products") != -1 ){ redirectHubUrl += "&h_pagetype=s-001"; if (skuIDContact!= undefined){ redirectHubUrl += "&sku=" + skuIDContact; } console.log(redirectHubUrl); window.location.href = redirectHubUrl; }else{ // if url contains '/' at end, remove it var urlLastIndex = url.length - 1; if(url.charAt(urlLastIndex) == separator) { url = url.substr(0,urlLastIndex); } console.log(url); window.location.href = url; } } } else { (reqTypeaheadBox).parents("form").submit(); } }); // keyboard events on the predictive results $(document).on("keydown","." + typeAheadObjClass + " li a",function(event) { event.stopPropagation(); event.preventDefault(); if ((event.which == KEY.DOWN)) { if (!($(document.activeElement).parents("li") .is(':last-child'))) { /*3244 start: stop all handlers from being executed in DOM tree*/ event.stopImmediatePropagation(); /*3244 end*/ $(document.activeElement).parents("li").find("a").removeClass("hover"); $(document.activeElement).parents("li").next().children("a").addClass("hover"); $(document.activeElement).parents("li").next().children("a").focus(); /*For d-3589 */ $(document.activeElement).closest(".hasTypeahead").find("input.search-input").val($(document.activeElement).text()); // $(".typeAheadBox").val($(document.activeElement).text()); //(reqTypeaheadBox).val($(document.activeElement).text()); } else { $("." + typeAheadObjClass + " li a").removeClass("hover"); (reqTypeaheadBox).focus(); (reqTypeaheadBox).val(currentValue); // autocomplete(reqTypeaheadBox, // typeAheadObjClass); } } else if(event.which == KEY.TAB){ var clearIcon = (reqTypeaheadBox).parents(".search-bg").find(".clear-search"); if($(clearIcon).length > 0 ){ $(clearIcon).focus(); } $("." + typeAheadObjClass).remove(); } else if ((event.which == KEY.UP)) { if (!($(document.activeElement).parents("li") .is(':first-child'))) { /*3244 start: stop all handlers from being executed in DOM tree*/ event.stopImmediatePropagation(); /*3244 end*/ $(document.activeElement).parents("li").find("a").removeClass("hover"); $(document.activeElement).parents("li").prev().children("a").addClass("hover"); $(document.activeElement).parents("li").prev().children("a").focus(); /*For d-3589 */ $(document.activeElement).closest(".hasTypeahead").find("input.search-input").val($(document.activeElement).text()); // $(".typeAheadBox").val($(document.activeElement).text()); //(reqTypeaheadBox).val($(document.activeElement).text()); } else { $("." + typeAheadObjClass + " li a").removeClass("hover"); (reqTypeaheadBox).focus(); (reqTypeaheadBox).val(currentValue); // autocomplete(reqTypeaheadBox, // typeAheadObjClass); } } else if (event.which == 13) { $(document.activeElement).trigger("click"); } }); } function createQueryParams(val){ val = $.trim(val); if (val!='' || val!=null || val!=undefined) { var words = val.split(' '); lengthOfWordList = words.length; var text = ''; var fieldText = ''; //cn, hk, tw var cc = getCCLC('cc'); var lc = getCCLC('lc'); var addFieldTextData = false; //The "+AND+MATCH{pm_series_value,pm_name_value}:CLASS" was added for story 6921 as part of the RnD to improve the functionality of the type ahead. // This prevents the SKUs from Showing up in the type ahead. By restricting the class to "pm_series_value" & "pm_name_value". var addFieldText = 'MATCH{'+cc+',NoValue}:COUNTRY_CODE+AND+BIASVAL{pm_series_value,'+biasvalValue+'}:CLASS+AND+MATCH{pm_series_value,pm_name_value}:CLASS'; if((cc=='tw'|| cc=='hk' || cc=='cn') && lc=='zh'){ addFieldTextData = true; } // adding false to override adding field text if(false && lengthOfWordList>1){ //more than one word fieldText = words[lengthOfWordList-1]; fieldText = 'WILD{*'+ fieldText +'*}:DRETitle'; if(addFieldTextData){ fieldText = addFieldText+'+AND+'+fieldText; } words[lengthOfWordList-1] = ''; text = words.join(' '); text = $.trim(text); ajaxParam.paramData['text'] = text; ajaxParam.paramData['fieldText'] = fieldText; console.log('FieldText --->'+ fieldText); console.log('Text --->'+ text); } else{ text = val+'*'; if(addFieldTextData){ //CR13588ALM fieldText = addFieldText; ajaxParam.paramData['fieldText'] = fieldText; } else{ ajaxParam.paramData['fieldText'] = ''; } console.log("field text"); console.log(ajaxParam.paramData['fieldText']); ajaxParam.paramData['text'] = text; console.log('Text --->'+ text) } }; } // This function makes the ajax call for typeahead function autocomplete(currentInput, typeAheadObjClass) { $("." + typeAheadObjClass + "").remove(); currentValue = (currentInput).val(); ajaxParam.paramData["cc"] = getCCLC("cc"); ajaxParam.paramData["lc"] = getCCLC("lc"); ajaxParam.paramData["searchContext"] = $( "#search-dropdown .search-category").val() != "" ? $( "#search-dropdown .search-category").val() : "All Support"; var modifiedCurrentValue = currentValue.replace("&","&"); //replace & with & for IDOL to understand //create query params including static params createQueryParams(currentValue); var requestJson = JSON.stringify(ajaxParam.paramData); var successHandlerParams = { 'currentValue':modifiedCurrentValue, 'currentInput':currentInput, 'typeAheadObjClass':typeAheadObjClass }; abortAjaxUtil(); // abort called to abort any previous typeahead ajax call //callAjaxUtil('typeahead',ajaxParam.url,'POST',getMatch,'JSON',requestJson,successHandlerParams,ajaxFailureHandler); //Updated Ajax call to Call IDOL directly: //Create the url here //ajaxParam.url = ajaxParam.url1.replace("QueryPlaceholder",modifiedCurrentValue); var idolUTF8Lc = $('#idolUTF8Lc').val(); //base URL from portal var url1 = ajaxParam.url1; ajaxParam.url = url1; if(ajaxParam.paramData['text']!=null){ ajaxParam.url += '&text='+ajaxParam.paramData['text']; } if(ajaxParam.paramData['fieldText']!=null && ajaxParam.paramData['fieldText']!=''){ ajaxParam.url += '&fieldtext='+ajaxParam.paramData['fieldText']; } // Make the call here callAjaxUtil('typeahead',ajaxParam.url,'POST',recallIdol,'JSON',null,successHandlerParams,ajaxFailureHandler); //callAjaxUtil('typeahead',ajaxParam.url,'GET',nonIdolTypeAhead,'JSON',null,successHandlerParams,ajaxFailureHandler); $(currentInput).parent(".hasTypeahead").find(".searching").show(); } /*This function takes the IDOL JSON response and makes sense out of it.*/ var RELEVANCE_DIFF = 10; //to be externalized var TYPEAHEAD_MAX_LIMIT = 8; //to be externalized /** * This method is used when hp-core-service is utilized * for type ahead in search. * This method populates type ahead. * * @since R3.0 * @author arka.sinha@hp.com */ var nonIdolTypeAhead = function(data,successHandlerParams){ var extractedData = []; for (var i=0; i 0){ createList(extractedData, extractedData.length, successHandlerParams.currentInput, successHandlerParams.currentValue, successHandlerParams.typeAheadObjClass); } } var recallIdol = function(data,successHandlerParams){ var totalResults; var responseDataJSON = data.autnresponse.responsedata.$; if(typeof(responseDataJSON)=='object'){ responseDataJSON = responseDataJSON.join(); } responseDataJSON = $.parseJSON(responseDataJSON); /* responseDataJSON = data; */ if(!(responseDataJSON.autnresponse.responsedata["autn:numhits"] == undefined)){ // if IDOL response is not error totalResults = responseDataJSON.autnresponse.responsedata["autn:numhits"].$; } else{ totalResults = 0; } var modifiedCurrentValue = successHandlerParams.currentValue; var words = modifiedCurrentValue.split(' '); var lengthOfWordList = words.length; if (totalResults == 0 && lengthOfWordList>1) { // if there are no results //createQueryParams var fieldtext = ""; var addFieldText = 'MATCH{'+cc+',NoValue}:COUNTRY_CODE'; if((cc=='tw'|| cc=='hk' || cc=='cn') && lc=='zh'){ fieldtext = "&fieldtext="+addFieldText; } ajaxParam.url = ajaxParam.url1+'&text='+modifiedCurrentValue+fieldtext; //commenting to cancel the second call to IDOL //callAjaxUtil('typeahead',ajaxParam.url,'POST',callTypeAheadResultConstructor,'JSON',null,successHandlerParams,ajaxFailureHandler); } else { callTypeAheadResultConstructor(data,successHandlerParams); } } var callTypeAheadResultConstructor = function(rawData, successHandlerParams){ new typeAheadResultConstructor(rawData,successHandlerParams).filter(); } var typeAheadResultConstructor = function(rawData, successHandlerParams) { var rawData = rawData; var relevantDataIntrim = []; var urlCreationTempData = []; //6523 - will store respoonse data to be used for url creation var relevantData = { "topic": { "suggestions": [] }, "product": { "suggestions": [] } }; var totalResults; var responseDataJSON = rawData.autnresponse.responsedata.$; if(typeof(responseDataJSON)=='object'){ responseDataJSON = responseDataJSON.join(); } responseDataJSON = $.parseJSON(responseDataJSON); /* responseDataJSON = rawData; */ if(!(responseDataJSON.autnresponse.responsedata["autn:numhits"] == undefined)){ // if IDOL response is not error totalResults = responseDataJSON.autnresponse.responsedata["autn:numhits"].$; } else{ totalResults = 0; } var lowestNodeDepth = 0; var lowestNodeDepthCount = 0; var maxWeightage = 0.0; var typeaheadResultCounter = 0; var calcNodeDepth = function(clazzType, navPathValue){ switch(clazzType){ case "category_navigation": return 1; case "pm_series_value": return 2; case "pm_name_value": return 3; case "pm_number_value": return 4; default: return 5; } } this.filter = function() { //initialise array to store child node paths (array or arrays) us-6523 var childNodeParentArray=[]; if (totalResults == 0) { // if there are no results getMatch(relevantData,successHandlerParams); } else { rawData = responseDataJSON; //Initialize this function by creating an array of the relevant data from the raw data set by using the filtering logic by VKS var isMultipleResult = (rawData.autnresponse.responsedata["autn:hit"] != undefined && rawData.autnresponse.responsedata["autn:hit"].length == undefined) ? false : true; if (isMultipleResult) { //if there are multiple results, autn:hit would be an array otherwise a single object $.each(rawData.autnresponse.responsedata["autn:hit"], function(index, obj) { var tempData = {}; var tempDataforURL = {}; var elemNavPathValue = ((this["autn:content"].DOCUMENT.SHORTESTNAVIGATIONPATH.$).split('|').length) - 2; //having a -2 as an empty string is created after the last '|' var elemClazzType = this["autn:content"].DOCUMENT.CLASS.$; var shortestNavPathLength = calcNodeDepth(elemClazzType, elemNavPathValue); //store child nodes if present only us-6523 //if(this["autn:content"].DOCUMENT.CHILDNODES.hasOwnProperty("$")) //{ // var childArray=this["autn:content"].DOCUMENT.CHILDNODES.$.split('|'); // childNodeParentArray.push(childArray); // } var weightage = this["autn:weight"].$; var nodeDepth = shortestNavPathLength; tempData["title"] = this["autn:content"].DOCUMENT.DRETITLE.$; tempData["nodeDepth"] = nodeDepth; tempData["weightage"] = weightage; tempData["product"] = (checkValidity(this["autn:content"].DOCUMENT.PRODUCTID.$)) ? this["autn:content"].DOCUMENT.PRODUCTID.$ : ""; if (maxWeightage == 0.0) { maxWeightage = weightage; relevantDataIntrim.push(tempData); lowestNodeDepth = nodeDepth; if(this["autn:content"].DOCUMENT.CHILDNODES.hasOwnProperty("$")) { var childArray=this["autn:content"].DOCUMENT.CHILDNODES.$.split('|'); childNodeParentArray.push(childArray); } } else if ((maxWeightage - weightage) < RELEVANCE_DIFF) { if (nodeDepth <= lowestNodeDepth) { relevantDataIntrim.push(tempData); lowestNodeDepth = nodeDepth; } else if (nodeDepth - lowestNodeDepth == 1) { relevantDataIntrim.push(tempData); } if(this["autn:content"].DOCUMENT.CHILDNODES.hasOwnProperty("$")) { var childArray=this["autn:content"].DOCUMENT.CHILDNODES.$.split('|'); childNodeParentArray.push(childArray); } } /*6523 - in case of pfinder, storing results for forming URL of drivers page (on click of typeahead results)*/ tempDataforURL["seriesName"] = tempData["title"]; tempDataforURL["classType"] = shortestNavPathLength; /*6594 - url creation using seofriendlyname */ if(this["autn:content"].DOCUMENT.SEO_FRIENDLY_NAME == undefined){ tempDataforURL["seoFriendlyName"] = "null"; //If no seoFriendlyName is found, use null } else{ tempDataforURL["seoFriendlyName"] = this["autn:content"].DOCUMENT.SEO_FRIENDLY_NAME.$; } if(shortestNavPathLength == 2) { tempDataforURL["seriesId"] = tempData["product"]; tempDataforURL["id"] = tempData["product"]; } else if(shortestNavPathLength == 3) { tempDataforURL["productId"] = tempData["product"]; tempDataforURL["id"] = tempDataforURL["productId"]; var seriesId = this["autn:content"].DOCUMENT.SHORTESTNAVIGATIONPATH.$; seriesId = (checkValidity(seriesId)) ? seriesId.split("|") : ""; seriesId == "" ? "" : (seriesId = seriesId[seriesId.length-3]); tempDataforURL["seriesId"] = seriesId; } else if(shortestNavPathLength == 4) { tempDataforURL["skuId"] = tempData["title"]; tempDataforURL["productId"] = tempData["product"]; tempDataforURL["id"] = tempDataforURL["productId"]; var seriesId = this["autn:content"].DOCUMENT.SHORTESTNAVIGATIONPATH.$; seriesId = (checkValidity(seriesId)) ? seriesId.split("|") : ""; seriesId == "" ? "" : (seriesId = seriesId[seriesId.length-4]); tempDataforURL["seriesId"] = seriesId; var productId = this["autn:content"].DOCUMENT.SHORTESTNAVIGATIONPATH.$; productId = (checkValidity(seriesId)) ? productId.split("|") : ""; productId == "" ? "" : (productId = productId[productId.length-3]); tempDataforURL["productId"] = productId; } urlCreationTempData.push(tempDataforURL); /* 6523 - in case of pfinder, storing results for forming URL of drivers page (on click of typeahead results - End */ }); } else { var tempData = {}; var tempDataforURL = {}; var elemNavPathValue = ((rawData.autnresponse.responsedata["autn:hit"]["autn:content"].DOCUMENT.SHORTESTNAVIGATIONPATH.$).split('|').length) - 2; //having a -2 as an empty string is created after the last '|' var elemClazzType = rawData.autnresponse.responsedata["autn:hit"]["autn:content"].DOCUMENT.CLASS.$; var shortestNavPathLength = calcNodeDepth(elemClazzType, elemNavPathValue) var weightage = rawData.autnresponse.responsedata["autn:hit"]["autn:weight"].$; tempData["title"] = rawData.autnresponse.responsedata["autn:hit"]["autn:content"].DOCUMENT.DRETITLE.$; tempData["nodeDepth"] = shortestNavPathLength; tempData["weightage"] = weightage; tempData["product"]= (checkValidity(rawData.autnresponse.responsedata["autn:hit"]["autn:content"].DOCUMENT.PRODUCTID.$)) ? rawData.autnresponse.responsedata["autn:hit"]["autn:content"].DOCUMENT.PRODUCTID.$ : "" ; lowestNodeDepth = shortestNavPathLength; relevantDataIntrim.push(tempData); tempDataforURL["seriesName"] = tempData["title"]; tempDataforURL["classType"] = shortestNavPathLength; /*6594 - url creation using seofriendlyname*/ tempDataforURL["seoFriendlyName"] = rawData.autnresponse.responsedata["autn:hit"]["autn:content"].DOCUMENT.SEO_FRIENDLY_NAME.$; if(shortestNavPathLength == 2) { tempDataforURL["seriesId"] = tempData["product"]; } else if(shortestNavPathLength == 3) { tempDataforURL["productId"] = tempData["product"]; var seriesId = rawData.autnresponse.responsedata["autn:hit"]["autn:content"].DOCUMENT.SHORTESTNAVIGATIONPATH.$; seriesId = (checkValidity(seriesId)) ? seriesId.split("|") : ""; seriesId == "" ? "" : (seriesId = seriesId[seriesId.length-3]); tempDataforURL["seriesId"] = seriesId; tempDataforURL["id"] = tempDataforURL["productId"]; } else if(shortestNavPathLength == 4) { tempDataforURL["skuId"] = tempData["title"]; tempDataforURL["productId"] = tempData["product"]; tempDataforURL["id"] = tempDataforURL["productId"]; var seriesId = rawData.autnresponse.responsedata["autn:hit"]["autn:content"].DOCUMENT.SHORTESTNAVIGATIONPATH.$; seriesId = (checkValidity(seriesId)) ? seriesId.split("|") : ""; seriesId == "" ? "" : (seriesId = seriesId[seriesId.length-4]); tempDataforURL["seriesId"] = seriesId; var productId = rawData.autnresponse.responsedata["autn:hit"]["autn:content"].DOCUMENT.SHORTESTNAVIGATIONPATH.$; productId = (checkValidity(seriesId)) ? productId.split("|") : ""; productId == "" ? "" : (productId = productId[productId.length-3]); tempDataforURL["productId"] = productId; } urlCreationTempData.push(tempDataforURL); } urlCreationFilteredData = urlCreationTempData; $.each(relevantDataIntrim, function(index, obj) { //filter relevantDataIntrim object user story 6523 var isChildItem = false; // check whether the product is child item from childnode array for(var i=0;i < childNodeParentArray.length;i++) { if(childNodeParentArray[i].indexOf(this["product"]) > -1) { isChildItem = true; break; } } ///if this item is a child item den discard if(isChildItem) { return true; } ////// end 6523 if (typeaheadResultCounter < TYPEAHEAD_MAX_LIMIT) { if(this["nodeDepth"] == lowestNodeDepth){ lowestNodeDepthCount++; typeaheadResultCounter++; var tempData = {}; tempData["label"] = this["title"]; tempData["productId"] = this["product"]; relevantData.product.suggestions.push(tempData); } else if( this["nodeDepth"]== lowestNodeDepth+1 && lowestNodeDepthCount==1){ typeaheadResultCounter++; var tempData = {}; tempData["label"] = this["title"]; tempData["productId"] = this["product"]; relevantData.product.suggestions.push(tempData); } else{ //do nothing } } else { return false; } }); getMatch(relevantData,successHandlerParams); } } } /*End*/ // Failure handler for ajax call function ajaxFailureHandler(){ $(".hasTypeahead .searching").hide(); } // Get the matched results for products and topics function getMatch(jsonData, paramObj) { // jsonData = jQuery.parseJSON(jsonData); var currentValue = paramObj.currentValue; var currentInput = paramObj.currentInput; var typeAheadObjClass = paramObj.typeAheadObjClass; $(".hasTypeahead .searching").hide(); var jsonProdLen = jsonData.product.suggestions.length; var jsonTopicLen = jsonData.topic.suggestions.length; var jsonTotalLength = jsonProdLen + jsonTopicLen; var jsonObj = new Array(); var j = 0; for (var i = 0; i < jsonProdLen; i++) { if ((currentValue != "")) { var tempData = {}; tempData["label"] = jsonData.product.suggestions[i].label; tempData["productId"] = jsonData.product.suggestions[i].productId; jsonObj[j] = tempData; j++; } } for (var i = 0; i < jsonTopicLen; i++) { if ((currentValue != "")) { var tempData = {}; tempData["label"] = jsonData.topic.suggestions[i].label; tempData["productId"] = (jsonData.topic.suggestions[i].productId); jsonObj[j] = tempData; j++; } } createList(jsonObj, jsonProdLen, currentInput, currentValue, typeAheadObjClass); } // This creates the DOM for the predictive results and append it function createList(jsonObj, jsonProdLen, currentInput, currentValue,typeAheadObjClass) { (currentInput).siblings("ul").remove(); /* * type head highlighting - creating array with each word in user query for * search box */ var userQuery = (currentInput).val(); var userQueryWord; var userQueryWordLen = 0; if (userQuery != undefined && userQuery != "") { userQueryWord = userQuery.split(" "); } /* * type head highlighting - creating array with each word in user query for * search box - end */ var jsonLen = jsonObj.length; var typeaheadLeftHook = (currentInput).siblings(".typeaheadHook").val() + "px"; if($("html").attr("dir")=="ltr"){ var stringList = "