You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by jo...@apache.org on 2010/12/15 04:23:39 UTC

svn commit: r1049403 - in /shindig/trunk/features: ./ src/main/javascript/features/ src/main/javascript/features/core.util.urlparams/ src/main/javascript/features/core.util/

Author: johnh
Date: Wed Dec 15 03:23:38 2010
New Revision: 1049403

URL: http://svn.apache.org/viewvc?rev=1049403&view=rev
Log:
Split feature core.util into core.util and core.util.urlparams, to allow users of gadgets.util.getUrlParameters() [only] to reduce in size by declaring their dependency in more fine-grained fashion.


Added:
    shindig/trunk/features/src/main/javascript/features/core.util.urlparams/
    shindig/trunk/features/src/main/javascript/features/core.util.urlparams/feature.xml
    shindig/trunk/features/src/main/javascript/features/core.util.urlparams/urlparams.js
Modified:
    shindig/trunk/features/pom.xml
    shindig/trunk/features/src/main/javascript/features/core.util/feature.xml
    shindig/trunk/features/src/main/javascript/features/core.util/util.js
    shindig/trunk/features/src/main/javascript/features/features.txt

Modified: shindig/trunk/features/pom.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/pom.xml?rev=1049403&r1=1049402&r2=1049403&view=diff
==============================================================================
--- shindig/trunk/features/pom.xml (original)
+++ shindig/trunk/features/pom.xml Wed Dec 15 03:23:38 2010
@@ -113,6 +113,7 @@
                 <source>core.json/json-jsimpl.js</source>
                 <source>core.json/json-flatten.js</source>
                 <source>shindig.auth/auth.js</source>
+                <source>core.util.urlparams/urlparams.js</source>
                 <source>core.util/util.js</source>
                 <source>core.prefs/prefs.js</source>
                 <source>core.log/log.js</source>

Added: shindig/trunk/features/src/main/javascript/features/core.util.urlparams/feature.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/core.util.urlparams/feature.xml?rev=1049403&view=auto
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/core.util.urlparams/feature.xml (added)
+++ shindig/trunk/features/src/main/javascript/features/core.util.urlparams/feature.xml Wed Dec 15 03:23:38 2010
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations under the License.
+-->
+<feature>
+  <name>core.util.urlparams</name>
+  <dependency>globals</dependency>
+  <gadget>
+    <script src="urlparams.js"/>
+  </gadget>
+  <container>
+    <script src="urlparams.js"/>
+  </container>
+</feature>

Added: shindig/trunk/features/src/main/javascript/features/core.util.urlparams/urlparams.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/core.util.urlparams/urlparams.js?rev=1049403&view=auto
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/core.util.urlparams/urlparams.js (added)
+++ shindig/trunk/features/src/main/javascript/features/core.util.urlparams/urlparams.js Wed Dec 15 03:23:38 2010
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * @fileoverview General purpose utilities that gadgets can use.
+ */
+
+/**
+ * @static
+ * @class Provides a thin method for parsing url parameters.
+ * @name gadgets.util
+ */
+
+gadgets['util'] = function() {
+  var parameters = null;
+
+  /**
+   * Parses URL parameters into an object.
+   * @param {string} url - the url parameters to parse.
+   * @return {Array.<string>} The parameters as an array.
+   */
+  function parseUrlParams(url) {
+    // Get settings from url, 'hash' takes precedence over 'search' component
+    // don't use document.location.hash due to browser differences.
+    var query;
+    var queryIdx = url.indexOf('?');
+    var hashIdx = url.indexOf('#');
+    if (hashIdx === -1) {
+      query = url.substr(queryIdx + 1);
+    } else {
+      // essentially replaces "#" with "&"
+      query = [url.substr(queryIdx + 1, hashIdx - queryIdx - 1), '&',
+               url.substr(hashIdx + 1)].join('');
+    }
+    return query.split('&');
+  }
+
+  return /** @scope gadgets.util */ {
+    /**
+     * Gets the URL parameters.
+     *
+     * @param {string=} opt_url Optional URL whose parameters to parse.
+     *                         Defaults to window's current URL.
+     * @return {Object} Parameters passed into the query string.
+     * @member gadgets.util
+     * @private Implementation detail.
+     */
+    getUrlParameters: function(opt_url) {
+      var no_opt_url = typeof opt_url === 'undefined';
+      if (parameters !== null && no_opt_url) {
+        // "parameters" is a cache of current window params only.
+        return parameters;
+      }
+      var parsed = {};
+      var pairs = parseUrlParams(opt_url || document.location.href);
+      var unesc = window.decodeURIComponent ? decodeURIComponent : unescape;
+      for (var i = 0, j = pairs.length; i < j; ++i) {
+        var pos = pairs[i].indexOf('=');
+        if (pos === -1) {
+          continue;
+        }
+        var argName = pairs[i].substring(0, pos);
+        var value = pairs[i].substring(pos + 1);
+        // difference to IG_Prefs, is that args doesn't replace spaces in
+        // argname. Unclear on if it should do:
+        // argname = argname.replace(/\+/g, " ");
+        value = value.replace(/\+/g, ' ');
+        parsed[argName] = unesc(value);
+      }
+      if (no_opt_url) {
+        // Cache current-window params in parameters var.
+        parameters = parsed;
+      }
+      return parsed;
+    }
+  };
+}();
+// Initialize url parameters so that hash data is pulled in before it can be
+// altered by a click.
+gadgets.util.getUrlParameters();

Modified: shindig/trunk/features/src/main/javascript/features/core.util/feature.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/core.util/feature.xml?rev=1049403&r1=1049402&r2=1049403&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/core.util/feature.xml (original)
+++ shindig/trunk/features/src/main/javascript/features/core.util/feature.xml Wed Dec 15 03:23:38 2010
@@ -20,6 +20,7 @@
   <name>core.util</name>
   <dependency>globals</dependency>
   <dependency>core.config</dependency>
+  <dependency>core.util.urlparams</dependency>
   <gadget>
     <script src="util.js"/>
     <script src="taming.js"/>

Modified: shindig/trunk/features/src/main/javascript/features/core.util/util.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/core.util/util.js?rev=1049403&r1=1049402&r2=1049403&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/core.util/util.js (original)
+++ shindig/trunk/features/src/main/javascript/features/core.util/util.js Wed Dec 15 03:23:38 2010
@@ -21,35 +21,15 @@
  * @fileoverview General purpose utilities that gadgets can use.
  */
 
+// Short-term incremental library-building mechanism.
+var __getUrlParameters = gadgets.util.getUrlParameters;
+
 /**
  * @static
  * @class Provides general-purpose utility functions.
  * @name gadgets.util
  */
-
 gadgets['util'] = function() {
-  /**
-   * Parses URL parameters into an object.
-   * @param {string} url - the url parameters to parse.
-   * @return {Array.<string>} The parameters as an array.
-   */
-  function parseUrlParams(url) {
-    // Get settings from url, 'hash' takes precedence over 'search' component
-    // don't use document.location.hash due to browser differences.
-    var query;
-    var queryIdx = url.indexOf('?');
-    var hashIdx = url.indexOf('#');
-    if (hashIdx === -1) {
-      query = url.substr(queryIdx + 1);
-    } else {
-      // essentially replaces "#" with "&"
-      query = [url.substr(queryIdx + 1, hashIdx - queryIdx - 1), '&',
-               url.substr(hashIdx + 1)].join('');
-    }
-    return query.split('&');
-  }
-
-  var parameters = null;
   var features = {};
   var services = {};
   var onLoadHandlers = [];
@@ -62,7 +42,6 @@ gadgets['util'] = function() {
    * If the value is "false", the character is removed entirely, otherwise
    * it will be replaced with an html entity.
    */
-
   var escapeCodePoints = {
     // nul; most browsers truncate because they use c strings under the covers.
     0 : false,
@@ -118,34 +97,7 @@ gadgets['util'] = function() {
      * @member gadgets.util
      * @private Implementation detail.
      */
-    'getUrlParameters' : function(opt_url) {
-      var no_opt_url = typeof opt_url === 'undefined';
-      if (parameters !== null && no_opt_url) {
-        // "parameters" is a cache of current window params only.
-        return parameters;
-      }
-      var parsed = {};
-      var pairs = parseUrlParams(opt_url || document.location.href);
-      var unesc = window.decodeURIComponent ? decodeURIComponent : unescape;
-      for (var i = 0, j = pairs.length; i < j; ++i) {
-        var pos = pairs[i].indexOf('=');
-        if (pos === -1) {
-          continue;
-        }
-        var argName = pairs[i].substring(0, pos);
-        var value = pairs[i].substring(pos + 1);
-        // difference to IG_Prefs, is that args doesn't replace spaces in
-        // argname. Unclear on if it should do:
-        // argname = argname.replace(/\+/g, " ");
-        value = value.replace(/\+/g, ' ');
-        parsed[argName] = unesc(value);
-      }
-      if (no_opt_url) {
-        // Cache current-window params in parameters var.
-        parameters = parsed;
-      }
-      return parsed;
-    },
+    'getUrlParameters' : __getUrlParameters,
 
     /**
      * Creates a closure that is suitable for passing as a callback.
@@ -367,7 +319,3 @@ gadgets['util'] = function() {
     }
   };
 }();
-// Initialize url parameters so that hash data is pulled in before it can be
-// altered by a click.
-gadgets['util'].getUrlParameters();
-

Modified: shindig/trunk/features/src/main/javascript/features/features.txt
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/features.txt?rev=1049403&r1=1049402&r2=1049403&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/features.txt (original)
+++ shindig/trunk/features/src/main/javascript/features/features.txt Wed Dec 15 03:23:38 2010
@@ -33,6 +33,7 @@ features/core.log/feature.xml
 features/core.none/feature.xml
 features/core.prefs/feature.xml
 features/core.util/feature.xml
+features/core.util.urlparams/feature.xml
 features/core/feature.xml
 features/dynamic-height.util/feature.xml
 features/dynamic-height/feature.xml