Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

A lot of fixes in the JavaScript files to enhance UI experience, inte…

…grate sound.
  • Loading branch information...
commit a6048caed6f03dd526c282d520033bddc896c5a1 1 parent 4c40745
@dsimmons authored
Showing with 23 additions and 12 deletions.
  1. +1 −0  index.html
  2. +21 −2 js/dom.js
  3. +1 −10 js/main.js
View
1  index.html
@@ -41,6 +41,7 @@
<button class="btn">5y</button>
<button class="btn">10y</button>
</div>
+ <div id="player"></div>
</div>
View
23 js/dom.js
@@ -2,10 +2,12 @@ $(function() {
var w = 800;
var h = 400;
+ audio = null;
// Select 1Y resolution by default
$(document).ready( function() {
$('#default_resolution').button('toggle');
+ $('#ticker').focus();
});
// Map 'space' to hitting "play"
@@ -16,7 +18,9 @@ $(function() {
// Reset buttons if changing ticker symbol.
$('#ticker').focus( function() {
$('#download').button('reset');
- $('#play').addClass('disabled').removeClass('btn-success');
+ $('#play').addClass('disabled').removeClass('btn-success btn-warning');
+ $('#play > i').attr('class', 'icon-play');
+ if (audio) audio.pause();
});
// Allow enter key to simulate clicking "download data" button
@@ -69,7 +73,22 @@ $(function() {
$('#play').click( function() {
// If the play button is green and ready to be pressed...
if ( ! ($('#play').hasClass('disabled')) ) {
- playReturnSeriesSonification(0.1);
+
+ if ($('#play').hasClass('btn-success')) {
+
+ playReturnSeriesSonification(0.1);
+ $('#play')
+ .removeClass('btn-success')
+ .addClass('btn-warning');
+ $('#play > i').attr('class', 'icon-pause');
+
+ } else if ($('#play').hasClass('btn-warning')) {
+ audio.pause();
+ $('#play')
+ .removeClass('btn-warning')
+ .addClass('btn-success');
+ $('#play > i').attr('class', 'icon-play');
+ }
}
});
});
View
11 js/main.js
@@ -1,5 +1,4 @@
function getYahooTimeSeriesData(symbol, years, fn) {
-
var now = new Date();
var before = new Date();
before.setFullYear(now.getFullYear() - years);
@@ -145,7 +144,7 @@ function playReturnSeriesSonification(timeOfOneBar) {
wave.Make(sound);
- var audio = new Audio(wave.dataURI);
+ audio = new Audio(wave.dataURI);
$(audio).on('timeupdate', function(e) {
var dataPointOn = Math.round(map(audio.currentTime, 0, audio.duration, 0, dataLength));
@@ -153,14 +152,6 @@ function playReturnSeriesSonification(timeOfOneBar) {
audio.volume = map(timeSeriesData[dataPointOn].volume, lowestVolume, highestVolume, 0.1, 0.9);
});
- play(audio);
-}
-
-
-function play(audio) {
- if (!audio.paused) { // if playing stop and rewind
- audio.pause();
- }
audio.play();
}
Please sign in to comment.
Something went wrong with that request. Please try again.