-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdonation-widget.js
112 lines (90 loc) · 3.32 KB
/
donation-widget.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
(function() {
function injectStyles() {
const style = document.createElement('style');
style.textContent = `
/* Widget Container */
.donate-widget-container {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 1000;
display: flex;
align-items: center;
justify-content: center;
}
.donate-widget {
background-color: #4285F4; /* Google Pay blue */
color: white;
padding: 15px 25px;
text-decoration: none;
border-radius: 30px;
font-size: 16px;
font-weight: bold;
font-family: 'Arial', sans-serif;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
transition: background-color 0.3s ease, transform 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
}
.donate-widget:hover {
background-color: #357AE8;
transform: translateY(-3px); /* Adds slight lift on hover */
}
.gpay-icon {
width: 30px;
height: auto;
margin-right: 10px;
}
/* Responsive Design */
@media (max-width: 768px) {
.donate-widget {
padding: 12px 20px;
font-size: 14px;
}
.gpay-icon {
width: 25px;
}
}
@media (max-width: 480px) {
.donate-widget {
padding: 10px 15px;
font-size: 13px;
border-radius: 20px;
}
.gpay-icon {
width: 20px;
}
}
`;
document.head.appendChild(style);
}
function createDonationWidget(upiId, amount, note) {
// Validate inputs
if (!upiId || !amount || isNaN(amount) || amount <= 0) {
console.error('Invalid UPI ID or amount.');
return;
}
injectStyles();
const container = document.createElement('div');
container.className = 'donate-widget-container';
const button = document.createElement('a');
button.href = `upi://pay?pa=${encodeURIComponent(upiId)}&pn=Donation&am=${encodeURIComponent(amount)}&cu=INR&tn=${encodeURIComponent(note)}`;
button.className = 'donate-widget';
button.id = 'donateButton';
// Add Google Pay icon
const icon = document.createElement('img');
icon.src = 'https://uxwing.com/wp-content/themes/uxwing/download/brands-and-social-media/google-pay-icon.png';
icon.alt = 'Google Pay';
icon.className = 'gpay-icon';
// Add text
button.textContent = `Support via Google Pay`;
// Append icon and text to button
button.appendChild(icon);
container.appendChild(button);
// Append container to the body
document.body.appendChild(container);
}
// Expose the function to the global scope
window.createDonationWidget = createDonationWidget;
})();