| 1 | /** |
|---|
| 2 | * Copyright (C) 2010, Tay Ray Chuan |
|---|
| 3 | */ |
|---|
| 4 | |
|---|
| 5 | jQuery(function($) { |
|---|
| 6 | var state = { |
|---|
| 7 | running: false, |
|---|
| 8 | reset: false, |
|---|
| 9 | use_value: false |
|---|
| 10 | }; |
|---|
| 11 | var field = $("input#field-hours"); |
|---|
| 12 | var stopwatch = $('<div></div>'); |
|---|
| 13 | stopwatch.append(StopwatchDisplay.display); |
|---|
| 14 | stopwatch.append(StopwatchControls.controls); |
|---|
| 15 | stopwatch.append($('<div class="clearer"></div>')); |
|---|
| 16 | |
|---|
| 17 | StopwatchControls.init(state); |
|---|
| 18 | |
|---|
| 19 | StopwatchControls.controls.bind("pause", StopwatchDisplay.pause_stopwatch); |
|---|
| 20 | StopwatchControls.controls.bind("continue", StopwatchDisplay.continue_stopwatch); |
|---|
| 21 | StopwatchControls.controls.bind("reset", StopwatchDisplay.reset_stopwatch); |
|---|
| 22 | |
|---|
| 23 | Toggler.init(state); |
|---|
| 24 | |
|---|
| 25 | Toggler.toggler.bind("show", function() { stopwatch.show("fast") }); |
|---|
| 26 | Toggler.toggler.bind("hide", function() { |
|---|
| 27 | if (state.use_value) field[0].value = StopwatchDisplay.get_hours(); |
|---|
| 28 | }); |
|---|
| 29 | Toggler.toggler.bind("hide", function() { stopwatch.hide("fast") }); |
|---|
| 30 | |
|---|
| 31 | StopwatchControls.controls.bind("pause", Toggler.pause_handler); |
|---|
| 32 | StopwatchControls.controls.bind("continue", Toggler.continue_handler); |
|---|
| 33 | StopwatchControls.controls.bind("reset", Toggler.reset_handler); |
|---|
| 34 | |
|---|
| 35 | /* put toggler and stopwatch in a div, then put it below the hours <input> |
|---|
| 36 | * field. */ |
|---|
| 37 | field.after( |
|---|
| 38 | $('<div></div>') |
|---|
| 39 | .append(Toggler.toggler) |
|---|
| 40 | .append($('<div class="clearer"></div>')) |
|---|
| 41 | .append(stopwatch)); |
|---|
| 42 | |
|---|
| 43 | /* initialize */ |
|---|
| 44 | StopwatchControls.controls.trigger("reset"); |
|---|
| 45 | Toggler.toggler.trigger("hide"); |
|---|
| 46 | }) |
|---|