You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by do...@apache.org on 2008/03/27 14:56:54 UTC
svn commit: r641817 -
/incubator/shindig/trunk/javascript/container/gadgets.js
Author: doll
Date: Thu Mar 27 06:56:53 2008
New Revision: 641817
URL: http://svn.apache.org/viewvc?rev=641817&view=rev
Log:
Added a basic requestNavigateToFunction to gadgets.js
Now containers can just override parts of the function to add their own implementation.
Modified:
incubator/shindig/trunk/javascript/container/gadgets.js
Modified: incubator/shindig/trunk/javascript/container/gadgets.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/container/gadgets.js?rev=641817&r1=641816&r2=641817&view=diff
==============================================================================
--- incubator/shindig/trunk/javascript/container/gadgets.js (original)
+++ incubator/shindig/trunk/javascript/container/gadgets.js Thu Mar 27 06:56:53 2008
@@ -182,6 +182,7 @@
gadgets.rpc.register('resize_iframe', this.setHeight);
gadgets.rpc.register('set_pref', this.setUserPref);
gadgets.rpc.register('set_title', this.setTitle);
+ gadgets.rpc.register('requestNavigateTo', this.requestNavigateTo);
};
gadgets.IfrGadgetService.inherits(gadgets.GadgetService);
@@ -211,15 +212,60 @@
* @param {String} value Value of user preference
* More names and values may follow
*/
-gadgets.IfrGadgetService.prototype.setUserPref = function(editToken, name, value) {
- // Quick hack to extract the gadget id from module id
- var id = parseInt(this.f.match(/_([0-9]+)$/)[1], 10);
+gadgets.IfrGadgetService.prototype.setUserPref = function(editToken, name,
+ value) {
+ var id = this.getGadgetIdFromModuleId(this.f);
var gadget = gadgets.container.getGadget(id);
var prefs = gadget.getUserPrefs();
for (var i = 1, j = arguments.length; i < j; i += 2) {
prefs[arguments[i]] = arguments[i + 1];
}
gadget.setUserPrefs(prefs);
+};
+
+/**
+ * Navigates the page to a new url based on a gadgets requested view and
+ * parameters.
+ */
+gadgets.IfrGadgetService.prototype.requestNavigateTo = function(view,
+ opt_params) {
+ var id = this.getGadgetIdFromModuleId(this.f);
+ var url = this.getUrlForView(view);
+
+ if (opt_params) {
+ var paramStr = JSON.stringify(opt_params);
+ if (paramStr.length > 0) {
+ url += '&appParams=' + encodeURIComponent(paramStr);
+ }
+ }
+
+ if (url && document.location.href.indexOf(url) == -1) {
+ document.location.href = url;
+ }
+};
+
+/**
+ * This is a silly implementation that will need to be overriden by almost all
+ * real containers.
+ * TODO: Find a better default for this function
+ *
+ * @param view The view name to get the url for
+ */
+gadgets.IfrGadgetService.prototype.getUrlForView = function(
+ view) {
+ if (view === 'canvas') {
+ return '/canvas';
+ } else if (view === 'profile') {
+ return '/profile';
+ } else {
+ return null;
+ }
+}
+
+gadgets.IfrGadgetService.prototype.getGadgetIdFromModuleId = function(
+ moduleId) {
+ // Quick hack to extract the gadget id from module id
+ return parseInt(moduleId.match(/_([0-9]+)$/)[1], 10);
};