Skip to content

Commit ee9643b

Browse files
authoredMay 31, 2020
Merge pull request #82 from easycoder/dev
Dev
2 parents 05055dc + 41528e4 commit ee9643b

File tree

11 files changed

+284
-903
lines changed

11 files changed

+284
-903
lines changed
 

‎dist/plugins/iwsy.js

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,46 @@ const EasyCoder_IWSY = {
1111

1212
const lino = compiler.getLino();
1313
const action = compiler.nextToken();
14-
if ([`init`, `show`].includes(action)) {
15-
compiler.next();
16-
compiler.addCommand({
17-
domain: `iwsy`,
18-
keyword: `iwsy`,
19-
lino,
20-
action
21-
});
22-
return true;
23-
}
14+
switch (action) {
15+
case `load`:
16+
if (compiler.nextIsSymbol()) {
17+
const playerRecord = compiler.getSymbolRecord();
18+
if (playerRecord.keyword === `div`) {
19+
const script = compiler.getNextValue();
20+
compiler.addCommand({
21+
domain: `iwsy`,
22+
keyword: `iwsy`,
23+
lino,
24+
action,
25+
player: playerRecord.name,
26+
script
27+
});
28+
return true;
29+
}
30+
}
31+
break;
32+
case `init`:
33+
compiler.next();
34+
compiler.addCommand({
35+
domain: `iwsy`,
36+
keyword: `iwsy`,
37+
lino,
38+
action
39+
});
40+
return true;
41+
case `goto`:
42+
const target = compiler.getNextValue();
43+
compiler.addCommand({
44+
domain: `iwsy`,
45+
keyword: `iwsy`,
46+
lino,
47+
action,
48+
target
49+
});
50+
return true;
51+
default:
52+
break;
53+
}
2454
return false;
2555
},
2656

@@ -33,8 +63,18 @@ const EasyCoder_IWSY = {
3363
function () {
3464
program.run(command.pc + 1);
3565
});
66+
return 0;
67+
case `load`:
68+
const playerRecord = program.getSymbolRecord(command.player);
69+
const player = playerRecord.element[playerRecord.index];
70+
player.innerHTML = ``;
71+
player.style.background = `none`;
72+
player.style.border = `none`;
73+
const script = program.getValue(command.script);
74+
EasyCoder.iwsyGotoStep = IWSY(player, JSON.parse(script));
3675
break;
37-
case `show`:
76+
case `goto`:
77+
EasyCoder.iwsyGotoStep(program.getValue(command.target));
3878
break;
3979
}
4080
return command.pc + 1;

‎iwsy/iwsy.js

Lines changed: 80 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -105,38 +105,40 @@ const IWSY = (container, script) => {
105105
block.element = element;
106106
element.style[`position`] = `absolute`;
107107
element.style[`opacity`] = `0.0`;
108-
let val = properties.blockLeft;
108+
let val = properties.left;
109109
if (!isNaN(val)) {
110110
val *= w;
111111
}
112112
element.style[`left`] = val;
113-
val = properties.blockTop;
113+
val = properties.top;
114114
if (!isNaN(val)) {
115115
val *= h;
116116
}
117117
element.style[`top`] = val;
118-
val = properties.blockWidth;
118+
val = properties.width;
119119
if (!isNaN(val)) {
120-
val *= w;
120+
val = `${val * w}px`;
121121
}
122-
element.style[`width`] = `${val}px`;
123-
val = properties.blockHeight;
122+
element.style[`width`] = val;
123+
val = properties.height;
124124
if (!isNaN(val)) {
125-
val *= h;
125+
val = `${val * h}px`;
126126
}
127-
element.style[`height`] = `${val}px`;
128-
element.style[`background`] = properties.blockBackground;
129-
element.style[`border`] = properties.blockBorder;
127+
element.style[`height`] = val;
128+
element.style[`background`] = properties.background;
129+
element.style[`border`] = properties.border;
130130
container.appendChild(element);
131131
val = properties.textMarginLeft;
132132
if (!isNaN(val)) {
133-
val *= w;
133+
val = `${val * w}px`;
134134
}
135+
element.style[`width`] = val;
135136
const marginLeft = val;
136137
val = properties.textMarginTop;
137138
if (!isNaN(val)) {
138-
val *= h;
139+
val = `${val * h}px`;
139140
}
141+
element.style[`height`] = val;
140142
const marginTop = val;
141143
const inner = document.createElement(`div`);
142144
inner.style[`position`] = `absolute`;
@@ -176,30 +178,30 @@ const IWSY = (container, script) => {
176178
block.element = element;
177179
element.style[`position`] = `absolute`;
178180
element.style[`opacity`] = `0.0`;
179-
let val = properties.blockLeft;
181+
let val = properties.left;
180182
if (!isNaN(val)) {
181183
val *= w;
182184
}
183185
element.style[`left`] = val;
184-
val = properties.blockTop;
186+
val = properties.top;
185187
if (!isNaN(val)) {
186188
val *= h;
187189
}
188190
element.style[`top`] = val;
189191
element.style[`top`] = val;
190-
val = properties.blockWidth;
192+
val = properties.width;
191193
if (!isNaN(val)) {
192-
val *= w;
194+
val = `${val * w}px`;
193195
}
194-
element.style[`width`] = `${val}px`;
195-
val = properties.blockHeight;
196+
element.style[`width`] = val;
197+
val = properties.height;
196198
if (!isNaN(val)) {
197-
val *= h;
199+
val = `${val * h}px`;
198200
}
199-
element.style[`height`] = `${val}px`;
200-
element.style[`background`] = properties.blockBackground;
201-
element.style[`border`] = properties.blockBorder;
202-
element.style[`border-radius`] = properties.blockBorderRadius;
201+
element.style[`height`] = val;
202+
element.style[`background`] = properties.background;
203+
element.style[`border`] = properties.border;
204+
element.style[`border-radius`] = properties.borderRadius;
203205
container.appendChild(element);
204206
if (script.speed === `scan`) {
205207
element.style.opacity = 0;
@@ -634,6 +636,13 @@ const IWSY = (container, script) => {
634636
}
635637
};
636638

639+
// Go to a specified step number
640+
const gotoStep = (target) => {
641+
script.scanTarget = target;
642+
script.singleStep = true;
643+
scan();
644+
};
645+
637646
// Load a plugin action
638647
const load = step => {
639648
if (script.speed === `scan`) {
@@ -652,7 +661,7 @@ const IWSY = (container, script) => {
652661
}
653662
};
654663

655-
// Initialize the presenttion
664+
// Initialize the presentation
656665
const init = step => {
657666
if (step.title) {
658667
document.title = step.title;
@@ -677,6 +686,16 @@ const IWSY = (container, script) => {
677686
step.next();
678687
};
679688

689+
// Chain to another presentation
690+
const chain = step => {
691+
step.next()
692+
};
693+
694+
// Embed another presentation
695+
const embed = step => {
696+
step.next()
697+
};
698+
680699
const actions = {
681700
init,
682701
setcontent,
@@ -689,7 +708,9 @@ const IWSY = (container, script) => {
689708
crossfade,
690709
transition,
691710
goto,
692-
load
711+
load,
712+
chain,
713+
embed
693714
};
694715

695716
// Process a single step
@@ -722,104 +743,48 @@ const IWSY = (container, script) => {
722743
handler(step);
723744
};
724745

725-
// Initialization
726-
const setup = () => {
727-
container.innerHTML = ``;
728-
document.removeEventListener(`click`, init);
729-
if (mode === `auto`) {
730-
document.addEventListener(`click`, onClick);
731-
}
732-
document.onkeydown = null;
733-
script.container = container;
734-
container.style.position = `relative`;
735-
container.style.overflow = `hidden`;
736-
container.style.cursor = 'none';
737-
container.style[`background-size`] = `cover`;
738-
script.speed = `normal`;
739-
script.labels = {};
740-
for (const [index, step] of script.steps.entries()) {
741-
step.index = index;
742-
step.script = script;
743-
if (typeof step.label !== `undefined`) {
744-
script.labels[step.label] = index;
745-
}
746-
if (index < script.steps.length - 1) {
747-
step.next = () => {
746+
container.innerHTML = ``;
747+
document.removeEventListener(`click`, init);
748+
if (mode === `auto`) {
749+
document.addEventListener(`click`, onClick);
750+
}
751+
document.onkeydown = null;
752+
script.container = container;
753+
container.style.position = `relative`;
754+
container.style.overflow = `hidden`;
755+
container.style.cursor = 'none';
756+
container.style[`background-size`] = `cover`;
757+
script.speed = `normal`;
758+
script.singleStep = true;
759+
script.labels = {};
760+
for (const [index, step] of script.steps.entries()) {
761+
step.index = index;
762+
step.script = script;
763+
if (typeof step.label !== `undefined`) {
764+
script.labels[step.label] = index;
765+
}
766+
if (index < script.steps.length - 1) {
767+
step.next = () => {
768+
if (script.singleStep && script.speed != `scan`) {
769+
console.log(`Single-step`);
770+
} else {
748771
const next = step.index + 1;
749772
setTimeout(() => {
750773
doStep(script.steps[next]);
751774
}, 0);
752775
}
753776
}
754-
else {
755-
step.next = () => {
756-
console.log(`Step ${index + 1}: Finished`);
757-
container.style.cursor = 'pointer';
758-
}
759-
};
760-
}
761-
IWSY.plugins = {};
762-
initBlocks();
763-
preloadImages();
764-
doStep(script.steps[0]);
765-
};
766-
767-
// Wait for a click/tap or a keypress to start
768-
document.addEventListener(`click`, init);
769-
document.onkeydown = function (event) {
770-
if (event.code === `Enter`) {
771-
mode = `auto`;
772-
}
773-
setup();
774-
return true;
775-
};
776-
};
777-
778-
window.onload = () => {
779-
const createCORSRequest = (url) => {
780-
let xhr = new XMLHttpRequest();
781-
if (`withCredentials` in xhr) {
782-
783-
// Check if the XMLHttpRequest object has a "withCredentials" property.
784-
// "withCredentials" only exists on XMLHTTPRequest2 objects.
785-
xhr.open(`GET`, url, true);
786-
787-
} else if (typeof XDomainRequest != `undefined`) {
788-
789-
// Otherwise, check if XDomainRequest.
790-
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
791-
xhr = new XDomainRequest();
792-
xhr.open(`GET`, url);
793-
794-
} else {
795-
796-
// Otherwise, CORS is not supported by the browser.
797-
xhr = null;
798-
799777
}
800-
return xhr;
801-
};
802-
803-
const scriptElement = document.getElementById(`iwsy-script`);
804-
if (scriptElement) {
805-
const request = createCORSRequest(`${scriptElement.innerText}?v=${Math.floor(Date.now())}`);
806-
if (!request) {
807-
throw Error(`Unable to access the JSON script`);
808-
}
809-
810-
request.onload = () => {
811-
if (200 <= request.status && request.status < 400) {
812-
const script = JSON.parse(request.responseText);
813-
IWSY(document.getElementById(`iwsy-container`), script);
814-
} else {
815-
throw Error(`Unable to access the JSON script`);
778+
else {
779+
step.next = () => {
780+
console.log(`Step ${index + 1}: Finished`);
781+
container.style.cursor = 'pointer';
816782
}
817783
};
818-
819-
request.onerror = () => {
820-
throw Error(`Unable to access the JSON script`);
821-
};
822-
823-
request.send();
824784
}
785+
IWSY.plugins = {};
786+
initBlocks();
787+
preloadImages();
788+
doStep(script.steps[0]);
789+
return gotoStep;
825790
};

0 commit comments

Comments
 (0)
Please sign in to comment.