You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by li...@apache.org on 2010/06/01 07:57:11 UTC

svn commit: r949934 - in /shindig/trunk/features/src/main/javascript/features/container: container.js feature.xml gadget_holder.js gadget_site.js service.js util.js

Author: lindner
Date: Tue Jun  1 05:57:11 2010
New Revision: 949934

URL: http://svn.apache.org/viewvc?rev=949934&view=rev
Log:
js cleanups

Modified:
    shindig/trunk/features/src/main/javascript/features/container/container.js
    shindig/trunk/features/src/main/javascript/features/container/feature.xml
    shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js
    shindig/trunk/features/src/main/javascript/features/container/gadget_site.js
    shindig/trunk/features/src/main/javascript/features/container/service.js
    shindig/trunk/features/src/main/javascript/features/container/util.js

Modified: shindig/trunk/features/src/main/javascript/features/container/container.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/container.js?rev=949934&r1=949933&r2=949934&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container/container.js (original)
+++ shindig/trunk/features/src/main/javascript/features/container/container.js Tue Jun  1 05:57:11 2010
@@ -20,9 +20,6 @@
  * @fileoverview This represents the container for the current window or create
  * the container if none already exists.
  */
-var shindig = shindig || {};
-shindig.container = shindig.container || {};
-
 
 /**
  * @param {Object=} opt_config Configuration JSON.
@@ -45,27 +42,28 @@ shindig.container.Container = function(o
   /**
    * @type {boolean}
    */
-  this.renderDebug_ = shindig.container.util.getSafeJsonValue(config,
-      shindig.container.ContainerConfig.RENDER_DEBUG, false);
+  this.renderDebug_ = Boolean(shindig.container.util.getSafeJsonValue(config,
+      shindig.container.ContainerConfig.RENDER_DEBUG, false));
 
   /**
    * @type {boolean}
    */
-  this.renderTest_ = shindig.container.util.getSafeJsonValue(config,
-      shindig.container.ContainerConfig.RENDER_TEST, false);
+  this.renderTest_ = Boolean(shindig.container.util.getSafeJsonValue(config,
+      shindig.container.ContainerConfig.RENDER_TEST, false));
 
   /**
    * @type {boolean}
    */
-  this.sameDomain_ = shindig.container.util.getSafeJsonValue(config,
-      shindig.container.ContainerConfig.SAME_DOMAIN, true);
+  this.sameDomain_ = Boolean(shindig.container.util.getSafeJsonValue(config,
+      shindig.container.ContainerConfig.SAME_DOMAIN, true));
 
   /**
+   * Security token refresh interval (in ms) for debugging.
    * @type {number}
    */
-  this.tokenRefreshInterval_ = shindig.container.util.getSafeJsonValue(config,
+  this.tokenRefreshInterval_ = Number(shindig.container.util.getSafeJsonValue(config,
       shindig.container.ContainerConfig.TOKEN_REFRESH_INTERVAL,
-      30 * 60 * 1000);
+      30 * 60 * 1000));
 
   /**
    * @type {shindig.container.Service}
@@ -73,8 +71,8 @@ shindig.container.Container = function(o
   this.service_ = new shindig.container.Service(config);
 
   /**
-   * Security token refresh interval (in ms) for debugging.
-   * @type {Object}
+   * result from calling window.setInterval()
+   * @type {number|null}
    */
   this.tokenRefreshTimer_ = null;
 
@@ -136,7 +134,7 @@ shindig.container.Container.prototype.ge
  * @param {string} gadgetUrl The URI of the gadget
  * @param {Object} gadgetParams view params for the gadget
  * @param {Object} renderParams render parameters, including the view
- * @param {Function=} opt_callback Callback that occurs after gadget is loaded
+ * @param {function(Object)=} opt_callback Callback that occurs after gadget is loaded
  */
 shindig.container.Container.prototype.navigateGadget = function(
     site, gadgetUrl, gadgetParams, renderParams, opt_callback) {
@@ -217,7 +215,7 @@ shindig.container.Container.prototype.on
 // -----------------------------------------------------------------------------
 
 /**
- * Enumeation of configuration keys for this container. This is specified in
+ * Enumeration of configuration keys for this container. This is specified in
  * JSON to provide extensible configuration. These enum values are for
  * documentation purposes only, it is expected that clients use the string
  * values.
@@ -322,7 +320,7 @@ shindig.container.Container.prototype.ad
 /**
  * Collect all URLs of gadgets that require tokens refresh. This comes from both
  * preloaded gadgets and navigated-to gadgets.
- * @return {array} An array of URLs of gadgets.
+ * @return {Array} An array of URLs of gadgets.
  * @private
  */
 shindig.container.Container.prototype.getTokenRefreshableGadgetUrls_ = function() {

Modified: shindig/trunk/features/src/main/javascript/features/container/feature.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/feature.xml?rev=949934&r1=949933&r2=949934&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container/feature.xml (original)
+++ shindig/trunk/features/src/main/javascript/features/container/feature.xml Tue Jun  1 05:57:11 2010
@@ -19,6 +19,7 @@ under the License.
 -->
 <feature>
   <name>container</name>
+  <dependency>globals</dependency>
   <dependency>core</dependency>
   <dependency>osapi</dependency>
   <dependency>rpc</dependency>

Modified: shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js?rev=949934&r1=949933&r2=949934&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js (original)
+++ shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js Tue Jun  1 05:57:11 2010
@@ -19,9 +19,6 @@
 /**
  * @fileoverview This represents an HTML element and the associated gadget.
  */
-var shindig = shindig || {};
-shindig.container = shindig.container || {};
-
 
 /**
  * @param {number} siteId The id of site containing this holder.
@@ -45,14 +42,14 @@ shindig.container.GadgetHolder = functio
 
   /**
    * JSON metadata for gadget
-   * @type {Object}
+   * @type {Object?}
    * @private
    */
   this.gadgetInfo_ = null;
 
   /**
    * View parameters to pass to gadget.
-   * @type {Object}
+   * @type {Object?}
    * @private
    */
   this.gadgetParams_ = null;
@@ -66,28 +63,28 @@ shindig.container.GadgetHolder = functio
 
   /**
    * Gadget rendering parameters
-   * @type {Object}
+   * @type {Object?}
    * @private
    */
   this.renderParams_ = null;
 
   /**
    * Unique string gadget ID. Used for DOM IDs/names.
-   * @type {string}
+   * @type {string?}
    * @private
    */
   this.iframeId_ = null;
 
   /**
    * Name of current view being rendered.
-   * @type {string}
+   * @type {string?}
    * @private
    */
   this.view_ = null;
 
   /**
    * JSON metadata about current view being rendered.
-   * @type {Object}
+   * @type {Object?}
    * @private
    */
   this.viewInfo_ = null;
@@ -96,7 +93,7 @@ shindig.container.GadgetHolder = functio
    * A dynamically set social/security token.
    * Social tokens are sent with original view URLs but may need
    * to be refreshed for long lived gadgets.
-   * @type {string}
+   * @type {string?}
    * @private
    */
   this.securityToken_ = null;
@@ -121,7 +118,7 @@ shindig.container.GadgetHolder.prototype
 
 
 /**
- * @return {string} The unique string ID for gadget iframe.
+ * @return {string|null} The unique string ID for gadget iframe.
  */
 shindig.container.GadgetHolder.prototype.getIframeId = function() {
   return this.iframeId_;
@@ -129,7 +126,7 @@ shindig.container.GadgetHolder.prototype
 
 
 /**
- * @return {Object} The metadata of gadget.
+ * @return {Object|null} The metadata of gadget.
  */
 shindig.container.GadgetHolder.prototype.getGadgetInfo = function() {
   return this.gadgetInfo_;
@@ -145,7 +142,7 @@ shindig.container.GadgetHolder.prototype
 
 
 /**
- * @return {string} The URL of current gadget.
+ * @return {string|null} The URL of current gadget.
  */
 shindig.container.GadgetHolder.prototype.getUrl = function() {
   return (this.gadgetInfo_) ? this.gadgetInfo_['url'] : null;
@@ -153,7 +150,7 @@ shindig.container.GadgetHolder.prototype
 
 
 /**
- * @return {string} The view of current gadget.
+ * @return {string|null} The view of current gadget.
  */
 shindig.container.GadgetHolder.prototype.getView = function() {
   return this.view_;
@@ -161,7 +158,7 @@ shindig.container.GadgetHolder.prototype
 
 
 /**
- * @return {string} The iframe element containing gadget.
+ * @return {Node} The iframe element containing gadget.
  */
 shindig.container.GadgetHolder.prototype.getIframeElement = function() {
   return this.el_.firstChild;
@@ -291,7 +288,7 @@ shindig.container.GadgetHolder.prototype
     }
   }
 
-  uri = this.addHashParam_(uri, 'mid', this.siteId_);
+  uri = this.addHashParam_(uri, 'mid', String(this.siteId_));
 
   if (this.hasGadgetParams_) {
     var gadgetParamText = gadgets.json.stringify(this.gadgetParams_);
@@ -311,7 +308,7 @@ shindig.container.GadgetHolder.prototype
  */
 shindig.container.GadgetHolder.prototype.updateBooleanParam_ = function(uri, param) {
   if (this.renderParams_[param]) {
-    uri = this.addQueryParam_(uri, param, 1);
+    uri = this.addQueryParam_(uri, param, "1");
   }
   return uri;
 };
@@ -321,7 +318,7 @@ shindig.container.GadgetHolder.prototype
  * Replace user prefs specified in url with only those specified. This will
  * maintain each user prefs existence (or lack of), order (from left to right)
  * and its appearance (in query params or fragment).
- * @param {string} url The URL possibly containing user preferences parameters
+ * @param {string} uri The URL possibly containing user preferences parameters
  *     prefixed by up_.
  * @return {string} The URL with up_ replaced by those specified in userPrefs.
  * @private

Modified: shindig/trunk/features/src/main/javascript/features/container/gadget_site.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/gadget_site.js?rev=949934&r1=949933&r2=949934&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container/gadget_site.js (original)
+++ shindig/trunk/features/src/main/javascript/features/container/gadget_site.js Tue Jun  1 05:57:11 2010
@@ -21,8 +21,6 @@
  * HTML element in the container. The API for this is low-level. Use the
  * container APIs to work with gadget sites.
  */
-var shindig = shindig || {};
-shindig.container = shindig.container || {};
 
 
 /**
@@ -48,10 +46,10 @@ shindig.container.GadgetSite = function(
 
   /**
    * Element holding the loading gadget for 2x buffering.
-   * @type {Element}
+   * @type {Element?}
    * @private
    */
-  this.loadingGadgetEl_ = opt_bufferEl;
+  this.loadingGadgetEl_ = opt_bufferEl || null;
 
   /**
    * Unique ID of this site.
@@ -62,21 +60,21 @@ shindig.container.GadgetSite = function(
 
   /**
    * ID of parent gadget.
-   * @type {string}
+   * @type {string?}
    * @private
    */
   this.parentId_ = null;
 
   /**
    * Information about the currently visible gadget.
-   * @type {shindig.container.GadgetHolder}
+   * @type {shindig.container.GadgetHolder?}
    * @private
    */
   this.curGadget_ = null;
 
   /**
    * Information about the currently loading gadget.
-   * @type {shindig.container.GadgetHolder}
+   * @type {shindig.container.GadgetHolder?}
    * @private
    */
   this.loadingGadget_ = null;
@@ -184,7 +182,7 @@ shindig.container.GadgetSite.prototype.g
 
 
 /**
- * @return {string} ID parent element containing this site.
+ * @return {string?} ID parent element containing this site.
  */
 shindig.container.GadgetSite.prototype.getParentId = function() {
   return this.parentId_;
@@ -197,7 +195,7 @@ shindig.container.GadgetSite.prototype.g
  * @param {Object} gadgetParams View parameters for the gadget.
  * @param {Object} renderParams. Render parameters for the gadget, including:
  *     view, width, height.
- * @param {Function=} opt_callback Function called with gadget info after
+ * @param {function(Object)=} opt_callback Function called with gadget info after
  *     navigation has occurred.
  */
 shindig.container.GadgetSite.prototype.navigateTo = function(gadgetUrl, gadgetParams,
@@ -289,7 +287,7 @@ shindig.container.GadgetSite.prototype.r
 /**
  * Sends RPC call to the current/visible gadget.
  * @param {string} serviceName RPC service name to call.
- * @param {Function} callback Function to call upon RPC completion.
+ * @param {function(Object)} callback Function to call upon RPC completion.
  * @param {...number} var_args payload to pass to the recipient.
  */
 shindig.container.GadgetSite.prototype.rpcCall = function(serviceName, callback, var_args) {
@@ -367,6 +365,7 @@ shindig.container.GadgetSite.prototype.o
   try {
     gadgets.rpc.call(this.loadingGadget_.getIframeId(), 'onLoad', null);
     if (this.resizeOnLoad_) {
+      // TODO need a value for setHeight
       this.setHeight();
     }
   } catch (e) {

Modified: shindig/trunk/features/src/main/javascript/features/container/service.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/service.js?rev=949934&r1=949933&r2=949934&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container/service.js (original)
+++ shindig/trunk/features/src/main/javascript/features/container/service.js Tue Jun  1 05:57:11 2010
@@ -20,8 +20,6 @@
  * @fileoverview This represents the service layer that talks to OSAPI
  * endpoints. All RPC requests should go into this class.
  */
-var shindig = shindig || {};
-shindig.container = shindig.container || {};
 
 
 /**
@@ -55,11 +53,11 @@ shindig.container.Service.prototype.onCo
  * request.sameDomain and request.aspDomain. The appropriate optional
  * callback opt_callback will be called, after a response is received.
  * @param {Object} request JSON object representing the request.
- * @param {Function=} opt_callback function to call upon data receive.
+ * @param {function(Object)=} opt_callback function to call upon data receive.
  */
 shindig.container.Service.prototype.getGadgetMetadata = function(
     request, opt_callback) {
-  var callback = opt_callback || function() {};
+  var callback = opt_callback || function(a) {};
   var self = this;
   osapi.gadgets.getMetadata(request, function(response) {
     if (response.error) {

Modified: shindig/trunk/features/src/main/javascript/features/container/util.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/util.js?rev=949934&r1=949933&r2=949934&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container/util.js (original)
+++ shindig/trunk/features/src/main/javascript/features/container/util.js Tue Jun  1 05:57:11 2010
@@ -19,15 +19,22 @@
 /**
  * @fileoverview Utility methods common container.
  */
-var shindig = shindig || {};
-shindig.container = shindig.container || {};
-shindig.container.util = shindig.container.util || {};
+
+/**
+ * @type {Object}
+ */
+shindig.container = {};
+
+/**
+ * @type {Object}
+ */
+shindig.container.util = {};
 
 
 /**
  * Extract protocol and domain of container page. Valid values:
  * http://www.cnn.com, chrome-extension://www.cnn.com
- * @param {string} url The URL to extract path domain from.
+ * @param {string} uri The URL to extract path domain from.
  * @return {string} The protocol and domain of container page.
  */
 shindig.container.util.parseOrigin = function(uri) {
@@ -39,7 +46,7 @@ shindig.container.util.parseOrigin = fun
 
 /**
  * Extract prefix path of a URL, not including opt_postfixPath.
- * @param {string} url The URL to extract path from.
+ * @param {string} uri The URL to extract path from.
  * @param {string=} opt_postfixPath The URL postfix to avoid extracting.
  * @return {string} The path in URL, before postfixPath.
  */
@@ -56,7 +63,7 @@ shindig.container.util.parsePrefixPath =
 
 /**
  * Extract path of a URL.
- * @param {string} url The URL to extract path from.
+ * @param {string} uri The URL to extract path from.
  * @return {string} The path in URL.
  */
 shindig.container.util.parsePath = function(uri) {
@@ -81,8 +88,8 @@ shindig.container.util.getParamValue = f
  * Return value of json at key, if valid. Otherwise, return defaultValue.
  * @param {Object} json The JSON to look up key param from.
  * @param {string} key Key in config.
- * @param {Object?} defaultValue The default value to return.
- * @return {Object?}
+ * @param {*=} defaultValue The default value to return.
+ * @return {*}
  */
 shindig.container.util.getSafeJsonValue = function(json, key, defaultValue) {
   return (json[key] != undefined && json[key] != null)
@@ -111,7 +118,7 @@ shindig.container.util.mergeJsons = func
 /**
  * Extract keys from a JSON to an array.
  * @param {Object} json to extract keys from.
- * @return {array} keys in the json.
+ * @return {Array.<string>} keys in the json.
  */
 shindig.container.util.toArrayOfJsonKeys = function(json) {
   var result = [];
@@ -122,6 +129,7 @@ shindig.container.util.toArrayOfJsonKeys
 };
 
 
+// TODO unused?
 /**
  * Count the number of own/self properties in json.
  * @param {Object} json the JSON to act on.