|
@@ -3,36 +3,36 @@ discard block |
|
|
block discarded – undo |
|
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
|
|
- public static function fileDropZone($jsCallback = "") { |
|
20
|
|
- $done = 'event.target.upload=formData;$(event.target).trigger("upload");'; |
|
21
|
|
- return 'var dt=event.dataTransfer || event.originalEvent.dataTransfer;var files=dt.files;var formData = new FormData();for (var i = 0; i < files.length; i++) {formData.append("file-"+i,files[i]);}' . $done . $jsCallback; |
|
|
19
|
+ public static function fileDropZone($jsCallback="") { |
|
|
20
|
+ $done='event.target.upload=formData;$(event.target).trigger("upload");'; |
|
|
21
|
+ return 'var dt=event.dataTransfer || event.originalEvent.dataTransfer;var files=dt.files;var formData = new FormData();for (var i = 0; i < files.length; i++) {formData.append("file-"+i,files[i]);}'.$done.$jsCallback; |
|
22
|
22
|
} |
|
23
|
23
|
|
|
24
|
24
|
public static function containsCode($expression) { |
|
25
|
|
- if ($expression == null) { |
|
|
25
|
+ if ($expression==null) { |
|
26
|
26
|
return false; |
|
27
|
27
|
} |
|
28
|
|
- return \strrpos($expression, 'this') !== false || \strrpos($expression, 'event') !== false || \strrpos($expression, 'self') !== false; |
|
|
28
|
+ return \strrpos($expression, 'this')!==false || \strrpos($expression, 'event')!==false || \strrpos($expression, 'self')!==false; |
|
29
|
29
|
} |
|
30
|
30
|
|
|
31
|
31
|
public static function isFunction($jsCode) { |
|
32
|
32
|
return JString::startswith($jsCode, "function"); |
|
33
|
33
|
} |
|
34
|
34
|
|
|
35
|
|
- public static function fileUploadBehavior($id = '') { |
|
|
35
|
+ public static function fileUploadBehavior($id='') { |
|
36
|
36
|
return "$('input:text, .ui.button', '#{$id}').on('click', function (e) {e.preventDefault();\$('input:file', '#{$id}').click();}); |
|
37
|
37
|
$('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);}});"; |
|
38
|
38
|
} |
|
@@ -46,8 +46,8 @@ discard block |
|
|
block discarded – undo |
|
46
|
46
|
* @return string |
|
47
|
47
|
*/ |
|
48
|
48
|
public static function prep_element($element) { |
|
49
|
|
- if (self::containsCode($element) === false) { |
|
50
|
|
- $element = '"' . addslashes($element ?? '') . '"'; |
|
|
49
|
+ if (self::containsCode($element)===false) { |
|
|
50
|
+ $element='"'.addslashes($element ?? '').'"'; |
|
51
|
51
|
} |
|
52
|
52
|
return $element; |
|
53
|
53
|
} |
|
@@ -62,24 +62,24 @@ discard block |
|
|
block discarded – undo |
|
62
|
62
|
*/ |
|
63
|
63
|
public static function prep_value($value) { |
|
64
|
64
|
if (\is_array($value)) { |
|
65
|
|
- $value = implode(",", $value); |
|
|
65
|
+ $value=implode(",", $value); |
|
66
|
66
|
} |
|
67
|
|
- if (self::containsCode($value) === false) { |
|
68
|
|
- $value = \str_replace([ |
|
|
67
|
+ if (self::containsCode($value)===false) { |
|
|
68
|
+ $value=\str_replace([ |
|
69
|
69
|
"\\", |
|
70
|
70
|
"\"" |
|
71
|
71
|
], [ |
|
72
|
72
|
"\\\\", |
|
73
|
73
|
"\\\"" |
|
74
|
74
|
], $value); |
|
75
|
|
- $value = '"' . $value . '"'; |
|
|
75
|
+ $value='"'.$value.'"'; |
|
76
|
76
|
} |
|
77
|
77
|
return trim($value, "%"); |
|
78
|
78
|
} |
|
79
|
79
|
|
|
80
|
80
|
public static function prep_jquery_selector($value) { |
|
81
|
|
- if (JString::startswith($value, '$(') === false) { |
|
82
|
|
- return '$(' . self::prep_value($value) . ')'; |
|
|
81
|
+ if (JString::startswith($value, '$(')===false) { |
|
|
82
|
+ return '$('.self::prep_value($value).')'; |
|
83
|
83
|
} |
|
84
|
84
|
return $value; |
|
85
|
85
|
} |