132 lines
4.8 KiB
JavaScript
132 lines
4.8 KiB
JavaScript
|
/**
|
||
|
* DO NOT EDIT THIS FILE.
|
||
|
* See the following change record for more information,
|
||
|
* https://www.drupal.org/node/2815083
|
||
|
* @preserve
|
||
|
**/
|
||
|
(function ($, Drupal, debounce) {
|
||
|
$.fn.drupalGetSummary = function () {
|
||
|
var callback = this.data('summaryCallback');
|
||
|
return this[0] && callback ? callback(this[0]).trim() : '';
|
||
|
};
|
||
|
$.fn.drupalSetSummary = function (callback) {
|
||
|
var self = this;
|
||
|
if (typeof callback !== 'function') {
|
||
|
var val = callback;
|
||
|
callback = function callback() {
|
||
|
return val;
|
||
|
};
|
||
|
}
|
||
|
return this.data('summaryCallback', callback).off('formUpdated.summary').on('formUpdated.summary', function () {
|
||
|
self.trigger('summaryUpdated');
|
||
|
}).trigger('summaryUpdated');
|
||
|
};
|
||
|
Drupal.behaviors.formSingleSubmit = {
|
||
|
attach: function attach() {
|
||
|
function onFormSubmit(e) {
|
||
|
var $form = $(e.currentTarget);
|
||
|
var formValues = $form.serialize();
|
||
|
var previousValues = $form.attr('data-drupal-form-submit-last');
|
||
|
if (previousValues === formValues) {
|
||
|
e.preventDefault();
|
||
|
} else {
|
||
|
$form.attr('data-drupal-form-submit-last', formValues);
|
||
|
}
|
||
|
}
|
||
|
$(once('form-single-submit', 'body')).on('submit.singleSubmit', 'form:not([method~="GET"])', onFormSubmit);
|
||
|
}
|
||
|
};
|
||
|
function triggerFormUpdated(element) {
|
||
|
$(element).trigger('formUpdated');
|
||
|
}
|
||
|
function fieldsList(form) {
|
||
|
return [].map.call(form.querySelectorAll('[name][id]'), function (el) {
|
||
|
return el.id;
|
||
|
});
|
||
|
}
|
||
|
Drupal.behaviors.formUpdated = {
|
||
|
attach: function attach(context) {
|
||
|
var $context = $(context);
|
||
|
var contextIsForm = $context.is('form');
|
||
|
var $forms = $(once('form-updated', contextIsForm ? $context : $context.find('form')));
|
||
|
var formFields;
|
||
|
if ($forms.length) {
|
||
|
$.makeArray($forms).forEach(function (form) {
|
||
|
var events = 'change.formUpdated input.formUpdated ';
|
||
|
var eventHandler = debounce(function (event) {
|
||
|
triggerFormUpdated(event.target);
|
||
|
}, 300);
|
||
|
formFields = fieldsList(form).join(',');
|
||
|
form.setAttribute('data-drupal-form-fields', formFields);
|
||
|
$(form).on(events, eventHandler);
|
||
|
});
|
||
|
}
|
||
|
if (contextIsForm) {
|
||
|
formFields = fieldsList(context).join(',');
|
||
|
var currentFields = $(context).attr('data-drupal-form-fields');
|
||
|
if (formFields !== currentFields) {
|
||
|
triggerFormUpdated(context);
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
detach: function detach(context, settings, trigger) {
|
||
|
var $context = $(context);
|
||
|
var contextIsForm = $context.is('form');
|
||
|
if (trigger === 'unload') {
|
||
|
once.remove('form-updated', contextIsForm ? $context : $context.find('form')).forEach(function (form) {
|
||
|
form.removeAttribute('data-drupal-form-fields');
|
||
|
$(form).off('.formUpdated');
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
Drupal.behaviors.fillUserInfoFromBrowser = {
|
||
|
attach: function attach(context, settings) {
|
||
|
var userInfo = ['name', 'mail', 'homepage'];
|
||
|
var $forms = $(once('user-info-from-browser', '[data-user-info-from-browser]'));
|
||
|
if ($forms.length) {
|
||
|
userInfo.forEach(function (info) {
|
||
|
var $element = $forms.find("[name=".concat(info, "]"));
|
||
|
var browserData = localStorage.getItem("Drupal.visitor.".concat(info));
|
||
|
if (!$element.length) {
|
||
|
return;
|
||
|
}
|
||
|
var emptyValue = $element[0].value === '';
|
||
|
var defaultValue = $element.attr('data-drupal-default-value') === $element[0].value;
|
||
|
if (browserData && (emptyValue || defaultValue)) {
|
||
|
$element.each(function (index, item) {
|
||
|
item.value = browserData;
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
$forms.on('submit', function () {
|
||
|
userInfo.forEach(function (info) {
|
||
|
var $element = $forms.find("[name=".concat(info, "]"));
|
||
|
if ($element.length) {
|
||
|
localStorage.setItem("Drupal.visitor.".concat(info), $element[0].value);
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
var handleFragmentLinkClickOrHashChange = function handleFragmentLinkClickOrHashChange(e) {
|
||
|
var url;
|
||
|
if (e.type === 'click') {
|
||
|
url = e.currentTarget.location ? e.currentTarget.location : e.currentTarget;
|
||
|
} else {
|
||
|
url = window.location;
|
||
|
}
|
||
|
var hash = url.hash.substr(1);
|
||
|
if (hash) {
|
||
|
var $target = $("#".concat(hash));
|
||
|
$('body').trigger('formFragmentLinkClickOrHashChange', [$target]);
|
||
|
setTimeout(function () {
|
||
|
return $target.trigger('focus');
|
||
|
}, 300);
|
||
|
}
|
||
|
};
|
||
|
var debouncedHandleFragmentLinkClickOrHashChange = debounce(handleFragmentLinkClickOrHashChange, 300, true);
|
||
|
$(window).on('hashchange.form-fragment', debouncedHandleFragmentLinkClickOrHashChange);
|
||
|
$(document).on('click.form-fragment', 'a[href*="#"]', debouncedHandleFragmentLinkClickOrHashChange);
|
||
|
})(jQuery, Drupal, Drupal.debounce);
|