f18.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. "use strict";
  2. FW_version["f18.js"] = "$Id: f18.js 17318 2018-09-10 16:25:56Z rudolfkoenig $";
  3. // TODO: hierMenu+Pin,SVGcolors,floorplan
  4. // Known bugs: AbsSize is wrong for ColorSlider
  5. var f18_attr={}, f18_sd, f18_icon={}, f18_room, f18_grid=20, f18_margin=10;
  6. var f18_small = (screen.width < 480 || screen.height < 480);
  7. $(window).resize(f18_resize);
  8. $(document).ready(function(){
  9. f18_room = $("div#content").attr("room");
  10. f18_sd = $("body").attr("data-styleData");
  11. if(f18_sd) {
  12. eval("f18_sd="+f18_sd);
  13. if(!f18_sd)
  14. f18_sd = {};
  15. f18_attr = f18_sd.f18;
  16. if(f18_attr)
  17. delete(f18_attr.cols); // fix the past
  18. } else {
  19. f18_sd = {};
  20. }
  21. if(!f18_sd.f18) {
  22. f18_attr = { "Pinned.menu":"true" };
  23. f18_resetCol();
  24. f18_sd.f18 = f18_attr;
  25. }
  26. if(typeof f18_attr.savePinChanges == "undefined")
  27. f18_attr.savePinChanges = true;
  28. f18_setCss('init');
  29. var icon = FW_root+"/images/default/fhemicon_ios.png";
  30. $('head').append(
  31. '<meta name="viewport" content="initial-scale=1.0,user-scalable=1">'+
  32. '<meta name= "mobile-web-app-capable" content="yes">'+
  33. '<meta name="apple-mobile-web-app-capable" content="yes">'+
  34. '<link rel="apple-touch-icon" href="'+icon+'">');
  35. if('ontouchstart' in window)
  36. $("body").addClass('touch');
  37. if(f18_small) {
  38. $("body").addClass('small');
  39. f18_attr["Pinned.menu"] = false;
  40. }
  41. var f18_aCol = getComputedStyle($("a").get(0),null).getPropertyValue('color');
  42. for(var i in f18_icon)
  43. f18_icon[i] = f18_icon[i].replace('gray', f18_aCol);
  44. f18_icon.pinOut = f18_icon.pinIn
  45. .replace('/>',' transform="rotate(90,896,896)"/>');
  46. // Needed for moving this label
  47. var szc = $("[data-name=svgZoomControl]");
  48. if($(szc).length)
  49. $(szc).before("<div class='SVGplot'></div>");
  50. $(".SVGlabel[data-name]").each(function(){
  51. $(this).attr("data-name", "Room_"+f18_room+"_"+$(this).attr("data-name"));
  52. });
  53. f18_menu();
  54. f18_tables();
  55. f18_svgSetCols();
  56. if(typeof svgCallback != "undefined")
  57. svgCallback.f18 = f18_svgSetCols;
  58. $("[data-name]").each(function(){ f18_setPos(this) });
  59. f18_setWrapColumns();
  60. f18_setFixedInput();
  61. });
  62. function
  63. f18_menu()
  64. {
  65. $("#menu").toggleClass("hidden", f18_small || !f18_getAttr("Pinned.menu"));
  66. if($("#menuScrollArea #menuBtn").length)
  67. return fixMenu();
  68. $("<div id='menuBtn'></div>").prependTo("div#menuScrollArea")
  69. .css( {"background-image":"url('"+f18_icon.bars+"')", "cursor":"pointer" })
  70. .click(function(){ $("#menu").toggleClass("hidden") });
  71. $("div#menu").prepend("<div></div>");
  72. f18_addPin("div#menu > div:first", "menu", true, fixMenu, f18_small);
  73. setTimeout(function(){ $("#menu,#content,#logo,#hdr").addClass("animated"); },
  74. 10);
  75. function
  76. fixMenu()
  77. {
  78. $("#menuScrollArea #logo").css("display",
  79. f18_getAttr("hideLogo") ? "none" : "block");
  80. if(f18_getAttr("Pinned.menu")) {
  81. $("body").addClass("pinnedMenu");
  82. $("#menu").removeClass("hidden");
  83. $("#content").css("left",
  84. (parseInt($("div#menu").width())+2*f18_margin)+"px");
  85. } else {
  86. $("body").removeClass("pinnedMenu");
  87. $("#content").css("left", f18_margin);
  88. }
  89. f18_resize();
  90. }
  91. }
  92. function
  93. f18_tables()
  94. {
  95. $("table.roomoverview > tbody > tr > td > .devType:not(:first)")
  96. .css("margin-top", "20px");
  97. $("table.column tbody tr:not(:first-child) .devType")
  98. .css("margin-top", "20px");
  99. $("#content .devType").each(function(){
  100. var el = this, grp = $(el).text();
  101. f18_addPin(el, "Room."+FW_urlParams.room+".grp."+grp, true,
  102. function(isFixed){
  103. var ntr = $(el).closest("tr").next("tr");
  104. isFixed ? $(ntr).show() : $(ntr).hide();
  105. });
  106. });
  107. if(FW_urlParams.detail) {
  108. $("div.makeTable > span").each(function(){
  109. var el = this, grp = $(el).text();
  110. var nel = $("<div>"+grp+"</div>");
  111. $(el).replaceWith(nel);
  112. f18_addPin(nel, "detail."+grp, true,
  113. function(isFixed){
  114. var ntr = $(nel).next("table");
  115. isFixed ? $(ntr).show() : $(ntr).hide();
  116. });
  117. });
  118. }
  119. if(FW_urlParams.cmd == "style%20list" ||
  120. FW_urlParams.cmd == "style%20select")
  121. $("div.fileList").each(function(){ f18_addPinToStyleDiv(this) });
  122. if(FW_urlParams.cmd == "style%20select")
  123. f18_special();
  124. else if(f18_getAttr("showDragger"))
  125. $("[data-name]").each(function(){ f18_addDragger(this) });
  126. }
  127. function
  128. f18_special()
  129. {
  130. var row, room='all', appendTo;
  131. var attr = function(attrName, inRoom)
  132. {
  133. if(inRoom && room != "all") {
  134. var val = f18_attr["Room."+room+"."+attrName];
  135. if(val != undefined)
  136. return val;
  137. }
  138. return f18_attr[attrName];
  139. };
  140. var setAttr = function(attrName, attrVal, inRoom)
  141. {
  142. if(inRoom && room != "all")
  143. attrName = "Room."+room+"."+attrName;
  144. f18_setAttr(attrName, attrVal);
  145. };
  146. var addRow = function(name, desc, val)
  147. {
  148. $(appendTo)
  149. .append("<tr class='ar_"+name+" "+(++row%2 ? "even":"odd")+"'>"+
  150. "<td "+(val ? "" : "colspan='2'")+">"+
  151. "<div class='col1'>"+desc+"</div></td>"+
  152. (val ? "<td><div class='col2'>"+val+"</div></div></td>" : '')+
  153. "</tr>");
  154. };
  155. var addHider = function(name, inRoom, desc, fn)
  156. {
  157. addRow(name, desc, "<input type='checkbox'>");
  158. $(appendTo+" tr.ar_"+name+" input")
  159. .prop("checked", attr(name, inRoom))
  160. .click(function(){
  161. var c = $(this).is(":checked");
  162. setAttr(name, c, inRoom);
  163. if(fn)
  164. fn(c);
  165. });
  166. };
  167. var addColorChooser = function(name, desc)
  168. {
  169. addRow(name, desc, "<div class='cp'></div>");
  170. FW_replaceWidget(appendTo+" tr.ar_"+name+" div.col2 div.cp", name,
  171. ["colorpicker","RGB"], attr("cols."+name, true), name, "rgb", undefined,
  172. function(value) {
  173. setAttr("cols."+name, value, true);
  174. f18_setCss(name);
  175. });
  176. };
  177. // call drawspecial after got the roomlist...
  178. var f18_drawSpecial = function()
  179. {
  180. var roomHash={};
  181. var cleanRoom = function(){
  182. for(var k in f18_attr) {
  183. var m = k.match(/^room\.([^.]*)\..*/);
  184. if(m && !roomHash[m[1]])
  185. delete f18_attr[k];
  186. }
  187. };
  188. row = 0;
  189. $("div#content tr.f18").remove();
  190. $("div#content > table").append("<tr id='f18rs' class='f18'></tr>");
  191. $("tr#f18rs").append("<div class='fileList f18colors'>f18 special</div>");
  192. $("tr#f18rs").append("<table id='f18ts' class='block wide'></table>");
  193. appendTo = "table#f18ts";
  194. addHider("rightMenu", false, "MenuBtn right<br>on small screen",f18_resize);
  195. addHider("savePinChanges", false, "Save pin changes");
  196. addHider("showDragger", false, "Dragging active", function(c){
  197. if(c) {
  198. if($(".ui-draggable").length) {
  199. $(".ui-draggable").draggable("enable");
  200. $(".dragMove,.dragSize,.dragReset").show();
  201. } else {
  202. $("div.fileList").each(function(){ f18_addDragger(this) });
  203. }
  204. } else {
  205. $(".dragMove,.dragSize,.dragReset").hide();
  206. $(".ui-draggable").draggable("disable");
  207. }
  208. });
  209. addHider("snapToGrid", false, "Snap to grid", function(c){
  210. $(".ui-draggable").draggable("option", "grid",
  211. c ? [f18_grid,f18_grid] : [1,1]);
  212. });
  213. addRow("editStyle", "<a href='#'>Additional CSS</a>");
  214. $(appendTo+" tr.ar_editStyle a").click(function(){
  215. $('body').append(
  216. '<div id="editdlg" style="display:none">'+
  217. '<textarea id="f18_cssEd" rows="25" cols="60" style="width:99%"/>'+
  218. '</div>');
  219. $("#f18_cssEd").val($("head #fhemweb_css").html());
  220. $('#editdlg').dialog(
  221. { modal:true, closeOnEscape:true, width:$(window).width()*3/4,
  222. height:$(window).height()*3/4, title:$(this).text(),
  223. close:function(){ $('#editdlg').remove(); },
  224. buttons:[
  225. { text: "Cancel",click:function(){$(this).dialog('close')}},
  226. { text: "OK", click:function(){
  227. if(!$("head #fhemweb_css"))
  228. $("head").append("<style id='fhemweb_css'>\n</style>");
  229. var txt = $("#f18_cssEd").val();
  230. $("head #fhemweb_css").html(txt);
  231. var wn = $("body").attr("data-webName");
  232. FW_cmd(FW_root+"?cmd=attr "+wn+" Css "+
  233. encodeURIComponent(txt.replace(/;/g,";;"))+"&XHR=1");
  234. $(this).dialog('close');
  235. }}]
  236. });
  237. });
  238. $("div#content > table").append("<tr id='f18rr' class='f18'></tr>");
  239. $("tr#f18rr").append("<div class='fileList f18colors'>"+
  240. "f18: Room specific</div>");
  241. $("tr#f18rr").append("<table id='f18tr' class='block wide'></table>");
  242. appendTo = "table#f18tr";
  243. addRow("room", "Target <select><option>all</option></select>");
  244. FW_cmd(FW_root+"?cmd=jsonlist2 .* room&XHR=1", function(data) {
  245. var d;
  246. try { d=JSON.parse(data); } catch(e){ log(data); return FW_okDialog(e); }
  247. for(var i1=0; i1<d.Results.length; i1++) {
  248. var rname = d.Results[i1].Attributes.room;
  249. if(!rname || rname == "hidden")
  250. continue;
  251. var rl = rname.split(",")
  252. for(var i2=0; i2<rl.length; i2++)
  253. roomHash[rl[i2]] = true;
  254. }
  255. cleanRoom();
  256. var rArr = Object.keys(roomHash); rArr.sort();
  257. $(appendTo+" tr.ar_room select")
  258. .html("<option>all</option><option>"+
  259. rArr.join("</option><option>")+
  260. "</option>")
  261. .change(function(e){
  262. room = $(e.target).val();
  263. f18_drawSpecial();
  264. });
  265. $("tr.ar_room select").val(room);
  266. });
  267. addRow("reset", "Preset colors: "+
  268. "<a href='#'>default</a> "+
  269. "<a href='#'>light</a> "+
  270. "<a href='#'>dark</a> "+
  271. (room=='all' ? '': "<a href='#'>like:all</a>"));
  272. $(appendTo+" tr.ar_reset a").click(function(){
  273. var txt = $(this).text();
  274. if(txt == "like:all") {
  275. delete(roomHash[room]);
  276. cleanRoom();
  277. } else {
  278. f18_resetCol(txt, room);
  279. if(room == "all")
  280. f18_setCss('preset');
  281. }
  282. f18_setAttr();
  283. f18_drawSpecial();
  284. });
  285. addColorChooser("bg", "Background");
  286. addColorChooser("fg", "Foreground");
  287. addColorChooser("link", "Link");
  288. addColorChooser("evenrow", "Even row");
  289. addColorChooser("oddrow", "Odd row");
  290. addColorChooser("header", "Header row");
  291. addColorChooser("menu", "Menu");
  292. addColorChooser("sel", "Menu:Selected");
  293. addColorChooser("inpBack", "Input bg");
  294. $("table.f18colors input").attr("size", 8);
  295. var bgImg = attr("bgImg", true);
  296. addRow("bgImg", "<a href='#'>Background: <span>"+
  297. (bgImg ? bgImg : "none")+"</span></a>");
  298. $(appendTo+" tr.ar_bgImg a").click(function(){
  299. FW_cmd(FW_root+'?cmd='+
  300. '{join("\\n",FW_fileList("$FW_icondir/background/.*.(jpg|png)"))}&XHR=1',
  301. function(data) {
  302. if(data)
  303. data += "none";
  304. var imgList = data.split(/\n/);
  305. FW_okDialog("List of files in www/images/background:<br><ul>"+
  306. "<a href='#'>"+imgList.join("</a><br><a href='#'>")+'</a></ul>');
  307. $("#FW_okDialog a").click(function(){
  308. var txt = $(this).text();
  309. setAttr("bgImg", txt == 'none' ? undefined : txt, true);
  310. $(appendTo+" tr.ar_bgImg span").html(txt);
  311. f18_setCss("bgImg");
  312. });
  313. });
  314. });
  315. addHider("hideLogo", true, "Hide logo", f18_menu);
  316. addHider("hideInput", true, "Hide input", f18_menu);
  317. addHider("hidePin", true, "Hide pin", function(c){
  318. $("div.pinHeader div.pin").css("display", c ? "none":"block");
  319. });
  320. addHider("fixedInput", false, "Fixed input and menu", f18_setFixedInput);
  321. addHider("wrapcolumns",false,"Wrap columns<br>on small screen",
  322. f18_setWrapColumns);
  323. $("div.f18colors").css("margin-top", "20px");
  324. $("tr.f18 div.fileList").each(function(e){ f18_addPinToStyleDiv(this) });
  325. if(f18_getAttr("showDragger"))
  326. $("div.fileList").each(function(){ f18_addDragger(this) });
  327. $("[data-name]").each(function(){ f18_setPos(this) });
  328. f18_setWrapColumns();
  329. };
  330. loadScript("pgm2/fhemweb_colorpicker.js", f18_drawSpecial);
  331. }
  332. function
  333. f18_setFixedInput()
  334. {
  335. // togleClass is true for undefined
  336. $("body").toggleClass("fixedInput", f18_getAttr("fixedInput") ? true:false);
  337. f18_resize();
  338. }
  339. function
  340. f18_setWrapColumns()
  341. {
  342. $("table.block").toggleClass("wrapcolumns", f18_getAttr("wrapcolumns"));
  343. }
  344. function
  345. f18_addPinToStyleDiv(el)
  346. {
  347. var grp = $(el).text();
  348. f18_addPin(el, "style.list."+grp, true,
  349. function(isFixed){
  350. var ntr = $(el).next("table");
  351. isFixed ? $(ntr).show() : $(ntr).hide();
  352. });
  353. }
  354. function
  355. f18_resize()
  356. {
  357. var w=$(window).width();
  358. log("f18.js resize W:"+w+" S:"+screen.width);
  359. var hl = f18_getAttr("hideLogo"),
  360. hi = f18_getAttr("hideInput"),
  361. pm = f18_getAttr("Pinned.menu"),
  362. rm = (f18_getAttr("rightMenu") && f18_small);
  363. var left = 0;
  364. left += hl ? 0 : 40;
  365. left += pm ? 0 : 44;
  366. var lleft = (pm ? 10 : 52);
  367. $("input.maininput").css({ width:(w-left-(FW_isiOS ? 36 : 24))+'px',
  368. "margin-left":(rm ? "0px" : "10px"),
  369. display: hi ? "none":"block"});
  370. $("#menu,#content").css("top", (hi && pm && hl) ? "10px" : "50px");
  371. $("#hdr").css({ left:(rm ? 10 : left)+'px' });
  372. $("#menuBtn").toggle(!pm || f18_small);
  373. $("#menuBtn").css({ left:(rm ? "auto":"10px"), right:(rm ? "10px":"auto") });
  374. $("#logo") .css({ left:(rm ? "auto":lleft ), right:(rm ? "48px":"auto") });
  375. if(FW_isiOS)
  376. $("#logo,#menuBtn").css({ top:'12px'});
  377. }
  378. function
  379. f18_addPin(el, name, defVal, fn, hidePin)
  380. {
  381. var init = f18_getAttr("Pinned."+name);
  382. if(init == undefined)
  383. init = defVal;
  384. $("<div class='pin'></div>")
  385. .appendTo(el)
  386. .css("background-image", "url('"+
  387. (init ? f18_icon.pinIn : f18_icon.pinOut)+"')");
  388. var f18_name = name.replace(/[^A-Z0-9]/ig,'_');
  389. $(el)
  390. .addClass("col_header pinHeader "+f18_name)
  391. .attr("data-name", f18_name);
  392. el = $(el).find("div.pin");
  393. $(el)
  394. .addClass(init ? "pinIn" : "")
  395. .css("cursor", "pointer")
  396. .css("display", (f18_getAttr("hidePin") || hidePin) ? "none" : "block")
  397. .click(function(){
  398. var nextVal = !$(el).hasClass("pinIn");
  399. $(el).toggleClass("pinIn");
  400. $(el).css("background-image","url('"+
  401. (nextVal ? f18_icon.pinIn : f18_icon.pinOut)+"')")
  402. f18_setAttr("Pinned."+name, nextVal);
  403. fn(nextVal);
  404. });
  405. fn(init);
  406. }
  407. // el is the drag-handle, return the corresponding SVG/table etc
  408. function
  409. f18_compEl(el)
  410. {
  411. return $(el).hasClass("fileList") ? $(el).next("table") :
  412. $(el).hasClass("SVGlabel") ? $(el).prev(".SVGplot") :
  413. $(el).closest("tr").next().find(">td>table").first();
  414. }
  415. function
  416. f18_addDragger(el)
  417. {
  418. if(f18_small || FW_urlParams.detail)
  419. return;
  420. if($(el).find(".dragger").length)
  421. return;
  422. var comp = f18_compEl(el);
  423. if($(comp).length == 0)
  424. return;
  425. f18_convertToAbs();
  426. var ep = $(el).position();
  427. var cp = $(comp).position();
  428. var pl = parseInt($(el).css("padding-left").replace("px",""));
  429. var grid = [1,1];
  430. if(f18_getAttr("snapToGrid"))
  431. grid = [f18_grid, f18_grid];
  432. function
  433. save()
  434. {
  435. var nep = $(el).position();
  436. f18_setAttr("Pos."+$(el).attr("data-name"), {
  437. left:nep.left, top:nep.top,
  438. width:$(comp).width(), height:$(comp).height(),
  439. oTop:cp.top-ep.top, oLeft:cp.left-ep.left
  440. });
  441. }
  442. /////////////////////////////////////
  443. // Position
  444. $("<div class='dragger dragMove'></div>")
  445. .appendTo(el)
  446. .css({"cursor":"pointer",
  447. "background-image":"url('"+f18_icon.arrows+"')"})
  448. $(el).draggable({
  449. drag:function(evt,ui){
  450. $(comp).css({ left:ui.position.left+cp.left-ep.left,
  451. top: ui.position.top +cp.top -ep.top });
  452. },
  453. stop:save, grid:grid
  454. });
  455. /////////////////////////////////////
  456. // Size
  457. var off = 20;
  458. if(!$(el).hasClass("SVGlabel")) {
  459. $("<div class='dragSize'></div>")
  460. .appendTo(el)
  461. .css({ cursor:"pointer", "background-image":"url('"+f18_icon.arrows+"')",
  462. position:"absolute", width:"16px", height:"16px",
  463. top:$(comp).height()+2, left:$(comp).width()-off, "z-index":1 })
  464. .draggable({
  465. drag:function(evt,ui){
  466. $(el).css( { width:ui.position.left+off });
  467. $(comp).css({ width:ui.position.left+off,
  468. height:ui.position.top });
  469. },
  470. stop:save, grid:grid
  471. });
  472. }
  473. /////////////////////////////////////
  474. // Reset _all_ elements on this page
  475. $("<div class='dragger dragReset'></div>")
  476. .appendTo(el)
  477. .css({"cursor":"pointer",
  478. "background-image":"url('"+f18_icon.ban+"')"})
  479. .click(function(){
  480. function
  481. delStyle(e)
  482. {
  483. var style = $(e).attr("style");
  484. $(e).attr("style", style.replace(/position:.*;/,"")); // hack
  485. }
  486. $("[data-name]").each(function(){
  487. var el = this;
  488. var name = $(el).attr("data-name");
  489. if(!f18_getAttr("Pos."+name))
  490. return;
  491. delete(f18_attr["Pos."+$(el).attr("data-name")]);
  492. delStyle(el);
  493. delStyle(f18_compEl(el));
  494. $(el).draggable('disable');
  495. $(el).find(".dragMove,.dragSize,.dragReset").hide();
  496. });
  497. f18_setAttr();
  498. });
  499. }
  500. function
  501. f18_applyGrid(pos)
  502. {
  503. if(!f18_getAttr("snapToGrid"))
  504. return;
  505. pos.left = Math.floor((pos.left + f18_grid-1)/f18_grid)*f18_grid;
  506. pos.top = Math.floor((pos.top + f18_grid-1)/f18_grid)*f18_grid;
  507. pos.width = Math.floor((pos.width + f18_grid-1)/f18_grid)*f18_grid;
  508. pos.height = Math.floor((pos.height+ f18_grid-1)/f18_grid)*f18_grid;
  509. }
  510. //////////////////////////
  511. // We use absolute positioning for all elements, if a user positioned
  512. // an item, relative (the default one) else.
  513. function
  514. f18_convertToAbs()
  515. {
  516. // Need two loops, else the sizes/positions are wrong
  517. var sz = {};
  518. $("[data-name]").each(function(){
  519. var el = this;
  520. var name = $(el).attr("data-name");
  521. if(f18_getAttr("Pos."+name))
  522. return;
  523. var comp = f18_compEl(el);
  524. if($(comp).length == 0)
  525. return;
  526. sz[name] = { ep:$(el).position(), cp:$(comp).position(),
  527. w:$(comp).width(), h:$(comp).height() };
  528. });
  529. var needSave=false;
  530. $("[data-name]").each(function(){
  531. var el = this;
  532. var name = $(el).attr("data-name");
  533. if(!name || !sz[name])
  534. return;
  535. needSave = true;
  536. var comp = f18_compEl(el);
  537. var ep=sz[name].ep, cp=sz[name].cp, w=sz[name].w, h=sz[name].h;
  538. var pos = {
  539. left:ep.left, top:ep.top, width:w, height:h,
  540. oTop:cp.top-ep.top, oLeft:cp.left-ep.left
  541. };
  542. f18_doSetPos(el, comp, pos);
  543. f18_setAttr("Pos."+name, pos, true);
  544. });
  545. if(needSave)
  546. f18_setAttr();
  547. }
  548. function
  549. f18_setPos(el)
  550. {
  551. if(f18_small || FW_urlParams.detail)
  552. return;
  553. var comp = f18_compEl(el);
  554. if($(comp).length == 0)
  555. return;
  556. var name = $(el).attr("data-name");
  557. var pos = f18_getAttr("Pos."+name);
  558. if(!pos || !pos.width)
  559. return;
  560. f18_doSetPos(el, comp, pos);
  561. // correct position
  562. var ds = $(el).find(".dragSize");
  563. if($(ds).length)
  564. $(ds).css({ top:pos.height+2, left:pos.width-20 });
  565. }
  566. function
  567. f18_doSetPos(el, comp, pos)
  568. {
  569. f18_applyGrid(pos);
  570. $(el).css({ position:"absolute", left:pos.left, top:pos.top });
  571. if(!$(el).hasClass("SVGlabel")) {
  572. var padding = parseInt($(el).css("padding-left").replace("px",""));
  573. $(el).css({ width:pos.width-padding });
  574. }
  575. $(comp).css({ position:"absolute",
  576. left:pos.left+pos.oLeft, top:pos.top+pos.oTop,
  577. width:pos.width, height:pos.height });
  578. }
  579. function
  580. f18_getAttr(attrName)
  581. {
  582. if(f18_room != undefined) {
  583. var val = f18_attr["Room."+f18_room+"."+attrName];
  584. if(val != undefined)
  585. return val
  586. }
  587. return f18_attr[attrName];
  588. }
  589. function
  590. f18_setAttr(name, value, dontSave)
  591. {
  592. if(name)
  593. f18_attr[name]=value;
  594. if(name && value == undefined)
  595. delete f18_attr[name];
  596. if(name && name.indexOf("Pinned.") == 0 && !f18_attr.savePinChanges)
  597. return;
  598. if(dontSave)
  599. return;
  600. var wn = $("body").attr("data-webName");
  601. FW_cmd(FW_root+"?cmd=attr "+wn+" styleData "+
  602. encodeURIComponent(JSON.stringify(f18_sd, undefined, 1))+"&XHR=1");
  603. }
  604. function
  605. f18_resetCol(name, room)
  606. {
  607. var cols = {
  608. "default":{ bg: "FFFFE7", fg: "000000", link: "278727",
  609. evenrow:"F8F8E0", oddrow:"F0F0D8", header: "E0E0C8",
  610. menu: "D7FFFF", sel: "A0FFFF", inpBack:"FFFFFF" },
  611. light: { bg: "F8F8F8", fg: "465666", link: "4C9ED9",
  612. evenrow:"E8E8E8", oddrow:"F0F0F0", header: "DDDDDD",
  613. menu: "EEEEEE", sel: "CAC8CF", inpBack:"FFFFFF" },
  614. dark: { bg: "444444", fg: "CCCCCC", link: "FF9900",
  615. evenrow:"333333", oddrow:"111111", header: "222222",
  616. menu: "111111", sel: "333333", inpBack:"444444" }
  617. };
  618. var col = (name ? cols[name] : cols["default"]);
  619. var prefix = (room && room != 'all' ? "Room."+room+".cols." : "cols.");
  620. for(var c in col)
  621. f18_attr[prefix+c] = col[c];
  622. }
  623. // Put all the colors into a head style tag, send background changes to FHEM
  624. function
  625. f18_setCss(why)
  626. {
  627. var style = "";
  628. function col(n) { return f18_getAttr("cols."+n, true) };
  629. function bg(c) { return "{ background:#"+c+"; fill:#"+c+"; }\n" }
  630. function fg(c) { return "{ color:#"+c+"; }\n" }
  631. style += ".col_fg, body, input, textarea "+fg(col("fg"));
  632. style += ".col_bg, textarea, input, option "+bg(col("bg"));
  633. style += ".col_link,a:not(.changed),.handle,.fhemlog,input[type=submit],"+
  634. "select,div.ui-widget-content a "+
  635. "{color:#"+col("link")+"!important; stroke:#"+col("link")+";}\n";
  636. style += "svg:not([fill]):not(.jssvg) { fill:#"+col("link")+"; }\n";
  637. style += ".col_evenrow, table.block,div.block "+bg(col("evenrow"));
  638. style += ".col_oddrow,table.block tr.odd,table.block tr.sel "+
  639. bg(col("oddrow"));
  640. style += ".col_header "+bg(col("header"));
  641. style += ".col_menu, table.room "+bg(col("menu"));
  642. style += ".col_sel, table.room tr.sel "+bg(col("sel"));
  643. style += ".col_inpBack, input "+bg(col("inpBack"));
  644. if(col("bg") == "FFFFE7") // default
  645. style += "div.pinHeader.menu {background:#"+col("sel")+";}\n";
  646. style += "div.ui-dialog-titlebar "+bg(col("header"));
  647. style += "div.ui-widget-content "+bg(col("bg"));
  648. style += "div.ui-widget-content, .ui-button-text "+fg(col("fg")+"!important");
  649. style += "div.ui-dialog { border:1px solid #"+col("link")+"; }";
  650. style += "button.ui-button { background:#"+col("oddrow")+"!important; "+
  651. "border:1px solid #"+col("link")+"!important; }\n";
  652. if(typeof DashboardDraggable != "undefined") {
  653. var db = "#dashboard ";
  654. style += db+".dashboard_widgetheader "+bg(col("header"));
  655. style += db+".dashboard_tabnav "+bg(col("menu")+"!important");
  656. style += db+".ui-widget-header .ui-state-default "+bg(col("menu"));
  657. style += db+".ui-widget-header .ui-state-active "+bg(col("sel"));
  658. style += db+".ui-widget-header "+fg(col("fg")+"!important;");
  659. style += db+".ui-widget-header li { border:none!important; }";
  660. style += db+".ui-widget-content a "+fg(col("link")+"!important" );
  661. }
  662. var bgImg = f18_getAttr("bgImg", true);
  663. if(bgImg) {
  664. style += 'body { background-image: url('+FW_root+
  665. '/images/background/'+bgImg+');}';
  666. } else {
  667. style += "body "+bg(col("bg"));
  668. }
  669. $("head style#f18_css").remove();
  670. style = "<style id='f18_css'>"+style+"</style>";
  671. if($("head style#fhemweb_css").length)
  672. $("head style#fhemweb_css").before(style);
  673. else
  674. $("head").append(style);
  675. $("head meta[name=theme-color]").remove();
  676. $("head").append('<meta name="theme-color" content="#'+col("bg")+'">');
  677. // Recolor the menu arrows. CSS does not apply to such SVGs :(
  678. if(why=='init' || why=='preset' || why=='link') {
  679. var a = $("a").get(0);
  680. if(window.getComputedStyle && a) {
  681. var col = getComputedStyle(a,null).getPropertyValue('color');
  682. FW_arrowRight = FW_arrowRight.replace(/rgb[^)]*\)/,col);
  683. FW_arrowDown = FW_arrowDown.replace(/rgb[^)]*\)/,col);
  684. $("div#menu table.room tr.menuTree > td > div > div")
  685. .css("background-image", "url('"+FW_arrowRight+"')");
  686. $("div#menu table.room tr.menuTree.open > td > div > div")
  687. .css("background-image", "url('"+FW_arrowDown+"')");
  688. }
  689. }
  690. }
  691. // SVG color tuning
  692. function
  693. f18_svgSetCols(svg)
  694. {
  695. function col(n) { return f18_getAttr("cols."+n, true) };
  696. if(!svg || !svg.getAttribute("data-origin"))
  697. return;
  698. var style = $(svg).find("> style").first();
  699. var sTxt = $(style).text();
  700. sTxt = sTxt.replace(/font-family:Times/, "fill:#"+col("fg"));
  701. $(style).text(sTxt);
  702. function
  703. addCol(c, d)
  704. {
  705. var r="";
  706. for(var i1=0; i1<6; i1+=2) {
  707. var n = parseInt(c.substr(i1,2), 16);
  708. n += d;
  709. if(n>255) n = 255;
  710. if(n< 0) n = 0;
  711. n = n.toString(16);
  712. if(n.length < 2)
  713. n = "0"+n;
  714. r += n;
  715. }
  716. return r;
  717. }
  718. // SVG background gradient: .css does not work in Firefox, has to use .attr
  719. var stA = $(svg).find("> defs > #gr_bg").children();
  720. var so = "; stop-opacity:1;";
  721. $(stA[0]).attr("style", "stop-color:#"+addCol(col("bg"),10)+so);
  722. $(stA[1]).attr("style", "stop-color:#"+addCol(col("bg"),-10)+so);
  723. }
  724. // font-awesome
  725. var f18_svgPrefix='data:image/svg+xml;utf8,<svg viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path fill="gray" ';
  726. f18_icon.pinIn=f18_svgPrefix+'d="M896 1088q66 0 128-15v655q0 26-19 45t-45 19h-128q-26 0-45-19t-19-45v-655q62 15 128 15zm0-1088q212 0 362 150t150 362-150 362-362 150-362-150-150-362 150-362 362-150zm0 224q14 0 23-9t9-23-9-23-23-9q-146 0-249 103t-103 249q0 14 9 23t23 9 23-9 9-23q0-119 84.5-203.5t203.5-84.5z"/></svg>';
  727. f18_icon.bars=f18_svgPrefix+'d="M1664 1344v128q0 26-19 45t-45 19h-1408q-26 0-45-19t-19-45v-128q0-26 19-45t45-19h1408q26 0 45 19t19 45zm0-512v128q0 26-19 45t-45 19h-1408q-26 0-45-19t-19-45v-128q0-26 19-45t45-19h1408q26 0 45 19t19 45zm0-512v128q0 26-19 45t-45 19h-1408q-26 0-45-19t-19-45v-128q0-26 19-45t45-19h1408q26 0 45 19t19 45z"/></svg>';
  728. f18_icon.arrows=f18_svgPrefix+'d="M1792 896q0 26-19 45l-256 256q-19 19-45 19t-45-19-19-45v-128h-384v384h128q26 0 45 19t19 45-19 45l-256 256q-19 19-45 19t-45-19l-256-256q-19-19-19-45t19-45 45-19h128v-384h-384v128q0 26-19 45t-45 19-45-19l-256-256q-19-19-19-45t19-45l256-256q19-19 45-19t45 19 19 45v128h384v-384h-128q-26 0-45-19t-19-45 19-45l256-256q19-19 45-19t45 19l256 256q19 19 19 45t-19 45-45 19h-128v384h384v-128q0-26 19-45t45-19 45 19l256 256q19 19 19 45z"/></svg>';
  729. f18_icon.ban=f18_svgPrefix+'d="M1440 893q0-161-87-295l-754 753q137 89 297 89 111 0 211.5-43.5t173.5-116.5 116-174.5 43-212.5zm-999 299l755-754q-135-91-300-91-148 0-273 73t-198 199-73 274q0 162 89 299zm1223-299q0 157-61 300t-163.5 246-245 164-298.5 61-298.5-61-245-164-163.5-246-61-300 61-299.5 163.5-245.5 245-164 298.5-61 298.5 61 245 164 163.5 245.5 61 299.5z"/></svg>';
  730. /*!
  731. * jQuery UI Touch Punch 0.2.3
  732. *
  733. * Copyright 2011-2014, Dave Furfero
  734. * Dual licensed under the MIT or GPL Version 2 licenses.
  735. *
  736. * Depends:
  737. * jquery.ui.widget.js
  738. * jquery.ui.mouse.js
  739. */
  740. !function(a){function f(a,b){if(!(a.originalEvent.touches.length>1)){a.preventDefault();var c=a.originalEvent.changedTouches[0],d=document.createEvent("MouseEvents");d.initMouseEvent(b,!0,!0,window,1,c.screenX,c.screenY,c.clientX,c.clientY,!1,!1,!1,!1,0,null),a.target.dispatchEvent(d)}}if(a.support.touch="ontouchend"in document,a.support.touch){var e,b=a.ui.mouse.prototype,c=b._mouseInit,d=b._mouseDestroy;b._touchStart=function(a){var b=this;!e&&b._mouseCapture(a.originalEvent.changedTouches[0])&&(e=!0,b._touchMoved=!1,f(a,"mouseover"),f(a,"mousemove"),f(a,"mousedown"))},b._touchMove=function(a){e&&(this._touchMoved=!0,f(a,"mousemove"))},b._touchEnd=function(a){e&&(f(a,"mouseup"),f(a,"mouseout"),this._touchMoved||f(a,"click"),e=!1)},b._mouseInit=function(){var b=this;b.element.bind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),c.call(b)},b._mouseDestroy=function(){var b=this;b.element.unbind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),d.call(b)}}}(jQuery);