Created
May 27, 2011 17:03
-
-
Save stealth35/995692 to your computer and use it in GitHub Desktop.
jwsummary
This file contains 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
(function (jwplayer) { | |
var template = function (player, config, div) { | |
function setup(event) { | |
config.links = []; | |
config.last = null; | |
var summary = document.getElementById(config.id); | |
if (summary) { | |
var links = summary.getElementsByTagName('a'); | |
var i; | |
for (i = 0; i < links.length; ++i) { | |
var link = links[i]; | |
var time = getLinkTime(link); | |
if (link.addEventListener) { | |
link.addEventListener('click', onButtonClick, false); | |
} else { | |
link.attachEvent('onclick', onButtonClick); | |
} | |
config.links.push({'link' : link, 'time' : time}); | |
} | |
player.onTime(onTimeEvent); | |
} | |
var seek = getLinkTime(window.location); | |
if (seek !== false) { | |
player.seek(seek); | |
} | |
} | |
function onTimeEvent(event) { | |
var i; | |
for (i = 0; i < config.links.length; ++i) { | |
var link = config.links[i].link; | |
var time = config.links[i].time; | |
if (link !== config.last && time <= event.position) { | |
onChangeStyle(link); | |
} | |
} | |
} | |
function onButtonClick(event) { | |
if (event.preventDefault) { | |
event.preventDefault(); | |
} else { | |
event.returnValue = false; | |
} | |
var link; | |
if (event.target) { | |
link = event.target; | |
} else { | |
link = event.srcElement; | |
} | |
var seek = getLinkTime(link); | |
if (seek !== false) { | |
player.seek(seek); | |
} | |
onChangeStyle(link); | |
} | |
function onChangeStyle(id) { | |
if (config.last) { | |
config.last.style.fontWeight = 'normal'; | |
} | |
config.last = id; | |
config.last.style.fontWeight = 'bold'; | |
} | |
function getLinkTime(link) { | |
var time = false; | |
if (link === window.location) { | |
var options = link.hash.split(/\-/); | |
var id = options[0].substr(1); | |
if (id === player.id) { | |
time = options[1]; | |
} | |
} else { | |
time = link.href.substr(link.href.lastIndexOf('#') + 1); | |
} | |
if (parseInt(time, 10) >= 0) { | |
return time; | |
} | |
return false; | |
} | |
player.onReady(setup); | |
}; | |
jwplayer().registerPlugin('jwsummary', template); | |
}(jwplayer)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment