@@ -3,28 +3,28 @@ discard block |
||
3 | 3 | |
4 | 4 | class Javascript { |
5 | 5 | |
6 | - public static $preventDefault = "\nif(event && event.preventDefault) event.preventDefault();\n"; |
|
6 | + public static $preventDefault="\nif(event && event.preventDefault) event.preventDefault();\n"; |
|
7 | 7 | |
8 | - public static $stopPropagation = "\nif(event && event.stopPropagation) event.stopPropagation();\n"; |
|
8 | + public static $stopPropagation="\nif(event && event.stopPropagation) event.stopPropagation();\n"; |
|
9 | 9 | |
10 | - public static function draggable($attr = "id") { |
|
11 | - return 'var dt=event.dataTransfer || event.originalEvent.dataTransfer;dt.setData("text/plain",JSON.stringify({id:$(event.target).attr("id"),data:$(event.target).attr("' . $attr . '")}));'; |
|
10 | + public static function draggable($attr="id") { |
|
11 | + return 'var dt=event.dataTransfer || event.originalEvent.dataTransfer;dt.setData("text/plain",JSON.stringify({id:$(event.target).attr("id"),data:$(event.target).attr("'.$attr.'")}));'; |
|
12 | 12 | } |
13 | 13 | |
14 | - public static function dropZone($jqueryDone, $jsCallback = "") { |
|
15 | - $done = ($jqueryDone != null) ? '$(event.target).' . $jqueryDone . '($("#"+_data.id));' : ''; |
|
16 | - return 'var dt=event.dataTransfer || event.originalEvent.dataTransfer;var _data=JSON.parse(dt.getData("text/plain"));' . $done . 'var data=_data.data;' . $jsCallback; |
|
14 | + public static function dropZone($jqueryDone, $jsCallback="") { |
|
15 | + $done=($jqueryDone!=null) ? '$(event.target).'.$jqueryDone.'($("#"+_data.id));' : ''; |
|
16 | + return 'var dt=event.dataTransfer || event.originalEvent.dataTransfer;var _data=JSON.parse(dt.getData("text/plain"));'.$done.'var data=_data.data;'.$jsCallback; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | public static function containsCode($expression) { |
20 | - return strrpos($expression, 'this') !== false || strrpos($expression, 'event') !== false || strrpos($expression, 'self') !== false; |
|
20 | + return strrpos($expression, 'this')!==false || strrpos($expression, 'event')!==false || strrpos($expression, 'self')!==false; |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | public static function isFunction($jsCode) { |
24 | 24 | return JString::startswith($jsCode, "function"); |
25 | 25 | } |
26 | 26 | |
27 | - public static function fileUploadBehavior($id = '') { |
|
27 | + public static function fileUploadBehavior($id='') { |
|
28 | 28 | return "$('input:text, .ui.button', '#{$id}').on('click', function (e) {e.preventDefault();\$('input:file', '#{$id}').click();}); |
29 | 29 | $('input:file', '#{$id}').on('change', function (e) {if(e.target.files.length){var name = e.target.files[0].name;$('input:text', $(e.target).parent()).val(name);}});"; |
30 | 30 | } |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | * @return string |
39 | 39 | */ |
40 | 40 | public static function prep_element($element) { |
41 | - if (self::containsCode($element) === false) { |
|
42 | - $element = '"' . addslashes($element) . '"'; |
|
41 | + if (self::containsCode($element)===false) { |
|
42 | + $element='"'.addslashes($element).'"'; |
|
43 | 43 | } |
44 | 44 | return $element; |
45 | 45 | } |
@@ -54,24 +54,24 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public static function prep_value($value) { |
56 | 56 | if (\is_array($value)) { |
57 | - $value = implode(",", $value); |
|
57 | + $value=implode(",", $value); |
|
58 | 58 | } |
59 | - if (self::containsCode($value) === false) { |
|
60 | - $value = \str_replace([ |
|
59 | + if (self::containsCode($value)===false) { |
|
60 | + $value=\str_replace([ |
|
61 | 61 | "\\", |
62 | 62 | "\"" |
63 | 63 | ], [ |
64 | 64 | "\\\\", |
65 | 65 | "\\\"" |
66 | 66 | ], $value); |
67 | - $value = '"' . $value . '"'; |
|
67 | + $value='"'.$value.'"'; |
|
68 | 68 | } |
69 | 69 | return trim($value, "%"); |
70 | 70 | } |
71 | 71 | |
72 | 72 | public static function prep_jquery_selector($value) { |
73 | - if (JString::startswith($value, '$(') === false) { |
|
74 | - return '$(' . self::prep_value($value) . ')'; |
|
73 | + if (JString::startswith($value, '$(')===false) { |
|
74 | + return '$('.self::prep_value($value).')'; |
|
75 | 75 | } |
76 | 76 | return $value; |
77 | 77 | } |