Skip to content

Commit 52e3ac3

Browse files
committed
minify function !
1 parent e24b4ab commit 52e3ac3

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

Ajax/common/traits/JsUtilsInternalTrait.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
namespace Ajax\common\traits;
33
use Ajax\common\BaseGui;
4-
use Ubiquity\js\Minify;
54

65
trait JsUtilsInternalTrait{
76

@@ -38,7 +37,29 @@ protected function ready($script){
3837

3938
protected function minify($input) {
4039
if(trim($input) === "") return $input;
41-
return Minify::minifyJavascript($input);
40+
$input= preg_replace(
41+
array(
42+
// Remove comment(s)
43+
'#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#',
44+
// Remove white-space(s) outside the string and regex
45+
'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s',
46+
// Remove the last semicolon
47+
//'#;+\}#',
48+
// Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}`
49+
'#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i',
50+
// --ibid. From `foo['bar']` to `foo.bar`
51+
'#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i'
52+
),
53+
array(
54+
'$1',
55+
'$1$2',
56+
//'}',
57+
'$1$3',
58+
'$1.$3'
59+
),
60+
$input);
61+
$input=str_replace("}$", "};$", $input);
62+
return $input;
4263
}
4364

4465
/**

0 commit comments

Comments
 (0)