forked from easyting/ting_marc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ting_marc.js
59 lines (54 loc) · 1.64 KB
/
ting_marc.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
/**
* Fetch values for Ajaxified ting marcXchange fields.
*/
(function($) {
var selector = 'ting-marc-unprocessed',
processing = 'ting-marc-processing',
nodata = 'ting-marc-nodata';
function ting_marc_fields(container, settings) {
var fields_obj = {};
$('.' + selector, container).each(function(index, value) {
var field = {
data: $(this).data('ting-marc'),
clickable: $(this).data('ting-clickable'),
link_index: $(this).data('ting-link_index')
};
if (field.data) {
fields_obj[index] = field;
}
$(this).removeClass(selector);
$(this).addClass(processing);
});
if (!jQuery.isEmptyObject(fields_obj)) {
$.ajax({
url: Drupal.settings.basePath + Drupal.settings.pathPrefix + 'ting/marc/fields',
dataType: 'json',
type: 'POST',
data: fields_obj,
success: function (data) {
$.each(data, function () {
$('.' + processing, container).each(function (index) {
var field = $(this),
_data = $(field).data('ting-marc'),
data_field = data[index];
if (data_field) {
if (typeof (data_field[_data]) === "undefined") {
field.addClass(nodata);
}
else {
field.find('.field-item').html(data_field[_data]);
}
field.removeClass(processing);
}
});
});
}
});
}
}
Drupal.behaviors.ting_marc = {
attach : function(context, settings) {
ting_marc_fields(context, settings);
}
};
})(jQuery);