web/data/cubicweb.ajax.js
changeset 5971 6109bdb8ac06
parent 5947 e13e7833a57a
child 5977 5b1ce013ae32
equal deleted inserted replaced
5970:fb8acdab4e12 5971:6109bdb8ac06
    90 
    90 
    91 var JSON_BASE_URL = baseuri() + 'json?';
    91 var JSON_BASE_URL = baseuri() + 'json?';
    92 
    92 
    93 //============= utility function handling remote calls responses. ==============//
    93 //============= utility function handling remote calls responses. ==============//
    94 function _loadAjaxHtmlHead($node, $head, tag, srcattr) {
    94 function _loadAjaxHtmlHead($node, $head, tag, srcattr) {
    95     var loaded = [];
       
    96     var jqtagfilter = tag + '[' + srcattr + ']';
    95     var jqtagfilter = tag + '[' + srcattr + ']';
    97     jQuery('head ' + jqtagfilter).each(function(i) {
    96     if (cw['loaded_'+srcattr] === undefined) {
    98         loaded.push(this.getAttribute(srcattr));
    97 	cw['loaded_'+srcattr] = [];
    99     });
    98 	var loaded = cw['loaded_'+srcattr];
       
    99 	jQuery('head ' + jqtagfilter).each(function(i) {
       
   100 		loaded.push(this.getAttribute(srcattr));
       
   101 	    });
       
   102     } else {
       
   103 	var loaded = cw['loaded_'+srcattr];
       
   104     }
   100     $node.find(tag).each(function(i) {
   105     $node.find(tag).each(function(i) {
   101 	 var url = this.getAttribute(srcattr);
   106 	 var url = this.getAttribute(srcattr);
   102         if (url) {
   107         if (url) {
   103             if (jQuery.inArray(url, loaded) == -1) {
   108             if (jQuery.inArray(url, loaded) == -1) {
   104 		if (srcattr == 'src') {
   109 		// take care to <script> tags: jQuery append method script nodes
   105 		    // special case for <script> tags: jQuery append method
   110 		// don't appears in the DOM (See comments on
   106 		    // script nodes don't appears in the DOM (See comments on
   111 		// http://api.jquery.com/append/), which cause undesired
   107 		    // http://api.jquery.com/append/), which cause undesired
   112 		// duplicated load in our case. After trying to use bare DOM api
   108 		    // duplicated load in our case. Use bare DOM api to avoid
   113 		// to avoid this, we switched to handle a list of already loaded
   109 		    // this.
   114 		// stuff ourselves, since bare DOM api gives bug with the
   110 		    var s = document.createElement("script");
   115 		// server-response event, since we loose control on when the
   111 		    s.type = "text/javascript";
   116 		// script is loaded (jQuery load it immediatly).
   112 		    s.src = url;
   117 		loaded.push(url);
   113 		    $head[0].appendChild(s);
   118 		jQuery(this).appendTo($head);
   114 		} else {
       
   115 		    jQuery(this).appendTo($head);
       
   116 		}
       
   117             }
   119             }
   118         } else {
   120         } else {
   119             jQuery(this).appendTo($head);
   121             jQuery(this).appendTo($head);
   120         }
   122         }
   121     });
   123     });