Skip to content

Commit 4d01bea

Browse files
authored
Merge pull request #91 from easycoder/dev
Development
2 parents 269812f + cc7814e commit 4d01bea

File tree

8 files changed

+232
-27
lines changed

8 files changed

+232
-27
lines changed

dist/plugins/iwsy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const EasyCoder_IWSY = {
109109
run: (program) => {
110110
const command = program[program.pc];
111111
const action = command.action;
112+
let scriptRecord;
112113
let script;
113114
switch (action) {
114115
case `init`:

iwsy/iwsy.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const IWSY = (container, text) => {
111111
element.style[`height`] = val;
112112
element.style[`background`] = block.background;
113113
element.style[`border`] = block.border;
114+
element.style[`overflow`] = `hidden`;
114115
val = block.textMarginLeft;
115116
if (!isNaN(val)) {
116117
val *= w;
@@ -151,7 +152,8 @@ const IWSY = (container, text) => {
151152
if (!block.element) {
152153
createBlock(block);
153154
}
154-
block.textPanel.innerHTML = content.split(`\n`).join(`<br>`);
155+
const converter = new showdown.Converter();
156+
block.textPanel.innerHTML = converter.makeHtml(content.split(`%0a`).join(`\n`));
155157
};
156158

157159
// Set the content of a block
@@ -605,7 +607,24 @@ const IWSY = (container, text) => {
605607
cb();
606608
};
607609
document.head.appendChild(element);
608-
},
610+
};
611+
612+
// Set a HEAD style
613+
const setHeadStyle = (styleName, styleValue) => {
614+
for (let i = 0; i < document.head.childNodes.length; i++) {
615+
let node = document.head.childNodes[i];
616+
if (node.tagName === `STYLE`) {
617+
let data = node.innerHTML;
618+
if (data.indexOf(`${styleName} `) === 0) {
619+
document.head.removeChild(node);
620+
break;
621+
}
622+
}
623+
}
624+
var style = document.createElement('style');
625+
style.innerHTML = `${styleName} ${styleValue}`;
626+
document.head.appendChild(style);
627+
};
609628

610629
// Initialize the script
611630
const initScript = () => {
@@ -700,14 +719,21 @@ const IWSY = (container, text) => {
700719
if (script.onStepCB && script.runMode === `auto`) {
701720
script.onStepCB(step.index);
702721
}
703-
handler(step);
722+
try {
723+
handler(step);
724+
} catch (err) {
725+
console.log(`Step ${step.index} (${step.action}): ${err}`);
726+
alert(`Step ${step.index} (${step.action}): ${err}`);
727+
}
704728
};
705729

706730
container.innerHTML = ``;
707731
document.removeEventListener(`click`, init);
708732
if (script.runMode === `auto`) {
709733
document.addEventListener(`click`, onClick);
710734
}
735+
setHeadStyle(`p`, `{margin:0 0 0.5em 0}`)
736+
setHeadStyle(`h1, h2, h3, h4, h5, h6`, `{margin:0}`)
711737
setupShowdown();
712738
initScript();
713739
IWSY.plugins = {};

iwsy/resources/ecs/blocks.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
input BlockNameInput
1616
input PropertyValue
1717
button EditButton
18+
button SaveButton
1819
img AddBlock
1920
img DeleteBlock
2021
a Link
@@ -84,6 +85,7 @@ Restart:
8485
set the elements of BlockNameSpan to N
8586
set the elements of BlockNameInput to N
8687
set the elements of EditButton to N
88+
set the elements of SaveButton to N
8789
set the elements of Editor to N
8890
set the elements of DeleteBlock to N
8991
create Table in Panel
@@ -149,6 +151,7 @@ Restart:
149151
set the text of EditButton to `Properties`
150152
index BlockNameSpan to SelectedBlock
151153
index BlockNameInput to SelectedBlock
154+
index SaveButton to SelectedBlock
152155
set style `display` of BlockNameSpan to `none`
153156
set style `display` of BlockNameInput to `inline`
154157
index Editor to SelectedBlock
@@ -173,6 +176,11 @@ Restart:
173176
set the content of PropertyValue to property PropertyName of Block
174177
add 1 to N
175178
end
179+
create Row in Editor
180+
create SaveButton in Row
181+
set the style of SaveButton to `width:100%`
182+
set the text of SaveButton to `Save`
183+
on click SaveButton gosub to SaveSelectedBlock
176184
end
177185
else
178186
begin

iwsy/resources/ecs/content.txt

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
input ItemNameInput
1616
textarea TextArea
1717
button EditButton
18+
button SaveButton
1819
img AddItem
1920
img DeleteItem
2021
a Link
@@ -61,22 +62,30 @@ Restart:
6162
on click AddItem
6263
begin
6364
put prompt `Name of new content item:` with `new content` into ItemName
64-
set Item to object
65+
put empty into Item
6566
set property ItemName of Items to Item
6667
set property `content` of Presentation to Items
6768
go to Restart
6869
end
6970

70-
put the json count of ItemNames into N
71+
put the json keys of Items into ItemNames
72+
put the json count of ItemNames into N
73+
set the elements of ItemNameSpan to N
74+
set the elements of ItemNameInput to N
7175
set the elements of EditButton to N
7276
set the elements of Editor to N
77+
set the elements of SaveButton to N
7378
set the elements of DeleteItem to N
7479
set the elements of TextArea to N
7580
create Table in Panel
7681
set the style of Table to `width:100%`
7782
put 0 into B
7883
while B is less than the elements of EditButton
7984
begin
85+
index EditButton to B
86+
index DeleteItem to B
87+
index ItemNameSpan to B
88+
index ItemNameInput to B
8089
put element B of ItemNames into ItemName
8190
create TR in Table
8291
create TD in TR
@@ -90,8 +99,6 @@ Restart:
9099
set the content of ItemNameInput to ItemName
91100
create TD in TR
92101
set the style of TD to `border:1px solid black`
93-
index EditButton to B
94-
index DeleteItem to B
95102
index Editor to B
96103
create Row in TD
97104
set the style of Row to `display:flex`
@@ -136,17 +143,22 @@ Restart:
136143
index ItemNameSpan to SelectedItem
137144
index ItemNameInput to SelectedItem
138145
index TextArea to SelectedItem
146+
index SaveButton to SelectedItem
139147
set style `display` of ItemNameSpan to `none`
140148
set style `display` of ItemNameInput to `inline`
141149
index Editor to SelectedItem
142150
set style `display` of Editor to `block`
143151
clear Editor
144-
put property ItemName of Items into Item
145152
create TextArea in Editor
146153
set the style of TextArea to `width:100%;max-width:100%;height:8em`
147154
put element SelectedItem of ItemNames into ItemName
155+
put property ItemName of Items into Item
148156
replace `%0a` with newline in Item
149157
set the content of TextArea to Item
158+
create SaveButton in Editor
159+
set the style of SaveButton to `width:100%`
160+
set the text of SaveButton to `Save`
161+
on click SaveButton gosub to SaveSelectedItem
150162
end
151163
else gosub to SaveSelectedItem
152164
end
@@ -161,20 +173,18 @@ Restart:
161173
end
162174
stop
163175

164-
! Save the seleced content
176+
! Save the selected content
165177
SaveSelectedItem:
166178
if SelectedItem is -1 return
179+
index ItemNameInput to SelectedItem
180+
index TextArea to SelectedItem
167181
put the content of TextArea into Item
168182
replace newline with `%0a` in Item
169183
set property ItemName of Items to Item
170-
index ItemNameInput to SelectedItem
171-
if ItemNameInput is not ItemName
172-
begin
173-
json delete property ItemName of Items
174-
put ItemNameInput into ItemName
175-
set element SelectedItem of ItemNames to ItemName
176-
set property ItemName of Items to Item
177-
end
184+
if ItemNameInput is not ItemName json delete property ItemName of Items
185+
put ItemNameInput into ItemName
186+
set element SelectedItem of ItemNames to ItemName
187+
set property ItemName of Items to Item
178188
set property `content` of Presentation to Items
179189

180190
! Tell the parent to refresh the script

iwsy/resources/ecs/iwsy.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
variable Item
4848
variable CurrentScriptName
4949
variable Action
50-
variable Source
5150
variable Running
5251
variable N
5352

@@ -523,7 +522,6 @@ SelectFile:
523522
set the content of Status to `Presentation '` cat File cat `' loaded`
524523
fork to ResetStatus
525524
set ShowRun
526-
print Presentation
527525
iwsy load Player Presentation
528526

529527
CloseBrowser:

iwsy/resources/ecs/steps.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
variable Block
4747
variable Contents
4848
variable Target
49-
variable Types
5049
variable Duration
5150
variable URL
5251
variable Names
@@ -763,12 +762,6 @@ CreateNewAction:
763762
end
764763
else if Action is `transition`
765764
begin
766-
put property `types` of CurrentStep into Types
767-
if Types is empty
768-
begin
769-
set Types to array
770-
set property `types` of CurrentStep to Types
771-
end
772765
put property `target` of CurrentStep into Target
773766
if Target is empty set property `target` of CurrentStep to `******`
774767
put property `duration` of CurrentStep into Duration

0 commit comments

Comments
 (0)