web/data/cubicweb.ajax.js
changeset 5947 e13e7833a57a
parent 5937 82cac9383dd8
child 5971 6109bdb8ac06
equal deleted inserted replaced
5946:9cbde75fefe8 5947:e13e7833a57a
    89 
    89 
    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 = [];
    95     var loaded = [];
    96     var jqtagfilter = tag + '[' + srcattr + ']';
    96     var jqtagfilter = tag + '[' + srcattr + ']';
    97     jQuery('head ' + jqtagfilter).each(function(i) {
    97     jQuery('head ' + jqtagfilter).each(function(i) {
    98         loaded.push(this.getAttribute(srcattr));
    98         loaded.push(this.getAttribute(srcattr));
    99     });
    99     });
   100     node.find(tag).each(function(i) {
   100     $node.find(tag).each(function(i) {
   101         if (this.getAttribute(srcattr)) {
   101 	 var url = this.getAttribute(srcattr);
   102             if (jQuery.inArray(this.getAttribute(srcattr), loaded) == -1) {
   102         if (url) {
   103                 jQuery(this).appendTo(head);
   103             if (jQuery.inArray(url, loaded) == -1) {
       
   104 		if (srcattr == 'src') {
       
   105 		    // special case for <script> tags: jQuery append method
       
   106 		    // script nodes don't appears in the DOM (See comments on
       
   107 		    // http://api.jquery.com/append/), which cause undesired
       
   108 		    // duplicated load in our case. Use bare DOM api to avoid
       
   109 		    // this.
       
   110 		    var s = document.createElement("script");
       
   111 		    s.type = "text/javascript";
       
   112 		    s.src = url;
       
   113 		    $head[0].appendChild(s);
       
   114 		} else {
       
   115 		    jQuery(this).appendTo($head);
       
   116 		}
   104             }
   117             }
   105         } else {
   118         } else {
   106             jQuery(this).appendTo(head);
   119             jQuery(this).appendTo($head);
   107         }
   120         }
   108     });
   121     });
   109     node.find(jqtagfilter).remove();
   122     $node.find(jqtagfilter).remove();
   110 }
   123 }
   111 
   124 
   112 /**
   125 /**
   113  * .. function:: function loadAjaxHtmlHead(response)
   126  * .. function:: function loadAjaxHtmlHead(response)
   114  *
   127  *