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> <html>
<head> <head>
<title>Proto 1</title> <title>Proto using safe-js</title>
<script data-main="./require-renderjs.js" <script data-main="./require-renderjs.js"
type="text/javascript" type="text/javascript"
...@@ -10,21 +10,21 @@ ...@@ -10,21 +10,21 @@
</head> </head>
<body> <body>
<div id="test"></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 id="test_no"> No changable</div> </div>
<div id="A" <div id="A"
data-gadget="A.html" data-gadget="examples/safe-js/A.html"
data-gadget-safejs="1"></div> data-gadget-safejs="1"></div>
<div id="B" <div id="B"
data-gadget="B.html" data-gadget="examples/safe-js/B.html"
data-gadget-safejs="1"></div> data-gadget-safejs="1"></div>
<div id="C" <div id="C"
data-gadget="C.html" data-gadget="examples/safe-js/C.html"
data-gadget-safejs="0"></div> data-gadget-safejs="0"></div>
</body> </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"); $("#A_test").html("hi A");
//$("#test_no").html("hi");
getSelfGadget().whatsyourname = function() { getSelfGadget().whatsyourname = function() {
return 'I am A'; 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) { communicate('C', 'whatsyourname', function(name) {
console.log(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() { ...@@ -4,7 +4,6 @@ getSelfGadget.whatsyourname = function() {
return 'I am B'; return 'I am B';
} }
communicate('A', 'whatsyourname', function(name) { communicate('A', 'whatsyourname', function(name) {
console.log(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 () { ...@@ -202,17 +202,14 @@ var RenderJs = (function () {
* Set gadget data and recursively load it in case it holds another * Set gadget data and recursively load it in case it holds another
* gadgets. * gadgets.
*/ */
var element, scripts, gadget_js, sandbox;
var element, scripts;
// set current gadget as being loaded so gadget instance itself knows which gadget it is // 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"))); setSelfGadget(gadget_js = RenderJs.GadgetIndex.getGadgetById(gadget.attr("id")));
element = $('<div>' + data + '</div>'); // we need to work with one root element only
element = $('<div>' + data + '</div>');
is_sandoxed = gadget.attr("data-gadget-safejs"); is_sandoxed = gadget.attr("data-gadget-safejs");
console.log(is_sandoxed); // we need to replace javascript by safe javascript which will be loaded inside a worker
// XXX: replace javascript by safe javascript // by safe-js
if(typeof safejs !== 'undefined' && (is_sandoxed==="1")) { if (typeof safejs !== 'undefined' && is_sandoxed==="1") {
scripts = []; scripts = [];
$($(element).find("script").attr("type", "text/safe-javascript")).get() $($(element).find("script").attr("type", "text/safe-javascript")).get()
.forEach(function(each) { scripts.push($(each).attr('src')) }); .forEach(function(each) { scripts.push($(each).attr('src')) });
...@@ -220,10 +217,13 @@ var RenderJs = (function () { ...@@ -220,10 +217,13 @@ var RenderJs = (function () {
sandbox = safejs({policy: "read-write", sandbox = safejs({policy: "read-write",
scripts: scripts, scripts: scripts,
node: element.get(0), node: element.get(0),
// XXX: remove hard coded url
dependencies: ["http://localhost/renderjs/renderjs.js"] dependencies: ["http://localhost/renderjs/renderjs.js"]
}); });
gadget_js.sandbox = sandbox; gadget_js.sandbox = sandbox;
} else { }
else {
// not sandboxed
gadget.append(element); 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