Created
February 5, 2018 19:23
-
-
Save stephenorem/95226160cefe9fba6009d9db18de2aa8 to your computer and use it in GitHub Desktop.
Load parameters into html elements on page load, for later use as user interacts with page/video player. Handle player when user interacts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.onreadystatechange = function () { | |
if (document.readyState === 'complete') { | |
var els = document.getElementsByClassName("vidlink"); | |
// assign attributes needed for actions, self invoking on page load | |
(function () { | |
Array.prototype.forEach.call(els, function(el, i){ | |
var newAtts = ["data-vidname", "data-vidlect"]; | |
var newNames = ["vidname", "vidlect"]; | |
Array.prototype.forEach.call(newAtts, function(newAtt, j){ | |
// meaning, myparams["data-vidname"][vidname], [vidlect] | |
// for each newAtt, set correct value | |
el.setAttribute(newAtt, myparams[i][newNames[j]]); | |
}); | |
}); | |
})(); | |
// on click on element, resets video info in player in separate div | |
Array.prototype.forEach.call(els, function(el){ | |
el.addEventListener("click", function(e){ | |
e.preventDefault(); | |
var vidlect = parseInt(el.getAttribute('data-vidlect')); | |
jwplayer().stop(); | |
// load video at index in playlist | |
jwplayer().playlistItem(vidlect); | |
document.getElementById("content").scrollIntoView(); | |
}); | |
}); | |
} | |
}; | |
// data required to set attributes, control player | |
var myparams = { | |
"0": { "vidname": "Intro", "vidlect": "0" }, | |
"1": { "vidname": "More", "vidlect": "1" } | |
// etc ... | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment