Skip to content

Commit 96c9218

Browse files
committed
add jqueryDone to dropzone
1 parent 027a73d commit 96c9218

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

Ajax/service/Javascript.php

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
<?php
2-
32
namespace Ajax\service;
43

54
class Javascript {
6-
public static $preventDefault="\nif(event && event.preventDefault) event.preventDefault();\n";
7-
public static $stopPropagation="\nif(event && event.stopPropagation) event.stopPropagation();\n";
85

9-
public static function draggable($attr="id"){
10-
return 'var dt=event.dataTransfer || event.originalEvent.dataTransfer;dt.setData("text/plain",JSON.stringify({id:$(event.target).attr("id"),data:$(event.target).attr("'.$attr.'")}));';
6+
public static $preventDefault = "\nif(event && event.preventDefault) event.preventDefault();\n";
7+
8+
public static $stopPropagation = "\nif(event && event.stopPropagation) event.stopPropagation();\n";
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 . '")}));';
1112
}
12-
13-
public static function dropZone($jqueryDone,$jsCallback=""){
14-
return 'var dt=event.dataTransfer || event.originalEvent.dataTransfer;var _data=JSON.parse(dt.getData("text/plain"));$(event.target).'.$jqueryDone.'($("#"+_data.id));var data=_data.data;'.$jsCallback;
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;
1517
}
16-
17-
public static function containsCode($expression){
18-
return strrpos($expression, 'this')!==false||strrpos($expression, 'event')!==false||strrpos($expression, 'self')!==false;
18+
19+
public static function containsCode($expression) {
20+
return strrpos($expression, 'this') !== false || strrpos($expression, 'event') !== false || strrpos($expression, 'self') !== false;
1921
}
20-
21-
public static function isFunction($jsCode){
22+
23+
public static function isFunction($jsCode) {
2224
return JString::startswith($jsCode, "function");
2325
}
24-
25-
public static function fileUploadBehavior($id=''){
26+
27+
public static function fileUploadBehavior($id = '') {
2628
return "$('input:text, .ui.button', '#{$id}').on('click', function (e) {e.preventDefault();\$('input:file', '#{$id}').click();});
2729
$('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);}});";
2830
}
@@ -36,8 +38,8 @@ public static function fileUploadBehavior($id=''){
3638
* @return string
3739
*/
3840
public static function prep_element($element) {
39-
if (self::containsCode($element)===false) {
40-
$element='"'.addslashes($element).'"';
41+
if (self::containsCode($element) === false) {
42+
$element = '"' . addslashes($element) . '"';
4143
}
4244
return $element;
4345
}
@@ -52,18 +54,24 @@ public static function prep_element($element) {
5254
*/
5355
public static function prep_value($value) {
5456
if (\is_array($value)) {
55-
$value=implode(",", $value);
57+
$value = implode(",", $value);
5658
}
57-
if (self::containsCode($value)===false) {
58-
$value=\str_replace(["\\","\""], ["\\\\","\\\""], $value);
59-
$value='"'.$value.'"';
59+
if (self::containsCode($value) === false) {
60+
$value = \str_replace([
61+
"\\",
62+
"\""
63+
], [
64+
"\\\\",
65+
"\\\""
66+
], $value);
67+
$value = '"' . $value . '"';
6068
}
61-
return trim($value,"%");
69+
return trim($value, "%");
6270
}
6371

64-
public static function prep_jquery_selector($value){
65-
if(JString::startswith($value, '$(')===false){
66-
return '$('.self::prep_value($value).')';
72+
public static function prep_jquery_selector($value) {
73+
if (JString::startswith($value, '$(') === false) {
74+
return '$(' . self::prep_value($value) . ')';
6775
}
6876
return $value;
6977
}

0 commit comments

Comments
 (0)