Skip to content

Commit

Permalink
Clean up deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bitWolfy committed Sep 16, 2020
1 parent 919dfcd commit ffebdeb
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 48 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
]
},
"plugins": [
"@typescript-eslint"
"@typescript-eslint",
"deprecation"
],
"extends": [
// "eslint:recommended",
Expand Down Expand Up @@ -89,6 +90,7 @@
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/type-annotation-spacing": "error",
"deprecation/deprecation": "warn",
"no-var": "error",
"prefer-const": "error",
"prefer-rest-params": "error",
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"browserify": "^16.5.0",
"crx": "^5.0.1",
"eslint": "^6.8.0",
"eslint-plugin-deprecation": "^1.1.0",
"npm-run-all": "^4.1.5",
"postcss-cli": "^7.1.1",
"rimraf": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/api/XMConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class XMConnect {
download: a.name,
})
.html("download")
.click(() => { btn.remove(); });
.on("click", () => { btn.remove(); });
btn[0].click();
}
});
Expand Down
14 changes: 7 additions & 7 deletions src/js/components/structure/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export class Form implements PreparedStructure {
}

let copyTimer: number;
$($copybutton).click(function () {
$($copybutton).on("click", () => {
XM.Util.setClipboard($input.val());

window.clearTimeout(copyTimer);
Expand Down Expand Up @@ -468,7 +468,7 @@ export class Form implements PreparedStructure {
}

let occupied = false;
$($recordbutton).click(function () {
$($recordbutton).on("click", () => {
if (occupied) return;
occupied = true;

Expand Down Expand Up @@ -618,7 +618,7 @@ export class Form implements PreparedStructure {
.appendTo($selectContainer);
}

$selectContainer.find("a").click((event) => {
$selectContainer.find("a").on("click", (event) => {
event.preventDefault();
$selectContainer.find("a").removeClass("active");

Expand All @@ -629,14 +629,14 @@ export class Form implements PreparedStructure {
if (changed) changed($input.val().toString(), $input);
});

if (options.value) { $selectContainer.find("a[data-value='" + options.value + "']").first().click(); }
else { $selectContainer.find("a").first().click(); }
if (options.value) { $selectContainer.find("a[data-value='" + options.value + "']").first().trigger("click"); }
else { $selectContainer.find("a").first().trigger("click"); }

// When the field value is set externally, this event needs to be triggered on the text input field.
// There is probably a better way to do this, but this should work for now.
$input.on("re621:form:update", () => {
if ($input.val() == "") { $selectContainer.find("a").first().click(); }
else { $selectContainer.find("a[data-value='" + $input.val() + "']").first().click(); }
if ($input.val() == "") { $selectContainer.find("a").first().trigger("click"); }
else { $selectContainer.find("a[data-value='" + $input.val() + "']").first().trigger("click"); }
});

return new FormElement($element, $input, $label);
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/structure/Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class Modal {

// This effectively clamps down the modal position while scrolling
// Without this, the modal gets run off the screen for some reason
$(window).scroll(() => {
$(window).on("scroll", () => {
if (timer) clearTimeout(timer);
else {
left = widget.css("left");
Expand Down
4 changes: 2 additions & 2 deletions src/js/components/structure/Prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export class Prompt extends Modal {
this.createForm();
this.addContent(this.$form);
this.open();
this.$input.focus();
this.$input.trigger("focus");

this.promise = new Promise((resolve, reject) => {
this.$form.submit(event => {
this.$form.on("submit", (event) => {
event.preventDefault();
this.destroy();
resolve(this.$input.val());
Expand Down
6 changes: 3 additions & 3 deletions src/js/components/utility/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export class Util {
* @param file File name
*/
public static downloadAsJSON(data: any, file: string): void {
$("<a>")
const tempLink = $("<a>")
.attr({
"download": file + ".json",
"href": "data:application/json," + encodeURIComponent(JSON.stringify(data, null, 4)),
})
.appendTo("body")
.click(function () { $(this).remove(); })
[0].click();
.on("click", () => { tempLink.remove(); });
tempLink[0].click();
}

/**
Expand Down
15 changes: 8 additions & 7 deletions src/js/modules/general/FormattingHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ class FormattingHelper {
`)
.appendTo($bar);

this.$toggleTabs.find("a").click(e => {
e.preventDefault();
this.$toggleTabs.find("a").on("click", (event) => {
event.preventDefault();
this.toggleEditing();
});

Expand All @@ -328,7 +328,7 @@ class FormattingHelper {
.html("&#x" + "f1de")
.attr("title", "Settings")
.appendTo($drawerButtonBox)
.click(event => {
.on("click", event => {
event.preventDefault();
this.toggleButtonDrawer();
});
Expand Down Expand Up @@ -404,7 +404,7 @@ class FormattingHelper {
.append(charCounter)
.appendTo(this.$container);

this.$textarea.keyup(() => {
this.$textarea.on("keyup", () => {
charCounter.html((this.$textarea.val() + "").length + " / 50000");
});
}
Expand Down Expand Up @@ -492,7 +492,7 @@ class FormattingHelper {
.appendTo(box);

this.$editButtonsModal.registerTrigger({ element: button });
button.click(event => {
button.on("click", (event) => {
event.preventDefault();
if (this.$container.attr("data-drawer") === "false") {
this.processFormattingTag(box.attr("data-text"));
Expand Down Expand Up @@ -546,6 +546,7 @@ class FormattingHelper {
} else {
this.$container.attr("data-editing", "true");
this.$toggleTabs.find("a").toggleClass("active");
this.$textarea.trigger("focus");
}
}

Expand Down Expand Up @@ -612,7 +613,7 @@ class FormattingHelper {

content = content.replace(/%selection%/g, currentText.substring(position.start, position.end));

this.$textarea.focus();
this.$textarea.trigger("focus");

// This is a workaround for a Firefox bug, which existed since 2015
// Check https://bugzilla.mozilla.org/show_bug.cgi?id=1220696 for more information
Expand All @@ -624,7 +625,7 @@ class FormattingHelper {
this.$textarea.prop("selectionStart", position.start);
this.$textarea.prop("selectionEnd", position.start + content.length);

this.$textarea.keyup();
this.$textarea.trigger("focus");
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/js/modules/general/Miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class Miscellaneous extends RE6Module {
$textarea.scrollTop($textarea[0].scrollHeight);

const newVal = $textarea.val() + strippedBody;
$textarea.focus().val("").val(newVal);
$textarea.trigger("focus").val("").val(newVal);
}

/**
Expand Down Expand Up @@ -257,7 +257,7 @@ export class Miscellaneous extends RE6Module {
* @param event Keydown event
*/
private handleSubmitForm(event): void {
$(event.target).parents("form").submit();
$(event.target).parents("form").trigger("submit");
}

/**
Expand All @@ -274,7 +274,7 @@ export class Miscellaneous extends RE6Module {
.append(charCounter)
.appendTo($container);

$textarea.keyup(() => {
$textarea.on("keyup", () => {
charCounter.html(($textarea.val() + "").length + " / 50000");
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/js/modules/general/SettingsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ export class SettingsController extends RE6Module {
.val(flag === undefined ? "" : flag.color)
.css("border-left-color", flag === undefined ? "transparent" : flag.color)
.appendTo(flagContainer)
.keyup((event) => {
.on("keyup", (event) => {
const $target = $(event.target);
if (($target.val() + "").match(/^#(?:[0-9a-f]{3}){1,2}$/i)) {
$target.css("border-left-color", $target.val() + "");
Expand All @@ -1013,7 +1013,7 @@ export class SettingsController extends RE6Module {
$("<button>")
.html(`<i class="far fa-trash-alt"></i>`)
.appendTo(flagContainer)
.click(() => {
.on("click", () => {
flagContainer.remove();
});

Expand Down
4 changes: 2 additions & 2 deletions src/js/modules/post/ImageScaler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class ImageScaler extends RE6Module {
.val(this.fetchSettings("size"))
.addClass("button btn-neutral")
.appendTo(resizeButtonContainer)
.change(async (event, save) => {
.on("change", async (event, save) => {
const size = $(event.target).val() + "";
this.setImageSize(size);
if (save !== false) {
Expand All @@ -88,7 +88,7 @@ export class ImageScaler extends RE6Module {

$("#image-download-link a").html("Fullscreen");

this.image.click(async () => {
this.image.on("click", async () => {
if (!this.fetchSettings("clickScale") || await Danbooru.Note.TranslationMode.active()) return;
this.setScale("", false);
});
Expand Down
6 changes: 3 additions & 3 deletions src/js/modules/post/PoolNavigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class PoolNavigator extends RE6Module {

this.buildDOM();

$("input[type='radio'].post-nav-switch").change((event) => {
$("input[type='radio'].post-nav-switch").on("change", (event) => {
this.activeNav = parseInt($(event.target).val() + "");
});

Expand All @@ -52,8 +52,8 @@ export class PoolNavigator extends RE6Module {

if (navbars.length == 0) return;

if ((active + 1) >= navbars.length) { navbars[0].checkbox.click(); }
else { navbars[active + 1].checkbox.click(); }
if ((active + 1) >= navbars.length) { navbars[0].checkbox.trigger("click"); }
else { navbars[active + 1].checkbox.trigger("click"); }
}

/** Emulates a click on the "next" button */
Expand Down
13 changes: 6 additions & 7 deletions src/js/modules/search/BetterSearch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isNumeric } from "jquery";
import { Danbooru } from "../../components/api/Danbooru";
import { E621 } from "../../components/api/E621";
import { APIPost, PostRating } from "../../components/api/responses/APIPost";
Expand Down Expand Up @@ -203,7 +202,7 @@ export class BetterSearch extends RE6Module {

// Preload previous pages
// Not available for relative page numbers
if (isNumeric(this.queryPage)) {
if (Util.Math.isNumeric(this.queryPage)) {

const currentPage = parseInt(this.queryPage);
const firstPage = preloadEnabled
Expand Down Expand Up @@ -635,7 +634,7 @@ export class BetterSearch extends RE6Module {
/** Loads the next page of results */
private async loadNextPage(): Promise<boolean> {

this.queryPage = isNumeric(this.queryPage)
this.queryPage = Util.Math.isNumeric(this.queryPage)
? this.queryPage = (parseInt(this.queryPage) + 1) + ""
: this.queryPage = "b" + Post.get($("post:last")).id;

Expand Down Expand Up @@ -668,7 +667,7 @@ export class BetterSearch extends RE6Module {

BetterSearch.trigger("pageload");

if (isNumeric(this.queryPage))
if (Util.Math.isNumeric(this.queryPage))
return Promise.resolve(parseInt(this.queryPage) < this.lastPage);
else return Promise.resolve(true);
}
Expand Down Expand Up @@ -748,7 +747,7 @@ export class BetterSearch extends RE6Module {
.addClass("paginator-numbers")
.appendTo(this.$paginator);

if (isNumeric(this.queryPage)) {
if (Util.Math.isNumeric(this.queryPage)) {
const currentPage = parseInt(this.queryPage);
const pageNum: number[] = [];

Expand Down Expand Up @@ -781,7 +780,7 @@ export class BetterSearch extends RE6Module {
function getPrevPageURL(page: string): string {

// Default pagination
if (isNumeric(page)) return getPageURL(parseInt(page) - 1);
if (Util.Math.isNumeric(page)) return getPageURL(parseInt(page) - 1);

// Relative pagination
const lookup = $("post:first");
Expand All @@ -793,7 +792,7 @@ export class BetterSearch extends RE6Module {
function getNextPageURL(page: string): string {

// Default pagination
if (isNumeric(page)) {
if (Util.Math.isNumeric(page)) {
const pageNum = parseInt(page);
if (pageNum < 750) return getPageURL(parseInt(page) + 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/modules/search/PostSuggester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class PostSuggester extends RE6Module {
.html("Search")
.addClass("button btn-neutral post-suggester-search")
.appendTo(this.status)
.click((event) => {
.on("click", (event) => {
event.preventDefault();
const checkedEls = $("input[name=post-suggester-selector]:checked").get();
const query = [];
Expand Down
10 changes: 5 additions & 5 deletions src/js/modules/search/SearchUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class SearchUtilities extends RE6Module {
// Auto-focus on the searchbar
if (Page.matches(PageDefinition.search)) {
const searchbox = $("section#search-box input");
if (searchbox.val() == "") searchbox.focus();
if (searchbox.val() == "") searchbox.trigger("focus");
}

// Remove the query string on posts
Expand Down Expand Up @@ -144,7 +144,7 @@ export class SearchUtilities extends RE6Module {
/** Sets the focus on the search bar */
private focusSearchbar(event): void {
event.preventDefault();
$("section#search-box input").focus();
$("section#search-box input").trigger("focus");
}

/** Switches the location over to a random post */
Expand All @@ -160,11 +160,11 @@ export class SearchUtilities extends RE6Module {
private switchModeBlacklist(): void { SearchUtilities.switchMode("blacklist"); }
private switchModeAddSet(): void {
SearchUtilities.switchMode("add-to-set");
$("#set-id").focus();
$("#set-id").trigger("focus");
}
private switchModeRemSet(): void {
SearchUtilities.switchMode("remove-from-set");
$("#set-id").focus();
$("#set-id").trigger("focus");
}

private static switchMode(mode: string): void {
Expand All @@ -187,7 +187,7 @@ export class SearchUtilities extends RE6Module {
.addClass("blacklist-tag-toggle")
.html(`<i class="fas fa-times"></i>`)
.prependTo($container)
.click((event) => {
.on("click", (event) => {
event.preventDefault();
Blacklist.toggleBlacklistTag($container.parent().attr("data-tag"));
});
Expand Down
Loading

0 comments on commit ffebdeb

Please sign in to comment.