You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by hs...@apache.org on 2012/06/29 23:55:13 UTC

svn commit: r1355574 - in /shindig/trunk: content/samplecontainer/examples/templates/TemplateClientAPI.xml features/src/main/javascript/features/opensocial-templates/loader.js

Author: hsaputra
Date: Fri Jun 29 21:55:12 2012
New Revision: 1355574

URL: http://svn.apache.org/viewvc?rev=1355574&view=rev
Log:
SHINDIG-1788 | Non-inline templates are not accessible from os.getTemplate JavaScript | Patch from Chris Geer. Thanks.

Added:
    shindig/trunk/content/samplecontainer/examples/templates/TemplateClientAPI.xml
Modified:
    shindig/trunk/features/src/main/javascript/features/opensocial-templates/loader.js

Added: shindig/trunk/content/samplecontainer/examples/templates/TemplateClientAPI.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/templates/TemplateClientAPI.xml?rev=1355574&view=auto
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/templates/TemplateClientAPI.xml (added)
+++ shindig/trunk/content/samplecontainer/examples/templates/TemplateClientAPI.xml Fri Jun 29 21:55:12 2012
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<Module>
+    <ModulePrefs title="TemplateClientAPI">
+        <Require feature="opensocial-templates">
+            <!-- This is required to be present to get access to the JavaScript -->
+            <Param name="client">true</Param>
+            <Param name="requireLibrary">TestTemplateLibrary.xml</Param>
+        </Require>
+        <Optional feature="content-rewrite">
+            <Param name="include-tags"></Param>
+        </Optional>
+    </ModulePrefs>
+    <Content type="html" view="home,profile">
+        <![CDATA[
+        <script type="text/os-template" xmlns:foomod="http://foo.com/module" tag="foomod:HelloWorldModule">
+            <div>Hello World Module</div>
+        </script>
+
+        <div>
+          <p>Simple test of gadget using template library with client API access</p>
+        </div>
+        <script type="text/os-template" xmlns:foo="http://foo.com/" xmlns:foomod="http://foo.com/module">
+          <p>
+            <div>Statically Defined from Module...</div><foomod:HelloWorldModule />
+            <div>Statically Defined from Template...</div><foo:HelloWorld />
+          </p>
+        </script><br/>
+
+        <div>Client Added from Module ...</div>
+        <div><div id='addheremod'/></div><br/>
+
+        <div>Client Added from Template ...</div>
+        <div><div id='addheretemplate'/></div><br/>
+
+        <script type="text/javascript">
+            function handleLoad() {
+                var template = os.getTemplate("foomod:HelloWorldModule");
+                if (template != undefined) {
+                    var placeholder = document.getElementById("addheremod");
+                    template.renderInto(placeholder);
+                } else {
+                    alert('Error: Inline Not Found (Module Defined) - This fails due to OnLoadHandler timing. '
+                        + 'This will succeed if you comment out the template library');
+                }
+
+                template = os.getTemplate("foo:HelloWorld");
+                if (template != undefined) {
+                    var placeholder = document.getElementById("addheretemplate");
+                    template.renderInto(placeholder);
+                } else {
+                    alert('Error: Inline Not Found (Template Defined)');
+                }
+            }
+            gadgets.util.registerOnLoadHandler(handleLoad);
+		</script>
+        ]]>
+    </Content>
+</Module>
\ No newline at end of file

Modified: shindig/trunk/features/src/main/javascript/features/opensocial-templates/loader.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/opensocial-templates/loader.js?rev=1355574&r1=1355573&r2=1355574&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/opensocial-templates/loader.js (original)
+++ shindig/trunk/features/src/main/javascript/features/opensocial-templates/loader.js Fri Jun 29 21:55:12 2012
@@ -226,8 +226,9 @@ os.Loader.processTemplateNode = function
       throw Error('Namespace not registered: ' + tagParts[0] +
           ' while trying to define ' + tag);
     }
-    var template = os.compileXMLNode(node);
+    var template = os.compileXMLNode(node, tag);
     nsObj[tagParts[1]] = os.createTemplateCustomTag(template);
+    os.registerTemplate(template);
   } else if (name) {
     var template = os.compileXMLNode(node);
     template.id = name;