|
Last change
on this file was
7477,
checked in by Russ Tyndall, 14 years ago
|
|
Made the stopwatch component less susceptible to browser flakiness and jsavascript slowdown. (Thanks T.R.Chuan)
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | /** |
|---|
| 2 | * Copyright (C) 2010, Tay Ray Chuan |
|---|
| 3 | */ |
|---|
| 4 | |
|---|
| 5 | /* toggles the stopwatch (and controls) with a simple slide */ |
|---|
| 6 | jQuery(function($) { |
|---|
| 7 | Toggler = function() { |
|---|
| 8 | var m_state; |
|---|
| 9 | |
|---|
| 10 | var should_show = true; |
|---|
| 11 | var toggler = $('<div class="stopwatch-button">Show stopwatch</div>'); |
|---|
| 12 | |
|---|
| 13 | toggler.bind("show", function() { should_show = true; }); |
|---|
| 14 | toggler.bind("hide", function() { should_show = false; }); |
|---|
| 15 | |
|---|
| 16 | toggler.click(function() { |
|---|
| 17 | if (!should_show) { |
|---|
| 18 | $(this).trigger("show"); |
|---|
| 19 | } else |
|---|
| 20 | $(this).trigger("hide"); |
|---|
| 21 | }); |
|---|
| 22 | |
|---|
| 23 | toggler.bind("hide", |
|---|
| 24 | function() { |
|---|
| 25 | this.firstChild.nodeValue = 'Show stopwatch'; |
|---|
| 26 | } |
|---|
| 27 | ); |
|---|
| 28 | toggler.bind("show", |
|---|
| 29 | function() { |
|---|
| 30 | if (m_state.reset) |
|---|
| 31 | this.firstChild.nodeValue = 'Hide stopwatch'; |
|---|
| 32 | else |
|---|
| 33 | this.firstChild.nodeValue = 'Use stopwatch value'; |
|---|
| 34 | } |
|---|
| 35 | ); |
|---|
| 36 | var continue_handler = function() { |
|---|
| 37 | toggler.hide("fast"); |
|---|
| 38 | }; |
|---|
| 39 | var pause_handler = function() { |
|---|
| 40 | toggler[0].firstChild.nodeValue = 'Use stopwatch value'; |
|---|
| 41 | toggler.show("fast"); |
|---|
| 42 | }; |
|---|
| 43 | var reset_handler = function() { |
|---|
| 44 | toggler[0].firstChild.nodeValue = 'Hide stopwatch'; |
|---|
| 45 | }; |
|---|
| 46 | |
|---|
| 47 | return { |
|---|
| 48 | toggler: toggler, |
|---|
| 49 | |
|---|
| 50 | continue_handler: continue_handler, |
|---|
| 51 | pause_handler: pause_handler, |
|---|
| 52 | reset_handler: reset_handler, |
|---|
| 53 | |
|---|
| 54 | init: function(state) { |
|---|
| 55 | m_state = state; |
|---|
| 56 | } |
|---|
| 57 | }; |
|---|
| 58 | }(); |
|---|
| 59 | }); |
|---|
Note: See
TracBrowser
for help on using the repository browser.