mirror of
https://github.com/dpnmw/community-landing.git
synced 2026-03-18 09:27:16 +00:00
Video Upload Removal
This commit is contained in:
@@ -173,7 +173,7 @@
|
|||||||
function openVideoModal(url) {
|
function openVideoModal(url) {
|
||||||
var ytId = parseYouTubeId(url);
|
var ytId = parseYouTubeId(url);
|
||||||
if (ytId) {
|
if (ytId) {
|
||||||
videoPlayer.innerHTML = '<iframe src="https://www.youtube-nocookie.com/embed/' + ytId + '?autoplay=1&rel=0" allow="autoplay; encrypted-media; fullscreen" allowfullscreen frameborder="0"></iframe>';
|
videoPlayer.innerHTML = '<iframe src="https://www.youtube-nocookie.com/embed/' + ytId + '?autoplay=1&rel=0" allow="autoplay; encrypted-media; fullscreen" referrerpolicy="origin" frameborder="0"></iframe>';
|
||||||
} else {
|
} else {
|
||||||
videoPlayer.innerHTML = '<video src="' + url + '" controls autoplay></video>';
|
videoPlayer.innerHTML = '<video src="' + url + '" controls autoplay></video>';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,8 +98,6 @@ const DESCRIPTIONS = {
|
|||||||
hero_primary_btn_color_light: "Primary button background for light mode.",
|
hero_primary_btn_color_light: "Primary button background for light mode.",
|
||||||
hero_secondary_btn_color_dark: "Secondary button background for dark mode. Leave blank for glass style.",
|
hero_secondary_btn_color_dark: "Secondary button background for dark mode. Leave blank for glass style.",
|
||||||
hero_secondary_btn_color_light: "Secondary button background for light mode.",
|
hero_secondary_btn_color_light: "Secondary button background for light mode.",
|
||||||
hero_video_upload: "Upload a video file to Discourse. Check your site's allowed file types and maximum file size in site settings before uploading.",
|
|
||||||
hero_video_url_enabled: "Use an external video URL instead of uploading a file.",
|
|
||||||
hero_video_url: "Hero video URL (MP4 or YouTube). Play button opens a lightbox modal.",
|
hero_video_url: "Hero video URL (MP4 or YouTube). Play button opens a lightbox modal.",
|
||||||
hero_video_button_color: "Custom color for the video play button. Leave blank for accent color.",
|
hero_video_button_color: "Custom color for the video play button. Leave blank for accent color.",
|
||||||
hero_video_blur_on_hover: "Blur the hero image when hovering the play button.",
|
hero_video_blur_on_hover: "Blur the hero image when hovering the play button.",
|
||||||
@@ -308,7 +306,7 @@ const TABS = [
|
|||||||
"hero_secondary_button_enabled", "hero_secondary_button_label", "hero_secondary_button_url",
|
"hero_secondary_button_enabled", "hero_secondary_button_label", "hero_secondary_button_url",
|
||||||
"hero_primary_btn_color_dark", "hero_primary_btn_color_light",
|
"hero_primary_btn_color_dark", "hero_primary_btn_color_light",
|
||||||
"hero_secondary_btn_color_dark", "hero_secondary_btn_color_light",
|
"hero_secondary_btn_color_dark", "hero_secondary_btn_color_light",
|
||||||
"hero_video_upload", "hero_video_url_enabled", "hero_video_url",
|
"hero_video_url",
|
||||||
"hero_video_button_color", "hero_video_blur_on_hover",
|
"hero_video_button_color", "hero_video_blur_on_hover",
|
||||||
"hero_bg_dark", "hero_bg_light", "hero_min_height", "hero_border_style",
|
"hero_bg_dark", "hero_bg_light", "hero_min_height", "hero_border_style",
|
||||||
"hero_card_bg_dark", "hero_card_bg_light", "hero_card_opacity",
|
"hero_card_bg_dark", "hero_card_bg_light", "hero_card_opacity",
|
||||||
@@ -442,7 +440,6 @@ const IMAGE_UPLOAD_SETTINGS = {
|
|||||||
footer_logo_url: { label: "Upload Logo", multi: false },
|
footer_logo_url: { label: "Upload Logo", multi: false },
|
||||||
hero_background_image_url: { label: "Upload Image", multi: false },
|
hero_background_image_url: { label: "Upload Image", multi: false },
|
||||||
hero_image_url: { label: "Upload Image", multi: false },
|
hero_image_url: { label: "Upload Image", multi: false },
|
||||||
hero_video_upload: { label: "Upload Video", multi: false, accept: "video/*" },
|
|
||||||
about_image_url: { label: "Upload Image", multi: false },
|
about_image_url: { label: "Upload Image", multi: false },
|
||||||
about_background_image_url: { label: "Upload Image", multi: false },
|
about_background_image_url: { label: "Upload Image", multi: false },
|
||||||
ios_app_badge_image_url: { label: "Upload Badge", multi: false },
|
ios_app_badge_image_url: { label: "Upload Badge", multi: false },
|
||||||
@@ -877,11 +874,6 @@ const CONDITIONAL_TOGGLES = [
|
|||||||
whenOff: ["hero_image_url"],
|
whenOff: ["hero_image_url"],
|
||||||
whenOn: ["hero_image_urls"],
|
whenOn: ["hero_image_urls"],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
toggle: "hero_video_url_enabled",
|
|
||||||
whenOff: ["hero_video_upload"],
|
|
||||||
whenOn: ["hero_video_url"],
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
function applyConditionalVisibility(container) {
|
function applyConditionalVisibility(container) {
|
||||||
@@ -912,47 +904,6 @@ function applyConditionalVisibility(container) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if file attachments are allowed for video upload toggle
|
|
||||||
injectVideoUploadNotice(container);
|
|
||||||
}
|
|
||||||
|
|
||||||
function injectVideoUploadNotice(container) {
|
|
||||||
const toggleRow = container.querySelector(
|
|
||||||
'.row.setting[data-setting="hero_video_upload"]'
|
|
||||||
);
|
|
||||||
if (!toggleRow) return;
|
|
||||||
if (toggleRow.dataset.clVideoNoticeInjected) return;
|
|
||||||
toggleRow.dataset.clVideoNoticeInjected = "1";
|
|
||||||
|
|
||||||
// Check Discourse site settings for file attachment support
|
|
||||||
const authorizedExtensions = (
|
|
||||||
(_siteSettings && _siteSettings.authorized_extensions) || ""
|
|
||||||
).toLowerCase();
|
|
||||||
const attachmentsAllowed =
|
|
||||||
authorizedExtensions.includes("mp4") ||
|
|
||||||
authorizedExtensions.includes("webm") ||
|
|
||||||
authorizedExtensions.includes("mov") ||
|
|
||||||
authorizedExtensions.includes("*");
|
|
||||||
|
|
||||||
const notice = document.createElement("div");
|
|
||||||
notice.className = "cl-upload-notice";
|
|
||||||
|
|
||||||
if (!attachmentsAllowed) {
|
|
||||||
notice.classList.add("cl-upload-notice--warn");
|
|
||||||
notice.textContent =
|
|
||||||
"Video file uploads require video extensions (mp4, webm, mov) to be added to your site\u2019s authorized extensions in Settings \u2192 Files.";
|
|
||||||
// Disable the upload button if injected
|
|
||||||
const uploadBtn = toggleRow.querySelector(".cl-upload-btn");
|
|
||||||
if (uploadBtn) uploadBtn.disabled = true;
|
|
||||||
} else {
|
|
||||||
const maxSize = _siteSettings && _siteSettings.max_attachment_size_kb;
|
|
||||||
const maxMB = maxSize ? (maxSize / 1024).toFixed(0) : "?";
|
|
||||||
notice.textContent =
|
|
||||||
`Check allowed video file types and max upload size (${maxMB} MB) in Settings \u2192 Files before uploading.`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const valueDiv = toggleRow.querySelector(".setting-value") || toggleRow;
|
|
||||||
valueDiv.appendChild(notice);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function listenForConditionalToggles(container) {
|
function listenForConditionalToggles(container) {
|
||||||
@@ -978,23 +929,17 @@ function getCsrfToken() {
|
|||||||
return meta ? meta.getAttribute("content") : "";
|
return meta ? meta.getAttribute("content") : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadFile(file, { isVideo = false } = {}) {
|
async function uploadFile(file) {
|
||||||
console.log("[CL Upload] Starting upload:", {
|
console.log("[CL Upload] Starting upload:", {
|
||||||
name: file.name,
|
name: file.name,
|
||||||
type: file.type,
|
type: file.type,
|
||||||
size: `${(file.size / 1024 / 1024).toFixed(2)} MB`,
|
size: `${(file.size / 1024 / 1024).toFixed(2)} MB`,
|
||||||
isVideo,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file", file);
|
formData.append("file", file);
|
||||||
if (isVideo) {
|
|
||||||
// Discourse rejects non-image files when for_site_setting is true
|
|
||||||
formData.append("upload_type", "composer");
|
|
||||||
} else {
|
|
||||||
formData.append("upload_type", "site_setting");
|
formData.append("upload_type", "site_setting");
|
||||||
formData.append("for_site_setting", "true");
|
formData.append("for_site_setting", "true");
|
||||||
}
|
|
||||||
formData.append("synchronous_uploads", "true");
|
formData.append("synchronous_uploads", "true");
|
||||||
|
|
||||||
const csrfToken = getCsrfToken();
|
const csrfToken = getCsrfToken();
|
||||||
@@ -1068,34 +1013,12 @@ function updatePreviewThumbnail(wrapper, settingName) {
|
|||||||
// Hide single preview if it exists
|
// Hide single preview if it exists
|
||||||
const preview = wrapper.querySelector(".cl-upload-preview");
|
const preview = wrapper.querySelector(".cl-upload-preview");
|
||||||
if (preview) preview.style.display = "none";
|
if (preview) preview.style.display = "none";
|
||||||
} else {
|
|
||||||
const isVideo = cfg && (cfg.accept || "").includes("video");
|
|
||||||
if (isVideo) {
|
|
||||||
// Video: show text label instead of broken img preview
|
|
||||||
let label = wrapper.querySelector(".cl-upload-preview-label");
|
|
||||||
if (!label) {
|
|
||||||
label = document.createElement("span");
|
|
||||||
label.className = "cl-upload-preview-label";
|
|
||||||
// Insert before remove button if it exists
|
|
||||||
const removeBtn = wrapper.querySelector(".cl-upload-remove");
|
|
||||||
if (removeBtn) {
|
|
||||||
wrapper.insertBefore(label, removeBtn);
|
|
||||||
} else {
|
|
||||||
wrapper.appendChild(label);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
label.textContent = url ? "Video uploaded" : "";
|
|
||||||
label.style.display = url ? "" : "none";
|
|
||||||
// Hide img preview if exists
|
|
||||||
const preview = wrapper.querySelector(".cl-upload-preview");
|
|
||||||
if (preview) preview.style.display = "none";
|
|
||||||
} else {
|
} else {
|
||||||
const preview = wrapper.querySelector(".cl-upload-preview");
|
const preview = wrapper.querySelector(".cl-upload-preview");
|
||||||
if (!preview) return;
|
if (!preview) return;
|
||||||
preview.src = url;
|
preview.src = url;
|
||||||
preview.style.display = url ? "" : "none";
|
preview.style.display = url ? "" : "none";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderMultiImageList(wrapper, row, input, settingName) {
|
function renderMultiImageList(wrapper, row, input, settingName) {
|
||||||
@@ -1263,8 +1186,7 @@ function injectUploadButtons() {
|
|||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const isVideo = (cfg.accept || "").includes("video");
|
const data = await uploadFile(file);
|
||||||
const data = await uploadFile(file, { isVideo });
|
|
||||||
await pinUpload(data.id, settingName);
|
await pinUpload(data.id, settingName);
|
||||||
setSettingValue(row, data.url, cfg.multi);
|
setSettingValue(row, data.url, cfg.multi);
|
||||||
updatePreviewThumbnail(wrapper, settingName);
|
updatePreviewThumbnail(wrapper, settingName);
|
||||||
|
|||||||
@@ -449,24 +449,6 @@ html.dark-scheme .admin-detail:not(.cl-tabs-active) .row.setting[data-setting="f
|
|||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cl-upload-preview-label {
|
|
||||||
font-size: var(--font-down-1);
|
|
||||||
color: var(--success);
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.cl-upload-notice {
|
|
||||||
margin-top: 6px;
|
|
||||||
font-size: var(--font-down-2);
|
|
||||||
color: var(--primary-medium);
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
.cl-upload-notice--warn {
|
|
||||||
color: var(--danger);
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ── Multi-image list (hero_image_urls) ── */
|
/* ── Multi-image list (hero_image_urls) ── */
|
||||||
|
|
||||||
|
|||||||
@@ -92,8 +92,6 @@ en:
|
|||||||
hero_primary_btn_color_light: "Light mode background for the primary button."
|
hero_primary_btn_color_light: "Light mode background for the primary button."
|
||||||
hero_secondary_btn_color_dark: "Secondary button background color. Dark (left) and light (right) pickers. Leave blank for default glass style."
|
hero_secondary_btn_color_dark: "Secondary button background color. Dark (left) and light (right) pickers. Leave blank for default glass style."
|
||||||
hero_secondary_btn_color_light: "Light mode background for the secondary button."
|
hero_secondary_btn_color_light: "Light mode background for the secondary button."
|
||||||
hero_video_upload: "Upload a video file to Discourse. Check your site's allowed file types and max file size before uploading."
|
|
||||||
hero_video_url_enabled: "Use an external video URL instead of uploading a file."
|
|
||||||
hero_video_url: "URL for a hero video. Supports MP4 and YouTube links. A play button appears in the hero area; clicking opens a lightbox modal with the video."
|
hero_video_url: "URL for a hero video. Supports MP4 and YouTube links. A play button appears in the hero area; clicking opens a lightbox modal with the video."
|
||||||
hero_video_button_color: "Custom background color for the hero video play button. Leave blank to use the accent color."
|
hero_video_button_color: "Custom background color for the hero video play button. Leave blank to use the accent color."
|
||||||
hero_video_blur_on_hover: "Apply a blur effect to the hero image when hovering the play button."
|
hero_video_blur_on_hover: "Apply a blur effect to the hero image when hovering the play button."
|
||||||
|
|||||||
@@ -300,12 +300,6 @@ plugins:
|
|||||||
hero_secondary_btn_color_light:
|
hero_secondary_btn_color_light:
|
||||||
default: ""
|
default: ""
|
||||||
type: color
|
type: color
|
||||||
hero_video_upload:
|
|
||||||
default: ""
|
|
||||||
type: string
|
|
||||||
hero_video_url_enabled:
|
|
||||||
default: false
|
|
||||||
type: bool
|
|
||||||
hero_video_url:
|
hero_video_url:
|
||||||
default: ""
|
default: ""
|
||||||
type: string
|
type: string
|
||||||
|
|||||||
@@ -383,11 +383,7 @@ module CommunityLanding
|
|||||||
else
|
else
|
||||||
hero_image_urls_raw = (@s.hero_image_url.presence rescue nil)
|
hero_image_urls_raw = (@s.hero_image_url.presence rescue nil)
|
||||||
end
|
end
|
||||||
if (@s.hero_video_url_enabled rescue false)
|
|
||||||
hero_video = (@s.hero_video_url.presence rescue nil)
|
hero_video = (@s.hero_video_url.presence rescue nil)
|
||||||
else
|
|
||||||
hero_video = (@s.hero_video_upload.presence rescue nil)
|
|
||||||
end
|
|
||||||
blur_attr = (@s.hero_video_blur_on_hover rescue true) ? " data-blur-hover=\"true\"" : ""
|
blur_attr = (@s.hero_video_blur_on_hover rescue true) ? " data-blur-hover=\"true\"" : ""
|
||||||
has_images = false
|
has_images = false
|
||||||
|
|
||||||
@@ -851,8 +847,7 @@ module CommunityLanding
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render_video_modal
|
def render_video_modal
|
||||||
has_video = (@s.hero_video_url.presence rescue nil) ||
|
has_video = (@s.hero_video_url.presence rescue nil)
|
||||||
(@s.hero_video_upload.presence rescue nil)
|
|
||||||
return "" unless has_video
|
return "" unless has_video
|
||||||
|
|
||||||
html = +""
|
html = +""
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ after_initialize do
|
|||||||
hero_background_image_url hero_image_url hero_image_urls about_image_url
|
hero_background_image_url hero_image_url hero_image_urls about_image_url
|
||||||
about_background_image_url ios_app_badge_image_url
|
about_background_image_url ios_app_badge_image_url
|
||||||
android_app_badge_image_url app_cta_image_url
|
android_app_badge_image_url app_cta_image_url
|
||||||
splits_background_image_url hero_video_upload
|
splits_background_image_url
|
||||||
preloader_logo_dark_url preloader_logo_light_url
|
preloader_logo_dark_url preloader_logo_light_url
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user