| 1 |
<?php |
| 2 |
|
| 3 |
namespace AgeGate\Presentation; |
| 4 |
|
| 5 |
use AgeGate\Common\Settings; |
| 6 |
|
| 7 |
class FocusTrap |
| 8 |
{ |
| 9 |
public function __construct() |
| 10 |
{ |
| 11 |
add_action('wp_enqueue_scripts', [$this, 'assets'], 1); |
| 12 |
} |
| 13 |
|
| 14 |
public function assets() |
| 15 |
{ |
| 16 |
$settings = Settings::getInstance(); |
| 17 |
$path = sprintf('%s%s%s', AGE_GATE_URL, 'dist', ($settings->rawAssets ? '/raw' : '')); |
| 18 |
wp_enqueue_script('age-gate-focus', $path . '/focus.js', [], AGE_GATE_VERSION, !$settings->inHeader); |
| 19 |
|
| 20 |
$elements = [ |
| 21 |
'.age-gate', |
| 22 |
]; |
| 23 |
|
| 24 |
if (is_admin_bar_showing()) { |
| 25 |
$elements[] = '#wpadminbar'; |
| 26 |
} |
| 27 |
|
| 28 |
if ($settings->inputType === 'buttons') { |
| 29 |
$focused = null; |
| 30 |
} elseif ($settings->stepped) { |
| 31 |
$focused = 'age_gate[y]'; |
| 32 |
} else { |
| 33 |
$focused = sprintf('age_gate[%s]', strtolower($settings->dateFormat[0] ?? 'd')); |
| 34 |
} |
| 35 |
|
| 36 |
wp_localize_script('age-gate-focus', 'agfocus', [ |
| 37 |
'focus' => $focused, |
| 38 |
'elements' => array_merge( |
| 39 |
apply_filters('age_gate/trap_focus/elements', []), |
| 40 |
$elements |
| 41 |
) |
| 42 |
]); |
| 43 |
} |
| 44 |
} |
| 45 |
|