You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.2 KiB
68 lines
2.2 KiB
<?php
|
|
|
|
namespace Zoomyboy\Stepper;
|
|
|
|
use Twig\Loader\FilesystemLoader;
|
|
use Twig\Environment;
|
|
use Twig\TwigFilter as Filter;
|
|
use Twig\TwigFunction as Func;
|
|
|
|
class Stepper {
|
|
|
|
private $twig;
|
|
public $url;
|
|
|
|
public function __construct() {
|
|
$loader = new FilesystemLoader(__DIR__.'/../views');
|
|
|
|
$this->twig = new Environment($loader);
|
|
|
|
$this->twig->addFilter(new Filter('svg', [$this, 'svgTag']));
|
|
$this->twig->addFilter(new Filter('prop', [$this, 'alpineProp']));
|
|
$this->twig->addFunction(new Func('cprop', function ($aprop, $modifier) {
|
|
return $this->alpineProp($aprop, $modifier);
|
|
}));
|
|
}
|
|
|
|
public function init() {
|
|
add_action('wp_enqueue_scripts', [ $this, 'enqueue' ]);
|
|
add_action('wp_ajax_nopriv_stepper_submit', [ $this, 'onSubmit' ]);
|
|
add_shortcode('stepper', [ $this, 'handle' ]);
|
|
}
|
|
|
|
public function enqueue() {
|
|
wp_enqueue_script('stepper-js', $this->url.'assets/public/app.js');
|
|
wp_enqueue_style('stepper-css', $this->url.'assets/public/app.css');
|
|
}
|
|
|
|
public function handle() {
|
|
echo $this->twig->render('stepper.twig.htm', [
|
|
'sprite' => $this->url.'assets/public/sprite.svg'
|
|
]);
|
|
}
|
|
|
|
public function svgTag($e, $class = '') {
|
|
return '<svg class="'.$class.'"><use xlink:href="'.$sprite.'#'.$e.'"></use></svg>';
|
|
}
|
|
|
|
public function alpineProp($prop, $modifier) {
|
|
$v = '$event.target.value';
|
|
$bv = '($event.target || $event.originalTarget).value';
|
|
|
|
return ':value="units.'.$modifier.'.to('.$prop.')"
|
|
@focus="$event.target.value = '.$prop.'"
|
|
@blur="console.log($event); '.$bv.' = units.'.$modifier.'.to('.$prop.');"
|
|
@change="console.log(\'change\'); '.$prop.' = units.'.$modifier.'.from('.$v.');"
|
|
onblur="console.log(\'RRRR\');"';
|
|
}
|
|
|
|
public function onSubmit() {
|
|
json_decode(file_get_contents('php://input'));
|
|
wp_mail('info@jonas-ruettgers.de', 'Neue Finanzierungs-Anfrage', $this->twig->render('mail.twig.htm', json_decode(file_get_contents('php://input'), true)), [
|
|
'From' => 'philipp@aweos.de'
|
|
]);
|
|
|
|
die();
|
|
}
|
|
|
|
}
|