Skip to content

Instantly share code, notes, and snippets.

@noahpryor
Created July 15, 2014 00:38
Show Gist options
  • Select an option

  • Save noahpryor/8947b2ee369766b4f977 to your computer and use it in GitHub Desktop.

Select an option

Save noahpryor/8947b2ee369766b4f977 to your computer and use it in GitHub Desktop.
minesweeper
<%= num_rows = 10 %>
<%= num_cols = 10 %>
<%= [[[""]][false]]
<table>
<thead></thead>
<tbody>
<% (0...num_row).each do |row| %>
<tr>
<% (0...num_cols).each do |col| %>
<td data-col="<%=col%>" data-row="<%=row%>"> <button class="btn" data-kind="flag">Flag</button><button class="btn" data-kind="check">Check</button></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<script>
var railsEndpoint = "/positions/query.json";
var handleCellResponse = function(response) {
var data = JSON.parse(response.data);
console.log(data)
if(data.status == "mine") {
cell.text = "mine"
}
else if(data.status == "count") {
cell.text "blah" //you get the idea
}
}
$(".flat-button").on('click',function(item) {
var cell = $(item).parent('td');
var queryData = cell.data();
queryData.kind = $(item).data().kind;
$.get((railsEndpoint, cellPosition),handleCellResponse)
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment