Browse Source

Run prettier on JS files

$ node node_modules/.bin/prettier static/js/ --write
merge-requests/173/head
Andrew Shu 4 weeks ago
parent
commit
6b3c247963
  1. 7
      tildes/static/js/behaviors/auto-focus.js
  2. 10
      tildes/static/js/behaviors/autocomplete-chip-clear.js
  3. 33
      tildes/static/js/behaviors/autocomplete-input.js
  4. 20
      tildes/static/js/behaviors/autocomplete-menu-item.js
  5. 4
      tildes/static/js/behaviors/autocomplete-menu.js
  6. 4
      tildes/static/js/behaviors/autoselect-input.js
  7. 8
      tildes/static/js/behaviors/autosubmit-on-change.js
  8. 16
      tildes/static/js/behaviors/cancel-button.js
  9. 25
      tildes/static/js/behaviors/comment-collapse-all-button.js
  10. 4
      tildes/static/js/behaviors/comment-collapse-button.js
  11. 20
      tildes/static/js/behaviors/comment-collapse-read-button.js
  12. 19
      tildes/static/js/behaviors/comment-expand-all-button.js
  13. 27
      tildes/static/js/behaviors/comment-label-button.js
  14. 10
      tildes/static/js/behaviors/comment-parent-button.js
  15. 4
      tildes/static/js/behaviors/comment-reply-form.js
  16. 4
      tildes/static/js/behaviors/confirm-leave-page-unsaved.js
  17. 8
      tildes/static/js/behaviors/copy-button.js
  18. 8
      tildes/static/js/behaviors/ctrl-enter-submit-form.js
  19. 10
      tildes/static/js/behaviors/dropdown-toggle.js
  20. 4
      tildes/static/js/behaviors/external-links-new-tabs.js
  21. 8
      tildes/static/js/behaviors/fadeout-parent-on-success.js
  22. 4
      tildes/static/js/behaviors/group-links-new-tabs.js
  23. 4
      tildes/static/js/behaviors/hide-sidebar-if-open.js
  24. 4
      tildes/static/js/behaviors/hide-sidebar-no-preventdefault.js
  25. 12
      tildes/static/js/behaviors/markdown-edit-tab.js
  26. 14
      tildes/static/js/behaviors/markdown-preview-tab.js
  27. 6
      tildes/static/js/behaviors/prevent-double-submit.js
  28. 4
      tildes/static/js/behaviors/remove-on-click.js
  29. 4
      tildes/static/js/behaviors/remove-on-success.js
  30. 4
      tildes/static/js/behaviors/sidebar-toggle.js
  31. 4
      tildes/static/js/behaviors/stripe-checkout.js
  32. 4
      tildes/static/js/behaviors/stripe-donate-form.js
  33. 8
      tildes/static/js/behaviors/tab.js
  34. 4
      tildes/static/js/behaviors/theme-preview.js
  35. 15
      tildes/static/js/behaviors/theme-selector.js
  36. 6
      tildes/static/js/behaviors/time-period-select.js
  37. 4
      tildes/static/js/behaviors/user-links-new-tabs.js
  38. 10
      tildes/static/js/scripts.js

7
tildes/static/js/behaviors/auto-focus.js

@ -1,14 +1,11 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-auto-focus]", function() {
$.onmount("[data-js-auto-focus]", function () {
var $input = $(this);
// just calling .focus() will place the cursor at the start of the field,
// so un-setting and re-setting the value moves the cursor to the end
var original_val = $input.val();
$input
.focus()
.val("")
.val(original_val);
$input.focus().val("").val(original_val);
});

10
tildes/static/js/behaviors/autocomplete-chip-clear.js

@ -1,7 +1,7 @@
// Copyright (c) 2019 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-autocomplete-chip-clear]", function() {
$.onmount("[data-js-autocomplete-chip-clear]", function () {
function clearChip($chip) {
var $tagsHiddenInput = $("[data-js-autocomplete-hidden-input]");
var $autocompleteInput = $("[data-js-autocomplete-input]");
@ -11,22 +11,22 @@ $.onmount("[data-js-autocomplete-chip-clear]", function() {
$tagsHiddenInput.val(
tags
.filter(function(tag) {
.filter(function (tag) {
return tag !== tagToRemove;
})
.join(",")
.join(","),
);
$chip.remove();
$autocompleteInput.focus();
}
$(this).click(function(event) {
$(this).click(function (event) {
event.preventDefault();
clearChip($(this).parent());
});
$(this).keydown(function(event) {
$(this).keydown(function (event) {
switch (event.key) {
case "Backspace":
event.preventDefault();

33
tildes/static/js/behaviors/autocomplete-input.js

@ -1,7 +1,7 @@
// Copyright (c) 2019 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-autocomplete-input]", function() {
$.onmount("[data-js-autocomplete-input]", function () {
function addChip($input, userTypedComma) {
var $autocompleteContainer = $input
.parents("[data-js-autocomplete-container]")
@ -15,10 +15,10 @@ $.onmount("[data-js-autocomplete-input]", function() {
var inputTags = $input
.val()
.split(",")
.map(function(tag) {
.map(function (tag) {
return tag.trim();
})
.filter(function(tag) {
.filter(function (tag) {
return tag !== "";
});
@ -28,7 +28,7 @@ $.onmount("[data-js-autocomplete-input]", function() {
inputTags = inputTags.slice(0, 1);
}
inputTags.forEach(function(tag) {
inputTags.forEach(function (tag) {
if (!$tagsHiddenInput.val().match(new RegExp("(^|,)" + tag + ","))) {
var clearIcon = document.createElement("a");
clearIcon.classList.add("btn");
@ -47,7 +47,7 @@ $.onmount("[data-js-autocomplete-input]", function() {
$chip.addClass("error");
$chip.attr(
"title",
"Tags may only contain letters, numbers, and spaces."
"Tags may only contain letters, numbers, and spaces.",
);
}
@ -74,7 +74,7 @@ $.onmount("[data-js-autocomplete-input]", function() {
$(this)
.closest("form")
/* eslint-disable-next-line no-unused-vars */
.on("beforeSend.ic", function(evt, elt, data, settings, xhr, requestId) {
.on("beforeSend.ic", function (evt, elt, data, settings, xhr, requestId) {
var $autocompleteInput = $(elt)
.find("[data-js-autocomplete-input]")
.first();
@ -98,7 +98,7 @@ $.onmount("[data-js-autocomplete-input]", function() {
addChip($(this));
}
$(this).focus(function() {
$(this).focus(function () {
var $autocompleteContainer = $(this)
.parents("[data-js-autocomplete-container]")
.first();
@ -109,7 +109,7 @@ $.onmount("[data-js-autocomplete-input]", function() {
$chips.children().removeClass("active");
});
$(this).keydown(function(event) {
$(this).keydown(function (event) {
var $this = $(this);
var $autocompleteMenu = $("[data-js-autocomplete-menu]").first();
var $nextActiveItem = null;
@ -121,7 +121,7 @@ $.onmount("[data-js-autocomplete-input]", function() {
break;
case ",":
// wait for comma to be added to text so addChip() sees it
setTimeout(function() {
setTimeout(function () {
addChip($this, true);
}, 100);
break;
@ -171,7 +171,7 @@ $.onmount("[data-js-autocomplete-input]", function() {
}
});
$(this).keyup(function() {
$(this).keyup(function () {
var $this = $(this);
var $autocompleteMenu = $("[data-js-autocomplete-menu]");
if ($autocompleteMenu) {
@ -183,14 +183,9 @@ $.onmount("[data-js-autocomplete-input]", function() {
var $tagsHiddenInput = $("[data-js-autocomplete-hidden-input]");
var suggestions = $this
.data("js-autocomplete-input")
.filter(function(suggestion) {
.filter(function (suggestion) {
return (
suggestion.startsWith(
$this
.val()
.toLowerCase()
.trim()
) &&
suggestion.startsWith($this.val().toLowerCase().trim()) &&
!$tagsHiddenInput
.val()
.match(new RegExp("(^|,)" + suggestion + ","))
@ -202,7 +197,7 @@ $.onmount("[data-js-autocomplete-input]", function() {
var $autocompleteSuggestions = $("[data-js-autocomplete-suggestions]");
$autocompleteMenu = $('<ol class="menu" data-js-autocomplete-menu>');
suggestions.forEach(function(suggestion) {
suggestions.forEach(function (suggestion) {
$autocompleteMenu.append(
'<li class="menu-item">' +
'<a href="#" data-js-autocomplete-menu-item>' +
@ -212,7 +207,7 @@ $.onmount("[data-js-autocomplete-input]", function() {
"</div>" +
"</div>" +
"</a>" +
"</li>"
"</li>",
);
});
$autocompleteSuggestions.append($autocompleteMenu);

20
tildes/static/js/behaviors/autocomplete-menu-item.js

@ -1,7 +1,7 @@
// Copyright (c) 2019 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-autocomplete-menu-item]", function() {
$.onmount("[data-js-autocomplete-menu-item]", function () {
function addChip($menuItem) {
var $autocompleteContainer = $menuItem
.parents("[data-js-autocomplete-container]")
@ -13,7 +13,7 @@ $.onmount("[data-js-autocomplete-menu-item]", function() {
var existingTags = $tagsHiddenInput.val().split(",");
if (
existingTags.every(function(val) {
existingTags.every(function (val) {
return val !== clickedSuggestionText;
})
) {
@ -46,18 +46,16 @@ $.onmount("[data-js-autocomplete-menu-item]", function() {
$.onmount();
}
$(this).click(function(event) {
$(this).click(function (event) {
event.preventDefault();
addChip($(this), event);
});
$(this).keydown(function(event) {
$(this).keydown(function (event) {
var $nextActiveItem = null;
switch (event.key) {
case "Escape":
$("[data-js-autocomplete-menu]")
.parent()
.remove();
$("[data-js-autocomplete-menu]").parent().remove();
break;
case "Enter":
event.preventDefault();
@ -65,9 +63,7 @@ $.onmount("[data-js-autocomplete-menu-item]", function() {
break;
case "ArrowDown":
event.preventDefault();
$nextActiveItem = $(this)
.parent()
.next();
$nextActiveItem = $(this).parent().next();
$nextActiveItem
.children("[data-js-autocomplete-menu-item]")
.first()
@ -75,9 +71,7 @@ $.onmount("[data-js-autocomplete-menu-item]", function() {
break;
case "ArrowUp":
event.preventDefault();
$nextActiveItem = $(this)
.parent()
.prev();
$nextActiveItem = $(this).parent().prev();
$nextActiveItem
.children("[data-js-autocomplete-menu-item]")
.first()

4
tildes/static/js/behaviors/autocomplete-menu.js

@ -1,7 +1,7 @@
// Copyright (c) 2019 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-autocomplete-menu]", function() {
$.onmount("[data-js-autocomplete-menu]", function () {
var $autocompleteContainer = $(this)
.parents("[data-js-autocomplete-container]")
.first();
@ -9,7 +9,7 @@ $.onmount("[data-js-autocomplete-menu]", function() {
$(this)
.children("[data-js-autocomplete-menu-item]")
.each(function(index, $menuItem) {
.each(function (index, $menuItem) {
$menuItem.setAttribute("tabindex", $chips.children().length + index);
});
});

4
tildes/static/js/behaviors/autoselect-input.js

@ -1,8 +1,8 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-autoselect-input]", function() {
$(this).click(function() {
$.onmount("[data-js-autoselect-input]", function () {
$(this).click(function () {
$(this).select();
});
});

8
tildes/static/js/behaviors/autosubmit-on-change.js

@ -1,10 +1,8 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-autosubmit-on-change]", function() {
$(this).change(function() {
$(this)
.closest("form")
.submit();
$.onmount("[data-js-autosubmit-on-change]", function () {
$(this).change(function () {
$(this).closest("form").submit();
});
});

16
tildes/static/js/behaviors/cancel-button.js

@ -1,8 +1,8 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-cancel-button]", function() {
$(this).click(function() {
$.onmount("[data-js-cancel-button]", function () {
$(this).click(function () {
var $parentForm = $(this).closest("form");
var shouldRemove = true;
@ -11,9 +11,11 @@ $.onmount("[data-js-cancel-button]", function() {
var confirmPrompt = $parentForm.attr("data-js-confirm-cancel");
if (confirmPrompt) {
// only prompt if any of the inputs aren't empty
var $nonEmptyFields = $parentForm.find("input,textarea").filter(function() {
return $(this).val();
});
var $nonEmptyFields = $parentForm
.find("input,textarea")
.filter(function () {
return $(this).val();
});
if ($nonEmptyFields.length > 0) {
shouldRemove = window.confirm(confirmPrompt);
@ -23,9 +25,7 @@ $.onmount("[data-js-cancel-button]", function() {
}
if (shouldRemove) {
$(this)
.closest("form")
.remove();
$(this).closest("form").remove();
}
});
});

25
tildes/static/js/behaviors/comment-collapse-all-button.js

@ -1,24 +1,21 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-comment-collapse-all-button]", function() {
$(this).click(function() {
$.onmount("[data-js-comment-collapse-all-button]", function () {
$(this).click(function () {
// first uncollapse any individually collapsed comments
$(".is-comment-collapsed-individual").each(function(idx, child) {
$(child)
.find("[data-js-comment-collapse-button]:first")
.trigger("click");
$(".is-comment-collapsed-individual").each(function (idx, child) {
$(child).find("[data-js-comment-collapse-button]:first").trigger("click");
});
// then collapse all first-level replies
$('.comment[data-comment-depth="1"]:not(.is-comment-collapsed)').each(function(
idx,
child
) {
$(child)
.find("[data-js-comment-collapse-button]:first")
.trigger("click");
});
$('.comment[data-comment-depth="1"]:not(.is-comment-collapsed)').each(
function (idx, child) {
$(child)
.find("[data-js-comment-collapse-button]:first")
.trigger("click");
},
);
$(this).blur();
});

4
tildes/static/js/behaviors/comment-collapse-button.js

@ -1,8 +1,8 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-comment-collapse-button]", function() {
$(this).click(function() {
$.onmount("[data-js-comment-collapse-button]", function () {
$(this).click(function () {
var $this = $(this);
var $comment = $this.closest(".comment");

20
tildes/static/js/behaviors/comment-collapse-read-button.js

@ -1,30 +1,30 @@
// Copyright (c) 2019 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-comment-collapse-read-button]", function() {
var commentExpand = function(idx, elem) {
$.onmount("[data-js-comment-collapse-read-button]", function () {
var commentExpand = function (idx, elem) {
$(elem).removeClass("is-comment-collapsed");
$(elem).removeClass("is-comment-collapsed-individual");
};
var commentCollapse = function(idx, elem) {
var commentCollapse = function (idx, elem) {
$(elem).removeClass("is-comment-collapsed-individual");
$(elem).addClass("is-comment-collapsed");
};
var commentCollapseIndividual = function(idx, elem) {
var commentCollapseIndividual = function (idx, elem) {
$(elem).removeClass("is-comment-collapsed");
$(elem).addClass("is-comment-collapsed-individual");
};
$(this).click(function() {
$(this).click(function () {
// expand all comments to start with consistent state
$(".is-comment-collapsed, .is-comment-collapsed-individual").each(
commentExpand
commentExpand,
);
// fully collapse the "shallowest" comment in a branch with no new descendants
$(".comment").each(function(idx, elem) {
$(".comment").each(function (idx, elem) {
if (
$(elem).parents(".is-comment-collapsed").length === 0 &&
$(elem).find(".is-comment-new").length === 0
@ -33,7 +33,7 @@ $.onmount("[data-js-comment-collapse-read-button]", function() {
});
// expand new comments
$(".is-comment-new").each(function(idx, elem) {
$(".is-comment-new").each(function (idx, elem) {
$(elem)
// expand new comments just in case they were collapsed above
.each(commentExpand)
@ -45,10 +45,10 @@ $.onmount("[data-js-comment-collapse-read-button]", function() {
// immediate parent of a new comment (in the case one new comment
// responds to another)
.parents(".comment")
.each(function(idx2, ancestor) {
.each(function (idx2, ancestor) {
if (
$(ancestor).find(
"> .comment-tree > .comment-tree-item > .is-comment-new"
"> .comment-tree > .comment-tree-item > .is-comment-new",
).length === 0
)
commentCollapseIndividual(idx2, ancestor);

19
tildes/static/js/behaviors/comment-expand-all-button.js

@ -1,16 +1,15 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-comment-expand-all-button]", function() {
$(this).click(function() {
$(".is-comment-collapsed, .is-comment-collapsed-individual").each(function(
idx,
child
) {
$(child)
.find("[data-js-comment-collapse-button]:first")
.trigger("click");
});
$.onmount("[data-js-comment-expand-all-button]", function () {
$(this).click(function () {
$(".is-comment-collapsed, .is-comment-collapsed-individual").each(
function (idx, child) {
$(child)
.find("[data-js-comment-collapse-button]:first")
.trigger("click");
},
);
$(this).blur();
});

27
tildes/static/js/behaviors/comment-label-button.js

@ -1,13 +1,11 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-comment-label-button]", function() {
$(this).click(function(event) {
$.onmount("[data-js-comment-label-button]", function () {
$(this).click(function (event) {
event.preventDefault();
var $comment = $(this)
.parents(".comment")
.first();
var $comment = $(this).parents(".comment").first();
var userLabels = $comment.attr("data-comment-user-labels");
// check if the label button div already exists and just remove it if so
@ -46,11 +44,11 @@ $.onmount("[data-js-comment-label-button]", function() {
if (labelPrompt) {
label.setAttribute(
"data-ic-confirm",
"Remove your " + labelName + " label?"
"Remove your " + labelName + " label?",
);
}
$(label).on("after.success.ic", function(evt) {
$(label).on("after.success.ic", function (evt) {
var labelName = evt.target.getAttribute("data-js-label-name");
Tildes.removeUserLabel(commentID, labelName);
});
@ -62,7 +60,7 @@ $.onmount("[data-js-comment-label-button]", function() {
label.setAttribute("data-ic-prompt-name", "reason");
}
$(label).on("after.success.ic", function(evt) {
$(label).on("after.success.ic", function (evt) {
var labelName = evt.target.getAttribute("data-js-label-name");
Tildes.addUserLabel(commentID, labelName);
@ -70,7 +68,7 @@ $.onmount("[data-js-comment-label-button]", function() {
// template since they can't use it again anyway
if (labelName === "exemplary") {
var exemplaryButton = labeltemplate.content.querySelector(
".btn-comment-label-exemplary"
".btn-comment-label-exemplary",
);
if (exemplaryButton) {
exemplaryButton.parentElement.remove();
@ -81,21 +79,18 @@ $.onmount("[data-js-comment-label-button]", function() {
label.setAttribute(
"data-ic-target",
"#comment-" + commentID + " .comment-itself:first"
"#comment-" + commentID + " .comment-itself:first",
);
}
// update Intercooler so it knows about these new elements
Intercooler.processNodes(clone);
$comment
.find(".btn-post")
.first()
.after(clone);
$comment.find(".btn-post").first().after(clone);
});
});
Tildes.removeUserLabel = function(commentID, labelName) {
Tildes.removeUserLabel = function (commentID, labelName) {
var $comment = $("#comment-" + commentID);
var userLabels = $comment.attr("data-comment-user-labels").split(" ");
@ -110,7 +105,7 @@ Tildes.removeUserLabel = function(commentID, labelName) {
$comment.attr("data-comment-user-labels", userLabels.join(" "));
};
Tildes.addUserLabel = function(commentID, labelName) {
Tildes.addUserLabel = function (commentID, labelName) {
var $comment = $("#comment-" + commentID);
var userLabels = $comment.attr("data-comment-user-labels").split(" ");

10
tildes/static/js/behaviors/comment-parent-button.js

@ -1,17 +1,15 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-comment-parent-button]", function() {
$(this).click(function() {
var $comment = $(this)
.parents(".comment")
.first();
$.onmount("[data-js-comment-parent-button]", function () {
$(this).click(function () {
var $comment = $(this).parents(".comment").first();
var $parentComment = $comment.parents(".comment").first();
var backButton = document.createElement("a");
backButton.setAttribute(
"href",
"#comment-" + $comment.attr("data-comment-id36")
"#comment-" + $comment.attr("data-comment-id36"),
);
backButton.setAttribute("class", "comment-nav-link");
backButton.setAttribute("data-js-comment-back-button", "");

4
tildes/static/js/behaviors/comment-reply-form.js

@ -1,7 +1,7 @@
// Copyright (c) 2020 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-comment-reply-form]", function() {
$.onmount("[data-js-comment-reply-form]", function () {
var $this = $(this);
// the parent comment's Reply button (that was clicked to create this form)
@ -14,7 +14,7 @@ $.onmount("[data-js-comment-reply-form]", function() {
$replyButton.css("pointer-events", "none");
// have the Cancel button re-enable click/hover events on the reply button
$this.find("[data-js-cancel-button]").click(function() {
$this.find("[data-js-cancel-button]").click(function () {
$replyButton.css("pointer-events", "auto");
});

4
tildes/static/js/behaviors/confirm-leave-page-unsaved.js

@ -1,14 +1,14 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-confirm-leave-page-unsaved]", function() {
$.onmount("[data-js-confirm-leave-page-unsaved]", function () {
var $form = $(this);
$form.areYouSure();
// Fixes a strange interaction between Intercooler and AreYouSure, where
// submitting a form by using the keyboard to push the submit button would
// trigger a confirmation prompt before leaving the page.
$form.on("success.ic", function() {
$form.on("success.ic", function () {
$form.removeClass("dirty");
});
});

8
tildes/static/js/behaviors/copy-button.js

@ -1,8 +1,8 @@
// Copyright (c) 2020 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-copy-button]", function() {
$(this).click(function(event) {
$.onmount("[data-js-copy-button]", function () {
$(this).click(function (event) {
event.preventDefault();
var textToCopy;
@ -25,10 +25,10 @@ $.onmount("[data-js-copy-button]", function() {
});
});
Tildes.writeToClipboard = function(text) {
Tildes.writeToClipboard = function (text) {
// Minimal polyfill for writing to clipboard, by Lucas Garron
// https://gist.github.com/lgarron/d1dee380f4ed9d825ca7
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
var success = false;
function listener(event) {
event.clipboardData.setData("text/plain", text);

8
tildes/static/js/behaviors/ctrl-enter-submit-form.js

@ -1,15 +1,13 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-ctrl-enter-submit-form]", function() {
$(this).keydown(function(event) {
$.onmount("[data-js-ctrl-enter-submit-form]", function () {
$(this).keydown(function (event) {
if (
(event.ctrlKey || event.metaKey) &&
(event.keyCode == 13 || event.keyCode == 10)
) {
$(this)
.closest("form")
.submit();
$(this).closest("form").submit();
}
});
});

10
tildes/static/js/behaviors/dropdown-toggle.js

@ -4,8 +4,8 @@
// Note: unlike almost all other JS behaviors, this one does not attach to elements
// based on the presence of a data-js-* HTML attribute. This attaches to any element
// with the dropdown-toggle class so that this behavior is always applied to dropdowns.
$.onmount(".dropdown-toggle", function() {
$(this).click(function() {
$.onmount(".dropdown-toggle", function () {
$(this).click(function () {
var $this = $(this);
// Spectre.css's dropdown menus use the focus event to display the menu,
@ -32,7 +32,7 @@ $.onmount(".dropdown-toggle", function() {
.parent()
.toggleClass(
"dropdown-right",
$this.offset().left + $this.outerWidth() - $menu.outerWidth() > 0
$this.offset().left + $this.outerWidth() - $menu.outerWidth() > 0,
);
// If the menu extends past the bottom of the viewport, or the site footer
@ -45,11 +45,11 @@ $.onmount(".dropdown-toggle", function() {
.parent()
.toggleClass(
"dropdown-bottom",
menuBottom > viewportHeight + scrollTop || menuBottom > footerTop
menuBottom > viewportHeight + scrollTop || menuBottom > footerTop,
);
});
$(this).blur(function() {
$(this).blur(function () {
$(this).removeClass("active");
});
});

4
tildes/static/js/behaviors/external-links-new-tabs.js

@ -1,11 +1,11 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-external-links-new-tabs]", function() {
$.onmount("[data-js-external-links-new-tabs]", function () {
// Open external links in topic, comment, and message text in new tabs
$(this)
.find("a")
.each(function() {
.each(function () {
if (this.host !== window.location.host) {
$(this).attr("target", "_blank");
$(this).attr("rel", "noopener");

8
tildes/static/js/behaviors/fadeout-parent-on-success.js

@ -1,10 +1,8 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-fadeout-parent-on-success]", function() {
$(this).on("after.success.ic", function() {
$(this)
.parent()
.fadeOut("fast");
$.onmount("[data-js-fadeout-parent-on-success]", function () {
$(this).on("after.success.ic", function () {
$(this).parent().fadeOut("fast");
});
});

4
tildes/static/js/behaviors/group-links-new-tabs.js

@ -1,11 +1,11 @@
// Copyright (c) 2020 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-group-links-new-tabs]", function() {
$.onmount("[data-js-group-links-new-tabs]", function () {
// Open links to groups on Tildes in new tabs
$(this)
.find(".link-group")
.each(function() {
.each(function () {
$(this).attr("target", "_blank");
});
});

4
tildes/static/js/behaviors/hide-sidebar-if-open.js

@ -1,8 +1,8 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-hide-sidebar-if-open]", function() {
$(this).on("click", function(event) {
$.onmount("[data-js-hide-sidebar-if-open]", function () {
$(this).on("click", function (event) {
if ($("#sidebar").hasClass("is-sidebar-displayed")) {
event.preventDefault();
event.stopPropagation();

4
tildes/static/js/behaviors/hide-sidebar-no-preventdefault.js

@ -1,8 +1,8 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-hide-sidebar-no-preventdefault]", function() {
$(this).on("click", function() {
$.onmount("[data-js-hide-sidebar-no-preventdefault]", function () {
$(this).on("click", function () {
$("#sidebar").removeClass("is-sidebar-displayed");
});
});

12
tildes/static/js/behaviors/markdown-edit-tab.js

@ -1,14 +1,10 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-markdown-edit-tab]", function() {
$(this).click(function() {
var $editTextarea = $(this)
.closest("form")
.find('[name="markdown"]');
var $previewDiv = $(this)
.closest("form")
.find(".form-markdown-preview");
$.onmount("[data-js-markdown-edit-tab]", function () {
$(this).click(function () {
var $editTextarea = $(this).closest("form").find('[name="markdown"]');
var $previewDiv = $(this).closest("form").find(".form-markdown-preview");
$editTextarea.removeClass("d-none");
$previewDiv.addClass("d-none");

14
tildes/static/js/behaviors/markdown-preview-tab.js

@ -1,14 +1,10 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-markdown-preview-tab]", function() {
$(this).click(function() {
var $editTextarea = $(this)
.closest("form")
.find('[name="markdown"]');
var $previewDiv = $(this)
.closest("form")
.find(".form-markdown-preview");
$.onmount("[data-js-markdown-preview-tab]", function () {
$(this).click(function () {
var $editTextarea = $(this).closest("form").find('[name="markdown"]');
var $previewDiv = $(this).closest("form").find(".form-markdown-preview");
var $previewErrors = $(this)
.closest("form")
.find(".text-status-message.text-error");
@ -18,7 +14,7 @@ $.onmount("[data-js-markdown-preview-tab]", function() {
$previewErrors.remove();
});
$(this).on("after.success.ic success.ic", function(event) {
$(this).on("after.success.ic success.ic", function (event) {
// Stop intercooler event from bubbling up past this button. This
// prevents behaviors on parent elements from mistaking a successful
// "preview" from a successful "submit".

6
tildes/static/js/behaviors/prevent-double-submit.js

@ -1,9 +1,9 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-prevent-double-submit]", function() {
$.onmount("[data-js-prevent-double-submit]", function () {
/* eslint-disable-next-line no-unused-vars */
$(this).on("beforeSend.ic", function(evt, elt, data, settings, xhr, requestId) {
$(this).on("beforeSend.ic", function (evt, elt, data, settings, xhr, requestId) {
var $form = $(this);
if ($form.attr("data-js-submitting") !== undefined) {
@ -14,7 +14,7 @@ $.onmount("[data-js-prevent-double-submit]", function() {
}
});
$(this).on("complete.ic", function() {
$(this).on("complete.ic", function () {
$(this).removeAttr("data-js-submitting");
});
});

4
tildes/static/js/behaviors/remove-on-click.js

@ -1,8 +1,8 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-remove-on-click]", function() {
$(this).on("click", function() {
$.onmount("[data-js-remove-on-click]", function () {
$(this).on("click", function () {
$(this).remove();
});
});

4
tildes/static/js/behaviors/remove-on-success.js

@ -1,8 +1,8 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-remove-on-success]", function() {
$(this).on("after.success.ic", function() {
$.onmount("[data-js-remove-on-success]", function () {
$(this).on("after.success.ic", function () {
$(this).remove();
});
});

4
tildes/static/js/behaviors/sidebar-toggle.js

@ -1,8 +1,8 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-sidebar-toggle]", function() {
$(this).click(function(event) {
$.onmount("[data-js-sidebar-toggle]", function () {
$(this).click(function (event) {
event.preventDefault();
event.stopPropagation();

4
tildes/static/js/behaviors/stripe-checkout.js

@ -1,10 +1,10 @@
// Copyright (c) 2019 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-stripe-checkout]", function() {
$.onmount("[data-js-stripe-checkout]", function () {
/* eslint-disable-next-line no-undef */
var stripe = Stripe($(this).attr("data-js-stripe-checkout"));
stripe.redirectToCheckout({
sessionId: $(this).attr("data-js-stripe-checkout-session")
sessionId: $(this).attr("data-js-stripe-checkout-session"),
});
});

4
tildes/static/js/behaviors/stripe-donate-form.js

@ -1,8 +1,8 @@
// Copyright (c) 2019 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-stripe-donate-form]", function() {
$(this).on("submit", function(event) {
$.onmount("[data-js-stripe-donate-form]", function () {
$(this).on("submit", function (event) {
var $amountInput = $(this).find("#amount");
var amount = $amountInput.val();

8
tildes/static/js/behaviors/tab.js

@ -1,11 +1,9 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-tab]", function() {
$(this).click(function() {
$(this)
.siblings()
.removeClass("active");
$.onmount("[data-js-tab]", function () {
$(this).click(function () {
$(this).siblings().removeClass("active");
$(this).addClass("active");
});
});

4
tildes/static/js/behaviors/theme-preview.js

@ -1,8 +1,8 @@
// Copyright (c) 2019 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-theme-preview]", function() {
$(this).click(function() {
$.onmount("[data-js-theme-preview]", function () {
$(this).click(function () {
var newTheme = $(this).attr("data-js-theme-preview");
Tildes.changeTheme(newTheme);

15
tildes/static/js/behaviors/theme-selector.js

@ -1,17 +1,14 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-theme-selector]", function() {
$.onmount("[data-js-theme-selector]", function () {
Tildes.toggleSetDefaultThemeButton($(this));
$(this).change(function(event) {
$(this).change(function (event) {
event.preventDefault();
// hide any IC change message
$(this)
.parent()
.find(".text-status-message")
.hide();
$(this).parent().find(".text-status-message").hide();
var new_theme = $(this).val();
@ -28,10 +25,8 @@ $.onmount("[data-js-theme-selector]", function() {
});
});
Tildes.toggleSetDefaultThemeButton = function(element) {
var selected_text = $(element)
.find("option:selected")
.text();
Tildes.toggleSetDefaultThemeButton = function (element) {
var selected_text = $(element).find("option:selected").text();
var $setDefaultButton = $("#button-set-default-theme");
// set visibility of 'Set as account default' button
if (selected_text.indexOf("account default") === -1) {

6
tildes/static/js/behaviors/time-period-select.js

@ -1,8 +1,8 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-time-period-select]", function() {
$(this).change(function() {
$.onmount("[data-js-time-period-select]", function () {
$(this).change(function () {
var periodValue = this.value;
if (periodValue === "other") {
@ -12,7 +12,7 @@ $.onmount("[data-js-time-period-select]", function() {
// prompt for a time period until they enter a valid one
while (!validRegex.test(enteredPeriod)) {
enteredPeriod = prompt(
'Enter a custom time period (number of hours, or add a "d" suffix for days):'
'Enter a custom time period (number of hours, or add a "d" suffix for days):',
);
// exit if they specifically cancelled the prompt

4
tildes/static/js/behaviors/user-links-new-tabs.js

@ -1,11 +1,11 @@
// Copyright (c) 2020 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-user-links-new-tabs]", function() {
$.onmount("[data-js-user-links-new-tabs]", function () {
// Open links to users on Tildes in new tabs
$(this)
.find(".link-user")
.each(function() {
.each(function () {
$(this).attr("target", "_blank");
});
});

10
tildes/static/js/scripts.js

@ -1,12 +1,12 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
$(function() {
$(function () {
$.onmount();
// Add the CSRF token to all Intercooler AJAX requests as a header
/* eslint-disable-next-line no-unused-vars */
$(document).on("beforeAjaxSend.ic", function(event, ajaxSetup, elt) {
$(document).on("beforeAjaxSend.ic", function (event, ajaxSetup, elt) {
var token = $("meta[name='csrftoken']").attr("content");
ajaxSetup.headers["X-CSRF-Token"] = token;
@ -31,14 +31,14 @@ $(function() {
});
// Automatically call onmount whenever Intercooler swaps in new content
Intercooler.ready(function() {
Intercooler.ready(function () {
$.onmount();
});
// Called whenever an Intercooler request completes; used to display an error or
// success message in an appropriate place near supported elements.
/* eslint-disable-next-line no-unused-vars */
$(document).on("complete.ic", function(evt, elt, data, status, xhr, requestId) {
$(document).on("complete.ic", function (evt, elt, data, status, xhr, requestId) {
var $container = null;
// Only display these messages if the triggering element was <form> or <button>
@ -99,7 +99,7 @@ if (!window.Tildes) {
window.Tildes = {};
}
Tildes.changeTheme = function(newThemeName) {
Tildes.changeTheme = function (newThemeName) {
// remove any theme classes currently on the body
var $body = $("body").first();
var bodyClasses = $body[0].className.split(" ");

Loading…
Cancel
Save