Skip to content

Commit

Permalink
Merge pull request katspaugh#623 from nabiulin/master
Browse files Browse the repository at this point in the history
Added custom time formatter callback
  • Loading branch information
katspaugh committed Jan 22, 2016
2 parents c9040bc + f211845 commit 220b43e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions example/timeline/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ <h4>Options</h4>
<li><code>timeInterval</code> - number of intervals that records consists of. Usually it is equal to the duration in minutes.</li>
<li><code>primaryLabelInterval</code> - number of primary time labels.</li>
<li><code>secondaryLabelInterval</code> - number of secondary time labels (Time labels between primary labels).</li>
<li><code>formatTimeCallback</code> - custom time format callback.</li>
</ul>
</div>
</div>
Expand Down
8 changes: 7 additions & 1 deletion plugin/wavesurfer.timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
this.timeInterval = this.params.timeInterval;
this.primaryLabelInterval = this.params.primaryLabelInterval;
this.secondaryLabelInterval = this.params.secondaryLabelInterval;
this.formatTimeCallback = this.params.formatTimeCallback;

this.createWrapper();
this.createCanvas();
Expand Down Expand Up @@ -118,7 +119,8 @@
drawTimeCanvas: function() {
var backend = this.wavesurfer.backend,
wsParams = this.wavesurfer.params,
duration = backend.getDuration();
duration = backend.getDuration(),
self = this;

if (wsParams.fillParent && !wsParams.scrollParent) {
var width = this.drawer.getWidth();
Expand All @@ -132,6 +134,10 @@
curSeconds = 0,
totalSeconds = parseInt(duration, 10) + 1,
formatTime = function(seconds) {
if (typeof self.formatTimeCallback === 'function') {
return self.formatTimeCallback(seconds);
}

if (seconds/60 > 1) {
var minutes = parseInt(seconds / 60),
seconds = parseInt(seconds % 60);
Expand Down

0 comments on commit 220b43e

Please sign in to comment.