# HG changeset patch # User Sylvain Thénault # Date 1310459782 -7200 # Node ID ede740bd70776a98c6949ecb10d3400a32aff48e # Parent 5d5d9893024721cf1ce4342cd78da85781721654 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE diff -r 5d5d98930247 -r ede740bd7077 utils.py --- a/utils.py Mon Jul 11 19:48:37 2011 +0200 +++ b/utils.py Tue Jul 12 10:36:22 2011 +0200 @@ -362,13 +362,33 @@ # 4/ js files jsfiles = ((x, None) for x in self.jsfiles) for jsfile, media in self.group_urls(jsfiles) if self.datadir_url else jsfiles: - w(u'\n' % - xml_escape(jsfile)) + if skiphead: + # Don't insert \n' % + xml_escape(jsfile)) # 5/ post inlined scripts (i.e. scripts depending on other JS files) if self.post_inlined_scripts: - w(self.xhtml_safe_script_opening) - w(u'\n\n'.join(self.post_inlined_scripts)) - w(self.xhtml_safe_script_closing) + if skiphead: + for script in self.post_inlined_scripts: + w(u'
')
+                    w(script)
+                    w(u'
') + else: + w(self.xhtml_safe_script_opening) + w(u'\n\n'.join(self.post_inlined_scripts)) + w(self.xhtml_safe_script_closing) header = super(HTMLHead, self).getvalue() if skiphead: return header diff -r 5d5d98930247 -r ede740bd7077 web/data/cubicweb.ajax.js --- a/web/data/cubicweb.ajax.js Mon Jul 11 19:48:37 2011 +0200 +++ b/web/data/cubicweb.ajax.js Tue Jul 12 10:36:22 2011 +0200 @@ -93,9 +93,10 @@ jQuery.extend(cw.ajax, { /* variant of jquery evalScript with cache: true in ajax call */ _evalscript: function ( i, elem ) { - if ( elem.src ) { + var src = elem.getAttribute('src'); + if (src) { jQuery.ajax({ - url: elem.src, + url: src, async: false, cache: true, dataType: "script" @@ -145,62 +146,76 @@ ); } return resources; + }, + + _buildMissingResourcesUrl: function(url, loadedResources) { + var resources = cw.ajax._listResources(url); + var missingResources = $.grep(resources, function(resource) { + return $.inArray(resource, loadedResources) == -1; + }); + cw.utils.extend(loadedResources, missingResources); + var missingResourceUrl = null; + if (missingResources.length == 1) { + // only one resource missing: build a node with a single resource url + // (maybe the browser has it in cache already) + missingResourceUrl = missingResources[0]; + } else if (missingResources.length > 1) { + // several resources missing: build a node with a concatenated + // resources url + var dataurl = cw.ajax._modconcatLikeUrl(url)[1]; + var missing_path = $.map(missingResources, function(resource) { + return resource.substring(dataurl.length); + }); + missingResourceUrl = dataurl + '??' + missing_path.join(','); + } + return missingResourceUrl; + }, + + _loadAjaxStylesheets: function($responseHead, $head) { + $responseHead.find('link[href]').each(function(i) { + var $srcnode = $(this); + var url = $srcnode.attr('href'); + if (url) { + var missingStylesheetsUrl = cw.ajax._buildMissingResourcesUrl(url, cw.loaded_links); + // compute concat-like url for missing resources and append + // element to $head + if (missingStylesheetsUrl) { + $srcnode.attr('href', missingStylesheetsUrl); + $srcnode.appendTo($head); + } + } + }); + $responseHead.find('link[href]').remove(); + }, + + _loadAjaxScripts: function($responseHead, $head) { + $responseHead.find('pre.script').each(function(i) { + var $srcnode = $(this); + var url = $srcnode.attr('src'); + if (url) { + var missingScriptsUrl = cw.ajax._buildMissingResourcesUrl(url, cw.loaded_scripts); + if (missingScriptsUrl) { + $srcnode.attr('src', missingScriptsUrl); + /* special handling of