lemonldap-ng/lemonldap-ng-portal/site/htdocs/static/common/js/portal.min.js
2020-01-28 15:58:25 +01:00

1 line
5.4 KiB
JavaScript

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