-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Core: added config option to specify init module
The bootstrap tag now allows to specify the init module via the attribute data-sap-ui-oninit. When prefixing the module name with "module:" the bootstrap identifies to require the given module. The init module will be loaded via a timeout to ensure that the boot step is completed before the module is required and loaded. This will also ensure an async behavior for the init module. Example usage: <script id='sap-ui-bootstrap' data-sap-ui-oninit='module:sap/ui/test/Main' data-sap-ui-resourceroots='{"sap.ui.test": "./}'> </script> In addition, the Core#_executeOnInit has been extended looking up specified functions instead of just evaluating the code. If you just write a String without "module:" prefix and without brackets it will try to lookup this function and execute it, e.g.: <script> window.my = { initfn: function() { ... } }; </script> <script id='sap-ui-bootstrap' data-sap-ui-oninit='my.initfn'> </script> or directly a function reference like this: <script> function initfn() { ... } </script> <script id='sap-ui-bootstrap' data-sap-ui-oninit='initfn'> </script> or directly as code: <script> function initfn() { ... } </script> <script id='sap-ui-bootstrap' data-sap-ui-oninit='initfn();'> </script> Change-Id: I64eb1926cdb494328214e44f0c2b547d018523e5
- Loading branch information
1 parent
3c97342
commit 8472aad
Showing
5 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/sap.ui.core/test/sap/ui/core/qunit/bootstrap/BootstrapMainModule.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
sap.ui.define(["sap/ui/core/Core"], function(Core) { | ||
window["sap-ui-main"] = true; | ||
}); |
41 changes: 41 additions & 0 deletions
41
src/sap.ui.core/test/sap/ui/core/qunit/bootstrap/BootstrapMainModule.qunit.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!DOCTYPE HTML> | ||
<!-- | ||
Tests the bootstrap variant with the attribute data-sap-ui-main specifying the main module | ||
@author Peter Muessig | ||
--> | ||
<html> | ||
<head> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta charset="utf-8"> | ||
<title>Test Page for Bootstrap within Head</title> | ||
|
||
<!-- Initialization --> | ||
<link rel="stylesheet" href="../../../../../../resources/sap/ui/thirdparty/qunit.css" type="text/css" media="screen"> | ||
<script src="../../../../../../resources/sap/ui/thirdparty/qunit.js"></script> | ||
<script src="../../../../../../resources/sap/ui/qunit/qunit-junit.js"></script> | ||
<script src="../../shared-config.js"></script> | ||
<script id="sap-ui-bootstrap" | ||
src="../../../../../../resources/sap-ui-core.js" | ||
data-sap-ui-oninit="module:sap/ui/test/BootstrapMainModule" | ||
data-sap-ui-resourceroots='{"sap.ui.test": "./"}' | ||
> | ||
</script> | ||
<script src="../../../../../../resources/sap/ui/qunit/QUnitUtils.js"></script> | ||
|
||
<script> | ||
QUnit.test("Check Main Module Functionality", function(assert) { | ||
var done = assert.async(); | ||
sap.ui.getCore().attachInit(function() { | ||
assert.ok(window["sap-ui-main"], "Main module has been loaded and executed."); | ||
done(); | ||
}); | ||
}); | ||
</script> | ||
|
||
</head> | ||
|
||
<body class="sapUiBody" role="application"> | ||
<div id="qunit"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters