Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit 7143be7

Browse files
committed
- preparation of submodules in sApi_modules that need to be executed (init()-functions) on document ready
- $s.require.object() bugfix for global objects that are not a child of window
1 parent f27050a commit 7143be7

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ A minimalistic javascript api: The core is a little javascript that can extend i
55

66
|   Version   | Info |
77
|---|---|
8+
| 202112.01 | Init for bundled sApi_modules, bugfix for $s.require.object() |
89
| 202012.01 | First public version of sApi, based on smdQS/smdApi from Schwäbisch Media Digital |
910
| 202106.01 | Some little fixes |
1011

sApi.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
_includeModulesPlaceHolder: {},
1919

2020
//to check which version of the api is running
21-
version: 202106.01,
21+
version: 202112.01,
2222

2323
/**
2424
* extends smdApi with object
@@ -204,8 +204,9 @@
204204
_onApiReady($s, splittedApiName, apiName);
205205
}
206206
};
207+
207208
/**
208-
* Initializes all subobjects of $s.
209+
* Initializes all ready functions of $s' subobjects.
209210
*/
210211
$s.ready(function()
211212
{
@@ -217,6 +218,15 @@
217218
delete($s._rF);
218219
});
219220

221+
/**
222+
* Prepares all subobjects of $s that are bundled via sApi_modules
223+
*/
224+
for (let i in $s) {
225+
if (typeof $s[i] === "object" && i !== "_rF") {
226+
$s._isapi($s, i, [i]);
227+
}
228+
}
229+
220230
// default name is $s
221231
w[pvn || "$s"] = $s;
222-
}(window, document));
232+
}(window, document));

sApi_modules/03_s_require.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ $s.extend({
142142
*/
143143
object: function (objectName, callback, useCustomEventListener)
144144
{
145+
try {
146+
let re = new RegExp("^[a-zA-Z0-9_]+$");
147+
if (re.exec(objectName) !== null && typeof eval(objectName) === "object") {
148+
callback();
149+
return;
150+
}
151+
} catch (e) {}
152+
145153
useCustomEventListener = useCustomEventListener || false;
146154
if (objectName in window) {
147155
callback();
@@ -158,4 +166,4 @@ $s.extend({
158166
}
159167
}
160168
}
161-
});
169+
});

0 commit comments

Comments
 (0)