|
|
@@ -11,6 +11,7 @@ function init() {
|
|
|
document.querySelector('.buttonCancelAdd').addEventListener('click', hideAddImageForm);
|
|
|
document.querySelector('.buttonApproveAdd').addEventListener('click', addImage);
|
|
|
document.querySelector('.buttonApproveAddMore').addEventListener('click', addMoreImage);
|
|
|
+
|
|
|
document.querySelector('.buttonClearCards').addEventListener('click', clearAllCards);
|
|
|
document.querySelector('.buttonAddMeme').addEventListener('click', addMeme);
|
|
|
document.querySelector('.buttonSeedCards').addEventListener('click', seedCards);
|
|
|
@@ -124,39 +125,29 @@ function hideAddImageForm() {
|
|
|
}
|
|
|
|
|
|
function addImage(event) {
|
|
|
- event.preventDefault();
|
|
|
- let imageUrl = document.getElementById('newPicUrl').value.trim();
|
|
|
- if (!imageUrl) {
|
|
|
- // 如果 URL 是空的,直接返回並且不進行任何操作
|
|
|
- console.log('URL is empty. No action taken.');
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!imageUrl.startsWith('http://') && !imageUrl.startsWith('https://')) {
|
|
|
- // 如果不是,則默默地為用戶添加 http://
|
|
|
- imageUrl = 'https://' + imageUrl;
|
|
|
- console.log('URL corrected to: ', imageUrl);
|
|
|
- }
|
|
|
- // 添加圖片
|
|
|
- addImageWithUrl(imageUrl);
|
|
|
-
|
|
|
- // 清空輸入欄位並隱藏添加圖片表單
|
|
|
- document.getElementById('newPicUrl').value = '';
|
|
|
- hideAddImageForm();
|
|
|
+ handleAddImage(event, true);
|
|
|
}
|
|
|
|
|
|
function addMoreImage(event) {
|
|
|
+ handleAddImage(event, false);
|
|
|
+}
|
|
|
+
|
|
|
+function handleAddImage(event, closeModal) {
|
|
|
event.preventDefault();
|
|
|
- let imageUrl = document.getElementById('newPicUrl').value.trim();
|
|
|
+ let imageUrl = document.getElementById('newPicUrl').value.trim();
|
|
|
if (!imageUrl) {
|
|
|
console.log('URL is empty. No action taken.');
|
|
|
return;
|
|
|
}
|
|
|
if (!imageUrl.startsWith('http://') && !imageUrl.startsWith('https://')) {
|
|
|
- imageUrl = 'http://' + imageUrl;
|
|
|
+ imageUrl = 'https://' + imageUrl;
|
|
|
console.log('URL corrected to: ', imageUrl);
|
|
|
}
|
|
|
addImageWithUrl(imageUrl);
|
|
|
document.getElementById('newPicUrl').value = '';
|
|
|
+ if (closeModal) {
|
|
|
+ hideAddImageForm()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|