21 if (($this->params[
'csp'] ??
false) ===
'nonce' && ContentSecurityManager::isStarted()) {
22 $nonce = ContentSecurityManager::getNonce(
'jsUtils');
23 $str .=
' nonce="' . $nonce .
'" ';
25 $str .= ($src ==
'') ?
'>' :
' src="' . $src .
'">';
29 public function inline($script, $cdata =
true) {
30 if (($this->params[
'csp'] ??
false) ===
'hash' && ContentSecurityManager::isStarted()) {
31 $script = ($cdata) ?
"\n// <![CDATA[\n{$script}\n// ]]>\n" :
"\n{$script}\n";
32 ContentSecurityManager::getHash(
'jsUtils', $script);
42 $controls = $view->getVar(
"q");
43 if (isset($controls) ===
false) {
46 $controls[$identifier] = $content;
47 $view->setVar(
"q", $controls);
51 $view->setVar($view_var, $output);
54 public function forward($initialController, $controller, $action,
$params = array()) {
55 return $initialController->forward($controller, $action,
$params,
true,
true,
true);
59 return $initialControllerInstance->loadView($viewName,
$params,
true);
63 return Startup::$urlParts;
76 public function renderView($viewName, $parameters = [], $asString =
false) {
77 if (isset($this->injected)) {
78 $view = $this->injected->getView();
80 return $this->injected->loadView($viewName, $parameters, $asString);
82 throw new \Exception(get_class() .
" instance is not properly instancied : you omitted the second parameter \$controller!");
95 return $this->
renderView(
'@framework/main/component.html',[],$asString);
108 return $this->
renderView($this->injected->getDefaultViewName(), $parameters, $asString);
121 if (isset($this->injected)) {
122 $view = $this->injected->getView();
123 if (isset($parameters))
124 $view->setVars($parameters);
125 $js = $view->render($jsFile .
'.js',
true);
126 return $this->
exec($js, $immediatly);
128 throw new \Exception(get_class() .
" instance is not properly instancied : you omitted the second parameter \$controller!");
142 $jquery =
new JsUtils($options, $controller);
144 $jquery->setAjaxLoader(
"<div class=\"ui active centered inline text loader\">Loading</div>");
159 $jquery =
new JsUtils($options, $controller);
161 $jquery->setAjaxLoader(
"<div class=\"d-flex justify-content-center\"><div class=\"spinner-border\" role=\"status\"><span class=\"sr-only\">Loading...</span></div></div>");
184 if (URequest::isPost()) {
187 $value = $_POST[
'_value'];
188 $result[
'result'] = $callback($value);
189 echo \json_encode($result);
194 $this->
setParam(
'beforeCompileHtml',
function ($elm) {
195 if (\method_exists($elm,
'setInverted')) {
196 $elm->setInverted(
false);
fromDispatcher($dispatcher)
BaseHtml for HTML components.
createScriptVariable(&$view, $view_var, $output)
execJSFromFile($jsFile, $parameters=[], $immediatly=true)
Loads and eventually executes a jsFile with php parameters, using the default template engine...
renderComponent(BaseHtml $component, bool $asString=false)
Compile and render a component.
static diSemantic($controller, $options=[ 'defer'=> true, 'gc'=> true])
Returns an instance of JsUtils initialized with Semantic (for di injection)
static ajax(JsUtils $js, $name, $url, $params, $jsCallback, $method="post", $parameters=[])
renderView($viewName, $parameters=[], $asString=false)
Performs jQuery compilation and displays a view.
static diBootstrap($controller, $options=[ 'defer'=> true, 'gc'=> true])
Returns an instance of JsUtils initialized with Bootstrap (for di injection)
addViewElement($identifier, $content, &$view)
forward($initialController, $controller, $action, $params=array())
setParam(string $param, $value)
_close_script($extra="\)
Outputs an closing </script>
exec($js, $immediatly=false)
Executes the code $js.
checkValidationRule($callback)
Checks a validation rule declared with .
compile(&$view=NULL, $view_var='script_foot', $script_tags=TRUE)
gather together all script needing to be output
ajaxValidationRule(string $ruleName, string $checkUrl, string $params='{_value:value}', string $method='post')
Adds a new semantic validation ajax rule.
renderDefaultView($parameters=[], $asString=false)
Performs jQuery compilation and displays the default view.
_open_script($src='')
Outputs an opening <script>
renderContent($initialControllerInstance, $viewName, $params=NULL)