Provide mechanism to get tab click (Fixes #4)

This commit is contained in:
2025-01-30 22:57:18 -05:00
parent 67c857bbed
commit 93800c2706
6 changed files with 207 additions and 56 deletions

View File

@@ -30,7 +30,7 @@ String.prototype.toPath = function () {
var font = {
size: 0
};
var copyColourFallback = function copyColourFallback(copyInfo, attr) {
var copyFallback = function copyFallback(copyInfo, attr) {
console.log("fallback");
var textArea = document.createElement('textarea');
textArea.value = copyInfo;
@@ -135,7 +135,6 @@ module.exports = {
oneClickSelect: function oneClickSelect(e) {
var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : e.currentTarget;
// In here, "this" is the element
alert("here");
var range, selection;
if (window.getSelection) {
selection = window.getSelection();
@@ -157,10 +156,10 @@ module.exports = {
navigator.clipboard.writeText(c).then(function () {
showMessage("Copied ".concat(w, "."));
}, function (e) {
copyColourFallback(c, w);
copyFallback(c, w);
});
} else {
copyColourFallback(c, w);
copyFallback(c, w);
}
},
positionTooltip: function positionTooltip() {
@@ -179,6 +178,21 @@ module.exports = {
var b = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
return window.getComputedStyle(el, null).getPropertyValue(prop);
},
getTabPath: function getTabPath(t) {
var url = window.location.toString();
url = url.indexOf("?") > 0 ? url.substring(0, url.indexOf("?")) : url;
url = "".concat(url, "?p=").concat(t.closest("article").getAttribute("data-path"), "#").concat(t.getAttribute("id"));
var type = "URL";
if (navigator.clipboard) {
navigator.clipboard.writeText(url).then(function () {
showMessage("Copied ".concat(type, "."));
}, function (e) {
copyFallback(url, type);
});
} else {
copyFallback(url, type);
}
},
init: function init() {
var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var url = getURLVars();
@@ -3193,10 +3207,30 @@ var click = new MouseEvent('click', {
bubbles: false,
cancelable: true
});
var waitForElement = function waitForElement(selector) {
return new Promise(function (resolve) {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
var observer = new MutationObserver(function (mutations) {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
// If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
observer.observe(document.body, {
childList: true,
subtree: true
});
});
};
function init() {
var p = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
var s = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
p.querySelectorAll(".tab-group, tabset").forEach(function (tabGroup) {
var container = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
var spacer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
container.querySelectorAll(".tab-group, tabset").forEach(function (tabGroup) {
if (tabGroup.querySelector("[role=tablist]") === null) {
var tabgroup = tabGroup.getAttribute("id");
var tablist = "";
@@ -3219,23 +3253,31 @@ function init() {
});
var ul = document.createElement('ul');
ul.setAttribute("role", "tablist");
ul.innerHTML = s != true ? "".concat(tablist) : "".concat(tablist, "<li role=\"separator\" class=\"separator\"></li>");
ul.innerHTML = spacer != true ? "".concat(tablist) : "".concat(tablist, "<li role=\"separator\" class=\"separator\"></li>");
tabGroup.insertBefore(ul, tabGroup.firstChild);
tabGroup.querySelectorAll('[role="tab"]').forEach(function (tab) {
tab.addEventListener("click", function () {
var siblings = Array.from(tab.parentNode.children);
siblings.forEach(function (sibling) {
return sibling.classList.remove("selected");
});
tab.classList.add("selected");
var tabPanels = Array.from(tab.parentNode.parentNode.children).filter(function (child) {
return child.getAttribute("role") === "tabpanel";
});
tabPanels.forEach(function (panel) {
return panel.classList.remove("open");
});
var tabPanelId = tab.getAttribute("id").replace("tab", "tab-panel");
document.getElementById(tabPanelId).classList.add("open");
tab.addEventListener("click", function (e) {
if (e.altKey && typeof args.altModifier == "function") {
args.altModifier(tab);
} else if (e.shiftKey && typeof args.shiftModifier == "function") {
args.shiftModifier(tab);
} else if (e.metaKey && typeof args.metaModifier == "function") {
args.metaModifier(tab);
} else {
var siblings = Array.from(tab.parentNode.children);
siblings.forEach(function (sibling) {
return sibling.classList.remove("selected");
});
tab.classList.add("selected");
var tabPanels = Array.from(tab.parentNode.parentNode.children).filter(function (child) {
return child.getAttribute("role") === "tabpanel";
});
tabPanels.forEach(function (panel) {
return panel.classList.remove("open");
});
var tabPanelId = tab.getAttribute("id").replace("tab", "tab-panel");
document.getElementById(tabPanelId).classList.add("open");
}
});
tab.addEventListener("keypress", function (e) {
e.preventDefault();
@@ -3246,7 +3288,10 @@ function init() {
});
}
if (document.location.hash != "" && document.location.hash.substring(0, 5) == "#tab-") {
document.querySelector(document.location.hash).dispatchEvent(click);
waitForElement(document.location.hash).then(function (el) {
el.scrollIntoView();
el.dispatchEvent(click);
});
}
});
}
@@ -3369,10 +3414,12 @@ __webpack_require__.r(__webpack_exports__);
// init core
// init c
_core_core_js__WEBPACK_IMPORTED_MODULE_0__.init({
success: function success(a) {
_pg_patterns_core_tabs_tabs_js__WEBPACK_IMPORTED_MODULE_9__.init(a);
_pg_patterns_core_tabs_tabs_js__WEBPACK_IMPORTED_MODULE_9__.init(a, true, {
shiftModifier: _core_core_js__WEBPACK_IMPORTED_MODULE_0__.getTabPath
});
_pg_patterns_core_switch_switch_js__WEBPACK_IMPORTED_MODULE_8__.init(a);
_pg_patterns_core_sticky_note_sticky_note_js__WEBPACK_IMPORTED_MODULE_7__.init(a);
},