Skip to content

Commit 1b61946

Browse files
committedOct 30, 2021
Add retry to 'attach' with 1-second limit
1 parent 1352ad8 commit 1b61946

File tree

9 files changed

+175
-137
lines changed

9 files changed

+175
-137
lines changed
 

‎dist/easycoder-min.js

Lines changed: 97 additions & 97 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/easycoder.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,23 +3222,9 @@ const EasyCoder_Browser = {
32223222
element = document.body;
32233223
} else {
32243224
content = program.value.evaluate(program, command.cssId).content;
3225-
element = document.getElementById(content);
3226-
}
3227-
if (!element) {
3228-
if (command.onError) {
3229-
program.run(command.onError);
3230-
} else {
3231-
program.runtimeError(command.lino, `No such element: '${content}'`);
3232-
}
3225+
EasyCoder_Browser.Attach.getElementById(program, command, content, 100);
32333226
return 0;
32343227
}
3235-
const target = program.getSymbolRecord(command.symbol);
3236-
target.element[target.index] = element;
3237-
target.value[target.index] = {
3238-
type: `constant`,
3239-
numeric: false,
3240-
content
3241-
};
32423228
if (command.type === `popup`) {
32433229
// Register a popup
32443230
program.popups.push(element.id);
@@ -3250,7 +3236,37 @@ const EasyCoder_Browser = {
32503236
};
32513237
}
32523238
return command.pc + 1;
3253-
}
3239+
},
3240+
3241+
getElementById: (program, command, id, retries) => {
3242+
element = document.getElementById(id);
3243+
if (element) {
3244+
if (program.run) {
3245+
const target = program.getSymbolRecord(command.symbol);
3246+
target.element[target.index] = element;
3247+
target.value[target.index] = {
3248+
type: `constant`,
3249+
numeric: false,
3250+
id
3251+
};
3252+
program.run(command.pc + 1);
3253+
}
3254+
} else {
3255+
if (retries > 0) {
3256+
setTimeout(function() {
3257+
EasyCoder_Browser.Attach.getElementById(program, command, id, --retries);
3258+
}, 10);
3259+
} else {
3260+
if (!element) {
3261+
if (command.onError) {
3262+
program.run(command.onError);
3263+
} else {
3264+
program.runtimeError(command.lino, `No such element: '${id}'`);
3265+
}
3266+
}
3267+
}
3268+
}
3269+
}
32543270
},
32553271

32563272
Audioclip: {
@@ -8290,7 +8306,7 @@ const EasyCoder = {
82908306
require: function(type, src, cb) {
82918307
let prefix = ``;
82928308
if (src[0] == `/`) {
8293-
prefix = window.location + `/`;
8309+
prefix = window.location.origin + `/`;
82948310
}
82958311
const element = document.createElement(type === `css` ? `link` : `script`);
82968312
switch (type) {
@@ -8519,7 +8535,7 @@ const EasyCoder = {
85198535
}
85208536
},
85218537
};
8522-
EasyCoder.version = `2.7.7`;
8538+
EasyCoder.version = `2.7.8`;
85238539
EasyCoder.timestamp = Date.now();
85248540
console.log(`EasyCoder loaded; waiting for page`);
85258541

‎dist/easycoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: EasyCoder
44
* Plugin URI: https://easycoder.software
55
* Description: Control the appearance and behavior of your posts and pages by embedding simple English-like scripts, without the need to learn JavaScript.
6-
* Version: 2.7.7
6+
* Version: 2.7.8
77
* Author: EasyCoder Software
88
* Author URI: https://easycoder.software
99
*/
@@ -16,7 +16,7 @@
1616
add_action('wp_enqueue_scripts', 'easycoder_enqueue_script', 2);
1717
function easycoder_enqueue_script() {
1818
wp_enqueue_script('easycoder_script',
19-
'https://cdn.jsdelivr.net/gh/easycoder/easycoder.github.io/dist/easycoder.js', array(), '2.7.7');
19+
'https://cdn.jsdelivr.net/gh/easycoder/easycoder.github.io/dist/easycoder.js', array(), '2.7.8');
2020
}
2121

2222
// Set up default plugin and REST scripts

‎dist/readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ For tutorials and a programmers' reference see our [EasyCoder Software Codex](ht
5454

5555
== Changelog ==
5656

57+
= 2.7.8 30-oct 2021 =
58+
* Retry 'attach' up to 1 second
59+
5760
= 2.7.7 20-aug 2021 =
5861
* Add encode/decode for Base64
5962

‎js/easycoder/Browser.js

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,9 @@ const EasyCoder_Browser = {
124124
element = document.body;
125125
} else {
126126
content = program.value.evaluate(program, command.cssId).content;
127-
element = document.getElementById(content);
128-
}
129-
if (!element) {
130-
if (command.onError) {
131-
program.run(command.onError);
132-
} else {
133-
program.runtimeError(command.lino, `No such element: '${content}'`);
134-
}
127+
EasyCoder_Browser.Attach.getElementById(program, command, content, 100);
135128
return 0;
136129
}
137-
const target = program.getSymbolRecord(command.symbol);
138-
target.element[target.index] = element;
139-
target.value[target.index] = {
140-
type: `constant`,
141-
numeric: false,
142-
content
143-
};
144130
if (command.type === `popup`) {
145131
// Register a popup
146132
program.popups.push(element.id);
@@ -152,7 +138,37 @@ const EasyCoder_Browser = {
152138
};
153139
}
154140
return command.pc + 1;
155-
}
141+
},
142+
143+
getElementById: (program, command, id, retries) => {
144+
element = document.getElementById(id);
145+
if (element) {
146+
if (program.run) {
147+
const target = program.getSymbolRecord(command.symbol);
148+
target.element[target.index] = element;
149+
target.value[target.index] = {
150+
type: `constant`,
151+
numeric: false,
152+
id
153+
};
154+
program.run(command.pc + 1);
155+
}
156+
} else {
157+
if (retries > 0) {
158+
setTimeout(function() {
159+
EasyCoder_Browser.Attach.getElementById(program, command, id, --retries);
160+
}, 10);
161+
} else {
162+
if (!element) {
163+
if (command.onError) {
164+
program.run(command.onError);
165+
} else {
166+
program.runtimeError(command.lino, `No such element: '${id}'`);
167+
}
168+
}
169+
}
170+
}
171+
}
156172
},
157173

158174
Audioclip: {

‎js/easycoder/EasyCoder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
EasyCoder.version = `2.7.7`;
1+
EasyCoder.version = `2.7.8`;
22
EasyCoder.timestamp = Date.now();
33
console.log(`EasyCoder loaded; waiting for page`);
44

‎js/easycoder/Main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ const EasyCoder = {
151151
require: function(type, src, cb) {
152152
let prefix = ``;
153153
if (src[0] == `/`) {
154-
prefix = window.location + `/`;
154+
prefix = window.location.origin + `/`;
155155
}
156156
const element = document.createElement(type === `css` ? `link` : `script`);
157157
switch (type) {

‎server/easycoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: EasyCoder
44
* Plugin URI: https://easycoder.software
55
* Description: Control the appearance and behavior of your posts and pages by embedding simple English-like scripts, without the need to learn JavaScript.
6-
* Version: 2.7.7
6+
* Version: 2.7.8
77
* Author: EasyCoder Software
88
* Author URI: https://easycoder.software
99
*/
@@ -16,7 +16,7 @@
1616
add_action('wp_enqueue_scripts', 'easycoder_enqueue_script', 2);
1717
function easycoder_enqueue_script() {
1818
wp_enqueue_script('easycoder_script',
19-
'https://cdn.jsdelivr.net/gh/easycoder/easycoder.github.io/dist/easycoder.js', array(), '2.7.7');
19+
'https://cdn.jsdelivr.net/gh/easycoder/easycoder.github.io/dist/easycoder.js', array(), '2.7.8');
2020
}
2121

2222
// Set up default plugin and REST scripts

‎server/readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ For tutorials and a programmers' reference see our [EasyCoder Software Codex](ht
5454

5555
== Changelog ==
5656

57+
= 2.7.8 30-oct 2021 =
58+
* Retry 'attach' up to 1 second
59+
5760
= 2.7.7 20-aug 2021 =
5861
* Add encode/decode for Base64
5962

0 commit comments

Comments
 (0)
Please sign in to comment.