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