|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
3
|
|
|
namespace Jaxon\Plugin\Response\JQuery; |
|
4
|
|
|
|
|
5
|
|
|
use Jaxon\Plugin\ResponsePlugin; |
|
6
|
|
|
|
|
7
|
|
|
class JQueryPlugin extends ResponsePlugin |
|
|
|
|
|
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @const The plugin name |
|
11
|
|
|
*/ |
|
12
|
|
|
const NAME = 'jquery'; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $jQueryNs; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* True if the next selector is a command |
|
21
|
|
|
* |
|
22
|
|
|
* @var bool |
|
|
|
|
|
|
23
|
|
|
*/ |
|
24
|
|
|
protected $bCommand = true; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The class constructor |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $jQueryNs |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(string $jQueryNs) |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
$this->jQueryNs = $jQueryNs; |
|
34
|
|
|
} |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param bool $bCommand |
|
|
|
|
|
|
38
|
|
|
* |
|
39
|
|
|
* @return JQueryPlugin |
|
40
|
|
|
*/ |
|
41
|
|
|
public function command(bool $bCommand): JQueryPlugin |
|
42
|
|
|
{ |
|
43
|
|
|
$this->bCommand = $bCommand; |
|
44
|
|
|
return $this; |
|
45
|
|
|
} |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @inheritDoc |
|
49
|
|
|
*/ |
|
|
|
|
|
|
50
|
|
|
public function getName(): string |
|
51
|
|
|
{ |
|
52
|
|
|
return self::NAME; |
|
53
|
|
|
} |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @inheritDoc |
|
57
|
|
|
*/ |
|
|
|
|
|
|
58
|
|
|
public function getHash(): string |
|
59
|
|
|
{ |
|
60
|
|
|
// Use the version number as hash |
|
61
|
|
|
return '4.0.0'; |
|
62
|
|
|
} |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @inheritDoc |
|
66
|
|
|
*/ |
|
|
|
|
|
|
67
|
|
|
public function getReadyScript(): string |
|
68
|
|
|
{ |
|
69
|
|
|
return ' |
|
70
|
|
|
jaxon.command.handler.register("jquery", function(args) { |
|
71
|
|
|
jaxon.cmd.script.execute(args); |
|
72
|
|
|
}); |
|
73
|
|
|
'; |
|
74
|
|
|
} |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Create a JQueryPlugin DomSelector, and link it to the current response. |
|
78
|
|
|
* |
|
79
|
|
|
* Since this element is linked to a response, its code will be automatically sent to the client. |
|
80
|
|
|
* The returned object can be used to call jQuery functions on the selected elements. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $sPath The jQuery selector path |
|
83
|
|
|
* @param string $sContext A context associated to the selector |
|
|
|
|
|
|
84
|
|
|
* |
|
85
|
|
|
* @return DomSelector |
|
86
|
|
|
*/ |
|
87
|
|
|
public function selector(string $sPath = '', string $sContext = ''): DomSelector |
|
88
|
|
|
{ |
|
89
|
|
|
$xSelector = new DomSelector($this->jQueryNs, $sPath, $sContext); |
|
90
|
|
|
if($this->bCommand && $this->response() !== null) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->addCommand(['cmd' => 'jquery'], $xSelector); |
|
93
|
|
|
} |
|
94
|
|
|
// Reset the command value. |
|
95
|
|
|
$this->bCommand = true; |
|
96
|
|
|
return $xSelector; |
|
97
|
|
|
} |
|
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|