/* Spacedeck Directives This module registers custom Vue directives for Spacedeck. */ function setup_directives() { Vue.directive('clipboard', { bind: function () { this.clipboard = new Clipboard(".clipboard-btn"); }, update: function (value) { }, unbind: function () { this.clipboard.destroy() } }); Vue.directive('t', { update: function (value, key) { this.el.innerHTML = key; } }); if ('ontouchstart' in window) { var edown = "touchstart"; var emove = "touchmove"; var eup = "touchend"; } else { var edown = "mousedown"; var emove = "mousemove"; var eup = "mouseup"; } Vue.directive('videoplayer', { update: function (a) { var el = this.el; var scope = this.vm.$root; var video = el.querySelectorAll("video")[0]; var play_button = el.querySelectorAll(".play")[0]; var pause_button = el.querySelectorAll(".pause")[0]; var stop_button = el.querySelectorAll(".stop")[0]; var player_state = "stop"; var update_view = function() { try { if (!a.player_view) { a.player_view = {} }; a.player_view.state = player_state; } catch (e) { // catch InvalidStateError } } var play_func = function() { video.play(); player_state = "playing"; update_view(); } var pause_func = function() { try { video.pause(); player_state = "paused"; update_view(); } catch (e) { // catch InvalidStateError } } var stop_func = function() { try { player_state = "stop"; video.pause(); video.currentTime = 0; update_view(); } catch (e) { // catch InvalidStateError } } el.addEventListener("remote_play",play_func); el.addEventListener("remote_pause",pause_func); el.addEventListener("remote_stop",stop_func); play_button.addEventListener(edown, function(evt) { try { play_func(); spacedeck.presenter_send_media_action(a._id,"video","play",video.currentTime); } catch (e) { // catch InvalidStateError } }, false); pause_button.addEventListener(edown, function(evt) { pause_func(); spacedeck.presenter_send_media_action(a._id,"video","pause",video.currentTime); }, false); stop_button.addEventListener(edown, function(evt) { stop_func(); spacedeck.presenter_send_media_action(a._id,"video","stop",0); }, false); } }); Vue.directive('audioplayer', { update: function (a) { var el = this.el; var scope = this.vm.$root; var play_button = el.querySelectorAll(".play")[0]; var pause_button = el.querySelectorAll(".pause")[0]; var stop_button = el.querySelectorAll(".stop")[0]; var timeline = el.querySelectorAll(".timeline")[0]; var set_inpoint = el.querySelectorAll(".set-inpoint")[0]; var set_outpoint = el.querySelectorAll(".set-outpoint")[0]; var reset_points = el.querySelectorAll(".reset-points")[0]; var player_state = "stop"; var play_from = 0.0; var play_to = 0.0; var audio = el.querySelectorAll("audio")[0]; var update_markers = function() { try { if (a.meta) { if (!a.meta.play_to) a.meta.play_to = audio.duration; play_from = parseFloat(a.meta.play_from) || 0.0; play_to = parseFloat(a.meta.play_to) || 0.0; } else { play_from = 0.0; play_to = parseFloat(audio.duration) || 0.0; a.meta = {}; } } catch (e) { // catch InvalidStateError } } var update_view = function() { try { if (!a.player_view) { a.player_view = {} }; a.player_view.state = player_state; a.player_view.total_time_string = format_time(audio.duration); a.player_view.current_time_string = format_time(audio.currentTime); a.player_view.current_time_float = audio.currentTime/audio.duration; a.player_view.inpoint_float = play_from/audio.duration; a.player_view.outpoint_float = play_to/audio.duration; a.player_view.duration = audio.duration; } catch (e) { // catch InvalidStateError } } var pause_audio = function() { try { audio.pause(); player_state = "paused"; } catch (e) { // catch InvalidStateError } update_view(); } var stop_audio = function() { try { audio.currentTime = play_from; audio.pause(); player_state = "stop"; } catch (e) { // catch InvalidStateError } update_view(); } update_view(); audio.addEventListener("loadedmetadata", function(evt) { update_markers(); update_view(); }, false); audio.addEventListener("timeupdate", function(evt) { try { update_markers(); if (audio.currentTime >= play_to && player_state == "playing") stop_audio(); update_view(); } catch (e) { // catch InvalidStateError } }, false); var play_func = function() { if (player_state == "stop") { audio.currentTime = play_from; } player_state = "playing"; update_markers(); audio.play(); update_view(); } var pause_func = function() { pause_audio(); update_view(); } var stop_func = function() { stop_audio(); update_view(); } el.addEventListener("remote_play",play_func); el.addEventListener("remote_pause",pause_func); el.addEventListener("remote_stop",stop_func); play_button.addEventListener(edown, function(evt) { try { play_func(); spacedeck.presenter_send_media_action(a._id,"audio","play",audio.currentTime); } catch (e) { // catch InvalidStateError } }, false); pause_button.addEventListener(edown, function(evt) { pause_func(); spacedeck.presenter_send_media_action(a._id,"audio","pause",audio.currentTime); }, false); stop_button.addEventListener(edown, function(evt) { stop_func(); spacedeck.presenter_send_media_action(a._id,"audio","stop",0); }, false); timeline.addEventListener(edown, function(evt) { var clicked_time = (parseFloat(evt.offsetX)/evt.currentTarget.offsetWidth)*audio.duration; if (isNaN(clicked_time)) { clicked_time = 0.0; } try { audio.currentTime = clicked_time; } catch (e) { // catch InvalidStateErrors } }, false); set_inpoint.addEventListener(edown, function(evt) { if (!a.meta) a.meta = {}; a.meta.play_from = audio.currentTime; if (a.meta.play_to