nur-sery/nur_src/v/plugins/setqakPlugin.php

47 lines
1.2 KiB
PHP
Raw Normal View History

2023-12-03 22:10:18 +04:00
<?php
namespace nur\v\plugins;
use nur\v\BasePlugin;
use nur\v\js;
/**
* Class setqakPlugin: installer l'accesskey 'q' sur le premier élément de
* formulaire
*/
class setqakPlugin extends BasePlugin {
const HAVE_JQUERY = true;
function __construct(?string $selector=null, ?bool $cond=null, ?string $accesskey=null) {
if ($selector === null) $selector = "input:text, textarea, select";
if ($cond === null) $cond = $selector? true: false;
if ($accesskey === null) $accesskey = "q";
$this->selector = $selector;
$this->cond = $cond;
$this->accesskey = $accesskey;
}
/**
* @var string sélecteur pour le composant concerné. par défaut, prendre le
* premier élément de formulaire de type text, textarea ou select
*/
private $selector;
/** @var bool ce plugin est-il activé? */
private $cond;
/** @var string acceskey à installer */
private $accesskey;
function printJquery(): void {
if (!$this->cond) return;
$ak = $this->accesskey;
?>
var $elems = $(<?=js::qv($this->selector)?>);
var $qelems = $elems.filter("[accesskey=<?=js::sqv($ak)?>]");
if ($qelems.length == 0) {
$elems.filter(":first").attr("accesskey", <?=js::qv($ak)?>);
}
<?php
}
}