Skip to content

Commit

Permalink
Implement refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob McGuire-Dale committed Feb 4, 2013
1 parent 25cc488 commit 2f9dcd2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
20 changes: 20 additions & 0 deletions demo/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Selectors
var BOARD_SEL = "#sudoku-board";
var TABS_SEL = "#generator-tabs";
var CONTROLS_SEL = "#puzzle-controls";

// Boards
var boards = {
Expand Down Expand Up @@ -61,6 +62,21 @@ var init_tabs = function(){
});
};

var init_controls = function(){
/* Initialize the puzzle controls
*/
$(CONTROLS_SEL + " #refresh").click(function(e){
/* Refresh the current puzzle
*/
e.preventDefault();
var $selected_tab = $(TABS_SEL + " li.active a");
var tab_name = $selected_tab.attr("id");
if(tab_name !== "import"){
show_puzzle(tab_name, true);
}
});
};

var show_puzzle = function(difficulty, refresh){
/* Show the puzzle of the specified difficulty. If the board has not been
generated yet, generate a new one and save. Optionally, set `refresh` to
Expand Down Expand Up @@ -107,4 +123,8 @@ var display_puzzle = function(board){
$(function(){
build_board();
init_tabs();
init_controls();

// Start with generating an easy puzzle
$(TABS_SEL + " #easy").click();
});
8 changes: 7 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h1>Sudoku.js Demo</h1>

<!-- Tabs -->
<ul id="generator-tabs" class="nav nav-tabs">
<li class="active">
<li>
<a id="easy" href="#">Easy</a>
</li>
<li>
Expand All @@ -72,6 +72,12 @@ <h1>Sudoku.js Demo</h1>
</li>
</ul>

<div id="puzzle-controls">
<a id="refresh" class="pull-right" href="#">
Refresh
</a>
</div>

<!-- Sudoku board -->
<table class="table table-striped">
<tbody id="sudoku-board"></tbody>
Expand Down

0 comments on commit 2f9dcd2

Please sign in to comment.