61 abstract public function getUrl($url);
71 abstract public function addViewElement($identifier, $content, &$view);
82 abstract public function createScriptVariable(&$view, $view_var, $output);
95 abstract public function forward($initialController, $controller, $action, $params);
106 abstract public function renderContent($initialControllerInstance, $viewName, $params = NULL);
127 $bs = $this->bootstrap();
142 if ($bootstrap !== NULL) {
143 $this->_bootstrap = $bootstrap;
144 $bootstrap->setJs($this);
150 return $this->_bootstrap;
160 if ($semantic !== NULL) {
161 $this->_semantic = $semantic;
162 $semantic->setJs($this);
168 return $this->_semantic;
177 if ($config === NULL) {
178 if ($this->config === NULL) {
181 } elseif (\is_array($config)) {
182 $this->config =
new Config($config);
183 } elseif ($config instanceof
Config) {
184 $this->config = $config;
186 return $this->config;
196 public function __construct($params = array(), $injected = NULL) {
198 'ajaxTransition' => null,
200 'historize' =>
false,
201 'jsCallback' => null,
203 'jqueryDone' =>
'html',
207 'jsCondition' => null,
208 'ajaxLoader' => null,
214 'ajax' => $ajaxDefault,
216 'autoActiveLinks' => true
218 foreach ($defaults as $key => $val) {
219 if (isset($params[$key]) ===
false || $params[$key] ===
"") {
220 $params[$key] = $defaults[$key];
223 foreach ($ajaxDefault as $key => $val) {
224 if (isset($params[
"ajax"][$key]) ===
false || $params[
"ajax"][$key] ===
"") {
225 $params[
"ajax"][$key] = $ajaxDefault[$key];
229 if (\array_key_exists(
"semantic", $params)) {
232 if (\array_key_exists(
"bootstrap", $params)) {
235 if (isset($params[
"ajax"])) {
236 if (isset($params[
"ajax"][
"ajaxTransition"])) {
237 $this->ajaxTransition = $this->
setAjaxDataCall($params[
"ajax"][
"ajaxTransition"]);
239 if ($params[
"ajax"][
"historize"]) {
240 $params[
"historize"] =
true;
242 if ($params[
"ajax"][
"csrf"]) {
246 if ($params[
"historize"]) {
249 if ($params[
"autoActiveLinks"]) {
253 $this->params = $params;
254 $this->injected = $injected;
255 if (isset($params[
'gc'])) {
266 public function __set($property, $value) {
269 $this->bootstrap($value);
272 $this->semantic(value);
278 throw new \Exception(
'Unknown property !');
287 if (isset($this->params[$key]))
288 return $this->params[$key];
299 if (! is_array($array_js)) {
305 foreach ($array_js as $js) {
306 $this->jquery_code_for_compile[] =
"\t$js\n";
319 public function compile(&$view = NULL, $view_var =
'script_foot', $script_tags = TRUE) {
320 if (isset($this->_ui)) {
323 if (isset($this->_bootstrap)) {
326 if (isset($this->_semantic)) {
330 $this->jquery_code_for_compile = \array_merge($this->jquery_code_for_compile, $this->jquery_code_for_compile_at_last);
332 if (\
count($this->jquery_code_for_compile) == 0) {
337 $script = $this->
ready(implode(
'', $this->jquery_code_for_compile));
338 if ($this->params[
"defer"]) {
339 $script = $this->
defer($script);
343 $this->jquery_code_for_compile = $this->jquery_code_for_compile_at_last = [];
344 if ($this->params[
"debug"] ===
false) {
345 $script = $this->
minify($script);
347 $output = ($script_tags === FALSE) ? $script : $this->
inline($script);
349 if ($view !== NULL) {
350 $this->createScriptVariable($view, $view_var, $output);
362 $this->jquery_code_for_compile = $this->jquery_code_for_compile_at_last = [];
363 if($this->_bootstrap!==null){
364 $this->_bootstrap->clearComponents();
366 if($this->_semantic!==null){
367 $this->_semantic->clearComponents();
369 if($this->_ui!==null){
370 $this->_ui->clearComponents();
375 $code = \array_merge($this->jquery_code_for_compile, $this->jquery_code_for_compile_at_last);
377 $code = \array_slice($code, $offset);
379 return \implode(
'', $code);
394 public function inline($script, $cdata = TRUE) {
396 $str .= ($cdata) ?
"\n// <![CDATA[\n{$script}\n// ]]>\n" :
"\n{$script}\n";
413 if (! is_null($result)) {
414 if (is_object($result)) {
415 $json_result = $result->result_array();
416 } elseif (\is_array($result)) {
417 $json_result = $result;
419 return $this->_prep_args($result);
424 return $this->_create_json($json_result, $match_array_type);
430 if (! is_array($json_result) && empty($json_result)) {
431 show_error(
"Generate JSON Failed - Illegal key, value pair.");
432 } elseif ($match_array_type) {
433 $_is_assoc = JArray::isAssociative($json_result);
435 foreach ($json_result as $k => $v) {
437 $json[] = $this->_prep_args($k, TRUE) .
':' . $this->generate_json($v, $match_array_type);
439 $json[] = $this->generate_json($v, $match_array_type);
442 $json = implode(
',', $json);
443 return $_is_assoc ?
"{" . $json .
"}" :
"[" . $json .
"]";
454 if (is_null($result)) {
456 } elseif (is_bool($result)) {
457 return ($result === TRUE) ?
'true' :
'false';
458 } elseif (is_string($result) || $is_key) {
459 return '"' . str_replace(array(
474 } elseif (is_scalar($result)) {
498 public function _add_event($element, $js, $event, $preventDefault =
false, $stopPropagation =
false, $immediatly =
true, $listenerOn =
false) {
499 if (\is_array($js)) {
500 $js = implode(
"\n\t\t", $js);
502 if ($preventDefault ===
true) {
503 $js = Javascript::$preventDefault . $js;
505 if ($stopPropagation ===
true) {
506 $js = Javascript::$stopPropagation . $js;
508 if (\is_string($listenerOn)) {
509 $event =
"\n\t$(" . Javascript::prep_element($listenerOn) .
").on('{$event}'," . Javascript::prep_element($element) .
",function(event){\n\t\t{$js}\n\t});\n";
511 if (\array_search($event, $this->jquery_events) ===
false) {
512 $event =
"\n\t$(" . Javascript::prep_element($element) .
").bind('{$event}',function(event){\n\t\t{$js}\n\t});\n";
514 $event =
"\n\t$(" . Javascript::prep_element($element) .
").{$event}(function(event){\n\t\t{$js}\n\t});\n";
518 $this->jquery_code_for_compile[] = $event;
523 return $this->injected;
527 $this->params[$param]=$value;
fromDispatcher(JsUtils $js, $dispatcher, $startIndex=0)
_add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false)
Constructs the syntax for an event, and adds to into the array for compilation.
addCsrf($name='csrf-token')
autoActiveLinks($previousURL="window.location.href")
output($array_js)
Outputs the called javascript to the screen.
clear_compile()
Clears the array of script events collected for output.
setParam(string $param, $value)
trait JsUtilsActionsTrait
__construct($params=array(), $injected=NULL)
_prep_args($result, $is_key=FALSE)
Ensures a standard json value and escapes values.
_close_script($extra="\)
Outputs an closing </script>
exec($js, $immediatly=false)
Executes the code $js.
compile(&$view=NULL, $view_var='script_foot', $script_tags=TRUE)
gather together all script needing to be output
semantic(Semantic $semantic=NULL)
getter or setter of the Semantic-UI variable
bootstrap(Bootstrap $bootstrap=NULL)
getter or setter of the Twitter Bootstrap variable
_open_script($src='')
Outputs an opening <script>
ui(JqueryUI $ui=NULL)
getter or setter of the jQuery-UI variable
JQuery UI Phalcon library.
initialize()
To override for special initialization of the component.
trait JsUtilsInternalTrait
generate_json($result=NULL, $match_array_type=FALSE)
Can be passed a database result or associative array and returns a JSON formatted string...
_compileLibrary(BaseGui $library, &$view=NULL)
_create_json($json_result, $match_array_type)
execAtLast($js)
Executes the code $js.