Commit 9c5a59ce authored by Sven Franck's avatar Sven Franck

refactor of renderjs, first pass (working, not cleaned)

parent 25bd1e4d
# files
RENDERJS = renderjs.js
RENDERJS_MIN = renderjs.min.js
# npm install uglify-js
UGLIFY_CMD = $(shell which uglifyjs || echo node ~/node_modules/uglify-js/bin/uglifyjs)
# npm install jslint
LINT_CMD = $(shell which jslint || echo node ~/node_modules/jslint/bin/jslint.js) --terse
YUIDOC_CMD = $(shell which yuidoc)
auto: build
build: uglify
uglify: $(RENDERJS_MIN)
$(RENDERJS_MIN): $(RENDERJS)
$(UGLIFY_CMD) "$<" > "$@"
lint: $(RENDERJS)
$(LINT_CMD) "$<"
doc:
$(YUIDOC_CMD) .
clean:
rm -f $(RENDERJS_MIN)
What is RenderJs?
RenderJs is a JavaScript library which uses jQuery and RequireJS.
RenderJs provides an easy way to define gadgets (aka mashups) in pure HTML5 and does not require application server.
It handles dependencies through RequireJS, caching and interaction.
It is suitable for the development of mobile applications, desktop applications. It is used by OfficeJS, ERP5.
Documentation
Documentation is available at http://www.renderjs.org/
Developer
> git clone https://git.erp5.org/repos/renderjs.git
> make (will produce a minified version for now, requires nodejs installed as well its uglifyjs module)
> make lint (will produce a jslint report, requires nodejs installed as well its jslint module)
\ No newline at end of file
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>content</title>
<!-- API add service LINK (src optional) -->
<!-- <link rel="multiply" type="math" src="http://www.somewhere.com/else"> -->
<link rel="multiply" type="service/math">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../../renderjs.js"></script>
</head>
<body>
<table style="border: 1px solid black; font-size: 9px">
<tr>
<td colspan="2" style="text-align:center;"><b>content.html</b></td>
<tr>
<td><b>Loaded</b></td>
<td>Ajax (via addGadget())</td>
</tr>
<tr>
<td><b>Location</b></td>
<td>inside content_loader.html</td>
</tr>
<tr>
<td><b>Service</b></td>
<td>Multiply</td>
</tr>
<tr>
<td><b>Domain</b></td>
<td>same</td>
</tr>
</table>
<p>Loaded via AJAX, Service: Multiply, same domain</p>
<p>Hello, I provide a service</p>
<!-- API add service HTML (src optional) -->
<div data-service = '[{"rel":"multiply", "type":"service/math"}]'></div>
<script type="text/javascript">
//<![CDATA[
// service multiplication
var multiply = function (a, b) {
try {
return parseFloat(a)*parseFloat(b);
}
catch (e) {
return "not possible to multiply";
}
};
// API add service JS (src optional)
$(this).addService({"type": "service/math", "rel": "multiply"});
//]]>
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>content_loader</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../../renderjs.js"></script>
<body>
<table style="border: 1px solid black; font-size: 9px">
<tr>
<td colspan="2" style="text-align:center;"><b>content_loader.html</b></td>
<tr>
<td><b>Loaded</b></td>
<td>iFrame (from HTML source)</td>
</tr>
<tr>
<td><b>Location</b></td>
<td>inside index.html</td>
</tr>
<tr>
<td><b>Service</b></td>
<td>None</td>
</tr>
<tr>
<td><b>Domain</b></td>
<td>same</td>
</tr>
</table>
<p>Hello, I'm the gadge text</p>
<div class="foo"></div>
<script type="text/javascript">
$('.foo').addGadget({"src":"content.html"});
// $('.foo').addGadget({"src":"content.html", "iframe":"true"});
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>content</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../../renderjs.js"></script>
</head>
<body>
<table style="border: 1px solid black; font-size: 9px">
<tr>
<td colspan="2" style="text-align:center;"><b>content_menu.html</b></td>
<tr>
<td><b>Loaded</b></td>
<td>iFrame (from HTML source)</td>
</tr>
<tr>
<td><b>Location</b></td>
<td>inside index.html</td>
</tr>
<tr>
<td><b>Service</b></td>
<td>None</td>
</tr>
<tr>
<td><b>Domain</b></td>
<td>same</td>
</tr>
</table>
<ul>
<li><button class="a" data-foo="5" data-bar="6">Button A</button></li>
<li><button class="b" data-foo="4" data-bar="1">Button B</button></li>
<li><button class="c" data-foo="8" data-bar="2">Button C</button></li>
</ul>
<script type="text/javascript">
$(this.document).addGadget({"src":"http://domain1/sven/newRenderjs/examples/gadgets/deep_menu.html", "iframe":"true"});
// $(this.document).addGadget({"src":"deep_menu.html", "iframe":"true"});
</script>
<script type="text/javascript">
(function () {
//<![CDATA[
var document = this.document;
// // retrieve parameters set by renderJs
// setTimeout(function(){
// console.log("settimeout");
// console.log($("body")[0])
// console.log($("body")[0].config);
// },0);
}());
//]]>
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>content</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../../renderjs.js"></script>
</head>
<body>
<table style="border: 1px solid black; font-size: 9px">
<tr>
<td colspan="2" style="text-align:center;"><b>menu_deep.html</b></td>
<tr>
<td><b>Loaded</b></td>
<td>Nested iFrame (via addGadget())</td>
</tr>
<tr>
<td><b>Location</b></td>
<td>inside content_menu.html</td>
</tr>
<tr>
<td><b>Service</b></td>
<td>substract</td>
</tr>
<tr>
<td><b>Domain</b></td>
<td>CROSS DOMAIN</td>
</tr>
</table>
<p>Hello, I'm a cross domain gadget, providing Substract Service</p>
<ul>
<li><button class="e" data-foo="1" data-bar="1">Button D</button></li>
<li><button class="f" data-foo="11" data-bar="2">Button E</button></li>
<li><button class="g" data-foo="111" data-bar="3">Button F</button></li>
</ul>
<script type="text/javascript">
//<![CDATA[
var document = this.document;
$(this.document).find('button').on('click', function(e, target) {
// var parent;
// if ( window.self === window.top || self == top ) {
// // parent is root
// parent = window.location.href;
// } else {
// // inside an iFrame
// parent = window.parent.location.href;
// }
// console.log("DEEP");
// console.log(window);
// console.log("posting to:");
// console.log(parent);
// window.postMessage(e.target.getAttribute("data-foo"), parent);
});
// service substraction
var subtract = function (a, b) {
try {
return a-b;
}
catch (e) {
return "not possible to subtract";
}
};
// API add service JS (src optional)
$(this).addService({"type": "service/math", "rel": "subtract"});
//]]>
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>menu</title>
<link rel="google" type="search" src="google.com/index">
<link rel="bing" type="search" src="bing.com/index">
<link rel="duckduck" type="search" src="duckduckgo.com/index">
<link rel="word" type="office" src="somewhere.com/word">
<link rel="word" type="excel" src="somewhere.com/excel">
<link rel="powerpoint" type="excel" src="somewhere.com/powerpoint">
<script type="text/javascript">
(function () {
//<![CDATA[
// console.log("I'm the menu gadget, I provide a bunch of links to display");
}());
//]]>
</script>
</head>
<body>
<p>Hello world from the menu</p>
<div data-gadget="content.html"
data-id="content"
data-iframe="true"></div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>nestedPlainText</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../renderjs.js"></script>
</head>
<body>
<table style="border: 1px solid black; font-size: 9px">
<tr>
<td colspan="2" style="text-align:center;"><b>nestedplaintext.html</b></td>
<tr>
<td><b>Loaded</b></td>
<td>Ajax (HTML hardcoded)</td>
</tr>
<tr>
<td><b>Location</b></td>
<td>inside plaintext.html</td>
</tr>
<tr>
<td><b>Service</b></td>
<td>None</td>
</tr>
<tr>
<td><b>Domain</b></td>
<td>same</td>
</tr>
</table>
<p>Just some text to see if adding gadgets recursively works on index.html</p>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>plaintext</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../renderjs.js"></script>
</head>
<body>
<table style="border: 1px solid black; font-size: 9px">
<tr>
<td colspan="2" style="text-align:center;"><b>plaintext.html</b></td>
<tr>
<td><b>Loaded</b></td>
<td>Ajax (from addGadget())</td>
</tr>
<tr>
<td><b>Location</b></td>
<td>inside index.html</td>
</tr>
<tr>
<td><b>Service</b></td>
<td>None</td>
</tr>
<tr>
<td><b>Domain</b></td>
<td>same</td>
</tr>
</table>
<p>We try to calculate!</p>
<div>
<input style="width: 20px;" type="number" value="2" name="a" id="a" />
<input style="width: 20px;" type="number" value="2" name="b" id="b" />
<input style="width: 50px;" type="number" value="" name="c" id="c" />
<button id="multiply">Multiply</button>
<button id="subtract" disabled="disabled">Subtract</button>
</div>
<div data-gadget="gadgets/nestedplaintext.html"></div>
<script type="text/javascript">
$(this.document).find('button').on('click', function(e, target) {
var options = {
"service" : $(this).attr('id'),
"parameters": [$('#a').val(), $('#b').val()]
};
// this is not perfect, because I cannot call $("button").requestService...
$("#c").val(renderJs.requestService(options));
});
</script>
</body>
</html>
\ No newline at end of file
<html>
<head>
<script data-main="../../require-renderjs.js"
type="text/javascript"
src="../../lib/require/require.js"></script>
<head>
<body>
<div id="say-hello"
data-gadget="say-hello.html"
data-gadget-cacheable="0"
data-gadget-cache-id="say-hello"></div>
</body>
</html>
\ No newline at end of file
<html>
<head></head>
<body>
Hello from the gadget!
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>first</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../renderjs.js"></script>
</head>
<body>
<div data-gadget="gadgets/content_menu.html"
data-iframe="true"
data-param='{
"_links": {
"self": {"href": "/menu"},
"app_foo": {"href": "/menu/foo"},
"app_bar": {"href": "/menu/bar"},
"app_baz": {"href": "/menu/baz"}
},
"filter": "search"
}'></div>
<div data-gadget="gadgets/content_loader.html" data-iframe="true"></div>
<script type="text/javascript">
$(this).addGadget({"src":"gadgets/plaintext.html"});
</script>
</body>
</html>
\ No newline at end of file
<html>
<head>
<script data-main="../../require-renderjs.js"
type="text/javascript"
src="../../lib/require/require.js"></script>
<head>
<body>
<div id="init-gadget"
data-gadget="init-gadget.html"
data-gadget-cacheable="0"
data-gadget-cache-id="init-gadget"
data-gadget-property="{&quot;name&quot;: &quot;Ivan&quot;}"></div>
</body>
</html>
\ No newline at end of file
<html>
<head></head>
<body>
<p>Hello to <span id="name"></span> from the gadget which can be initialized via data-gadget-property attribute from parent gadget!</p>
<script type="text/javascript" language="javascript">
//<![CDATA[
name = RenderJs.GadgetIndex.getGadgetById("init-gadget").name;
$("#name").html(name);
//]]>
</script>
</body>
</html>
\ No newline at end of file
<div>
A (gadget)
<button onclick="RenderJs.GadgetIndex.getGadgetById('A').jsCall1()">A.jsCall1 -> B.jsCall1</button>
<button onclick="$('#A').trigger('htmlEvent1')">HTML event 1</button>
<button onclick="$('#A').trigger('htmlEvent2')">HTML event 2</button>
<button onclick="$('#main-interactor').trigger('htmlEvent3')">
A.htmlEvent3 -> InteractionGadget.htmlEvent3 -> A.htmlEvent3 AND B.htmlEvent3
</button>
<p id="hide" style="display:none;"> hidden text on myownHTMlEvent1</p>
</div>
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
gadget = RenderJs.GadgetIndex.getGadgetById("A");
gadget.jsCall1 = function (){alert("A.jscall1");};
gadget.jsCall2 = function (){alert("A.jscall2");};
gadget.htmlEvent3 = function (){alert("A.htmlEvent3");};
gadget.myOwnHtmlEvent1 = function (){
$("#hide").toggle();
alert("A.myOwnHtmlEvent1");
};
});
//]]>
</script>
\ No newline at end of file
<div>
B (gadget)
<button onclick="RenderJs.GadgetIndex.getGadgetById('B').jsCall2();">B.jsCall2 -> A.jsCall2</button>
</div>
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
gadget = RenderJs.GadgetIndex.getGadgetById("B");
gadget.jsCall1 = function (){alert("B.jscall1");};
gadget.jsCall2 = function (){alert("B.jscall2");};
gadget.htmlEvent1 = function (){alert("B.htmlEvent1");};
gadget.htmlEvent2 = function (){alert("B.htmlEvent2");};
gadget.htmlEvent3 = function (){alert("B.htmlEvent3");};
});
//]]>
</script>
\ No newline at end of file
<html>
<head>
<script data-main="../../require-renderjs.js"
type="text/javascript"
src="../../lib/require/require.js"></script>
<head>
<body>
<div id="A"
data-gadget="A.html"
data-gadget-cacheable="0"
data-gadget-cache-id="A"></div>
<div id="B"
data-gadget="B.html"
data-gadget-cacheable="0"
data-gadget-cache-id="B"></div>
<div data-gadget=""
id="main-interactor"
data-gadget-connection="[
{&quot;source&quot;: &quot;A.jsCall1&quot;, &quot;destination&quot;: &quot;B.jsCall1&quot;},
{&quot;source&quot;: &quot;A.htmlEvent1&quot;, &quot;destination&quot;: &quot;B.htmlEvent1&quot;},
{&quot;source&quot;: &quot;A.htmlEvent1&quot;, &quot;destination&quot;: &quot;A.myOwnHtmlEvent1&quot;},
{&quot;source&quot;: &quot;A.htmlEvent2&quot;, &quot;destination&quot;: &quot;B.htmlEvent2&quot;},
{&quot;source&quot;: &quot;B.jsCall2&quot;, &quot;destination&quot;: &quot;A.jsCall2&quot;},
{&quot;source&quot;: &quot;main-interactor.htmlEvent3&quot;, &quot;destination&quot;: &quot;A.htmlEvent3&quot;},
{&quot;source&quot;: &quot;main-interactor.htmlEvent3&quot;, &quot;destination&quot;: &quot;B.htmlEvent3&quot;}]">
</div>
</body>
</html>
<html>
<head></head>
<body>
<div data-role="page">
<div data-role="header">
<h1>Jquery mobile and RenderJs test</h1>
</div>
<div data-role="content">
<h2>Some documentation for this gadget.</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0-rc.1/jquery.mobile-1.3.0-rc.1.min.css" />
<link rel="stylesheet" href="jqm-gadget.css" />
<script data-main="require-renderjs_jqm.js"
type="text/javascript"
src="../../lib/require/require.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>Jquery mobile and RenderJs test</h1>
</div>
<div data-role="content">
<div id="jqm-gadget"
data-gadget="jqm-gadget.html"></div>
<div id="jqm-details-gadget"
data-gadget="jqm-details-gadget.html"></div>
<div id="jqm-doc-gadget"
data-gadget="jqm-doc-gadget.html"></div>
</div>
</div>
</body>
</html>
<html>
<head></head>
<body>
Country of origin:<span id="country"> ...</span>
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
gadget = RenderJs.GadgetIndex.getGadgetById("jqm-details-gadget");
gadget.updateCountry = function (country) {
$("#country").html(country);
};
});
//]]>
</script>
</body>
</html>
<html>
<head></head>
<body>
<ul data-role="listview" data-inset="true" data-filter="false">
<li><a href="documentation.html" class="ui-link-inherit">Link</a></li>
</ul>
</body>
</html>
#jqm-gadget,
#jqm-details-gadget{
width:45%;
float:left;
margin-left:10px;
}
#country{
font-weight: bold;
}
#jqm-doc-gadget{
width:100%;
float:left;
}
\ No newline at end of file
<html>
<head></head>
<body>
<ul data-role="listview" data-inset="true" data-filter="true" id="mylist">
<li onclick="RenderJs.GadgetIndex.getGadgetById('jqm-details-gadget').updateCountry('Germany');"><a href="#">Audi</a></li>
<li onclick="RenderJs.GadgetIndex.getGadgetById('jqm-details-gadget').updateCountry('USA');"><a href="#">Cadillac</a></li>
<li onclick="RenderJs.GadgetIndex.getGadgetById('jqm-details-gadget').updateCountry('Italy');"><a href="#">Ferrari</a></li>
<li onclick="RenderJs.GadgetIndex.getGadgetById('jqm-details-gadget').updateCountry('Japan');"><a href="#">Toyota</a></li>
<li onclick="RenderJs.GadgetIndex.getGadgetById('jqm-details-gadget').updateCountry('Russia');"><a href="#">Moskvich</a></li>
<li onclick="RenderJs.GadgetIndex.getGadgetById('jqm-details-gadget').updateCountry('Bulgaria');"><a href="#">Moskvich Aleko</a></li>
</ul>
</body>
</html>
// JavaScript file that is used to load RenderJs depenencies
require.config({
baseUrl: "../..",
paths: {
jqm: "lib/jqm/jquery.mobile-1.3.0-rc.1.min"
},
});
require([ "require-renderjs", "renderjs", "jqm" ], function(domReady) {
// when all gadgets are loaded make sure JQM renders them
RenderJs.bindReady(
function () {
$("[data-gadget]").trigger('create');
}
);
});
<html>
<head>
<script data-main="require-renderjs.js"
type="text/javascript"
src="../../lib/require/require.js"></script>
<head>
<body>
<p>Contained below gadget will get some JSON data from server and update it on page.</p>
<p>It will also load an additional library (using requirejs) that will be used by this gadget.</p>
<div id="json-gadget"
data-gadget=""
data-gadget-source = "json_file.json"
data-gadget-handler="parseJSONAndUpdateDOM"
data-gadget-cacheable="0"
data-gadget-cache-id="json-gadget">
First name: <div id="first_name"></div>
Last name: <div id="last_name"></div>
</div>
</body>
</html>
\ No newline at end of file
{"first_name": "John",
"last_name": "Doh"}
\ No newline at end of file
function parseJSONAndUpdateDOM(result) {
$("#first_name").text(result['first_name']);
$("#last_name").text(result['last_name']);
}
\ No newline at end of file
// JavaScript file that is used to load RenderJs depenencies
require(["../../lib/jquery/jquery.js",
"../../renderjs.js",
"json_gadget.js"
],
function (domReady) {
// Place code to be executed when libraries are loaded
// impliticly call RenderJs bootstrap
RenderJs.init();
});
<html>
<head>
<script data-main="../../require-renderjs.js"
type="text/javascript"
src="../../lib/require/require.js"></script>
<head>
<body>
<div id="recursive"
data-gadget="recursive.html"
data-gadget-cacheable="0"
data-gadget-cache-id="recursive"></div>
</body>
</html>
\ No newline at end of file
<html>
<head></head>
<body>
<p>
Hello from the recursive contained gadget!
</p>
</body>
</html>
<html>
<head></head>
<body>
<p>
Hello from the recursive gadget!
Below a new gadget will be loaded
</p>
<div data-gadget="recursive-contained.html"
data-gadget-cacheable="0"
data-gadget-cache-id="recursive-contained"></div>
</body>
</html>
\ No newline at end of file
<html>
<head>
<script data-main="../../require-renderjs.js"
type="text/javascript"
src="../../lib/require/require.js"></script>
<head>
<body>
<div id="requirejs-gadget"
data-gadget="requirejs-gadget.html"
data-gadget-cacheable="0"
data-gadget-cache-id="requirejs-gadget"></div>
</body>
</html>
\ No newline at end of file
// This module contains gagdets JavaScript implementation code
function setLoaded() {
$("#loading").text('Loaded now using requirejs.');
}
\ No newline at end of file
// This file defines all required javascript files for this gadget
require(["require-gadget-implementation.js"],
function (domReady) {
// required by this gadget code is loaded so we can use it
setLoaded();
});
<html>
<head>
<script type="text/javascript"
src="require-gadget.js"></script>
</head>
<body>
<p>This gadget uses requirejs to load its dependency.</p>
<div id="loading">Loading ....</div>
</body>
</html>
\ No newline at end of file
.list-item {
text-decoration: none;
display: block;
width: 2em;
}
\ No newline at end of file
<html>
<head>
<link type="text/css" href="gadget-color-picker.css" rel="stylesheet">
</head>
<body>
<h2> Color picker</h2>
<div class="body">
<ul style="list-style: none;">
<li><a href="#/color/0/0/0/" class="list-item" style="background-color:rgb(0,0,0);">&nbsp;</a></li>
<li><a href="#/color/0/0/150/" class="list-item" style="background-color:rgb(0,0,150);">&nbsp;</a></li>
<li><a href="#/color/0/150/0/" class="list-item" style="background-color:rgb(0,150,0);">&nbsp;</a></li>
<li><a href="#/color/0/150/150/" class="list-item" style="background-color:rgb(0,150,150);">&nbsp;</a></li>
<li><a href="#/color/150/0/0/" class="list-item" style="background-color:rgb(150,0,0);">&nbsp;</a></li>
<li><a href="#/color/150/0/150/" class="list-item" style="background-color:rgb(150,0,150);">&nbsp;</a></li>
<li><a href="#/color/150/150/0/" class="list-item" style="background-color:rgb(150,150,0);">&nbsp;</a></li>
<li><a href="#/color/150/150/150/" class="list-item" style="background-color:rgb(150,150,150);">&nbsp;</a></li>
<li style="text-align: center;"><a href="#/color/X/X/X" style="text-decoration: none; display: block; width: 2em;">XXX</a></li>
</ul>
<div class="select-color" style="display: block;"></div>
</div>
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
gadget = RenderJs.getSelfGadget();
gadget.redirect = function () {
// Default route. Redirect to color subapp
$.url.redirect('/color/');
};
gadget.selectColorMessage = function () {
$('.select-color').text("Please select a color");
};
gadget.updateColor = function (red, green, blue) {
$('.select-color').html(
"<div style='background-color:rgb(" + red + "," + green + "," + blue + ");'>&nbsp;<\/div>" +
"<p>Color (" + red + "," + green + "," + blue + ") selected at " + new Date() + "<\/p>");
};
gadget.initRoutes = function () {
// XXX: improve this part so we can declare in RouteGadget
RenderJs.RouteGadget.go($.url.getPath(),
function () {
$('.select-color').html("Unknown color (" + $.url.getPath() + ")");},
2);
};
});
//]]>
</script>
</body>
</html>
<html>
<head></head>
<body>
<h1> This is footer loaded asynchronously at startup</h1>
<div class="route-select">
<ul>
<li><a href="#/footer_gadget_1/">Footer Gadget 1</a></li>
<li><a href="#/footer_gadget_2/">Footer Gadget 2</a></li>
<li><a href="#/footer_gadget_3/">Footer Gadget 3</a></li>
<li><a href="#/footer_gadget_4/">Footer Gadget 4</a></li>
<li><a href="#/footer_gadget_5/">Footer Gadget 5</a></li>
</ul>
</div>
<div id="footer-container">
<div data-gadget-source="" data-gadget-handler="" data-gadget="gadget-three.html" id="footer_gadget_1"></div>
<div data-gadget-source="" data-gadget-handler="" data-gadget="gadget-three.html" id="footer_gadget_2"></div>
<div data-gadget-source="" data-gadget-handler="" data-gadget="gadget-three.html" id="footer_gadget_3"></div>
<div data-gadget-source="" data-gadget-handler="" data-gadget="gadget-three.html" id="footer_gadget_4"></div>
<div data-gadget-source="" data-gadget-handler="" data-gadget="gadget-three.html" id="footer_gadget_5"></div>
<div data-gadget=""
id="footer-router"
data-gadget-route="[
{&quot;source&quot;: &quot;/footer_gadget_1/&quot;, &quot;destination&quot;: &quot;footer_gadget_1.render&quot;},
{&quot;source&quot;: &quot;/footer_gadget_2/&quot;, &quot;destination&quot;: &quot;footer_gadget_2.render&quot;},
{&quot;source&quot;: &quot;/footer_gadget_3/&quot;, &quot;destination&quot;: &quot;footer_gadget_3.render&quot;},
{&quot;source&quot;: &quot;/footer_gadget_4/&quot;, &quot;destination&quot;: &quot;footer_gadget_4.render&quot;},
{&quot;source&quot;: &quot;/footer_gadget_5/&quot;, &quot;destination&quot;: &quot;footer_gadget_5.render&quot;}]">
</div>
</div>
</body>
</html>
<html>
<head></head>
<body>
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
gadget = RenderJs.GadgetIndex.getGadgetById("gadget-one");
gadget.render = function (){
$("#gadget-one").html("<h2>Gadget 1</h2><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>");
$("#gadget-two").empty(); // XXX: this will become redundant if we use Tabbular gadget
};
});
//]]>
</script>
</body>
</html>
<html>
<head></head>
<body>
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
gadget = RenderJs.getSelfGadget();
gadget.showMessage = function (msg){
$("#portal-status-message").html(msg);
window.setTimeout(function () {
$("#portal-status-message").empty();
}, 2000);
};
});
//]]>
</script>
</body>
</html>
<html>
<head></head>
<body>
<div class="gadget-id-viewer" style="display:none;">
</div>
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
gadget = RenderJs.getSelfGadget();
$(gadget.getDom()).find(".gadget-id-viewer").html("This is " + gadget.getId())
gadget.render = function (){
gadget = RenderJs.getSelfGadget();
$(gadget.getDom().find(".gadget-id-viewer")).toggle();
};
});
//]]>
</script>
</body>
</html>
<html>
<head></head>
<body>
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
gadget = RenderJs.GadgetIndex.getGadgetById("gadget-two");
gadget.render = function (){
$("#gadget-one").empty(); // XXX: this will become redundant if we use Tabbular gadget
$("#gadget-two").html("<h2>Gadget 2</h2><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>");
};
});
//]]>
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script data-main="require-renderjs_route.js"
type="text/javascript"
src="../../lib/require/require.js"></script>
</head>
<body>
<div id="portal-status-message"
data-gadget="gadget-portal-status-message.html"></div>
<div data-gadget=""
id="main-router"
data-gadget-route="[
{&quot;source&quot;: &quot;&quot;, &quot;destination&quot;: &quot;gadget-color-picker.redirect&quot;},
{&quot;source&quot;: &quot;/color<path:params>&quot;, &quot;destination&quot;: &quot;gadget-color-picker.initRoutes&quot;},
{&quot;source&quot;: &quot;/color/&quot;,
&quot;destination&quot;: &quot;gadget-color-picker.selectColorMessage&quot;,
&quot;priority&quot;:2},
{&quot;source&quot;: &quot;/color/<int:red>/<int:green>/<int:blue>/&quot;,
&quot;destination&quot;: &quot;gadget-color-picker.updateColor&quot;,
&quot;priority&quot;:2},
{&quot;source&quot;: &quot;/gadget-one/&quot;, &quot;destination&quot;: &quot;main-router.gadget_one&quot;},
{&quot;source&quot;: &quot;/gadget-two/&quot;, &quot;destination&quot;: &quot;main-router.gadget_two&quot;}]">
</div>
<a href="#unknown">Wrong route</a>
<div id="gadget-color-picker"
data-gadget="gadget-color-picker.html"></div>
<a href="#/gadget-one/">Gadget 1</a>&nbsp;
<a href="#/gadget-two/">Gadget 2</a>
<div id="gadget-one"
data-gadget="gadget-one.html"></div>
<div id="gadget-two"
data-gadget="gadget-two.html"></div>
<div id="gadget-footer"
data-gadget="gadget-footer.html"></div>
<div data-gadget=""
id="main-interactor"
data-gadget-connection="[
{&quot;source&quot;: &quot;main-router.gadget_one&quot;, &quot;destination&quot;: &quot;gadget-one.render&quot;},
{&quot;source&quot;: &quot;main-router.gadget_two&quot;, &quot;destination&quot;: &quot;gadget-two.render&quot;}]">
</div>
<noscript>
Please enable Javascript
</noscript>
</body>
</html>
// JavaScript file that is used to load RenderJs depenencies
require.config({
baseUrl: "../..",
paths: {
route: "lib/route/route",
url: "lib/route/url",
jquery: "lib/jquery/jquery",
renderjs: "renderjs",
},
shim: {
url: [ "renderjs" ]
}
});
require([ "renderjs", "require-renderjs", "jquery", "route", "url" ], function(domReady) {
RenderJs.bindReady(function (){
// XXX: try to encapsulate this in router gadget
gadget = RenderJs.GadgetIndex.getGadgetById("main-router");
gadget.gadget_one = function (){
// we use interactionGadget which will call proper gadgets' function
};
gadget.gadget_two = function (){
// we use interactionGadget which will call proper gadgets' function
};
// we have to re-bind (force) interaction gadget as main-route API implemantation changed
RenderJs.InteractionGadget.init(force=1);
$.url.onhashchange(function () {
RenderJs.RouteGadget.go($.url.getPath(),
function () {
// Method to display error to the user
gadget = RenderJs.GadgetIndex.getGadgetById("portal-status-message");
gadget.showMessage(
"<p>Oups, seems the route '<b>" + $.url.getPath() + "<\/b>' doesn't exist!<\/p>" +
"<a href='" + $.url.generateUrl("") + "'>Go back to home<\/a>");
// All routes have been deleted by fail.
// So recreate the default routes using RouteGadget
$("div[data-gadget-route]").each(function (index, element) {
RenderJs.RouteGadget.route($(element));
});
});
});
});
});
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
/*! jQuery JSON plugin 2.4.0 | code.google.com/p/jquery-json */
(function($){'use strict';var escape=/["\\\x00-\x1f\x7f-\x9f]/g,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},hasOwn=Object.prototype.hasOwnProperty;$.toJSON=typeof JSON==='object'&&JSON.stringify?JSON.stringify:function(o){if(o===null){return'null';}
var pairs,k,name,val,type=$.type(o);if(type==='undefined'){return undefined;}
if(type==='number'||type==='boolean'){return String(o);}
if(type==='string'){return $.quoteString(o);}
if(typeof o.toJSON==='function'){return $.toJSON(o.toJSON());}
if(type==='date'){var month=o.getUTCMonth()+1,day=o.getUTCDate(),year=o.getUTCFullYear(),hours=o.getUTCHours(),minutes=o.getUTCMinutes(),seconds=o.getUTCSeconds(),milli=o.getUTCMilliseconds();if(month<10){month='0'+month;}
if(day<10){day='0'+day;}
if(hours<10){hours='0'+hours;}
if(minutes<10){minutes='0'+minutes;}
if(seconds<10){seconds='0'+seconds;}
if(milli<100){milli='0'+milli;}
if(milli<10){milli='0'+milli;}
return'"'+year+'-'+month+'-'+day+'T'+
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
pairs=[];if($.isArray(o)){for(k=0;k<o.length;k++){pairs.push($.toJSON(o[k])||'null');}
return'['+pairs.join(',')+']';}
if(typeof o==='object'){for(k in o){if(hasOwn.call(o,k)){type=typeof k;if(type==='number'){name='"'+k+'"';}else if(type==='string'){name=$.quoteString(k);}else{continue;}
type=typeof o[k];if(type!=='function'&&type!=='undefined'){val=$.toJSON(o[k]);pairs.push(name+':'+val);}}}
return'{'+pairs.join(',')+'}';}};$.evalJSON=typeof JSON==='object'&&JSON.parse?JSON.parse:function(str){return eval('('+str+')');};$.secureEvalJSON=typeof JSON==='object'&&JSON.parse?JSON.parse:function(str){var filtered=str.replace(/\\["\\\/bfnrtu]/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered)){return eval('('+str+')');}
throw new SyntaxError('Error parsing JSON, source is not valid.');};$.quoteString=function(str){if(str.match(escape)){return'"'+str.replace(escape,function(a){var c=meta[a];if(typeof c==='string'){return c;}
c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
return'"'+str+'"';};}(jQuery));
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// 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"
},
shim: {
"jquery.json": [ "jquery" ],
jio: ["md5"],
davstorage: ["jio"],
renderjs: [ "jquery", "jquery.json", "jio", "md5", "davstorage" ]
}
});
require([ "renderjs" ], function(domReady) {
RenderJs.init();
});
\ No newline at end of file
{
"gadget_list":[ {"title": "HTML WYSIWYG",
"description": "A simple HTML editor",
"url": "http://example.com/html-editor.html",
"service_list": ["edit_html", "view_html"]},
{"title": "SVG WYSIWYG",
"description": "A simple SVG editor",
"url": "http://example.com/svg-editor.html",
"service_list": ["edit_svg", "view_svg"]}
]
}
\ No newline at end of file
This diff is collapsed.
<div>A (gadget)</div>
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
gadget = RenderJs.GadgetIndex.getGadgetById("A");
gadget.inc = function (){counter = counter +1;};
gadget.inc2 = function (){counter = counter +2;};
});
//]]>
</script>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
{"first_name": "John",
"last_name": "Doh"}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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