Getting started
Starting netDecor is easy: add two JavaScript files to your document (NetPlusAPI.js, UnityLoader.js) and call RunNetPlusApp:
function RunNetPlusApp(containerId: string, buildPath: string, params: string, onAPIInitialised);
containerId: string; // ID of element where netDecor will be embedded.
buildPath: string; // URL to app data (comes in package delivered by CADProjekt).
params: string // JSON containing startup info.
dbaddr: string // startup paremeter, database address
onAPIInitialised : Function // no-argument-method that will be called right after API initialisation is complete. This parameter is optional
How exaclty "params" JSON looks like is client-dependant, but one of parameters will be dbaddr : string – database URL.
RunNetPlusAPP returns integer (errorCode):
0 – no error
1 – app is running already
If this call is executed properly there will be new object available: window.NetDecor, which contains API (also window.NetPlusAPI, API calls in that object are DEPRECATED and will be removed in a future.)
IMPORTANT netDecor API is not asynchronous and is available only after app is initially loaded. In order to be sure it is callable you need to implement onAPIInitialised parameter from runNetPlusAPP
Many of publicly facing API calls are overrides of events fired up by an app, in order to register override for event you need to call window.NetDecor.Events.RegisterEventHandler
window.NetDecor.Events.RegisterEventHandler("eventName",methodToCall);
„eventName” : string – name of an event you want to override (names are included in this document)
methodToCall : function – method that will be called instead of default implementation when firing event.
Example (simple html file with netDecor app and auto-resizing canvas):
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>netDecor template</title>
<link rel="stylesheet" href="TemplateData/style.css">
<link rel="stylesheet" href="Frames.css">
<script src="Build/UnityLoader.js"></script>
<script src="NetPlusAPI.js"></script>
<style>
</style>
</head>
<body class="template" id="appcontainer">
<script type='text/javascript'>
function onElementHeightChange(elm, callback) {
var lastHeight = elm.clientHeight, newHeight;
var lastWidth = elm.clientWidth, newWidth;
(function run() {
newHeight = elm.clientHeight;
newWidth = elm.clientWidth;
if (lastHeight != newHeight || lastWidth != newWidth)
callback();
lastHeight = newHeight;
lastWidth = newWidth;
if (elm.onElementHeightChangeTimer)
clearTimeout(elm.onElementHeightChangeTimer);
elm.onElementHeightChangeTimer = setTimeout(run, 200);
})();
}
onElementHeightChange(document.documentElement, function () {
var canvasEl = document.getElementById("#canvas");
if(canvasEl != null)
{
canvasEl.width = document.documentElement.clientWidth;
canvasEl.height = document.documentElement.clientHeight;
}
});
var myEvent = window.attachEvent || window.addEventListener;
var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; /// make IE7, IE8 compitable
myEvent(chkevent, function (e) { // For >=IE7, Chrome, Firefox
var confirmationMessage = 'Are you sure to leave the page?'; // a space
(e || window.event).returnValue = confirmationMessage;
return confirmationMessage;
});
RunNetPlusApp("appcontainer", "Build/","{ \"dbaddr\":\"database/\"}");
</script>
</body>
</html>
Method can throw exceptions, most often because of bad call parameters. ALL API calls can throw exceptions!