Author: lindner
Date: Sat Oct 24 08:48:49 2009
New Revision: 829323

URL: http://svn.apache.org/viewvc?rev=829323&view=rev
Log:
SHINDIG-890 | Patch from Henning Schmiedehausen | Make URL Template example 
from opensocial spec actually work with shindig

Modified:
    incubator/shindig/trunk/features/src/main/javascript/features/views/views.js

Modified: 
incubator/shindig/trunk/features/src/main/javascript/features/views/views.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/main/javascript/features/views/views.js?rev=829323&r1=829322&r2=829323&view=diff
==============================================================================
--- 
incubator/shindig/trunk/features/src/main/javascript/features/views/views.js 
(original)
+++ 
incubator/shindig/trunk/features/src/main/javascript/features/views/views.js 
Sat Oct 24 08:48:49 2009
@@ -185,6 +185,18 @@
         return j;
       }
 
+      function objectIsEmpty(v) {
+       if ((typeof v === 'object') || (typeof v === 'function')) {
+         for (i in v) {
+           if (v.hasOwnProperty(i)) {
+             return false;
+           }
+         }
+         return true;
+       }
+       return false;
+      }
+
       while ((group = expansionRE.exec(urlTemplate))) {
         result.push(urlTemplate.substring(textStart, group.index));
         textStart = expansionRE.lastIndex;
@@ -203,10 +215,11 @@
               flag = 1;
             case 'opt':
               if (matchVars(vars, {flag: flag}, function(j, v) {
-                    if (typeof v !== 'undefined' && (typeof v !== 'object' || 
v.length)) {
+                    if (typeof v !== 'undefined' && !objectIsEmpty(v)) {
                       j.flag = !j.flag;
                       return 1;
                     }
+                    return 0;
                   }).flag) {
                 result.push(arg);
               }
@@ -215,6 +228,12 @@
               result.push(matchVars(vars, [], function(j, v, k) {
                 if (typeof v === 'string') {
                   j.push(k + '=' + v);
+                } else if (typeof v === 'object') {
+                  for (i in v) {
+                    if (v.hasOwnProperty(i)) {
+                      j.push(i + '=' + v[i]);
+                   }
+                 }
                 }
               }).join(arg));
               break;


Reply via email to