Created
April 18, 2011 08:34
-
-
Save rymai/924995 to your computer and use it in GitHub Desktop.
SublimeVideo: Interactive thumbnails JavaScript code (Prototype)
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
var SublimeVideo = SublimeVideo || {}; | |
var InteractiveThumbnailsHandler = Class.create({ | |
initialize: function(interactiveWrapperId) { | |
this.interactiveWrapperId = interactiveWrapperId; | |
this.videosCount = $$("#" + interactiveWrapperId + " .video_wrap").size(); | |
$$("#" + this.interactiveWrapperId + " li").each(function(thumb) { | |
thumb.on("click", function(event) { | |
event.stop(); | |
if (!thumb.hasClassName("active")) { | |
this.clickOnThumbnail(thumb.readAttribute("id")); | |
} | |
}.bind(this)); | |
}.bind(this)); | |
sublimevideo.ready(function() { | |
sublimevideo.onEnd(function(sv) { | |
var matches = sv.element.id.match(/^video(\d+)$/); | |
if (matches != undefined) { | |
if (parseInt(matches[1], 10) <= this.videosCount) { | |
this.handleAutoNext(sv.element.id); | |
} | |
} | |
}.bind(this)); | |
}.bind(this)); | |
this.loadDemo(); | |
}, | |
loadDemo: function() { | |
// Only if not the first time here | |
if (this.activeVideoId) this.reset(); | |
this.activeVideoId = "video1"; | |
// Show first video | |
this.showActiveVideo(this.activeVideoId); | |
}, | |
reset: function() { | |
// Hide the current active video | |
$$("#" + interactiveWrapperId + " .video_wrap.active").first().removeClassName("active"); | |
// Get current active video and unprepare it | |
// we could have called sublimevideo.unprepare() without any arguments, but this is faster | |
sublimevideo.unprepare(this.activeVideoId); | |
// Deselect its thumbnail | |
this.deselectThumbnail(this.activeVideoId); | |
}, | |
clickOnThumbnail: function(thumbnailId) { | |
// Basically undo all the stuff and bring it back to the point before js kicked in | |
this.reset(); | |
// Set the new active video ... | |
this.activeVideoId = thumbnailId.replace(/^thumbnail_/, ""); | |
// Show it ... | |
this.showActiveVideo(this.activeVideoId); | |
// And finally, prepare and play it | |
sublimevideo.prepareAndPlay(this.activeVideoId); | |
}, | |
selectThumbnail: function(videoId) { | |
$("thumbnail_" + videoId).addClassName("active"); | |
}, | |
deselectThumbnail: function(videoId) { | |
$("thumbnail_" + videoId).removeClassName("active"); | |
}, | |
showActiveVideo: function(videoId) { | |
// Show it | |
$(this.activeVideoId).up().addClassName("active"); | |
// Select its thumb | |
this.selectThumbnail(this.activeVideoId); | |
}, | |
handleAutoNext: function(endedVideoId) { | |
var nextId = parseInt(endedVideoId.replace(/^video/, ""), 10) + 1; | |
if (nextId > 1 && nextId <= this.videosCount) { | |
this.clickOnThumbnail("thumbnail_video" + nextId); | |
} | |
} | |
}); | |
document.observe("dom:loaded", function() { | |
// Pass in the id of the interactive wrapper div | |
SublimeVideo.interactiveThumbnails = new InteractiveThumbnailsHandler("interactive"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment