js: replace <meta> tags with <body> data attributes.
Refactor things to store information about the current user as data attributes on the <body> tag rather than as <meta> tags. These <meta> tags are now deprecated and will be eventually removed. * Store all of the current user's API attributes as data attributes on the <body> tag. * Add `CurrentUser.data` for getting data from the <body> tag, and use it instead of `Utility.meta`. * Add `CurrentUser.update` for updating the current user's settings. * Fix a bug with the user named "Anonymous" not being able to edit notes.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import CurrentUser from './current_user'
|
||||
import Utility from './utility'
|
||||
|
||||
require('qtip2');
|
||||
@@ -99,25 +100,21 @@ PostTooltip.hide = function (event) {
|
||||
};
|
||||
|
||||
PostTooltip.disabled = function (event) {
|
||||
return PostTooltip.isTouching || Utility.meta("disable-post-tooltips") === "true";
|
||||
return PostTooltip.isTouching || CurrentUser.data("disable-post-tooltips");
|
||||
};
|
||||
|
||||
PostTooltip.on_disable_tooltips = function (event) {
|
||||
PostTooltip.on_disable_tooltips = async function (event) {
|
||||
event.preventDefault();
|
||||
$(event.target).parents(".qtip").qtip("hide");
|
||||
|
||||
if (Utility.meta("current-user-id") === "") {
|
||||
Utility.notice('<a href="/session/new">Login</a> to disable tooltips permanently');
|
||||
if (CurrentUser.data("is-anonymous")) {
|
||||
Utility.notice('You must <a href="/session/new">login</a> to disable tooltips');
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax("/users/" + Utility.meta("current-user-id") + ".json", {
|
||||
method: "PUT",
|
||||
data: { "user[disable_post_tooltips]": "true" },
|
||||
}).then(function() {
|
||||
Utility.notice("Tooltips disabled; check your account settings to re-enable.");
|
||||
location.reload();
|
||||
});
|
||||
await CurrentUser.update({ disable_post_tooltips: true });
|
||||
Utility.notice("Tooltips disabled; check your account settings to re-enable.");
|
||||
location.reload();
|
||||
};
|
||||
|
||||
$(document).ready(PostTooltip.initialize);
|
||||
|
||||
Reference in New Issue
Block a user