-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsubmit-button.js
73 lines (64 loc) · 1.51 KB
/
submit-button.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
import _ from 'underscore';
/**
* @class SubmitButton
*/
class SubmitButton {
/**
* Sets up stuff.
* @abstract
* @param {Object} options - Instantiation options
*/
constructor (options) {
options = _.extend({
el: null,
disabledClass: 'disabled',
onClick: null
}, options);
this.options = options;
this._onClickEventListener = this.onClick.bind(this);
this.options.el.addEventListener('click', this._onClickEventListener);
}
/**
* When the submit button is clicked.
* @param e
*/
onClick (e) {
if (this.options.onClick) {
this.options.onClick(e);
}
}
/**
* Returns the submit button element
* @returns {HTMLElement} the submit button
* @abstract
*/
getSubmitButton () {
return this.options.el;
}
/**
* Enables the form element.
* @abstract
*/
enable () {
var btn = this.getSubmitButton();
btn.disabled = false;
btn.classList.remove(this.options.disabledClass);
}
/**
* Disables the form element.
* @abstract
*/
disable () {
var btn = this.getSubmitButton();
btn.disabled = true;
btn.classList.add(this.options.disabledClass);
}
/**
* Removes event listeners.
*/
destroy () {
this.options.el.removeEventListener('click', this._onClickEventListener);
}
}
module.exports = SubmitButton;