Skip to content

Instantly share code, notes, and snippets.

@houhr
Last active February 15, 2017 17:54
Show Gist options
  • Select an option

  • Save houhr/5bf4777c08280305c9f1 to your computer and use it in GitHub Desktop.

Select an option

Save houhr/5bf4777c08280305c9f1 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Clock</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
ul {
list-style: none;
margin: 0;
padding: 0;
}
div {
height: 60px;
margin-bottom: 10px;
}
button {
width: 49%;
margin-bottom: 10px;
padding: 0;
height: 50px;
border: 0;
background-color: #ccc;
}
#rainbow {
float: left;
}
#theater {
float: right;
}
</style>
</head>
<body>
<ul>
<li>
<div></div>
</li>
<li>
<div></div>
</li>
<li>
<div></div>
</li>
<li>
<div></div>
</li>
<li>
<div></div>
</li>
<li>
<div></div>
</li>
<li>
<div></div>
</li>
<li>
<div></div>
</li>
<li>
<div></div>
</li>
</ul>
<button id="rainbow">Rainbow</button>
<button id="theater">Theater</button>
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script>
var colors = ['FF8000', 'FFFF00', '80FF00', '00FF00', '00FF80', '00FFFF', '0080FF', '0000FF', '8000FF'];
var requestObject = {};
function hexToR(hex) {
return parseInt(hex.substring(0, 2), 16);
}
function hexToG(hex) {
return parseInt(hex.substring(2, 4), 16);
}
function hexToB(hex) {
return parseInt(hex.substring(4, 6), 16);
}
function pushToParse(object) {
console.log(object.data);
$.ajax({
type:"POST",
beforeSend: function (request) {
request.setRequestHeader("X-Parse-Application-Id", "YOUR APPLICATION ID HERE");
request.setRequestHeader("X-Parse-REST-API-Key", "YOUR CLIENT KEY HERE");
},
url: "https://api.parse.com/1/push",
data: JSON.stringify(object),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
console.log(msg);
},
error: function (errormessage) {
console.log(errormessage);
}
});
}
$('#rainbow').on('click', function() {
requestObject = {
"where": {},
"data": {
"mode": 2
}
};
pushToParse(requestObject);
});
$('#theater').on('click', function() {
requestObject = {
"where": {},
"data": {
"mode": 3
}
};
pushToParse(requestObject);
});
$('div').each(function(index) {
$(this).css('background-color', '#' + colors[index])
.on('click', function() {
requestObject = {
"where": {},
"data": {
"mode": 1,
"r": hexToR(colors[index]),
"g": hexToG(colors[index]),
"b": hexToB(colors[index])
}
};
pushToParse(requestObject);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment