diff --git a/static/js/directives/youtubevideo.js b/static/js/directives/youtubevideo.js index 44021e18..bfd213e5 100644 --- a/static/js/directives/youtubevideo.js +++ b/static/js/directives/youtubevideo.js @@ -106,7 +106,11 @@ define(['require', 'jquery', 'underscore', 'moment', 'text!partials/youtubevideo var initialState = null; var sandboxApi = null; - var createSandboxApi = function() { + var createSandboxApi = function(force) { + if (sandboxApi && force) { + sandboxApi.destroy(); + sandboxApi = null; + } if (!sandboxApi) { var sandboxFrame = $("#youtubeplayer", $element)[0]; @@ -515,6 +519,10 @@ define(['require', 'jquery', 'underscore', 'moment', 'text!partials/youtubevideo } }; + $scope.loadYouTubeAPI = function() { + createSandboxApi(true); + }; + $scope.showYouTubeVideo = function() { createSandboxApi(); $scope.layout.youtubevideo = true;