Mercurial > code > home > repos > homeauto
changeset 929:e7532dfa1a39
fix up garagearduino web ui color pickers
Ignore-this: e8cf01ec95116ef6cf0bc4be80ea5aee
darcs-hash:20130929091649-312f9-3c50acdcac62c06ac4373c0ec19cc5e39557b0fc
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Sun, 29 Sep 2013 02:16:49 -0700 |
parents | 9d96882a742c |
children | 23d47a9a968b |
files | service/garageArduino/index.html |
diffstat | 1 files changed, 44 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/service/garageArduino/index.html Sun Sep 29 01:34:01 2013 -0700 +++ b/service/garageArduino/index.html Sun Sep 29 02:16:49 2013 -0700 @@ -10,6 +10,9 @@ .val { font-weight: bold; } +.colorpicker { + display: inline-block; +} /* ]]> */ </style> </head> @@ -29,12 +32,16 @@ <p><button type="submit" id="refresh">refresh</button></p> - <p>Bathroom shiftbrite</p> + <p>Bathroom LEDs</p> + <div><input id="lockColor" type="checkbox"/> Send first color to all LEDs</div> <div class="colorpicker" id="p0"></div> + <div class="colorpicker" id="p1"></div> + <div class="colorpicker" id="p2"></div> + <div class="colorpicker" id="p3"></div> - <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"/> - <script type="text/javascript" src="http://bigasterisk.com/bathroomLight/static/farbtastic/farbtastic.js"></script> - <link rel="stylesheet" href="http://bigasterisk.com/bathroomLight/static/farbtastic/farbtastic.css" type="text/css" /> + <script type="text/javascript" src="//bigasterisk.com/lib/jquery-2.0.3.min.js"/> + <script type="text/javascript" src="//bigasterisk.com/lib/farbtastic-1.2/farbtastic.js"></script> + <link rel="stylesheet" href="//bigasterisk.com/lib/farbtastic-1.2/farbtastic.css" type="text/css" /> <script type="text/javascript"> // <![CDATA[ @@ -76,14 +83,43 @@ refresh(); $("#refresh").click(refresh); + var inProgress = false; + var pending = {}; // url : data + function sendColor(url, newColor) { + inProgress = 1; + $.ajax({ + type: "put", url: url, + contentType: "text/plain", data: newColor, + success: function () { + inProgress = false; + $.each(pending, function (u, n) { + delete pending[u]; + sendColor(u, n); + }); + } + }); + } + function copyColor(newColor) { + $.farbtastic("#p1").setColor(newColor); + $.farbtastic("#p2").setColor(newColor); + $.farbtastic("#p3").setColor(newColor); + } + $("#lockColor").click(function () { copyColor($.farbtastic("#p0").color); }); $.each([ ["#p0", "brite/0"], + ["#p1", "brite/1"], + ["#p2", "brite/2"], + ["#p3", "brite/3"], ], function (i, row) { var picker = $.farbtastic(row[0], function (newColor) { - $.ajax({ - type: "put", url: row[1], - contentType: "text/plain", data: newColor - }); + if (row[1] == "brite/0" && $("#lockColor")[0].checked) { + copyColor(newColor); + } + if (inProgress) { + pending[row[1]] = newColor; + return; + } + sendColor(row[1], newColor); }); $.get(row[1], picker.setColor); });