Skip to content

Commit 2022f8c

Browse files
authored
Merge pull request #1 from rplvrtha/main
modified: assets/js/camera.js
2 parents 1c9880b + dfa0e18 commit 2022f8c

File tree

2 files changed

+54
-54
lines changed

2 files changed

+54
-54
lines changed

assets/js/camera.js

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
$(document).ready(function() {
2-
const options = window.cameraWidgetOptions || {};
3-
const openCameraBtn = $('#openNativeCamera');
4-
const fileInput = $('#fileInput');
5-
const previewImage = $('#previewImage');
6-
7-
// Gunakan opsi dari PHP
8-
const uploadUrl = options.uploadUrl;
9-
const retakeText = options.retakeText || 'Ambil Ulang Gambar';
10-
const onSuccess = options.onSuccess;
11-
const onError = options.onError;
1+
$(document).ready(function () {
2+
const options = window.cameraWidgetOptions || {};
3+
const openCameraBtn = $("#openNativeCamera");
4+
const fileInput = $("#fileInput");
5+
const previewImage = $("#previewImage");
126

13-
openCameraBtn.on('click', function() {
14-
fileInput.click();
15-
});
7+
// Gunakan opsi dari PHP
8+
const uploadUrl = options.uploadUrl;
9+
const retakeText = options.retakeText || "Ambil Ulang Gambar";
10+
const onSuccess = options.onSuccess;
11+
const onError = options.onError;
1612

17-
fileInput.on('change', function(event) {
18-
const file = event.target.files[0];
19-
if (!file) {
20-
return;
21-
}
13+
openCameraBtn.on("click", function () {
14+
fileInput.click();
15+
});
2216

23-
const reader = new FileReader();
24-
reader.onload = function(e) {
25-
openCameraBtn.text(retakeText);
26-
previewImage.attr('src', e.target.result).show();
17+
fileInput.on("change", function (event) {
18+
const file = event.target.files[0];
19+
if (!file) {
20+
return;
21+
}
2722

28-
const formData = new FormData();
29-
formData.append('imageFile', file);
30-
formData.append('_csrf', yii.getCsrfToken());
31-
32-
$.ajax({
33-
url: uploadUrl,
34-
method: 'POST',
35-
data: formData,
36-
processData: false,
37-
contentType: false,
38-
success: function(response) {
39-
if (onSuccess && typeof window[onSuccess] === 'function') {
40-
window[onSuccess](response);
41-
} else {
42-
console.log('Gambar berhasil diunggah:', response);
43-
}
44-
},
45-
error: function(xhr, status, error) {
46-
if (onError && typeof window[onError] === 'function') {
47-
window[onError](error);
48-
} else {
49-
console.error('Error saat mengunggah gambar:', error);
50-
}
51-
}
52-
});
53-
};
54-
reader.readAsDataURL(file);
55-
});
56-
});
23+
const reader = new FileReader();
24+
reader.onload = function (e) {
25+
openCameraBtn.text(retakeText);
26+
previewImage.attr("src", e.target.result).show();
27+
28+
const formData = new FormData();
29+
formData.append("imageFile", file);
30+
formData.append("_csrf", yii.getCsrfToken());
31+
32+
$.ajax({
33+
url: uploadUrl,
34+
method: "POST",
35+
data: formData,
36+
processData: false,
37+
contentType: false,
38+
success: function (response) {
39+
if (onSuccess && typeof window[onSuccess] === "function") {
40+
window[onSuccess](response);
41+
} else {
42+
console.log("Gambar berhasil diunggah:", response);
43+
}
44+
},
45+
error: function (xhr, status, error) {
46+
if (onError && typeof window[onError] === "function") {
47+
window[onError](error);
48+
} else {
49+
console.error("Error saat mengunggah gambar:", error);
50+
}
51+
},
52+
});
53+
};
54+
reader.readAsDataURL(file);
55+
});
56+
});

src/Yii2Cam.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public function run()
3737
'div',
3838
Html::img('', [
3939
'id' => 'previewImage',
40-
'class' => 'img-fluid d-block mb-3 ' . $this->previewClass,
41-
'style' => 'display: none; width: ' . $this->previewWidth . ';',
40+
'class' => "img-fluid mb-3 $this->previewClass",
41+
'style' => "width: $this->previewWidth; display: none;",
4242
'alt' => 'Pratinjau Gambar'
4343
]) .
4444
Html::button($this->buttonText, [

0 commit comments

Comments
 (0)