var ma_create=Array(); ma_create['scriptEls'] = document.getElementsByTagName( 'script' ); ma_create['thisScriptEl'] = ma_create['scriptEls'][ma_create['scriptEls'].length - 1]; ma_create['scriptPath'] = ma_create['thisScriptEl'].src; ma_create['scriptFolder'] = ma_create['scriptPath'].substr(0, ma_create['scriptPath'].lastIndexOf( '/' )+1 ); if (typeof String.prototype.startsWith != 'function') { //Implementation to startsWith starts below String.prototype.startsWith = function (str){ return this.indexOf(str) == 0; }; } if (typeof String.prototype.endsWith != 'function') { //Implementation to endsWith starts below String.prototype.endsWith = function (str){ return this.substr(this.length-str.length) == str; }; } $.fn.textWidth = function(){ var html_org = $(this).html(); var html_calc = '' + html_org + ''; $(this).html(html_calc); var width = $(this).find('span:first').width(); $(this).html(html_org); return width; }; var MiniApps=new function(){ this.encodeHash=function(url){ url=url.replace(/\?/g, "%3f"); url=url.replace(/\n/g, "%0a"); return url.replace(/#/g, "%23"); } this.decodeHash=function(url){ url=url.replace(/&/g, "&"); url=url.replace(/%3f/g, "?"); url=url.replace(/%0a/g, "\n"); return url.replace(/%23/g, "#"); } this.urlSplit=function(string) { var arr=Array(); while(string.length>0) { var paramsep=string.indexOf("&"); var urlsep=string.indexOf("\\\\"); if( urlsep==-1 && paramsep==-1 ) { arr.push(string); string=""; } else if( ( paramsep>urlsep && urlsep != -1 ) || paramsep==-1 ) { var endurlsep=string.indexOf("\\\\", urlsep+1); var stemp=string.substr(0, endurlsep); stemp=stemp.replace("\\\\",""); arr.push(stemp); string=string.substr(endurlsep+3); } else { arr.push(string.substr(0, paramsep)); string=string.substr(paramsep+1); } } return arr; } this.ConfigToArray=function( string ) { var arr={}; if( string!=-1 ) { if(string.startsWith("\\\\")) { string=string.substr(2); } if(string.endsWith("\\\\")) { string=string.substr(0,string.length-2); } string=this.decodeHash(decodeURI(string)); if(string.startsWith("http://") || string.startsWith("https://")) { var parambegin=string.indexOf("?"); if( parambegin>0 ) { string=string.substr(parambegin+1) } } var sarr=this.urlSplit(string); //urlarr=string.split("\\\\") //sarr=string.split("&"); if( sarr.length!=0 ) { $.each(sarr, function( key, value ){ if( value.length!=0 ) { var sep=value.indexOf("=") //var kv=value.split("="); var k=value.substr(0, sep);//kv[0]; var v=value.substr(sep+1);//kv[1]; if( k.indexOf("[")>0 ) { var beg=k.indexOf("["); var end=k.indexOf("]"); var index=k.substr(beg+1, end-beg-1); k=k.substr(0,beg); if( arr[k]==undefined ) { arr[k]=new Object(); } arr[k][index]=v; } else { arr[k]=v; } } }); } } return arr; } this.activateParameter=function(script, destHtml) { var ret=this.GetNewAppUrl(script, destHtml); var f=$('.testview', destHtml)[0]; f.src=ret.string; if( !f.src.startsWith("change") ) { f.contentWindow.location.href = f.src; } } this.countParameter=function(k,v){ if( k.startsWith("count_") ) { if(v==undefined) { var t=$("input[name='" + k + "']"); if(t.attr("def")!="") { v=t.attr("def"); } } var f=0; var s=k.substr(6); for( c=0; c<20; c++ ) { var display="none"; var item=$("input[name='b_" + s + "\[" + c + "\]'"); if( item.length==0 ) { item=$("input[name='" + s + "\[" + c + "\]'"); } if(f0 ) { var end=k.indexOf("]"); kindex=parseInt(k.substr(start+1, end-start-1)); k=k.substr(0,start); } if( cfgArr.hasOwnProperty(k) ) { if( kindex>0 ) { if(kindex in cfgArr[k] && $(value).attr("type")=="hidden" ) { // url $(value).val("\\\\" + cfgArr[k][kindex] + "\\\\"); } } else { switch( cfgArr[k].toString() ) { case "true": value.checked=true; break; case "false": value.checked=false; break; default: if( k.startsWith("col_") ) { $(this).css('background-color', cfgArr[k]); $(this).val(cfgArr[k]); } else if( k.startsWith("cal_") ) { appdata=$(value); (apps[appnamelower])($(value), cfgArr); /*for(i=0; i', {value:calendars[i].id, text:calendars[i].summary})); }*/ } else if( k.startsWith("TZ_") ) { var par=$(value).parent().parent(); if( k.startsWith("TZ_C_") ) { var end=k.substr(5); $(".TZ_C_"+end, par).bfhcountries({country:cfgArr["TZ_C_"+end], flags:true}); } else { var end=k.substr(3); var arr=bfhtz; arr['timezone']=cfgArr["TZ_"+end]; $(".TZ_"+end, par).bfhtimezones(arr); } } else { var v=mapps.countParameter(k,cfgArr[k]); $(value).val(cfgArr[k]); } break; } } } else { if( k.startsWith("cal_") ) { appdata=$(value); (apps[appnamelower])($(value), cfgArr); } else if( k.startsWith("TZ_") ) { if( k.startsWith("TZ_C_") ) { var end=k.substr(5); $(".TZ_C_"+end, par).bfhcountries({flags:true}); } else { var end=k.substr(3); var arr=bfhtz; $(".TZ_"+end, par).bfhtimezones(arr); } } /* else if(name.startsWith("aspect_ratio_")) { var v=$(value).val(); MiniApps.AspectRatioForTestView(destHtml, v); }*/ } }); $('._TZ_C').on('change.bfhselectbox', function () { var country = $(this).val(); var ref=$(this).parent().parent(); if($("._TZ", ref)[0].length<2) { $("._TZ option", ref).prop("selected", true); } }); $('._TZ').on('change.bfhselectbox', function () { }); $('._CP', destHtml).colorpickerplus(); $('._CP', destHtml).on('changeColor', function(e, color) { if(color==null) { $(this).val('transparent').css('background-color', '#fff');//tranparent } else { $(this).val(color).css('background-color', color); } $(destHtml).find('input[name="use_' + $(this).attr("name") + '"]')[0].checked=true; mapps.activateParameter(script, destHtml); }); $('select', destHtml).on("change textInput input", function(){ var name=$(this).attr("name"); if(name.startsWith("count_")) { mapps.countParameter(name, $(this).val()); } else if(name.startsWith("align") || name.startsWith("media_size") || name.startsWith("aspect_ratio")) { var val=$("select[name='aspect_ratio']", destHtml).val(); var align=$("select[name='align']", destHtml).val(); var media_size=$("select[name='media_size']", destHtml).val(); MiniApps.AspectRatioForTestView(destHtml, val, align, media_size); } mapps.activateParameter(script, destHtml); }); $('input', destHtml).on("change textInput input", function(){ mapps.activateParameter(script, destHtml); }); $('textarea', destHtml).on("change textInput input", function(){ mapps.activateParameter(script, destHtml); }); $('.subsites > input.button', destHtml).click(function(){ var value=$(this).prev(); var u=value.val(); // url var t=$(this); if( u.startsWith("change subitem") ) { u=""; } else if( u.startsWith("\\\\") ) { u=u.replace("\\\\", ""); } if( $(".mapps", this).length==0 ) { $(this).html("
") } mapps.config_apps($(".mapps", this), u, function(url){ value.val("\\\\" + url + "\\\\"); mapps.activateParameter(script, destHtml); }, function(){ //$(".testview").css("top", $(destHtml).scrollTop()); }); }); var handle = $( "#custom-handle" ); $( ".slider" ).each(function(){ var max=$( this ).attr( "max" ); if(max==undefined || max==0) { max=100; } $(this).slider({ create: function() { var k=$("input", this).attr("name"); var v=$( this ).attr( "default" )*$( this ).attr( "divide" ); if( cfgArr[k]!=undefined ) { v=cfgArr[k]; } $(".slider_text", this).text( v ); $("input", this).val( v ); $(this).slider("value", v); }, slide: function( event, ui ) { $(".slider_text", this).text( ui.value ); $("input", this).val( ui.value ); mapps.activateParameter(script, destHtml); }, max: max }); }); mapps.activateParameter(script, destHtml); destHtml.dialog("open"); if("aspect_ratio" in cfgArr)//k.startsWith("aspect_ratio_testview")) { MiniApps.AspectRatioForTestView(destHtml, cfgArr['aspect_ratio'], cfgArr['align'], cfgArr['media_size']); } $(destHtml).scroll(function(){ $(".testview", destHtml).css("position", "relative"); $(".testview", destHtml).css("top", $(destHtml).scrollTop()); }); }); } var scriptsLoaded=new Array(); var script=""; var server=""; var scripts_with_servers= new Array( { Server: "/widgets/", Apps: { Wetter: 'wetter/',Calendar: 'calendar/',Clock: 'clock/',Container: 'container/',Textticker: 'textticker/' } } ); this.scripts_with_servers=scripts_with_servers; this.calc_scripts=function(){ var s={}; $.each(scripts_with_servers, function(skey, svalue){ var server=svalue['Server']; var apps=svalue['Apps']; $.each(apps, function(key, value){ s[key]=server+value; }); }); return s; }; var scripts=this.calc_scripts(); $.widget( "custom.iconselectmenu", $.ui.selectmenu, { _renderItem: function( ul, item ) { var li = $( "
  • " ), wrapper = $( "
    ", { text: item.label, "data-name": item.element.attr("data-name") } ); if ( item.disabled ) { li.addClass( "ui-state-disabled" ); } $( "", { style: item.element.attr( "data-style" ), "class": "ui-icon " + item.element.attr( "data-class" ) }) .appendTo( wrapper ); return li.append( wrapper ).appendTo( ul ); } }); this.select_script=function(dest, qstring, successCB, failCB) { var sel=""; //sel=sel+""; $(dest).html(sel); $(dest).css("z-index", 50000); $(dest).dialog({ autoOpen: true, modal: true, width: 400, height: "auto", title: "Script Selection", buttons: { Load: function() { var key=$("select", dest).val(); var sscript=scripts[key]; successCB(key, sscript); $(this).dialog("close"); $(this).dialog("destroy"); $(this).html("") }, Cancel: function() { failCB(); $(this).dialog("close"); $(this).dialog("destroy"); $(this).html("") } } }); // $(dest).dialog("open"); $("select", dest).iconselectmenu(); } this.config_apps=function(mappscfg, qstring, finishedCallBack, cleanupDialog) { var def=false; if( mappscfg==undefined ) { mappscfg=$("#miniAppsConfig"); if(mappscfg==undefined || mappscfg.length==0) { $("
    ").appendTo("body"); mappscfg=$("#miniAppsConfig"); def=true; } } success=function (querystring, arr) { var nScriptPath=window.location.pathname;//ma_create['scriptFolder']; var i=nScriptPath.indexOf("?"); if(i!=-1) { nScriptPath=nScriptPath.substr(0,i); } if(nScriptPath.endsWith(".php")) { var i=nScriptPath.lastIndexOf("/"); nScriptPath=nScriptPath.substr(0,i); } if( nScriptPath.substr(-1)=="/" ) { nScriptPath=nScriptPath.substr(0,nScriptPath.length-1); } if(querystring.substr(0,1)=='/') { nScriptPath=""; } else { while(querystring.substr(0,3)=="../") { nScriptPath=nScriptPath.substr(0, nScriptPath.lastIndexOf("/")) querystring=querystring.substr(3); } querystring="/" + querystring; } querystring=window.location.origin+nScriptPath+querystring; server="3.124.131.30"; server1="http://" + server; server2="https://" + server; if(querystring.startsWith(server1)) { querystring=querystring.substr(server1.length); } else if(querystring.startsWith(server2)) { querystring=querystring.substr(server2.length); } finishedCallBack(querystring); } this.select_script( $(mappscfg), qstring, function( key, value ){ var script=value; { var miniAppsConfig=$(mappscfg); var mapps=MiniApps; mapps.openDialog(script, key, value, miniAppsConfig, qstring, success, cleanupDialog ); } }, cleanupDialog ); } this.GetNewAppUrl=function(script, inputdiv) { /*if(inputdiv==undefined) { //var dHtml=$("#miniAppsConfig"); //inputdiv=dHtml; }*/ var arr={}; var string=""; $(inputdiv).find('input, select, textarea').each(function(key, value){ var k=$(value).attr('name'); var v=$(value).val(); if( v=="on" ) { v=value.checked; } arr[k]=v; if( key!=0 ) { string=string+"&"; } string=string+k+"="+v; }); return{ arr: arr, string: script+"?"+this.encodeHash(string) }; } this.Ratio=function(rwidth, rheight, dwidth, dheight, elem) { var sheight=window.innerHeight; var swidth=window.innerWidth; if(elem!=null) { sheight=elem.height(); swidth=elem.width(); } var ratio=rwidth/rheight; var ratio_width=dwidth/rwidth; var ratio_height=dheight/rheight; var destratio=swidth/sheight; var owidth=(ratio_width)*(ratio*sheight); var oheight=(ratio_height*sheight); if(ratio>destratio) { owidth=ratio_width*swidth;//((1.0/ratio)*swidth); oheight=ratio_height*((1.0/ratio)*swidth); } return{ owidth: /*Math.round*/(owidth), oheight: /*Math.round*/(oheight) }; } this.CenterApp=function(className, rwidth, rheight, elem) { var ret=MiniApps.Ratio(rwidth, rheight, rwidth, rheight, elem); $(className, elem).css("height", ret.oheight); $(className, elem).css("width", ret.owidth); $(className, elem).css("margin-top", /*Math.floor*/((elem.height()-ret.oheight)/2)); return; } this.LoopThroughApps=function(app) { for(i=0; i"+t+"
    "); var div=orgdiv;//orgdiv.clone(); //div.css("position", "absolute"); //div.css("visibility", "hidden"); //var orgWidth=div.css("width"); // div.css("width", width); div.css("font-family", orgdiv.css("font-family")); div.css("width", "auto"); div.css("white-space", "nowrap"); div.css("overflow", "visible"); div.css("display", "inline-block"); //div.css("height", height); //div.css("whitespace", "nowrap"); var fontsize=height+1; do{ fontsize=fontsize-1; div.css("font-size", fontsize); }while((div.height()>height || div.width()>width )&& fontsize>3); div.css("display", "block"); //div.css("width", "auto"); //orgdiv.css("width", orgWidth); return fontsize; } this.DrawFunctions=Array(); this.RegisterDrawFunction=function(fIndex, drawFunction) { //apps_init_finished[fIndex]=true; this.DrawFunctions.push(drawFunction); return; } var time=undefined; var startTime=undefined; this.DrawFunc=function() { if(MiniApps.DrawFunctions.length<=0) { window.setTimeout(MiniApps.DrawFunc, 1000); return; } //if (time === undefined) { time = Date.now(); //} if (startTime === undefined) { startTime = time; } var milliseconds=(time-startTime); for(var i=0; i