-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3838a8
commit a6972be
Showing
8 changed files
with
218 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function SetDefaultValues_gift_aid(field) { | ||
field.label = 'GiftAid'; | ||
field.checkboxLabel = 'Yes, please claim GiftAid'; | ||
field.descriptionPlaceholder = 'Enter additional description text here.'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
function gfGiftAidOnInputChange(elem) { | ||
if ( | ||
!(elem instanceof HTMLElement) || | ||
!elem.classList.contains('ginput_amount') | ||
) { | ||
return; | ||
} | ||
|
||
const parentForm = elem.closest('form'); | ||
if (!(parentForm instanceof HTMLFormElement)) { | ||
return; | ||
} | ||
|
||
const spanTotal = parentForm.querySelectorAll('.gform_donation_total'); | ||
if (!(spanTotal instanceof NodeList) || 0 === spanTotal.length) { | ||
return; | ||
} | ||
|
||
const spanTotalGift = parentForm.querySelectorAll( | ||
'.gform_donation_gifttotal', | ||
); | ||
if (!(spanTotalGift instanceof NodeList) || 0 === spanTotalGift.length) { | ||
return; | ||
} | ||
|
||
const extractFloat = (str) => { | ||
// Regular expression to match floating-point numbers | ||
const regex = /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/g; | ||
|
||
// Use match() to find all matching numbers in the string | ||
const matches = str.match(regex); | ||
|
||
// If there are matches, convert them to floats and return them; otherwise, return the original str. | ||
return matches ? matches.map(Number) : str; | ||
}; | ||
|
||
const val = extractFloat(elem.value); | ||
const total = parseFloat(val).toFixed(2); | ||
const totalGift = parseFloat(val * 1.25).toFixed(2); | ||
|
||
Array.from(spanTotal).forEach((item) => { | ||
item.innerHTML = total; | ||
}); | ||
|
||
Array.from(spanTotalGift).forEach((item) => { | ||
item.innerHTML = totalGift; | ||
}); | ||
} | ||
document.addEventListener('DOMContentLoaded', () => { | ||
window.gform.addAction('gform_input_change', gfGiftAidOnInputChange, 10); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Itineris\GfGiftaidField; | ||
|
||
use GF_Fields; | ||
use GFAddOn; | ||
|
||
class AddOn extends GFAddOn | ||
{ | ||
private static ?self $_instance = null; | ||
|
||
protected $_version = GfGiftAidField::VERSION; | ||
protected $_min_gravityforms_version = '2.7'; | ||
protected $_slug = 'gf-giftaid-field'; | ||
protected $_path = 'gf-giftaid-field/gf-giftaid-field.php'; | ||
protected $_full_path = __DIR__; | ||
protected $_title = 'GF GiftAid Field'; | ||
protected $_short_title = 'GF GiftAid Field'; | ||
protected $_url = 'https://github.com/ItinerisLtd/gf-giftaid-field'; | ||
|
||
public static function get_instance(): self | ||
{ | ||
if (! self::$_instance instanceof self) { | ||
self::$_instance = new self(); | ||
} | ||
|
||
return self::$_instance; | ||
} | ||
|
||
public function pre_init(): void | ||
{ | ||
parent::pre_init(); | ||
|
||
if ($this->is_gravityforms_supported() && class_exists('GF_Field')) { | ||
GF_Fields::register(new GiftAidField()); | ||
} | ||
} | ||
|
||
public function scripts(): array | ||
{ | ||
return [ | ||
...parent::scripts(), | ||
[ | ||
'handle' => "{$this->_slug}-frontend", | ||
'src' => $this->get_base_url() . '/public/js/gf-giftaid-frontend.js', | ||
'version' => $this->_version, | ||
'deps' => [], | ||
'in_footer' => true, | ||
'enqueue' => [ | ||
'callback' => fn (): bool => ! is_admin(), | ||
], | ||
], | ||
[ | ||
'handle' => "{$this->_slug}-admin", | ||
'src' => $this->get_base_url() . '/public/js/gf-giftaid-admin.js', | ||
'version' => $this->_version, | ||
'deps' => [], | ||
'in_footer' => true, | ||
'enqueue' => [ | ||
[ | ||
'admin_page' => ['form_editor'], | ||
], | ||
], | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters