Commit bc44610f authored by Tristan Cavelier's avatar Tristan Cavelier

Update to latest renderjs

parent 648eaee9
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
</item> </item>
<item> <item>
<key> <string>_EtagSupport__etag</string> </key> <key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts46068994.72</string> </value> <value> <string>ts49355317.03</string> </value>
</item> </item>
<item> <item>
<key> <string>__name__</string> </key> <key> <string>__name__</string> </key>
...@@ -26,454 +26,596 @@ ...@@ -26,454 +26,596 @@
<key> <string>data</string> </key> <key> <string>data</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string encoding="cdata"><![CDATA[
/*global console, require, $, localStorage, document */\n
"use strict";\n
\n
/*\n
* RenderJs - Generic Gadget library renderer.\n
* http://www.renderjs.org/documentation\n
*/\n
\n
// by default RenderJs will render all gadgets when page is loaded\n
// still it\'s possible to override this and use explicit gadget rendering\n
var RENDERJS_ENABLE_IMPLICIT_GADGET_RENDERING = true;\n
\n
// by default RenderJs will examin and bind all interaction gadgets\n
// available\n
var RENDERJS_ENABLE_IMPLICIT_INTERACTION_BIND = true;\n
\n
if (typeof require !== \'undefined\') {\n
// example of how we can use requirejs to load external libraries\n
//require(["../../../../lib/jstorage/jstorage.js"], function (util) {\n
//});\n
}\n
\n
// fallback for IE\n // fallback for IE\n
if (typeof console === "undefined" || typeof console.log === "undefined") {\n if (typeof console === "undefined" || typeof console.log === "undefined") {\n
console = {};\n console = {};\n
console.log = function() {};\n console.log = function () {};\n
}\n }\n
\n \n
\n
/*\n
* Generic Gadget library renderer\n
*/\n
\n
var RenderJs = (function () {\n var RenderJs = (function () {\n
// a variable indicating if current gadget loading is over or not\n
var is_ready = false;\n
\n
return {\n
bootstrap: function (root) {\n
/* initial load application gadget */\n
var gadget_id;\n
gadget_id = root.attr("id");\n
if (gadget_id!==undefined) {\n
// bootstart root gadget only if it is indeed a gadget\n
RenderJs.loadGadgetFromUrl(root);\n
}\n
RenderJs.load(root);\n
},\n
\n
load: function (root) {\n
/* Load gadget layout by traversing DOM */\n
var gadget_list, gadget, gadget_id, gadget_js;\n
gadget_list = root.find("[data-gadget]");\n
\n
// register all gadget in advance so checkAndTriggerReady\n
// can have accurate information for list of all gadgets\n
gadget_list.each(function () {\n
gadget = $(this);\n
gadget_id = gadget.attr("id");\n
gadget_js = new RenderJs.Gadget(gadget_id, gadget);\n
RenderJs.GadgetIndex.registerGadget(gadget_js);\n
});\n
\n
// Load chilren\n
gadget_list.each(function () {\n
RenderJs.loadGadgetFromUrl($(this));\n
});\n
},\n
\n
updateAndRecurse: function (gadget, data) {\n
/* Update current gadget and recurse down */\n
gadget.append(data);\n
// a gadget may contain sub gadgets\n
this.load(gadget);\n
},\n
\n
loadGadgetFromUrl: function (gadget) {\n
/* Load gadget\'s SPECs from URL */\n
var url, gadget_id, gadget_property, cacheable, cache_id,\n
app_cache, data, gadget_js;\n
url = gadget.attr("data-gadget");\n
gadget_id = gadget.attr("id");\n
gadget_js = RenderJs.GadgetIndex.getGadgetById(gadget_id);\n
if (gadget_js===undefined) {\n
// register gadget in javascript namespace if not already registered\n
gadget_js = new RenderJs.Gadget(gadget_id, gadget);\n
RenderJs.GadgetIndex.registerGadget(gadget_js);\n
}\n
\n \n
// a variable indicating if current gadget loading is over or not\n // update Gadget\'s instance with contents of "data-gadget-property"\n
var is_ready = false;\n gadget_property = gadget.attr("data-gadget-property");\n
\n if (gadget_property !== undefined) {\n
return {\n gadget_property = $.parseJSON(gadget_property);\n
\n $.each(gadget_property, function (key, value) {\n
bootstrap: function (root){\n gadget_js[key] = value;\n
/* initial load application gadget */\n });\n
RenderJs.loadGadgetFromUrl(root);\n }\n
RenderJs.load(root);\n \n
},\n if (url !== undefined && url !== "") {\n
\n cacheable = gadget.attr("data-gadget-cacheable");\n
load: function (root) {\n cache_id = gadget.attr("data-gadget-cache-id");\n
/* Load gadget layout by traversing DOM */\n if (cacheable !== undefined && cache_id !== undefined) {\n
var gadget_list;\n cacheable = Boolean(parseInt(cacheable, 10));\n
gadget_list = root.find("[data-gadget]");\n }\n
// Load chilren\n //cacheable = false ; // to develop faster\n
gadget_list.each(function() {\n if (cacheable) {\n
RenderJs.loadGadgetFromUrl($(this));\n // get from cache if possible, use last part from URL as\n
});\n // cache_key\n
},\n app_cache = RenderJs.Cache.get(cache_id, undefined);\n
\n if (app_cache === undefined || app_cache === null) {\n
updateAndRecurse: function(gadget, data){\n // not in cache so we pull from network and cache\n
/* Update current gadget and recurse down */\n $.ajax({\n
gadget.append(data);\n url: url,\n
// a gadget may contain sub gadgets\n yourCustomData: {\n
this.load(gadget);\n "gadget_id": gadget_id,\n
},\n "cache_id": cache_id\n
\n },\n
loadGadgetFromUrl: function(gadget) {\n success: function (data) {\n
/* Load gadget\'s SPECs from URL */\n cache_id = this.yourCustomData.cache_id;\n
var url, gadget_id, gadget_property, cacheable, cache_id, app_cache, data, gadget_js;\n gadget_id = this.yourCustomData.gadget_id;\n
url = gadget.attr("data-gadget");\n RenderJs.Cache.set(cache_id, data);\n
gadget_id = gadget.attr("id");\n RenderJs.GadgetIndex.getGadgetById(gadget_id).\n
\n setReady();\n
// register gadget in javascript namespace\n RenderJs.updateAndRecurse(gadget, data);\n
gadget_js = new RenderJs.Gadget(gadget_id, gadget);\n RenderJs.checkAndTriggerReady();\n
RenderJs.GadgetIndex.registerGadget(gadget_js);\n }\n
\n });\n
if (url!==undefined && url!==""){\n } else {\n
gadget_property = gadget.attr("data-gadget:property");\n // get from cache\n
cacheable = false;\n data = app_cache;\n
if (gadget_property!==undefined) {\n gadget_js.setReady();\n
gadget_property = $.parseJSON(gadget_property);\n this.updateAndRecurse(gadget, data);\n
cacheable = Boolean(gadget_property.cacheable);\n this.checkAndTriggerReady();\n
}\n
//cacheable = false ; // to develop faster\n
if (cacheable) {\n
// get from cache if possible, use last part from URL as cache_key\n
cache_id = gadget_property.cache_id;\n
app_cache = RenderJs.Cache.get(cache_id, undefined);\n
if(app_cache===undefined || app_cache===null){\n
// not in cache so we pull from network and cache\n
$.ajax({url:url,\n
yourCustomData: {"gadget_id": gadget_id, "cache_id": cache_id},\n
success: function (data) {\n
cache_id = this.yourCustomData.cache_id;\n
gadget_id = this.yourCustomData.gadget_id;\n
RenderJs.Cache.set(cache_id, data);\n
RenderJs.GadgetIndex.getGadgetById(gadget_id).setReady();\n
RenderJs.updateAndRecurse(gadget, data);\n
RenderJs.checkAndTriggerReady();\n
}});\n
}\n
else {\n
// get from cache\n
data = app_cache;\n
gadget_js.setReady();\n
this.updateAndRecurse(gadget, data);\n
this.checkAndTriggerReady();\n
}\n
}\n
else {\n
// not to be cached\n
$.ajax({url:url,\n
yourCustomData: {"gadget_id": gadget_id},\n
success: function (data) {\n
gadget_id = this.yourCustomData.gadget_id;\n
RenderJs.GadgetIndex.getGadgetById(gadget_id).setReady();\n
RenderJs.updateAndRecurse(gadget, data);\n
RenderJs.checkAndTriggerReady();\n
}});\n
}\n
}\n
else {\n
// gadget is an inline one so no need to load it from network\n
gadget_js.setReady();\n
RenderJs.checkAndTriggerReady();\n
}\n }\n
},\n } else {\n
// not to be cached\n
$.ajax({\n
url: url,\n
yourCustomData: {"gadget_id": gadget_id},\n
success: function (data) {\n
gadget_id = this.yourCustomData.gadget_id;\n
RenderJs.GadgetIndex.getGadgetById(gadget_id).\n
setReady();\n
RenderJs.updateAndRecurse(gadget, data);\n
RenderJs.checkAndTriggerReady();\n
}\n
});\n
}\n
} else {\n
// gadget is an inline one so no need to load it from network\n
gadget_js.setReady();\n
RenderJs.checkAndTriggerReady();\n
}\n
},\n
\n \n
isReady: function (value) {\n isReady: function (value) {\n
/*\n /*\n
* Get rendering status\n * Get rendering status\n
*/\n */\n
return is_ready;\n return is_ready;\n
},\n },\n
\n \n
setReady: function (value) {\n setReady: function (value) {\n
/*\n /*\n
* Update rendering status\n * Update rendering status\n
*/\n */\n
is_ready = value; \n is_ready = value;\n
},\n },\n
\n \n
checkAndTriggerReady: function() {\n bindReady: function (ready_function) {\n
/*\n
* Bind a function on ready gadget loading.\n
*/\n
$("body").one("ready", ready_function);\n
},\n
\n
checkAndTriggerReady: function () {\n
/*\n /*\n
* Trigger "ready" event only if all gadgets were marked as "ready"\n * Trigger "ready" event only if all gadgets were marked as "ready"\n
*/\n */\n
var is_gadget_list_loaded;\n var is_gadget_list_loaded;\n
is_gadget_list_loaded = RenderJs.GadgetIndex.isGadgetListLoaded();\n is_gadget_list_loaded = RenderJs.GadgetIndex.isGadgetListLoaded();\n
if (is_gadget_list_loaded){\n if (is_gadget_list_loaded) {\n
if (!RenderJs.isReady()) {\n if (!RenderJs.isReady()) {\n
RenderJs.GadgetIndex.getRootGadget().getDom().trigger("ready");\n // backwards compatability with already written code\n
RenderJs.setReady(true);\n RenderJs.GadgetIndex.getRootGadget().getDom().\n
}\n trigger("ready");\n
//is_ready = true;\n // trigger ready on root body element\n
$("body").trigger("ready");\n
RenderJs.setReady(true);\n
}\n
}\n }\n
return is_gadget_list_loaded;\n return is_gadget_list_loaded;\n
},\n },\n
\n \n
update: function (root) {\n update: function (root) {\n
/* update gadget with data from remote source */\n /* update gadget with data from remote source */\n
root.find("[gadget]").each(function(i,v){RenderJs.updateGadgetData($(this));});\n root.find("[gadget]").each(function (i, v) {\n
},\n RenderJs.updateGadgetData($(this));\n
\n });\n
updateGadgetWithDataHandler: function (result) {\n },\n
var data_handler;\n \n
data_handler = this.yourCustomData.data_handler;\n updateGadgetWithDataHandler: function (result) {\n
if (data_handler!==undefined){\n var data_handler;\n
eval(data_handler+ "(result)");\n data_handler = this.yourCustomData.data_handler;\n
}\n if (data_handler !== undefined) {\n
},\n eval(data_handler + "(result)");\n
\n }\n
updateGadgetData: function(gadget) {\n },\n
/* Do real gagdet update here */\n \n
var data_source, data_handler;\n updateGadgetData: function (gadget) {\n
data_source = gadget.attr("data-gadget:data-source");\n /* Do real gagdet update here */\n
data_handler = gadget.attr("data-gadget:data-handler");\n var data_source, data_handler;\n
// acquire data and pass it to method handler\n data_source = gadget.attr("data-gadget-source");\n
if (data_source!==undefined){\n data_handler = gadget.attr("data-gadget-handler");\n
$.ajax({url:data_source,\n // acquire data and pass it to method handler\n
dataType: "json",\n if (data_source !== undefined && data_source !== "") {\n
yourCustomData: {"data_handler": data_handler},\n $.ajax({\n
success: RenderJs.updateGadgetWithDataHandler});}\n url: data_source,\n
},\n dataType: "json",\n
\n yourCustomData: {"data_handler": data_handler},\n
Cache : (function() {\n success: RenderJs.updateGadgetWithDataHandler\n
/*\n });\n
* Generic cache implementation that can fall back to local namespace storage\n }\n
* if no "modern" storage like localStorage is available\n },\n
*/\n
\n
return {\n
\n
ROOT_CACHE_ID: \'APP_CACHE\',\n
\n
getCacheId: function (cache_id) {\n
/* We should have a way to \'purge\' localStorage by setting a ROOT_CACHE_ID in all browser\n
* instances\n
*/\n
return this.ROOT_CACHE_ID + cache_id;\n
},\n
\n
hasLocalStorage: function() {\n
/*\n
* Feature test if localStorage is supported\n
*/\n
var mod;\n
mod = \'localstorage_test_12345678\';\n
try {\n
localStorage.setItem(mod, mod);\n
localStorage.removeItem(mod);\n
return true;\n
}\n
catch (e) {\n
return false;\n
}\n
},\n
\n \n
get: function (cache_id, default_value) {\n addGadget: function (dom_id, gadget, gadget_data_handler,\n
/* Get cache key value */\n gadget_data_source) {\n
cache_id = this.getCacheId(cache_id);\n /*\n
if (this.hasLocalStorage()) {\n * add new gadget and render it\n
return this.LocalStorageCachePlugin.get(cache_id, default_value);\n */\n
}\n var html_string, tab_container, tab_gadget;\n
//fallback to javscript namespace cache\n tab_container = $(\'#\' + dom_id);\n
return this.NameSpaceStorageCachePlugin.get(cache_id, default_value);\n tab_container.empty();\n
},\n html_string = [\n
\'<div class="gadget" \',\n
\'data-gadget="\' + gadget + \'"\',\n
\'data-gadget-handler="\' + gadget_data_handler + \'" \',\n
\'data-gadget-source="\' + gadget_data_source + \'"></div>\'\n
].join(\'\\n\');\n
\n
tab_container.append(html_string);\n
tab_gadget = tab_container.find(".gadget");\n
// render new gadget\n
RenderJs.setReady(false);\n
RenderJs.loadGadgetFromUrl(tab_gadget);\n
// clear previous events\n
RenderJs.GadgetIndex.getRootGadget().getDom().bind(\n
"ready",\n
function () {\n
if (!is_ready) {\n
RenderJs.updateGadgetData(tab_gadget);\n
is_ready = true;\n
}\n
}\n
);\n
return tab_gadget;\n
},\n
\n \n
set: function (cache_id, data) {\n Cache: (function () {\n
/* Set cache key value */\n /*\n
cache_id = this.getCacheId(cache_id);\n * Generic cache implementation that can fall back to local\n
if (this.hasLocalStorage()){\n * namespace storage if no "modern" storage like localStorage\n
this.LocalStorageCachePlugin.set(cache_id, data);}\n * is available\n
else{\n */\n
this.NameSpaceStorageCachePlugin.set(cache_id, data);}\n return {\n
},\n ROOT_CACHE_ID: \'APP_CACHE\',\n
\n
getCacheId: function (cache_id) {\n
/*\n
* We should have a way to \'purge\' localStorage by setting a\n
* ROOT_CACHE_ID in all browser instances\n
*/\n
return this.ROOT_CACHE_ID + cache_id;\n
},\n
\n \n
LocalStorageCachePlugin : (function() {\n hasLocalStorage: function () {\n
/*\n
* This plugin saves using HTML5 localStorage.\n
*/\n
return {\n
get: function (cache_id, default_value) {\n
/* Get cache key value */\n
return $.jStorage.get(cache_id, default_value);\n
},\n
\n
set: function (cache_id, data) {\n
/* Set cache key value */\n
$.jStorage.set(cache_id, data);\n
}\n
}}()),\n
\n
NameSpaceStorageCachePlugin: (function() {\n
/*\n
* This plugin saves within current page namespace.\n
*/\n
\n
var namespace = {};\n
\n
return {\n
get: function (cache_id, default_value) {\n
/* Get cache key value */\n
return namespace[cache_id];\n
},\n
\n
set: function (cache_id, data) {\n
/* Set cache key value */\n
namespace[cache_id] = data;\n
}\n
\n
}}())\n
\n
}}()),\n
\n
Gadget: ( function (id, dom) {\n
/*\n
* Javascript Gadget representation\n
*/\n
this.id = id;\n
this.dom = dom;\n
this.is_ready = false;\n
\n
this.getId = function() {\n
return this.id;\n
};\n
\n
this.getDom = function() {\n
return this.dom;\n
};\n
\n
this.isReady = function() {\n
/*\n /*\n
* Return True if remote gadget is loaded into DOM.\n * Feature test if localStorage is supported\n
*/\n */\n
return this.is_ready;\n var mod;\n
};\n mod = \'localstorage_test_12345678\';\n
try {\n
localStorage.setItem(mod, mod);\n
localStorage.removeItem(mod);\n
return true;\n
} catch (e) {\n
return false;\n
}\n
},\n
\n
get: function (cache_id, default_value) {\n
/* Get cache key value */\n
cache_id = this.getCacheId(cache_id);\n
if (this.hasLocalStorage()) {\n
return this.LocalStorageCachePlugin.\n
get(cache_id, default_value);\n
}\n
//fallback to javscript namespace cache\n
return this.NameSpaceStorageCachePlugin.\n
get(cache_id, default_value);\n
},\n
\n
set: function (cache_id, data) {\n
/* Set cache key value */\n
cache_id = this.getCacheId(cache_id);\n
if (this.hasLocalStorage()) {\n
this.LocalStorageCachePlugin.set(cache_id, data);\n
} else {\n
this.NameSpaceStorageCachePlugin.set(cache_id, data);\n
}\n
},\n
\n \n
this.setReady = function() {\n LocalStorageCachePlugin: (function () {\n
/*\n /*\n
* Return True if remote gadget is loaded into DOM.\n * This plugin saves using HTML5 localStorage.\n
*/\n */\n
this.is_ready = true;\n return {\n
};\n get: function (cache_id, default_value) {\n
}),\n /* Get cache key value */\n
\n if (cache_id in localStorage) {\n
TabbularGadget : (function () {\n return JSON.parse(localStorage.getItem(cache_id));\n
/*\n }\n
* Generic tabular gadget\n else {\n
*/\n return default_value;\n
return {\n }\n
\n
toggleVisibility: function(visible_dom) {\n
/*\n
* Set tab as active visually and mark as not active rest.\n
*/\n
$(".selected").addClass("not_selected"); $(".selected").removeClass("selected");\n
visible_dom.addClass("selected");\n
visible_dom.removeClass("not_selected");\n
},\n },\n
\n \n
addNewTabGadget: function(dom_id, gadget, gadget_data_handler, gadget_data_source) {\n set: function (cache_id, data) {\n
/*\n /* Set cache key value */\n
* add new gadget and render it\n localStorage.setItem(cache_id, JSON.stringify(data));\n
*/\n
var html_string;\n
tab_container=$(\'#\'+dom_id);\n
tab_container.empty();\n
html_string =[\'<div class="gadget" \',\n
\'data-gadget="\' + gadget + \'"\',\n
\'data-gadget:data-handler="\' + gadget_data_handler + \'" \',\n
\'data-gadget:data-source="\' + gadget_data_source +\'"></div>\'].join(\'\\n\');\n
\n
tab_container.append(html_string);\n
tab_gadget = tab_container.find(".gadget");\n
\n
// XXX: we should unregister all gadgets (if any we replace now in DOM)\n
\n
// render new gadget\n
RenderJs.setReady(false);\n
RenderJs.loadGadgetFromUrl(tab_gadget);\n
// clear previous events\n
RenderJs.GadgetIndex.getRootGadget().getDom().bind("ready", function (){\n
if (!is_ready){\n
RenderJs.updateGadgetData(tab_gadget);\n
is_ready = true;\n
}\n
});\n
}\n }\n
};\n
}()),\n
\n \n
}}()),\n NameSpaceStorageCachePlugin: (function () {\n
\n /*\n
* This plugin saves within current page namespace.\n
*/\n
var namespace = {};\n
\n
return {\n
get: function (cache_id, default_value) {\n
/* Get cache key value */\n
return namespace[cache_id];\n
},\n
\n \n
GadgetIndex : (function () {\n set: function (cache_id, data) {\n
/*\n /* Set cache key value */\n
* Generic gadget index placeholder\n namespace[cache_id] = data;\n
*/\n }\n
var gadget_list = [];\n };\n
}())\n
};\n
}()),\n
\n \n
return {\n Gadget: (function (gadget_id, dom) {\n
/*\n
* Javascript Gadget representation\n
*/\n
this.id = gadget_id;\n
this.dom = dom;\n
this.is_ready = false;\n
\n
this.getId = function () {\n
return this.id;\n
};\n
\n
this.getDom = function () {\n
return this.dom;\n
};\n
\n
this.isReady = function () {\n
/*\n
* Return True if remote gadget is loaded into DOM.\n
*/\n
return this.is_ready;\n
};\n
\n
this.setReady = function () {\n
/*\n
* Return True if remote gadget is loaded into DOM.\n
*/\n
this.is_ready = true;\n
};\n
}),\n
\n
TabbularGadget: (function () {\n
/*\n
* Generic tabular gadget\n
*/\n
return {\n
toggleVisibility: function (visible_dom) {\n
/*\n
* Set tab as active visually and mark as not active rest.\n
*/\n
$(".selected").addClass("not_selected");\n
$(".selected").removeClass("selected");\n
visible_dom.addClass("selected");\n
visible_dom.removeClass("not_selected");\n
},\n
\n
addNewTabGadget: function (dom_id, gadget, gadget_data_handler,\n
gadget_data_source) {\n
/*\n
* add new gadget and render it\n
*/\n
var tab_gadget;\n
tab_gadget = RenderJs.addGadget(\n
dom_id, gadget, gadget_data_handler, gadget_data_source\n
);\n
// XXX: we should unregister all gadgets (if any we replace now in DOM)\n
}\n
};\n
}()),\n
\n
GadgetIndex: (function () {\n
/*\n
* Generic gadget index placeholder\n
*/\n
var gadget_list = [];\n
\n \n
getGadgetList: function() {\n return {\n
/*\n getGadgetList: function () {\n
* Return list of registered gadgets\n /*\n
*/\n * Return list of registered gadgets\n
return gadget_list;\n */\n
},\n return gadget_list;\n
},\n
\n \n
registerGadget: function(gadget) {\n registerGadget: function (gadget) {\n
/*\n /*\n
* Register gadget\n * Register gadget\n
*/\n */\n
gadget_list.push(gadget);\n gadget_list.push(gadget);\n
},\n },\n
\n \n
unregisterGadget: function(gadget) {\n unregisterGadget: function (gadget) {\n
/*\n /*\n
* Unregister gadget\n * Unregister gadget\n
*/\n */\n
var index = $.inArray(gadget, gadget_list);\n var index = $.inArray(gadget, gadget_list);\n
if (index!==-1) {\n if (index !== -1) {\n
gadget_list.splice(index, 1);\n gadget_list.splice(index, 1);\n
}\n }\n
},\n },\n
\n \n
getGadgetById: function (gadget_id) {\n getGadgetById: function (gadget_id) {\n
/*\n /*\n
* Get gadget javascript representation by its Id\n * Get gadget javascript representation by its Id\n
*/\n */\n
var gadget;\n var gadget;\n
gadget = undefined;\n gadget = undefined;\n
$(RenderJs.GadgetIndex.getGadgetList()).each(\n $(RenderJs.GadgetIndex.getGadgetList()).each(\n
function (index, value) {\n function (index, value) {\n
if (value.getId()===gadget_id) {\n if (value.getId() === gadget_id) {\n
gadget = value;\n gadget = value;\n
}});\n }\n
return gadget;\n }\n
},\n );\n
return gadget;\n
},\n
\n \n
getRootGadget: function () {\n getRootGadget: function () {\n
/*\n /*\n
* Return root gadget (always first one in list)\n * Return root gadget (always first one in list)\n
*/\n */\n
return this.getGadgetList()[0];\n return this.getGadgetList()[0];\n
},\n },\n
\n \n
isGadgetListLoaded: function () {\n isGadgetListLoaded: function () {\n
/*\n /*\n
* Return True if all gadgets were loaded from network or cache\n * Return True if all gadgets were loaded from network or\n
*/\n * cache\n
var result;\n */\n
result = true;\n var result;\n
$(this.getGadgetList()).each(\n result = true;\n
function (index, value) {\n $(this.getGadgetList()).each(\n
if (value.isReady()===false) {\n function (index, value) {\n
if (value.isReady() === false) {\n
result = false;\n result = false;\n
}\n }\n
});\n
return result;\n
},\n
\n
getSelf: function (){\n
/*\n
* Return Gadget\'s Javascript representation\n
*/\n
// XXX:\n
}\n }\n
);\n
return result;\n
}\n
};\n
}()),\n
\n \n
}}()),\n InteractionGadget : (function () {\n
\n /*\n
InteractionGadget : (function () {\n * Basic gadget interaction gadget implementation.\n
/*\n */\n
* Basic gadget interaction gadget implementation.\n return {\n
*/\n bind: function (gadget_dom) {\n
return {\n /*\n
\n * Bind event between gadgets.\n
bind: function (gadget_dom){\n */\n
/*\n var gadget_id, gadget_connection_list,\n
* Bind event between gadgets.\n createMethodInteraction = function (\n
*/\n original_source_method_id, source_gadget_id,\n
gadget_id = gadget_dom.attr("id");\n source_method_id, destination_gadget_id,\n
gadget_dom.find("connect").each(function (key, value){\n destination_method_id) {\n
var source, source_gadget_id, source_method_id, source_gadget, destination, destination_gadget_id,\n var interaction = function () {\n
destination_method_id, destination_gadget, func_body, func;\n RenderJs.GadgetIndex.getGadgetById(\n
source = $(value).attr("source").split(".");\n source_gadget_id)[original_source_method_id].\n
source_gadget_id = source[0];\n apply(null, arguments);\n
source_method_id = source[1];\n RenderJs.GadgetIndex.getGadgetById(\n
source_gadget = RenderJs.GadgetIndex.getGadgetById(source_gadget_id);\n destination_gadget_id)[destination_method_id].\n
\n apply(null, arguments);\n
destination = $(value).attr("destination").split(".");\n };\n
destination_gadget_id = destination[0];\n return interaction;\n
destination_method_id = destination[1];\n },\n
destination_gadget = RenderJs.GadgetIndex.getGadgetById(destination_gadget_id);\n createTriggerInteraction = function (\n
\n destination_gadget_id, destination_method_id) {\n
if (source_gadget.hasOwnProperty(source_method_id)){\n var interaction = function () {\n
RenderJs.GadgetIndex.getGadgetById(\n
destination_gadget_id)[destination_method_id].\n
apply(null, arguments);\n
};\n
return interaction;\n
};\n
gadget_id = gadget_dom.attr("id");\n
gadget_connection_list = gadget_dom.attr("data-gadget-connection");\n
gadget_connection_list = $.parseJSON(gadget_connection_list);\n
$.each(gadget_connection_list, function (key, value) {\n
var source, source_gadget_id, source_method_id,\n
source_gadget, destination, destination_gadget_id,\n
destination_method_id, destination_gadget,\n
original_source_method_id;\n
source = value.source.split(".");\n
source_gadget_id = source[0];\n
source_method_id = source[1];\n
source_gadget = RenderJs.GadgetIndex.\n
getGadgetById(source_gadget_id);\n
\n
destination = value.destination.split(".");\n
destination_gadget_id = destination[0];\n
destination_method_id = destination[1];\n
destination_gadget = RenderJs.GadgetIndex.\n
getGadgetById(destination_gadget_id);\n
\n
if (source_gadget.hasOwnProperty(source_method_id)) {\n
// direct javascript use case\n // direct javascript use case\n
func_body = \'RenderJs.GadgetIndex.getGadgetById("\' + source_gadget_id + \'")["original_\' + source_method_id + \'"]();\';\n original_source_method_id = "original_" +\n
func_body = func_body + \'\\nRenderJs.GadgetIndex.getGadgetById("\' + destination_gadget_id + \'")["\' + destination_method_id + \'"]();\';\n source_method_id;\n
func = new Function(func_body);\n source_gadget[original_source_method_id] =\n
source_gadget["original_" + source_method_id] = source_gadget[source_method_id];\n source_gadget[source_method_id];\n
source_gadget[source_method_id] = func;\n source_gadget[source_method_id] =\n
}\n createMethodInteraction(\n
else{\n original_source_method_id,\n
// this is a custom event attached to HTML gadget representation\n source_gadget_id,\n
func_body = \'RenderJs.GadgetIndex.getGadgetById("\' + destination_gadget_id + \'")["\' + destination_method_id + \'"]();\';\n source_method_id,\n
func = new Function(func_body);\n destination_gadget_id,\n
source_gadget.dom.bind(source_method_id, func);\n destination_method_id\n
}\n );\n
}\n }\n
);\n else {\n
}\n // this is a custom event attached to HTML gadget\n
}}())\n // representation\n
\n source_gadget.dom.bind(\n
}}()); source_method_id,\n
createTriggerInteraction(\n
destination_gadget_id, destination_method_id\n
)\n
);\n
}\n
});\n
}\n
};\n
}())\n
};\n
}());\n
\n
// impliticly call RenderJs bootstrap\n
$(document).ready(function () {\n
if (RENDERJS_ENABLE_IMPLICIT_GADGET_RENDERING) {\n
RenderJs.bootstrap($(\'body\'));\n
}\n
if (RENDERJS_ENABLE_IMPLICIT_INTERACTION_BIND) {\n
var root_gadget = RenderJs.GadgetIndex.getRootGadget();\n
// We might have a page without gadgets.\n
// Be careful, right now we can be in this case because\n
// asynchronous gadget loading is not finished\n
if (root_gadget !== undefined) {\n
RenderJs.bindReady(\n
function () {\n
// examine all Intaction Gadgets and bind accordingly\n
$("div[data-gadget-connection]").each( function(index, element) {\n
RenderJs.InteractionGadget.bind($(element));\n
})\n
});\n
}\n
}\n
});
]]></string> </value> ]]></string> </value>
</item> </item>
...@@ -483,7 +625,7 @@ var RenderJs = (function () {\n ...@@ -483,7 +625,7 @@ var RenderJs = (function () {\n
</item> </item>
<item> <item>
<key> <string>size</string> </key> <key> <string>size</string> </key>
<value> <int>18997</int> </value> <value> <int>22925</int> </value>
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
......
20 21
\ No newline at end of file \ 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