diff --git a/app/assets/javascripts/concerto_remote_video/remote_video.js b/app/assets/javascripts/concerto_remote_video/remote_video.js index 149b64e..162c519 100644 --- a/app/assets/javascripts/concerto_remote_video/remote_video.js +++ b/app/assets/javascripts/concerto_remote_video/remote_video.js @@ -1,117 +1,118 @@ -var initializedRemoteVideoHandlers = false; -function initializeRemoteVideoHandlers() { - if (!initializedRemoteVideoHandlers) { +var ConcertoRemoteVideo = { + _initialized: false, - function getVideoPreview() { - var preview_url = '/concerto-remote-video/preview'; + getVideoPreview: function () { + var preview_url = '/concerto-remote-video/preview'; - // Form video details - var video_id = $('input#remote_video_config_video_id').val(); - var video_vendor = $('select#remote_video_config_video_vendor').val(); + // Form video details + var video_id = $('input#remote_video_config_video_id').val(); + var video_vendor = $('select#remote_video_config_video_vendor').val(); - // Loading icon - if (video_id.length != 0) { - $(preview_div).empty().html(' searching...'); - $('.remote-video-info').empty(); - // Video preview request - $.ajax({ - type: 'POST', - url: preview_url, - data: { - video_id: video_id, - video_vendor: video_vendor - }, - success: function(data) { - loadVideoInfo(data); - loadVideoPreview(data); - }, - error: function(e) { - //loadVideoPreview({video_available: false}); - $(preview_div).empty().text(e.responseText); - } - }); - } + // Loading icon + if (video_id.length != 0) { + $(preview_div).empty().html(' searching...'); + $('.remote-video-info').empty(); + // Video preview request + $.ajax({ + type: 'POST', + url: preview_url, + data: { + video_id: video_id, + video_vendor: video_vendor + }, + success: function(data) { + ConcertoRemoteVideo.loadVideoInfo(data); + ConcertoRemoteVideo.loadVideoPreview(data); + }, + error: function(e) { + //loadVideoPreview({video_available: false}); + $(preview_div).empty().text(e.responseText); + } + }); } + }, - function loadVideoInfo(data) { - if (data['video_available']) { - // Target elements for setting video info - var info_el = $('.remote-video-info'); - var name_el = $('input#remote_video_name'); - var duration_el = $('input#remote_video_duration'); - // Initialize info content - var title = ''; - var description = '
'; - var duration = ''; - var vendor = data['video_vendor']; + loadVideoInfo: function (data) { + if (data['video_available']) { + // Target elements for setting video info + var info_el = $('.remote-video-info'); + var name_el = $('input#remote_video_name'); + var duration_el = $('input#remote_video_duration'); + // Initialize info content + var title = ''; + var description = ''; + var duration = ''; + var vendor = data['video_vendor']; - if (vendor == 'HTTPVideo') { - $(info_el).empty(); - return; - } else { - // YouTube no longer returns these details without an API key - if (vendor != 'YouTube') { - if (data['description']) { - // Preview video description - var description = '' + data['description'] + '
'; - } - if (data['title']) { - // Set content title to video returned title - name_el.val(data['title']); - } - if (data['duration']) { - // Set content duration to video duration - duration = '' + data['duration'] + ' secs'; - duration_el.val(data['duration']); - } + if (vendor == 'HTTPVideo') { + $(info_el).empty(); + return; + } else { + // YouTube no longer returns these details without an API key + if (vendor != 'YouTube') { + if (data['description']) { + // Preview video description + var description = '' + data['description'] + '
'; } - } - - // Load video info - var info = ''+duration+'