Commit 7e8c50e6 authored by Ivan Tyagov's avatar Ivan Tyagov

Move to examples.

Add more comments what needs to be done.
parent 45670813
<p id='A_test'>A test gadget</p>
<script type="text/javascript" src="http://localhost/renderjs/A.js"></script>
\ No newline at end of file
<p id='B_test'>B test gadget</p>
<script type="text/javascript" src="http://localhost/renderjs/B.js"></script>
\ No newline at end of file
<p id='C_test'>C test gadget</p>
<script type="text/javascript" src="http://localhost/renderjs/C.js"></script>
\ No newline at end of file
<html>
<head>
<title>Proto 1</title>
<title>Proto using safe-js</title>
<script data-main="./require-renderjs.js"
type="text/javascript"
......@@ -10,21 +10,21 @@
</head>
<body>
<div id="test"></div>
<div id="test_no"> No changable</div>
<div id="test">This example is in root folder until we find a way to use properly requirejs
with renderjs dependencies inside a worker environment
</div>
<div id="A"
data-gadget="A.html"
data-gadget="examples/safe-js/A.html"
data-gadget-safejs="1"></div>
<div id="B"
data-gadget="B.html"
data-gadget="examples/safe-js/B.html"
data-gadget-safejs="1"></div>
<div id="C"
data-gadget="C.html"
data-gadget="examples/safe-js/C.html"
data-gadget-safejs="0"></div>
</body>
......
<p id='A_test'>A test gadget</p>
<script type="text/javascript" src="http://localhost/renderjs/examples/safe-js/A.js"></script>
\ No newline at end of file
$("#A_test").html("hi A");
//$("#test_no").html("hi");
getSelfGadget().whatsyourname = function() {
return 'I am A';
}
// ask gadget C which is not sandbox what it's name is
// as it's asynchronous provide a callback to get executed when
// result is know
communicate('C', 'whatsyourname', function(name) {
console.log(name);
});
\ No newline at end of file
<p id='B_test'>B test gadget</p>
<script type="text/javascript" src="http://localhost/renderjs/examples/safe-js/B.js"></script>
\ No newline at end of file
......@@ -4,7 +4,6 @@ getSelfGadget.whatsyourname = function() {
return 'I am B';
}
communicate('A', 'whatsyourname', function(name) {
console.log(name);
});
\ No newline at end of file
<p id='C_test'>C test gadget</p>
<script type="text/javascript" src="http://localhost/renderjs/examples/safe-js/C.js"></script>
\ No newline at end of file
......@@ -202,17 +202,14 @@ var RenderJs = (function () {
* Set gadget data and recursively load it in case it holds another
* gadgets.
*/
var element, scripts;
var element, scripts, gadget_js, sandbox;
// set current gadget as being loaded so gadget instance itself knows which gadget it is
var gadget_js, sandbox;
setSelfGadget(gadget_js = RenderJs.GadgetIndex.getGadgetById(gadget.attr("id")));
element = $('<div>' + data + '</div>');
element = $('<div>' + data + '</div>'); // we need to work with one root element only
is_sandoxed = gadget.attr("data-gadget-safejs");
console.log(is_sandoxed);
// XXX: replace javascript by safe javascript
if(typeof safejs !== 'undefined' && (is_sandoxed==="1")) {
// we need to replace javascript by safe javascript which will be loaded inside a worker
// by safe-js
if (typeof safejs !== 'undefined' && is_sandoxed==="1") {
scripts = [];
$($(element).find("script").attr("type", "text/safe-javascript")).get()
.forEach(function(each) { scripts.push($(each).attr('src')) });
......@@ -220,10 +217,13 @@ var RenderJs = (function () {
sandbox = safejs({policy: "read-write",
scripts: scripts,
node: element.get(0),
// XXX: remove hard coded url
dependencies: ["http://localhost/renderjs/renderjs.js"]
});
gadget_js.sandbox = sandbox;
} else {
}
else {
// not sandboxed
gadget.append(element);
}
......
// JavaScript file that is used to load RenderJs depenencies
require.config({
paths: {
jquery: "lib/jquery/jquery",
// "jquery.json": "lib/json/jquery.json.min",
// davstorage: "lib/jio/davstorage",
// md5: "lib/jio/md5",
// jio: "lib/jio/jio",
renderjs: "renderjs",
//"safe": "./lib/safe-js/safe"
},
shim: {
// "jquery.json": [ "jquery" ],
// jio: ["md5"],
// davstorage: ["jio"],
//"safe": ["renderjs"],
renderjs: [ "jquery"] //, "jquery.json", "jio", "md5", "davstorage" ]
}
});
require([ "renderjs"], function(domReady) {
RenderJs.init();
});
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment