Commit Graph

8125 Commits

Author SHA1 Message Date
evazion
2cbce9a525 notes: rewrite notes Javascript to object-oriented style.
Rewrite the notes Javascript from a procedural style to an
object-oriented style.

Before the notes Javascript had a lot of problems:

* There was hidden state everywhere, both locally and globally. We had
  state in global variables, in <meta> tags, in DOM data-* attributes
  (on multiple elements), and in jQuery .data() properties (which are
  different from data-* attributes, because they aren't visible in the
  DOM).

* Local state was hard to reason about. There was lots of direct DOM
  manipulation in random places. Functions had to constantly pass around
  note ids and look up elements in the DOM to get the state. State was
  invisible because it was stored as jQuery .data() properties. It was
  hard to follow where state was stored, how it was initialized, and how
  it changed.

* Global state was also a mess. There were a lot of global flags and
  variables only used in specific situations. Almost all of this state was
  unnecessary. Global state also prevented us from doing things like
  loading or unloading posts dynamically, or showing multiple posts with
  notes on the same page.

* There was a lot of duplication of code, especially for placing notes,
  and for loading or saving new notes versus saved notes.

Now the code is organized in an object-oriented fashion:

* The Note class represents a single note. A post has a list of notes,
  and each note object has a Note.Box and a Note.Body. Together these
  objects encapsulate the note's state.

* Notes have methods for doing things like placing note boxes, or showing
  and hiding note bodies, or creating, saving, or deleting notes. This
  makes the JS API cleaner.

* Global state is kept to a minimum.

This is one big patch because it was too hard to make these changes
incrementally. There are a couple minor bugfixes, but the actual
behavior of notes should remain unchanged.

Bugfixes:

* It was possible to enter translation mode, start dragging a new note,
  then press N to leave translation mode while still dragging the note.
  If you did this, then you would be stuck in translation mode and you
  couldn't stop dragging the note.

* Placement of new notes is now pixel-perfect. Before when placing a
  note, the note would shift by 1-2 pixels.

* Previewing an empty note didn't show the "Click to edit" message.

Other noteworthy changes:

* Most global state has been eliminated. There were a lot of flags and
  variables stored as global variables on `Danbooru.Note`. Most of these
  turned out to be either unnecessary or even unused.

* Notes now have an explicit minimum size of 10x10 pixels. Before this
  limit was hardcoded and undocumented.

* A lot of the note placement and note creation code has been simplified.

* `Note.add()` and `Note.create()` have been refactored into `new Note()`.
  Before `Note.add` was used to load an existing note, while `Note.create`
  was used to create a new note. These did the same thing, but had
  slightly different behavior.

* `Note.Box.scale()` and `Note.box.update_data_attributes` have been
  refactored into `Note.Box.place_note()`. Contrary to their names,
  these functions were actually both used to place notes.
2020-07-28 22:06:35 -05:00
evazion
3a3d456bd2 html: standardize font sizes and heading tags.
Standardize font sizes and heading tags (<h1>-<h6>) to be more
consistent across the site.

Changes:

* Introduce font size CSS variables and start replacing hardcoded font
  sizes with standard sizes.
* Change header tags to use only one <h1> per page. One <h1> per page is
  recommended for SEO purposes. Usually this is for the page title, like
  in forum threads or wiki pages.
* Standardize on <h2> for section headers in sidebars and <h3> for
  smaller subsection headers. Don't use <h4>-<h6>.
* In DText, make h1-h4 headers all the same size. Standard wiki style is
  to ignore h1-h3 and start at h4.
* In DText, make h4-h6 the same size as the h1-h3 tags outside of DText.
* In the tag list, change the <h1> and <h2> tag category headers to <h3>.
* Make usernames in comments and forum posts smaller. Also change the
  <h4> tag for the commenter name to <div class="author-name">.
* Make the tag list, paginator, and nav menu smaller on mobile.
* Change h1#app-name-header to a#app-name-header.
2020-07-23 17:34:17 -05:00
evazion
a59afcdf29 Merge pull request #4547 from nonamethanks/fix_4545
Uploads: Check if strategy is enabled before use
2020-07-23 17:28:36 -05:00
evazion
da9c2a26ce Merge branch 'master' into mobile-mode-default-image-size 2020-07-23 16:22:37 -05:00
evazion
c4fb43a5b4 Fix #4549: Export the UserTooltips module. 2020-07-16 14:24:06 -05:00
evazion
87b6f59bf0 post tooltips: fix tooltips appearing over one another.
When viewing a list of post #XXX links, like this:

* post #123
* post #456
* post #789

Then moving from bottom to top could cause multiple tooltips to appear
over one another. This was because tippy.js tries to keep tooltips
active while moving towards them, which meant it was possible to
activate a second tooltip while moving towards the first.
2020-07-16 14:23:48 -05:00
evazion
ce61202d14 post tooltips: fix long usernames causing header to overflow.
* Make tooltips wider.
* Abbreviate ratings.
* Truncate long usernames.
2020-07-16 12:53:00 -05:00
evazion
afef9cc9ab tests: fix tests. 2020-07-13 19:30:40 -05:00
evazion
7f2eaeb02b Fix #4541: Possible to create new user while logged in. 2020-07-13 19:25:30 -05:00
evazion
ed79b623cc Fix #4544: Show limited view of other user's uploads on the upload index.
* Show completed uploads to other users.
* Don't show failed or incomplete uploads to other users.
* Don't show tags to other users.
* Delete completed uploads after 1 hour.
* Delete incomplete uploads after 1 day.
* Delete failed uploads after 3 days.
2020-07-13 19:25:30 -05:00
evazion
85f464df83 Fix #4540: Demotion sends "You have been promoted" dmail.
Change message to "Your account has been updated". It's possible for a
user to both gain and lose permissions at the same time, so just say
their account has been updated to make it easier.
2020-07-13 19:25:29 -05:00
evazion
0b52b1622f posts: bring back uploader names. 2020-07-13 19:25:29 -05:00
evazion
45bbb71eba posts: hide ids of restricted posts. 2020-07-13 19:25:29 -05:00
evazion
b5e647dc51 posts: add file type to post info. 2020-07-13 19:25:29 -05:00
evazion
5687c67fc3 posts: autotag video instead of webm/mp4.
Automatically add the `video` tag instead of the `webm` or `mp4` tags.
2020-07-13 19:25:29 -05:00
evazion
1e2e99a941 post tooltips: fix tooltips not appearing on /comments page. 2020-07-13 19:10:15 -05:00
evazion
cf4469f902 users: add dropdown actions to username tooltips. 2020-07-13 17:09:03 -05:00
evazion
88bbd1e3f0 users: add username tooltips. 2020-07-13 17:09:03 -05:00
evazion
d7f489b68e users: get rid of the .with-style class.
Replace with `body[data-current-user-style-usernames="true"]` instead.
2020-07-13 17:08:53 -05:00
evazion
b1ccc44c91 users: allow searching for banned users. 2020-07-13 13:48:39 -05:00
evazion
9885ae61fb user name changes: add search options. 2020-07-13 13:48:39 -05:00
nonamethanks
3179509791 Uploads: Check if strategy is enabled before use
Avoid returning bare API tracebacks from pixiv et al when login details
are not configured, and instead raise a generic error.
2020-07-11 04:56:46 +02:00
evazion
42f0112c38 seo: increase sitemap coverage.
Rework sitemaps to provide more coverage of the site. We want every
important page on the site - including every post, tag, and wiki page -
to be indexed by Google. We do this by generating sitemaps and sitemap
indexes that contain links to every important page on the site.
2020-07-10 00:18:30 -05:00
evazion
d88a2a674f seo: allow /sitemap.xml in robots.txt 2020-07-08 16:16:46 -05:00
evazion
fc331f2079 seo: add json-ld structured data for videos.
Makes video posts eligible for rich results in Google, which means they
can include a thumbnail.

Ref: https://developers.google.com/search/docs/data-types/video
2020-07-08 15:16:58 -05:00
evazion
df32e0da72 seo: remove obsolete itemprop microdata attributes.
Remove obsolete itemprop attributes. These were originally added in
2dd4b4c, but they haven't been working since e334c34 removed the
itemscope and itemtype attributes. They never worked right because they
weren't nested properly, and they were never really useful because
Google doesn't use the ImageObject schema for anything.

* https://developers.google.com/search/docs/guides/intro-structured-data
* https://developer.mozilla.org/en-US/docs/Web/HTML/Microdata
* https://schema.org/docs/gs.html
* https://schema.org/ImageObject
2020-07-08 14:59:35 -05:00
evazion
3762a66b92 seo: fix Google rich results not detecting site logo.
Bug: for some reason, Google's rich results tool doesn't detect our logo
when the @id property is present.

https://search.google.com/test/rich-results
2020-07-08 12:38:03 -05:00
evazion
2219a96d2e pool.js: remove leftover recent pools code.
Removed in 1e3c97e4.
2020-07-08 11:33:10 -05:00
evazion
7bfea5cd19 js: drop stupidtable plugin.
This was only used on the saved search index. It let you click on column
headers to sort the table by that column. This doesn't make sense now
that saved searches are paginated.
2020-07-08 11:31:45 -05:00
evazion
bfc31acbed artists: fix accidental gentag category changes.
Bug: if you created an artist with the name of an existing general tag,
then the gentag would be changed to an artist tag, no matter how big the
gentag was.

Now we only allow creating artist entries for non-artist tags if the tag
is empty.

Ref: https://danbooru.donmai.us/forum_topics/17095
2020-07-07 12:47:18 -05:00
evazion
7dfc783f2c Fix #4537: Forum quoting broken in topics where user has a reply. 2020-07-06 16:02:19 -05:00
evazion
40a114c99c posts: restrict banned paid rewards for non-approvers. 2020-07-06 13:52:57 -05:00
evazion
0c7d48d890 posts: autoban uploads tagged paid_reward. 2020-07-06 13:52:46 -05:00
evazion
e18c258be5 Rewrite Terms of Service (fix #4415). 2020-07-06 02:55:57 -05:00
evazion
b5fc8fff6e Add privacy policy (#4415). 2020-07-06 02:53:01 -05:00
evazion
f0a573e1e5 /comments.atom: fix restricted posts being leaked.
Fix thumbnail URLs of loli/shota/banned posts being leaked in
/comments.atom. Restricted posts are now entirely hidden in
/comments.atom.

Example: https://danbooru.donmai.us/comments.atom?search[post_id]=2.
2020-07-06 02:51:30 -05:00
evazion
d9b7879a4c html: add <meta name="theme-color"> tag.
Make the address bar blue on mobile.

* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta/name/theme-color
* https://developers.google.com/web/fundamentals/design-and-ux/browser-customization#meta_theme_color_for_chrome_and_opera
2020-07-05 11:26:26 -05:00
evazion
89c1c927ee html: add <meta charset="utf-8"> tag.
ref: https://webhint.io/docs/user-guide/hints/hint-meta-charset-utf-8/
2020-07-04 22:31:18 -05:00
evazion
9a03582513 Add OpenSearch suggestion support.
Add autocomplete support when searching Danbooru from the Chrome address
bar. If you type "danb<tab>" in the address bar then search for a tag,
then autocomplete results from Danbooru will appear as search
suggestions in Chrome.

Note that the "Autocomplete searches and URLs" Chrome setting must be
enabled for this to work.

Ref:

* http://dev.chromium.org/tab-to-search
* https://developer.mozilla.org/en-US/docs/Archive/Add-ons/Supporting_search_suggestions_in_search_plugins
* https://github.com/dewitt/opensearch/blob/master/mediawiki/Specifications/OpenSearch/Extensions/Suggestions/1.1/Draft%201.wiki
2020-07-04 17:52:53 -05:00
evazion
aa1a21aece Add OpenSearch support (/opensearch.xml).
Add https://danbooru.donmai.us/opensearch.xml. This file tells browsers
how to perform searches on Danbooru.

In Chrome, this lets you type "danb<tab>" in the address bar to perform
a search on Danbooru.

In Firefox, you have to click the "..." icon next to the address bar,
then choose "Add Search Engine". After that, you can search Danbooru
from the address bar.

Ref:

* http://dev.chromium.org/tab-to-search
* https://developer.mozilla.org/en-US/docs/Web/OpenSearch
* https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md
* https://en.wikipedia.org/wiki/OpenSearch
2020-07-04 17:52:49 -05:00
evazion
b6b0218e1d seo: update JSON-LD site metadata.
* Add the Danbooru logo and social media links to the Organization data.
  This is to make Danbooru eligible for Google's knowledge panel ([1], [2]).
* Only include this metadata on the frontpage as per Google's recommendations ([3]).

[1]: https://support.google.com/knowledgepanel/answer/9163198
[2], https://developers.google.com/search/docs/data-types/logo
[3]: https://developers.google.com/search/docs/data-types/sitelinks-searchbox
2020-07-03 18:18:35 -05:00
evazion
a0ee4c67a8 Add lang="en" to <html> tag. 2020-07-03 15:59:45 -05:00
evazion
99e88b3dae seo: add rel=nofollow to various internal search links.
Add rel=nofollow to various internal search links to prevent Google from
attempting to crawl things like `<tag> status:deleted` or `approver:<name>`
searches.
2020-07-03 15:58:59 -05:00
evazion
629a634b22 seo: don't block css in robots.txt.
/packs was blocked by robots.txt, which prevented Googlebot from
fetching CSS when indexing pages, which made Google penalize pages for
being mobile unfriendly because it couldn't load the CSS and it thought
the layout was broken.
2020-07-03 15:58:59 -05:00
evazion
f97c62c71d search: fix search timeout error page not appearing.
Bug: when a search timed out we got the generic failbooru page instead
of the search timeout error page.

Cause: when rendering the <link rel="next"> / <link rel="prev"> tags in
the header, we may need to evaluate the search to determine the next or
previous page, but if the searches times out then this fails, which
caused Rails to throw a ActionView::Template::Error because an exception
was thrown while rendering the template.

Likewise, rendering the attributes for the <body> tag could fail with an
ActionView::Template::Error because the call to `current_item.present?`
forced evaluation of the search.
2020-07-03 13:08:49 -05:00
evazion
efe5111a9e js: bundle jQuery with Webpack.
Include jQuery in our Webpack bundle instead of loading it from CDNJS.
This means we no longer load any Javascript libraries from third party
sites.
2020-06-30 23:41:47 -05:00
evazion
94490eb57f Fix #4492: Switch from qtip2 to tippy.js. 2020-06-30 22:40:40 -05:00
evazion
5f05a41fbc Fix #4468: Tag edit mode on posts view applies taglist to wrong post. 2020-06-30 15:20:59 -05:00
evazion
1a8729e0d9 Fix #4462: "You have already favorited this post" on upload.
Make adding the fav:self metatag ignore all errors, including when the
post was already favorited before editing the post.
2020-06-30 14:29:25 -05:00
evazion
3d90414e06 Merge pull request #4487 from BrokenEagle/fix-invalid-url
Fix invalid artist URLs being allowed
2020-06-29 17:46:13 -05:00