Browse Source

Run prettier on JS files

$ node node_modules/.bin/prettier static/js/ --write
merge-requests/176/head
Andrew Shu 3 months ago
parent
commit
d7aa69139b
  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> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-auto-focus]", function() {
$.onmount("[data-js-auto-focus]", function () {
var $input = $(this); var $input = $(this);
// just calling .focus() will place the cursor at the start of the field, // 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 // so un-setting and re-setting the value moves the cursor to the end
var original_val = $input.val(); 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> // Copyright (c) 2019 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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) { function clearChip($chip) {
var $tagsHiddenInput = $("[data-js-autocomplete-hidden-input]"); var $tagsHiddenInput = $("[data-js-autocomplete-hidden-input]");
var $autocompleteInput = $("[data-js-autocomplete-input]"); var $autocompleteInput = $("[data-js-autocomplete-input]");
@ -11,22 +11,22 @@ $.onmount("[data-js-autocomplete-chip-clear]", function() {
$tagsHiddenInput.val( $tagsHiddenInput.val(
tags tags
.filter(function(tag) {
.filter(function (tag) {
return tag !== tagToRemove; return tag !== tagToRemove;
}) })
.join(",")
.join(","),
); );
$chip.remove(); $chip.remove();
$autocompleteInput.focus(); $autocompleteInput.focus();
} }
$(this).click(function(event) {
$(this).click(function (event) {
event.preventDefault(); event.preventDefault();
clearChip($(this).parent()); clearChip($(this).parent());
}); });
$(this).keydown(function(event) {
$(this).keydown(function (event) {
switch (event.key) { switch (event.key) {
case "Backspace": case "Backspace":
event.preventDefault(); event.preventDefault();

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

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

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

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

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

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

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

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

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

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

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

@ -1,13 +1,11 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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(); event.preventDefault();
var $comment = $(this)
.parents(".comment")
.first();
var $comment = $(this).parents(".comment").first();
var userLabels = $comment.attr("data-comment-user-labels"); var userLabels = $comment.attr("data-comment-user-labels");
// check if the label button div already exists and just remove it if so // 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) { if (labelPrompt) {
label.setAttribute( label.setAttribute(
"data-ic-confirm", "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"); var labelName = evt.target.getAttribute("data-js-label-name");
Tildes.removeUserLabel(commentID, labelName); Tildes.removeUserLabel(commentID, labelName);
}); });
@ -62,7 +60,7 @@ $.onmount("[data-js-comment-label-button]", function() {
label.setAttribute("data-ic-prompt-name", "reason"); 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"); var labelName = evt.target.getAttribute("data-js-label-name");
Tildes.addUserLabel(commentID, labelName); Tildes.addUserLabel(commentID, labelName);
@ -70,7 +68,7 @@ $.onmount("[data-js-comment-label-button]", function() {
// template since they can't use it again anyway // template since they can't use it again anyway
if (labelName === "exemplary") { if (labelName === "exemplary") {
var exemplaryButton = labeltemplate.content.querySelector( var exemplaryButton = labeltemplate.content.querySelector(
".btn-comment-label-exemplary"
".btn-comment-label-exemplary",
); );
if (exemplaryButton) { if (exemplaryButton) {
exemplaryButton.parentElement.remove(); exemplaryButton.parentElement.remove();
@ -81,21 +79,18 @@ $.onmount("[data-js-comment-label-button]", function() {
label.setAttribute( label.setAttribute(
"data-ic-target", "data-ic-target",
"#comment-" + commentID + " .comment-itself:first"
"#comment-" + commentID + " .comment-itself:first",
); );
} }
// update Intercooler so it knows about these new elements // update Intercooler so it knows about these new elements
Intercooler.processNodes(clone); 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 $comment = $("#comment-" + commentID);
var userLabels = $comment.attr("data-comment-user-labels").split(" "); 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(" ")); $comment.attr("data-comment-user-labels", userLabels.join(" "));
}; };
Tildes.addUserLabel = function(commentID, labelName) {
Tildes.addUserLabel = function (commentID, labelName) {
var $comment = $("#comment-" + commentID); var $comment = $("#comment-" + commentID);
var userLabels = $comment.attr("data-comment-user-labels").split(" "); 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> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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 $parentComment = $comment.parents(".comment").first();
var backButton = document.createElement("a"); var backButton = document.createElement("a");
backButton.setAttribute( backButton.setAttribute(
"href", "href",
"#comment-" + $comment.attr("data-comment-id36")
"#comment-" + $comment.attr("data-comment-id36"),
); );
backButton.setAttribute("class", "comment-nav-link"); backButton.setAttribute("class", "comment-nav-link");
backButton.setAttribute("data-js-comment-back-button", ""); 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> // Copyright (c) 2020 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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); var $this = $(this);
// the parent comment's Reply button (that was clicked to create this form) // 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"); $replyButton.css("pointer-events", "none");
// have the Cancel button re-enable click/hover events on the reply button // 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"); $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> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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); var $form = $(this);
$form.areYouSure(); $form.areYouSure();
// Fixes a strange interaction between Intercooler and AreYouSure, where // Fixes a strange interaction between Intercooler and AreYouSure, where
// submitting a form by using the keyboard to push the submit button would // submitting a form by using the keyboard to push the submit button would
// trigger a confirmation prompt before leaving the page. // trigger a confirmation prompt before leaving the page.
$form.on("success.ic", function() {
$form.on("success.ic", function () {
$form.removeClass("dirty"); $form.removeClass("dirty");
}); });
}); });

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

@ -1,8 +1,8 @@
// Copyright (c) 2020 Tildes contributors <code@tildes.net> // Copyright (c) 2020 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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(); event.preventDefault();
var textToCopy; 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 // Minimal polyfill for writing to clipboard, by Lucas Garron
// https://gist.github.com/lgarron/d1dee380f4ed9d825ca7 // https://gist.github.com/lgarron/d1dee380f4ed9d825ca7
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
var success = false; var success = false;
function listener(event) { function listener(event) {
event.clipboardData.setData("text/plain", text); 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> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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 ( if (
(event.ctrlKey || event.metaKey) && (event.ctrlKey || event.metaKey) &&
(event.keyCode == 13 || event.keyCode == 10) (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 // 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 // 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. // 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); var $this = $(this);
// Spectre.css's dropdown menus use the focus event to display the menu, // Spectre.css's dropdown menus use the focus event to display the menu,
@ -32,7 +32,7 @@ $.onmount(".dropdown-toggle", function() {
.parent() .parent()
.toggleClass( .toggleClass(
"dropdown-right", "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 // If the menu extends past the bottom of the viewport, or the site footer
@ -45,11 +45,11 @@ $.onmount(".dropdown-toggle", function() {
.parent() .parent()
.toggleClass( .toggleClass(
"dropdown-bottom", "dropdown-bottom",
menuBottom > viewportHeight + scrollTop || menuBottom > footerTop
menuBottom > viewportHeight + scrollTop || menuBottom > footerTop,
); );
}); });
$(this).blur(function() {
$(this).blur(function () {
$(this).removeClass("active"); $(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> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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 // Open external links in topic, comment, and message text in new tabs
$(this) $(this)
.find("a") .find("a")
.each(function() {
.each(function () {
if (this.host !== window.location.host) { if (this.host !== window.location.host) {
$(this).attr("target", "_blank"); $(this).attr("target", "_blank");
$(this).attr("rel", "noopener"); $(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> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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> // Copyright (c) 2020 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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 // Open links to groups on Tildes in new tabs
$(this) $(this)
.find(".link-group") .find(".link-group")
.each(function() {
.each(function () {
$(this).attr("target", "_blank"); $(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> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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")) { if ($("#sidebar").hasClass("is-sidebar-displayed")) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();

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

@ -1,8 +1,8 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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"); $("#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> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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"); $editTextarea.removeClass("d-none");
$previewDiv.addClass("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> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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) var $previewErrors = $(this)
.closest("form") .closest("form")
.find(".text-status-message.text-error"); .find(".text-status-message.text-error");
@ -18,7 +14,7 @@ $.onmount("[data-js-markdown-preview-tab]", function() {
$previewErrors.remove(); $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 // Stop intercooler event from bubbling up past this button. This
// prevents behaviors on parent elements from mistaking a successful // prevents behaviors on parent elements from mistaking a successful
// "preview" from a successful "submit". // "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> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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 */ /* 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); var $form = $(this);
if ($form.attr("data-js-submitting") !== undefined) { 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"); $(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> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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(); $(this).remove();
}); });
}); });

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

@ -1,8 +1,8 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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(); $(this).remove();
}); });
}); });

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

@ -1,8 +1,8 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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.preventDefault();
event.stopPropagation(); event.stopPropagation();

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

@ -1,10 +1,10 @@
// Copyright (c) 2019 Tildes contributors <code@tildes.net> // Copyright (c) 2019 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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 */ /* eslint-disable-next-line no-undef */
var stripe = Stripe($(this).attr("data-js-stripe-checkout")); var stripe = Stripe($(this).attr("data-js-stripe-checkout"));
stripe.redirectToCheckout({ 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> // Copyright (c) 2019 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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 $amountInput = $(this).find("#amount");
var amount = $amountInput.val(); var amount = $amountInput.val();

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

@ -1,11 +1,9 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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"); $(this).addClass("active");
}); });
}); });

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

@ -1,8 +1,8 @@
// Copyright (c) 2019 Tildes contributors <code@tildes.net> // Copyright (c) 2019 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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"); var newTheme = $(this).attr("data-js-theme-preview");
Tildes.changeTheme(newTheme); Tildes.changeTheme(newTheme);

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

@ -1,17 +1,14 @@
// Copyright (c) 2018 Tildes contributors <code@tildes.net> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // SPDX-License-Identifier: AGPL-3.0-or-later
$.onmount("[data-js-theme-selector]", function() {
$.onmount("[data-js-theme-selector]", function () {
Tildes.toggleSetDefaultThemeButton($(this)); Tildes.toggleSetDefaultThemeButton($(this));
$(this).change(function(event) {
$(this).change(function (event) {
event.preventDefault(); event.preventDefault();
// hide any IC change message // hide any IC change message
$(this)
.parent()
.find(".text-status-message")
.hide();
$(this).parent().find(".text-status-message").hide();
var new_theme = $(this).val(); 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"); var $setDefaultButton = $("#button-set-default-theme");
// set visibility of 'Set as account default' button // set visibility of 'Set as account default' button
if (selected_text.indexOf("account default") === -1) { 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> // Copyright (c) 2018 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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; var periodValue = this.value;
if (periodValue === "other") { 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 // prompt for a time period until they enter a valid one
while (!validRegex.test(enteredPeriod)) { while (!validRegex.test(enteredPeriod)) {
enteredPeriod = prompt( 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 // 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> // Copyright (c) 2020 Tildes contributors <code@tildes.net>
// SPDX-License-Identifier: AGPL-3.0-or-later // 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 // Open links to users on Tildes in new tabs
$(this) $(this)
.find(".link-user") .find(".link-user")
.each(function() {
.each(function () {
$(this).attr("target", "_blank"); $(this).attr("target", "_blank");
}); });
}); });

10
tildes/static/js/scripts.js

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

Loading…
Cancel
Save