-
Notifications
You must be signed in to change notification settings - Fork 12
/
replace form submit button submitting text.html
95 lines (52 loc) · 2.72 KB
/
replace form submit button submitting text.html
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<script>
$( ( ) => {
/*
replace form submit button submitting text
License : < https://tinyurl.com/s872fb68 >
Version : 0.1d1
SS Versions : 7.1, 7.0
v7.0 Templates : Brine ( Aria, Blend, Burke, Cacao, Clay, Fairfield,
Feed, Foster, Greenwich, Hatch, Heights, Hunter, Hyde,
Impact, Jaunt, Juke, Keene, Kin, Lincoln, Maple, Margot,
Marta, Mentor, Mercer, Miller, Mojave, Moksha, Motto,
Nueva, Pedro, Pursuit, Rally, Rover, Royce, Sofia,
Sonora, Stella, Thorne, Vow, Wav, West )
your template is not listed? then it is not currently
supported
Dependencies : jQuery
twcsl
Note : SS often does text transforms on button text, enter the
replacement text as you would want it to appear, when SS
doesn't change it
By : Thomas Creedon < http://www.tomsWeb.consulting/ >
*/
const replacmentText = '[enter replacement submitting text here between single quotes]';
const nth = 1; // nth form on page
// do not change anything below, there be the borg here
// bail if no mutation observer available
if ( ! ( 'MutationObserver' in window ) ) return;
const $form = twcsl.getFormNth ( nth );
if ( $form === undefined ) return; // bail if no form
const element = $( 'input[type="submit"]', $form )
.get ( 0 );
const observer = new MutationObserver ( function ( mutations ) {
$.each ( mutations, function ( ) {
if ( this.type !== 'attributes' ) return; // bail if not attribute
if ( this.attributeName !== 'value' ) return; // bail if value attribute
// bail if field error
if ( $( '.field-error:first', $form ).length ) return;
const $element = $( this.target );
// bail if submit is hidden, indicates form was submitted
if ( $element.hasClass ( 'hidden' ) ) return;
const value = $element.val ( );
// bail if button text already set
if ( value == replacmentText ) return;
$element.val ( replacmentText );
} );
} );
// start listening for changes in specified element
observer.observe ( element, {
attributes : true
} );
} );
</script>