mod-build 3.6.0 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "3.6.0",
3
+ "version": "3.6.1",
4
4
  "description": "Share components for S3 sites.",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1,122 +0,0 @@
1
- /* exported contactUs */
2
-
3
- var contactUs = {
4
- $form: $('.contact-us__form'),
5
- $thankyou: $('.contact-us__thankyou'),
6
- url: 'https://contact.formfetch.com/v2_submit',
7
- getFormData: function() {
8
- const date = new Date();
9
- const data = {};
10
- this.$form.serializeArray().forEach(function(input) {
11
- data[input.name] = input.value;
12
- });
13
-
14
- data.time = date.toLocaleTimeString();
15
- data.date = date.toLocaleDateString();
16
- return data;
17
- },
18
- validateData: function(data) {
19
- const _this = this;
20
- var isFormValid = true;
21
- const emailPattern = /^([\w\+-]+(?:\.[\w\+-]+)*)(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)/i;
22
-
23
- Object.keys(data).forEach(function(key) {
24
- var isValid = true;
25
- const value = data[key];
26
- switch (key) {
27
- case 'email':
28
- isValid = emailPattern.test(value);
29
- break;
30
- default:
31
- isValid = value !== '';
32
- break;
33
- }
34
-
35
- if (!isValid) {
36
- _this.markFieldAsInvalid(key);
37
- isFormValid = false;
38
- }
39
- });
40
-
41
- return isFormValid;
42
- },
43
- markFieldAsInvalid: function(fieldName) {
44
- this.$form.find('#' + fieldName).parent().addClass('has-error');
45
- },
46
- submit: function() {
47
- this.$form.addClass('form--loading');
48
-
49
- const _this = this;
50
- const data = this.getFormData();
51
- const isFormValid = this.validateData(data);
52
-
53
- if (isFormValid) {
54
- // Submit
55
- $.ajax({
56
- url: _this.url,
57
- dataType: 'json',
58
- type: 'post',
59
- crossDomain: true,
60
- data: data,
61
- success: function(response) {
62
- if (response.success) {
63
- _this.$form.hide();
64
- _this.$thankyou.show();
65
- } else {
66
- _this.$form.removeClass('form--loading');
67
- $('.step__error').html(response.message);
68
- }
69
- }
70
- });
71
- } else {
72
- _this.$form.removeClass('form--loading');
73
- }
74
- },
75
- changeStep: function(direction) {
76
- const $activeStep = this.$form.find('.step--active');
77
- const $nextStep = $activeStep.next();
78
- const $prevStep = $activeStep.prev();
79
-
80
- $activeStep.removeClass('step--active');
81
- if (direction === 'next') {
82
- $nextStep.addClass('step--active');
83
- } else {
84
- $prevStep.addClass('step--active');
85
- }
86
- },
87
- watch: function() {
88
- const _this = this;
89
-
90
- // Watch form submission
91
- _this.$form.on('submit', function(e) {
92
- e.preventDefault();
93
- if (!$(this).hasClass('form--loading')) {
94
- _this.submit();
95
- }
96
- });
97
-
98
- // Watch radio click
99
- $('input[type="radio"]').on('change', function() {
100
- _this.changeStep('next');
101
- });
102
-
103
- // Watch back button
104
- _this.$form.find('.btn-back').on('click', function() {
105
- _this.changeStep('prev');
106
- });
107
-
108
- // Remove error state when input/textarea changes
109
- _this.$form.find('input, textarea').on('change', function() {
110
- $(this).parent().removeClass('has-error');
111
- });
112
- },
113
- init: function() {
114
- this.watch();
115
- }
116
- };
117
-
118
- (function($) {
119
- $(document).ready(function() {
120
- contactUs.init();
121
- });
122
- })(jQuery);