|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* JsCode.php |
|
5
|
|
|
* |
|
6
|
|
|
* The javascript codes generated by a Jaxon plugin. |
|
7
|
|
|
* |
|
8
|
|
|
* @package jaxon-core |
|
9
|
|
|
* @author Thierry Feuzeu <[email protected]> |
|
10
|
|
|
* @copyright 2025 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\Plugin; |
|
16
|
|
|
|
|
17
|
|
|
class JsCode |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @param string $sCode |
|
21
|
|
|
* @param string $sHtml |
|
22
|
|
|
* @param array $aUrls |
|
23
|
|
|
* @param string $sCodeBefore |
|
24
|
|
|
* @param string $sCodeAfter |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct(protected string $sCode = '', |
|
27
|
|
|
protected string $sHtml = '', protected array $aUrls = [], |
|
28
|
|
|
protected string $sCodeBefore = '', protected string $sCodeAfter = '') |
|
29
|
|
|
{} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Get the javascript files to include into the page |
|
33
|
|
|
* |
|
34
|
|
|
* Each entry can be a string or an array with "uri" and "options". |
|
35
|
|
|
* |
|
36
|
|
|
* @return array |
|
37
|
|
|
*/ |
|
38
|
|
|
public function urls(): array |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->aUrls; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get the javascript code to include into the page |
|
45
|
|
|
* |
|
46
|
|
|
* The code must NOT be enclosed in HTML tags. |
|
47
|
|
|
* |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
|
|
public function code(): string |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->sCode; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get the javascript code to include into the page |
|
57
|
|
|
* |
|
58
|
|
|
* The code must be enclosed in HTML tags. |
|
59
|
|
|
* |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
public function html(): string |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->sHtml; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get the javascript code to be inserted inline before the main code |
|
69
|
|
|
* |
|
70
|
|
|
* The code must NOT be enclosed in HTML tags. |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
public function before(): string |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->sCodeBefore; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get the javascript code to be inserted inline after the main code |
|
81
|
|
|
* |
|
82
|
|
|
* The code must NOT be enclosed in HTML tags. |
|
83
|
|
|
* |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
|
|
public function after(): string |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->sCodeAfter; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|