Skip to content

Commit

Permalink
Merge pull request #20 from raccoongang/master
Browse files Browse the repository at this point in the history
Add tabindex support, bower.json, refactor scroll-to-center
  • Loading branch information
walsh9 authored May 4, 2017
2 parents 76f96a0 + fa916ff commit 3b9b2cf
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 14 deletions.
21 changes: 21 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "videojs-transcript",
"version": "0.8.1",
"dependencies": {
"video.js": "^5.6.0"
},
"homepage": "https://github.com/walsh9/videojs-transcript",
"authors": [
"walsh9"
],
"description": "",
"main": "",
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
10 changes: 6 additions & 4 deletions dist/videojs-transcript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! videojs-transcript - v0.8.0 - 2016-02-21
* Copyright (c) 2016 Matthew Walsh; Licensed MIT */
/*! videojs-transcript - v0.8.1 - 2017-04-21
* Copyright (c) 2017 Matthew Walsh; Licensed MIT */
(function (window, videojs) {
'use strict';

Expand Down Expand Up @@ -376,6 +376,7 @@ var widget = function (plugin) {
var timestamp = utils.createEl('span', '-timestamp');
var text = utils.createEl('span', '-text');
line.setAttribute('data-begin', cue.startTime);
line.setAttribute('tabindex', my._options.tabIndex || 0);
timestamp.textContent = utils.secondsToTime(cue.startTime);
text.innerHTML = cue.text;
line.appendChild(timestamp);
Expand Down Expand Up @@ -415,8 +416,9 @@ var widget = function (plugin) {
}

};
var create = function () {
var create = function (options) {
var el = document.createElement('div');
my._options = options;
my.element = el;
el.setAttribute('id', plugin.prefix + '-' + plugin.player.id());
if (plugin.settings.showTitle) {
Expand Down Expand Up @@ -477,7 +479,7 @@ var transcript = function (options) {
my.validTracks = trackList.get();
my.currentTrack = trackList.active(my.validTracks);
my.settings = videojs.mergeOptions(defaults, options);
my.widget = widget.create();
my.widget = widget.create(options);
var timeUpdate = function () {
my.widget.setCue(my.player.currentTime());
};
Expand Down
6 changes: 3 additions & 3 deletions dist/videojs-transcript.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "videojs-transcript",
"version": "0.8.0",
"version": "0.8.1",
"author": "Matthew Walsh",
"description": "Creates interactive transcripts from text tracks.",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var transcript = function (options) {
my.validTracks = trackList.get();
my.currentTrack = trackList.active(my.validTracks);
my.settings = videojs.mergeOptions(defaults, options);
my.widget = widget.create();
my.widget = widget.create(options);
var timeUpdate = function () {
my.widget.setCue(my.player.currentTime());
};
Expand Down
1 change: 1 addition & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ var defaults = {
showTitle: true,
showTrackSelector: true,
followPlayerTrack: true,
scrollToCenter: false,
stopScrollWhenInUse: true,
};
12 changes: 8 additions & 4 deletions src/scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,21 @@ var scrollerProto = function(plugin) {
var elementOffsetBottom = element.offsetTop + element.clientHeight;
var relTop = element.offsetTop - parent.offsetTop;
var relBottom = (element.offsetTop + element.clientHeight) - parent.offsetTop;
var centerPosCorrection = 0;
var newPos;

if (plugin.settings.scrollToCenter){
centerPosCorrection = Math.round(parent.clientHeight/2 - element.clientHeight/2);
}
// If the top of the line is above the top of the parent view, were scrolling up,
// so we want to move the top of the element downwards to match the top of the parent.
if (relTop < parent.scrollTop) {
newPos = element.offsetTop - parent.offsetTop;
if (relTop < parent.scrollTop + centerPosCorrection) {
newPos = element.offsetTop - parent.offsetTop -centerPosCorrection;

// If the bottom of the line is below the parent view, we're scrolling down, so we want the
// bottom edge of the line to move up to meet the bottom edge of the parent.
} else if (relBottom > (parent.scrollTop + parent.clientHeight)) {
newPos = elementOffsetBottom - parentOffsetBottom;
} else if (relBottom > (parent.scrollTop + parent.clientHeight) - centerPosCorrection) {
newPos = elementOffsetBottom - parentOffsetBottom + centerPosCorrection;
}

// Don't try to scroll if we haven't set a new position. If we didn't
Expand Down
4 changes: 3 additions & 1 deletion src/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var widget = function (plugin) {
var timestamp = utils.createEl('span', '-timestamp');
var text = utils.createEl('span', '-text');
line.setAttribute('data-begin', cue.startTime);
line.setAttribute('tabindex', my._options.tabIndex || 0);
timestamp.textContent = utils.secondsToTime(cue.startTime);
text.innerHTML = cue.text;
line.appendChild(timestamp);
Expand Down Expand Up @@ -88,8 +89,9 @@ var widget = function (plugin) {
}

};
var create = function () {
var create = function (options) {
var el = document.createElement('div');
my._options = options;
my.element = el;
el.setAttribute('id', plugin.prefix + '-' + plugin.player.id());
if (plugin.settings.showTitle) {
Expand Down

0 comments on commit 3b9b2cf

Please sign in to comment.