Skip to content

Commit c38c4d0

Browse files
authored
Merge pull request #136 from easycoder/dev
Embedding
2 parents dc3738f + 1c2ec6e commit c38c4d0

File tree

3 files changed

+145
-134
lines changed

3 files changed

+145
-134
lines changed

dist/plugins/iwsy.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ const EasyCoder_IWSY = {
160160
});
161161
return 0;
162162
case `load`:
163-
if (typeof EasyCoder.iwsyFunctions !== `undefined`) {
163+
if (program.iwsyFunctions) {
164164
throw Error(`IWSY has already been set up`);
165165
}
166166
const playerRecord = program.getSymbolRecord(command.player);
@@ -174,11 +174,11 @@ const EasyCoder_IWSY = {
174174
} catch (err) {
175175
alert(`iwsy load: Badly formatted script`);
176176
}
177-
EasyCoder.iwsyFunctions = IWSY(player, script);
177+
program.iwsyFunctions = IWSY(player, script);
178178
break;
179179
case `path`:
180-
if (EasyCoder.iwsyFunctions) {
181-
EasyCoder.iwsyFunctions.setPath(program.getValue(command.path));
180+
if (program.iwsyFunctions) {
181+
program.iwsyFunctions.setPath(program.getValue(command.path));
182182
}
183183
break;
184184
case `script`:
@@ -188,42 +188,43 @@ const EasyCoder_IWSY = {
188188
} catch (err) {
189189
alert(`iwsy script: Badly formatted script`);
190190
}
191-
if (EasyCoder.iwsyFunctions) {
192-
EasyCoder.iwsyFunctions.setScript(script);
191+
if (program.iwsyFunctions) {
192+
program.iwsyFunctions.setScript(script);
193193
}
194194
break;
195195
case `goto`:
196-
if (EasyCoder.iwsyFunctions) {
197-
EasyCoder.iwsyFunctions.gotoStep(program.getValue(command.target));
196+
if (program.iwsyFunctions) {
197+
program.iwsyFunctions.gotoStep(program.getValue(command.target));
198198
}
199199
break;
200200
case `block`:
201-
if (EasyCoder.iwsyFunctions) {
202-
EasyCoder.iwsyFunctions.block(program.getValue(command.block));
201+
if (program.iwsyFunctions) {
202+
program.iwsyFunctions.block(program.getValue(command.block));
203203
}
204204
break;
205205
case `run`:
206-
if (EasyCoder.iwsyFunctions) {
207-
EasyCoder.iwsyFunctions.run(command.mode, command.startMode, () => {
206+
if (program.iwsyFunctions) {
207+
program.iwsyFunctions.run(command.mode, command.startMode, () => {
208208
program.run(command.then);
209209
});
210210
return 0;
211211
}
212212
break;
213213
case `stop`:
214-
if (EasyCoder.iwsyFunctions) {
215-
EasyCoder.iwsyFunctions.stop();
214+
if (program.iwsyFunctions) {
215+
program.iwsyFunctions.stop();
216+
delete program.iwsyFunctions;
216217
}
217218
break;
218219
case `removeStyles`:
219-
if (EasyCoder.iwsyFunctions) {
220-
EasyCoder.iwsyFunctions.removeStyles();
220+
if (program.iwsyFunctions) {
221+
program.iwsyFunctions.removeStyles();
221222
}
222223
break;
223224
case `onstep`:
224225
const cb = command.pc + 2;
225-
if (EasyCoder.iwsyFunctions) {
226-
EasyCoder.iwsyFunctions.onStep(function(step) {
226+
if (program.iwsyFunctions) {
227+
program.iwsyFunctions.onStep(function(step) {
227228
program.iwsyStep = step;
228229
program.run(cb);
229230
});
@@ -274,8 +275,8 @@ const EasyCoder_IWSY = {
274275
switch (value.type) {
275276
case `script`:
276277
let script = null;
277-
if (EasyCoder.iwsyFunctions) {
278-
script = EasyCoder.iwsyFunctions.getScript();
278+
if (program.iwsyFunctions) {
279+
script = program.iwsyFunctions.getScript();
279280
return {
280281
type: `constant`,
281282
numeric: false,

iwsy/iwsy.js

Lines changed: 103 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,6 @@ const IWSY = (playerElement, scriptObject) => {
487487
doTransitionStep(block, target, ratio);
488488
} catch (err) {
489489
clearInterval(interval);
490-
throw Error(err);
491490
}
492491
animStep++;
493492
} else {
@@ -828,75 +827,80 @@ const IWSY = (playerElement, scriptObject) => {
828827

829828
// Process a single step
830829
const doStep = step => {
831-
if (!step) {
832-
return;
833-
}
834-
if (step.title) {
835-
console.log(`Step ${step.index}: ${step.title}`);
836-
} else {
837-
console.log(`Step ${step.index}: ${step.action}`);
838-
}
839-
if (script.speed === `scan` && step.index === script.scanTarget) {
840-
script.speed = `normal`;
841-
for (const block of script.blocks) {
842-
if (block.element) {
843-
block.element.style.display = `block`;
830+
try {
831+
if (!step) {
832+
return;
833+
}
834+
if (step.title) {
835+
console.log(`Step ${step.index}: ${step.title}`);
836+
} else {
837+
console.log(`Step ${step.index}: ${step.action}`);
838+
}
839+
if (script.speed === `scan` && step.index === script.scanTarget) {
840+
script.speed = `normal`;
841+
for (const block of script.blocks) {
842+
if (block.element) {
843+
block.element.style.display = `block`;
844+
}
844845
}
845846
}
846-
}
847847

848-
const onStepCB = script.onStepCB;
849-
if (step.action === `chain`) {
850-
const runMode = script.runMode;
851-
fetch(`${path}${step.script}`)
852-
.then(response => {
853-
if (response.status >= 400) {
854-
throw Error(`Unable to load ${step.script}: ${response.status}`)
855-
}
856-
response.json().then(data => {
857-
script = data;
858-
if (onStepCB) {
859-
onStepCB(-1);
848+
const onStepCB = script.onStepCB;
849+
if (step.action === `chain`) {
850+
const runMode = script.runMode;
851+
fetch(`${path}${step.script}?v=${Date.now()}`)
852+
.then(response => {
853+
if (response.status >= 400) {
854+
throw Error(`Unable to load ${step.script}: ${response.status}`)
860855
}
861-
initScript();
862-
script.runMode = runMode;
863-
doStep(script.steps[1]);
856+
response.json().then(data => {
857+
script = data;
858+
if (onStepCB) {
859+
onStepCB(-1);
860+
}
861+
initScript();
862+
script.runMode = runMode;
863+
doStep(script.steps[1]);
864+
});
865+
})
866+
.catch(err => {
867+
throw Error(`Fetch Error :${err}`);
864868
});
865-
})
866-
.catch(err => {
867-
throw Error(`Fetch Error :${err}`);
868-
});
869-
return;
870-
}
871-
872-
const actionName = step.action.split(` `).join(``);
873-
let handler = actions[actionName];
874-
if (script.runMode === `auto`) {
875-
if (typeof handler === `undefined`) {
876-
handler = IWSY.plugins[actionName];
869+
return;
870+
}
871+
872+
const actionName = step.action.split(` `).join(``);
873+
let handler = actions[actionName];
874+
if (script.runMode === `auto`) {
877875
if (typeof handler === `undefined`) {
878-
throw Error(`Unknown action: '${step.action}'`);
876+
handler = IWSY.plugins[actionName];
877+
if (typeof handler === `undefined`) {
878+
throw Error(`Unknown action: '${step.action}'`);
879+
}
880+
}
881+
if (onStepCB) {
882+
onStepCB(step.index);
883+
}
884+
try {
885+
handler(step);
886+
} catch (err) {
887+
console.log(`Step ${step.index} (${step.action}): ${err}`);
888+
alert(`Step ${step.index} (${step.action}): ${err}`);
889+
}
890+
} else {
891+
try {
892+
handler(step);
893+
} catch (err) {
894+
console.log(JSON.stringify(step,0,2) + `\n` + JSON.stringify(handler,0,2));
895+
console.log(`Step ${step.index} (${step.action}): ${err}`);
896+
alert(`Step ${step.index} (${step.action}): ${err}`);
879897
}
880-
}
881-
if (onStepCB) {
882-
onStepCB(step.index);
883-
}
884-
try {
885-
handler(step);
886-
} catch (err) {
887-
console.log(`Step ${step.index} (${step.action}): ${err}`);
888-
alert(`Step ${step.index} (${step.action}): ${err}`);
889-
}
890-
} else {
891-
try {
892-
handler(step);
893-
} catch (err) {
894-
console.log(JSON.stringify(step,0,2) + `\n` + JSON.stringify(handler,0,2));
895-
console.log(`Step ${step.index} (${step.action}): ${err}`);
896-
alert(`Step ${step.index} (${step.action}): ${err}`);
897898
}
898899
}
899-
900+
catch (err) {
901+
console.log(`Step error: ${err}`);
902+
throw Error(err);
903+
}
900904
};
901905

902906
///////////////////////////////////////////////////////////////////////////////
@@ -983,41 +987,46 @@ const IWSY = (playerElement, scriptObject) => {
983987

984988
// Run the presentation
985989
const run = (mode, startMode, then) => {
986-
homeScript = JSON.parse(JSON.stringify(script));
987-
afterRun = then;
988-
initScript();
989-
if (mode === `fullscreen`) {
990-
if (document.fullscreenElement) {
991-
document.exitFullscreen();
992-
} else {
993-
player.requestFullscreen();
994-
document.onfullscreenchange = () => {
995-
if (document.fullscreenElement) {
996-
player = document.fullscreenElement;
997-
script.nextStep = script.steps[0];
998-
switch (startMode) {
999-
case `auto`:
1000-
script.runMode = `auto`;
1001-
release();
1002-
break;
1003-
case `manual`:
1004-
script.runMode = `manual`;
1005-
release();
1006-
break;
1007-
case `wait`:
1008-
script.runMode = `manual`;
1009-
enterManualMode(null);
1010-
break;
990+
try {
991+
homeScript = JSON.parse(JSON.stringify(script));
992+
afterRun = then;
993+
initScript();
994+
if (mode === `fullscreen`) {
995+
if (document.fullscreenElement) {
996+
document.exitFullscreen();
997+
} else {
998+
player.requestFullscreen();
999+
document.onfullscreenchange = () => {
1000+
if (document.fullscreenElement) {
1001+
player = document.fullscreenElement;
1002+
script.nextStep = script.steps[0];
1003+
switch (startMode) {
1004+
case `auto`:
1005+
script.runMode = `auto`;
1006+
release();
1007+
break;
1008+
case `manual`:
1009+
script.runMode = `manual`;
1010+
release();
1011+
break;
1012+
case `wait`:
1013+
script.runMode = `manual`;
1014+
enterManualMode(null);
1015+
break;
1016+
}
1017+
} else {
1018+
player = playerElement;
1019+
script.stop = true;
10111020
}
1012-
} else {
1013-
player = playerElement;
1014-
script.stop = true;
1015-
}
1016-
};
1021+
};
1022+
}
1023+
} else {
1024+
script.runMode = `auto`;
1025+
doStep(script.steps[0]);
10171026
}
1018-
} else {
1019-
script.runMode = `auto`;
1020-
doStep(script.steps[0]);
1027+
} catch (err) {
1028+
console.log(`Run error: ${err}`);
1029+
throw Error(err);
10211030
}
10221031
}
10231032

0 commit comments

Comments
 (0)