Commit c7b04104 authored by Ivan Tyagov's avatar Ivan Tyagov

Add a generic addGadget API to RenderJs.

Allow to control RenderJs's implicit gadget rendering process.
Make sure OfficeJs uses always recent RenderJs.
parent 28da4618
......@@ -9,7 +9,7 @@
<title>OfficeJS</title>
<script type="text/javascript" src="lib/jquery/jquery.js"></script>
<script type="text/javascript" src="lib/jstorage/jstorage.js"></script>
<script type="text/javascript" src="lib/renderjs/renderjs.js"></script>
<script type="text/javascript" src="src/renderjs/renderjs.js"></script>
<script type="text/javascript" src="src/localorcookiestorage.js"></script>
<script type="text/javascript" src="lib/jio/jio.js"></script>
......
......@@ -1056,7 +1056,7 @@
scope[app.varname]=OfficeJS.lib.cloneAndProtectObjectRoot(app.api);
}
// open
TabbularGadget.addNewTabGadget(app.componentpath,app.gadgetid);
RenderJs.addGadget(app.gadgetid, app.componentpath);
OfficeJS.tmp[app.gadgetid] = app;
// load
if (app.onload) {
......@@ -1083,8 +1083,12 @@
//////////////////////////////////////////////////////////////////////
odf(scope,'OfficeJS',OfficeJS.command);
OfficeJS.lib.openApplication(OfficeJS.system.applications['top_nav_bar']);
OfficeJS.lib.openApplication(OfficeJS.system.applications['left_nav_bar']);
OfficeJS.lib.openApplication(OfficeJS.system.applications['login']);
}(window));
// configure RenderJs to skip its built in implicit gadget rendering
// as our application will do that explicitly
var RENDERJS_ENABLE_IMPLICIT_GADGET_RENDERING=false;
\ No newline at end of file
This diff is collapsed.
// by default RenderJs will render all gadgets when page is loaded
// still it's possible to override this and use explicit gadget rendering
var RENDERJS_ENABLE_IMPLICIT_GADGET_RENDERING = true;
// Add required by RenderJs jstorage library only if used HTML application uses requirejs
if (typeof require !== 'undefined') {
require(["../../../../lib/jstorage/jstorage.js"], function(util) {
......@@ -162,6 +166,33 @@ var RenderJs = (function () {
yourCustomData: {"data_handler": data_handler},
success: RenderJs.updateGadgetWithDataHandler});}
},
addGadget: function(dom_id, gadget, gadget_data_handler, gadget_data_source) {
/*
* add new gadget and render it
*/
var html_string;
tab_container=$('#'+dom_id);
tab_container.empty();
html_string =['<div class="gadget" ',
'data-gadget="' + gadget + '"',
'data-gadget:data-handler="' + gadget_data_handler + '" ',
'data-gadget:data-source="' + gadget_data_source +'"></div>'].join('\n');
tab_container.append(html_string);
tab_gadget = tab_container.find(".gadget");
// render new gadget
RenderJs.setReady(false);
RenderJs.loadGadgetFromUrl(tab_gadget);
// clear previous events
RenderJs.GadgetIndex.getRootGadget().getDom().bind("ready", function (){
if (!is_ready){
RenderJs.updateGadgetData(tab_gadget);
is_ready = true;
}
});
return tab_gadget;
},
Cache : (function() {
/*
......@@ -303,29 +334,9 @@ var RenderJs = (function () {
/*
* add new gadget and render it
*/
var html_string;
tab_container=$('#'+dom_id);
tab_container.empty();
html_string =['<div class="gadget" ',
'data-gadget="' + gadget + '"',
'data-gadget:data-handler="' + gadget_data_handler + '" ',
'data-gadget:data-source="' + gadget_data_source +'"></div>'].join('\n');
tab_container.append(html_string);
tab_gadget = tab_container.find(".gadget");
tab_gadget = RenderJs.addGadget(dom_id, gadget, gadget_data_handler, gadget_data_source)
// XXX: we should unregister all gadgets (if any we replace now in DOM)
// render new gadget
RenderJs.setReady(false);
RenderJs.loadGadgetFromUrl(tab_gadget);
// clear previous events
RenderJs.GadgetIndex.getRootGadget().getDom().bind("ready", function (){
if (!is_ready){
RenderJs.updateGadgetData(tab_gadget);
is_ready = true;
}
});
}
}}()),
......@@ -455,5 +466,7 @@ var RenderJs = (function () {
// impliticly call RenderJs bootstrap
$(document).ready(function() {
RenderJs.bootstrap($('body'));
if (RENDERJS_ENABLE_IMPLICIT_GADGET_RENDERING){
RenderJs.bootstrap($('body'));
}
});
\ 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