PageSourceSearch

https://www.jhrl.com/sites/all/modules/vrweb/vrweb_collection/js/vrweb_collection.ajax.js?v=1.0

js jhrl.com collected 2026-10-06 13:17:38 UTC 3,849 bytes, 107 lines download raw bytes

1/**
2 * @file
3 * Drupal AJAX integration for rezFusion Collection.
4 */
5(function ($, Drupal) {
6  window.VRWeb.AJAX = window.VRWeb.AJAX || {};
7  // Init rezFusion AJAX namespace.
8
9  // Helper function to fetch and update a container div's content using AJAX.
10  window.VRWeb.AJAX.fetchContent = function (namespace) {
11    // Init/clear vars. This is kinda superfluous but has made things
12    // play nicer together and helped debugging.
13    var view, container, $container, collection, items, data, url;
14
15    if (!Drupal.settings.vrweb_collection.ajax.hasOwnProperty('get')
16      || !Drupal.settings.vrweb_collection.ajax.get.hasOwnProperty(namespace)) {
17      return false;
18    }
19
20    // Set vars.
21    view = Drupal.settings.vrweb_collection.ajax.get[namespace].view;
22    container = Drupal.settings.vrweb_collection.ajax.get[namespace].container;
23    $container = $('#' + container);
24    collection = new VRWeb.cookieCollection(namespace);
25    items = collection.get();
26    data = 'view=' + view + '&nids=' + items.join('+');
27    url = Drupal.settings.basePath + 'ajax/vrweb_collection/get';
28
29    // Add AJAX loader.
30    $container.addClass('vrweb-loading');
31
32    // If we're viewing a node right now, pass it along so we know
33    // not to render it.
34    if (Drupal.settings.vrweb_collection.ajax.add) {
35      for (var i in Drupal.settings.vrweb_collection.ajax.add[namespace]) {
36        url += '/' + Drupal.settings.vrweb_collection.ajax.add[namespace][i];
37      }
38    }
39
40    // Make AJAX request and replace contents of $container.
41    // These have to be synchronous to accomodate for multiple AJAX
42    // blocks on the same page and asynchronous requests will end up
43    // trampling on eachother and causing problems.
44    $.ajax({
45      type: 'get',
46      async: false,
47      url: url,
48      data: data,
49      dataType: 'json',
50      success: function(response) {
51        // Add contents to container.
52        if (response.contents) {
53          $container.removeClass('vrweb-loading').html(response.contents);
54        }
55      }
56    });
57  };
58
59  // Process JS settings and make magic happen.
60  Drupal.behaviors.vrweb_collection_ajax = {
61    attach: function(context, settings) {
62      if (settings.vrweb_collection.ajax) {
63
64        // Add items to cookie.
65        if (settings.vrweb_collection.ajax.add) {
66          for (var namespace in settings.vrweb_collection.ajax.add) {
67            var collection = new VRWeb.cookieCollection(namespace);
68
69            for (var i in settings.vrweb_collection.ajax.add[namespace]) {
70              var id = settings.vrweb_collection.ajax.add[namespace][i];
71
72              if (!collection.has(id)) {
73                collection.add(id);
74              }
75            }
76          }
77        }
78
79        // Fetch items using AJAX and insert into container.
80        if (settings.vrweb_collection.ajax.get) {
81          for (var namespace in settings.vrweb_collection.ajax.get) {
82            var container = Drupal.settings.vrweb_collection.ajax.get[namespace].container;
83
84            // Populate with initial content.
85            window.VRWeb.AJAX.fetchContent(namespace);
86
87            // Listen for add/remove events and update content.
88            $('#' + container).on('VRWebCollectionAJAXUpdate', function(e, namespace) {
89              window.VRWeb.AJAX.fetchContent(namespace);
90            });
91          }
92        }
93      }
94    }
95  };
96
97  // After the document has loaded and initial events have been fired, listen in
98  // for additional add/remove events and update any ajax blocks.
99  $(window).load(function () {
100    // Watch for changes to existing collections and update AJAX blocks.
101    jQuery(document).on('VRWebCollectionUpdate', function(e, action, namespace) {
102      if (action === 'add' || action === 'remove') {
103        window.VRWeb.AJAX.fetchContent(namespace);
104      }
105    });
106  });
107})(jQuery, Drupal);

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.