This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
forked from drupalprojects/metatag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metatag.vertical-tabs.js
57 lines (53 loc) · 1.67 KB
/
metatag.vertical-tabs.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
/**
* @file
* Custom JS for controlling the Metatag vertical tab.
*/
(function ($) {
'use strict';
Drupal.behaviors.metatagFieldsetSummaries = {
attach: function (context) {
$('fieldset.metatags-form', context).drupalSetSummary(function (context) {
var vals = [];
$("input[type='text'], select, textarea", context).each(function() {
var input_field = $(this).attr('name');
// Verify the field exists before proceeding.
if (input_field === undefined) {
return false;
}
var default_name = input_field.replace(/\[value\]/, '[default]');
var default_value = $("input[type='hidden'][name='" + default_name + "']", context);
if (default_value.length && default_value.val() === $(this).val()) {
// Meta tag has a default value and form value matches default value.
return true;
}
else if (!default_value.length && !$(this).val().length) {
// Meta tag has no default value and form value is empty.
return true;
}
var label = $("label[for='" + $(this).attr('id') + "']").text();
vals.push(Drupal.t('@label: @value', {
'@label': $.trim(label),
'@value': Drupal.truncate($(this).val(), 25) || Drupal.t('None')
}));
});
if (vals.length === 0) {
return Drupal.t('Using defaults');
}
else {
return vals.join('<br />');
}
});
}
};
/**
* Encode special characters in a plain-text string for display as HTML.
*/
Drupal.truncate = function (str, limit) {
if (str.length > limit) {
return str.substr(0, limit) + '...';
}
else {
return str;
}
};
})(jQuery);