Skip to content

Commit

Permalink
Refacto
Browse files Browse the repository at this point in the history
Refactoring with ECMA classes #115
  • Loading branch information
dascritch committed Mar 17, 2021
1 parent 560e161 commit e4181fe
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ function play_once_unlock(event, audiotag) {

export const trigger = {

// @private
// @private MAY GO OUT OF THIS OBJECT IF NOT TESTED OUTSIDE
_timecode_start : 0,
// @private
// @private MAY GO OUT OF THIS OBJECT IF NOT TESTED OUTSIDE
_timecode_end : false,

// @private
// @private MAY GO OUT OF THIS OBJECT IF NOT TESTED OUTSIDE
_last_play_error : false,

/**
Expand Down Expand Up @@ -151,13 +151,13 @@ export const trigger = {
if (!target.id) {
target = target.closest('[id]');
}
if (target === null) {
if (!target) {
return;
}

let container = document.CPU.find_container(target);
let names = container.get_point_names_from_id(target.id);
container.highlight_point(names[0], names[1]);
let [plane_name, point_name] = container.get_point_names_from_id(target.id);
container.highlight_point(plane_name, point_name);
},


Expand Down Expand Up @@ -261,9 +261,7 @@ export const trigger = {
*/
play : function(event=undefined, audiotag=undefined) {

if (audiotag === undefined) {
audiotag = document.CPU.find_container(event.target).audiotag;
}
audiotag = audiotag ?? document.CPU.find_container(event.target).audiotag;

if ( (event === undefined) && (trigger._last_play_error)) {
warn(`play() prevented because already waiting for focus`);
Expand All @@ -275,7 +273,6 @@ export const trigger = {

let promised = audiotag.play();


if (promised !== undefined) {
promised.then(
() => {
Expand Down Expand Up @@ -324,14 +321,13 @@ export const trigger = {
* @param {Object} event The event
* @param {number} mult Multiply the keypressed act, 1 by default
*/
key : function(event, mult=undefined) {
key : function(event, mult=1) {

// do not interpret key when there is a modifier, for not preventing browsers shortcurs
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
return;
}

mult = mult === undefined ? 1 : mult;
let container = document.CPU.find_container(event.target);
let audiotag = container.audiotag;

Expand Down Expand Up @@ -524,9 +520,9 @@ export const trigger = {
native_share : function(event) {
let dataset = document.CPU.find_container(event.target).fetch_audiotag_dataset();
navigator.share({
'title': dataset.title,
'text': dataset.title,
'url': dataset.canonical
title : dataset.title,
text : dataset.title,
url : dataset.canonical
});
event.preventDefault();
},
Expand Down

0 comments on commit e4181fe

Please sign in to comment.