JqCall::on()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * JqCall.php
5
 *
6
 * Call to a jquery selector.
7
 *
8
 * @package jaxon-core
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2024 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-core
13
 */
14
15
namespace Jaxon\Script;
16
17
use Jaxon\Plugin\Response\Dialog\DialogCommand;
18
use Jaxon\Script\Call\Selector;
19
use Closure;
20
21
class JqCall extends AbstractJsCall
22
{
23
    /**
24
     * The selector path
25
     *
26
     * @var string
27
     */
28
    protected $sSelector;
29
30
    /**
31
     * The selector context
32
     *
33
     * @var mixed
34
     */
35
    protected $xContext;
36
37
    /**
38
     * The constructor.
39
     *
40
     * @param DialogCommand $xDialog
41
     * @param Closure|null $xExprCb
42
     * @param string $sSelector    The jQuery selector path
43
     * @param mixed $xContext    A context associated to the selector
44
     */
45
    public function __construct(DialogCommand $xDialog, ?Closure $xExprCb,
46
        string $sSelector, $xContext = null)
47
    {
48
        parent::__construct($xDialog, $xExprCb);
49
        $this->sSelector = $sSelector;
50
        $this->xContext = $xContext;
51
    }
52
53
    /**
54
     * Get the json expression
55
     */
56
    protected function _expr(): JsExpr
57
    {
58
        return $this->_initExpr(new JsExpr($this->xDialog,
59
            new Selector('jq', $this->sSelector, $this->xContext)));
60
    }
61
62
    /**
63
     * Set an event handler on the first selected element
64
     *
65
     * @param string $sName
66
     * @param JsExpr $xHandler
67
     *
68
     * @return JsExpr
69
     */
70
    public function on(string $sName, JsExpr $xHandler): JsExpr
71
    {
72
        return $this->_expr()->on($sName, $xHandler);
73
    }
74
75
    /**
76
     * Set an "click" event handler on the first selected element
77
     *
78
     * @param JsExpr $xHandler
79
     *
80
     * @return JsExpr
81
     */
82
    public function click(JsExpr $xHandler): JsExpr
83
    {
84
        return $this->on('click', $xHandler);
85
    }
86
}
87