Skip to content

Commit

Permalink
Merge pull request #140 from dascritch/preprod
Browse files Browse the repository at this point in the history
finished panels navigation
  • Loading branch information
dascritch authored Apr 9, 2021
2 parents 1d71347 + 715c796 commit 3b5cc6f
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 30 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Todo later
- Aria roles on fine position buttons
- [Automated example page generated for each theme from make.sh #124](#124)
- Full test comparing campaign of all available platforms ([#138](#138)), ([#113](#113))
- Upate dotclear addon companion ([#67](#67))
- Udpate dotclear addon companion ([#67](#67))
- Resolve failing test only on Chrome Android ([#121](#121)) may be linked to event engine on this very specific software.

Planned evolutions
Expand Down
2 changes: 1 addition & 1 deletion build/cpu-audio.big-square.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/cpu-audio.big-square.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/cpu-audio.direct-download.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/cpu-audio.direct-download.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/cpu-audio.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/cpu-audio.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/cpu-audio.test-all-buttons.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/cpu-audio.test-all-buttons.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/document_cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {DefaultParametersDocumentCPU} from './default_document_cpu_parameters.js
import {defaultDataset} from './default_dataset.js';
import {convert, timeInSeconds} from './convert.js';
import {trigger} from './trigger.js';
import {isAudiotagStreamed, normalizeSeekTime} from './media_element_extension.js';
import {isAudiotagStreamed, uncertainPosition, normalizeSeekTime} from './media_element_extension.js';

export const DocumentCPU = {
// global object for global API
Expand Down Expand Up @@ -110,13 +110,14 @@ export const DocumentCPU = {

let audiotag = /** @type {HTMLAudioElement} */ ( (hash !== '') ? document.getElementById(hash) : document.querySelector(selectorAudioInComponent) );

if ((audiotag == null) || (audiotag.currentTime === undefined)) {
//if ((audiotag == null) || (audiotag.currentTime === undefined)) {
if ( ( audiotag?.currentTime ?? null ) == null ) {
warn(`Unknow audiotag ${hash}`);
return;
}

let mocked_event = {target : audiotag};
if (audiotag.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
if (audiotag.readyState < audiotag.HAVE_CURRENT_DATA) {
// WHHYYYY ??????
audiotag.addEventListener('loadedmetadata', doNeedleMove , oncePassiveEvent);
audiotag.load();
Expand All @@ -136,7 +137,7 @@ export const DocumentCPU = {
*
*/
seekElementAt : function (audiotag, seconds) {
if ((isNaN(seconds)) || // may happens, if the audio track is not loaded/loadable
if ((uncertainPosition(seconds)) || // may happens, if the audio track is not loaded/loadable
(isAudiotagStreamed(audiotag))) { // never try to set a position on a streamed media
return;
}
Expand Down
9 changes: 6 additions & 3 deletions src/element_cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -1513,9 +1513,12 @@ function relativeFocus(self, go_foward) {
return;
}

const validPlane = (data) => {
let {track, panel, points} = self.plane(data);
return (((track !== false) || (panel !== false)) && (points) && (Object.keys(points).length > 0));
const validPlane = (id) => {
let {track, panel, points} = self.plane(id);
return (((track !== false) || (panel !== false))
&& ((self.planePanel(id)?.clientHeight > 0) || (self.planeTrack(id)?.clientHeight > 0))
&& (points)
&& (Object.keys(points).length > 0));
};

const scanToPrevPlane = (fromPlane) => {
Expand Down
19 changes: 16 additions & 3 deletions src/media_element_extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ export function isAudiotagStreamed(audiotag) {
}


/**
* @summary Checks if a time position is seekabe into an audiotag
* @private
*
* @param {number|null} time Expected time to seek in an audiotag
* @return {boolean} Unusable time
*/
export function uncertainPosition(time) {

return (time === Infinity) || (time === null) || (isNaN(time));
}


/**
* @summary Checks if an audiotag's duration is suitable for ratio maths
* A media may have unusable duration for ratio because
Expand All @@ -60,7 +73,7 @@ export function isAudiotagStreamed(audiotag) {
*/
export function uncertainDuration(duration) {

return (duration === 0) || (duration === Infinity) || (duration === null) || (isNaN(duration));
return (duration === 0) || (uncertainPosition(duration));
}

/**
Expand All @@ -73,11 +86,11 @@ export function uncertainDuration(duration) {
export function audiotagDuration({duration, dataset}) {
let out = null;
let _natural = Number(duration);
if (!isNaN(_natural)){
if (!uncertainDuration(_natural)) {
out = _natural;
} else {
const _forced = Number(dataset.duration);
if (_forced > 0) {
if (!uncertainDuration(_forced)) { // yes, because isNaN(Number('Infinity')) !
out = _forced;
}
}
Expand Down
27 changes: 16 additions & 11 deletions tests/tests-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -787,15 +787,20 @@ document.querySelector('#get_focus').addEventListener('click', function() {
componenttag.CPU.nextFocus();
assert.equal(componenttag.CPU.focusedId(), 'control', 'nextFocus() without existing planes do not move');

// NOTE : to be visible, tracks must be set to `"chapters"` instead of `true`
componenttag.CPU.addPlane('plane1', {track:false, panel:true});
componenttag.CPU.bulkPoints('plane1', points);
componenttag.CPU.addPlane('plane2', {track:true, panel:true});
componenttag.CPU.addPlane('plane2', {track:"chapters", panel:true});
componenttag.CPU.bulkPoints('plane2', points);
componenttag.CPU.addPlane('plane3', {track:true, panel:true});
componenttag.CPU.addPlane('plane3', {track:"chapters", panel:true});
componenttag.CPU.addPlane('plane4', {track:false, panel:false});
componenttag.CPU.bulkPoints('plane4', points);
componenttag.CPU.addPlane('plane5', {track:true, panel:false});
componenttag.CPU.addPlane('plane5', {track:false, panel:'no'});
componenttag.CPU.bulkPoints('plane5', points);
componenttag.CPU.addPlane('plane6', {track:'no', panel:false});
componenttag.CPU.bulkPoints('plane6', points);
componenttag.CPU.addPlane('plane7', {track:"chapters", panel:false});
componenttag.CPU.bulkPoints('plane7', points);
componenttag.CPU.prevFocus();
assert.equal(componenttag.CPU.focusedId(), 'control', 'prevFocus() out of planes doesnt move');
componenttag.CPU.nextFocus();
Expand All @@ -806,26 +811,26 @@ document.querySelector('#get_focus').addEventListener('click', function() {
assert.equal(componenttag.CPU.focused().closest('[id]').id, 'panel_«plane2»_point_«a»', 'nextFocus() and the end of a plane take the first point of the next plane');
componenttag.CPU.nextFocus();
componenttag.CPU.nextFocus();
assert.equal(componenttag.CPU.focused().closest('[id]').id, 'track_«plane5»_point_«a»', 'nextFocus() and the end of a plane take the first point of the next plane with entries and with track or panel activated');
assert.equal(componenttag.CPU.focused().closest('[id]').id, 'track_«plane7»_point_«a»', 'nextFocus() and the end of a plane take the first point of the next plane with entries and with track or panel activated and visible');
componenttag.CPU.nextFocus();
componenttag.CPU.nextFocus();
assert.equal(componenttag.CPU.focused().closest('[id]').id, 'track_«plane5»_point_«b»', 'nextFocus() at the end of panels stays on last focused point');
assert.equal(componenttag.CPU.focused().closest('[id]').id, 'track_«plane7»_point_«b»', 'nextFocus() at the end of panels stays on last focused point');
componenttag.CPU.prevFocus();
assert.equal(componenttag.CPU.focused().closest('[id]').id, 'track_«plane5»_point_«a»', 'prevFocus() at the end of panels goes back from one point');
assert.equal(componenttag.CPU.focused().closest('[id]').id, 'track_«plane7»_point_«a»', 'prevFocus() at the end of panels goes back from one point');
componenttag.CPU.focusPoint('plane3','a');
componenttag.CPU.prevFocus();
assert.equal(componenttag.CPU.focused().closest('[id]').id, 'panel_«plane2»_point_«b»', 'prevFocus() at the begining of a panel goes back at the end of previous panel');
componenttag.CPU.focusPoint('plane5','a');
componenttag.CPU.focusPoint('plane7','a');
componenttag.CPU.prevFocus();
assert.equal(componenttag.CPU.focused().closest('[id]').id, 'panel_«plane2»_point_«b»', 'prevFocus() at the begining of a panel goes back at the end of the previous panel with points and with or a track or a panel');
componenttag.CPU.focusPoint('plane1','a');
componenttag.CPU.prevFocus();
assert.equal(componenttag.CPU.focused().closest('[id]').id, 'panel_«plane1»_point_«a»', 'prevFocus() at the begining of the first panel does nothing');

componenttag.CPU.removePlane('plane1');
componenttag.CPU.removePlane('plane2');
componenttag.CPU.removePlane('plane3');
componenttag.CPU.removePlane('plane4');
for (let id = 1; id < 8; id++) {
componenttag.CPU.removePlane(`plane${id}`);
}

});

});

0 comments on commit 3b5cc6f

Please sign in to comment.