var renderAwardWidget = function () { "use strict"; // get brandData with widgetType, brandType, style, size, htid, langId var brandData = { awardId : "d8a84f0a-2374-40b8-acbb-ff2af522273f", brandType: "Hotels", style: "Light", sizeType: "Square", brandLink: "https://www.hotels.com", hotelLink: "https://www.hotels.com/hotel/details.html?pos=HCOM_US&locale=en_US&eds=false&hotel-id=477867#section-reviews", awardLink:"", hotelName: "BCA Furnished Apartments", htid: "7439992", widgetName: "Loved by Guests 2021 Hotels.com award", clickDomain: "https://apps.expediapartnercentral.com/lodging/content/award/static", language: "English", theme: "_LGBTQ+" }; //get ${config} with widgetType, brandType, style ,size var config = { elementConfig:{"widgetElement":"
{{bgImgElement}}{{awImgElement}}{{linkElement}}<\/div>","bgImgElement":"","awImgElement":"","linkElement":"Awarded to {{data}}<\/a><\/span><\/span>"}, colorConfig:{"textColor":"color:#fff;","linkColor":"color:#fff;"} }; var bgImgSrc = "https://apps.expediapartnercentral.com/lodging/content/award/static/images/bg7/" + brandData.brandType + "/" + "award_" + brandData.style + "_" + brandData.sizeType + ".png?"+ Math.random(); var awImgSrc= "https://apps.expediapartnercentral.com/lodging/content/award/static/aw/"+brandData.sizeType+"/"+ brandData.brandType+"/"+brandData.style+"_"+brandData.awardId+brandData.theme+".png?"+ Math.random(); var widget = { defaultStyleConfig:{ widgetElementStyle: "position:relative;top:0;right:0;bottom:0;left:0;display:inline-block;margin:auto;font-family:"Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;", imgElementStyle: "position:absolute;", awImgElementStyle: "position:absolute;", linkElementStyle: "position:absolute;display:table;text-align:center;font-family:Helvetica;" }, init: function () { this.widgetContainerBox = document.getElementById("widgetContainerBox"); if (this.widgetContainerBox === null) { throw new Error("widget requires a container
"); return false; } this.isAddNofollow = this.widgetContainerBox.getAttribute("data-isaddnofollow"); this.widgetElement = config.elementConfig.widgetElement; this.createWidgetElement(); this.createBgImgElement(); this.createAwImageElement(); this.createLinkElement(); this.renderWidget(); }, generateElementWithDefaultStyle: function(element, defaultStyle) { var preStyle, newStyle; var styleObj = element.match(/style='[\s\S]*?'/); if(styleObj){ preStyle = styleObj[0]; newStyle = preStyle.substring(0, 7) + defaultStyle + preStyle.substring(7); element = element.replace(/style='[\s\S]*?'/, newStyle); } return element; }, createWidgetElement: function () { var defaultStyle = this.defaultStyleConfig.widgetElementStyle; this.widgetElement = this.generateElementWithDefaultStyle(this.widgetElement, defaultStyle); }, createBgImgElement: function () { var bgImgElement = config.elementConfig.bgImgElement; bgImgElement = bgImgElement.replace(/\{\{data\}\}/, bgImgSrc); this.widgetElement = this.widgetElement.replace(/\{\{bgImgElement\}\}/, bgImgElement); }, createAwImageElement: function () { var awImgElement = config.elementConfig.awImgElement; var defaultStyle = this.defaultStyleConfig.awImgElementStyle; awImgElement = this.generateElementWithDefaultStyle(awImgElement, defaultStyle); awImgElement = awImgElement.replace(/\{\{data\}\}/, awImgSrc); this.widgetElement = this.widgetElement.replace(/\{\{awImgElement\}\}/, awImgElement); }, createLinkElement: function () { var linkElement = config.elementConfig.linkElement; var nameStyle, nameNewStyle; var defaultStyle = this.defaultStyleConfig.linkElementStyle + config.colorConfig.textColor; linkElement = this.generateElementWithDefaultStyle(linkElement, defaultStyle); if (this.isAddNofollow === "true") { linkElement = linkElement.replace(/
maxHeight) { var replaceTextWithDots = function (text) { return text.replace(/\s(\S)*$/, "..."); }; hotelLinkElement.innerHTML = replaceTextWithDots(hotelLinkElement.innerHTML); } }, sendLog: function (clickType, that) { var img = new Image(); img.src = brandData.clickDomain + "/statistics/click/" + brandData.htid + "/" + brandData.brandType + "/" + brandData.awardId + ".gif" + "?widgetName=" + brandData.widgetName + "&clickType=" + clickType + "&hotelName=" + brandData.hotelName + "&language=" + brandData.language + "&style=" + brandData.style + "&size=" + brandData.sizeType + "&noFollow=" + that.isAddNofollow } }; widget.init(); return widget; }; if (document.readyState === "complete" || (document.readyState !== "loading" && !document.documentElement.doScroll)) { renderAwardWidget(); } else { document.addEventListener("DOMContentLoaded", renderAwardWidget); }