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) {
|
||||
var ytId = parseYouTubeId(url);
|
||||
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 {
|
||||
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_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_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_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.",
|
||||
@@ -308,7 +306,7 @@ const TABS = [
|
||||
"hero_secondary_button_enabled", "hero_secondary_button_label", "hero_secondary_button_url",
|
||||
"hero_primary_btn_color_dark", "hero_primary_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_bg_dark", "hero_bg_light", "hero_min_height", "hero_border_style",
|
||||
"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 },
|
||||
hero_background_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_background_image_url: { label: "Upload Image", multi: false },
|
||||
ios_app_badge_image_url: { label: "Upload Badge", multi: false },
|
||||
@@ -877,11 +874,6 @@ const CONDITIONAL_TOGGLES = [
|
||||
whenOff: ["hero_image_url"],
|
||||
whenOn: ["hero_image_urls"],
|
||||
},
|
||||
{
|
||||
toggle: "hero_video_url_enabled",
|
||||
whenOff: ["hero_video_upload"],
|
||||
whenOn: ["hero_video_url"],
|
||||
},
|
||||
];
|
||||
|
||||
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) {
|
||||
@@ -978,23 +929,17 @@ function getCsrfToken() {
|
||||
return meta ? meta.getAttribute("content") : "";
|
||||
}
|
||||
|
||||
async function uploadFile(file, { isVideo = false } = {}) {
|
||||
async function uploadFile(file) {
|
||||
console.log("[CL Upload] Starting upload:", {
|
||||
name: file.name,
|
||||
type: file.type,
|
||||
size: `${(file.size / 1024 / 1024).toFixed(2)} MB`,
|
||||
isVideo,
|
||||
});
|
||||
|
||||
const formData = new FormData();
|
||||
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("for_site_setting", "true");
|
||||
}
|
||||
formData.append("upload_type", "site_setting");
|
||||
formData.append("for_site_setting", "true");
|
||||
formData.append("synchronous_uploads", "true");
|
||||
|
||||
const csrfToken = getCsrfToken();
|
||||
@@ -1069,32 +1014,10 @@ function updatePreviewThumbnail(wrapper, settingName) {
|
||||
const preview = wrapper.querySelector(".cl-upload-preview");
|
||||
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 {
|
||||
const preview = wrapper.querySelector(".cl-upload-preview");
|
||||
if (!preview) return;
|
||||
preview.src = url;
|
||||
preview.style.display = url ? "" : "none";
|
||||
}
|
||||
const preview = wrapper.querySelector(".cl-upload-preview");
|
||||
if (!preview) return;
|
||||
preview.src = url;
|
||||
preview.style.display = url ? "" : "none";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1263,8 +1186,7 @@ function injectUploadButtons() {
|
||||
btn.disabled = true;
|
||||
|
||||
try {
|
||||
const isVideo = (cfg.accept || "").includes("video");
|
||||
const data = await uploadFile(file, { isVideo });
|
||||
const data = await uploadFile(file);
|
||||
await pinUpload(data.id, settingName);
|
||||
setSettingValue(row, data.url, cfg.multi);
|
||||
updatePreviewThumbnail(wrapper, settingName);
|
||||
|
||||
@@ -449,24 +449,6 @@ html.dark-scheme .admin-detail:not(.cl-tabs-active) .row.setting[data-setting="f
|
||||
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) ── */
|
||||
|
||||
|
||||
@@ -92,8 +92,6 @@ en:
|
||||
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_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_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."
|
||||
|
||||
@@ -300,12 +300,6 @@ plugins:
|
||||
hero_secondary_btn_color_light:
|
||||
default: ""
|
||||
type: color
|
||||
hero_video_upload:
|
||||
default: ""
|
||||
type: string
|
||||
hero_video_url_enabled:
|
||||
default: false
|
||||
type: bool
|
||||
hero_video_url:
|
||||
default: ""
|
||||
type: string
|
||||
|
||||
@@ -383,11 +383,7 @@ module CommunityLanding
|
||||
else
|
||||
hero_image_urls_raw = (@s.hero_image_url.presence rescue nil)
|
||||
end
|
||||
if (@s.hero_video_url_enabled rescue false)
|
||||
hero_video = (@s.hero_video_url.presence rescue nil)
|
||||
else
|
||||
hero_video = (@s.hero_video_upload.presence rescue nil)
|
||||
end
|
||||
hero_video = (@s.hero_video_url.presence rescue nil)
|
||||
blur_attr = (@s.hero_video_blur_on_hover rescue true) ? " data-blur-hover=\"true\"" : ""
|
||||
has_images = false
|
||||
|
||||
@@ -851,8 +847,7 @@ module CommunityLanding
|
||||
end
|
||||
|
||||
def render_video_modal
|
||||
has_video = (@s.hero_video_url.presence rescue nil) ||
|
||||
(@s.hero_video_upload.presence rescue nil)
|
||||
has_video = (@s.hero_video_url.presence rescue nil)
|
||||
return "" unless has_video
|
||||
|
||||
html = +""
|
||||
|
||||
@@ -87,7 +87,7 @@ after_initialize do
|
||||
hero_background_image_url hero_image_url hero_image_urls about_image_url
|
||||
about_background_image_url ios_app_badge_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
|
||||
].freeze
|
||||
|
||||
|
||||
Reference in New Issue
Block a user