PageSourceSearch

https://theartssociety.org/sites/all/modules/contrib/views_load_more/views_load_more.js?tlvm4t

js theartssociety.org collected 2026-09-24 20:56:02 UTC 5,952 bytes, 139 lines download raw bytes

1/**
2 * @file views_load_more.js
3 *
4 * Handles the AJAX pager for the view_load_more plugin.
5 */
6(function ($) {
7
8  /**
9   * Provide a series of commands that the server can request the client perform.
10   */
11  Drupal.ajax.prototype.commands.viewsLoadMoreAppend = function (ajax, response, status) {
12    // Get information from the response. If it is not there, default to
13    // our presets.
14    var wrapper = response.selector ? $(response.selector) : $(ajax.wrapper);
15    var method = response.method || ajax.method;
16    var targetList = response.targetList || '';
17    var effect = ajax.getEffect(response);
18    var pager_selector = response.options.pager_selector ? response.options.pager_selector : '.pager-load-more';
19
20    // We don't know what response.data contains: it might be a string of text
21    // without HTML, so don't rely on jQuery correctly iterpreting
22    // $(response.data) as new HTML rather than a CSS selector. Also, if
23    // response.data contains top-level text nodes, they get lost with either
24    // $(response.data) or $('<div></div>').replaceWith(response.data).
25    var new_content_wrapped = $('<div></div>').html(response.data);
26    var new_content = new_content_wrapped.contents();
27
28    // For legacy reasons, the effects processing code assumes that new_content
29    // consists of a single top-level element. Also, it has not been
30    // sufficiently tested whether attachBehaviors() can be successfully called
31    // with a context object that includes top-level text nodes. However, to
32    // give developers full control of the HTML appearing in the page, and to
33    // enable Ajax content to be inserted in places where DIV elements are not
34    // allowed (e.g., within TABLE, TR, and SPAN parents), we check if the new
35    // content satisfies the requirement of a single top-level element, and
36    // only use the container DIV created above when it doesn't. For more
37    // information, please see http://drupal.org/node/736066.
38    if (new_content.length != 1 || new_content.get(0).nodeType != 1) {
39      new_content = new_content_wrapped;
40    }
41    // If removing content from the wrapper, detach behaviors first.
42    var settings = response.settings || ajax.settings || Drupal.settings;
43    Drupal.detachBehaviors(wrapper, settings);
44    if ($.waypoints != undefined) {
45      $.waypoints('refresh');
46    }
47
48    // Set up our default query options. This is for advance users that might
49    // change there views layout classes. This allows them to write there own
50    // jquery selector to replace the content with.
51    // Provide sensible defaults for unordered list, ordered list and table
52    // view styles.
53    var content_query = targetList && !response.options.content ? '> .view-content ' + targetList : response.options.content || '> .view-content';
54
55    // If we're using any effects. Hide the new content before adding it to the DOM.
56    if (effect.showEffect != 'show') {
57      new_content.find(content_query).children().hide();
58    }
59
60    // Update the pager
61    // Find both for the wrapper as the newly loaded content the direct child
62    // .item-list in case of nested pagers
63    wrapper.find(pager_selector).replaceWith(new_content.find(pager_selector));
64
65    // Add the new content to the page.
66    wrapper.find(content_query)[method](new_content.find(content_query).children());
67
68    // Re-class the loaded content.
69    // @todo this is faulty in many ways.  first of which is that user may have configured view to not have these classes at all.
70    wrapper.find(content_query).children()
71      .removeClass('views-row-first views-row-last views-row-odd views-row-even')
72      .filter(':first')
73        .addClass('views-row-first')
74        .end()
75      .filter(':last')
76        .addClass('views-row-last')
77        .end()
78      .filter(':even')
79        .addClass('views-row-odd')
80        .end()
81      .filter(':odd')
82        .addClass('views-row-even')
83        .end();
84
85    if (effect.showEffect != 'show') {
86      wrapper.find(content_query).children(':not(:visible)')[effect.showEffect](effect.showSpeed);
87    }
88
89    // Additional processing over new content
90    wrapper.trigger('views_load_more.new_content', new_content.clone());
91
92    // Attach all JavaScript behaviors to the new content
93    // Remove the Jquery once Class, TODO: There needs to be a better
94    // way of doing this, look at .removeOnce() :-/
95    var classes = wrapper.attr('class');
96    var onceClass = classes.match(/jquery-once-[0-9]*-[a-z]*/);
97    wrapper.removeClass(onceClass[0]);
98    settings = response.settings || ajax.settings || Drupal.settings;
99    Drupal.attachBehaviors(wrapper, settings);
100  };
101
102  /**
103   * Attaches the AJAX behavior to Views Load More waypoint support.
104   */
105  Drupal.behaviors.ViewsLoadMore = {
106    attach: function (context, settings) {
107      var default_opts = {
108          offset: '100%'
109        };
110
111      if (settings && settings.viewsLoadMore && settings.views && settings.views.ajaxViews) {
112        $.each(settings.viewsLoadMore, function(i, setting) {
113          var view = '.view-id-' + setting.view_name + '.view-display-id-' + setting.view_display_id + ' .pager-next a',
114            opts = {};
115
116          $.extend(opts, default_opts, settings.viewsLoadMore[i].opts);
117
118          $(view).waypoint('destroy');
119          $(view).waypoint(function(event, direction) {
120            $(view).click();
121          }, opts);
122        });
123      }
124    },
125    detach: function (context, settings, trigger) {
126      if (settings && settings.viewsLoadMore && settings.views && settings.views.ajaxViews) {
127        $.each(settings.viewsLoadMore, function(i, setting) {
128          var view = '.view-id-' + setting.view_name + '.view-display-id-' + setting.view_display_id;
129          if ($(context).is(view)) {
130            $('.pager-next a', view).waypoint('destroy');
131          }
132          else {
133            $(view, context).waypoint('destroy');
134          }
135        });
136      }
137    }
138  };
139})(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.