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

Commit

Permalink
- preparation of submodules in sApi_modules that need to be executed …
Browse files Browse the repository at this point in the history
…(init()-functions) on document ready

- $s.require.object() bugfix for global objects that are not a child of window
  • Loading branch information
codeandcreate committed Dec 6, 2021
1 parent f27050a commit 7143be7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ A minimalistic javascript api: The core is a little javascript that can extend i

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

Expand Down
16 changes: 13 additions & 3 deletions sApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
_includeModulesPlaceHolder: {},

//to check which version of the api is running
version: 202106.01,
version: 202112.01,

/**
* extends smdApi with object
Expand Down Expand Up @@ -204,8 +204,9 @@
_onApiReady($s, splittedApiName, apiName);
}
};

/**
* Initializes all subobjects of $s.
* Initializes all ready functions of $s' subobjects.
*/
$s.ready(function()
{
Expand All @@ -217,6 +218,15 @@
delete($s._rF);
});

/**
* Prepares all subobjects of $s that are bundled via sApi_modules
*/
for (let i in $s) {
if (typeof $s[i] === "object" && i !== "_rF") {
$s._isapi($s, i, [i]);
}
}

// default name is $s
w[pvn || "$s"] = $s;
}(window, document));
}(window, document));
10 changes: 9 additions & 1 deletion sApi_modules/03_s_require.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ $s.extend({
*/
object: function (objectName, callback, useCustomEventListener)
{
try {
let re = new RegExp("^[a-zA-Z0-9_]+$");
if (re.exec(objectName) !== null && typeof eval(objectName) === "object") {
callback();
return;
}
} catch (e) {}

useCustomEventListener = useCustomEventListener || false;
if (objectName in window) {
callback();
Expand All @@ -158,4 +166,4 @@ $s.extend({
}
}
}
});
});

0 comments on commit 7143be7

Please sign in to comment.