Commit 790d533a authored by Ivan Tyagov's avatar Ivan Tyagov

Allow to initialize a gadget.

Add an example for this.
Gadget's ID is a mandatory argument so fix examples accordingly.
parent 0ced97f2
......@@ -6,8 +6,9 @@
<script type="text/javascript" src="../../renderjs.js"></script>
<head>
<body>
<div data-gadget="say-hello.html"
<div id="say-hello"
data-gadget="say-hello.html"
data-gadget-cacheable="0"
data-gadget-cache-id="say_hello"></div>
data-gadget-cache-id="say-hello"></div>
</body>
</html>
\ No newline at end of file
<html>
<head>
<script type="text/javascript" src="../../../../lib/require/require.js"> </script>
<script type="text/javascript" src="../../../../lib/jquery/jquery.js"> </script>
<script type="text/javascript" src="../../renderjs.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
<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>
\ No newline at end of file
......@@ -5,7 +5,8 @@
<script type="text/javascript" src="../../renderjs.js"></script>
<head>
<body>
<div data-gadget="recursive.html"
<div id="recursive"
data-gadget="recursive.html"
data-gadget-cacheable="0"
data-gadget-cache-id="recursive"></div>
</body>
......
......@@ -59,7 +59,14 @@ var RenderJs = (function () {
gadget_js = new RenderJs.Gadget(gadget_id, gadget);
RenderJs.GadgetIndex.registerGadget(gadget_js);
// XXX: update Gadget's instance with contents of "data-gadget-property"
// update Gadget's instance with contents of "data-gadget-property"
gadget_property = gadget.attr("data-gadget-property");
if (gadget_property !== undefined) {
gadget_property = $.parseJSON(gadget_property);
$.each(gadget_property, function (key, value) {
gadget_js[key] = value;
});
}
if (url !== undefined && url !== "") {
cacheable = gadget.attr("data-gadget-cacheable");
......
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