Commit 2504bce4 authored by gbyte.co's avatar gbyte.co

Adding some js to forms including automatic hiding/showing fields and vertical tab summaries.

parent 6dd60103
/**
* @file
* Attaches simplesitemap behaviors to the entity form.
*/
(function($) {
"use strict";
Drupal.behaviors.simplesitemapFieldsetSummaries = {
attach: function(context) {
$(context).find('#edit-simplesitemap').drupalSetSummary(function (context) {
var vals = [];
if ($(context).find('#edit-simplesitemap-index-content').is(':checked')) {
// Display summary of the settings in tabs.
vals.push(Drupal.t('Included in sitemap'));
vals.push(Drupal.t('Priority') + ' ' + $('#edit-simplesitemap-priority option:selected', context).text());
}
else {
// Display summary of the settings in tabs.
vals.push(Drupal.t('Excluded from sitemap'));
}
return vals.join('<br />');
});
}
};
})(jQuery);
/**
* @file
* Attaches simplesitemap behaviors to the entity form.
*/
(function($) {
"use strict";
// Hide the 'Regenerate sitemap' field to only display it if settings have changed.
$('.form-item-simplesitemap-regenerate-now').hide();
Drupal.behaviors.simplesitemapForm = {
attach: function(context) {
$(context).find('#edit-simplesitemap').drupalSetSummary(function (context) {
if ($(context).find('#edit-simplesitemap-index-content').is(':checked')) {
// Show 'Priority' field if 'Index sitemap' is ticked.
$('.form-item-simplesitemap-priority').show();
}
else { // Hide 'Priority' field if 'Index sitemap' is unticked.
$('.form-item-simplesitemap-priority').hide();
}
// Show 'Regenerate sitemap' field if setting has changed.
$( "#edit-simplesitemap-index-content" ).change(function() {
$('.form-item-simplesitemap-regenerate-now').show();
});
// Show 'Regenerate sitemap' field if setting has changed.
$( "#edit-simplesitemap-priority" ).change(function() {
$('.form-item-simplesitemap-regenerate-now').show();
});
})
}
};
})(jQuery);
fieldsetSummaries:
version: VERSION
js:
js/simplesitemap.fieldsetSummaries.js: {}
dependencies:
- core/jquery
form:
version: VERSION
js:
js/simplesitemap.form.js: {}
dependencies:
- core/jquery
......@@ -24,12 +24,21 @@ function simplesitemap_form_alter(&$form, $form_state, $form_id) {
// Get current entity type sitemap settings.
$entity_types = $sitemap->get_config('entity_types');
$form['simplesitemap'] = array(
'#type' => 'details',
'#group' => 'additional_settings',
'#title' => t('Simple XML sitemap'),
'#type' => 'details'
);
// Attach some js magic to forms.
// Only attach fieldset summary js to 'additional settings' vertical tabs.
$form['simplesitemap']['#attached']['library'][] = 'simplesitemap/form';
if (isset($form['additional_settings'])) {
$form['simplesitemap']['#attached']['library'][] = 'simplesitemap/fieldsetSummaries';
}
$index_content_checked = isset($entity_types[$entity_type_id][$bundle_name]['index']) ? $entity_types[$entity_type_id][$bundle_name]['index'] : FALSE;
$form['simplesitemap']['simplesitemap_index_content'] = array(
'#type' => 'checkbox',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment