PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 3.0.71
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v3.0.71
5.6.2 5.6.3 5.6.1 5.6.0 5.5.0 5.4.0 5.3.2 5.3.1 5.1.6 5.1.5 trunk 2.1.5 2.11 2.12 2.13 2.15 3.0.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.51 3.0.60 3.0.61 3.0.62 All 38 releases
double-opt-in / core / assets / toggle.js

toggle.js in Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification 3.0.71, at core/assets/toggle.js

81 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 if (typeof ToggleButton !== "function") {
2 /**
3 * Create the Toggle Button
4 * @param dom
5 * @constructor
6 */
7 function ToggleButton(dom, id) {
8 this.dom = dom;
9
10 this.setId = function(id){
11 this.id = 'f12-toggle-id-'+id;
12 this.id = this.id.replace(new RegExp('\\[', 'g'), '');
13 this.id = this.id.replace(new RegExp('\\]', 'g'), '');
14 }
15
16 this.setId(id);
17
18 this.init = function () {
19 var name = this.dom.attr('name');
20
21 var before = this.dom.attr('data-before');
22 var after = this.dom.attr('data-after');
23
24 this.dom.wrap('<div class="f12-toggle"></div>');
25 this.dom.parent().append('<button type="button" id="' + this.id + '" class="btn btn-toggle" data-before="' + before + '" data-after="' + after + '" data-switch-target="' + name + '" aria-pressed="false"><span class="handle"></span></button>');
26
27 if (parseInt(this.dom.val()) === 1) {
28 this.updateStatus(1);
29 }
30 };
31
32 this.updateStatus = function (value) {
33 this.dom.val(value);
34 this.dom.attr('value', value);
35
36 // Change button status
37 if (value === 1) {
38 this.dom.parent().find('button').addClass('active');
39 this.dom.parent().find('button').attr('aria-pressed', 'true');
40 } else {
41 this.dom.parent().find('button').removeClass('active');
42 this.dom.parent().find('button').attr('aria-pressed', 'false')
43 }
44 }
45
46 this.onClick = function (target) {
47 var targetObject = 'input[name="' + target + '"]';
48 var value = parseInt(jQuery(document).find(targetObject).val());
49
50 if (value === 1) {
51 value = 0;
52 } else {
53 value = 1;
54 }
55
56 this.updateStatus(value);
57 }
58
59 this.addEventHandler = function () {
60 var c = this;
61 jQuery(document).on('click', '#' + this.id, function () {
62 c.onClick(jQuery(this).attr('data-switch-target'));
63 });
64 }
65
66 this.init();
67 this.addEventHandler();
68 }
69
70 jQuery.fn.f12Toggle = function () {
71
72 this.each(function () {
73 var name = jQuery(this).attr('name');
74 new ToggleButton(jQuery(this), name);
75 });
76 }
77
78 jQuery(document).ready(function () {
79 jQuery('input[type="hidden"].toggle').f12Toggle();
80 });
81 }