Skip to content

Commit

Permalink
Merge pull request #33 from hyperaudio/27-autoscroll-init
Browse files Browse the repository at this point in the history
27 autoscroll init
  • Loading branch information
maboa authored Feb 17, 2021
2 parents d7102e2 + d31c291 commit 8fbac7f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -993,9 +993,11 @@ <h5 data-m="214800">What kind of help is available for people to manage their ow

// minimizedMode is still experimental - it aims to show the current words in the title, which can be seen on the browser tab.
var minimizedMode = false;
var autoScroll = true;

var ht1 = hyperaudiolite();
ht1.init("hypertranscript", "hyperplayer", minimizedMode);
ht1.init("hypertranscript", "hyperplayer", minimizedMode, autoScroll);
//ht1.setScrollParameters(<duration>, <delay>, <offset>, <container>);

</script>

Expand Down
57 changes: 44 additions & 13 deletions js/hyperaudio-lite.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! (C) The Hyperaudio Project. MIT @license: en.wikipedia.org/wiki/MIT_License. */
/*! Version 1.1.3 */
/*! Version 1.1.4 */

'use strict';

Expand All @@ -22,10 +22,15 @@ var hyperaudiolite = (function () {
windowHash,
hashArray,
hashVar,
velocity;
scroller,
scrollerContainer,
scrollerDuration,
scrollerDelay,
scrollerOffset,
autoscroll;


function init(mediaElementId, m) {
function init(mediaElementId, m, a) {

windowHash = window.location.hash;

Expand All @@ -50,6 +55,12 @@ var hyperaudiolite = (function () {
textShot = "";
wordIndex = 0;

autoscroll = a;
scrollerContainer = transcript;
scrollerOffset = 0;
scrollerDuration = 800;
scrollerDelay = 0;

//Create the array of timed elements (wordArr)

var words = transcript.querySelectorAll('[data-m]');
Expand Down Expand Up @@ -162,9 +173,11 @@ var hyperaudiolite = (function () {
}
}

velocity = window.Velocity || window.jQuery.Velocity;
scroller = window.Velocity || window.jQuery.Velocity;
}



function getSelectionMediaFragment() {

var fragment = "";
Expand Down Expand Up @@ -350,12 +363,23 @@ var hyperaudiolite = (function () {

if (currentParaIndex != paraIndex) {

if (typeof velocity !== 'undefined') {
velocity(scrollNode, "scroll", {
container: transcript,
duration: 800,
delay: 0
});
if (typeof scroller !== 'undefined' && autoscroll === true) {

if (typeof(scrollerContainer) !== 'undefined' && scrollerContainer !== null) {

scroller(scrollNode, "scroll", {
container: scrollerContainer,
duration: scrollerDuration,
delay: scrollerDelay,
offset: scrollerOffset
});
} else {
scroller(scrollNode, "scroll", {
duration: scrollerDuration,
delay: scrollerDelay,
offset: scrollerOffset
});
}
}

newPara = true;
Expand Down Expand Up @@ -397,12 +421,19 @@ var hyperaudiolite = (function () {

}

hal.init = function(transcriptId, mediaElementId, minimizedMode) {
hal.init = function(transcriptId, mediaElementId, minimizedMode, autoscroll) {
transcript = document.getElementById(transcriptId);
init(mediaElementId, minimizedMode);
init(mediaElementId, minimizedMode, autoscroll);
//set minimizedMode is an experimental feature
}

hal.setScrollParameters = function(duration, delay, offset, container) {
scrollerContainer = container;
scrollerDuration = duration;
scrollerDelay = delay;
scrollerOffset = offset;
}

return hal;

});
});

0 comments on commit 8fbac7f

Please sign in to comment.