Author: etnu
Date: Thu May 21 17:38:08 2009
New Revision: 777199

URL: http://svn.apache.org/viewvc?rev=777199&view=rev
Log:
Added client-side support for osx:parseJSON to align with server-side support. 
Patch from Lev Epshteyn.


Modified:
    
incubator/shindig/trunk/features/src/main/javascript/features/opensocial-templates/template.js

Modified: 
incubator/shindig/trunk/features/src/main/javascript/features/opensocial-templates/template.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/main/javascript/features/opensocial-templates/template.js?rev=777199&r1=777198&r2=777199&view=diff
==============================================================================
--- 
incubator/shindig/trunk/features/src/main/javascript/features/opensocial-templates/template.js
 (original)
+++ 
incubator/shindig/trunk/features/src/main/javascript/features/opensocial-templates/template.js
 Thu May 21 17:38:08 2009
@@ -28,7 +28,12 @@
 os.createContext = function(data, opt_globals) {
   var context = JsEvalContext.create(data);
   context.setVariable(os.VAR_callbacks, []);
-  context.setVariable(os.VAR_identifierresolver, os.getFromContext);
+  var defaults = os.getContextDefaults_();
+  for (var def in defaults) {
+    if (defaults.hasOwnProperty(def)) {
+      context.setVariable(def, defaults[def]);
+    }
+  }
   context.setVariable(os.VAR_emptyArray, os.EMPTY_ARRAY);
   if (opt_globals) {
     for (var global in opt_globals) {
@@ -40,6 +45,22 @@
   return context;
 };
 
+os.contextDefaults_ = null;
+
+os.getContextDefaults_ = function() {
+  if (!os.contextDefaults_) {
+    os.contextDefaults_ = {};
+    os.contextDefaults_[os.VAR_emptyArray] = os.EMPTY_ARRAY;
+    os.contextDefaults_[os.VAR_identifierresolver] = os.getFromContext;
+    if (window["JSON"] && JSON.parse) {
+      os.contextDefaults_["osx:parseJson"] = JSON.parse;
+    } else if (window["gadgets"] && gadgets.json && gadgets.json.parse) {
+      os.contextDefaults_["osx:parseJson"] = gadgets.json.parse;
+    }
+  }
+  return os.contextDefaults_;
+};
+
 /**
  * A renderable compiled Template. A template can contain one or more
  * compiled nodes pre-processed for JST operation. 


Reply via email to