(function() { var options = {"id":11483,"hash":"258bc132071b119e078de7144a995c0c","siteUrl":"https:\/\/libanswers.lib.xjtlu.edu.cn","iid":1591,"onlinerules":[{"u":0,"d":[2532,2533,2534,2535,3843],"c":""}],"width":"375px","height":"340","autoload_time":10,"slidebutton_height":"70px","slidebutton_width":"75px","slidebutton_bcolor":"transparent","slidebutton_color":"#ffffff","slidebutton_bcolor_off":"","slidebutton_color_off":"#ffffff","slidebutton_url":"https:\/\/libapps-au.s3-ap-southeast-2.amazonaws.com\/accounts\/103410\/images\/chat-01-01.png","slidebutton_url_off":"https:\/\/libapps-au.s3-ap-southeast-2.amazonaws.com\/accounts\/103410\/images\/chat-01-01.png","slidebutton_text":"Chat with Us","slidebutton_text_off":"Offline","translation":{"ch_float_show":"Open chat","ch_float_hide":"Minimize chat","ch_float_start":"Start chat"}}; var cascadeServer = "https:\/\/chat-au.libanswers.com"; var referer = ""; var refererTitle = ""; const removeCoverageFromRule=function(rule){return{u:rule.u,d:rule.d,c:rule.c,fallbackSeconds:rule.fallbackSeconds||0}},isCoverageInRange=function(hour,minute,ranges){if(0===ranges.length)return!1;for(let i=0;i<=ranges.length;i++){const range=ranges[i];if(!Array.isArray(range)||2!==range.length)continue;const start=range[0].split(":").map((el=>parseInt(el,10))),end=range[1].split(":").map((el=>parseInt(el,10)));if(!(start[0]>hour||end[0]hour)return!0;if(start[0]!==hour){if(end[0]!==hour);else if(end[1]>minute)return!0}else if(start[1]{if(!rule.c||1===rule.coverageType)return void finalRules.push(removeCoverageFromRule(rule));if(0===rule.coverageType)return;const times=rule.coverageHours;if(!times||!times[day]||0===times[day].length)return;const ranges=times[day];isCoverageInRange(hour,minute,ranges)&&finalRules.push(removeCoverageFromRule(rule))})),finalRules};; const floatWidget={config:{},online:!1,loaded:!1,autoload:!1,chat_load:null,chat_button:null,image:null,svgTitle:null,openBtnContent:"",overlay:null,chat_timer:null,referer:"",refererTitle:"",boundKeyboardHandler:null,boundOverlayHandler:null,narrowScreen:null,insertWidgetCSS:function(){const css=`/* LibChat Widget CSS */\n .s-lch-widget-float { position: fixed; bottom: 1px; right: 1px; z-index: 1000; padding: 1em; font-size: 16px; display: flex; flex-direction: column; flex-wrap: nowrap; justify-content: flex-end; align-content: flex-end; align-items: flex-end; box-sizing: border-box; pointer-events: none; }\n .s-lch-widget-float.open { top: 1px; width: ${this.config.width}; height: 100%; }\n .s-lch-widget-float > * { pointer-events: auto; }\n .s-lch-widget-float-load { flex: 0 1 auto; display: none; transition: flex-grow 2s; border-radius: 5px; border: 1px solid rgb(221, 221, 221); box-shadow: 0.1em 0.2em 0.5em #ccc; min-height: 200px; width: 100%; height: 200px; z-index: 501; position: relative; }\n .s-lch-widget-float-load.expanded {flex: 2 1 auto; min-height: 0; }\n .s-lch-widget-float.open .s-lch-widget-float-load { display: block; }\n .s-lch-widget-float-btn { border: none; padding: .75em .75em .5em .75em; border-radius: 5px; position: relative; bottom: 0; right: 0; flex: 0 0 auto; box-shadow: 0.1em 0.2em 0.5em #ccc; font-size: .9em; background-color: ${this.config.slidebutton_bcolor_off}; color: ${this.config.slidebutton_color_off}; width: 4em; height: 3.75em; z-index: 501; }\n .s-lch-widget-float.open .s-lch-widget-float-btn { margin-top: 1em; }\n .s-lch-widget-float-btn.online { background-color: ${this.config.slidebutton_bcolor}; color: ${this.config.slidebutton_color}; }\n .s-lch-widget-float-btn svg .dots { display: none; }\n .s-lch-widget-float-btn.online svg .dots { display: block; }\n .s-lch-widget-float-btn.s-lch-widget-img-btn, .s-lch-widget-float-btn img { padding: 0; height: ${this.config.slidebutton_height}; width: ${this.config.slidebutton_width}; }\n #s-lch-widget-float-indicator { position: absolute; top: -.5em; right: -.5em; background-color: red; border-radius: 1em; width: 1em; height: 1em; }\n .s-lch-widget-float div.tab_overlay { position: fixed; background-color: rgb(0, 0, 0); top: 0; left: 0; bottom: 0; right: 0; opacity: 0.0; z-index: 500; display: none; }\n @media (max-width: 550px) {\n .s-lch-widget-float { left: 0; width: 100%; }\n .s-lch-widget-float.open .s-lch-widget-float-load { width: 100%; }\n .s-lch-widget-float.open .s-lch-widget-float-btn { display: none; }\n }`,head=document.head||document.getElementsByTagName("head")[0],style=document.createElement("style");style.styleSheet?style.styleSheet.cssText=css:style.appendChild(document.createTextNode(css)),head.appendChild(style)},isNarrowScreen:function(){if(null!==this.narrowScreen)return this.narrowScreen;const mediaQuery=window.matchMedia("(max-width: 700px)");return this.narrowScreen=mediaQuery.matches,this.narrowScreen},getWidgetUrl:function(){""===this.referer&&(this.referer=window.location.href),""===this.refererTitle&&window.document.title&&(this.refererTitle=window.document.title);let authId=0;window.springSpace&&window.springSpace.la&&window.springSpace.la.Page&&window.springSpace.la.Page.auth_id&&(authId=window.springSpace.la.Page.auth_id);let qs=`${this.config.siteUrl}/chat/widget/${this.config.hash}?referer=${encodeURIComponent(this.referer)}&referer_title=${encodeURIComponent(this.refererTitle)}&auth_id=${authId}`;return this.autoload&&(qs+="&auto=true",this.autoload=!1),qs},statusSuccess:function(data){let online=!1;(data.u||data.d||data.c)&&(online=!0),this.changeButtonStatus(online);let isCoopOnline=!1;data.c&&data.c.length>0&&(isCoopOnline=!0),this.setTimer(isCoopOnline)},checkStatus:function(){const adjustedRules=adjustStatusRequestForCoverage(this.config.onlinerules),xhr=new XMLHttpRequest;xhr.onload=()=>{const status=xhr.status;if(status>=200&&status<300)try{this.statusSuccess(JSON.parse(xhr.responseText))}catch(e){this.changeButtonStatus(!1)}else this.changeButtonStatus(!1)},xhr.onerror=()=>{this.changeButtonStatus(!1)},xhr.open("GET",`${this.cascadeServer}/widget_status?iid=${this.config.iid}&rules=${encodeURIComponent(JSON.stringify(adjustedRules))}`),xhr.send()},autoPopDenied:function(){try{let obj=localStorage.getItem("libchat_auto");if(""===obj)return!1;obj=JSON.parse(obj);return!(Math.floor(Date.now()/1e3)-obj.date>3600)||(this.deleteAutoPopDeny(),!1)}catch(e){this.deleteAutoPopDeny()}return!1},deleteAutoPopDeny:function(){try{localStorage.removeItem("libchat_auto")}catch(e){}},showMsgNotice:function(){this.indicator||(this.indicator=document.createElement("span"),this.indicator.id="s-lch-widget-float-indicator"),null===this.indicator.parentNode&&this.chat_button.appendChild(this.indicator),this.indicator.style.display="block"},hideMsgNotice:function(){this.indicator&&(this.indicator.style.display="none")},handleMessages:function(e){const data=e.data;if("object"==typeof data&&data.action)switch(data.action){case"closeWidget":this.chat_button.focus(),this.closeWidget();break;case"chatStarted":case"expandWidget":this.boundOverlayHandler&&this.overlay.removeEventListener("click",this.boundOverlayHandler),this.overlay.style.display="none",this.chat_load.classList.contains("expanded")||(this.chat_load.classList.add("expanded"),this.chat_load.style.minHeight=0);break;case"autopop":this.openWidget(),this.boundOverlayHandler=this.closeWidget.bind(this),this.overlay.addEventListener("click",this.boundOverlayHandler),this.overlay.style.display="block";break;case"height":null!==this.chat_load&&data.height&&(this.chat_load.style.minHeight=`${data.height}px`);break;case"newMessage":"true"===this.chat_load.getAttribute("aria-hidden")&&this.showMsgNotice();break;case"changeStatus":this.changeButtonStatus(data.online||!1)}},closeWidget:function(){this.chat_load.removeAttribute("aria-live"),this.chat_load.setAttribute("aria-hidden","true"),this.chat_div.classList.remove("open"),this.chat_button.setAttribute("aria-label",this.config.translation.ch_float_show),this.chat_button.setAttribute("title",this.config.translation.ch_float_show),this.chat_button.setAttribute("aria-expanded",!1),this.chat_load.contentWindow.postMessage("closeChatWidget",`${this.config.siteUrl}/`),document.body.removeEventListener("keydown",this.boundKeyboardHandler),this.boundOverlayHandler&&this.overlay.removeEventListener("click",this.boundOverlayHandler),this.overlay.style.display="none"},openWidget:function(){this.chat_div.classList.contains("open")||this.chat_div.classList.add("open"),this.chat_button.setAttribute("aria-label",this.config.translation.ch_float_hide),this.chat_button.setAttribute("title",this.config.translation.ch_float_hide),this.chat_button.setAttribute("aria-expanded",!0),this.hideMsgNotice(),this.boundKeyboardHandler=this.keyboardCloseWidget.bind(this),document.body.addEventListener("keydown",this.boundKeyboardHandler),null===this.chat_load?this.loadIframe():this.chat_load.setAttribute("aria-hidden","false")},keyboardCloseWidget:function(ev){"Escape"===ev.key&&this.closeWidget()},loadIframe:function(){if(null!==this.chat_load)return;const chatUrl=this.getWidgetUrl();this.chat_load=document.createElement("iframe"),this.chat_load.setAttribute("id",`iframe_${this.config.hash}`),this.chat_load.setAttribute("name",`iframe_${this.config.hash}`),this.chat_load.setAttribute("src",chatUrl),this.chat_load.setAttribute("title","Chat Widget"),this.chat_load.setAttribute("scrolling","no"),this.chat_load.className="s-lch-widget-float-load",this.chat_load.setAttribute("aria-live","polite"),this.chat_load.setAttribute("aria-hidden","false"),this.chat_load.innerHTML="Content is loading...",this.chat_div.insertBefore(this.chat_load,this.chat_button),window.addEventListener("message",this.handleMessages.bind(this))},autoOpenWidget:function(){this.autoPopDenied()||(this.autoload=!0,this.loadIframe())},toggleWidget:function(){window.clearTimeout(this.chat_timer),this.chat_div.classList.contains("open")?this.closeWidget():this.openWidget()},showButton:function(){this.chat_button.style.display=""},setTimer:function(isCoopOnline){if(!this.isNarrowScreen())if(this.online){if(isCoopOnline)return;this.config.autoload_time&&parseInt(this.config.autoload_time,10)>0&&!this.autoPopDenied()&&(this.chat_timer=window.setTimeout(this.autoOpenWidget.bind(this),1e3*parseInt(this.config.autoload_time,10)))}else this.autoload=!1},changeButtonStatus(online){if(online!==this.online){if(this.online=online,this.online)return this.chat_button.classList.add("online"),void(this.image?(this.image.setAttribute("src",this.config.slidebutton_url),this.image.setAttribute("alt",this.config.slidebutton_text)):this.svgTitle.innerHTML=this.config.slidebutton_text);this.chat_button.classList.remove("online"),this.image?(this.image.setAttribute("src",this.config.slidebutton_url_off),this.image.setAttribute("alt",this.config.slidebutton_text_off)):this.svgTitle.innerHTML=this.config.slidebutton_text_off}},buildButton:function(){this.chat_button=document.createElement("button"),this.chat_button.setAttribute("aria-controls",`s-lch-widget-${this.config.id}`),this.chat_button.setAttribute("aria-expanded",!1),this.chat_button.setAttribute("type","button"),this.chat_button.className="s-lch-widget-float-btn",""!==this.config.slidebutton_url_off&&""!==this.config.slidebutton_url?(this.chat_button.style.display="none",this.image=document.createElement("img"),this.image.addEventListener("load",this.showButton.bind(this)),this.image.setAttribute("src",this.config.slidebutton_url_off),this.image.setAttribute("alt",this.config.slidebutton_text_off),this.chat_button.classList.add("s-lch-widget-img-btn"),this.chat_button.appendChild(this.image)):(this.chat_button.innerHTML=`${this.config.slidebutton_text_off}`,this.svgTitle=this.chat_button.querySelector("svg title")),this.chat_button.setAttribute("aria-label",this.config.translation.ch_float_start),this.chat_button.setAttribute("title",this.config.translation.ch_float_start),this.chat_div.appendChild(this.chat_button),this.isNarrowScreen()?this.chat_button.addEventListener("click",this.openChat.bind(this)):this.chat_button.addEventListener("click",this.toggleWidget.bind(this))},openChat:function(){const chatUrl=this.getWidgetUrl();window.open(chatUrl,"libchat",`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=${this.config.width}, height=${this.config.height}`)},start:function(){!0!==this.loaded&&(this.loaded=!0,this.insertWidgetCSS(),this.chat_div=document.createElement("div"),this.chat_div.id=`s-lch-widget-${this.config.id}`,this.chat_div.setAttribute("role","region"),this.chat_div.setAttribute("aria-label","Chat Widget"),this.chat_div.className="s-lch-widget-float",this.overlay=document.createElement("div"),this.overlay.classList.add("tab_overlay"),this.chat_div.appendChild(this.overlay),document.body.appendChild(this.chat_div),this.buildButton(),this.checkStatus(),document.addEventListener("visibilitychange",(()=>{"visible"!==document.visibilityState||this.chat_load||this.checkStatus()})))}};floatWidget.config=options,floatWidget.cascadeServer=cascadeServer,floatWidget.referer=referer,floatWidget.refererTitle=refererTitle,window.openChat=floatWidget.openChat.bind(floatWidget),"complete"===document.readyState||"interactive"===document.readyState?floatWidget.start():(document.addEventListener("DOMContentLoaded",floatWidget.start.bind(floatWidget),!1),window.addEventListener("load",floatWidget.start.bind(floatWidget),!1));})();