forked from yhahn/searchlight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchlight.js
82 lines (72 loc) · 2.64 KB
/
searchlight.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(function($) {
Drupal.behaviors.searchlight = {};
Drupal.behaviors.searchlight.attach = function(context, settings) {
if (Drupal.settings && Drupal.settings.views && Drupal.settings.views.ajaxViews) {
$('.searchlight-environment:not(.searchlightProcessed)').each(function() {
// Retrieve current page view's settings and DOM element.
var settings = {};
var view = '';
var identifier = $(this).attr('class').split('searchlight-view-')[1].split('-');
for (var i in Drupal.settings.views.ajaxViews) {
if (
Drupal.settings.views.ajaxViews[i].view_name == identifier[0] &&
Drupal.settings.views.ajaxViews[i].view_display_id == identifier[1]
) {
settings = Drupal.settings.views.ajaxViews[i];
view = $('.view-dom-id-' + settings.view_dom_id);
$('a', this).drupalSearchlight('ajaxViewLink', {view: view, settings: settings});
break;
}
}
}).addClass('searchlightProcessed');
}
};
$.fn.drupalSearchlight = function(method, params) {
switch (method) {
case 'ajaxViewLink':
var settings = params.settings;
var view = params.view;
// If there are multiple views this might've ended up showing up multiple times.
var ajax_path = Drupal.settings.views.ajax_path;
if (ajax_path.constructor.toString().indexOf("Array") != -1) {
ajax_path = ajax_path[0];
}
$(this).each(function() {
var viewData = {};
var link = $(this);
// Construct an object using the settings defaults and then overriding
// with data specific to the link.
$.extend(
viewData,
Drupal.Views.parseQueryString(link.attr('href')),
// Extract argument data from the URL.
Drupal.Views.parseViewArgs(link.attr('href'), settings.view_base_path),
// Settings must be used last to avoid sending url aliases to the server.
settings
);
var ajax = new Drupal.ajax(false, link, {
url: ajax_path,
submit: viewData,
event: 'click',
selector: view
});
// Override HTTP method type and beforeSerialize method.
// See note above.
ajax.options.type = 'GET';
ajax.beforeSerialize = function(element_settings, options) { return; };
});
break;
}
return this;
};
$.fn.drupalSearchlight.replace = function(selector, data) {
if (data.searchlightData) {
for (var target in data.searchlightData) {
if ($(target).size()) {
$(target).replaceWith(data.searchlightData[target]);
Drupal.attachBehaviors($(target));
}
}
}
};
})(jQuery);