Chris@0
|
1 /**
|
Chris@0
|
2 * DO NOT EDIT THIS FILE.
|
Chris@0
|
3 * See the following change record for more information,
|
Chris@0
|
4 * https://www.drupal.org/node/2815083
|
Chris@0
|
5 * @preserve
|
Chris@0
|
6 **/
|
Chris@0
|
7
|
Chris@0
|
8 (function ($, Drupal, debounce) {
|
Chris@0
|
9 $.fn.drupalGetSummary = function () {
|
Chris@0
|
10 var callback = this.data('summaryCallback');
|
Chris@0
|
11 return this[0] && callback ? $.trim(callback(this[0])) : '';
|
Chris@0
|
12 };
|
Chris@0
|
13
|
Chris@0
|
14 $.fn.drupalSetSummary = function (callback) {
|
Chris@0
|
15 var self = this;
|
Chris@0
|
16
|
Chris@0
|
17 if (typeof callback !== 'function') {
|
Chris@0
|
18 var val = callback;
|
Chris@0
|
19 callback = function callback() {
|
Chris@0
|
20 return val;
|
Chris@0
|
21 };
|
Chris@0
|
22 }
|
Chris@0
|
23
|
Chris@0
|
24 return this.data('summaryCallback', callback).off('formUpdated.summary').on('formUpdated.summary', function () {
|
Chris@0
|
25 self.trigger('summaryUpdated');
|
Chris@0
|
26 }).trigger('summaryUpdated');
|
Chris@0
|
27 };
|
Chris@0
|
28
|
Chris@0
|
29 Drupal.behaviors.formSingleSubmit = {
|
Chris@0
|
30 attach: function attach() {
|
Chris@0
|
31 function onFormSubmit(e) {
|
Chris@0
|
32 var $form = $(e.currentTarget);
|
Chris@0
|
33 var formValues = $form.serialize();
|
Chris@0
|
34 var previousValues = $form.attr('data-drupal-form-submit-last');
|
Chris@0
|
35 if (previousValues === formValues) {
|
Chris@0
|
36 e.preventDefault();
|
Chris@0
|
37 } else {
|
Chris@0
|
38 $form.attr('data-drupal-form-submit-last', formValues);
|
Chris@0
|
39 }
|
Chris@0
|
40 }
|
Chris@0
|
41
|
Chris@0
|
42 $('body').once('form-single-submit').on('submit.singleSubmit', 'form:not([method~="GET"])', onFormSubmit);
|
Chris@0
|
43 }
|
Chris@0
|
44 };
|
Chris@0
|
45
|
Chris@0
|
46 function triggerFormUpdated(element) {
|
Chris@0
|
47 $(element).trigger('formUpdated');
|
Chris@0
|
48 }
|
Chris@0
|
49
|
Chris@0
|
50 function fieldsList(form) {
|
Chris@0
|
51 var $fieldList = $(form).find('[name]').map(function (index, element) {
|
Chris@0
|
52 return element.getAttribute('id');
|
Chris@0
|
53 });
|
Chris@0
|
54
|
Chris@0
|
55 return $.makeArray($fieldList);
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@0
|
58 Drupal.behaviors.formUpdated = {
|
Chris@0
|
59 attach: function attach(context) {
|
Chris@0
|
60 var $context = $(context);
|
Chris@0
|
61 var contextIsForm = $context.is('form');
|
Chris@0
|
62 var $forms = (contextIsForm ? $context : $context.find('form')).once('form-updated');
|
Chris@0
|
63 var formFields = void 0;
|
Chris@0
|
64
|
Chris@0
|
65 if ($forms.length) {
|
Chris@0
|
66 $.makeArray($forms).forEach(function (form) {
|
Chris@0
|
67 var events = 'change.formUpdated input.formUpdated ';
|
Chris@0
|
68 var eventHandler = debounce(function (event) {
|
Chris@0
|
69 triggerFormUpdated(event.target);
|
Chris@0
|
70 }, 300);
|
Chris@0
|
71 formFields = fieldsList(form).join(',');
|
Chris@0
|
72
|
Chris@0
|
73 form.setAttribute('data-drupal-form-fields', formFields);
|
Chris@0
|
74 $(form).on(events, eventHandler);
|
Chris@0
|
75 });
|
Chris@0
|
76 }
|
Chris@0
|
77
|
Chris@0
|
78 if (contextIsForm) {
|
Chris@0
|
79 formFields = fieldsList(context).join(',');
|
Chris@0
|
80
|
Chris@0
|
81 var currentFields = $(context).attr('data-drupal-form-fields');
|
Chris@0
|
82
|
Chris@0
|
83 if (formFields !== currentFields) {
|
Chris@0
|
84 triggerFormUpdated(context);
|
Chris@0
|
85 }
|
Chris@0
|
86 }
|
Chris@0
|
87 },
|
Chris@0
|
88 detach: function detach(context, settings, trigger) {
|
Chris@0
|
89 var $context = $(context);
|
Chris@0
|
90 var contextIsForm = $context.is('form');
|
Chris@0
|
91 if (trigger === 'unload') {
|
Chris@0
|
92 var $forms = (contextIsForm ? $context : $context.find('form')).removeOnce('form-updated');
|
Chris@0
|
93 if ($forms.length) {
|
Chris@0
|
94 $.makeArray($forms).forEach(function (form) {
|
Chris@0
|
95 form.removeAttribute('data-drupal-form-fields');
|
Chris@0
|
96 $(form).off('.formUpdated');
|
Chris@0
|
97 });
|
Chris@0
|
98 }
|
Chris@0
|
99 }
|
Chris@0
|
100 }
|
Chris@0
|
101 };
|
Chris@0
|
102
|
Chris@0
|
103 Drupal.behaviors.fillUserInfoFromBrowser = {
|
Chris@0
|
104 attach: function attach(context, settings) {
|
Chris@0
|
105 var userInfo = ['name', 'mail', 'homepage'];
|
Chris@0
|
106 var $forms = $('[data-user-info-from-browser]').once('user-info-from-browser');
|
Chris@0
|
107 if ($forms.length) {
|
Chris@14
|
108 userInfo.forEach(function (info) {
|
Chris@0
|
109 var $element = $forms.find('[name=' + info + ']');
|
Chris@0
|
110 var browserData = localStorage.getItem('Drupal.visitor.' + info);
|
Chris@0
|
111 var emptyOrDefault = $element.val() === '' || $element.attr('data-drupal-default-value') === $element.val();
|
Chris@0
|
112 if ($element.length && emptyOrDefault && browserData) {
|
Chris@0
|
113 $element.val(browserData);
|
Chris@0
|
114 }
|
Chris@0
|
115 });
|
Chris@0
|
116 }
|
Chris@0
|
117 $forms.on('submit', function () {
|
Chris@14
|
118 userInfo.forEach(function (info) {
|
Chris@0
|
119 var $element = $forms.find('[name=' + info + ']');
|
Chris@0
|
120 if ($element.length) {
|
Chris@0
|
121 localStorage.setItem('Drupal.visitor.' + info, $element.val());
|
Chris@0
|
122 }
|
Chris@0
|
123 });
|
Chris@0
|
124 });
|
Chris@0
|
125 }
|
Chris@0
|
126 };
|
Chris@0
|
127
|
Chris@0
|
128 var handleFragmentLinkClickOrHashChange = function handleFragmentLinkClickOrHashChange(e) {
|
Chris@0
|
129 var url = void 0;
|
Chris@0
|
130 if (e.type === 'click') {
|
Chris@0
|
131 url = e.currentTarget.location ? e.currentTarget.location : e.currentTarget;
|
Chris@0
|
132 } else {
|
Chris@17
|
133 url = window.location;
|
Chris@0
|
134 }
|
Chris@0
|
135 var hash = url.hash.substr(1);
|
Chris@0
|
136 if (hash) {
|
Chris@0
|
137 var $target = $('#' + hash);
|
Chris@0
|
138 $('body').trigger('formFragmentLinkClickOrHashChange', [$target]);
|
Chris@0
|
139
|
Chris@0
|
140 setTimeout(function () {
|
Chris@0
|
141 return $target.trigger('focus');
|
Chris@0
|
142 }, 300);
|
Chris@0
|
143 }
|
Chris@0
|
144 };
|
Chris@0
|
145
|
Chris@0
|
146 var debouncedHandleFragmentLinkClickOrHashChange = debounce(handleFragmentLinkClickOrHashChange, 300, true);
|
Chris@0
|
147
|
Chris@0
|
148 $(window).on('hashchange.form-fragment', debouncedHandleFragmentLinkClickOrHashChange);
|
Chris@0
|
149
|
Chris@0
|
150 $(document).on('click.form-fragment', 'a[href*="#"]', debouncedHandleFragmentLinkClickOrHashChange);
|
Chris@0
|
151 })(jQuery, Drupal, Drupal.debounce); |