|
|
@@ -7,6 +7,35 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ var articleVideoPattern = /\.(mp4|webm|ogg|m4v|mov|m3u8)(\?|#|$)/i;
|
|
|
+
|
|
|
+ function normalizePortalUrl(url, baseUrl) {
|
|
|
+ if (!url) return "";
|
|
|
+ try {
|
|
|
+ return new URL(url, baseUrl || window.location.href).href;
|
|
|
+ } catch (error) {
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function normalizePortalUploadUrl(url, baseUrl) {
|
|
|
+ var normalized = normalizePortalUrl(url, baseUrl);
|
|
|
+ if (!normalized) return "";
|
|
|
+ try {
|
|
|
+ var parsed = new URL(normalized, window.location.href);
|
|
|
+ var uploadIndex = parsed.pathname.indexOf("/web/upload/");
|
|
|
+ if (uploadIndex >= 0) {
|
|
|
+ var uploadPath = parsed.pathname.slice(uploadIndex).replace(/\/{2,}/g, "/");
|
|
|
+ return window.location.origin + uploadPath + parsed.search + parsed.hash;
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ normalized = String(normalized).replace(/^(?:https?:)?\/\/[^/]*(\/web\/upload\/.*)$/i, "$1");
|
|
|
+ normalized = normalized.replace(/^(https?:)\/+(\/web\/upload\/.*)$/i, "$2");
|
|
|
+ normalized = normalized.replace(/(\/web\/upload\/modules)\/+/i, "$1/");
|
|
|
+ }
|
|
|
+ return normalized;
|
|
|
+ }
|
|
|
+
|
|
|
function setDrawer(open, trigger) {
|
|
|
var drawerLayer = document.querySelector(".drawer-layer");
|
|
|
var buttons = Array.prototype.slice.call(document.querySelectorAll(".mobile-menu"));
|
|
|
@@ -163,6 +192,109 @@
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ function setupArticleBodyVideos() {
|
|
|
+ var videos = Array.prototype.slice.call(document.querySelectorAll(".article-body video"));
|
|
|
+ if (!videos.length) return;
|
|
|
+
|
|
|
+ function sourceOf(video) {
|
|
|
+ var source = video.querySelector("source[src]");
|
|
|
+ return {
|
|
|
+ node: source,
|
|
|
+ value: video.getAttribute("src") || (source && source.getAttribute("src")) || ""
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ function closestArticleBody(node) {
|
|
|
+ while (node && node !== document) {
|
|
|
+ if (node.classList && node.classList.contains("article-body")) return node;
|
|
|
+ node = node.parentNode;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ function thumbnailPoster(video) {
|
|
|
+ var body = closestArticleBody(video);
|
|
|
+ var poster = body ? body.getAttribute("data-article-thumbnail") : "";
|
|
|
+ return poster ? normalizePortalUploadUrl(poster) : "";
|
|
|
+ }
|
|
|
+
|
|
|
+ function syncSource(video) {
|
|
|
+ var current = sourceOf(video);
|
|
|
+ if (!current.value || !articleVideoPattern.test(current.value)) return;
|
|
|
+ var normalized = normalizePortalUploadUrl(current.value);
|
|
|
+ if (!normalized || normalized === current.value) return;
|
|
|
+ if (video.getAttribute("src")) video.setAttribute("src", normalized);
|
|
|
+ if (current.node) current.node.setAttribute("src", normalized);
|
|
|
+ if (video.load) video.load();
|
|
|
+ }
|
|
|
+
|
|
|
+ function capturePoster(video) {
|
|
|
+ if (video.poster || video.getAttribute("data-article-poster-ready") === "true") return;
|
|
|
+ if (!video.videoWidth || !video.videoHeight) return;
|
|
|
+ try {
|
|
|
+ var canvas = document.createElement("canvas");
|
|
|
+ canvas.width = video.videoWidth;
|
|
|
+ canvas.height = video.videoHeight;
|
|
|
+ canvas.getContext("2d").drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
|
+ video.poster = canvas.toDataURL("image/jpeg", 0.86);
|
|
|
+ video.setAttribute("data-article-poster-ready", "true");
|
|
|
+ if (video.paused && video.currentTime > 0.02) {
|
|
|
+ try {
|
|
|
+ video.currentTime = 0;
|
|
|
+ } catch (error) {}
|
|
|
+ }
|
|
|
+ } catch (error) {}
|
|
|
+ }
|
|
|
+
|
|
|
+ function primePoster(video) {
|
|
|
+ if (video.poster) return;
|
|
|
+ var seeked = false;
|
|
|
+
|
|
|
+ function seekFirstFrame() {
|
|
|
+ if (seeked) return;
|
|
|
+ seeked = true;
|
|
|
+ if (video.readyState >= 2) {
|
|
|
+ capturePoster(video);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!isFinite(video.duration) || video.duration <= 0) return;
|
|
|
+ try {
|
|
|
+ video.currentTime = Math.min(0.12, Math.max(0, video.duration - 0.05));
|
|
|
+ } catch (error) {}
|
|
|
+ }
|
|
|
+
|
|
|
+ video.addEventListener("loadeddata", function () {
|
|
|
+ capturePoster(video);
|
|
|
+ }, { once: true });
|
|
|
+ video.addEventListener("seeked", function () {
|
|
|
+ capturePoster(video);
|
|
|
+ }, { once: true });
|
|
|
+ video.addEventListener("loadedmetadata", seekFirstFrame, { once: true });
|
|
|
+
|
|
|
+ if (video.readyState >= 1) {
|
|
|
+ seekFirstFrame();
|
|
|
+ } else if (video.load) {
|
|
|
+ video.load();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ videos.forEach(function (video) {
|
|
|
+ video.classList.add("article-inline-video");
|
|
|
+ video.controls = true;
|
|
|
+ video.playsInline = true;
|
|
|
+ video.setAttribute("playsinline", "");
|
|
|
+ video.setAttribute("preload", "metadata");
|
|
|
+ video.removeAttribute("width");
|
|
|
+ video.removeAttribute("height");
|
|
|
+ syncSource(video);
|
|
|
+ if (!video.poster) {
|
|
|
+ var poster = thumbnailPoster(video);
|
|
|
+ if (poster) video.poster = poster;
|
|
|
+ }
|
|
|
+ if (!video.poster) primePoster(video);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
function setupColorfulVideoPlayer() {
|
|
|
var cards = Array.prototype.slice.call(document.querySelectorAll(".colorful-slide.is-video"));
|
|
|
if (!cards.length || !window.DOMParser) return;
|
|
|
@@ -1037,6 +1169,7 @@
|
|
|
setupDrawer();
|
|
|
setupSearch();
|
|
|
setupEmptyArticleNotice();
|
|
|
+ setupArticleBodyVideos();
|
|
|
setupScreenHeaderScroll();
|
|
|
setupDepartmentNavStickyState();
|
|
|
setupScreenNavPanelBounds();
|