Browse Source

Run prettier on JS files

$ node node_modules/.bin/prettier static/js/ --write
merge-requests/173/head
Andrew Shu 3 months ago
parent
commit
6b3c247963
  1. 5
      tildes/static/js/behaviors/auto-focus.js
  2. 2
      tildes/static/js/behaviors/autocomplete-chip-clear.js
  3. 11
      tildes/static/js/behaviors/autocomplete-input.js
  4. 12
      tildes/static/js/behaviors/autocomplete-menu-item.js
  5. 4
      tildes/static/js/behaviors/autosubmit-on-change.js
  6. 8
      tildes/static/js/behaviors/cancel-button.js
  7. 13
      tildes/static/js/behaviors/comment-collapse-all-button.js
  8. 4
      tildes/static/js/behaviors/comment-collapse-read-button.js
  9. 9
      tildes/static/js/behaviors/comment-expand-all-button.js
  10. 15
      tildes/static/js/behaviors/comment-label-button.js
  11. 6
      tildes/static/js/behaviors/comment-parent-button.js
  12. 4
      tildes/static/js/behaviors/ctrl-enter-submit-form.js
  13. 4
      tildes/static/js/behaviors/dropdown-toggle.js
  14. 4
      tildes/static/js/behaviors/fadeout-parent-on-success.js
  15. 8
      tildes/static/js/behaviors/markdown-edit-tab.js
  16. 8
      tildes/static/js/behaviors/markdown-preview-tab.js
  17. 2
      tildes/static/js/behaviors/stripe-checkout.js
  18. 4
      tildes/static/js/behaviors/tab.js
  19. 9
      tildes/static/js/behaviors/theme-selector.js
  20. 2
      tildes/static/js/behaviors/time-period-select.js

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

@ -7,8 +7,5 @@ $.onmount("[data-js-auto-focus]", function() {
// 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);
});

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

@ -14,7 +14,7 @@ $.onmount("[data-js-autocomplete-chip-clear]", function() {
.filter(function (tag) {
return tag !== tagToRemove;
})
.join(",")
.join(","),
);
$chip.remove();

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

@ -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.",
);
}
@ -185,12 +185,7 @@ $.onmount("[data-js-autocomplete-input]", function() {
.data("js-autocomplete-input")
.filter(function (suggestion) {
return (
suggestion.startsWith(
$this
.val()
.toLowerCase()
.trim()
) &&
suggestion.startsWith($this.val().toLowerCase().trim()) &&
!$tagsHiddenInput
.val()
.match(new RegExp("(^|,)" + suggestion + ","))
@ -212,7 +207,7 @@ $.onmount("[data-js-autocomplete-input]", function() {
"</div>" +
"</div>" +
"</a>" +
"</li>"
"</li>",
);
});
$autocompleteSuggestions.append($autocompleteMenu);

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

@ -55,9 +55,7 @@ $.onmount("[data-js-autocomplete-menu-item]", function() {
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/autosubmit-on-change.js

@ -3,8 +3,6 @@
$.onmount("[data-js-autosubmit-on-change]", function () {
$(this).change(function () {
$(this)
.closest("form")
.submit();
$(this).closest("form").submit();
});
});

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

@ -11,7 +11,9 @@ $.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() {
var $nonEmptyFields = $parentForm
.find("input,textarea")
.filter(function () {
return $(this).val();
});
@ -23,9 +25,7 @@ $.onmount("[data-js-cancel-button]", function() {
}
if (shouldRemove) {
$(this)
.closest("form")
.remove();
$(this).closest("form").remove();
}
});
});

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

@ -5,20 +5,17 @@ $.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");
$(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
) {
$('.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-read-button.js

@ -20,7 +20,7 @@ $.onmount("[data-js-comment-collapse-read-button]", 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
@ -48,7 +48,7 @@ $.onmount("[data-js-comment-collapse-read-button]", function() {
.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);

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

@ -3,14 +3,13 @@
$.onmount("[data-js-comment-expand-all-button]", function () {
$(this).click(function () {
$(".is-comment-collapsed, .is-comment-collapsed-individual").each(function(
idx,
child
) {
$(".is-comment-collapsed, .is-comment-collapsed-individual").each(
function (idx, child) {
$(child)
.find("[data-js-comment-collapse-button]:first")
.trigger("click");
});
},
);
$(this).blur();
});

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

@ -5,9 +5,7 @@ $.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,7 +44,7 @@ $.onmount("[data-js-comment-label-button]", function() {
if (labelPrompt) {
label.setAttribute(
"data-ic-confirm",
"Remove your " + labelName + " label?"
"Remove your " + labelName + " label?",
);
}
@ -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,17 +79,14 @@ $.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);
});
});

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

@ -3,15 +3,13 @@
$.onmount("[data-js-comment-parent-button]", function () {
$(this).click(function () {
var $comment = $(this)
.parents(".comment")
.first();
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/ctrl-enter-submit-form.js

@ -7,9 +7,7 @@ $.onmount("[data-js-ctrl-enter-submit-form]", function() {
(event.ctrlKey || event.metaKey) &&
(event.keyCode == 13 || event.keyCode == 10)
) {
$(this)
.closest("form")
.submit();
$(this).closest("form").submit();
}
});
});

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

@ -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,7 +45,7 @@ $.onmount(".dropdown-toggle", function() {
.parent()
.toggleClass(
"dropdown-bottom",
menuBottom > viewportHeight + scrollTop || menuBottom > footerTop
menuBottom > viewportHeight + scrollTop || menuBottom > footerTop,
);
});

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

@ -3,8 +3,6 @@
$.onmount("[data-js-fadeout-parent-on-success]", function () {
$(this).on("after.success.ic", function () {
$(this)
.parent()
.fadeOut("fast");
$(this).parent().fadeOut("fast");
});
});

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

@ -3,12 +3,8 @@
$.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");
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");

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

@ -3,12 +3,8 @@
$.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 $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");

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

@ -5,6 +5,6 @@ $.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/tab.js

@ -3,9 +3,7 @@
$.onmount("[data-js-tab]", function () {
$(this).click(function () {
$(this)
.siblings()
.removeClass("active");
$(this).siblings().removeClass("active");
$(this).addClass("active");
});
});

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

@ -8,10 +8,7 @@ $.onmount("[data-js-theme-selector]", function() {
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();
@ -29,9 +26,7 @@ $.onmount("[data-js-theme-selector]", function() {
});
Tildes.toggleSetDefaultThemeButton = function (element) {
var selected_text = $(element)
.find("option:selected")
.text();
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) {

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

@ -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

Loading…
Cancel
Save