-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
61 lines (56 loc) · 2.04 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @file example.js
*
* Handles AJAX facets reactions.
*
* @see views/js/ajax_views.js
*/
(function ($) {
/**
* Attaches the AJAX behavior to Views exposed filter forms and key View links.
*/
Drupal.behaviors.ExampleFacets = {};
Drupal.behaviors.ExampleFacets.attach = function() {
if (Drupal.settings && Drupal.settings.views && Drupal.settings.views.ajaxViews) {
// Retrieve the path to use for views' ajax.
var ajax_path = Drupal.settings.views.ajax_path;
$.each(Drupal.settings.views.ajaxViews, function(i, settings) {
var view = '.search-api-facets';
var element_settings = {
url: ajax_path,
submit: settings,
setClick: true,
event: 'click',
selector: view,
progress: {type: 'throbber'}
};
$(view).filter(':not(.views-processed)')
.each(function() {
// Set a reference that will work in subsequent calls.
var target = this;
$(this)
.addClass('views-processed')
// Process facet links.
.find('li > a')
.each(function () {
var viewData = {};
// Construct an object using the settings defaults and then overriding
// with data specific to the link.
$.extend(
viewData,
settings,
Drupal.Views.parseQueryString($(this).attr('href')),
// Extract argument data from the URL.
Drupal.Views.parseViewArgs($(this).attr('href'), settings.view_base_path)
);
// For anchor tags, these will go to the target of the anchor rather
// than the usual location.
$.extend(viewData, Drupal.Views.parseViewArgs($(this).attr('href'), settings.view_base_path));
element_settings.submit = viewData;
var ajax = new Drupal.ajax(false, this, element_settings);
}); // .each function () {
}); // $view.filter().each
}); // .each Drupal.settings.views.ajaxViews
} // if
};
})(jQuery);