/** * JS Library for Video Player Module * * This file contains all of the needed JavaScript functions * required by the video player module. There are 2 methods * for loading an embedded video player: AJAX (preferred), and * IFRAME. The AJAX method will allow cleaner integration, but * the IFRAME method will work on older browsers. * * @author Harold Asbridge * @package Video * @version 1.0 */ /** * XMLHttpRequest global object */ var req; /** * Video container element Id. Default is 'video_player'. This should be * a DIV or a SPAN, since it's innerHTML property will be used. */ var videoPlayerId = 'video_player'; /** * Initiate remote request to shared/video.display.php, using XMLHttpRequest * @param {integer} videoId * @param {integer} width * @param {integer} height * @param {bool} autoplay */ function loadVideoPlayer(videoId, width, height, autoplay) { height = height + 20; var url = 'http://www.positivelycleveland.com/shared/video.display.php?id=' + videoId + '&width=' + width + '&height=' + height + '&autoplay=' + autoplay; // branch for native XMLHttpRequest object if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.onreadystatechange = updateVideoContent; req.open("GET", url, true); req.send(null); // branch for IE/Windows ActiveX version } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.onreadystatechange = updateVideoContent; req.open("GET", url, true); req.send(); } } } /** * Pop up a new window, with an embedded video player. * @param {integer} videoId * @param {integer} width * @param {integer} height * @param {bool} autoplay */ function popupVideoPlayer(videoId, width, height, autoplay) { height = height + 20; var url = 'http://www.positivelycleveland.com/shared/video.display.php?id=' + videoId + '&width=' + width + '&height=' + height + '&autoplay=' + autoplay; var newWin = window.open(url, '', 'toolbar=0, menubar=0, statusbar=0, width=' + width + ', height=' + height); } /** * Update video player content on-the-fly, after receiving answer from XMLHttpRequest * */ function updateVideoContent() { // only if req shows "complete" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { // Update video player var videoElement; if (videoElement = document.getElementById(videoPlayerId)) { videoElement.innerHTML = req.responseText; } else { alert('Could not locate "video_player" element'); } } else { // Error alert("There was a problem retrieving the XML data:\n" + req.statusText); } } }