lemonldap-ng/lemonldap-ng-portal/site/htdocs/static/common/js/portal.min.js
2020-04-13 11:47:02 +02:00

1 line
5.9 KiB
JavaScript

(function(){var G,e,D,I,_,C,M,N,t,R,f,i,U,s,A=[].indexOf||function(t){for(var e=0,n=this.length;e<n;e++)if(e in this&&this[e]===t)return e;return-1};s={},U=function(o){return $.getJSON(window.staticPrefix+"languages/"+o+".json",function(t){var e,n,a,r;for(e in s=t,n=window.datas.trOver.all)r=n[e],s[e]=r;if(window.datas.trOver[o])for(e in a=window.datas.trOver[o])r=a[e],s[e]=r;return $("[trspan]").each(function(){var t,e,n,a;for(t=$(this).attr("trspan").split(","),a=i(t.shift()),e=0,n=t.length;e<n;e++)r=t[e],a=a.replace(/%[sd]/,r);return $(this).html(a)}),$("[trmsg]").each(function(){if($(this).html(i("PE"+$(this).attr("trmsg"))),i("PE"+$(this).attr("trmsg")).match(/_hide_/))return $(this).parent().hide()}),$("[trplaceholder]").each(function(){return $(this).attr("placeholder",i($(this).attr("trplaceholder")))}),$("[localtime]").each(function(){var t;return t=new Date(1e3*$(this).attr("localtime")),$(this).text(t.toLocaleString())})})},i=function(t){return s[t]?s[t]:t},window.translate=i,I=function(){var r;return r={},$("script[type='application/init']").each(function(){var e,t,n,a;try{for(t in a=JSON.parse($(this).text()),n=[],a)n.push(r[t]=a[t]);return n}catch(t){return e=t,console.log("Parsing error",e),console.log("JSON",$(this).text())}}),console.log(r),r},f="#appslist",R=function(){return t("_appsListOrder",$(f).sortable("toArray").join())},C=function(t){return e("_oidcConsents",t,function(){return $("[partner='"+t+"']").hide()},function(t,e,n){return alert(e+" "+n)})},t=function(n,a,r,o){return $.ajax({type:"GET",url:G.scriptname+"/mysession/?gettoken",dataType:"json",error:o,success:function(t){var e;return(e={token:t.token})[n]=a,$.ajax({type:"PUT",url:G.scriptname+"/mysession/persistent",dataType:"json",data:e,success:r,error:o})}})},e=function(e,n,a,r){return $.ajax({type:"GET",url:G.scriptname+"/mysession/?gettoken",dataType:"json",error:r,success:function(t){return $.ajax({type:"DELETE",url:G.scriptname+"/mysession/persistent/"+e+"?sub="+n+"&token="+t.token,dataType:"json",success:a,error:r})}})},M=function(){var t,e,n,a,r,o,i,s,l,c,u,g,p;if(null==(c=$(f))||!G.appslistorder)return null;for(t=G.appslistorder.split(","),u=[],n=0,s=(o=c.sortable("toArray")).length;n<s;n++)u[p=o[n]]=p;for(i=0,l=t.length;i<l;i++)u[r=t[i]]&&(a=u[r],e=$(f+".ui-sortable").children("#"+a),g=$(f+".ui-sortable").children("#"+r),e.remove(),$(f+".ui-sortable").filter(":first").append(g));return 1},_=function(){return $.ajax({type:"POST",url:G.scriptname,data:{ping:1},dataType:"json",success:function(t){return null!=t.result&&1===t.result?setTimeout(_,G.pingInterval):location.reload(!0)},error:function(t,e,n){return location.reload(!0)}})},window.ping=_,D=function(t){var e,n,a,r,o;for(t+"=",n=decodeURIComponent(document.cookie).split(";"),o=new RegExp("^ *"+t+"="),a=0,r=n.length;a<r;a++)if((e=n[a]).match(o))return e=e.replace(o,"");return""},N=function(t,e,n){var a;return(a=new Date).setTime(a.getTime()+864e5*n),document.cookie=t+"="+e+"; expires="+a.toUTCString()+"; path=/"},G={},$(window).on("load",function(){var t,e,n,a,r,o,i,s,l,c,u,g,p,f,h,d,m,w,v,b,y,x,T,O,j,k,L,S,P,E;if(G=I(),window.datas=G,$("#appslist").sortable({axis:"y",cursor:"move",opacity:.5,revert:!0,items:"> div.category",update:function(){return R()}}),M(),$("div.message").fadeIn("slow"),$("input[name=timezone]").val(-(new Date).getTimezoneOffset()/60),v=$("#menu").tabs({active:0}),(w=$('#menu a[href="#'+G.displaytab+'"]').parent().index())<0&&(w=0),v.tabs("option","active",w),a=$("#authMenu").tabs({active:0}),(n=$('#authMenu a[href="#'+G.displaytab+'"]').parent().index())<0&&(n=0),a.tabs("option","active",n),G.choicetab&&a.tabs("option","active",$('#authMenu a[href="#'+G.choicetab+'"]').parent().index()),G.login?$("input[type=password]:first").focus():0===$("input[autofocus]").length&&$("input[type!=hidden]:first").focus(),G.newwindow&&$("#appslist a").attr("target","_blank"),$("p.removeOther").length&&(t=$("form.login").attr("action"),b=$("form.login").attr("method"),r="",-1!==t.indexOf("?")?t.substring(0,t.indexOf("?")):r=t+"?",$("form.login input[type=hidden]").each(function(t){return r+="&"+$(this).attr("name")+"="+$(this).val()}),d=$("p.removeOther a").attr("href")+"&method="+b+"&url="+btoa(r),$("p.removeOther a").attr("href",d)),j=window.location.search,console.log("Parsed queryString:",j),j&&(E=new URLSearchParams(j)),E&&(O=E.get("llnglanguage")),O&&console.log("Get lang from parameter"),s||(s=D("llnglanguage"))&&!O&&console.log("Get lang from cookie"),s)A.call(window.availableLanguages,s)<0&&(s=window.availableLanguages[0],O||console.log("Get default lang"));else if(navigator){for(c=[],u=[],T=[navigator.language],navigator.languages&&(T=navigator.languages),o=0,g=(L=window.availableLanguages).length;o<g;o++)e=L[o],l+='<img class="langicon" src="'+window.staticPrefix+"common/"+e+'.png" title="'+e+'" alt="['+e+']"> ';for(i=0,p=T.length;i<p;i++)for(x=T[i],console.log("Navigator lang",x),m=0,f=(S=window.availableLanguages).length;m<f;m++)e=S[m],console.log(" Available lang",e),k=new RegExp("^"+e+"-?"),x.match(k)?(console.log(" Matching lang =",e),c.push(e)):e.substring(0,1)===x.substring(0,1)&&u.push(e);(s=c[0]?c[0]:u[0]?u[0]:window.availableLanguages[0])&&!O&&console.log("Get lang from navigator")}else(s=window.availableLanguages[0])&&!O&&console.log("Get lang from window");for(O?(console.log("Selected lang ->",O),U(O)):(console.log("Selected lang ->",s),N("llnglanguage",s),U(s)),l="",y=0,h=(P=window.availableLanguages).length;y<h;y++)e=P[y],l+='<img class="langicon" src="'+window.staticPrefix+"common/"+e+'.png" title="'+e+'" alt="['+e+']"> ';return $("#languages").html(l),$(".langicon").on("click",function(){return s=$(this).attr("title"),N("llnglanguage",s),U(s)}),G.pingInterval&&0<G.pingInterval&&window.setTimeout(_,G.pingInterval),$(".localeDate").each(function(){var t;return t=new Date(1e3*$(this).attr("val")),$(this).text(t.toLocaleString())}),$(".oidcConsent").on("click",function(){return C($(this).attr("partner"))})})}).call(this);