[utils] Fix define_var in ajax context (closes #4881301)
authorRémi Cardona <remi.cardona@logilab.fr>
Wed, 28 Jan 2015 11:59:06 +0100
changeset 10166 0095961df66c
parent 10165 7f1f7f710b16
child 10167 de62952550d9
[utils] Fix define_var in ajax context (closes #4881301) Use namespaced <cubicweb:script> instead of just <script>
utils.py
--- a/utils.py	Wed Jan 28 11:53:20 2015 +0100
+++ b/utils.py	Wed Jan 28 11:59:06 2015 +0100
@@ -368,14 +368,20 @@
         w = self.write
         # 1/ variable declaration if any
         if self.jsvars:
-            w(self.script_opening)
+            if skiphead:
+                w(u'<cubicweb:script>')
+            else:
+                w(self.script_opening)
             for var, value, override in self.jsvars:
                 vardecl = u'%s = %s;' % (var, json.dumps(value))
                 if not override:
                     vardecl = (u'if (typeof %s == "undefined") {%s}' %
                                (var, vardecl))
                 w(vardecl + u'\n')
-            w(self.script_closing)
+            if skiphead:
+                w(u'</cubicweb:script>')
+            else:
+                w(self.script_closing)
         # 2/ css files
         ie_cssfiles = ((x, (y, z)) for x, y, z in self.ie_cssfiles)
         if self.datadir_url and self._cw.vreg.config['concat-resources']: