From 6fa0ae2cf14cb5492704e5fe17bcb1784d3573b0 Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Fri, 6 Jul 2018 16:41:08 -0700 Subject: [PATCH] Migrate assets to use Webpacker --- .babelrc | 18 + .gitignore | 7 +- .postcssrc.yml | 3 + Gemfile | 1 + Gemfile.lock | 7 + app/assets/javascripts/application.js | 11 - app/assets/javascripts/artist_commentaries.js | 151 - app/assets/javascripts/artists.js | 46 - app/assets/javascripts/autocomplete.js.erb | 524 -- app/assets/javascripts/blacklists.js | 200 - app/assets/javascripts/comments.js | 108 - app/assets/javascripts/cookie.js | 73 - app/assets/javascripts/dtext.js | 68 - app/assets/javascripts/favorite_groups.js | 51 - app/assets/javascripts/favorites.js | 61 - .../forum_post_votes_controller.js | 2 - app/assets/javascripts/forum_posts.js | 45 - app/assets/javascripts/janitor_trials.js | 29 - app/assets/javascripts/mod_queue.js | 65 - app/assets/javascripts/news_updates.js | 28 - app/assets/javascripts/paginator.js | 25 - app/assets/javascripts/pools.js | 63 - app/assets/javascripts/post_appeals.js | 42 - app/assets/javascripts/post_flags.js | 46 - app/assets/javascripts/post_mode_menu.js | 186 - app/assets/javascripts/post_moderation.js | 29 - app/assets/javascripts/post_popular.js | 36 - app/assets/javascripts/posts.js.erb | 680 -- app/assets/javascripts/related_tag.js.erb | 350 - app/assets/javascripts/saved_searches.js | 16 - app/assets/javascripts/shortcuts.js | 57 - app/assets/javascripts/tag_script.js | 57 - app/assets/javascripts/uploads.js | 203 - app/assets/javascripts/utility.js | 170 - app/assets/javascripts/wiki_pages.js | 25 - app/assets/stylesheets/application.scss | 10 - app/javascript/packs/application.js | 29 + .../src/javascripts/artist_commentaries.js | 151 + app/javascript/src/javascripts/artists.js | 46 + .../src/javascripts/autocomplete.js.erb | 526 ++ app/javascript/src/javascripts/blacklists.js | 203 + app/javascript/src/javascripts/comments.js | 124 + .../src}/javascripts/common.js | 17 +- app/javascript/src/javascripts/cookie.js | 72 + app/javascript/src/javascripts/dtext.js | 68 + .../src/javascripts/favorite_groups.js | 53 + app/javascript/src/javascripts/favorites.js | 65 + app/javascript/src/javascripts/forum_posts.js | 47 + .../src/javascripts/janitor_trials.js | 29 + app/javascript/src/javascripts/mod_queue.js | 67 + .../src/javascripts/news_updates.js | 30 + .../src}/javascripts/notes.js | 325 +- app/javascript/src/javascripts/paginator.js | 26 + app/javascript/src/javascripts/pools.js | 65 + .../src/javascripts/post_appeals.js | 44 + app/javascript/src/javascripts/post_flags.js | 48 + .../src/javascripts/post_mode_menu.js | 191 + .../src/javascripts/post_moderation.js | 29 + .../src/javascripts/post_popular.js | 38 + .../src}/javascripts/post_tooltips.js.erb | 64 +- app/javascript/src/javascripts/posts.js.erb | 723 ++ .../src/javascripts/related_tag.js.erb | 354 + .../src}/javascripts/responsive.js | 0 .../src/javascripts/saved_searches.js | 20 + app/javascript/src/javascripts/shortcuts.js | 59 + app/javascript/src/javascripts/tag_script.js | 60 + app/javascript/src/javascripts/uploads.js | 208 + app/javascript/src/javascripts/utility.js | 182 + app/javascript/src/javascripts/wiki_pages.js | 25 + .../src/styles}/common/000_vars.scss | 2 + .../src/styles}/common/010_reset.scss | 0 .../src/styles}/common/020_base.scss | 0 .../src/styles}/common/030_links.scss | 0 .../src/styles}/common/autocomplete.scss | 0 .../src/styles}/common/diffs.scss | 0 .../src/styles}/common/dtext.scss | 0 .../src/styles}/common/inline.scss | 0 .../src/styles}/common/jquery_ui_custom.scss | 2 + .../src/styles}/common/main_layout.scss | 0 .../src/styles}/common/news.scss | 0 .../src/styles}/common/notices.scss | 0 .../src/styles}/common/page_header.scss | 0 .../src/styles}/common/paginator.scss | 0 .../src/styles}/common/simple_form.scss | 0 .../src/styles}/common/spoiler.scss | 0 .../src/styles}/common/tables.scss | 0 .../src/styles/common}/tags.scss.erb | 2 + .../src/styles}/common/user_styles.scss | 0 .../styles}/specific/admin_dashboards.scss | 0 .../src/styles}/specific/api_keys.scss | 0 .../src/styles}/specific/artists.scss | 0 .../src/styles}/specific/bans.scss | 0 .../specific/bulk_update_requests.scss | 0 .../src/styles}/specific/comments.scss | 0 .../src/styles}/specific/dmails.scss | 0 .../src/styles}/specific/dropzone.scss | 0 .../src/styles}/specific/explore.scss | 0 .../src/styles}/specific/favorite_groups.scss | 0 .../src/styles}/specific/favorites.scss | 0 .../src/styles}/specific/forum.scss | 0 .../src/styles}/specific/iqdb_queries.scss | 0 .../styles}/specific/keyboard_shortcuts.scss | 0 .../src/styles}/specific/maintenance.scss | 0 .../src/styles}/specific/meta_searches.scss | 0 .../src/styles/specific}/mod_queue.scss.erb | 2 +- .../styles}/specific/moderator_dashboard.scss | 0 .../src/styles}/specific/news_updates.scss | 0 .../src/styles}/specific/notes.scss | 2 + .../src/styles}/specific/pools.scss | 0 .../src/styles}/specific/post_appeals.scss | 0 .../src/styles}/specific/post_events.scss | 0 .../src/styles}/specific/post_flags.scss | 0 .../src/styles}/specific/post_mode_menu.scss | 0 .../src/styles}/specific/post_tooltips.scss | 2 + .../src/styles}/specific/post_versions.scss | 0 .../src/styles}/specific/posts.scss | 0 .../src/styles}/specific/related_tags.scss | 0 .../src/styles}/specific/reports.scss | 0 .../src/styles}/specific/saved_searches.scss | 0 .../src/styles}/specific/sessions.scss | 0 .../src/styles}/specific/site_map.scss | 0 .../src/styles}/specific/tags.scss | 0 .../styles}/specific/terms_of_service.scss | 0 .../src/styles}/specific/uploads.scss | 0 .../src/styles}/specific/user_deletions.scss | 0 .../src/styles}/specific/user_feedback.scss | 0 .../specific/user_name_change_requests.scss | 0 .../src/styles}/specific/user_upgrades.scss | 0 .../src/styles}/specific/users.scss | 0 .../styles}/specific/wiki_page_versions.scss | 0 .../src/styles}/specific/wiki_pages.scss | 0 .../src/styles}/specific/z_responsive.scss | 0 app/javascript/vendor/jquery-dropdown.js | 147 + app/javascript/vendor/jquery-hotkeys.js | 204 + app/javascript/vendor/jquery-timeout.js | 47 + app/javascript/vendor/pixiv-ugoira-player.js | 521 ++ app/javascript/vendor/stupidtable.js | 281 + app/views/bulk_update_requests/approve.js.erb | 2 +- app/views/comment_votes/create.js.erb | 4 +- app/views/comment_votes/destroy.js.erb | 2 +- app/views/comments/index_for_post.js.erb | 13 +- app/views/dmails/ham.js.erb | 2 +- app/views/dmails/spam.js.erb | 2 +- app/views/favorite_groups/add_post.js.erb | 2 +- app/views/favorites/create.js.erb | 4 +- app/views/favorites/destroy.js.erb | 2 +- app/views/forum_post_votes/create.js.erb | 4 +- app/views/forum_post_votes/destroy.js.erb | 2 +- app/views/layouts/blank.html.erb | 3 - app/views/layouts/default.html.erb | 17 +- .../maintenance/user/api_keys/update.js.erb | 4 +- .../moderator/post/approvals/create.js.erb | 6 +- .../moderator/post/disapprovals/create.js.erb | 6 +- app/views/moderator/post/posts/expunge.js.erb | 6 +- .../moderator/post/posts/undelete.js.erb | 2 +- app/views/pool_elements/create.js.erb | 2 +- app/views/post_appeals/create.js.erb | 4 +- app/views/post_flags/create.js.erb | 4 +- app/views/post_votes/create.js.erb | 4 +- app/views/post_votes/destroy.js.erb | 4 +- .../posts/partials/common/_search.html.erb | 4 +- app/views/saved_searches/create.js.erb | 4 +- app/views/saved_searches/destroy.js.erb | 4 +- bin/webpack | 15 + bin/webpack-dev-server | 15 + config/environments/development.rb | 2 + config/environments/production.rb | 2 + config/webpack/development.js | 5 + config/webpack/environment.js | 23 + config/webpack/loaders/erb.js | 11 + config/webpack/production.js | 5 + config/webpack/test.js | 5 + config/webpacker.yml | 69 + package.json | 18 + yarn.lock | 6268 +++++++++++++++++ 175 files changed, 11518 insertions(+), 3726 deletions(-) create mode 100644 .babelrc create mode 100644 .postcssrc.yml delete mode 100644 app/assets/javascripts/application.js delete mode 100644 app/assets/javascripts/artist_commentaries.js delete mode 100644 app/assets/javascripts/artists.js delete mode 100644 app/assets/javascripts/autocomplete.js.erb delete mode 100644 app/assets/javascripts/blacklists.js delete mode 100644 app/assets/javascripts/comments.js delete mode 100644 app/assets/javascripts/cookie.js delete mode 100644 app/assets/javascripts/dtext.js delete mode 100644 app/assets/javascripts/favorite_groups.js delete mode 100644 app/assets/javascripts/favorites.js delete mode 100644 app/assets/javascripts/forum_post_votes_controller.js delete mode 100644 app/assets/javascripts/forum_posts.js delete mode 100644 app/assets/javascripts/janitor_trials.js delete mode 100644 app/assets/javascripts/mod_queue.js delete mode 100644 app/assets/javascripts/news_updates.js delete mode 100644 app/assets/javascripts/paginator.js delete mode 100644 app/assets/javascripts/pools.js delete mode 100644 app/assets/javascripts/post_appeals.js delete mode 100644 app/assets/javascripts/post_flags.js delete mode 100644 app/assets/javascripts/post_mode_menu.js delete mode 100644 app/assets/javascripts/post_moderation.js delete mode 100644 app/assets/javascripts/post_popular.js delete mode 100644 app/assets/javascripts/posts.js.erb delete mode 100644 app/assets/javascripts/related_tag.js.erb delete mode 100644 app/assets/javascripts/saved_searches.js delete mode 100644 app/assets/javascripts/shortcuts.js delete mode 100644 app/assets/javascripts/tag_script.js delete mode 100644 app/assets/javascripts/uploads.js delete mode 100644 app/assets/javascripts/utility.js delete mode 100644 app/assets/javascripts/wiki_pages.js delete mode 100644 app/assets/stylesheets/application.scss create mode 100644 app/javascript/packs/application.js create mode 100644 app/javascript/src/javascripts/artist_commentaries.js create mode 100644 app/javascript/src/javascripts/artists.js create mode 100644 app/javascript/src/javascripts/autocomplete.js.erb create mode 100644 app/javascript/src/javascripts/blacklists.js create mode 100644 app/javascript/src/javascripts/comments.js rename app/{assets => javascript/src}/javascripts/common.js (74%) create mode 100644 app/javascript/src/javascripts/cookie.js create mode 100644 app/javascript/src/javascripts/dtext.js create mode 100644 app/javascript/src/javascripts/favorite_groups.js create mode 100644 app/javascript/src/javascripts/favorites.js create mode 100644 app/javascript/src/javascripts/forum_posts.js create mode 100644 app/javascript/src/javascripts/janitor_trials.js create mode 100644 app/javascript/src/javascripts/mod_queue.js create mode 100644 app/javascript/src/javascripts/news_updates.js rename app/{assets => javascript/src}/javascripts/notes.js (62%) create mode 100644 app/javascript/src/javascripts/paginator.js create mode 100644 app/javascript/src/javascripts/pools.js create mode 100644 app/javascript/src/javascripts/post_appeals.js create mode 100644 app/javascript/src/javascripts/post_flags.js create mode 100644 app/javascript/src/javascripts/post_mode_menu.js create mode 100644 app/javascript/src/javascripts/post_moderation.js create mode 100644 app/javascript/src/javascripts/post_popular.js rename app/{assets => javascript/src}/javascripts/post_tooltips.js.erb (51%) create mode 100644 app/javascript/src/javascripts/posts.js.erb create mode 100644 app/javascript/src/javascripts/related_tag.js.erb rename app/{assets => javascript/src}/javascripts/responsive.js (100%) create mode 100644 app/javascript/src/javascripts/saved_searches.js create mode 100644 app/javascript/src/javascripts/shortcuts.js create mode 100644 app/javascript/src/javascripts/tag_script.js create mode 100644 app/javascript/src/javascripts/uploads.js create mode 100644 app/javascript/src/javascripts/utility.js create mode 100644 app/javascript/src/javascripts/wiki_pages.js rename app/{assets/stylesheets => javascript/src/styles}/common/000_vars.scss (99%) rename app/{assets/stylesheets => javascript/src/styles}/common/010_reset.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/common/020_base.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/common/030_links.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/common/autocomplete.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/common/diffs.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/common/dtext.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/common/inline.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/common/jquery_ui_custom.scss (97%) rename app/{assets/stylesheets => javascript/src/styles}/common/main_layout.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/common/news.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/common/notices.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/common/page_header.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/common/paginator.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/common/simple_form.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/common/spoiler.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/common/tables.scss (100%) rename app/{assets/stylesheets/common/erb => javascript/src/styles/common}/tags.scss.erb (95%) rename app/{assets/stylesheets => javascript/src/styles}/common/user_styles.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/admin_dashboards.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/api_keys.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/artists.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/bans.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/bulk_update_requests.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/comments.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/dmails.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/dropzone.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/explore.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/favorite_groups.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/favorites.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/forum.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/iqdb_queries.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/keyboard_shortcuts.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/maintenance.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/meta_searches.scss (100%) rename app/{assets/stylesheets/specific/erb => javascript/src/styles/specific}/mod_queue.scss.erb (96%) rename app/{assets/stylesheets => javascript/src/styles}/specific/moderator_dashboard.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/news_updates.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/notes.scss (98%) rename app/{assets/stylesheets => javascript/src/styles}/specific/pools.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/post_appeals.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/post_events.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/post_flags.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/post_mode_menu.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/post_tooltips.scss (98%) rename app/{assets/stylesheets => javascript/src/styles}/specific/post_versions.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/posts.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/related_tags.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/reports.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/saved_searches.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/sessions.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/site_map.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/tags.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/terms_of_service.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/uploads.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/user_deletions.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/user_feedback.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/user_name_change_requests.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/user_upgrades.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/users.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/wiki_page_versions.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/wiki_pages.scss (100%) rename app/{assets/stylesheets => javascript/src/styles}/specific/z_responsive.scss (100%) create mode 100644 app/javascript/vendor/jquery-dropdown.js create mode 100644 app/javascript/vendor/jquery-hotkeys.js create mode 100644 app/javascript/vendor/jquery-timeout.js create mode 100644 app/javascript/vendor/pixiv-ugoira-player.js create mode 100644 app/javascript/vendor/stupidtable.js create mode 100755 bin/webpack create mode 100755 bin/webpack-dev-server create mode 100644 config/webpack/development.js create mode 100644 config/webpack/environment.js create mode 100644 config/webpack/loaders/erb.js create mode 100644 config/webpack/production.js create mode 100644 config/webpack/test.js create mode 100644 config/webpacker.yml create mode 100644 package.json create mode 100644 yarn.lock diff --git a/.babelrc b/.babelrc new file mode 100644 index 000000000..ded31c0d8 --- /dev/null +++ b/.babelrc @@ -0,0 +1,18 @@ +{ + "presets": [ + ["env", { + "modules": false, + "targets": { + "browsers": "> 1%", + "uglify": true + }, + "useBuiltIns": true + }] + ], + + "plugins": [ + "syntax-dynamic-import", + "transform-object-rest-spread", + ["transform-class-properties", { "spec": true }] + ] +} diff --git a/.gitignore b/.gitignore index 6aa281710..6a066aef7 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,9 @@ danbooru.sublime-workspace script/scratch.* test/fixtures/vcr_cassettes .gitconfig -test/reports \ No newline at end of file +test/reports +/public/packs-test +/node_modules +yarn-debug.log* +.yarn-integrity +public/packs \ No newline at end of file diff --git a/.postcssrc.yml b/.postcssrc.yml new file mode 100644 index 000000000..150dac3c6 --- /dev/null +++ b/.postcssrc.yml @@ -0,0 +1,3 @@ +plugins: + postcss-import: {} + postcss-cssnext: {} diff --git a/Gemfile b/Gemfile index a87bad6e0..b5998fcd6 100644 --- a/Gemfile +++ b/Gemfile @@ -50,6 +50,7 @@ gem 'recaptcha', require: "recaptcha/rails" gem 'activemodel-serializers-xml' gem 'ptools' gem 'jquery-rails' +gem 'webpacker', '>= 4.0.x' # needed for looser jpeg header compat gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes" diff --git a/Gemfile.lock b/Gemfile.lock index 034fa2351..a24c2e83f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -277,6 +277,8 @@ GEM rack (2.0.5) rack-protection (2.0.3) rack + rack-proxy (0.6.4) + rack rack-test (1.0.0) rack (>= 1.0, < 3) radix62 (1.0.1) @@ -419,6 +421,10 @@ GEM addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff + webpacker (4.0.0.pre.pre.2) + activesupport (>= 4.2) + rack-proxy (>= 0.6.1) + railties (>= 4.2) webrobots (0.1.2) websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) @@ -507,6 +513,7 @@ DEPENDENCIES unicorn unicorn-worker-killer webmock + webpacker (>= 4.0.x) whenever BUNDLED WITH diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js deleted file mode 100644 index 955fc7695..000000000 --- a/app/assets/javascripts/application.js +++ /dev/null @@ -1,11 +0,0 @@ -//= require hammer.js -//= require jquery.dropdown.js -//= require stupidtable.js -//= require jquery.qtip.js -//= require jquery.hammer.js -//= require jquery.timeout.js -//= require jquery.hotkeys.js -//= require ugoira_player.js -//= require jquery_ujs -//= require common.js -//= require_tree . diff --git a/app/assets/javascripts/artist_commentaries.js b/app/assets/javascripts/artist_commentaries.js deleted file mode 100644 index 9e17bfb40..000000000 --- a/app/assets/javascripts/artist_commentaries.js +++ /dev/null @@ -1,151 +0,0 @@ -(function() { - Danbooru.ArtistCommentary = {}; - - Danbooru.ArtistCommentary.initialize_all = function() { - if ($("#c-posts").length && $("#a-show").length) { - if ($("#original-artist-commentary").length && $("#translated-artist-commentary").length) { - this.initialize_commentary_display_tabs(); - } - - this.initialize_edit_commentary_dialog(); - } - } - - Danbooru.ArtistCommentary.initialize_commentary_display_tabs = function() { - $("#commentary-sections li a").click(function(e) { - if (e.target.hash === "#original") { - $("#original-artist-commentary").show(); - $("#translated-artist-commentary").hide(); - } else if (e.target.hash === "#translated") { - $("#original-artist-commentary").hide(); - $("#translated-artist-commentary").show(); - } - - $("#commentary-sections li").removeClass("active"); - $(e.target).parent("li").addClass("active"); - e.preventDefault(); - }); - - $("#commentary-sections li:last-child").addClass("active"); - $("#original-artist-commentary").hide(); - } - - Danbooru.ArtistCommentary.initialize_edit_commentary_dialog = function() { - $("#add-commentary-dialog").dialog({ - autoOpen: false, - width: 500, - buttons: { - "Submit": function() { - $("#add-commentary-dialog #edit-commentary").submit(); - $(this).dialog("close"); - }, - "Cancel": function() { - $(this).dialog("close"); - } - } - }); - - $('#add-commentary-dialog #edit-commentary').submit(function() { - $('#add-commentary-dialog').dialog('close'); - }); - - $("#add-commentary").click(function(e) { - e.preventDefault(); - $("#add-commentary-dialog").dialog("open"); - }); - - $('#fetch-commentary select[name="commentary_source_type"]').change(function() { - $("#fetch-commentary input").toggle(); - }); - - $('#fetch-commentary button[type="submit"]').click(Danbooru.ArtistCommentary.fetch_commentary); - } - - Danbooru.ArtistCommentary.fetch_commentary = function() { - Danbooru.notice("Fetching artist commentary..."); - - var type = $('#fetch-commentary select[name="commentary_source_type"]').val(); - if (type === "Source") { - var source = $('#fetch-commentary input[name="commentary_source"]').val(); - var commentary = Danbooru.ArtistCommentary.from_source(source); - } else if (type === "Post") { - var id = $('#fetch-commentary input[name="commentary_post_id"]').val(); - var commentary = Danbooru.ArtistCommentary.from_post_id(id); - } - - commentary.then(Danbooru.ArtistCommentary.fill_commentary).then(function (success) { - var message = success ? "Artist commentary copied." : "Artist commentary copied; conflicting fields ignored."; - Danbooru.notice(message); - }).catch(function () { - Danbooru.notice("Fetching artist commentary failed."); - }); - - return false; - }; - - Danbooru.ArtistCommentary.from_source = function(source) { - return $.get("/source.json?url=" + encodeURIComponent(source)).then(function(data) { - return { - original_title: data.artist_commentary.dtext_title, - original_description: data.artist_commentary.dtext_description, - source: source, - }; - }); - }; - - Danbooru.ArtistCommentary.from_post_id = function(post_id) { - return $.get("/posts/" + encodeURIComponent(post_id) + "/artist_commentary.json").then(function(commentary) { - commentary.source = "post #" + post_id; - return commentary; - }); - }; - - Danbooru.ArtistCommentary.fill_commentary = function(commentary) { - var description = Danbooru.ArtistCommentary.merge_commentaries($("#artist_commentary_original_description").val().trim(), commentary); - $("#artist_commentary_original_description").val(description); - - // Update the other fields if they're blank. Return success if none conflict. - return [ - Danbooru.ArtistCommentary.update_field($("#artist_commentary_original_title"), commentary.original_title), - Danbooru.ArtistCommentary.update_field($("#artist_commentary_translated_title"), commentary.translated_title), - Danbooru.ArtistCommentary.update_field($("#artist_commentary_translated_description"), commentary.translated_description), - ].every(function (i) { return i; }); - }; - - // If the new description conflicts with the current description, merge them - // by appending the new description onto the old one. - Danbooru.ArtistCommentary.merge_commentaries = function(description, commentary) { - var post_source = $('#image-container').data().source; - var normalized_source = $("#image-container").data().normalizedSource; - - if ((commentary.original_description && description) && - (commentary.original_description != description)) { - return description - + "\n\n[tn]\nSource: " + normalized_source + "\n[/tn]" - + "\n\nh6. " + (commentary.original_title || "Untitled") - + "\n\n" + commentary.original_description - + "\n\n[tn]\nSource: " + commentary.source + "\n[/tn]"; - } else if (commentary.source != post_source) { - return commentary.original_description + "\n\n[tn]\nSource: " + commentary.source + "\n[/tn]"; - } else { - return commentary.original_description || description; - } - }; - - // Update commentary field if it's blank, signal an error if there's a conflict. - Danbooru.ArtistCommentary.update_field = function($field, value) { - if ($field.val().trim() === "") { - $field.val(value); - return true; - } else if ($field.val().trim() !== value) { - $field.effect("shake", { direction: "up", distance: 5 }); - return false; - } else { - return true; - } - } -})(); - -$(function() { - Danbooru.ArtistCommentary.initialize_all(); -}); diff --git a/app/assets/javascripts/artists.js b/app/assets/javascripts/artists.js deleted file mode 100644 index 878c764b3..000000000 --- a/app/assets/javascripts/artists.js +++ /dev/null @@ -1,46 +0,0 @@ -(function() { - Danbooru.Artist = {}; - - Danbooru.Artist.initialize_all = function() { - if ($("#c-artists").length) { - Danbooru.Artist.initialize_check_name(); - Danbooru.Artist.initialize_shortcuts(); - } - } - - Danbooru.Artist.initialize_check_name = function() { - $("#artist_name").keyup(function(e) { - if ($("#artist_name").val().length > 0) { - $("#check-name-result").html(""); - - $.getJSON("/artists?search[name]=" + escape($("#artist_name").val()), function(data) { - if (data.length === 0) { - $.getJSON("/wiki_pages/" + escape($("#artist_name").val()), function(data) { - if (data !== null) { - $("#check-name-result").html("A wiki page with this name already exists. You must either move the wiki page or pick another artist name.") - } - }); - } else { - $("#check-name-result").html("An artist with this name already exists.") - } - }); - } - }); - } - - Danbooru.Artist.initialize_shortcuts = function() { - if ($("#c-artists #a-show").length) { - Danbooru.keydown("e", "edit", function(e) { - $("#artist-edit a")[0].click(); - }); - - Danbooru.keydown("shift+d", "delete", function(e) { - $("#artist-delete a")[0].click(); - }); - } - }; -})(); - -$(document).ready(function() { - Danbooru.Artist.initialize_all(); -}); diff --git a/app/assets/javascripts/autocomplete.js.erb b/app/assets/javascripts/autocomplete.js.erb deleted file mode 100644 index 62a863c9c..000000000 --- a/app/assets/javascripts/autocomplete.js.erb +++ /dev/null @@ -1,524 +0,0 @@ -(function() { - Danbooru.Autocomplete = {}; - - Danbooru.Autocomplete.AUTOCOMPLETE_VERSION = 1; - - Danbooru.Autocomplete.PREFIXES = /^(-|~|<%= TagCategory.mapping.keys.map {|category| category + ':'}.join('|') %>)(.*)$/i; - Danbooru.Autocomplete.METATAGS = /^(<%= Tag::METATAGS %>):(.*)$/i; - - Danbooru.Autocomplete.initialize_all = function() { - if (Danbooru.meta("enable-auto-complete") === "true") { - $.widget("ui.autocomplete", $.ui.autocomplete, { - options: { - delay: 0, - minLength: 1, - autoFocus: false, - focus: function() { return false; }, - }, - _create: function() { - this.element.on("keydown.danbooru.autocomplete.tab", null, "tab", Danbooru.Autocomplete.on_tab); - this._super(); - }, - _renderItem: Danbooru.Autocomplete.render_item, - }); - - this.initialize_tag_autocomplete(); - this.initialize_mention_autocomplete($(".autocomplete-mentions textarea")); - this.initialize_artist_autocomplete($('[data-autocomplete="artist"]')); - this.initialize_pool_autocomplete($('[data-autocomplete="pool"]')); - this.initialize_wiki_autocomplete($('[data-autocomplete="wiki-page"]')); - } - } - - Danbooru.Autocomplete.initialize_mention_autocomplete = function($fields) { - $fields.autocomplete({ - search: function() { - $(this).data("ui-autocomplete").menu.bindings = $(); - }, - select: function(event, ui) { - Danbooru.Autocomplete.insert_completion(this, ui.item.value); - return false; - }, - source: function(req, resp) { - var cursor = this.element.get(0).selectionStart; - var i; - var name = null; - - for (i=cursor; i>=1; --i) { - if (req.term[i-1] === " ") { - return; - } - - if (req.term[i-1] === "@") { - if (i == 1 || /[ \r\n]/.test(req.term[i-2])) { - name = req.term.substring(i, cursor); - break; - } else { - return; - } - } - } - - if (name) { - Danbooru.Autocomplete.user_source(name, resp, "@"); - } - - return; - } - }); - } - - Danbooru.Autocomplete.initialize_tag_autocomplete = function() { - var $fields_multiple = $('[data-autocomplete="tag-query"], [data-autocomplete="tag-edit"]'); - var $fields_single = $('[data-autocomplete="tag"]'); - - $fields_multiple.autocomplete({ - search: function() { - if ($(this).data("ui-autocomplete")) { - $(this).data("ui-autocomplete").menu.bindings = $(); - } - }, - select: function(event, ui) { - // Prevent Danbooru.Upload.initialize_enter_on_tags from running if the - // Enter key is used to select a tag from the autocomplete menu. - if (event.key === "Enter") { - event.stopImmediatePropagation(); - } - - Danbooru.Autocomplete.insert_completion(this, ui.item.value); - return false; - }, - source: function(req, resp) { - var query = Danbooru.Autocomplete.parse_query(req.term, this.element.get(0).selectionStart); - var metatag = query.metatag; - var term = query.term; - - if (!metatag && !term) { - this.close(); - return; - } - - switch(metatag) { - case "md5": - case "width": - case "height": - case "mpixels": - case "ratio": - case "score": - case "favcount": - case "filesize": - case "source": - case "id": - case "date": - case "age": - case "limit": - case "tagcount": - case "pixiv_id": - case "pixiv": - <% TagCategory.short_name_list.each do |category| %> - case "<%= category %>tags": - <% end %> - resp([]); - return; - case "order": - case "status": - case "rating": - case "locked": - case "child": - case "parent": - case "filetype": - Danbooru.Autocomplete.static_metatag_source(term, resp, metatag); - return; - case "user": - case "approver": - case "commenter": - case "comm": - case "noter": - case "noteupdater": - case "artcomm": - case "fav": - case "ordfav": - case "appealer": - case "flagger": - case "upvote": - case "downvote": - Danbooru.Autocomplete.user_source(term, resp, metatag); - break; - case "pool": - case "ordpool": - Danbooru.Autocomplete.pool_source(term, resp, metatag); - break; - case "favgroup": - Danbooru.Autocomplete.favorite_group_source(term, resp, metatag); - break; - case "search": - Danbooru.Autocomplete.saved_search_source(term, resp); - break; - default: - Danbooru.Autocomplete.normal_source(term, resp); - break; - } - } - }); - - $fields_single.autocomplete({ - search: function() { - $(this).data("ui-autocomplete").menu.bindings = $(); - }, - source: function(req, resp) { - Danbooru.Autocomplete.normal_source(req.term, resp); - } - }); - } - - Danbooru.Autocomplete.initialize_artist_autocomplete = function($fields) { - $fields.autocomplete({ - search: function() { - $(this).data("ui-autocomplete").menu.bindings = $(); - }, - source: function(req, resp) { - $.ajax({ - url: "/artists.json", - data: { - "search[name]": req.term + "*", - "search[is_active]": true, - "search[order]": "post_count", - "limit": 10, - "expiry": 7 - }, - method: "get", - success: function(data) { - resp($.map(data, function(artist) { - return { - type: "tag", - label: artist.name.replace(/_/g, " "), - value: artist.name, - category: <%= Tag.categories.artist %>, - }; - })); - } - }); - } - }); - }; - - Danbooru.Autocomplete.initialize_pool_autocomplete = function($fields) { - $fields.autocomplete({ - search: function() { - $(this).data("ui-autocomplete").menu.bindings = $(); - }, - source: function(req, resp) { - Danbooru.Autocomplete.pool_source(req.term, resp); - }, - }); - }; - - Danbooru.Autocomplete.initialize_wiki_autocomplete = function($fields) { - $fields.autocomplete({ - search: function() { - $(this).data("ui-autocomplete").menu.bindings = $(); - }, - source: function(req, resp) { - $.ajax({ - url: "/wiki_pages.json", - data: { - "search[title]": req.term + "*", - "search[hide_deleted]": "Yes", - "search[order]": "post_count", - "limit": 10, - "expiry": 7 - }, - method: "get", - success: function(data) { - resp($.map(data, function(wiki_page) { - return { - type: "tag", - label: wiki_page.title.replace(/_/g, " "), - value: wiki_page.title, - category: wiki_page.category_name - }; - })); - } - }); - } - }); - }; - - Danbooru.Autocomplete.normal_source = function(term, resp) { - var key = "ac-" + term.replace(/\./g,'\uFFFF'); - - $.ajax({ - url: "/tags/autocomplete.json", - data: { - "search[name_matches]": term, - "expiry": 7 - }, - method: "get", - success: function(data) { - var d = $.map(data, function(tag) { - return { - type: "tag", - label: tag.name.replace(/_/g, " "), - antecedent: tag.antecedent_name, - value: tag.name, - category: tag.category, - post_count: tag.post_count - }; - }); - - resp(d); - } - }); - } - - Danbooru.Autocomplete.parse_query = function(text, caret) { - var metatag = ""; - var term = ""; - - var before_caret_text = text.substring(0, caret); - var match = before_caret_text.match(/\S+$/g); - if (match) { - term = match[0]; - } else { - return {}; - } - - if (match = term.match(Danbooru.Autocomplete.PREFIXES)) { - metatag = match[1].toLowerCase(); - term = match[2]; - } - - if (match = term.match(Danbooru.Autocomplete.METATAGS)) { - metatag = match[1].toLowerCase(); - term = match[2]; - } - - return { metatag: metatag, term: term }; - }; - - // Update the input field with the item currently focused in the - // autocomplete menu, then position the caret just after the inserted completion. - Danbooru.Autocomplete.insert_completion = function(input, completion) { - var before_caret_text = input.value.substring(0, input.selectionStart).trim(); - var after_caret_text = input.value.substring(input.selectionStart).trim(); - - var prefixes = "-|~|" + "<%= TagCategory.mapping.keys.map {|category| category + ':'}.join('|') %>"; - var regexp = new RegExp("(" + prefixes + ")?\\S+$", "g"); - before_caret_text = before_caret_text.replace(regexp, "$1") + completion + " "; - - input.value = before_caret_text + after_caret_text; - input.selectionStart = input.selectionEnd = before_caret_text.length; - }; - - // If we press tab while the autocomplete menu is open but nothing is - // focused, complete the first item and close the menu. - Danbooru.Autocomplete.on_tab = function(event) { - var input = this; - var autocomplete = $(input).autocomplete("instance"); - var $autocomplete_menu = autocomplete.menu.element; - - if (!$autocomplete_menu.is(":visible")) { - return; - } - - if ($autocomplete_menu.has(".ui-state-active").length === 0) { - var $first_item = $autocomplete_menu.find(".ui-menu-item").first(); - var completion = $first_item.data().uiAutocompleteItem.value; - - Danbooru.Autocomplete.insert_completion(input, completion); - autocomplete.close(); - } - - // Prevent the tab key from moving focus to the next element. - event.preventDefault(); - }; - - Danbooru.Autocomplete.render_item = function(list, item) { - var $link = $(""); - $link.text(item.label); - $link.attr("href", "/posts?tags=" + encodeURIComponent(item.value)); - $link.click(function(e) { - e.preventDefault(); - }); - - if (item.antecedent) { - var antecedent = item.antecedent.replace(/_/g, " "); - var arrow = $("").html(" → ").addClass("autocomplete-arrow"); - var antecedent_element = $("").text(antecedent).addClass("autocomplete-antecedent"); - $link.prepend([ - antecedent_element, - arrow - ]); - } - - if (item.post_count !== undefined) { - var count; - if (item.post_count >= 1000) { - count = Math.floor(item.post_count / 1000) + "k"; - } else { - count = item.post_count; - } - var $post_count = $("").addClass("post-count").css("float", "right").text(count); - $link.append($post_count); - } - - if (item.type === "tag") { - $link.addClass("tag-type-" + item.category); - } else if (item.type === "user") { - var level_class = "user-" + item.level.toLowerCase(); - $link.addClass(level_class); - if (Danbooru.meta("style-usernames") === "true") { - $link.addClass("with-style"); - } - } else if (item.type === "pool") { - $link.addClass("pool-category-" + item.category); - } - - var $menu_item = $("
").append($link); - return $("
  • ").data("item.autocomplete", item).append($menu_item).appendTo(list); - }; - - Danbooru.Autocomplete.static_metatags = { - order: [ - "id", "id_desc", - "score", "score_asc", - "favcount", "favcount_asc", - "created_at", "created_at_asc", - "change", "change_asc", - "comment", "comment_asc", - "comment_bumped", "comment_bumped_asc", - "note", "note_asc", - "artcomm", "artcomm_asc", - "mpixels", "mpixels_asc", - "portrait", "landscape", - "filesize", "filesize_asc", - "tagcount", "tagcount_asc", - "rank", - "random", - "custom" - ].concat(<%= TagCategory.short_name_list.map {|category| [category + "tags", category + "tags_asc"]}.flatten %>), - status: [ - "any", "deleted", "active", "pending", "flagged", "banned" - ], - rating: [ - "safe", "questionable", "explicit" - ], - locked: [ - "rating", "note", "status" - ], - child: [ - "any", "none" - ], - parent: [ - "any", "none" - ], - filetype: [ - "jpg", "png", "gif", "swf", "zip", "webm", "mp4" - ], - } - - Danbooru.Autocomplete.static_metatag_source = function(term, resp, metatag) { - var sub_metatags = this.static_metatags[metatag]; - - var regexp = new RegExp("^" + $.ui.autocomplete.escapeRegex(term), "i"); - var matches = $.grep(sub_metatags, function (sub_metatag) { - return regexp.test(sub_metatag); - }); - - resp($.map(matches, function(sub_metatag) { - return metatag + ":" + sub_metatag; - })); - } - - Danbooru.Autocomplete.user_source = function(term, resp, metatag) { - $.ajax({ - url: "/users.json", - data: { - "search[order]": "post_upload_count", - "search[current_user_first]": "true", - "search[name_matches]": term + "*", - "limit": 10 - }, - method: "get", - success: function(data) { - var prefix; - var display_name; - - if (metatag === "@") { - prefix = "@"; - display_name = function(name) {return name;}; - } else { - prefix = metatag + ":"; - display_name = function(name) {return name.replace(/_/g, " ");}; - } - - resp($.map(data, function(user) { - return { - type: "user", - label: display_name(user.name), - value: prefix + user.name, - level: user.level_string - }; - })); - } - }); - } - - Danbooru.Autocomplete.pool_source = function(term, resp, metatag) { - $.ajax({ - url: "/pools.json", - data: { - "search[order]": "post_count", - "search[name_matches]": term, - "limit": 10 - }, - method: "get", - success: function(data) { - resp($.map(data, function(pool) { - return { - type: "pool", - label: pool.name.replace(/_/g, " "), - value: (metatag ? (metatag + ":" + pool.name) : pool.name), - post_count: pool.post_count, - category: pool.category - }; - })); - } - }); - } - - Danbooru.Autocomplete.favorite_group_source = function(term, resp, metatag) { - $.ajax({ - url: "/favorite_groups.json", - data: { - "search[name_matches]": term, - "limit": 10 - }, - method: "get", - success: function(data) { - resp($.map(data, function(favgroup) { - return { - label: favgroup.name.replace(/_/g, " "), - value: metatag + ":" + favgroup.name, - post_count: favgroup.post_count - }; - })); - } - }); - } - - Danbooru.Autocomplete.saved_search_source = function(term, resp) { - return Danbooru.SavedSearch.labels(term).then(function(labels) { - resp(labels.map(function(label) { - return { - label: label.replace(/_/g, " "), - value: "search:" + label, - }; - })); - }); - } -})(); - -$(document).ready(function() { - Danbooru.Autocomplete.initialize_all(); -}); diff --git a/app/assets/javascripts/blacklists.js b/app/assets/javascripts/blacklists.js deleted file mode 100644 index 14f1faad5..000000000 --- a/app/assets/javascripts/blacklists.js +++ /dev/null @@ -1,200 +0,0 @@ -(function() { - Danbooru.Blacklist = {}; - - Danbooru.Blacklist.entries = []; - - Danbooru.Blacklist.parse_entry = function(string) { - var entry = { - "tags": string, - "require": [], - "exclude": [], - "disabled": false, - "hits": 0, - "min_score": null - }; - var matches = string.match(/\S+/g) || []; - $.each(matches, function(i, tag) { - if (tag.charAt(0) === '-') { - entry.exclude.push(tag.slice(1)); - } else if (tag.match(/^score:<.+/)) { - var score = tag.match(/^score:<(.+)/)[1]; - entry.min_score = parseInt(score); - } else { - entry.require.push(tag); - } - }); - return entry; - } - - Danbooru.Blacklist.parse_entries = function() { - var entries = (Danbooru.meta("blacklisted-tags") || "nozomiisthebestlovelive").replace(/(rating:[qes])\w+/ig, "$1").toLowerCase().split(/,/); - - $.each(entries, function(i, tags) { - var entry = Danbooru.Blacklist.parse_entry(tags); - Danbooru.Blacklist.entries.push(entry); - }); - } - - Danbooru.Blacklist.toggle_entry = function(e) { - var tags = $(e.target).text(); - var match = $.grep(Danbooru.Blacklist.entries, function(entry, i) { - return entry.tags === tags; - })[0]; - if (match) { - match.disabled = !match.disabled; - if (match.disabled) { - Danbooru.Blacklist.post_hide(e.target); - } else { - Danbooru.Blacklist.post_unhide(e.target); - } - } - Danbooru.Blacklist.apply(); - } - - Danbooru.Blacklist.update_sidebar = function() { - $.each(this.entries, function(i, entry) { - if (entry.hits === 0) { - return; - } - - var item = $("
  • "); - var link = $(""); - var count = $(""); - var hash = entry.tags.hash(); - - link.text(entry.tags); - link.click(Danbooru.Blacklist.toggle_entry); - count.html(entry.hits); - count.addClass("count"); - item.append(link); - item.append(" "); - item.append(count); - - $("#blacklist-list").append(item); - }); - - $("#blacklist-box").show(); - } - - Danbooru.Blacklist.initialize_disable_all_blacklists = function() { - if (Danbooru.Cookie.get("dab") === "1") { - $("#re-enable-all-blacklists").show(); - $("#blacklist-list a:not(.blacklisted-active)").click(); - Danbooru.Blacklist.apply(); - } else { - $("#disable-all-blacklists").show() - } - - $("#disable-all-blacklists").click(function(e) { - $("#disable-all-blacklists").hide(); - $("#re-enable-all-blacklists").show(); - Danbooru.Cookie.put("dab", "1"); - $("#blacklist-list a:not(.blacklisted-active)").click(); - e.preventDefault(); - }); - - $("#re-enable-all-blacklists").click(function(e) { - $("#disable-all-blacklists").show(); - $("#re-enable-all-blacklists").hide(); - Danbooru.Cookie.put("dab", "0"); - $("#blacklist-list a.blacklisted-active").click(); - e.preventDefault(); - }); - } - - Danbooru.Blacklist.apply = function() { - $.each(this.entries, function(i, entry) { - entry.hits = 0; - }); - - var count = 0 - - $.each(this.posts(), function(i, post) { - var post_count = 0; - $.each(Danbooru.Blacklist.entries, function(i, entry) { - if (Danbooru.Blacklist.post_match(post, entry)) { - entry.hits += 1; - count += 1; - post_count += 1; - } - }); - if (post_count > 0) { - Danbooru.Blacklist.post_hide(post); - } else { - Danbooru.Blacklist.post_unhide(post); - } - }); - - return count; - } - - Danbooru.Blacklist.posts = function() { - return $(".post-preview, #image-container, #c-comments .post"); - } - - Danbooru.Blacklist.post_match = function(post, entry) { - if (entry.disabled) { - return false; - } - - var $post = $(post); - var score = parseInt($post.attr("data-score")); - - if (entry.min_score !== null && score < entry.min_score) { - return true; - } - - var tags = String($post.attr("data-tags")).match(/\S+/g) || []; - tags = tags.concat(String($post.attr("data-pools")).match(/\S+/g) || []); - tags.push("rating:" + $post.data("rating")); - if ($post.attr("data-uploader")) { - tags.push("user:" + $post.attr("data-uploader").toLowerCase()); - } - tags.push("uploaderid:" + $post.attr("data-uploader-id")); - tags.push("toptaggerid:" + $post.attr("data-top-tagger")); - $.each(String($post.data("flags")).match(/\S+/g) || [], function(i, v) { - tags.push("status:" + v); - }); - return (entry.require.length > 0 || entry.exclude.length > 0) && Danbooru.is_subset(tags, entry.require) && !Danbooru.intersect(tags, entry.exclude).length; - } - - Danbooru.Blacklist.post_hide = function(post) { - var $post = $(post); - $post.addClass("blacklisted").addClass("blacklisted-active"); - - var $video = $post.find("video").get(0); - if ($video) { - $video.pause(); - $video.currentTime = 0; - } - } - - Danbooru.Blacklist.post_unhide = function(post) { - var $post = $(post); - $post.addClass("blacklisted").removeClass("blacklisted-active"); - - var $video = $post.find("video").get(0); - if ($video) { - $video.play(); - } - } - - Danbooru.Blacklist.initialize_all = function() { - Danbooru.Blacklist.parse_entries(); - - if (Danbooru.Blacklist.apply() > 0) { - Danbooru.Blacklist.update_sidebar(); - Danbooru.Blacklist.initialize_disable_all_blacklists(); - } else { - $("#blacklist-box").hide(); - } - } -})(); - -$(document).ready(function() { - if ($("#blacklist-box").length == 0) { - return; - } - - Danbooru.Blacklist.initialize_all(); -}); diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js deleted file mode 100644 index aee396324..000000000 --- a/app/assets/javascripts/comments.js +++ /dev/null @@ -1,108 +0,0 @@ -(function() { - Danbooru.Comment = {}; - - Danbooru.Comment.initialize_all = function() { - if ($("#c-posts").length || $("#c-comments").length) { - this.initialize_response_link(); - this.initialize_reply_links(); - this.initialize_expand_links(); - this.initialize_vote_links(); - - if (!$("#a-edit").length) { - this.initialize_edit_links(); - } - } - - if ($("#c-posts").length && $("#a-show").length) { - Danbooru.Comment.highlight_threshold_comments(Danbooru.meta("post-id")); - } - } - - Danbooru.Comment.quote = function(e) { - $.get( - "/comments/" + $(e.target).data('comment-id') + ".json", - function(data) { - var $link = $(e.target); - var $div = $link.closest("div.comments-for-post").find(".new-comment"); - var $textarea = $div.find("textarea"); - var msg = data["quoted_response"]; - if ($textarea.val().length > 0) { - msg = $textarea.val() + "\n\n" + msg; - } - $textarea.val(msg); - $div.find("a.expand-comment-response").trigger("click"); - $textarea.selectEnd(); - } - ); - e.preventDefault(); - } - - Danbooru.Comment.initialize_reply_links = function($parent) { - $parent = $parent || $(document); - $parent.find(".reply-link").click(Danbooru.Comment.quote); - } - - Danbooru.Comment.initialize_expand_links = function() { - $(".comment-section form").hide(); - $(".comment-section input.expand-comment-response").click(function(e) { - var post_id = $(this).closest(".comment-section").data("post-id"); - $(this).hide(); - $(".comment-section[data-post-id=" + post_id + "] form").slideDown("fast"); - e.preventDefault(); - }); - } - - Danbooru.Comment.initialize_response_link = function() { - $("a.expand-comment-response").click(function(e) { - $(e.target).hide(); - var $form = $(e.target).closest("div.new-comment").find("form"); - $form.show(); - Danbooru.scroll_to($form); - e.preventDefault(); - }); - - $("div.new-comment form").hide(); - } - - Danbooru.Comment.initialize_edit_links = function($parent) { - $parent = $parent || $(document); - $parent.find(".edit_comment").hide(); - $parent.find(".edit_comment_link").click(function(e) { - var link_id = $(this).attr("id"); - var comment_id = link_id.match(/^edit_comment_link_(\d+)$/)[1]; - $("#edit_comment_" + comment_id).fadeToggle("fast"); - e.preventDefault(); - }); - } - - Danbooru.Comment.highlight_threshold_comments = function(post_id) { - var threshold = parseInt(Danbooru.meta("user-comment-threshold")); - var articles = $("article.comment[data-post-id=" + post_id + "]"); - articles.each(function(i, v) { - var $comment = $(v); - if (parseInt($comment.data("score")) < threshold) { - $comment.addClass("below-threshold"); - } - }); - } - - Danbooru.Comment.hide_threshold_comments = function(post_id) { - var threshold = parseInt(Danbooru.meta("user-comment-threshold")); - var articles = $("article.comment[data-post-id=" + post_id + "]"); - articles.each(function(i, v) { - var $comment = $(v); - if (parseInt($comment.data("score")) < threshold) { - $comment.hide(); - } - }); - } - - Danbooru.Comment.initialize_vote_links = function($parent) { - $parent = $parent || $(document); - $parent.find(".unvote-comment-link").hide(); - } -})(); - -$(document).ready(function() { - Danbooru.Comment.initialize_all(); -}); diff --git a/app/assets/javascripts/cookie.js b/app/assets/javascripts/cookie.js deleted file mode 100644 index 3ce42224d..000000000 --- a/app/assets/javascripts/cookie.js +++ /dev/null @@ -1,73 +0,0 @@ -(function() { - Danbooru.Cookie = {}; - - Danbooru.Cookie.put = function(name, value, days) { - var expires = ""; - if (days !== "session") { - if (!days) { - days = 365; - } - - var date = new Date(); - date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); - expires = "expires=" + date.toGMTString() + "; "; - } - - var new_val = name + "=" + encodeURIComponent(value) + "; " + expires + "path=/"; - if (document.cookie.length < (4090 - new_val.length)) { - document.cookie = new_val; - return true; - } else { - Danbooru.error("You have too many cookies on this site. Consider deleting them all.") - return false; - } - } - - Danbooru.Cookie.raw_get = function(name) { - var nameEq = name + "="; - var ca = document.cookie.split(";"); - - for (var i = 0; i < ca.length; ++i) { - var c = ca[i]; - - while (c.charAt(0) == " ") { - c = c.substring(1, c.length); - } - - if (c.indexOf(nameEq) == 0) { - return c.substring(nameEq.length, c.length); - } - } - - return ""; - } - - Danbooru.Cookie.get = function(name) { - return this.unescape(this.raw_get(name)); - } - - Danbooru.Cookie.remove = function(name) { - this.put(name, "", -1); - } - - Danbooru.Cookie.unescape = function(val) { - return decodeURIComponent(val.replace(/\+/g, " ")); - } - - Danbooru.Cookie.initialize = function() { - var loc = location.href; - - if (loc.match(/^http/)) { - loc = loc.replace(/^https?:\/\/[^\/]+/, ""); - } - - if (this.get("hide-upgrade-account") != "1") { - $("#upgrade-account").show(); - } - } -})(); - -$(function() { - Danbooru.Cookie.initialize(); -}); - diff --git a/app/assets/javascripts/dtext.js b/app/assets/javascripts/dtext.js deleted file mode 100644 index 94b79b502..000000000 --- a/app/assets/javascripts/dtext.js +++ /dev/null @@ -1,68 +0,0 @@ -(function() { - Danbooru.Dtext = {}; - - Danbooru.Dtext.initialize_all = function() { - Danbooru.Dtext.initialize_links(); - Danbooru.Dtext.initialize_expandables(); - } - - Danbooru.Dtext.initialize_links = function() { - $(".simple_form .dtext-preview").hide(); - $(".simple_form input[value=Preview]").click(Danbooru.Dtext.click_button); - } - - Danbooru.Dtext.initialize_expandables = function($parent) { - $parent = $parent || $(document); - $parent.find(".expandable-content").hide(); - $parent.find(".expandable-button").click(function(e) { - var button = $(this); - button.parent().next().fadeToggle("fast"); - if (button.val() === "Show") { - button.val("Hide"); - } else { - button.val("Show"); - } - }); - } - - Danbooru.Dtext.call_preview = function(e, $button, $input, $preview) { - $button.val("Edit"); - $input.hide(); - $preview.text("Loading...").fadeIn("fast"); - $.ajax({ - type: "post", - url: "/dtext_preview", - data: { - body: $input.val() - }, - success: function(data) { - $preview.html(data).fadeIn("fast"); - Danbooru.Dtext.initialize_expandables($preview); - } - }); - } - - Danbooru.Dtext.call_edit = function(e, $button, $input, $preview) { - $button.val("Preview"); - $preview.hide(); - $input.slideDown("fast"); - } - - Danbooru.Dtext.click_button = function(e) { - var $button = $(e.target); - var $input = $("#" + $button.data("input-id")); - var $preview = $("#" + $button.data("preview-id")); - - if ($button.val().match(/preview/i)) { - Danbooru.Dtext.call_preview(e, $button, $input, $preview); - } else { - Danbooru.Dtext.call_edit(e, $button, $input, $preview); - } - - e.preventDefault(); - } -})(); - -$(document).ready(function() { - Danbooru.Dtext.initialize_all(); -}); diff --git a/app/assets/javascripts/favorite_groups.js b/app/assets/javascripts/favorite_groups.js deleted file mode 100644 index cd7706122..000000000 --- a/app/assets/javascripts/favorite_groups.js +++ /dev/null @@ -1,51 +0,0 @@ -(function() { - Danbooru.FavoriteGroup = {}; - - Danbooru.FavoriteGroup.initialize_all = function() { - if ($("#c-posts").length && $("#a-show").length) { - this.initialize_add_to_favgroup_dialog(); - Danbooru.keydown("1 2 3 4 5 6 7 8 9 0", "add_to_favgroup", Danbooru.FavoriteGroup.add_to_favgroup); - } - } - - Danbooru.FavoriteGroup.initialize_add_to_favgroup_dialog = function() { - $("#add-to-favgroup-dialog").dialog({ - autoOpen: false, - width: 500, - buttons: { - "Cancel": function() { - $(this).dialog("close"); - } - } - }); - - var open_favgroup_dialog = function(e) { - if (Danbooru.meta("current-user-id") == "") { // anonymous - return; - } - - if ($(".add-to-favgroup").length === 1) { - // If the user only has one favorite group we don't need to ask which group to add the post to. - $(".add-to-favgroup").click(); - } else if ($(".add-to-favgroup").length > 1) { - $("#add-to-favgroup-dialog").dialog("open"); - } - e.preventDefault(); - } - - Danbooru.keydown("g", "open_favgroup_dialog", open_favgroup_dialog); - $("#open-favgroup-dialog-link").click(open_favgroup_dialog); - } - - Danbooru.FavoriteGroup.add_to_favgroup = function(e) { - var favgroup_index = (e.key === "0") ? "10" : e.key; - var link = $("#add-to-favgroup-" + favgroup_index + ":visible"); - if (link.length) { - link.click(); - } - } -})(); - -$(function() { - Danbooru.FavoriteGroup.initialize_all(); -}); diff --git a/app/assets/javascripts/favorites.js b/app/assets/javascripts/favorites.js deleted file mode 100644 index a3d59af7b..000000000 --- a/app/assets/javascripts/favorites.js +++ /dev/null @@ -1,61 +0,0 @@ -(function() { - Danbooru.Favorite = {}; - - Danbooru.Favorite.initialize_all = function() { - if ($("#c-posts").length) { - this.hide_or_show_add_to_favorites_link(); - } - } - - Danbooru.Favorite.hide_or_show_add_to_favorites_link = function() { - var current_user_id = Danbooru.meta("current-user-id"); - if (current_user_id == "") { - $("#add-to-favorites").hide(); - $("#remove-from-favorites").hide(); - $("#add-fav-button").hide(); - $("#remove-fav-button").hide(); - return; - } - if ($("#image-container").length && $("#image-container").data("is-favorited") == true) { - $("#add-to-favorites").hide(); - $("#add-fav-button").hide(); - } else { - $("#remove-from-favorites").hide(); - $("#remove-fav-button").hide(); - } - } - - Danbooru.Favorite.create = function(post_id) { - Danbooru.Post.notice_update("inc"); - - $.ajax({ - type: "POST", - url: "/favorites", - data: { - post_id: post_id - }, - complete: function() { - Danbooru.Post.notice_update("dec"); - }, - error: function(data, status, xhr) { - Danbooru.notice("Error: " + data.reason); - } - }); - } - - Danbooru.Favorite.destroy = function(post_id) { - Danbooru.Post.notice_update("inc"); - - $.ajax({ - type: "DELETE", - url: "/favorites/" + post_id, - complete: function() { - Danbooru.Post.notice_update("dec"); - } - }); - } -})(); - -$(document).ready(function() { - Danbooru.Favorite.initialize_all(); -}); diff --git a/app/assets/javascripts/forum_post_votes_controller.js b/app/assets/javascripts/forum_post_votes_controller.js deleted file mode 100644 index dee720fac..000000000 --- a/app/assets/javascripts/forum_post_votes_controller.js +++ /dev/null @@ -1,2 +0,0 @@ -// Place all the behaviors and hooks related to the matching controller here. -// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/forum_posts.js b/app/assets/javascripts/forum_posts.js deleted file mode 100644 index 4125f9dec..000000000 --- a/app/assets/javascripts/forum_posts.js +++ /dev/null @@ -1,45 +0,0 @@ -(function() { - Danbooru.ForumPost = {}; - - Danbooru.ForumPost.initialize_all = function() { - if ($("#c-forum-topics #a-show,#c-forum-posts #a-show").length) {; - this.initialize_edit_links(); - - Danbooru.keydown("e", "edit", function(e) { - $(".edit_forum_topic_link")[0].click(); - }); - - Danbooru.keydown("shift+d", "delete", function(e) { - $("#forum-topic-delete a")[0].click(); - }); - } - - if ($("#c-forum-topics").length) { - Danbooru.keydown("shift+r", "mark_all_as_read", function(e) { - $("#forum-topic-mark-all-as-read a")[0].click(); - }); - } - } - - Danbooru.ForumPost.initialize_edit_links = function() { - $(".edit_forum_post, .edit_forum_topic").hide(); - - $(".edit_forum_post_link").click(function(e) { - var link_id = $(this).attr("id"); - var forum_post_id = link_id.match(/^edit_forum_post_link_(\d+)$/)[1]; - $("#edit_forum_post_" + forum_post_id).fadeToggle("fast"); - e.preventDefault(); - }); - - $(".edit_forum_topic_link").click(function(e) { - var link_id = $(this).attr("id"); - var forum_topic_id = link_id.match(/^edit_forum_topic_link_(\d+)$/)[1]; - $("#edit_forum_topic_" + forum_topic_id).fadeToggle("fast"); - e.preventDefault(); - }); - } -})(); - -$(document).ready(function() { - Danbooru.ForumPost.initialize_all(); -}); diff --git a/app/assets/javascripts/janitor_trials.js b/app/assets/javascripts/janitor_trials.js deleted file mode 100644 index 6c28fad1d..000000000 --- a/app/assets/javascripts/janitor_trials.js +++ /dev/null @@ -1,29 +0,0 @@ -(function() { - Danbooru.JanitorTrials = {}; - - Danbooru.JanitorTrials.initialize_all = function() { - if ($("#c-janitor-trials").length) { - $("input[value=Test]").click(function(e) { - $.ajax({ - type: "get", - url: "/janitor_trials/test.json", - data: { - janitor_trial: { - user_name: $("#janitor_trial_user_name").val() - } - }, - success: function(data) { - $("#test-results").html(data); - } - }); - - e.preventDefault(); - }); - } - } -})(); - - -$(document).ready(function() { - Danbooru.JanitorTrials.initialize_all(); -}); diff --git a/app/assets/javascripts/mod_queue.js b/app/assets/javascripts/mod_queue.js deleted file mode 100644 index a2075e735..000000000 --- a/app/assets/javascripts/mod_queue.js +++ /dev/null @@ -1,65 +0,0 @@ -(function() { - Danbooru.ModQueue = {}; - - Danbooru.ModQueue.processed = 0; - - Danbooru.ModQueue.increment_processed = function() { - if (Danbooru.meta("random-mode") === "1") { - Danbooru.ModQueue.processed += 1; - - if (Danbooru.ModQueue.processed === 12) { - window.location = Danbooru.meta("return-to"); - } - } - } - - Danbooru.ModQueue.initialize_hilights = function() { - $.each($("div.post"), function(i, v) { - var $post = $(v); - var score = parseInt($post.data("score")); - if (score >= 3) { - $post.addClass("post-pos-score"); - } - if (score <= -3) { - $post.addClass("post-neg-score"); - } - if ($post.data("has-children")) { - $post.addClass("post-has-children"); - } - }); - } - - Danbooru.ModQueue.initialize_detailed_rejection_links = function() { - $(".detailed-rejection-link").click(Danbooru.ModQueue.detailed_rejection_dialog) - } - - Danbooru.ModQueue.detailed_rejection_dialog = function() { - $("#post_disapproval_post_id").val($(this).data("post-id")); - - $("#detailed-rejection-dialog").dialog({ - width: 500, - buttons: { - "Submit": function() { - $(this).find("form").submit(); - $(this).dialog("close"); - }, - "Cancel": function() { - $(this).dialog("close"); - } - } - }); - - return false; - } -})(); - -$(function() { - if ($("#c-moderator-post-queues").length) { - Danbooru.ModQueue.initialize_hilights(); - Danbooru.ModQueue.initialize_detailed_rejection_links(); - } - - if ($("#c-posts #a-show").length) { - Danbooru.ModQueue.initialize_detailed_rejection_links(); - } -}); diff --git a/app/assets/javascripts/news_updates.js b/app/assets/javascripts/news_updates.js deleted file mode 100644 index 9283bbb79..000000000 --- a/app/assets/javascripts/news_updates.js +++ /dev/null @@ -1,28 +0,0 @@ -(function() { - Danbooru.NewsUpdate = {}; - - Danbooru.NewsUpdate.initialize = function() { - var key = $("#news-updates").data("id"); - - if (Danbooru.Cookie.get("news-ticker") == key) { - $("#news-updates").hide(); - } else { - $("#news-updates").show(); - - $("#close-news-ticker-link").click(function(e) { - $("#news-updates").hide(); - Danbooru.Cookie.put("news-ticker", key); - - // need to reset the more link - var $site_map_link = $("#site-map-link"); - $("#more-links").hide().offset({top: $site_map_link.offset().top + $site_map_link.height() + 10, left: $site_map_link.offset().left}); - - return false; - }); - } - } -})(); - -$(function() { - Danbooru.NewsUpdate.initialize(); -}); diff --git a/app/assets/javascripts/paginator.js b/app/assets/javascripts/paginator.js deleted file mode 100644 index 74b814d1a..000000000 --- a/app/assets/javascripts/paginator.js +++ /dev/null @@ -1,25 +0,0 @@ -(function() { - Danbooru.Paginator = {}; - - Danbooru.Paginator.next_page = function() { - var href = $(".paginator a[rel=next]").attr("href"); - if (href) { - window.location = href; - } - } - - Danbooru.Paginator.prev_page = function() { - var href = $(".paginator a[rel=prev]").attr("href"); - if (href) { - window.location = href; - } - } -})(); - -$(function() { - if ($(".paginator").length) { - Danbooru.keydown("d right", "next_page", Danbooru.Paginator.next_page); - Danbooru.keydown("a left", "prev_page", Danbooru.Paginator.prev_page); - } -}); - diff --git a/app/assets/javascripts/pools.js b/app/assets/javascripts/pools.js deleted file mode 100644 index 7c69a6f01..000000000 --- a/app/assets/javascripts/pools.js +++ /dev/null @@ -1,63 +0,0 @@ -(function() { - Danbooru.Pool = {}; - - Danbooru.Pool.initialize_all = function() { - if ($("#c-pools").length) { - this.initialize_shortcuts(); - } - - if ($("#c-posts").length && $("#a-show").length) { - this.initialize_add_to_pool_link(); - } - - if ($("#c-pool-orders,#c-favorite-group-orders").length) { - this.initialize_simple_edit(); - } - } - - Danbooru.Pool.initialize_add_to_pool_link = function() { - $("#add-to-pool-dialog").dialog({autoOpen: false}); - - $("#pool").click(function(e) { - e.preventDefault(); - $("#add-to-pool-dialog").dialog("open"); - }); - - $("#recent-pools li").click(function(e) { - e.preventDefault(); - $("#pool_name").val($(this).attr("data-value")); - }); - } - - Danbooru.Pool.initialize_shortcuts = function() { - if ($("#c-pools #a-show").length) { - Danbooru.keydown("e", "edit", function(e) { - $("#pool-edit a")[0].click(); - }); - - Danbooru.keydown("shift+d", "delete", function(e) { - $("#pool-delete a")[0].click(); - }); - } - }; - - Danbooru.Pool.initialize_simple_edit = function() { - $("#sortable").sortable({ - placeholder: "ui-state-placeholder" - }); - $("#sortable").disableSelection(); - - $("#ordering-form").submit(function(e) { - $.ajax({ - type: "put", - url: e.target.action, - data: $("#sortable").sortable("serialize") + "&" + $(e.target).serialize() - }); - e.preventDefault(); - }); - } -})(); - -$(document).ready(function() { - Danbooru.Pool.initialize_all(); -}); diff --git a/app/assets/javascripts/post_appeals.js b/app/assets/javascripts/post_appeals.js deleted file mode 100644 index 409910d02..000000000 --- a/app/assets/javascripts/post_appeals.js +++ /dev/null @@ -1,42 +0,0 @@ -(function() { - Danbooru.PostAppeal = {}; - - Danbooru.PostAppeal.initialize_all = function() { - if ($("#c-posts").length && $("#a-show").length) { - this.initialize_appeal(); - this.hide_or_show_appeal_link(); - } - } - - Danbooru.PostAppeal.hide_or_show_appeal_link = function() { - if ((Danbooru.meta("post-is-flagged") === "false") && (Danbooru.meta("post-is-deleted") === "false")) { - $("#appeal").hide(); - } - } - - Danbooru.PostAppeal.initialize_appeal = function() { - $("#appeal-dialog").dialog({ - autoOpen: false, - width: 700, - modal: true, - buttons: { - "Submit": function() { - $("#appeal-dialog form").submit(); - $(this).dialog("close"); - }, - "Cancel": function() { - $(this).dialog("close"); - } - } - }); - - $("#appeal").click(function(e) { - e.preventDefault(); - $("#appeal-dialog").dialog("open"); - }); - } -})(); - -$(document).ready(function() { - Danbooru.PostAppeal.initialize_all(); -}); diff --git a/app/assets/javascripts/post_flags.js b/app/assets/javascripts/post_flags.js deleted file mode 100644 index d8ea3b70d..000000000 --- a/app/assets/javascripts/post_flags.js +++ /dev/null @@ -1,46 +0,0 @@ -(function() { - Danbooru.PostFlag = {}; - - Danbooru.PostFlag.initialize_all = function() { - if ($("#c-posts").length && $("#a-show").length) { - this.initialize_flag(); - this.hide_or_show_flag_link(); - } - } - - Danbooru.PostFlag.hide_or_show_flag_link = function() { - if (Danbooru.meta("post-is-deleted") === "true") { - $("#flag").hide(); - } - } - - Danbooru.PostFlag.initialize_flag = function() { - $("#flag-dialog").dialog({ - autoOpen: false, - width: 700, - modal: true, - buttons: { - "Submit": function() { - $("#flag-dialog form").submit(); - $(this).dialog("close"); - }, - "Cancel": function() { - $(this).dialog("close"); - } - } - }); - - $('#flag-dialog form').submit(function() { - $('#flag-dialog').dialog('close'); - }); - - $("#flag").click(function(e) { - e.preventDefault(); - $("#flag-dialog").dialog("open"); - }); - } -})(); - -$(function() { - Danbooru.PostFlag.initialize_all(); -}); diff --git a/app/assets/javascripts/post_mode_menu.js b/app/assets/javascripts/post_mode_menu.js deleted file mode 100644 index e3a1c363d..000000000 --- a/app/assets/javascripts/post_mode_menu.js +++ /dev/null @@ -1,186 +0,0 @@ -(function() { - Danbooru.PostModeMenu = {}; - - Danbooru.PostModeMenu.initialize = function() { - if ($("#c-posts").length || $("#c-favorites").length || $("#c-pools").length) { - this.initialize_selector(); - this.initialize_preview_link(); - this.initialize_edit_form(); - this.initialize_tag_script_field(); - this.initialize_shortcuts(); - Danbooru.PostModeMenu.change(); - } - } - - Danbooru.PostModeMenu.initialize_shortcuts = function() { - Danbooru.keydown("1 2 3 4 5 6 7 8 9 0", "change_tag_script", Danbooru.PostModeMenu.change_tag_script); - } - - Danbooru.PostModeMenu.show_notice = function(i) { - Danbooru.notice("Switched to tag script #" + i + ". To switch tag scripts, use the number keys."); - } - - Danbooru.PostModeMenu.change_tag_script = function(e) { - if ($("#mode-box select").val() === "tag-script") { - var old_tag_script_id = Danbooru.Cookie.get("current_tag_script_id") || "1"; - var old_tag_script = $("#tag-script-field").val(); - - var new_tag_script_id = String.fromCharCode(e.which); - var new_tag_script = Danbooru.Cookie.get("tag-script-" + new_tag_script_id); - - $("#tag-script-field").val(new_tag_script); - Danbooru.Cookie.put("current_tag_script_id", new_tag_script_id); - if (old_tag_script_id != new_tag_script_id) { - Danbooru.PostModeMenu.show_notice(new_tag_script_id); - } - - e.preventDefault(); - } - } - - Danbooru.PostModeMenu.initialize_selector = function() { - if (Danbooru.Cookie.get("mode") === "") { - Danbooru.Cookie.put("mode", "view"); - $("#mode-box select").val("view"); - } else { - $("#mode-box select").val(Danbooru.Cookie.get("mode")); - } - - $("#mode-box select").change(function(e) { - Danbooru.PostModeMenu.change(); - $("#tag-script-field:visible").focus().select(); - }); - } - - Danbooru.PostModeMenu.initialize_preview_link = function() { - $(".post-preview a").click(Danbooru.PostModeMenu.click); - } - - Danbooru.PostModeMenu.initialize_edit_form = function() { - $("#quick-edit-div").hide(); - $("#quick-edit-form input[value=Cancel]").click(function(e) { - Danbooru.PostModeMenu.close_edit_form(); - e.preventDefault(); - }); - - $("#quick-edit-form").submit(function(e) { - $.ajax({ - type: "put", - url: $("#quick-edit-form").attr("action"), - data: { - post: { - tag_string: $("#post_tag_string").val() - } - }, - complete: function() { - $.rails.enableFormElements($("#quick-edit-form")); - }, - success: function(data) { - Danbooru.Post.update_data(data); - $("#post_" + data.id).effect("shake", {distance: 5, times: 1}, 100); - Danbooru.notice("Post #" + data.id + " updated"); - Danbooru.PostModeMenu.close_edit_form(); - } - }); - - e.preventDefault(); - }); - } - - Danbooru.PostModeMenu.close_edit_form = function() { - $("#quick-edit-div").slideUp("fast"); - if (Danbooru.meta("enable-auto-complete") === "true") { - $("#post_tag_string").data("uiAutocomplete").close(); - } - } - - Danbooru.PostModeMenu.initialize_tag_script_field = function() { - $("#tag-script-field").blur(function(e) { - var script = $(this).val(); - - if (script) { - var current_script_id = Danbooru.Cookie.get("current_tag_script_id"); - Danbooru.Cookie.put("tag-script-" + current_script_id, script); - } else { - $("#mode-box select").val("view"); - Danbooru.PostModeMenu.change(); - } - }); - } - - Danbooru.PostModeMenu.change = function() { - $("#quick-edit-div").slideUp("fast"); - var s = $("#mode-box select").val(); - if (s === undefined) { - return; - } - var $body = $(document.body); - $body.removeClass(); - $body.addClass("mode-" + s); - Danbooru.Cookie.put("mode", s, 1); - - if (s === "tag-script") { - var current_script_id = Danbooru.Cookie.get("current_tag_script_id"); - if (!current_script_id) { - current_script_id = "1"; - Danbooru.Cookie.put("current_tag_script_id", current_script_id); - } - var script = Danbooru.Cookie.get("tag-script-" + current_script_id); - - $("#tag-script-field").val(script).show(); - Danbooru.PostModeMenu.show_notice(current_script_id); - } else { - $("#tag-script-field").hide(); - } - } - - Danbooru.PostModeMenu.open_edit = function(post_id) { - var $post = $("#post_" + post_id); - $("#quick-edit-div").slideDown("fast"); - $("#quick-edit-form").attr("action", "/posts/" + post_id + ".json"); - $("#post_tag_string").val($post.data("tags") + " ").focus().selectEnd(); - - /* Set height of tag edit box to fit content. */ - $("#post_tag_string").height(80); // min height: 80px. - var padding = $("#post_tag_string").innerHeight() - $("#post_tag_string").height(); - var height = $("#post_tag_string").prop("scrollHeight") - padding; - $("#post_tag_string").height(height); - } - - Danbooru.PostModeMenu.click = function(e) { - var s = $("#mode-box select").val(); - var post_id = $(e.target).closest("article").data("id"); - - if (s === "add-fav") { - Danbooru.Favorite.create(post_id); - } else if (s === "remove-fav") { - Danbooru.Favorite.destroy(post_id); - } else if (s === "edit") { - Danbooru.PostModeMenu.open_edit(post_id); - } else if (s === 'vote-down') { - Danbooru.Post.vote("down", post_id); - } else if (s === 'vote-up') { - Danbooru.Post.vote("up", post_id); - } else if (s === 'lock-rating') { - Danbooru.Post.update(post_id, {"post[is_rating_locked]": "1"}); - } else if (s === 'lock-note') { - Danbooru.Post.update(post_id, {"post[is_note_locked]": "1"}); - } else if (s === 'approve') { - Danbooru.Post.approve(post_id); - } else if (s === 'ban') { - Danbooru.Post.ban(post_id); - } else if (s === "tag-script") { - var current_script_id = Danbooru.Cookie.get("current_tag_script_id"); - var tag_script = Danbooru.Cookie.get("tag-script-" + current_script_id); - Danbooru.TagScript.run(post_id, tag_script); - } else { - return; - } - - e.preventDefault(); - } -})(); - -$(function() { - Danbooru.PostModeMenu.initialize(); -}); diff --git a/app/assets/javascripts/post_moderation.js b/app/assets/javascripts/post_moderation.js deleted file mode 100644 index 407609683..000000000 --- a/app/assets/javascripts/post_moderation.js +++ /dev/null @@ -1,29 +0,0 @@ -(function() { - Danbooru.PostModeration = {}; - - Danbooru.PostModeration.initialize_all = function() { - if ($("#c-posts").length && $("#a-show").length) { - this.hide_or_show_approve_and_disapprove_links(); - this.hide_or_show_delete_and_undelete_links(); - } - } - - Danbooru.PostModeration.hide_or_show_approve_and_disapprove_links = function() { - if (Danbooru.meta("post-is-approvable") !== "true") { - $("#approve").hide(); - $("#disapprove").hide(); - } - } - - Danbooru.PostModeration.hide_or_show_delete_and_undelete_links = function() { - if (Danbooru.meta("post-is-deleted") === "true") { - $("#delete").hide(); - } else { - $("#undelete").hide(); - } - } -})(); - -$(document).ready(function() { - Danbooru.PostModeration.initialize_all(); -}); diff --git a/app/assets/javascripts/post_popular.js b/app/assets/javascripts/post_popular.js deleted file mode 100644 index 7908f1e08..000000000 --- a/app/assets/javascripts/post_popular.js +++ /dev/null @@ -1,36 +0,0 @@ -(function() { - Danbooru.PostPopular = {}; - - Danbooru.PostPopular.nav_prev = function(e) { - if ($("#popular-nav-links").length) { - var href = $("#popular-nav-links a[rel=prev]").attr("href"); - if (href) { - location.href = href; - } - } - - e.preventDefault(); - } - - Danbooru.PostPopular.nav_next = function(e) { - if ($("#popular-nav-links").length) { - var href = $("#popular-nav-links a[rel=next]").attr("href"); - if (href) { - location.href = href; - } - } - - e.preventDefault(); - } - - Danbooru.PostPopular.initialize_all = function() { - if ($("#c-explore-posts").length) { - Danbooru.keydown("a left", "prev_page", Danbooru.PostPopular.nav_prev); - Danbooru.keydown("d right", "next_page", Danbooru.PostPopular.nav_next); - } - } -})(); - -$(document).ready(function() { - Danbooru.PostPopular.initialize_all(); -}); diff --git a/app/assets/javascripts/posts.js.erb b/app/assets/javascripts/posts.js.erb deleted file mode 100644 index aa7a0f2ab..000000000 --- a/app/assets/javascripts/posts.js.erb +++ /dev/null @@ -1,680 +0,0 @@ -(function() { - Danbooru.Post = {}; - - Danbooru.Post.pending_update_count = 0; - - Danbooru.Post.initialize_all = function() { - if ($("#c-posts").length) { - this.initialize_shortcuts(); - this.initialize_saved_searches(); - } - - if ($("#c-posts").length && $("#a-index").length) { - this.initialize_excerpt(); - this.initialize_gestures(); - } - - if ($("#c-posts").length && $("#a-show").length) { - this.initialize_links(); - this.initialize_post_relationship_previews(); - this.initialize_favlist(); - this.initialize_post_sections(); - this.initialize_post_image_resize_links(); - this.initialize_post_image_resize_to_window_link(); - this.initialize_similar(); - this.initialize_replace_image_dialog(); - this.initialize_gestures(); - - if ((Danbooru.meta("always-resize-images") === "true") || (Danbooru.meta("viewport") && (window.screen.width <= 660))) { - $("#image-resize-to-window-link").click(); - } - } - - if ($("#image").length) { - this.initialize_edit_dialog(); - } - } - - Danbooru.Post.initialize_gestures = function() { - if (Danbooru.meta("disable-mobile-gestures") === "true") { - return; - } - var $body = $("body"); - if ($body.data("hammer")) { - return; - } - if (!Danbooru.test_max_width(660)) { - return; - } - $("#image-container").css({overflow: "visible"}); - var hasPrev = $("#a-show").length || $(".paginator a[rel~=prev]").length; - var hasNext = $("#a-index").length && $(".paginator a[rel~=next]").length; - - $body.hammer({touchAction: 'pan-y', recognizers: [[Hammer.Swipe, { threshold: 20, velocity: 0.4, direction: Hammer.DIRECTION_HORIZONTAL }]], inputClass: Hammer.TouchInput}); - - if (hasPrev) { - $body.hammer().on("swiperight", function(e) { - $("body").css({"transition-timing-function": "ease", "transition-duration": "0.2s", "opacity": "0", "transform": "translateX(150%)"}); - $.timeout(200).done(function() {Danbooru.Post.swipe_prev(e)}); - }); - } - - if (hasNext) { - $body.hammer().on("swipeleft", function(e) { - $("body").css({"transition-timing-function": "ease", "transition-duration": "0.2s", "opacity": "0", "transform": "translateX(-150%)"}); - $.timeout(200).done(function() {Danbooru.Post.swipe_next(e)}); - }); - } - } - - Danbooru.Post.initialize_edit_dialog = function(e) { - $("#open-edit-dialog").button().show().click(function(e) { - $(window).scrollTop($("#image").offset().top); - Danbooru.Post.open_edit_dialog(); - e.preventDefault(); - }); - - $("#toggle-related-tags-link").click(function(e) { - Danbooru.RelatedTag.toggle(); - e.preventDefault(); - }); - } - - Danbooru.Post.open_edit_dialog = function() { - var $tag_string = $("#post_tag_string,#upload_tag_string"); - $("div.input").has($tag_string).prevAll().hide(); - $("#open-edit-dialog").hide(); - - $("#toggle-related-tags-link").show().click(); - - var dialog = $("
    ").attr("id", "edit-dialog"); - $("#form").appendTo(dialog); - dialog.dialog({ - title: "Edit tags", - width: $(window).width() * 0.6, - position: { - my: "right", - at: "right-20", - of: window - }, - drag: function(e, ui) { - if (Danbooru.meta("enable-auto-complete") === "true") { - $tag_string.data("uiAutocomplete").close(); - } - }, - close: Danbooru.Post.close_edit_dialog - }); - dialog.dialog("widget").draggable("option", "containment", "none"); - - var pin_button = $("