-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathting_marc.js
More file actions
70 lines (62 loc) · 1.78 KB
/
ting_marc.js
File metadata and controls
70 lines (62 loc) · 1.78 KB
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
/**
* Fetch values for Ajaxified ting marcXchange fields.
*/
(function($) {
var hidden = 'item-collapsed',
selector = 'ting-marc-unprocessed',
processing = 'ting-marc-processing',
nodata = 'ting-marc-nodata';
function ting_marc_fields(container) {
var fields = [];
$('.' + selector, container).each(function() {
var data = $(this).data('ting-marc');
if (data) {
fields.push(data);
}
$(this).removeClass(selector);
$(this).addClass(processing);
});
if (fields.length > 0) {
$.post(
Drupal.settings.basePath + Drupal.settings.pathPrefix + 'ting/marc/fields',
{ting_marc_fields: fields},
function(data) {
$('.' + processing, container).each(function(){
var field = $(this),
_data = field.data('ting-marc');
if (typeof(data[_data]) == "undefined") {
field.addClass(nodata);
}
else {
field.find('.field-item').html(data[_data]);
}
field.removeClass(processing);
});
}
);
}
}
function show_for_opened(container) {
$('.group_details', container).each(function(){
if (!$(this).hasClass('hidden')) {
ting_marc_fields(this);
}
});
}
Drupal.behaviors.ting_marc = {
attach : function(context, settings) {
// Fetch data for visible fields.
show_for_opened(context);
// Fetch data when "details" is opened.
$('legend', context).click(function() {
var parent = $(this).parent().parent();
if (!parent.hasClass(hidden)) {
ting_marc_fields(parent);
}
});
$('.show-info', context).click(function() {
show_for_opened(context);
});
}
};
})(jQuery);