Commit 4b02c50e authored by WalkingDexter's avatar WalkingDexter Committed by atymchuk

Improved JavaScript files.

parent c490bf5c
/**
* @file
* Attaches simple_sitemap behaviors to the sitemap views form.
*/
(function ($, Drupal) {
Drupal.simpleSitemapSitemapViews = {};
Drupal.behaviors.simpleSitemapSitemapViewsForm = {
attach: function attach() {
var $form = $('[data-drupal-selector="simple-sitemap-views-form"]').once('simple-sitemap-sitemap-views-form');
if ($form.length) {
new Drupal.simpleSitemapSitemapViews.Form($form);
}
}
};
Drupal.simpleSitemapSitemapViews.Form = function ($form) {
this.$form = $form;
this.$enabled = $form.find('[data-drupal-selector="edit-enabled"]');
this.$details = $form.find('[data-drupal-selector="edit-indexed-displays"]');
this.$warning = $form.find('[data-drupal-selector="edit-warning"]');
this.$regenerate = $form.find('.form-item-simple-sitemap-regenerate-now');
this.$enabled.on('change', $.proxy(this, 'changeHandler'));
this.updateElementsDisplay();
this.$regenerate.hide();
};
Drupal.simpleSitemapSitemapViews.Form.prototype.changeHandler = function () {
this.updateElementsDisplay();
this.$regenerate.show();
};
Drupal.simpleSitemapSitemapViews.Form.prototype.updateElementsDisplay = function () {
if (this.$enabled.prop('checked')) {
this.$details.show();
this.$warning.hide();
}
else {
this.$details.hide();
this.$warning.show();
}
};
})(jQuery, Drupal);
\ No newline at end of file
......@@ -4,54 +4,54 @@
*/
(function ($, Drupal) {
Drupal.simpleSitemapViews = {};
Drupal.simpleSitemapViewsUi = {};
Drupal.behaviors.simpleSitemapViewsCheckboxify = {
attach: function attach(context, settings) {
var $button = $('[data-drupal-selector="edit-index-button"]').once('simple-sitemap-views-checkboxify');
Drupal.behaviors.simpleSitemapViewsUiCheckboxify = {
attach: function attach() {
var $button = $('[data-drupal-selector="edit-index-button"]').once('simple-sitemap-views-ui-checkboxify');
if ($button.length) {
new Drupal.simpleSitemapViews.Checkboxifier($button[0]);
new Drupal.simpleSitemapViewsUi.Checkboxifier($button);
}
}
};
Drupal.behaviors.simpleSitemapViewsArguments = {
attach: function attach(context, settings) {
var $arguments = $('.indexed-arguments').once('simple-sitemap-views-arguments');
Drupal.behaviors.simpleSitemapViewsUiArguments = {
attach: function attach() {
var $arguments = $('.indexed-arguments').once('simple-sitemap-views-ui-arguments');
var $checkboxes = $arguments.find('input[type="checkbox"]');
if ($checkboxes.length) {
new Drupal.simpleSitemapViews.Arguments($checkboxes);
new Drupal.simpleSitemapViewsUi.Arguments($checkboxes);
}
}
};
Drupal.simpleSitemapViews.Checkboxifier = function (button) {
this.$button = $(button);
Drupal.simpleSitemapViewsUi.Checkboxifier = function ($button) {
this.$button = $button;
this.$parent = this.$button.parent('div.simple-sitemap-views-index');
this.$input = this.$parent.find('input:checkbox');
this.$button.hide();
this.$input.on('click', $.proxy(this, 'clickHandler'));
};
Drupal.simpleSitemapViews.Checkboxifier.prototype.clickHandler = function (e) {
Drupal.simpleSitemapViewsUi.Checkboxifier.prototype.clickHandler = function () {
this.$button.trigger('click').trigger('submit');
};
Drupal.simpleSitemapViews.Arguments = function ($checkboxes) {
Drupal.simpleSitemapViewsUi.Arguments = function ($checkboxes) {
this.$checkboxes = $checkboxes;
this.$checkboxes.on('change', $.proxy(this, 'changeHandler'));
};
Drupal.simpleSitemapViews.Arguments.prototype.changeHandler = function (e) {
Drupal.simpleSitemapViewsUi.Arguments.prototype.changeHandler = function (e) {
var $checkbox = $(e.target), index = this.$checkboxes.index($checkbox);
$checkbox.prop('checked') ? this.check(index) : this.uncheck(index);
};
Drupal.simpleSitemapViews.Arguments.prototype.check = function (index) {
Drupal.simpleSitemapViewsUi.Arguments.prototype.check = function (index) {
this.$checkboxes.slice(0, index).prop('checked', true);
};
Drupal.simpleSitemapViews.Arguments.prototype.uncheck = function (index) {
Drupal.simpleSitemapViewsUi.Arguments.prototype.uncheck = function (index) {
this.$checkboxes.slice(index).prop('checked', false);
};
......
views:
viewsUi:
version: VERSION
js:
js/simple_sitemap.views.js: {}
js/simple_sitemap.viewsUi.js: {}
dependencies:
- core/jquery
- core/drupal
- core/jquery.once
sitemapViews:
version: VERSION
js:
js/simple_sitemap.sitemapViews.js: {}
dependencies:
- core/jquery
- core/drupal
......
......@@ -80,7 +80,7 @@ class SimpleSitemapViewsForm extends SimplesitemapFormBase {
$indexable_views = $this->sitemapViews->getIndexableViews();
if (empty($indexable_views)) {
$form['simple_sitemap_views']['views']['info'] = [
$form['simple_sitemap_views']['views']['indexed_displays'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => $this->t('No displays are set to be indexed yet.'),
......@@ -120,14 +120,21 @@ class SimpleSitemapViewsForm extends SimplesitemapFormBase {
}
// Show information about indexed displays.
$form['simple_sitemap_views']['views']['info'] = [
$form['simple_sitemap_views']['views']['indexed_displays'] = [
'#type' => 'details',
'#title' => $this->t('Displays set to be indexed'),
'table' => $table,
];
// A warning message that is controlled by JavaScript.
$form['simple_sitemap_views']['views']['warning'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => $this->t('<strong>Warning:</strong> The views sitemap data will be deleted after hitting <em>Save</em>.'),
];
}
$this->formHelper->displayRegenerateNow($form['simple_sitemap_views']['views']);
$form['#attached']['library'][] = 'simple_sitemap_views/sitemapViews';
return parent::buildForm($form, $form_state);
}
......
......@@ -192,7 +192,7 @@ class SimpleSitemapDisplayExtender extends DisplayExtenderPluginBase {
}
// Attaching script to form.
$form['#attached']['library'][] = 'simple_sitemap_views/views';
$form['#attached']['library'][] = 'simple_sitemap_views/viewsUi';
}
}
......
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