Skip to content

Commit

Permalink
Tabindex (#3)
Browse files Browse the repository at this point in the history
* Feature/scroll to center (#1)

* Auto scroll to the center of transcripts block.

* Fix bower.json syntax.
  • Loading branch information
xahgmah authored and dorosh committed Mar 21, 2017
1 parent a383c47 commit be71451
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ object may contain any of the following properties:

Set to false to disable autoscrolling.

#### scrollToCenter
**Default:** false

By default current row shows on the bottom on autoscrolling. Set to true to show it in the center

#### clickArea
**Default:** 'line'

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "videojs-transcript",
"version": "0.1",
"dependencies": {
"video-js": "5.13.1",
"video-js": "5.13.1"
},
"homepage": "https://github.com/raccoongang/videojs-transcript",
"authors": [
Expand Down
13 changes: 9 additions & 4 deletions dist/videojs-transcript.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ var defaults = {
showTitle: true,
showTrackSelector: true,
followPlayerTrack: true,
scrollToCenter: false,
stopScrollWhenInUse: true,
};

Expand Down Expand Up @@ -246,17 +247,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
2 changes: 1 addition & 1 deletion dist/videojs-transcript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit be71451

Please sign in to comment.