Completed
Push — master ( 5b3cfe...9166d3 )
by Thierry
06:16 queued 04:30
created

Plugin::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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