PageSourceSearch

https://viewmycatalogs.com/sites/all/modules/ajax_load/ajax_load.js?n

js viewmycatalogs.com collected 2026-09-29 08:45:21 UTC 3,585 bytes, 107 lines download raw bytes

1// $Id: ajax_load.js,v 1.11 2009/09/20 14:22:29 markuspetrux Exp $
2
3(function ($) {
4
5Drupal.AjaxLoad = Drupal.AjaxLoad || { externalScripts: [], loadPending: [] };
6
7/**
8 * Load JavaScript and CSS files and data. 
9 */
10Drupal.AjaxLoad.loadFiles = function (target, response) {
11  // Handle scripts.
12
13  // Initialize the list of currently loaded external scripts.
14  if (Drupal.AjaxLoad.externalScripts.length < 1) {
15    $('script[src]').each(function() {
16      Drupal.AjaxLoad.externalScripts.push($(this).attr('src'));
17    });
18  }
19  // See if we have any settings to extend. Do this first so that behaviors
20  // can access the new settings easily.
21  if (response.scripts) {
22    // Each Ajax operation needs its own counter.
23    var index = Drupal.AjaxLoad.loadPending.length;
24    Drupal.AjaxLoad.loadPending[index] = 0;
25    if (!response.__customSettings && response.scripts.setting) {
26      $.extend(Drupal.settings, response.scripts.setting);
27    }
28    // Inline scripts will be handled separately.
29    var types = ['core', 'module', 'theme'];
30    $.each(types, function (i, type) {
31      if (response.scripts[type]) {
32        $.each(response.scripts[type], function (src, data) {
33          // Load scripts.
34          src = Drupal.settings.basePath + src;
35          // Test if the script already exists.
36          var found = false;
37          for (var j = 0; j < Drupal.AjaxLoad.externalScripts.length; j++) {
38            if (Drupal.AjaxLoad.externalScripts[j].indexOf(src) == 0) {
39              found = true;
40              break;
41            }
42          }
43          if (!found) {
44            Drupal.AjaxLoad.loadPending[index]++;
45            $.getScript(src, function () {
46              Drupal.AjaxLoad.externalScripts.push(src);
47              Drupal.AjaxLoad.loadComplete(index, target, response);
48            });
49          }
50        });
51      }
52    });
53    // Ensure Drupal behaviors are attached to new content, even when no
54    // new external scripts have been loaded.
55    if (Drupal.AjaxLoad.loadPending[index] == 0) {
56      Drupal.attachBehaviors(target);
57      // Ensure inline scripts are parsed after all external scripts have loaded.
58      Drupal.AjaxLoad.loadInline(response);
59    }
60  }
61  if (response.css) {
62    // Handle stylesheets.
63    var types = ['module', 'theme'];
64    $.each(response.css, function (media, files) {
65      $.each(types, function (i, type) {
66        if (files[type]) {
67          $.each(files[type], function (src, data) {
68            src = Drupal.settings.basePath + src;
69            // Test if the stylesheet already exists.
70            if (!$('link[href*=' + src + ']').size()) {
71              $('<link type="text/css" rel="stylesheet" media="' + media + '" href="' + src + '" />').appendTo('head');
72            }
73          });
74        }
75      });
76    });
77  }
78};
79
80/**
81 * When all scripts have loaded, attach behaviors. 
82 */
83Drupal.AjaxLoad.loadInline = function(response) {
84  // Handle inline scripts.
85  if (response.scripts.inline) {
86    $.each(response.scripts.inline, function (i, script) {
87      // document.write calls would mess things up.
88      if (script.code.indexOf('document.write') == -1) {
89        eval(script.code);
90      }
91    });
92  }
93};
94
95/**
96 * When all scripts have loaded, attach behaviors. 
97 */
98Drupal.AjaxLoad.loadComplete = function(index, target, response) {
99  Drupal.AjaxLoad.loadPending[index]--;
100  if (Drupal.AjaxLoad.loadPending[index] == 0) {
101    Drupal.attachBehaviors(target);
102    // Ensure inline scripts are parsed after all external scripts have loaded.
103    Drupal.AjaxLoad.loadInline(response);
104  }
105};
106
107})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.