|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jaxon\Response\Plugin; |
|
4
|
|
|
|
|
5
|
|
|
use Jaxon\Response\Plugin\JQuery\Dom\Element; |
|
6
|
|
|
|
|
7
|
|
|
class JQuery extends \Jaxon\Plugin\Response |
|
8
|
|
|
{ |
|
9
|
|
|
use \Jaxon\Utils\Traits\Config; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Return the name of the plugin. |
|
13
|
|
|
* |
|
14
|
|
|
* @return string |
|
15
|
|
|
*/ |
|
16
|
|
|
public function getName() |
|
17
|
|
|
{ |
|
18
|
|
|
return 'jquery'; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Generate a unique hash for each version of the plugin. |
|
23
|
|
|
* |
|
24
|
|
|
* @return string |
|
25
|
|
|
*/ |
|
26
|
|
|
public function generateHash() |
|
27
|
|
|
{ |
|
28
|
|
|
// Use the version number as hash |
|
29
|
|
|
return '3.3.0'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Return init script for the Jaxon JQuery plugin. |
|
34
|
|
|
* |
|
35
|
|
|
* The init code registers the "jquery" handler with the Jaxon javascript library, |
|
36
|
|
|
* together with a function wich runs the javascript code generated by the plugin. |
|
37
|
|
|
* |
|
38
|
|
|
* @return void |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getScript() |
|
41
|
|
|
{ |
|
42
|
|
|
return ' |
|
43
|
|
|
jaxon.command.handler.register("jquery", function(args) { |
|
44
|
|
|
jaxon.cmd.script.execute(args); |
|
45
|
|
|
}); |
|
46
|
|
|
'; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Create a JQuery Element with a given selector, and link it to the current response. |
|
51
|
|
|
* |
|
52
|
|
|
* Since this element is linked to a response, its code will be automatically sent to the client. |
|
53
|
|
|
* The returned object can be used to call jQuery functions on the selected elements. |
|
54
|
|
|
* |
|
55
|
|
|
* @param string $sSelector The jQuery selector |
|
56
|
|
|
* @param string $sContext A context associated to the selector |
|
57
|
|
|
* |
|
58
|
|
|
* @return Element |
|
59
|
|
|
*/ |
|
60
|
|
|
public function element($sSelector = '', $sContext = '') |
|
61
|
|
|
{ |
|
62
|
|
|
$xElement = new Element($sSelector, $sContext); |
|
63
|
|
|
$this->addCommand(array('cmd' => 'jquery'), $xElement); |
|
64
|
|
|
return $xElement; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|