Skip to content

Commit

Permalink
Switch internal JavaScript functions and members to camelCase.
Browse files Browse the repository at this point in the history
This leaves the public API with two snake case functions, show_toolbar and
hide_toolbar.
  • Loading branch information
tim-schilling committed Oct 22, 2022
1 parent 99d5d79 commit 4499607
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
84 changes: 42 additions & 42 deletions debug_toolbar/static/debug_toolbar/js/toolbar.js
Expand Up @@ -2,7 +2,7 @@ import { $$, ajax, replaceToolbarState, debounce } from "./utils.js";

function onKeyDown(event) {
if (event.keyCode === 27) {
djdt.hide_one_level();
djdt.hideOneLevel();
}
}

Expand Down Expand Up @@ -30,9 +30,9 @@ const djdt = {
const panelId = this.className;
const current = document.getElementById(panelId);
if ($$.visible(current)) {
djdt.hide_panels();
djdt.hidePanels();
} else {
djdt.hide_panels();
djdt.hidePanels();

$$.show(current);
this.parentElement.classList.add("djdt-active");
Expand All @@ -41,13 +41,13 @@ const djdt = {
const inner = current.querySelector(
".djDebugPanelContent .djdt-scroll"
),
store_id = djDebug.dataset.storeId;
if (store_id && inner.children.length === 0) {
storeId = djDebug.dataset.storeId;
if (storeId && inner.children.length === 0) {
const url = new URL(
djDebug.dataset.renderPanelUrl,
window.location
);
url.searchParams.append("store_id", store_id);
url.searchParams.append("store_id", storeId);
url.searchParams.append("panel_id", panelId);
ajax(url).then(function (data) {
inner.previousElementSibling.remove(); // Remove AJAX loader
Expand All @@ -71,7 +71,7 @@ const djdt = {
}
);
$$.on(document.body, "click", "#djDebug .djDebugClose", function () {
djdt.hide_one_level();
djdt.hideOneLevel();
});
$$.on(
document.body,
Expand All @@ -94,18 +94,18 @@ const djdt = {
event.preventDefault();

let url;
const ajax_data = {};
const ajaxData = {};

if (this.tagName === "BUTTON") {
const form = this.closest("form");
url = this.formAction;
ajax_data.method = form.method.toUpperCase();
ajax_data.body = new FormData(form);
ajaxData.method = form.method.toUpperCase();
ajaxData.body = new FormData(form);
} else if (this.tagName === "A") {
url = this.href;
}

ajax(url, ajax_data).then(function (data) {
ajax(url, ajaxData).then(function (data) {
const win = document.getElementById("djDebugWindow");
win.innerHTML = data.content;
$$.show(win);
Expand All @@ -117,24 +117,24 @@ const djdt = {
const id = this.dataset.toggleId;
const toggleOpen = "+";
const toggleClose = "-";
const open_me = this.textContent === toggleOpen;
const openMe = this.textContent === toggleOpen;
const name = this.dataset.toggleName;
const container = document.getElementById(name + "_" + id);
container
.querySelectorAll(".djDebugCollapsed")
.forEach(function (e) {
$$.toggle(e, open_me);
$$.toggle(e, openMe);
});
container
.querySelectorAll(".djDebugUncollapsed")
.forEach(function (e) {
$$.toggle(e, !open_me);
$$.toggle(e, !openMe);
});
const self = this;
this.closest(".djDebugPanelContent")
.querySelectorAll(".djToggleDetails_" + id)
.forEach(function (e) {
if (open_me) {
if (openMe) {
e.classList.add("djSelected");
e.classList.remove("djUnselected");
self.textContent = toggleClose;
Expand All @@ -152,12 +152,12 @@ const djdt = {

$$.on(document.body, "click", "#djHideToolBarButton", function (event) {
event.preventDefault();
djdt.hide_toolbar();
djdt.hideToolbar();
});

$$.on(document.body, "click", "#djShowToolBarButton", function () {
if (!djdt.handleDragged) {
djdt.show_toolbar();
djdt.showToolbar();
}
});
let startPageY, baseY;
Expand Down Expand Up @@ -199,26 +199,26 @@ const djdt = {
requestAnimationFrame(function () {
djdt.handleDragged = false;
});
djdt.ensure_handle_visibility();
djdt.ensureHandleVisibility();
}
});
const djDebug = getDebugElement();
// Make sure the debug element is rendered at least once.
// show_toolbar will continue to show it in the future if the
// showToolbar will continue to show it in the future if the
// entire DOM is reloaded.
$$.show(djDebug);
const show =
localStorage.getItem("djdt.show") || djDebug.dataset.defaultShow;
if (show === "true") {
djdt.show_toolbar();
djdt.showToolbar();
} else {
djdt.hide_toolbar();
djdt.hideToolbar();
}
if (djDebug.dataset.sidebarUrl !== undefined) {
djdt.update_on_ajax();
djdt.updateOnAjax();
}
},
hide_panels() {
hidePanels() {
const djDebug = getDebugElement();
$$.hide(document.getElementById("djDebugWindow"));
djDebug.querySelectorAll(".djdt-panelContent").forEach(function (e) {
Expand All @@ -228,7 +228,7 @@ const djdt = {
e.classList.remove("djdt-active");
});
},
ensure_handle_visibility() {
ensureHandleVisibility() {
const handle = document.getElementById("djDebugToolbarHandle");
// set handle position
const handleTop = Math.min(
Expand All @@ -237,42 +237,42 @@ const djdt = {
);
handle.style.top = handleTop + "px";
},
hide_toolbar() {
djdt.hide_panels();
hideToolbar() {
djdt.hidePanels();

$$.hide(document.getElementById("djDebugToolbar"));

const handle = document.getElementById("djDebugToolbarHandle");
$$.show(handle);
djdt.ensure_handle_visibility();
window.addEventListener("resize", djdt.ensure_handle_visibility);
djdt.ensureHandleVisibility();
window.addEventListener("resize", djdt.ensureHandleVisibility);
document.removeEventListener("keydown", onKeyDown);

localStorage.setItem("djdt.show", "false");
},
hide_one_level() {
hideOneLevel() {
const win = document.getElementById("djDebugWindow");
if ($$.visible(win)) {
$$.hide(win);
} else {
const toolbar = document.getElementById("djDebugToolbar");
if (toolbar.querySelector("li.djdt-active")) {
djdt.hide_panels();
djdt.hidePanels();
} else {
djdt.hide_toolbar();
djdt.hideToolbar();
}
}
},
show_toolbar() {
showToolbar() {
document.addEventListener("keydown", onKeyDown);
$$.show(document.getElementById("djDebug"));
$$.hide(document.getElementById("djDebugToolbarHandle"));
$$.show(document.getElementById("djDebugToolbar"));
localStorage.setItem("djdt.show", "true");
window.removeEventListener("resize", djdt.ensure_handle_visibility);
window.removeEventListener("resize", djdt.ensureHandleVisibility);
},
update_on_ajax() {
const sidebar_url =
updateOnAjax() {
const sidebarUrl =
document.getElementById("djDebug").dataset.sidebarUrl;
const slowjax = debounce(ajax, 200);

Expand All @@ -285,11 +285,11 @@ const djdt = {
if (
this.getAllResponseHeaders().indexOf("djdt-store-id") >= 0
) {
let store_id = this.getResponseHeader("djdt-store-id");
store_id = encodeURIComponent(store_id);
const dest = `${sidebar_url}?store_id=${store_id}`;
let storeId = this.getResponseHeader("djdt-store-id");
storeId = encodeURIComponent(storeId);
const dest = `${sidebarUrl}?store_id=${storeId}`;
slowjax(dest).then(function (data) {
replaceToolbarState(store_id, data);
replaceToolbarState(storeId, data);
});
}
});
Expand Down Expand Up @@ -339,10 +339,10 @@ const djdt = {
},
};
window.djdt = {
show_toolbar: djdt.show_toolbar,
hide_toolbar: djdt.hide_toolbar,
show_toolbar: djdt.showToolbar,
hide_toolbar: djdt.hideToolbar,
init: djdt.init,
close: djdt.hide_one_level,
close: djdt.hideOneLevel,
cookie: djdt.cookie,
};

Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/static/debug_toolbar/js/utils.js
Expand Up @@ -108,7 +108,7 @@ function ajaxForm(element) {
function replaceToolbarState(newStoreId, data) {
const djDebug = document.getElementById("djDebug");
djDebug.setAttribute("data-store-id", newStoreId);
// Check if response is empty, it could be due to an expired store_id.
// Check if response is empty, it could be due to an expired storeId.
Object.keys(data).forEach(function (panelId) {
const panel = document.getElementById(panelId);
if (panel) {
Expand Down

0 comments on commit 4499607

Please sign in to comment.