phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
JsUtilsInternalTrait.php
Go to the documentation of this file.
1<?php
2namespace Ajax\common\traits;
3
5
7
8 protected $jquery_code_for_compile = array();
9
11
12 protected function _addToCompile($jsScript) {
13 $this->jquery_code_for_compile[] = $jsScript;
14 }
15
21 protected function _compileLibrary(BaseGui $library, &$view = NULL) {
22 if (isset($view))
23 $library->compileHtml($this, $view);
24 if ($library->isAutoCompile()) {
25 $library->compile(true);
26 }
27 }
28
29 protected function defer($script) {
30 $result = "(function(){window.defer=function (method) {if (window.jQuery) method(); else setTimeout(function() { window.defer(method); }, 50);};";
31 $result .= "window.defer(function(){" . $script . "})})()";
32 return $result;
33 }
34
35 protected function ready($script) {
36 $result = '$(function() {' . "\n";
37 $result .= $script . '});';
38 return $result;
39 }
40
41 protected function minify($input) {
42 if (trim($input) === "")
43 return $input;
44 $input = preg_replace(array(
45 // Remove comment(s)
46 '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#',
47 // Remove white-space(s) outside the string and regex
48 '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\‍(\‍)\-=+\[\]\{\}|;:,.<>?\/])\s*#s',
49 // Remove the last semicolon
50 // '#;+\}#',
51 // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}`
52 '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i',
53 // --ibid. From `foo['bar']` to `foo.bar`
54 '#([a-z0-9_\‍)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i'
55 ), array(
56 '$1',
57 '$1$2',
58 // '}',
59 '$1$3',
60 '$1.$3'
61 ), $input);
62 $input = str_replace("}$", "};$", $input);
63 return $input;
64 }
65
72 protected function _open_script($src = '') {
73 $str = '<script ';
74 $str .= ($src == '') ? '>' : ' src="' . $src . '">';
75 return $str;
76 }
77
84 protected function _close_script($extra = "\n") {
85 return "</script>$extra";
86 }
87
88 protected function conflict() {
89 $this->_addToCompile("var btn = $.fn.button.noConflict();$.fn.btn = btn;");
90 }
91
92 public function addToCompile($jsScript) {
93 $this->_addToCompile($jsScript);
94 }
95}
BaseGui Phalcon library.
Definition BaseGui.php:18
compileHtml(JsUtils $js=NULL, &$view=NULL)
Definition BaseGui.php:83
compile($internal=false)
Definition BaseGui.php:47
_compileLibrary(BaseGui $library, &$view=NULL)
_close_script($extra="\n")
Outputs an closing </script>
_open_script($src='')
Outputs an opening <script>