Initial commit: simpleblog
This commit is contained in:
@@ -0,0 +1,268 @@
|
||||
/* Analytics dashboard: visitor location map + location trend chart.
|
||||
*
|
||||
* Both charts read their data from JSON <script> blocks embedded by
|
||||
* templates/admin/analytics.html, so there is no extra API request and no
|
||||
* chart library to load. Leaflet (vendored under /static/vendor/leaflet) is
|
||||
* used for the map only when it is present.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var PALETTE = [
|
||||
"#1f6feb", "#e36209", "#2ea043", "#8250df", "#cf222e", "#8b949e",
|
||||
];
|
||||
|
||||
function readJSON(id) {
|
||||
var el = document.getElementById(id);
|
||||
if (!el) return null;
|
||||
try {
|
||||
return JSON.parse(el.textContent);
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function dayLabel(iso) {
|
||||
var parts = String(iso).split("-");
|
||||
var date = new Date(Date.UTC(+parts[0], +parts[1] - 1, +parts[2]));
|
||||
return date.toLocaleDateString(undefined, {
|
||||
month: "short", day: "numeric", timeZone: "UTC",
|
||||
});
|
||||
}
|
||||
|
||||
function niceMax(value) {
|
||||
if (value <= 4) return 4;
|
||||
var power = Math.pow(10, Math.floor(Math.log10(value)));
|
||||
var steps = [1, 2, 2.5, 5, 10];
|
||||
for (var i = 0; i < steps.length; i++) {
|
||||
if (steps[i] * power >= value) return steps[i] * power;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function drawTrend() {
|
||||
var data = readJSON("location-trend-data");
|
||||
var canvas = document.getElementById("location-trend-chart");
|
||||
if (!data || !canvas || !data.series || !data.series.length) return;
|
||||
|
||||
var wrap = canvas.parentNode;
|
||||
var tooltip = document.createElement("div");
|
||||
tooltip.className = "chart-tooltip";
|
||||
tooltip.hidden = true;
|
||||
wrap.appendChild(tooltip);
|
||||
|
||||
var legend = document.getElementById("location-trend-legend");
|
||||
data.series.forEach(function (series, index) {
|
||||
var item = document.createElement("span");
|
||||
var swatch = document.createElement("span");
|
||||
swatch.className = "swatch";
|
||||
swatch.style.backgroundColor = PALETTE[index % PALETTE.length];
|
||||
item.appendChild(swatch);
|
||||
item.appendChild(document.createTextNode(series.name));
|
||||
legend.appendChild(item);
|
||||
});
|
||||
|
||||
var PAD = { top: 14, right: 14, bottom: 30, left: 44 };
|
||||
var HEIGHT = 280;
|
||||
var hoverIndex = -1;
|
||||
|
||||
function render() {
|
||||
var width = Math.max(320, wrap.clientWidth);
|
||||
var dpr = window.devicePixelRatio || 1;
|
||||
canvas.width = Math.round(width * dpr);
|
||||
canvas.height = Math.round(HEIGHT * dpr);
|
||||
canvas.style.width = width + "px";
|
||||
canvas.style.height = HEIGHT + "px";
|
||||
|
||||
var ctx = canvas.getContext("2d");
|
||||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||
ctx.clearRect(0, 0, width, HEIGHT);
|
||||
|
||||
var plotW = width - PAD.left - PAD.right;
|
||||
var plotH = HEIGHT - PAD.top - PAD.bottom;
|
||||
var max = 0;
|
||||
data.series.forEach(function (series) {
|
||||
series.data.forEach(function (value) {
|
||||
if (value > max) max = value;
|
||||
});
|
||||
});
|
||||
max = niceMax(max);
|
||||
var count = data.labels.length;
|
||||
|
||||
function xAt(index) {
|
||||
return PAD.left + (count === 1 ? plotW / 2 : (index / (count - 1)) * plotW);
|
||||
}
|
||||
function yAt(value) {
|
||||
return PAD.top + plotH - (value / max) * plotH;
|
||||
}
|
||||
|
||||
ctx.strokeStyle = "#e5e7eb";
|
||||
ctx.fillStyle = "#6b7280";
|
||||
ctx.font = "12px system-ui, -apple-system, sans-serif";
|
||||
ctx.lineWidth = 1;
|
||||
ctx.textAlign = "right";
|
||||
ctx.textBaseline = "middle";
|
||||
for (var tick = 0; tick <= 4; tick++) {
|
||||
var tickValue = (max / 4) * tick;
|
||||
var tickY = yAt(tickValue);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(PAD.left, tickY);
|
||||
ctx.lineTo(width - PAD.right, tickY);
|
||||
ctx.stroke();
|
||||
ctx.fillText(String(Math.round(tickValue)), PAD.left - 8, tickY);
|
||||
}
|
||||
|
||||
ctx.textAlign = "center";
|
||||
ctx.textBaseline = "top";
|
||||
var stride = Math.max(1, Math.ceil(count / 7));
|
||||
for (var i = 0; i < count; i += stride) {
|
||||
ctx.fillText(dayLabel(data.labels[i]), xAt(i), HEIGHT - PAD.bottom + 8);
|
||||
}
|
||||
|
||||
data.series.forEach(function (series, index) {
|
||||
ctx.strokeStyle = PALETTE[index % PALETTE.length];
|
||||
ctx.lineWidth = 2;
|
||||
ctx.lineJoin = "round";
|
||||
ctx.beginPath();
|
||||
series.data.forEach(function (value, i) {
|
||||
var x = xAt(i);
|
||||
var y = yAt(value);
|
||||
if (i === 0) ctx.moveTo(x, y);
|
||||
else ctx.lineTo(x, y);
|
||||
});
|
||||
ctx.stroke();
|
||||
});
|
||||
|
||||
if (hoverIndex >= 0) {
|
||||
var hoverX = xAt(hoverIndex);
|
||||
ctx.strokeStyle = "rgba(31, 111, 235, 0.35)";
|
||||
ctx.lineWidth = 1;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(hoverX, PAD.top);
|
||||
ctx.lineTo(hoverX, HEIGHT - PAD.bottom);
|
||||
ctx.stroke();
|
||||
|
||||
var lines = [dayLabel(data.labels[hoverIndex])];
|
||||
data.series.forEach(function (series, index) {
|
||||
var value = series.data[hoverIndex] || 0;
|
||||
if (!value) return;
|
||||
ctx.fillStyle = PALETTE[index % PALETTE.length];
|
||||
ctx.beginPath();
|
||||
ctx.arc(hoverX, yAt(value), 3, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
lines.push(series.name + ": " + value);
|
||||
});
|
||||
tooltip.textContent = lines.join(" \u00b7 ");
|
||||
tooltip.hidden = false;
|
||||
var left = Math.min(Math.max(hoverX + 10, 8), width - tooltip.offsetWidth - 8);
|
||||
tooltip.style.left = left + "px";
|
||||
tooltip.style.top = PAD.top + "px";
|
||||
} else {
|
||||
tooltip.hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
canvas.addEventListener("mousemove", function (event) {
|
||||
var rect = canvas.getBoundingClientRect();
|
||||
var plotW = Math.max(1, rect.width - PAD.left - PAD.right);
|
||||
var count = data.labels.length;
|
||||
var ratio = (event.clientX - rect.left - PAD.left) / plotW;
|
||||
var index = Math.round(ratio * (count - 1));
|
||||
index = Math.max(0, Math.min(count - 1, index));
|
||||
if (index !== hoverIndex) {
|
||||
hoverIndex = index;
|
||||
render();
|
||||
}
|
||||
});
|
||||
canvas.addEventListener("mouseleave", function () {
|
||||
hoverIndex = -1;
|
||||
render();
|
||||
});
|
||||
|
||||
var resizeTimer = null;
|
||||
window.addEventListener("resize", function () {
|
||||
clearTimeout(resizeTimer);
|
||||
resizeTimer = setTimeout(render, 150);
|
||||
});
|
||||
|
||||
render();
|
||||
}
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value == null ? "" : value)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function initMap() {
|
||||
var points = readJSON("visitor-map-data") || [];
|
||||
var container = document.getElementById("visitor-map");
|
||||
if (!container || typeof L === "undefined") return;
|
||||
|
||||
var map = L.map(container, { minZoom: 2, worldCopyJump: true }).setView([20, 0], 2);
|
||||
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
||||
maxZoom: 19,
|
||||
attribution:
|
||||
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
||||
}).addTo(map);
|
||||
|
||||
// Keep the world map visible even before the first located visit.
|
||||
if (!points.length) {
|
||||
setTimeout(function () { map.invalidateSize(); }, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
var maxVisits = 1;
|
||||
points.forEach(function (point) {
|
||||
if (point.visits > maxVisits) maxVisits = point.visits;
|
||||
});
|
||||
|
||||
var bounds = [];
|
||||
points.forEach(function (point) {
|
||||
var radius = 5 + 16 * Math.sqrt(point.visits / maxVisits);
|
||||
var label = [point.city, point.region, point.country]
|
||||
.filter(Boolean)
|
||||
.join(", ");
|
||||
L.circleMarker([point.lat, point.lon], {
|
||||
radius: radius,
|
||||
color: "#1f6feb",
|
||||
weight: 1.5,
|
||||
fillColor: "#1f6feb",
|
||||
fillOpacity: 0.3,
|
||||
})
|
||||
.addTo(map)
|
||||
.bindPopup(
|
||||
"<strong>" + escapeHtml(label || "Unknown location") + "</strong><br>" +
|
||||
escapeHtml(point.visits) + " visit(s) from " +
|
||||
escapeHtml(point.visitors) + " visitor(s)"
|
||||
);
|
||||
bounds.push([point.lat, point.lon]);
|
||||
});
|
||||
|
||||
if (bounds.length === 1) {
|
||||
map.setView(bounds[0], 5);
|
||||
} else {
|
||||
map.fitBounds(L.latLngBounds(bounds).pad(0.25), { maxZoom: 6 });
|
||||
}
|
||||
setTimeout(function () {
|
||||
map.invalidateSize();
|
||||
}, 0);
|
||||
window.addEventListener("resize", function () {
|
||||
map.invalidateSize();
|
||||
});
|
||||
}
|
||||
|
||||
function start() {
|
||||
drawTrend();
|
||||
initMap();
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", start);
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,114 @@
|
||||
// gallery_lightbox.js — full-album gallery viewer for /photos/<slug>.
|
||||
// A random image from the album is shown as a hero at the top of the page.
|
||||
// Clicking the hero (or any thumbnail) opens a modal showing every photo of the
|
||||
// album, with the album title, prev/next navigation and a thumbnail strip.
|
||||
// Esc, backdrop click, or the close button close it. Dependency-free / offline.
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var imgs = [];
|
||||
var lightbox = null;
|
||||
var mainImg = null;
|
||||
var idx = -1;
|
||||
|
||||
function collectGallery() {
|
||||
var out = [];
|
||||
if (document.querySelectorAll) {
|
||||
var nodes = document.querySelectorAll(".gallery-img");
|
||||
for (var i = 0; i < nodes.length; i++) out.push(nodes[i]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function buildLightbox() {
|
||||
// Reuse the existing viewer ONLY while it is still attached to the DOM.
|
||||
// Once close() has removed it, `lightbox` must be rebuilt so the next
|
||||
// thumbnail click doesn't set its src on a detached (invisible) node.
|
||||
if (lightbox && lightbox.isConnected) return lightbox;
|
||||
lightbox = document.getElementById("gallery-lightbox");
|
||||
if (!lightbox) return null;
|
||||
var closeBtn = document.querySelector(".lightbox-close");
|
||||
var prevBtn = document.querySelector(".lightbox-prev");
|
||||
var nextBtn = document.querySelector(".lightbox-next");
|
||||
mainImg = lightbox.querySelector(".lightbox-img-main");
|
||||
|
||||
if (closeBtn) closeBtn.addEventListener("click", close);
|
||||
if (prevBtn) prevBtn.addEventListener("click", function () { show(idx - 1); });
|
||||
if (nextBtn) nextBtn.addEventListener("click", function () { show(idx + 1); });
|
||||
|
||||
lightbox.addEventListener("click", function (e) {
|
||||
// Don't close when clicking a control button or the main image; only the
|
||||
// dark backdrop should dismiss the viewer.
|
||||
var t = e.target;
|
||||
if (t.closest(".lightbox-close, .lightbox-prev, .lightbox-next")) return;
|
||||
if (mainImg && mainImg.contains(t)) return;
|
||||
close();
|
||||
});
|
||||
|
||||
document.addEventListener("keydown", function (e) {
|
||||
if (!lightbox || !lightbox.classList.contains("is-open")) return;
|
||||
if (e.key === "Escape") { close(); }
|
||||
else if (e.key === "ArrowRight" || e.key === "ArrowDown") { e.preventDefault(); show(idx + 1); }
|
||||
else if (e.key === "ArrowLeft" || e.key === "ArrowUp") { e.preventDefault(); show(idx - 1); }
|
||||
});
|
||||
|
||||
return lightbox;
|
||||
}
|
||||
|
||||
// Pick a random thumbnail to feature as the hero.
|
||||
function pickRandomHero() {
|
||||
var g = collectGallery();
|
||||
if (!g.length) return null;
|
||||
return g[Math.floor(Math.random() * g.length)];
|
||||
}
|
||||
|
||||
function show(i) {
|
||||
var g = collectGallery();
|
||||
if (!g.length) return;
|
||||
idx = (i + g.length) % g.length;
|
||||
var el = g[idx];
|
||||
var src = el.getAttribute("data-src") || el.getAttribute("src") || "";
|
||||
buildLightbox(); // ensure the viewer (mainImg) exists before we use it
|
||||
if (mainImg && mainImg.getAttribute("src")) mainImg.removeAttribute("src"); // avoid flash
|
||||
mainImg.setAttribute("src", src);
|
||||
lightbox.classList.add("is-open");
|
||||
document.body.style.overflow = "hidden";
|
||||
}
|
||||
|
||||
function open() {
|
||||
var heroImg = document.querySelector(".gallery-hero-img");
|
||||
if (heroImg && !heroImg.getAttribute("src")) {
|
||||
var heroEl = pickRandomHero();
|
||||
if (heroEl) heroImg.setAttribute("src", heroEl.getAttribute("data-src") || heroEl.getAttribute("src"));
|
||||
}
|
||||
buildLightbox();
|
||||
show(0);
|
||||
}
|
||||
|
||||
function close() {
|
||||
if (!lightbox) return;
|
||||
lightbox.classList.remove("is-open");
|
||||
document.body.style.overflow = "";
|
||||
lightbox = null; // drop the cached node so buildLightbox() rebuilds next open
|
||||
setTimeout(function () { if (!lightbox.classList.contains("is-open")) lightbox.remove(); }, 300);
|
||||
}
|
||||
|
||||
// Wire up clicks: the hero opens the gallery (showing image 0), while any
|
||||
// individual thumbnail opens the gallery showing THAT photo.
|
||||
var heroFigure = document.getElementById("gallery-hero");
|
||||
if (heroFigure) heroFigure.addEventListener("click", open);
|
||||
var g = collectGallery();
|
||||
for (let k = 0; k < g.length; k++) {
|
||||
// NOTE: `let` gives each thumbnail its OWN copy of `k`, so clicking one
|
||||
// shows THAT photo. With the original `var k`, every handler shared the
|
||||
// final loop value (g.length) and always called show(0) instead — the bug.
|
||||
g[k].addEventListener("click", function () { buildLightbox(); show(k); });
|
||||
}
|
||||
|
||||
// Feature a random image on load.
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", pickRandomHero);
|
||||
} else {
|
||||
pickRandomHero();
|
||||
}
|
||||
})();
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,134 @@
|
||||
// lightbox.js — tiny dependency-free image viewer for rendered pages.
|
||||
// Click any <img> (from an uploaded TinyMCE image, or inline markdown) to open
|
||||
// it full-size in an overlay within the page. Esc, backdrop click, or arrow keys
|
||||
// close / navigate. Images with class "no-lightbox" (or data-no-lightbox) and
|
||||
// the site banner stay non-clickable. No external CDN → works offline.
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var EXCLUDE_CLASSES = ["no-lightbox", "site-banner-img"];
|
||||
|
||||
function isExcluded(img) {
|
||||
if (img.hasAttribute("data-no-lightbox")) return true;
|
||||
var cls = (img.getAttribute("class") || "").toLowerCase();
|
||||
for (var i = 0; i < EXCLUDE_CLASSES.length; i++) {
|
||||
if (cls.indexOf(EXCLUDE_CLASSES[i]) !== -1) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Collect clickable images in document order (once).
|
||||
var images = [];
|
||||
var doc = document;
|
||||
if (doc.querySelectorAll) {
|
||||
var nodes = doc.querySelectorAll("img");
|
||||
for (var n = 0; n < nodes.length; n++) {
|
||||
if (!isExcluded(nodes[n])) images.push(nodes[n]);
|
||||
}
|
||||
}
|
||||
|
||||
var lightbox = null;
|
||||
var imgEl = null;
|
||||
var idx = -1;
|
||||
|
||||
function buildLightbox() {
|
||||
if (lightbox) return lightbox;
|
||||
lightbox = document.createElement("div");
|
||||
lightbox.className = "lightbox";
|
||||
lightbox.setAttribute("role", "dialog");
|
||||
lightbox.setAttribute("aria-modal", "true");
|
||||
lightbox.setAttribute("aria-label", "Image viewer");
|
||||
|
||||
var backdrop = document.createElement("div");
|
||||
backdrop.className = "lightbox-backdrop";
|
||||
|
||||
var wrapper = document.createElement("div");
|
||||
wrapper.className = "lightbox-wrapper";
|
||||
|
||||
imgEl = document.createElement("img");
|
||||
imgEl.className = "lightbox-img";
|
||||
imgEl.alt = "";
|
||||
wrapper.appendChild(imgEl);
|
||||
|
||||
lightbox.appendChild(backdrop);
|
||||
lightbox.appendChild(wrapper);
|
||||
lightbox.addEventListener("click", onLightboxClick);
|
||||
return lightbox;
|
||||
}
|
||||
|
||||
function ensureLightbox() {
|
||||
buildLightbox();
|
||||
// Re-attach if the viewer was removed from the DOM (e.g. after a close),
|
||||
// so clicking another image still reopens it.
|
||||
if (lightbox && lightbox.parentNode !== document.body) {
|
||||
document.body.appendChild(lightbox);
|
||||
}
|
||||
return lightbox;
|
||||
}
|
||||
|
||||
function openAt(i) {
|
||||
ensureLightbox(); // ensure the viewer (imgEl + lightbox) exists before we use them
|
||||
idx = (i + images.length) % images.length;
|
||||
var src = images[idx].getAttribute("src");
|
||||
if (!src) src = images[idx].getAttribute("data-src") || "";
|
||||
if (imgEl.getAttribute("src")) imgEl.removeAttribute("src"); // avoid flash
|
||||
imgEl.setAttribute("src", src);
|
||||
lightbox.classList.add("is-open");
|
||||
document.body.style.overflow = "hidden";
|
||||
}
|
||||
|
||||
function close() {
|
||||
lightbox.classList.remove("is-open");
|
||||
document.body.style.overflow = "";
|
||||
setTimeout(function () { if (!lightbox.classList.contains("is-open")) lightbox.remove(); }, 300);
|
||||
}
|
||||
|
||||
function next() { openAt(idx + 1); }
|
||||
function prev() { openAt(idx - 1); }
|
||||
|
||||
function isClickable(img) {
|
||||
if (img.hasAttribute("data-no-lightbox")) return false;
|
||||
var cls = (img.getAttribute("class") || "").toLowerCase();
|
||||
for (var i = 0; i < EXCLUDE_CLASSES.length; i++) {
|
||||
if (cls.indexOf(EXCLUDE_CLASSES[i]) !== -1) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function onImgClick(e) {
|
||||
var t = e.target;
|
||||
if (t.tagName !== "IMG" || !isClickable(t)) return; // delegated: currentTarget is always the listener element, never the img
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
openAt(idx + 1);
|
||||
}
|
||||
|
||||
function onLightboxClick(e) {
|
||||
// Clicking anywhere in the viewer except the image itself closes it.
|
||||
if (imgEl && imgEl.contains(e.target)) return;
|
||||
close();
|
||||
}
|
||||
|
||||
function onKeyDown(e) {
|
||||
if (lightbox && lightbox.classList.contains("is-open")) {
|
||||
if (e.key === "Escape") { close(); }
|
||||
else if (e.key === "ArrowRight" || e.key === "ArrowDown") { e.preventDefault(); next(); }
|
||||
else if (e.key === "ArrowLeft" || e.key === "ArrowUp") { e.preventDefault(); prev(); }
|
||||
}
|
||||
}
|
||||
|
||||
if (images.length > 0) {
|
||||
// Delegate off the document so it survives images added later.
|
||||
doc.addEventListener("click", onImgClick);
|
||||
doc.addEventListener("keydown", onKeyDown);
|
||||
// Re-scan on DOMContentLoaded in case images appear after load.
|
||||
if (doc.readyState === "loading") {
|
||||
doc.addEventListener("DOMContentLoaded", function () {
|
||||
var again = doc.querySelectorAll("img");
|
||||
for (var j = 0; j < again.length; j++) {
|
||||
if (!images.indexOf(again[j])) images.push(again[j]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
+1
@@ -0,0 +1 @@
|
||||
!function(){"use strict";var e=tinymce.util.Tools.resolve("tinymce.PluginManager"),t=tinymce.util.Tools.resolve("tinymce.dom.RangeUtils"),o=tinymce.util.Tools.resolve("tinymce.util.Tools");const n=e=>e.options.get("allow_html_in_named_anchor");const a="a:not([href])",r=e=>!e,i=e=>e.getAttribute("id")||e.getAttribute("name")||"",l=e=>(e=>"a"===e.nodeName.toLowerCase())(e)&&!e.getAttribute("href")&&""!==i(e),s=e=>e.dom.getParent(e.selection.getStart(),a),d=(e,a)=>{const r=s(e);r?((e,t,o)=>{o.removeAttribute("name"),o.id=t,e.addVisual(),e.undoManager.add()})(e,a,r):((e,a)=>{e.undoManager.transact(()=>{n(e)||e.selection.collapse(!0),e.selection.isCollapsed()?e.insertContent(e.dom.createHTML("a",{id:a})):((e=>{const n=e.dom;t(n).walk(e.selection.getRng(),e=>{o.each(e,e=>{var t;l(t=e)&&!t.firstChild&&n.remove(e,!1)})})})(e),e.formatter.remove("namedAnchor",void 0,void 0,!0),e.formatter.apply("namedAnchor",{value:a}),e.addVisual())})})(e,a),e.focus()},c=e=>(e=>r(e.attr("href"))&&!r(e.attr("id")||e.attr("name")))(e)&&!e.firstChild,m=e=>t=>{for(let o=0;o<t.length;o++){const n=t[o];c(n)&&n.attr("contenteditable",e)}},u=e=>t=>{const o=()=>{t.setEnabled(e.selection.isEditable())};return e.on("NodeChange",o),o(),()=>{e.off("NodeChange",o)}},h="anchor";e.add(h,e=>((e=>{(0,e.options.register)("allow_html_in_named_anchor",{processor:"boolean",default:!1})})(e),(e=>{e.on("PreInit",()=>{e.parser.addNodeFilter("a",m("false")),e.serializer.addNodeFilter("a",m(null))})})(e),(e=>{e.addCommand("mceAnchor",()=>{(e=>{const t=(e=>{const t=s(e);return t?i(t):""})(e);e.windowManager.open({title:"Anchor",size:"normal",body:{type:"panel",items:[{name:"id",type:"input",label:"ID",placeholder:"example"}]},buttons:[{type:"cancel",name:"cancel",text:"Cancel"},{type:"submit",name:"save",text:"Save",primary:!0}],initialData:{id:t},onSubmit:t=>{((e,t)=>/^[A-Za-z][A-Za-z0-9\-:._]*$/.test(t)?(d(e,t),!0):(e.windowManager.alert("ID should start with a letter, followed only by letters, numbers, dashes, dots, colons or underscores."),!1))(e,t.getData().id)&&t.close()}})})(e)})})(e),(e=>{const t=()=>e.execCommand("mceAnchor");e.ui.registry.addToggleButton("anchor",{icon:"bookmark",tooltip:"Anchor",onAction:t,onSetup:t=>{const o=e.selection.selectorChangedWithUnbind("a:not([href])",t.setActive).unbind,n=u(e)(t);return()=>{o(),n()}}}),e.ui.registry.addMenuItem("anchor",{icon:"bookmark",text:"Anchor...",onAction:t,onSetup:u(e)})})(e),e.on("PreInit",()=>{(e=>{e.formatter.register("namedAnchor",{inline:"a",selector:a,remove:"all",split:!0,deep:!0,attributes:{id:"%value"},onmatch:(e,t,o)=>l(e)})})(e)}),{getMetadata:()=>({name:"Anchor",type:"opensource",slug:h})}))}();
|
||||
+1
@@ -0,0 +1 @@
|
||||
!function(){"use strict";var e=tinymce.util.Tools.resolve("tinymce.PluginManager");const t=e=>"string"===(e=>{const t=typeof e;return null===e?"null":"object"===t&&Array.isArray(e)?"array":"object"===t&&(n=o=e,(r=String).prototype.isPrototypeOf(n)||o.constructor?.name===r.name)?"string":t;var n,o,r})(e);const n=e=>void 0===e;const o=e=>!(e=>null==e)(e),r=Object.hasOwnProperty,a=e=>"\ufeff"===e,s=e=>t=>t.options.get(e),l=s("autolink_pattern"),c=s("link_default_target"),i=s("link_default_protocol"),d=s("allow_unsafe_link_target");var u=tinymce.util.Tools.resolve("tinymce.dom.TextSeeker");const f=e=>3===e.nodeType,g=e=>1===e.nodeType,m=e=>/^[(\[{ \u00a0]$/.test(e),k=(e,t,n)=>{for(let o=t-1;o>=0;o--){const t=e.charAt(o);if(!a(t)&&n(t))return o}return-1},p=(e,t)=>{const o=e.schema.getVoidElements(),a=l(e),{dom:s,selection:c}=e;if(null!==s.getParent(c.getNode(),"a[href]")||e.mode.isReadOnly())return null;const d=c.getRng(),p=u(s,e=>{return s.isBlock(e)||(t=o,n=e.nodeName.toLowerCase(),r.call(t,n))||"false"===s.getContentEditable(e)||null!==s.getParent(e,"a[href]");var t,n}),{container:y,offset:w}=((e,t)=>{let n=e,o=t;for(;g(n)&&n.childNodes[o];)n=n.childNodes[o],o=f(n)?n.data.length:n.childNodes.length;return{container:n,offset:o}})(d.endContainer,d.endOffset),h=s.getParent(y,s.isBlock)??s.getRoot(),_=p.backwards(y,w+t,(e,t)=>{const n=e.data,o=k(n,t,(r=m,e=>!r(e)));var r,a;return-1===o||(a=n[o],/[?!,.;:]/.test(a))?o:o+1},h);if(!_)return null;let v=_.container;const A=p.backwards(_.container,_.offset,(e,t)=>{v=e;const n=k(e.data,t,m);return-1===n?n:n+1},h),C=s.createRng();A?C.setStart(A.container,A.offset):C.setStart(v,0),C.setEnd(_.container,_.offset);const b=C.toString().replace(/\uFEFF/g,"").match(a);if(b){let t=b[0];return $="www.",(P=t).length>=4&&P.substr(0,4)===$?t=i(e)+"://"+t:((e,t,o=0,r)=>{const a=e.indexOf(t,o);return-1!==a&&(!!n(r)||a+t.length<=r)})(t,"@")&&!(e=>/^([A-Za-z][A-Za-z\d.+-]*:\/\/)|mailto:/.test(e))(t)&&(t="mailto:"+t),{rng:C,url:t}}var P,$;return null},y=(e,n)=>{const{dom:o,selection:r}=e,{rng:a,url:s}=n,l=r.getBookmark();r.setRng(a);const i="createlink",u={command:i,ui:!1,value:s};if(!e.dispatch("BeforeExecCommand",u).isDefaultPrevented()){e.getDoc().execCommand(i,!1,s),e.dispatch("ExecCommand",u);const n=c(e);if(t(n)){const t=r.getNode();o.setAttrib(t,"target",n),"_blank"!==n||d(e)||o.setAttrib(t,"rel","noopener")}}r.moveToBookmark(l),e.nodeChanged()},w=e=>{const t=p(e,-1);o(t)&&y(e,t)},h=w,_="autolink";e.add(_,e=>((e=>{const t=e.options.register;t("autolink_pattern",{processor:"regexp",default:new RegExp("^"+/(?:[A-Za-z][A-Za-z\d.+-]{0,14}:\/\/(?:[-.~*+=!&;:'%@?^${}(),\w]+@)?|www\.|[-;:&=+$,.\w]+@)[A-Za-z\d-]+(?:\.[A-Za-z\d-]+)*(?::\d+)?(?:\/(?:[-.~*+=!;:'%@$(),\/\w]*[-~*+=%@$()\/\w])?)?(?:\?(?:[-.~*+=!&;:'%@?^${}(),\/\w]+))?(?:#(?:[-.~*+=!&;:'%@?^${}(),\/\w]+))?/g.source+"$","i")}),t("link_default_target",{processor:"string"}),t("link_default_protocol",{processor:"string",default:"https"})})(e),(e=>{e.on("keydown",t=>{13!==t.keyCode||t.isDefaultPrevented()||(e=>{const t=p(e,0);o(t)&&y(e,t)})(e)}),e.on("keyup",t=>{32===t.keyCode?w(e):(48===t.keyCode&&t.shiftKey||221===t.keyCode)&&h(e)})})(e),{getMetadata:()=>({name:"Autolink",type:"opensource",slug:_})}))}();
|
||||
+1
File diff suppressed because one or more lines are too long
+9
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
Vendored
+1
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
!function(){"use strict";var t=tinymce.util.Tools.resolve("tinymce.PluginManager");const e=(t,e,o)=>{t.dom.toggleClass(t.getBody(),"mce-visualblocks"),o.set(!o.get()),((t,e)=>{t.dispatch("VisualBlocks",{state:e})})(t,o.get())},o=t=>t.options.get("visualblocks_default_state");const s=(t,e)=>o=>{o.setActive(e.get());const s=t=>o.setActive(t.state);return t.on("VisualBlocks",s),()=>t.off("VisualBlocks",s)},l="visualblocks";t.add(l,(t,a)=>{(t=>{(0,t.options.register)("visualblocks_default_state",{processor:"boolean",default:!1})})(t);const c=(()=>{let t=!1;return{get:()=>t,set:e=>{t=e}}})();return((t,o,s)=>{t.addCommand("mceVisualBlocks",()=>{e(t,0,s)})})(t,0,c),((t,e)=>{const o=()=>t.execCommand("mceVisualBlocks");t.ui.registry.addToggleButton("visualblocks",{icon:"visualblocks",tooltip:"Show blocks",onAction:o,onSetup:s(t,e),context:"any"}),t.ui.registry.addToggleMenuItem("visualblocks",{text:"Show blocks",icon:"visualblocks",onAction:o,onSetup:s(t,e),context:"any"})})(t,c),((t,s,l)=>{t.on("PreviewFormats AfterPreviewFormats",e=>{l.get()&&t.dom.toggleClass(t.getBody(),"mce-visualblocks","afterpreviewformats"===e.type)}),t.on("init",()=>{o(t)&&e(t,0,l)})})(t,0,c),{getMetadata:()=>({name:"Visual Blocks",type:"opensource",slug:l})}})}();
|
||||
+1
File diff suppressed because one or more lines are too long
+10
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
Vendored
+7
File diff suppressed because one or more lines are too long
Vendored
+3
File diff suppressed because one or more lines are too long
Vendored
+43095
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user