Migrate assets to use Webpacker
This commit is contained in:
18
.babelrc
Normal file
18
.babelrc
Normal file
@@ -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 }]
|
||||||
|
]
|
||||||
|
}
|
||||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -25,4 +25,9 @@ danbooru.sublime-workspace
|
|||||||
script/scratch.*
|
script/scratch.*
|
||||||
test/fixtures/vcr_cassettes
|
test/fixtures/vcr_cassettes
|
||||||
.gitconfig
|
.gitconfig
|
||||||
test/reports
|
test/reports
|
||||||
|
/public/packs-test
|
||||||
|
/node_modules
|
||||||
|
yarn-debug.log*
|
||||||
|
.yarn-integrity
|
||||||
|
public/packs
|
||||||
3
.postcssrc.yml
Normal file
3
.postcssrc.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
plugins:
|
||||||
|
postcss-import: {}
|
||||||
|
postcss-cssnext: {}
|
||||||
1
Gemfile
1
Gemfile
@@ -50,6 +50,7 @@ gem 'recaptcha', require: "recaptcha/rails"
|
|||||||
gem 'activemodel-serializers-xml'
|
gem 'activemodel-serializers-xml'
|
||||||
gem 'ptools'
|
gem 'ptools'
|
||||||
gem 'jquery-rails'
|
gem 'jquery-rails'
|
||||||
|
gem 'webpacker', '>= 4.0.x'
|
||||||
|
|
||||||
# needed for looser jpeg header compat
|
# needed for looser jpeg header compat
|
||||||
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"
|
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"
|
||||||
|
|||||||
@@ -277,6 +277,8 @@ GEM
|
|||||||
rack (2.0.5)
|
rack (2.0.5)
|
||||||
rack-protection (2.0.3)
|
rack-protection (2.0.3)
|
||||||
rack
|
rack
|
||||||
|
rack-proxy (0.6.4)
|
||||||
|
rack
|
||||||
rack-test (1.0.0)
|
rack-test (1.0.0)
|
||||||
rack (>= 1.0, < 3)
|
rack (>= 1.0, < 3)
|
||||||
radix62 (1.0.1)
|
radix62 (1.0.1)
|
||||||
@@ -419,6 +421,10 @@ GEM
|
|||||||
addressable (>= 2.3.6)
|
addressable (>= 2.3.6)
|
||||||
crack (>= 0.3.2)
|
crack (>= 0.3.2)
|
||||||
hashdiff
|
hashdiff
|
||||||
|
webpacker (4.0.0.pre.pre.2)
|
||||||
|
activesupport (>= 4.2)
|
||||||
|
rack-proxy (>= 0.6.1)
|
||||||
|
railties (>= 4.2)
|
||||||
webrobots (0.1.2)
|
webrobots (0.1.2)
|
||||||
websocket-driver (0.7.0)
|
websocket-driver (0.7.0)
|
||||||
websocket-extensions (>= 0.1.0)
|
websocket-extensions (>= 0.1.0)
|
||||||
@@ -507,6 +513,7 @@ DEPENDENCIES
|
|||||||
unicorn
|
unicorn
|
||||||
unicorn-worker-killer
|
unicorn-worker-killer
|
||||||
webmock
|
webmock
|
||||||
|
webpacker (>= 4.0.x)
|
||||||
whenever
|
whenever
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
|
|||||||
@@ -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 .
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
@@ -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 href='/wiki_pages/" + escape($("#artist_name").val()) + "'>A wiki page with this name already exists</a>. 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();
|
|
||||||
});
|
|
||||||
@@ -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 = $("<a/>");
|
|
||||||
$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 = $("<span/>").html(" → ").addClass("autocomplete-arrow");
|
|
||||||
var antecedent_element = $("<span/>").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 = $("<span/>").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 = $("<div/>").append($link);
|
|
||||||
return $("<li/>").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();
|
|
||||||
});
|
|
||||||
@@ -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 = $("<li/>");
|
|
||||||
var link = $("<a/>");
|
|
||||||
var count = $("<span/>");
|
|
||||||
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();
|
|
||||||
});
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
@@ -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.
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
@@ -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();
|
|
||||||
});
|
|
||||||
@@ -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 = $("<div/>").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 = $("<button/>").button({icons: {primary: "ui-icon-pin-w"}, label: "pin", text: false});
|
|
||||||
pin_button.css({width: "20px", height: "20px", position: "absolute", right: "28.4px"});
|
|
||||||
dialog.parent().children(".ui-dialog-titlebar").append(pin_button);
|
|
||||||
pin_button.click(function(e) {
|
|
||||||
var dialog_widget = $('.ui-dialog:has(#edit-dialog)');
|
|
||||||
var pos = dialog_widget.offset();
|
|
||||||
|
|
||||||
if (dialog_widget.css("position") === "absolute") {
|
|
||||||
pos.left -= $(window).scrollLeft();
|
|
||||||
pos.top -= $(window).scrollTop();
|
|
||||||
dialog_widget.offset(pos).css({position:"fixed"});
|
|
||||||
dialog.dialog("option", "resize", function() { dialog_widget.css({position:"fixed"}); });
|
|
||||||
|
|
||||||
pin_button.button("option", "icons", {primary: "ui-icon-pin-s"});
|
|
||||||
} else {
|
|
||||||
pos.left += $(window).scrollLeft();
|
|
||||||
pos.top += $(window).scrollTop();
|
|
||||||
dialog_widget.offset(pos).css({position:"absolute"});
|
|
||||||
dialog.dialog("option", "resize", function() {});
|
|
||||||
|
|
||||||
pin_button.button("option", "icons", {primary: "ui-icon-pin-w"});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dialog.parent().mouseout(function(e) {
|
|
||||||
dialog.parent().css({"opacity": 0.6, "transition": "opacity .2s ease"});
|
|
||||||
})
|
|
||||||
.mouseover(function(e) {
|
|
||||||
dialog.parent().css({"opacity": 1});
|
|
||||||
});
|
|
||||||
|
|
||||||
$tag_string.css({"resize": "none", "width": "100%"});
|
|
||||||
$tag_string.focus().selectEnd().height($tag_string[0].scrollHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.close_edit_dialog = function(e, ui) {
|
|
||||||
$("#form").appendTo($("#c-posts #edit,#c-uploads #a-new"));
|
|
||||||
$("#edit-dialog").remove();
|
|
||||||
Danbooru.RelatedTag.show();
|
|
||||||
$("#toggle-related-tags-link").hide();
|
|
||||||
var $tag_string = $("#post_tag_string,#upload_tag_string");
|
|
||||||
$("div.input").has($tag_string).prevAll().show();
|
|
||||||
$("#open-edit-dialog").show();
|
|
||||||
$tag_string.css({"resize": "", "width": ""});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.initialize_similar = function() {
|
|
||||||
$("#similar-button").click(function(e) {
|
|
||||||
$.get("/iqdb_queries", {"url": $("#post_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.swipe_prev = function(e) {
|
|
||||||
if ($("#a-show").length) {
|
|
||||||
window.history.back();
|
|
||||||
} if ($(".paginator a[rel~=prev]").length) {
|
|
||||||
location.href = $("a[rel~=prev]").attr("href");
|
|
||||||
}
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.nav_prev = function(e) {
|
|
||||||
if ($("#search-seq-nav").length) {
|
|
||||||
var href = $("#search-seq-nav a[rel~=prev]").attr("href");
|
|
||||||
if (href) {
|
|
||||||
location.href = href;
|
|
||||||
}
|
|
||||||
} else if ($(".paginator a[rel~=prev]").length) {
|
|
||||||
location.href = $("a[rel~=prev]").attr("href");
|
|
||||||
} else {
|
|
||||||
var href = $("#pool-nav a.active[rel~=prev], #favgroup-nav a.active[rel~=prev]").attr("href");
|
|
||||||
if (href) {
|
|
||||||
location.href = href;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.nav_next = function(e) {
|
|
||||||
if ($("#search-seq-nav").length) {
|
|
||||||
var href = $("#search-seq-nav a[rel~=next]").attr("href");
|
|
||||||
location.href = href;
|
|
||||||
} else if ($(".paginator a[rel~=next]").length) {
|
|
||||||
location.href = $(".paginator a[rel~=next]").attr("href");
|
|
||||||
} else {
|
|
||||||
var href = $("#pool-nav a.active[rel~=next], #favgroup-nav a.active[rel~=next]").attr("href");
|
|
||||||
if (href) {
|
|
||||||
location.href = href;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.swipe_next = function(e) {
|
|
||||||
if ($(".paginator a[rel~=next ]").length) {
|
|
||||||
location.href = $(".paginator a[rel~=next]").attr("href");
|
|
||||||
}
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.initialize_shortcuts = function() {
|
|
||||||
if ($("#a-show").length) {
|
|
||||||
Danbooru.keydown("e", "edit", function(e) {
|
|
||||||
$("#post-edit-link").trigger("click");
|
|
||||||
$("#post_tag_string").focus();
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (Danbooru.meta("current-user-can-approve-posts") === "true") {
|
|
||||||
Danbooru.keydown("shift+o", "approve", function(e) {
|
|
||||||
$(".approve-link").click();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.keydown("a", "prev_page", Danbooru.Post.nav_prev);
|
|
||||||
Danbooru.keydown("d", "next_page", Danbooru.Post.nav_next);
|
|
||||||
Danbooru.keydown("f", "favorite", Danbooru.Post.favorite);
|
|
||||||
Danbooru.keydown("shift+f", "unfavorite", Danbooru.Post.unfavorite);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.initialize_links = function() {
|
|
||||||
$("#copy-notes").click(function(e) {
|
|
||||||
var current_post_id = $("meta[name=post-id]").attr("content");
|
|
||||||
var other_post_id = parseInt(prompt("Enter the ID of the post to copy all notes to:"), 10);
|
|
||||||
|
|
||||||
if (other_post_id !== null) {
|
|
||||||
$.ajax("/posts/" + current_post_id + "/copy_notes", {
|
|
||||||
type: "PUT",
|
|
||||||
data: {
|
|
||||||
other_post_id: other_post_id
|
|
||||||
},
|
|
||||||
success: function(data) {
|
|
||||||
Danbooru.notice("Successfully copied notes to <a href='" + other_post_id + "'>post #" + other_post_id + "</a>");
|
|
||||||
},
|
|
||||||
error: function(data) {
|
|
||||||
if (data.status === 404) {
|
|
||||||
Danbooru.error("Error: Invalid destination post");
|
|
||||||
} else if (data.responseJSON && data.responseJSON.reason) {
|
|
||||||
Danbooru.error("Error: " + data.responseJSON.reason);
|
|
||||||
} else {
|
|
||||||
Danbooru.error("There was an error copying notes to <a href='" + other_post_id + "'>post #" + other_post_id + "</a>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
$(".unvote-post-link").hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.initialize_post_relationship_previews = function() {
|
|
||||||
var current_post_id = $("meta[name=post-id]").attr("content");
|
|
||||||
$("[id=post_" + current_post_id + "]").addClass("current-post");
|
|
||||||
|
|
||||||
if (Danbooru.Cookie.get("show-relationship-previews") === "0") {
|
|
||||||
this.toggle_relationship_preview($("#has-children-relationship-preview"), $("#has-children-relationship-preview-link"));
|
|
||||||
this.toggle_relationship_preview($("#has-parent-relationship-preview"), $("#has-parent-relationship-preview-link"));
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#has-children-relationship-preview-link").click(function(e) {
|
|
||||||
Danbooru.Post.toggle_relationship_preview($("#has-children-relationship-preview"), $(this));
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#has-parent-relationship-preview-link").click(function(e) {
|
|
||||||
Danbooru.Post.toggle_relationship_preview($("#has-parent-relationship-preview"), $(this));
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.toggle_relationship_preview = function(preview, preview_link) {
|
|
||||||
preview.toggle();
|
|
||||||
if (preview.is(":visible")) {
|
|
||||||
preview_link.html("« hide");
|
|
||||||
Danbooru.Cookie.put("show-relationship-previews", "1");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
preview_link.html("show »");
|
|
||||||
Danbooru.Cookie.put("show-relationship-previews", "0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.initialize_favlist = function() {
|
|
||||||
$("#favlist").hide();
|
|
||||||
$("#hide-favlist-link").hide();
|
|
||||||
var fav_count = $("#show-favlist-link").prev().text();
|
|
||||||
if (fav_count === "0") {
|
|
||||||
$("#show-favlist-link").hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#show-favlist-link").click(function(e) {
|
|
||||||
$("#favlist").show();
|
|
||||||
$(this).hide();
|
|
||||||
$("#hide-favlist-link").show();
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#hide-favlist-link").click(function(e) {
|
|
||||||
$("#favlist").hide();
|
|
||||||
$(this).hide();
|
|
||||||
$("#show-favlist-link").show();
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.expand_image = function(e) {
|
|
||||||
if (Danbooru.test_max_width(660)) {
|
|
||||||
// just do the default behavior
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var $link = $(e.target);
|
|
||||||
var $image = $("#image");
|
|
||||||
var $notice = $("#image-resize-notice");
|
|
||||||
$image.attr("src", $link.attr("href"));
|
|
||||||
$image.css("opacity", "0.25");
|
|
||||||
$image.width($image.data("original-width"));
|
|
||||||
$image.height($image.data("original-height"));
|
|
||||||
$image.on("load", function() {
|
|
||||||
$image.css("opacity", "1");
|
|
||||||
$notice.hide();
|
|
||||||
});
|
|
||||||
$notice.children().eq(0).hide();
|
|
||||||
$notice.children().eq(1).show(); // Loading message
|
|
||||||
Danbooru.Note.Box.scale_all();
|
|
||||||
$image.data("scale-factor", 1);
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.initialize_post_image_resize_links = function() {
|
|
||||||
$("#image-resize-link").click(Danbooru.Post.expand_image);
|
|
||||||
|
|
||||||
if ($("#image-resize-notice").length) {
|
|
||||||
Danbooru.keydown("v", "resize", function(e) {
|
|
||||||
if ($("#image-resize-notice").is(":visible")) {
|
|
||||||
$("#image-resize-link").click();
|
|
||||||
} else {
|
|
||||||
var $image = $("#image");
|
|
||||||
var $notice = $("#image-resize-notice");
|
|
||||||
$image.attr("src", $("#image-container").data("large-file-url"));
|
|
||||||
$image.css("opacity", "0.25");
|
|
||||||
$image.width($image.data("large-width"));
|
|
||||||
$image.height($image.data("large-height"));
|
|
||||||
$notice.children().eq(0).show();
|
|
||||||
$notice.children().eq(1).hide(); // Loading message
|
|
||||||
$image.on("load", function() {
|
|
||||||
$image.css("opacity", "1");
|
|
||||||
$notice.show();
|
|
||||||
});
|
|
||||||
Danbooru.Note.Box.scale_all();
|
|
||||||
$image.data("scale-factor", 1);
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.resize_image_to_window = function($img) {
|
|
||||||
if (($img.data("scale-factor") === 1) || ($img.data("scale-factor") === undefined)) {
|
|
||||||
if ($(window).width() > 660) {
|
|
||||||
var sidebar_width = $("#sidebar").width() || 0;
|
|
||||||
var client_width = $(window).width() - sidebar_width - 75;
|
|
||||||
} else {
|
|
||||||
var client_width = $(window).width() - 2;
|
|
||||||
}
|
|
||||||
var client_height = $(window).height();
|
|
||||||
|
|
||||||
if ($img.width() > client_width) {
|
|
||||||
var ratio = client_width / $img.data("original-width");
|
|
||||||
$img.data("scale-factor", ratio);
|
|
||||||
$img.css("width", $img.data("original-width") * ratio);
|
|
||||||
$img.css("height", $img.data("original-height") * ratio);
|
|
||||||
Danbooru.Post.resize_ugoira_controls();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$img.data("scale-factor", 1);
|
|
||||||
$img.width($img.data("original-width"));
|
|
||||||
$img.height($img.data("original-height"));
|
|
||||||
Danbooru.Post.resize_ugoira_controls();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Note.Box.scale_all();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.initialize_post_image_resize_to_window_link = function() {
|
|
||||||
$("#image-resize-to-window-link").click(function(e) {
|
|
||||||
Danbooru.Post.resize_image_to_window($("#image"));
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.initialize_excerpt = function() {
|
|
||||||
$("#excerpt").hide();
|
|
||||||
|
|
||||||
$("#show-posts-link").click(function(e) {
|
|
||||||
$("#show-posts-link").parent("li").addClass("active");
|
|
||||||
$("#show-excerpt-link").parent("li").removeClass("active");
|
|
||||||
$("#posts").show();
|
|
||||||
$("#excerpt").hide();
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#show-excerpt-link").click(function(e) {
|
|
||||||
if ($(this).parent("li").hasClass("active")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$("#show-posts-link").parent("li").removeClass("active");
|
|
||||||
$("#show-excerpt-link").parent("li").addClass("active");
|
|
||||||
$("#posts").hide();
|
|
||||||
$("#excerpt").show();
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!$(".post-preview").length && /Nobody here but us chickens/.test($("#posts").html())) {
|
|
||||||
$("#show-excerpt-link").click();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.initialize_post_sections = function() {
|
|
||||||
$("#post-sections li a").click(function(e) {
|
|
||||||
if (e.target.hash === "#comments") {
|
|
||||||
$("#comments").show();
|
|
||||||
$("#edit").hide();
|
|
||||||
$("#share").hide();
|
|
||||||
$("#recommended").hide();
|
|
||||||
} else if (e.target.hash === "#edit") {
|
|
||||||
$("#edit").show();
|
|
||||||
$("#comments").hide();
|
|
||||||
$("#share").hide();
|
|
||||||
$("#post_tag_string").focus().selectEnd().height($("#post_tag_string")[0].scrollHeight);
|
|
||||||
$("#related-tags-button").trigger("click");
|
|
||||||
$("#find-artist-button").trigger("click");
|
|
||||||
$("#recommended").hide();
|
|
||||||
} else if (e.target.hash === "#recommended") {
|
|
||||||
$("#comments").hide();
|
|
||||||
$("#edit").hide();
|
|
||||||
$("#share").hide();
|
|
||||||
$("#recommended").show();
|
|
||||||
$.get("/recommended_posts", {context: "post", post_id: Danbooru.meta("post-id")}, function(data) {
|
|
||||||
$("#recommended").html(data);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$("#edit").hide();
|
|
||||||
$("#comments").hide();
|
|
||||||
$("#share").show();
|
|
||||||
addthis.init();
|
|
||||||
$("#recommended").hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#post-sections li").removeClass("active");
|
|
||||||
$(e.target).parent("li").addClass("active");
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#notes").hide();
|
|
||||||
$("#edit").hide();
|
|
||||||
$("#recommended").hide();
|
|
||||||
$("#post-sections li:first-child").addClass("active");
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.resize_ugoira_controls = function() {
|
|
||||||
var $img = $("#image");
|
|
||||||
var width = Math.max($img.width(), 350);
|
|
||||||
$("#ugoira-control-panel").css("width", width);
|
|
||||||
$("#seek-slider").css("width", width - 81);
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.notice_update = function(x) {
|
|
||||||
if (x === "inc") {
|
|
||||||
Danbooru.Post.pending_update_count += 1;
|
|
||||||
Danbooru.notice("Updating posts (" + Danbooru.Post.pending_update_count + " pending)...", true);
|
|
||||||
} else {
|
|
||||||
Danbooru.Post.pending_update_count -= 1;
|
|
||||||
|
|
||||||
if (Danbooru.Post.pending_update_count < 1) {
|
|
||||||
Danbooru.notice("Posts updated");
|
|
||||||
} else {
|
|
||||||
Danbooru.notice("Updating posts (" + Danbooru.Post.pending_update_count + " pending)...", true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.update_data = function(data) {
|
|
||||||
var $post = $("#post_" + data.id);
|
|
||||||
$post.attr("data-tags", data.tag_string);
|
|
||||||
$post.data("rating", data.rating);
|
|
||||||
$post.removeClass("post-status-has-parent post-status-has-children");
|
|
||||||
if (data.parent_id) {
|
|
||||||
$post.addClass("post-status-has-parent");
|
|
||||||
}
|
|
||||||
if (data.has_visible_children) {
|
|
||||||
$post.addClass("post-status-has-children");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.vote = function(score, id) {
|
|
||||||
Danbooru.notice("Voting...");
|
|
||||||
|
|
||||||
$.post("/posts/" + id + "/votes.js", {
|
|
||||||
score: score
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.update = function(post_id, params) {
|
|
||||||
Danbooru.Post.notice_update("inc");
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
type: "PUT",
|
|
||||||
url: "/posts/" + post_id + ".json",
|
|
||||||
data: params,
|
|
||||||
success: function(data) {
|
|
||||||
Danbooru.Post.notice_update("dec");
|
|
||||||
Danbooru.Post.update_data(data);
|
|
||||||
},
|
|
||||||
error: function(data) {
|
|
||||||
Danbooru.Post.notice_update("dec");
|
|
||||||
Danbooru.error('There was an error updating <a href="/posts/' + post_id + '">post #' + post_id + '</a>');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.ban = function(post_id) {
|
|
||||||
$.ajax({
|
|
||||||
type: "POST",
|
|
||||||
url: "/moderator/post/posts/" + post_id + "/ban.js",
|
|
||||||
data: {
|
|
||||||
commit: "Ban"
|
|
||||||
},
|
|
||||||
success: function(data) {
|
|
||||||
$("#post_" + post_id).remove();
|
|
||||||
},
|
|
||||||
error: function(data) {
|
|
||||||
Danbooru.error('There was an error updating <a href="/posts/' + post_id + '">post #' + post_id + '</a>');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.approve = function(post_id) {
|
|
||||||
$.post(
|
|
||||||
"/moderator/post/approval.json",
|
|
||||||
{"post_id": post_id}
|
|
||||||
).fail(function(data) {
|
|
||||||
var message = $.map(data.responseJSON.errors, function(msg, attr) { return msg; }).join("; ");
|
|
||||||
Danbooru.error("Error: " + message);
|
|
||||||
}).done(function(data) {
|
|
||||||
var $post = $("#post_" + post_id);
|
|
||||||
if ($post.length) {
|
|
||||||
$post.data("flags", $post.data("flags").replace(/pending/, ""));
|
|
||||||
$post.removeClass("post-status-pending");
|
|
||||||
Danbooru.notice("Approved post #" + post_id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.favorite = function (e) {
|
|
||||||
if ($("#add-to-favorites").is(":visible")) {
|
|
||||||
$("#add-to-favorites")[0].click();
|
|
||||||
} else {
|
|
||||||
if (Danbooru.meta("current-user-id") == "") {
|
|
||||||
Danbooru.notice("You must be logged in to favorite posts");
|
|
||||||
} else {
|
|
||||||
Danbooru.notice("You have already favorited this post");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Danbooru.Post.unfavorite = function (e) {
|
|
||||||
$.ajax("/favorites/" + Danbooru.meta("post-id") + ".js", {
|
|
||||||
type: "DELETE"
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Danbooru.Post.initialize_saved_searches = function() {
|
|
||||||
$("#new_saved_search #saved_search_label_string").autocomplete({
|
|
||||||
search: function() {
|
|
||||||
$(this).data("ui-autocomplete").menu.bindings = $();
|
|
||||||
},
|
|
||||||
source: function(req, resp) {
|
|
||||||
Danbooru.SavedSearch.labels(req.term).then(function(labels) {
|
|
||||||
resp(labels.map(function(label) {
|
|
||||||
return {
|
|
||||||
label: label.replace(/_/g, " "),
|
|
||||||
value: label
|
|
||||||
};
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#save-search-dialog").dialog({
|
|
||||||
width: 500,
|
|
||||||
modal: true,
|
|
||||||
autoOpen: false,
|
|
||||||
buttons: {
|
|
||||||
"Submit": function() {
|
|
||||||
$("#save-search-dialog form").submit();
|
|
||||||
$(this).dialog("close");
|
|
||||||
},
|
|
||||||
"Cancel": function() {
|
|
||||||
$(this).dialog("close");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#save-search").click(function(e) {
|
|
||||||
$("#save-search-dialog #saved_search_query").val($("#tags").val());
|
|
||||||
|
|
||||||
if (Danbooru.meta("disable-labeled-saved-searches") === "false") {
|
|
||||||
$("#save-search-dialog").dialog("open");
|
|
||||||
} else {
|
|
||||||
$.post(
|
|
||||||
"/saved_searches.js",
|
|
||||||
{
|
|
||||||
"saved_search": {
|
|
||||||
"query": $("#tags").val()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#search-dropdown #wiki-search").click(function(e) {
|
|
||||||
window.location.href = "/wiki_pages?search%5Btitle%5D=" + encodeURIComponent($("#tags").val());
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#search-dropdown #artist-search").click(function(e) {
|
|
||||||
window.location.href = "/artists?search%5Bname%5D=" + encodeURIComponent($("#tags").val());
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Post.initialize_replace_image_dialog = function() {
|
|
||||||
$("#replace-image-dialog").dialog({
|
|
||||||
autoOpen: false,
|
|
||||||
width: 700,
|
|
||||||
modal: true,
|
|
||||||
buttons: {
|
|
||||||
"Submit": function() {
|
|
||||||
$("#replace-image-dialog form").submit();
|
|
||||||
$(this).dialog("close");
|
|
||||||
},
|
|
||||||
"Cancel": function() {
|
|
||||||
$(this).dialog("close");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#replace-image-dialog form').submit(function() {
|
|
||||||
$('#replace-image-dialog').dialog('close');
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#replace-image").click(function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
$("#replace-image-dialog").dialog("open");
|
|
||||||
});
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
Danbooru.Post.initialize_all();
|
|
||||||
});
|
|
||||||
@@ -1,350 +0,0 @@
|
|||||||
(function() {
|
|
||||||
Danbooru.RelatedTag = {};
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.initialize_all = function() {
|
|
||||||
if ($("#c-posts #a-show").length || $("#c-uploads #a-new").length) {
|
|
||||||
this.initialize_buttons();
|
|
||||||
$("#artist-tags-container").hide();
|
|
||||||
$("#upload_tag_string,#post_tag_string").keyup(Danbooru.RelatedTag.update_selected);
|
|
||||||
$("body").on("click", "#artist-related-tags-column a.del", Danbooru.RelatedTag.disable_artist_url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.initialize_buttons = function() {
|
|
||||||
this.common_bind("#related-tags-button", "");
|
|
||||||
<% TagCategory.related_button_list.each do |category| %>
|
|
||||||
Danbooru.RelatedTag.common_bind("#related-<%= category %>-button", "<%= category %>");
|
|
||||||
<% end %>
|
|
||||||
$("#find-artist-button").click(Danbooru.RelatedTag.find_artist);
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.tags_include = function(name) {
|
|
||||||
var current = $("#upload_tag_string,#post_tag_string").val().toLowerCase().match(/\S+/g) || [];
|
|
||||||
if ($.inArray(name.toLowerCase(), current) > -1) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.common_bind = function(button_name, category) {
|
|
||||||
$(button_name).click(function(e) {
|
|
||||||
var $dest = $("#related-tags");
|
|
||||||
$dest.empty();
|
|
||||||
Danbooru.RelatedTag.build_recent_and_frequent($dest);
|
|
||||||
$dest.append("<em>Loading...</em>");
|
|
||||||
$.get("/related_tag.json", {
|
|
||||||
"query": Danbooru.RelatedTag.current_tag(),
|
|
||||||
"category": category
|
|
||||||
}, Danbooru.RelatedTag.process_response);
|
|
||||||
$("#artist-tags-container").hide();
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.current_tag = function() {
|
|
||||||
// 1. abc def | -> def
|
|
||||||
// 2. abc def| -> def
|
|
||||||
// 3. abc de|f -> def
|
|
||||||
// 4. abc |def -> def
|
|
||||||
// 5. abc| def -> abc
|
|
||||||
// 6. ab|c def -> abc
|
|
||||||
// 7. |abc def -> abc
|
|
||||||
// 8. | abc def -> abc
|
|
||||||
|
|
||||||
var $field = $("#upload_tag_string,#post_tag_string");
|
|
||||||
var string = $field.val();
|
|
||||||
var n = string.length;
|
|
||||||
var a = $field.prop('selectionStart');
|
|
||||||
var b = $field.prop('selectionStart');
|
|
||||||
|
|
||||||
if ((a > 0) && (a < (n - 1)) && (!/\s/.test(string[a])) && (/\s/.test(string[a - 1]))) {
|
|
||||||
// 4 is the only case where we need to scan forward. in all other cases we
|
|
||||||
// can drag a backwards, and then drag b forwards.
|
|
||||||
|
|
||||||
while ((b < n) && (!/\s/.test(string[b]))) {
|
|
||||||
b++;
|
|
||||||
}
|
|
||||||
} else if (string.search(/\S/) > b) { // case 8
|
|
||||||
b = string.search(/\S/);
|
|
||||||
while ((b < n) && (!/\s/.test(string[b]))) {
|
|
||||||
b++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while ((a > 0) && ((/\s/.test(string[a])) || (string[a] === undefined))) {
|
|
||||||
a--;
|
|
||||||
b--;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((a > 0) && (!/\s/.test(string[a - 1]))) {
|
|
||||||
a--;
|
|
||||||
b--;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((b < (n - 1)) && (!/\s/.test(string[b]))) {
|
|
||||||
b++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
b++;
|
|
||||||
return string.slice(a, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.process_response = function(data) {
|
|
||||||
Danbooru.RelatedTag.recent_search = data;
|
|
||||||
Danbooru.RelatedTag.build_all();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.update_selected = function(e) {
|
|
||||||
var current_tags = $("#upload_tag_string,#post_tag_string").val().toLowerCase().match(/\S+/g) || [];
|
|
||||||
var $all_tags = $("#related-tags a");
|
|
||||||
$all_tags.removeClass("selected");
|
|
||||||
|
|
||||||
$all_tags.each(function(i, tag) {
|
|
||||||
if (current_tags.indexOf(tag.textContent.replace(/ /g, "_")) > -1) {
|
|
||||||
$(tag).addClass("selected");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.build_all = function() {
|
|
||||||
if (Danbooru.RelatedTag.recent_search === null || Danbooru.RelatedTag.recent_search === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.show();
|
|
||||||
|
|
||||||
var query = Danbooru.RelatedTag.recent_search.query;
|
|
||||||
var related_tags = Danbooru.RelatedTag.recent_search.tags;
|
|
||||||
var wiki_page_tags = Danbooru.RelatedTag.recent_search.wiki_page_tags;
|
|
||||||
var other_wikis = Danbooru.RelatedTag.recent_search.other_wikis;
|
|
||||||
var $dest = $("#related-tags");
|
|
||||||
$dest.empty();
|
|
||||||
|
|
||||||
this.build_recent_and_frequent($dest);
|
|
||||||
|
|
||||||
$dest.append(this.build_html(query, related_tags, "general"));
|
|
||||||
this.build_translated($dest);
|
|
||||||
if (wiki_page_tags.length) {
|
|
||||||
$dest.append(Danbooru.RelatedTag.build_html("wiki:" + query, wiki_page_tags, "wiki"));
|
|
||||||
}
|
|
||||||
$.each(other_wikis, function(i,wiki) {
|
|
||||||
$dest.append(Danbooru.RelatedTag.build_html("wiki:" + wiki.title, wiki.wiki_page_tags, "otherwiki" + i.toString()));
|
|
||||||
});
|
|
||||||
if (Danbooru.RelatedTag.recent_artists) {
|
|
||||||
var tags = [];
|
|
||||||
if (Danbooru.RelatedTag.recent_artists.length === 0) {
|
|
||||||
tags.push([" none", 0]);
|
|
||||||
} else if (Danbooru.RelatedTag.recent_artists.length === 1) {
|
|
||||||
tags.push([Danbooru.RelatedTag.recent_artists[0].name, 1]);
|
|
||||||
if (Danbooru.RelatedTag.recent_artists[0].is_banned === true) {
|
|
||||||
tags.push(["BANNED_ARTIST", "banned"]);
|
|
||||||
}
|
|
||||||
$.each(Danbooru.RelatedTag.recent_artists[0].sorted_urls, function(i, url) {
|
|
||||||
var x = url.url;
|
|
||||||
if (!url.is_active) {
|
|
||||||
x = "-" + x;
|
|
||||||
}
|
|
||||||
tags.push([" " + x, 0]);
|
|
||||||
});
|
|
||||||
} else if (Danbooru.RelatedTag.recent_artists.length >= 10) {
|
|
||||||
tags.push([" none", 0]);
|
|
||||||
} else {
|
|
||||||
$.each(Danbooru.RelatedTag.recent_artists, function(i, artist) {
|
|
||||||
tags.push([artist.name, 1]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
$dest.append(Danbooru.RelatedTag.build_html("artist", tags, "artist", true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.build_recent_and_frequent = function($dest) {
|
|
||||||
var recent_tags = Danbooru.Cookie.get("recent_tags_with_categories");
|
|
||||||
var favorite_tags = Danbooru.Cookie.get("favorite_tags_with_categories");
|
|
||||||
if (recent_tags.length) {
|
|
||||||
$dest.append(this.build_html("recent", this.other_tags(recent_tags), "recent"));
|
|
||||||
}
|
|
||||||
if (favorite_tags.length) {
|
|
||||||
$dest.append(this.build_html("frequent", this.other_tags(favorite_tags), "frequent"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.other_tags = function(string) {
|
|
||||||
if (string && string.length) {
|
|
||||||
return $.map(string.match(/\S+ \d+/g), function(x, i) {
|
|
||||||
var submatch = x.match(/(\S+) (\d+)/);
|
|
||||||
return [[submatch[1], submatch[2]]];
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.build_translated = function($dest) {
|
|
||||||
if (Danbooru.RelatedTag.translated_tags && Danbooru.RelatedTag.translated_tags.length) {
|
|
||||||
$dest.append(this.build_html("Translated Tags", Danbooru.RelatedTag.translated_tags, "translated"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.build_html = function(query, related_tags, name, is_wide_column) {
|
|
||||||
if (query === null || query === "") {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
query = query.replace(/_/g, " ");
|
|
||||||
var header = $("<em/>");
|
|
||||||
|
|
||||||
var match = query.match(/^wiki:(.+)/);
|
|
||||||
if (match) {
|
|
||||||
header.html($("<a/>").attr("href", "/wiki_pages?title=" + encodeURIComponent(match[1])).attr("target", "_blank").text(query));
|
|
||||||
} else {
|
|
||||||
header.text(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
var $div = $("<div/>");
|
|
||||||
$div.attr("id", name + "-related-tags-column");
|
|
||||||
$div.addClass("tag-column");
|
|
||||||
if (is_wide_column) {
|
|
||||||
$div.addClass("wide-column");
|
|
||||||
}
|
|
||||||
var $ul = $("<ul/>");
|
|
||||||
$ul.append(
|
|
||||||
$("<li/>").append(
|
|
||||||
header
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$.each(related_tags, function(i, tag) {
|
|
||||||
if (tag[0][0] !== " ") {
|
|
||||||
var $link = $("<a/>");
|
|
||||||
$link.text(tag[0].replace(/_/g, " "));
|
|
||||||
$link.addClass("tag-type-" + tag[1]);
|
|
||||||
$link.attr("href", "/posts?tags=" + encodeURIComponent(tag[0]));
|
|
||||||
$link.click(Danbooru.RelatedTag.toggle_tag);
|
|
||||||
if (Danbooru.RelatedTag.tags_include(tag[0])) {
|
|
||||||
$link.addClass("selected");
|
|
||||||
}
|
|
||||||
$ul.append(
|
|
||||||
$("<li/>").append($link)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
var text = tag[0];
|
|
||||||
if (text.match(/^ -http/)) {
|
|
||||||
text = text.substring(1, 1000);
|
|
||||||
var desc = text.replace(/^-https?:\/\//, "");
|
|
||||||
if (desc.length > 30) {
|
|
||||||
desc = desc.substring(0, 30) + "...";
|
|
||||||
}
|
|
||||||
$ul.append(
|
|
||||||
$("<li>").append(
|
|
||||||
$("<del>").text(desc)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else if (text.match(/^ http/)) {
|
|
||||||
text = text.substring(1, 1000);
|
|
||||||
var desc = text.replace(/^https?:\/\//, "");
|
|
||||||
if (desc.length > 30) {
|
|
||||||
desc = desc.substring(0, 30) + "...";
|
|
||||||
}
|
|
||||||
$ul.append(
|
|
||||||
$("<li>").append([
|
|
||||||
$("<a>").text(desc).attr("href", text).attr("target", "_blank"),
|
|
||||||
" ",
|
|
||||||
$("<a>").attr("href", text).addClass("del").append(
|
|
||||||
$("<i>").addClass("fas fa-minus-circle")
|
|
||||||
)
|
|
||||||
])
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$ul.append($("<li/>").text(text));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$div.append($ul);
|
|
||||||
return $div;
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.toggle_tag = function(e) {
|
|
||||||
var $field = $("#upload_tag_string,#post_tag_string");
|
|
||||||
var tag = $(e.target).html().replace(/ /g, "_").replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&");
|
|
||||||
|
|
||||||
if (Danbooru.RelatedTag.tags_include(tag)) {
|
|
||||||
var escaped_tag = Danbooru.regexp_escape(tag);
|
|
||||||
$field.val($field.val().replace(new RegExp("(^|\\s)" + escaped_tag + "($|\\s)", "gi"), "$1$2"));
|
|
||||||
} else {
|
|
||||||
$field.val($field.val() + " " + tag);
|
|
||||||
}
|
|
||||||
$field.val($field.val().trim().replace(/ +/g, " ") + " ");
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.update_selected();
|
|
||||||
if (Danbooru.RelatedTag.recent_artist && $("#artist-tags-container").css("display") === "block") {
|
|
||||||
Danbooru.RelatedTag.process_artist(Danbooru.RelatedTag.recent_artist);
|
|
||||||
}
|
|
||||||
|
|
||||||
//The timeout is needed on Chrome since it will clobber the field attribute otherwise
|
|
||||||
setTimeout(function () { $field.prop('selectionStart', $field.val().length);}, 100);
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.find_artist = function(e) {
|
|
||||||
$("#artist-tags").html("<em>Loading...</em>");
|
|
||||||
var url = $("#upload_source,#post_source");
|
|
||||||
var referer_url = $("#upload_referer_url");
|
|
||||||
$.get("/artists/finder.json", {"url": url.val(), "referer_url": referer_url.val()}, Danbooru.RelatedTag.process_artist);
|
|
||||||
if (e) {
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.process_artist = function(data) {
|
|
||||||
Danbooru.RelatedTag.recent_artists = data;
|
|
||||||
Danbooru.RelatedTag.build_all();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.toggle = function() {
|
|
||||||
if ($("#related-tags").is(":visible")) {
|
|
||||||
Danbooru.RelatedTag.hide();
|
|
||||||
} else {
|
|
||||||
Danbooru.RelatedTag.show();
|
|
||||||
$("#related-tags-button").trigger("click");
|
|
||||||
$("#find-artist-button").trigger("click");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.show = function() {
|
|
||||||
$("#related-tags").show()
|
|
||||||
$("#toggle-related-tags-link").text("«");
|
|
||||||
$("#edit-dialog").height("auto");
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.hide = function() {
|
|
||||||
$("#related-tags").hide();
|
|
||||||
$("#toggle-related-tags-link").text("»");
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.disable_artist_url = function(e) {
|
|
||||||
var url = e.currentTarget.href;
|
|
||||||
$.each(Danbooru.RelatedTag.recent_artists[0].sorted_urls, function(k, v) {
|
|
||||||
if (v["normalized_url"] === url || v["url"] === url) {
|
|
||||||
if (!confirm("This will mark the URL as inactive. Continue?")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$.ajax("/artist_urls/" + v["id"], {
|
|
||||||
method: "PUT",
|
|
||||||
data: {
|
|
||||||
artist_url: {
|
|
||||||
is_active: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).done(Danbooru.RelatedTag.find_artist);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
Danbooru.RelatedTag.initialize_all();
|
|
||||||
});
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
Danbooru.SavedSearch = {};
|
|
||||||
|
|
||||||
Danbooru.SavedSearch.initialize_all = function() {
|
|
||||||
if ($("#c-saved-searches").length) {
|
|
||||||
Danbooru.sorttable($("#c-saved-searches table"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.SavedSearch.labels = function(term) {
|
|
||||||
return $.getJSON("/saved_searches/labels", {
|
|
||||||
"search[label]": term + "*",
|
|
||||||
"limit": 10
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
$(Danbooru.SavedSearch.initialize_all);
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
(function() {
|
|
||||||
Danbooru.Shortcuts = {};
|
|
||||||
|
|
||||||
Danbooru.Shortcuts.initialize = function() {
|
|
||||||
Danbooru.keydown("s", "scroll_down", Danbooru.Shortcuts.nav_scroll_down);
|
|
||||||
Danbooru.keydown("w", "scroll_up", Danbooru.Shortcuts.nav_scroll_up);
|
|
||||||
|
|
||||||
Danbooru.keydown("q", "focus_search", function(e) {
|
|
||||||
$("#tags, #search_name, #search_name_matches, #query").trigger("focus").selectEnd();
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
if ($("#image").length) { // post page or bookmarklet upload page
|
|
||||||
Danbooru.keydown("shift+e", "edit_dialog", function(e) {
|
|
||||||
if (Danbooru.meta("current-user-id") == "") { // anonymous
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$("#edit-dialog").length) {
|
|
||||||
$("#edit").show();
|
|
||||||
$("#comments").hide();
|
|
||||||
$("#share").hide();
|
|
||||||
$("#post-sections li").removeClass("active");
|
|
||||||
$("#post-edit-link").parent("li").addClass("active");
|
|
||||||
$("#related-tags-container").show();
|
|
||||||
|
|
||||||
Danbooru.Post.open_edit_dialog();
|
|
||||||
}
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($("#c-posts #a-index, #c-favorites #a-index").length) {
|
|
||||||
Danbooru.keydown("r", "random", function(e) {
|
|
||||||
$("#random-post")[0].click();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Shortcuts.nav_scroll_down = function() {
|
|
||||||
var scroll_top = $(window).scrollTop() + ($(window).height() * 0.15);
|
|
||||||
$(window).scrollTop(scroll_top);
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Shortcuts.nav_scroll_up = function() {
|
|
||||||
var scroll_top = $(window).scrollTop() - ($(window).height() * 0.15);
|
|
||||||
if (scroll_top < 0) {
|
|
||||||
scroll_top = 0;
|
|
||||||
}
|
|
||||||
$(window).scrollTop(scroll_top);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
Danbooru.Shortcuts.initialize();
|
|
||||||
});
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
(function() {
|
|
||||||
Danbooru.TagScript = {};
|
|
||||||
|
|
||||||
Danbooru.TagScript.parse = function(script) {
|
|
||||||
return script.match(/\[.+?\]|\S+/g);
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.TagScript.test = function(tags, predicate) {
|
|
||||||
var split_pred = predicate.match(/\S+/g);
|
|
||||||
var is_true = true;
|
|
||||||
|
|
||||||
$.each(split_pred, function(i, x) {
|
|
||||||
if (x[0] === "-") {
|
|
||||||
if ($.inArray(x.substr(1, 100), tags)) {
|
|
||||||
is_true = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!$.inArray(x, tags)) {
|
|
||||||
is_true = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return is_true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.TagScript.process = function(tags, command) {
|
|
||||||
if (command.match(/^\[if/)) {
|
|
||||||
var match = command.match(/\[if\s+(.+?)\s*,\s*(.+?)\]/);
|
|
||||||
if (Danbooru.TagScript.test(tags, match[1])) {
|
|
||||||
return Danbooru.TagScript.process(tags, match[2]);
|
|
||||||
} else {
|
|
||||||
return tags;
|
|
||||||
}
|
|
||||||
} else if (command === "[reset]") {
|
|
||||||
return [];
|
|
||||||
} else if (command[0] === "-" && !command.match(/^(?:-pool|-parent|-fav|-favgroup):/i)) {
|
|
||||||
return Danbooru.reject(tags, function(x) {return x === command.substr(1, 100)});
|
|
||||||
} else {
|
|
||||||
tags.push(command);
|
|
||||||
return tags;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.TagScript.run = function(post_id, tag_script) {
|
|
||||||
var commands = Danbooru.TagScript.parse(tag_script);
|
|
||||||
var $post = $("#post_" + post_id);
|
|
||||||
var old_tags = $post.data("tags");
|
|
||||||
|
|
||||||
$.each(commands, function(i, x) {
|
|
||||||
var array = String($post.data("tags")).match(/\S+/g);
|
|
||||||
$post.data("tags", Danbooru.TagScript.process(array, x).join(" "));
|
|
||||||
});
|
|
||||||
|
|
||||||
Danbooru.Post.update(post_id, {"post[old_tag_string]": old_tags, "post[tag_string]": $post.data("tags")});
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
@@ -1,203 +0,0 @@
|
|||||||
(function() {
|
|
||||||
Danbooru.Upload = {};
|
|
||||||
|
|
||||||
Danbooru.Upload.initialize_all = function() {
|
|
||||||
if ($("#c-uploads,#c-posts").length) {
|
|
||||||
this.initialize_enter_on_tags();
|
|
||||||
this.initialize_info_manual();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($("#c-uploads").length) {
|
|
||||||
if ($("#image").prop("complete")) {
|
|
||||||
this.initialize_image();
|
|
||||||
} else {
|
|
||||||
$("#image").on("load error", this.initialize_image);
|
|
||||||
}
|
|
||||||
this.initialize_info_bookmarklet();
|
|
||||||
this.initialize_similar();
|
|
||||||
this.initialize_shortcuts();
|
|
||||||
this.initialize_submit();
|
|
||||||
$("#related-tags-button").trigger("click");
|
|
||||||
|
|
||||||
$("#toggle-artist-commentary").click(function(e) {
|
|
||||||
Danbooru.Upload.toggle_commentary();
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($("#iqdb-similar").length) {
|
|
||||||
this.initialize_iqdb_source();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Upload.initialize_submit = function() {
|
|
||||||
$("#form").submit(function(e) {
|
|
||||||
var error_messages = [];
|
|
||||||
if (($("#upload_file").val() === "") && ($("#upload_source").val() === "") && $("#upload_md5_confirmation").val() === "") {
|
|
||||||
error_messages.push("Must choose file or specify source");
|
|
||||||
}
|
|
||||||
if (!$("#upload_rating_s").prop("checked") && !$("#upload_rating_q").prop("checked") && !$("#upload_rating_e").prop("checked") &&
|
|
||||||
($("#upload_tag_string").val().search(/\brating:[sqe]/i) < 0)) {
|
|
||||||
error_messages.push("Must specify a rating");
|
|
||||||
}
|
|
||||||
if (error_messages.length === 0) {
|
|
||||||
$("#submit-button").prop("disabled","true");
|
|
||||||
$("#submit-button").prop("value","Submitting...");
|
|
||||||
$("#client-errors").hide();
|
|
||||||
} else {
|
|
||||||
$("#client-errors").html("<strong>Error</strong>: " + error_messages.join(", "));
|
|
||||||
$("#client-errors").show();
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Upload.initialize_shortcuts = function() {
|
|
||||||
Danbooru.keydown("e", "edit", function(e) {
|
|
||||||
$("#upload_tag_string").focus();
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Danbooru.Upload.initialize_iqdb_source = function() {
|
|
||||||
if (/^https?:\/\//.test($("#normalized_url").val())) {
|
|
||||||
$.get("/iqdb_queries", {"url": $("#normalized_url").val()}).done(function(html) {$("#iqdb-similar").html(html)});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Upload.initialize_enter_on_tags = function() {
|
|
||||||
var $textarea = $("#upload_tag_string, #post_tag_string");
|
|
||||||
var $submit = $textarea.parents("form").find('input[type="submit"]');
|
|
||||||
|
|
||||||
$textarea.on("keydown.danbooru.submit", null, "return", function(e) {
|
|
||||||
$submit.click();
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Upload.initialize_similar = function() {
|
|
||||||
$("#similar-button").click(function(e) {
|
|
||||||
$.get("/iqdb_queries", {"url": $("#upload_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Upload.initialize_info_bookmarklet = function() {
|
|
||||||
$("#upload_source").change(function (e) {
|
|
||||||
$("#fetch-data-manual").click();
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#fetch-data-manual").click();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Upload.initialize_info_manual = function() {
|
|
||||||
$("#fetch-data-manual").click(function(e) {
|
|
||||||
var source = $("#upload_source,#post_source").val();
|
|
||||||
var referer = $("#upload_referer_url").val();
|
|
||||||
|
|
||||||
if (/^https?:\/\//.test(source)) {
|
|
||||||
$("#source-info span#loading-data").show();
|
|
||||||
Danbooru.Upload.fetch_source_data(source, referer);
|
|
||||||
}
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Upload.fetch_source_data = function(url, referer_url) {
|
|
||||||
return $.getJSON("/source.json", { url: url, ref: referer_url })
|
|
||||||
.then(Danbooru.Upload.fill_source_info)
|
|
||||||
.catch(function(data) {
|
|
||||||
$("#source-info span#loading-data").html("Error: " + data.responseJSON["message"])
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Upload.fill_source_info = function(data) {
|
|
||||||
$("#source-tags").empty();
|
|
||||||
$.each(data.tags, function(i, v) {
|
|
||||||
$("<a>").attr("href", v[1]).text(v[0]).appendTo("#source-tags");
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#source-artist-profile").attr("href", data.profile_url).text(data.artist_name);
|
|
||||||
|
|
||||||
Danbooru.RelatedTag.process_artist(data.artists);
|
|
||||||
Danbooru.RelatedTag.translated_tags = data.translated_tags;
|
|
||||||
Danbooru.RelatedTag.build_all();
|
|
||||||
|
|
||||||
if (data.artists.length === 0) {
|
|
||||||
var new_artist_params = $.param({
|
|
||||||
artist: {
|
|
||||||
name: data.unique_id,
|
|
||||||
other_names: data.artist_name,
|
|
||||||
url_string: $.uniqueSort([data.profile_url, data.normalized_for_artist_finder_url]).join("\n")
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var link = $("<a>").attr("href", "/artists/new?" + new_artist_params).text("Create new artist");
|
|
||||||
$("#source-danbooru-artists").html(link);
|
|
||||||
} else {
|
|
||||||
var artistLinks = data.artists.map(function (artist) {
|
|
||||||
return $('<a class="tag-type-1">').attr("href", "/artists/" + artist.id).text(artist.name);
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#source-danbooru-artists").html(artistLinks)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.image_urls.length > 1) {
|
|
||||||
$("#gallery-warning").show();
|
|
||||||
} else {
|
|
||||||
$("#gallery-warning").hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#upload_artist_commentary_title").val(data.artist_commentary.dtext_title);
|
|
||||||
$("#upload_artist_commentary_desc").val(data.artist_commentary.dtext_description);
|
|
||||||
Danbooru.Upload.toggle_commentary();
|
|
||||||
|
|
||||||
$("#source-info span#loading-data").hide();
|
|
||||||
$("#source-info ul").show();
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Upload.update_scale = function() {
|
|
||||||
var $image = $("#image");
|
|
||||||
var ratio = $image.data("scale-factor");
|
|
||||||
if (ratio < 1) {
|
|
||||||
$("#scale").html("Scaled " + parseInt(100 * ratio) + "% (original: " + $image.data("original-width") + "x" + $image.data("original-height") + ")");
|
|
||||||
} else {
|
|
||||||
$("#scale").html("Original: " + $image.data("original-width") + "x" + $image.data("original-height"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Upload.initialize_image = function() {
|
|
||||||
var $image = $("#image");
|
|
||||||
if (!$image.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var width = $image.width();
|
|
||||||
var height = $image.height();
|
|
||||||
if (!width || !height) {
|
|
||||||
// try again later
|
|
||||||
$.timeout(100).done(function() {Danbooru.Upload.initialize_image()});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$image.data("original-width", width);
|
|
||||||
$image.data("original-height", height);
|
|
||||||
Danbooru.Post.resize_image_to_window($image);
|
|
||||||
Danbooru.Post.initialize_post_image_resize_to_window_link();
|
|
||||||
Danbooru.Upload.update_scale();
|
|
||||||
$("#image-resize-to-window-link").click(Danbooru.Upload.update_scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.Upload.toggle_commentary = function() {
|
|
||||||
if ($(".artist-commentary").is(":visible")) {
|
|
||||||
$("#toggle-artist-commentary").text("show »");
|
|
||||||
} else {
|
|
||||||
$("#toggle-artist-commentary").text("« hide");
|
|
||||||
}
|
|
||||||
|
|
||||||
$(".artist-commentary").slideToggle();
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
Danbooru.Upload.initialize_all();
|
|
||||||
});
|
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
(function() {
|
|
||||||
Danbooru.meta = function(key) {
|
|
||||||
return $("meta[name=" + key + "]").attr("content");
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.test_max_width = function(width) {
|
|
||||||
if (!window.matchMedia) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
var mq = window.matchMedia('(max-width: ' + width + 'px)');
|
|
||||||
return mq.matches;
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.scrolling = false;
|
|
||||||
|
|
||||||
Danbooru.scroll_to = function(element) {
|
|
||||||
if (Danbooru.scrolling) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
Danbooru.scrolling = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var top = null;
|
|
||||||
if (typeof(element) === "number") {
|
|
||||||
top = element;
|
|
||||||
} else {
|
|
||||||
top = element.offset().top - 10;
|
|
||||||
}
|
|
||||||
$('html, body').animate({scrollTop: top}, 300, "linear", function() {Danbooru.scrolling = false;});
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.notice_timeout_id = undefined;
|
|
||||||
|
|
||||||
Danbooru.notice = function(msg, permanent) {
|
|
||||||
$('#notice').addClass("ui-state-highlight").removeClass("ui-state-error").fadeIn("fast").children("span").html(msg);
|
|
||||||
|
|
||||||
if (Danbooru.notice_timeout_id !== undefined) {
|
|
||||||
clearTimeout(Danbooru.notice_timeout_id)
|
|
||||||
}
|
|
||||||
if (!permanent) {
|
|
||||||
Danbooru.notice_timeout_id = setTimeout(function() {
|
|
||||||
$("#close-notice-link").click();
|
|
||||||
Danbooru.notice_timeout_id = undefined;
|
|
||||||
}, 6000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.error = function(msg) {
|
|
||||||
$('#notice').removeClass("ui-state-highlight").addClass("ui-state-error").fadeIn("fast").children("span").html(msg);
|
|
||||||
|
|
||||||
if (Danbooru.notice_timeout_id !== undefined) {
|
|
||||||
clearTimeout(Danbooru.notice_timeout_id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.keydown = function(keys, namespace, handler) {
|
|
||||||
if (Danbooru.meta("enable-js-navigation") === "true") {
|
|
||||||
$(document).on("keydown" + ".danbooru." + namespace, null, keys, handler);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Danbooru.is_subset = function(array, subarray) {
|
|
||||||
var all = true;
|
|
||||||
|
|
||||||
$.each(subarray, function(i, val) {
|
|
||||||
if ($.inArray(val, array) === -1) {
|
|
||||||
all = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return all;
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.intersect = function(a, b) {
|
|
||||||
a = a.slice(0).sort();
|
|
||||||
b = b.slice(0).sort();
|
|
||||||
var result = [];
|
|
||||||
while (a.length > 0 && b.length > 0)
|
|
||||||
{
|
|
||||||
if (a[0] < b[0]) {
|
|
||||||
a.shift();
|
|
||||||
} else if (a[0] > b[0]) {
|
|
||||||
b.shift();
|
|
||||||
} else {
|
|
||||||
result.push(a.shift());
|
|
||||||
b.shift();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.without = function(array, element) {
|
|
||||||
var temp = [];
|
|
||||||
$.each(array, function(i, v) {
|
|
||||||
if (v !== element) {
|
|
||||||
temp.push(v);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.reject = function(array, f) {
|
|
||||||
var filtered = [];
|
|
||||||
$.each(array, function(i, x) {
|
|
||||||
if (!f(x)) {
|
|
||||||
filtered.push(x);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return filtered;
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.regexp_escape = function(string) {
|
|
||||||
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.get_url_parameter = function(sParam) {
|
|
||||||
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
|
|
||||||
sURLVariables = sPageURL.split('&'),
|
|
||||||
sParameterName,
|
|
||||||
i;
|
|
||||||
|
|
||||||
for (i = 0; i < sURLVariables.length; i++) {
|
|
||||||
sParameterName = sURLVariables[i].split('=');
|
|
||||||
|
|
||||||
if (sParameterName[0] === sParam) {
|
|
||||||
return sParameterName[1] === undefined ? true : sParameterName[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Danbooru.sorttable = function(table) {
|
|
||||||
table.stupidtable();
|
|
||||||
table.bind("aftertablesort", function(event, data) {
|
|
||||||
$("#c-saved-searches table tbody tr").removeClass("even odd");
|
|
||||||
$("#c-saved-searches table tbody tr:even").addClass("even");
|
|
||||||
$("#c-saved-searches table tbody tr:odd").addClass("odd");
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
String.prototype.hash = function() {
|
|
||||||
var hash = 5381, i = this.length;
|
|
||||||
|
|
||||||
while(i)
|
|
||||||
hash = (hash * 33) ^ this.charCodeAt(--i)
|
|
||||||
|
|
||||||
return hash >>> 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$.fn.selectRange = function(start, end) {
|
|
||||||
return this.each(function() {
|
|
||||||
if (this.setSelectionRange) {
|
|
||||||
this.focus();
|
|
||||||
this.setSelectionRange(start, end);
|
|
||||||
} else if (this.createTextRange) {
|
|
||||||
var range = this.createTextRange();
|
|
||||||
range.collapse(true);
|
|
||||||
range.moveEnd('character', end);
|
|
||||||
range.moveStart('character', start);
|
|
||||||
range.select();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$.fn.selectEnd = function(){
|
|
||||||
if (this.length) {
|
|
||||||
this.selectRange(this.val().length, this.val().length);
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
(function() {
|
|
||||||
Danbooru.WikiPage = {};
|
|
||||||
|
|
||||||
Danbooru.WikiPage.initialize_all = function() {
|
|
||||||
if ($("#c-wiki-pages,#c-wiki-page-versions").length) {
|
|
||||||
this.initialize_shortcuts();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Danbooru.WikiPage.initialize_shortcuts = function() {
|
|
||||||
if ($("#a-show").length) {
|
|
||||||
Danbooru.keydown("e", "edit", function(e) {
|
|
||||||
$("#wiki-page-edit a")[0].click();
|
|
||||||
});
|
|
||||||
|
|
||||||
Danbooru.keydown("shift+d", "delete", function(e) {
|
|
||||||
$("#wiki-page-delete a")[0].click();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
Danbooru.WikiPage.initialize_all();
|
|
||||||
});
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
@import "jquery.dropdown.scss";
|
|
||||||
@import "jquery.qtip.scss";
|
|
||||||
@import "common/*";
|
|
||||||
|
|
||||||
// @import wildcards don't work with .erb files. Put .erb files in a separate
|
|
||||||
// directory and load them explicitly to work around this.
|
|
||||||
// https://github.com/rails/sass-rails/issues/185
|
|
||||||
@import "specific/*";
|
|
||||||
@import "specific/erb/mod_queue";
|
|
||||||
@import "common/erb/tags";
|
|
||||||
29
app/javascript/packs/application.js
Normal file
29
app/javascript/packs/application.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/* eslint no-console:0 */
|
||||||
|
|
||||||
|
function importAll (r) {
|
||||||
|
r.keys().forEach(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
require('jquery-ujs');
|
||||||
|
require('hammerjs');
|
||||||
|
require('qtip2');
|
||||||
|
|
||||||
|
// should start looking for nodejs replacements
|
||||||
|
importAll(require.context('../vendor', true, /\.js$/));
|
||||||
|
|
||||||
|
require("jquery-ui/ui/widgets/autocomplete");
|
||||||
|
require("jquery-ui/ui/widgets/button");
|
||||||
|
require("jquery-ui/ui/widgets/dialog");
|
||||||
|
require("jquery-ui/ui/widgets/draggable");
|
||||||
|
require("jquery-ui/ui/widgets/resizable");
|
||||||
|
require("jquery-ui/themes/base/core.css");
|
||||||
|
require("jquery-ui/themes/base/autocomplete.css");
|
||||||
|
require("jquery-ui/themes/base/button.css");
|
||||||
|
require("jquery-ui/themes/base/dialog.css");
|
||||||
|
require("jquery-ui/themes/base/draggable.css");
|
||||||
|
require("jquery-ui/themes/base/resizable.css");
|
||||||
|
require("jquery-ui/themes/base/theme.css");
|
||||||
|
|
||||||
|
importAll(require.context('../src/javascripts', true, /\.js(\.erb)?$/));
|
||||||
|
importAll(require.context('../src/styles', true, /\.scss$/));
|
||||||
|
importAll(require.context('../src/styles', true, /\.scss.erb$/));
|
||||||
151
app/javascript/src/javascripts/artist_commentaries.js
Normal file
151
app/javascript/src/javascripts/artist_commentaries.js
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
let ArtistCommentary = {};
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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(ArtistCommentary.fetch_commentary);
|
||||||
|
}
|
||||||
|
|
||||||
|
ArtistCommentary.fetch_commentary = function() {
|
||||||
|
Utility.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 = ArtistCommentary.from_source(source);
|
||||||
|
} else if (type === "Post") {
|
||||||
|
var id = $('#fetch-commentary input[name="commentary_post_id"]').val();
|
||||||
|
var commentary = ArtistCommentary.from_post_id(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
commentary.then(ArtistCommentary.fill_commentary).then(function (success) {
|
||||||
|
var message = success ? "Artist commentary copied." : "Artist commentary copied; conflicting fields ignored.";
|
||||||
|
Utility.notice(message);
|
||||||
|
}).catch(function () {
|
||||||
|
Utility.notice("Fetching artist commentary failed.");
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
ArtistCommentary.fill_commentary = function(commentary) {
|
||||||
|
var description = 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 [
|
||||||
|
ArtistCommentary.update_field($("#artist_commentary_original_title"), commentary.original_title),
|
||||||
|
ArtistCommentary.update_field($("#artist_commentary_translated_title"), commentary.translated_title),
|
||||||
|
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.
|
||||||
|
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.
|
||||||
|
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() {
|
||||||
|
ArtistCommentary.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default ArtistCommentary
|
||||||
46
app/javascript/src/javascripts/artists.js
Normal file
46
app/javascript/src/javascripts/artists.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
let Artist = {};
|
||||||
|
|
||||||
|
Artist.initialize_all = function() {
|
||||||
|
if ($("#c-artists").length) {
|
||||||
|
Artist.initialize_check_name();
|
||||||
|
Artist.initialize_shortcuts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 href='/wiki_pages/" + escape($("#artist_name").val()) + "'>A wiki page with this name already exists</a>. You must either move the wiki page or pick another artist name.")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$("#check-name-result").html("An artist with this name already exists.")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Artist.initialize_shortcuts = function() {
|
||||||
|
if ($("#c-artists #a-show").length) {
|
||||||
|
Utility.keydown("e", "edit", function(e) {
|
||||||
|
$("#artist-edit a")[0].click();
|
||||||
|
});
|
||||||
|
|
||||||
|
Utility.keydown("shift+d", "delete", function(e) {
|
||||||
|
$("#artist-delete a")[0].click();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
Artist.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Artist
|
||||||
526
app/javascript/src/javascripts/autocomplete.js.erb
Normal file
526
app/javascript/src/javascripts/autocomplete.js.erb
Normal file
@@ -0,0 +1,526 @@
|
|||||||
|
export { AutoComplete }
|
||||||
|
|
||||||
|
import Utility from './utility'
|
||||||
|
import SavedSearch from './saved_searches'
|
||||||
|
|
||||||
|
let Autocomplete = {};
|
||||||
|
|
||||||
|
Autocomplete.AUTOCOMPLETE_VERSION = 1;
|
||||||
|
Autocomplete.PREFIXES = /^(-|~|<%= TagCategory.mapping.keys.map {|category| category + ':'}.join('|') %>)(.*)$/i;
|
||||||
|
Autocomplete.METATAGS = /^(<%= Tag::METATAGS %>):(.*)$/i;
|
||||||
|
|
||||||
|
Autocomplete.initialize_all = function() {
|
||||||
|
if (Utility.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.Autocomplete.tab", null, "tab", Autocomplete.on_tab);
|
||||||
|
this._super();
|
||||||
|
},
|
||||||
|
_renderItem: 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"]'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Autocomplete.initialize_mention_autocomplete = function($fields) {
|
||||||
|
$fields.autocomplete({
|
||||||
|
search: function() {
|
||||||
|
$(this).data("ui-autocomplete").menu.bindings = $();
|
||||||
|
},
|
||||||
|
select: function(event, ui) {
|
||||||
|
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) {
|
||||||
|
Autocomplete.user_source(name, resp, "@");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
Autocomplete.insert_completion(this, ui.item.value);
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
source: function(req, resp) {
|
||||||
|
var query = 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":
|
||||||
|
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":
|
||||||
|
Autocomplete.user_source(term, resp, metatag);
|
||||||
|
break;
|
||||||
|
case "pool":
|
||||||
|
case "ordpool":
|
||||||
|
Autocomplete.pool_source(term, resp, metatag);
|
||||||
|
break;
|
||||||
|
case "favgroup":
|
||||||
|
Autocomplete.favorite_group_source(term, resp, metatag);
|
||||||
|
break;
|
||||||
|
case "search":
|
||||||
|
Autocomplete.saved_search_source(term, resp);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Autocomplete.normal_source(term, resp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$fields_single.autocomplete({
|
||||||
|
search: function() {
|
||||||
|
$(this).data("ui-autocomplete").menu.bindings = $();
|
||||||
|
},
|
||||||
|
source: function(req, resp) {
|
||||||
|
Autocomplete.normal_source(req.term, resp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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 %>,
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Autocomplete.initialize_pool_autocomplete = function($fields) {
|
||||||
|
$fields.autocomplete({
|
||||||
|
search: function() {
|
||||||
|
$(this).data("ui-autocomplete").menu.bindings = $();
|
||||||
|
},
|
||||||
|
source: function(req, resp) {
|
||||||
|
Autocomplete.pool_source(req.term, resp);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
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
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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(Autocomplete.PREFIXES)) {
|
||||||
|
metatag = match[1].toLowerCase();
|
||||||
|
term = match[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match = term.match(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.
|
||||||
|
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.
|
||||||
|
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;
|
||||||
|
|
||||||
|
Autocomplete.insert_completion(input, completion);
|
||||||
|
autocomplete.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent the tab key from moving focus to the next element.
|
||||||
|
event.preventDefault();
|
||||||
|
};
|
||||||
|
|
||||||
|
Autocomplete.render_item = function(list, item) {
|
||||||
|
var $link = $("<a/>");
|
||||||
|
$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 = $("<span/>").html(" → ").addClass("autocomplete-arrow");
|
||||||
|
var antecedent_element = $("<span/>").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 = $("<span/>").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 (Utility.meta("style-usernames") === "true") {
|
||||||
|
$link.addClass("with-style");
|
||||||
|
}
|
||||||
|
} else if (item.type === "pool") {
|
||||||
|
$link.addClass("pool-category-" + item.category);
|
||||||
|
}
|
||||||
|
|
||||||
|
var $menu_item = $("<div/>").append($link);
|
||||||
|
return $("<li/>").data("item.autocomplete", item).append($menu_item).appendTo(list);
|
||||||
|
};
|
||||||
|
|
||||||
|
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"
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Autocomplete.saved_search_source = function(term, resp) {
|
||||||
|
return SavedSearch.labels(term).then(function(labels) {
|
||||||
|
resp(labels.map(function(label) {
|
||||||
|
return {
|
||||||
|
label: label.replace(/_/g, " "),
|
||||||
|
value: "search:" + label,
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
Autocomplete.initialize_all();
|
||||||
|
});
|
||||||
203
app/javascript/src/javascripts/blacklists.js
Normal file
203
app/javascript/src/javascripts/blacklists.js
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
import Cookie from './cookie'
|
||||||
|
|
||||||
|
let Blacklist = {};
|
||||||
|
|
||||||
|
Blacklist.entries = [];
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
Blacklist.parse_entries = function() {
|
||||||
|
var entries = (Utility.meta("blacklisted-tags") || "nozomiisthebestlovelive").replace(/(rating:[qes])\w+/ig, "$1").toLowerCase().split(/,/);
|
||||||
|
|
||||||
|
$.each(entries, function(i, tags) {
|
||||||
|
var entry = Blacklist.parse_entry(tags);
|
||||||
|
Blacklist.entries.push(entry);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Blacklist.toggle_entry = function(e) {
|
||||||
|
var tags = $(e.target).text();
|
||||||
|
var match = $.grep(Blacklist.entries, function(entry, i) {
|
||||||
|
return entry.tags === tags;
|
||||||
|
})[0];
|
||||||
|
if (match) {
|
||||||
|
match.disabled = !match.disabled;
|
||||||
|
if (match.disabled) {
|
||||||
|
Blacklist.post_hide(e.target);
|
||||||
|
} else {
|
||||||
|
Blacklist.post_unhide(e.target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Blacklist.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
Blacklist.update_sidebar = function() {
|
||||||
|
$.each(this.entries, function(i, entry) {
|
||||||
|
if (entry.hits === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var item = $("<li/>");
|
||||||
|
var link = $("<a/>");
|
||||||
|
var count = $("<span/>");
|
||||||
|
var hash = entry.tags.hash();
|
||||||
|
|
||||||
|
link.text(entry.tags);
|
||||||
|
link.click(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();
|
||||||
|
}
|
||||||
|
|
||||||
|
Blacklist.initialize_disable_all_blacklists = function() {
|
||||||
|
if (Cookie.get("dab") === "1") {
|
||||||
|
$("#re-enable-all-blacklists").show();
|
||||||
|
$("#blacklist-list a:not(.blacklisted-active)").click();
|
||||||
|
Blacklist.apply();
|
||||||
|
} else {
|
||||||
|
$("#disable-all-blacklists").show()
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#disable-all-blacklists").click(function(e) {
|
||||||
|
$("#disable-all-blacklists").hide();
|
||||||
|
$("#re-enable-all-blacklists").show();
|
||||||
|
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();
|
||||||
|
Cookie.put("dab", "0");
|
||||||
|
$("#blacklist-list a.blacklisted-active").click();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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(Blacklist.entries, function(i, entry) {
|
||||||
|
if (Blacklist.post_match(post, entry)) {
|
||||||
|
entry.hits += 1;
|
||||||
|
count += 1;
|
||||||
|
post_count += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (post_count > 0) {
|
||||||
|
Blacklist.post_hide(post);
|
||||||
|
} else {
|
||||||
|
Blacklist.post_unhide(post);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
Blacklist.posts = function() {
|
||||||
|
return $(".post-preview, #image-container, #c-comments .post");
|
||||||
|
}
|
||||||
|
|
||||||
|
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) && Utility.is_subset(tags, entry.require) && !Utility.intersect(tags, entry.exclude).length;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Blacklist.initialize_all = function() {
|
||||||
|
Blacklist.parse_entries();
|
||||||
|
|
||||||
|
if (Blacklist.apply() > 0) {
|
||||||
|
Blacklist.update_sidebar();
|
||||||
|
Blacklist.initialize_disable_all_blacklists();
|
||||||
|
} else {
|
||||||
|
$("#blacklist-box").hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
if ($("#blacklist-box").length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Blacklist.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Blacklist
|
||||||
124
app/javascript/src/javascripts/comments.js
Normal file
124
app/javascript/src/javascripts/comments.js
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
import Dtext from './dtext'
|
||||||
|
|
||||||
|
let Comment = {};
|
||||||
|
|
||||||
|
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) {
|
||||||
|
Comment.highlight_threshold_comments(Utility.meta("post-id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
$(window).on("danbooru:index_for_post", (post_id, current_comment_section, include_below_threshold) => {
|
||||||
|
if (include_below_threshold) {
|
||||||
|
$("#threshold-comments-notice-for-" + post_id).hide();
|
||||||
|
} else {
|
||||||
|
Comment.highlight_threshold_comments(post_id);
|
||||||
|
}
|
||||||
|
Comment.initialize_reply_links(current_comment_section);
|
||||||
|
Comment.initialize_edit_links(current_comment_section);
|
||||||
|
Comment.initialize_vote_links(current_comment_section);
|
||||||
|
Dtext.initialize_expandables(current_comment_section);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
Comment.initialize_reply_links = function($parent) {
|
||||||
|
$parent = $parent || $(document);
|
||||||
|
$parent.find(".reply-link").click(Comment.quote);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
Utility.scroll_to($form);
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("div.new-comment form").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Comment.highlight_threshold_comments = function(post_id) {
|
||||||
|
var threshold = parseInt(Utility.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");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Comment.hide_threshold_comments = function(post_id) {
|
||||||
|
var threshold = parseInt(Utility.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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Comment.initialize_vote_links = function($parent) {
|
||||||
|
$parent = $parent || $(document);
|
||||||
|
$parent.find(".unvote-comment-link").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
Comment.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Comment
|
||||||
|
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import Cookie from './cookie'
|
||||||
|
import Utility from './utility'
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
// Table striping
|
// Table striping
|
||||||
$(".striped tbody tr:even").addClass("even");
|
$(".striped tbody tr:even").addClass("even");
|
||||||
@@ -6,13 +9,13 @@ $(function() {
|
|||||||
// Account notices
|
// Account notices
|
||||||
$("#hide-sign-up-notice").click(function(e) {
|
$("#hide-sign-up-notice").click(function(e) {
|
||||||
$("#sign-up-notice").hide();
|
$("#sign-up-notice").hide();
|
||||||
Danbooru.Cookie.put("hide_sign_up_notice", "1", 7);
|
Cookie.put("hide_sign_up_notice", "1", 7);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#hide-upgrade-account-notice").click(function(e) {
|
$("#hide-upgrade-account-notice").click(function(e) {
|
||||||
$("#upgrade-account-notice").hide();
|
$("#upgrade-account-notice").hide();
|
||||||
Danbooru.Cookie.put('hide_upgrade_account_notice', '1', 7);
|
Cookie.put('hide_upgrade_account_notice', '1', 7);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -20,7 +23,7 @@ $(function() {
|
|||||||
var $dmail_notice = $("#dmail-notice");
|
var $dmail_notice = $("#dmail-notice");
|
||||||
$dmail_notice.hide();
|
$dmail_notice.hide();
|
||||||
var dmail_id = $dmail_notice.data("id");
|
var dmail_id = $dmail_notice.data("id");
|
||||||
Danbooru.Cookie.put("hide_dmail_notice", dmail_id);
|
Cookie.put("hide_dmail_notice", dmail_id);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -31,7 +34,7 @@ $(function() {
|
|||||||
|
|
||||||
$("#desktop-version-link a").click(function(e) {
|
$("#desktop-version-link a").click(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
$.ajax("/users/" + Danbooru.meta("current-user-id") + ".json", {
|
$.ajax("/users/" + Utility.meta("current-user-id") + ".json", {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
data: {
|
data: {
|
||||||
"user[disable_responsive_mode]": "true"
|
"user[disable_responsive_mode]": "true"
|
||||||
@@ -42,8 +45,6 @@ $(function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var Danbooru = {};
|
global.submitInvisibleRecaptchaForm = function () {
|
||||||
|
|
||||||
var submitInvisibleRecaptchaForm = function () {
|
|
||||||
document.getElementById("signup-form").submit();
|
document.getElementById("signup-form").submit();
|
||||||
};
|
}
|
||||||
72
app/javascript/src/javascripts/cookie.js
Normal file
72
app/javascript/src/javascripts/cookie.js
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
let Cookie = {};
|
||||||
|
|
||||||
|
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 {
|
||||||
|
Utility.error("You have too many cookies on this site. Consider deleting them all.")
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 "";
|
||||||
|
}
|
||||||
|
|
||||||
|
Cookie.get = function(name) {
|
||||||
|
return this.unescape(this.raw_get(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
Cookie.remove = function(name) {
|
||||||
|
this.put(name, "", -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Cookie.unescape = function(val) {
|
||||||
|
return decodeURIComponent(val.replace(/\+/g, " "));
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
Cookie.initialize();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Cookie
|
||||||
68
app/javascript/src/javascripts/dtext.js
Normal file
68
app/javascript/src/javascripts/dtext.js
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
let Dtext = {};
|
||||||
|
|
||||||
|
Dtext.initialize_all = function() {
|
||||||
|
Dtext.initialize_links();
|
||||||
|
Dtext.initialize_expandables();
|
||||||
|
}
|
||||||
|
|
||||||
|
Dtext.initialize_links = function() {
|
||||||
|
$(".simple_form .dtext-preview").hide();
|
||||||
|
$(".simple_form input[value=Preview]").click(Dtext.click_button);
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
Dtext.initialize_expandables($preview);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Dtext.call_edit = function(e, $button, $input, $preview) {
|
||||||
|
$button.val("Preview");
|
||||||
|
$preview.hide();
|
||||||
|
$input.slideDown("fast");
|
||||||
|
}
|
||||||
|
|
||||||
|
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)) {
|
||||||
|
Dtext.call_preview(e, $button, $input, $preview);
|
||||||
|
} else {
|
||||||
|
Dtext.call_edit(e, $button, $input, $preview);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
Dtext.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Dtext
|
||||||
53
app/javascript/src/javascripts/favorite_groups.js
Normal file
53
app/javascript/src/javascripts/favorite_groups.js
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
|
||||||
|
let FavoriteGroup = {};
|
||||||
|
|
||||||
|
FavoriteGroup.initialize_all = function() {
|
||||||
|
if ($("#c-posts").length && $("#a-show").length) {
|
||||||
|
this.initialize_add_to_favgroup_dialog();
|
||||||
|
Utility.keydown("1 2 3 4 5 6 7 8 9 0", "add_to_favgroup", FavoriteGroup.add_to_favgroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (Utility.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility.keydown("g", "open_favgroup_dialog", open_favgroup_dialog);
|
||||||
|
$("#open-favgroup-dialog-link").click(open_favgroup_dialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
FavoriteGroup.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default FavoriteGroup
|
||||||
65
app/javascript/src/javascripts/favorites.js
Normal file
65
app/javascript/src/javascripts/favorites.js
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import Post from './posts.js.erb'
|
||||||
|
import Utility from './utility'
|
||||||
|
|
||||||
|
let Favorite = {}
|
||||||
|
|
||||||
|
Favorite.initialize_all = function() {
|
||||||
|
if ($("#c-posts").length) {
|
||||||
|
this.hide_or_show_add_to_favorites_link();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Favorite.hide_or_show_add_to_favorites_link = function() {
|
||||||
|
var current_user_id = Utility.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Favorite.create = function(post_id) {
|
||||||
|
Post.notice_update("inc");
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "/favorites.js",
|
||||||
|
data: {
|
||||||
|
post_id: post_id
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
Post.notice_update("dec");
|
||||||
|
},
|
||||||
|
error: function(data, status, xhr) {
|
||||||
|
Utility.notice("Error: " + data.reason);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Favorite.destroy = function(post_id) {
|
||||||
|
Post.notice_update("inc");
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "DELETE",
|
||||||
|
url: "/favorites/" + post_id + ".js",
|
||||||
|
complete: function() {
|
||||||
|
Post.notice_update("dec");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
Favorite.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Favorite
|
||||||
|
|
||||||
47
app/javascript/src/javascripts/forum_posts.js
Normal file
47
app/javascript/src/javascripts/forum_posts.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
|
||||||
|
let ForumPost = {};
|
||||||
|
|
||||||
|
ForumPost.initialize_all = function() {
|
||||||
|
if ($("#c-forum-topics #a-show,#c-forum-posts #a-show").length) {;
|
||||||
|
this.initialize_edit_links();
|
||||||
|
|
||||||
|
Utility.keydown("e", "edit", function(e) {
|
||||||
|
$(".edit_forum_topic_link")[0].click();
|
||||||
|
});
|
||||||
|
|
||||||
|
Utility.keydown("shift+d", "delete", function(e) {
|
||||||
|
$("#forum-topic-delete a")[0].click();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($("#c-forum-topics").length) {
|
||||||
|
Utility.keydown("shift+r", "mark_all_as_read", function(e) {
|
||||||
|
$("#forum-topic-mark-all-as-read a")[0].click();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
ForumPost.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default ForumPost
|
||||||
29
app/javascript/src/javascripts/janitor_trials.js
Normal file
29
app/javascript/src/javascripts/janitor_trials.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
let JanitorTrials = {};
|
||||||
|
|
||||||
|
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() {
|
||||||
|
JanitorTrials.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default JanitorTrials
|
||||||
67
app/javascript/src/javascripts/mod_queue.js
Normal file
67
app/javascript/src/javascripts/mod_queue.js
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
let ModQueue = {};
|
||||||
|
|
||||||
|
ModQueue.processed = 0;
|
||||||
|
|
||||||
|
ModQueue.increment_processed = function() {
|
||||||
|
if (Utility.meta("random-mode") === "1") {
|
||||||
|
ModQueue.processed += 1;
|
||||||
|
|
||||||
|
if (ModQueue.processed === 12) {
|
||||||
|
window.location = Utility.meta("return-to");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ModQueue.initialize_detailed_rejection_links = function() {
|
||||||
|
$(".detailed-rejection-link").click(ModQueue.detailed_rejection_dialog)
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
$(window).on("danbooru:modqueue_increment_processed", ModQueue.increment_processed);
|
||||||
|
|
||||||
|
if ($("#c-moderator-post-queues").length) {
|
||||||
|
ModQueue.initialize_hilights();
|
||||||
|
ModQueue.initialize_detailed_rejection_links();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($("#c-posts #a-show").length) {
|
||||||
|
ModQueue.initialize_detailed_rejection_links();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default ModQueue
|
||||||
30
app/javascript/src/javascripts/news_updates.js
Normal file
30
app/javascript/src/javascripts/news_updates.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import Cookie from './cookie'
|
||||||
|
|
||||||
|
let NewsUpdate = {};
|
||||||
|
|
||||||
|
NewsUpdate.initialize = function() {
|
||||||
|
var key = $("#news-updates").data("id");
|
||||||
|
|
||||||
|
if (Cookie.get("news-ticker") == key) {
|
||||||
|
$("#news-updates").hide();
|
||||||
|
} else {
|
||||||
|
$("#news-updates").show();
|
||||||
|
|
||||||
|
$("#close-news-ticker-link").click(function(e) {
|
||||||
|
$("#news-updates").hide();
|
||||||
|
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() {
|
||||||
|
NewsUpdate.initialize();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default NewsUpdate
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
Danbooru.Note = {
|
import Utility from './utility'
|
||||||
|
|
||||||
|
let Note = {
|
||||||
Box: {
|
Box: {
|
||||||
create: function(id) {
|
create: function(id) {
|
||||||
var $inner_border = $('<div/>');
|
var $inner_border = $('<div/>');
|
||||||
$inner_border.addClass("note-box-inner-border");
|
$inner_border.addClass("note-box-inner-border");
|
||||||
|
|
||||||
var opacity = 0;
|
var opacity = 0;
|
||||||
if (Danbooru.Note.embed) {
|
if (Note.embed) {
|
||||||
opacity = 0.95
|
opacity = 0.95
|
||||||
} else {
|
} else {
|
||||||
opacity = 0.5
|
opacity = 0.5
|
||||||
@@ -18,7 +20,7 @@ Danbooru.Note = {
|
|||||||
var $note_box = $('<div/>');
|
var $note_box = $('<div/>');
|
||||||
$note_box.addClass("note-box");
|
$note_box.addClass("note-box");
|
||||||
|
|
||||||
if (Danbooru.Note.embed) {
|
if (Note.embed) {
|
||||||
$note_box.addClass("embedded");
|
$note_box.addClass("embedded");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,19 +29,19 @@ Danbooru.Note = {
|
|||||||
$note_box.draggable({
|
$note_box.draggable({
|
||||||
containment: $("#image"),
|
containment: $("#image"),
|
||||||
stop: function(e, ui) {
|
stop: function(e, ui) {
|
||||||
Danbooru.Note.Box.update_data_attributes($note_box);
|
Note.Box.update_data_attributes($note_box);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$note_box.resizable({
|
$note_box.resizable({
|
||||||
containment: $("#image"),
|
containment: $("#image"),
|
||||||
handles: "se, nw",
|
handles: "se, nw",
|
||||||
stop: function(e, ui) {
|
stop: function(e, ui) {
|
||||||
Danbooru.Note.Box.update_data_attributes($note_box);
|
Note.Box.update_data_attributes($note_box);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$note_box.css({position: "absolute"});
|
$note_box.css({position: "absolute"});
|
||||||
$note_box.append($inner_border);
|
$note_box.append($inner_border);
|
||||||
Danbooru.Note.Box.bind_events($note_box);
|
Note.Box.bind_events($note_box);
|
||||||
|
|
||||||
return $note_box;
|
return $note_box;
|
||||||
},
|
},
|
||||||
@@ -67,10 +69,10 @@ Danbooru.Note = {
|
|||||||
function(e) {
|
function(e) {
|
||||||
var $note_box_inner = $(e.currentTarget);
|
var $note_box_inner = $(e.currentTarget);
|
||||||
$note_box_inner.find(".note-box-inner-border").addClass("unsaved");
|
$note_box_inner.find(".note-box-inner-border").addClass("unsaved");
|
||||||
Danbooru.Note.dragging = true;
|
Note.dragging = true;
|
||||||
Danbooru.Note.clear_timeouts();
|
Note.clear_timeouts();
|
||||||
Danbooru.Note.Body.hide_all();
|
Note.Body.hide_all();
|
||||||
if (Danbooru.Note.embed) {
|
if (Note.embed) {
|
||||||
var $bg = $note_box_inner.find("div.bg")
|
var $bg = $note_box_inner.find("div.bg")
|
||||||
if ($bg.length) {
|
if ($bg.length) {
|
||||||
$bg.hide();
|
$bg.hide();
|
||||||
@@ -83,7 +85,7 @@ Danbooru.Note = {
|
|||||||
$note_box.resize(
|
$note_box.resize(
|
||||||
function(e) {
|
function(e) {
|
||||||
var $note_box_inner = $(e.currentTarget);
|
var $note_box_inner = $(e.currentTarget);
|
||||||
Danbooru.Note.Box.resize_inner_border($note_box_inner);
|
Note.Box.resize_inner_border($note_box_inner);
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -91,13 +93,13 @@ Danbooru.Note = {
|
|||||||
$note_box.on(
|
$note_box.on(
|
||||||
"dragstop resizestop",
|
"dragstop resizestop",
|
||||||
function(e) {
|
function(e) {
|
||||||
Danbooru.Note.dragging = false;
|
Note.dragging = false;
|
||||||
if (Danbooru.Note.embed) {
|
if (Note.embed) {
|
||||||
var $note_box_inner = $(e.currentTarget);
|
var $note_box_inner = $(e.currentTarget);
|
||||||
var $bg = $note_box_inner.find("div.bg")
|
var $bg = $note_box_inner.find("div.bg")
|
||||||
if ($bg.length) {
|
if ($bg.length) {
|
||||||
$bg.show();
|
$bg.show();
|
||||||
Danbooru.Note.Box.resize_inner_border($note_box_inner.closest(".note-box"));
|
Note.Box.resize_inner_border($note_box_inner.closest(".note-box"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@@ -107,21 +109,21 @@ Danbooru.Note = {
|
|||||||
$note_box.on(
|
$note_box.on(
|
||||||
"mouseover mouseout",
|
"mouseover mouseout",
|
||||||
function(e) {
|
function(e) {
|
||||||
if (Danbooru.Note.dragging) {
|
if (Note.dragging) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var $note_box_inner = $(e.currentTarget);
|
var $note_box_inner = $(e.currentTarget);
|
||||||
if (e.type === "mouseover") {
|
if (e.type === "mouseover") {
|
||||||
Danbooru.Note.Body.show($note_box_inner.data("id"));
|
Note.Body.show($note_box_inner.data("id"));
|
||||||
if (Danbooru.Note.editing) {
|
if (Note.editing) {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
$this.resizable("enable");
|
$this.resizable("enable");
|
||||||
$this.draggable("enable");
|
$this.draggable("enable");
|
||||||
}
|
}
|
||||||
} else if (e.type === "mouseout") {
|
} else if (e.type === "mouseout") {
|
||||||
Danbooru.Note.Body.hide($note_box_inner.data("id"));
|
Note.Body.hide($note_box_inner.data("id"));
|
||||||
if (Danbooru.Note.editing) {
|
if (Note.editing) {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
$this.resizable("disable");
|
$this.resizable("disable");
|
||||||
$this.draggable("disable");
|
$this.draggable("disable");
|
||||||
@@ -140,10 +142,10 @@ Danbooru.Note = {
|
|||||||
show_highlighted: function($note_box) {
|
show_highlighted: function($note_box) {
|
||||||
var note_id = $note_box.data("id");
|
var note_id = $note_box.data("id");
|
||||||
|
|
||||||
Danbooru.Note.Body.show(note_id);
|
Note.Body.show(note_id);
|
||||||
$(".note-box-highlighted").removeClass("note-box-highlighted");
|
$(".note-box-highlighted").removeClass("note-box-highlighted");
|
||||||
$note_box.addClass("note-box-highlighted");
|
$note_box.addClass("note-box-highlighted");
|
||||||
Danbooru.scroll_to($note_box);
|
Utility.scroll_to($note_box);
|
||||||
},
|
},
|
||||||
|
|
||||||
resize_inner_border: function($note_box) {
|
resize_inner_border: function($note_box) {
|
||||||
@@ -161,7 +163,7 @@ Danbooru.Note = {
|
|||||||
$note_box.height($inner_border.height() + 2);
|
$note_box.height($inner_border.height() + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Danbooru.Note.embed) {
|
if (Note.embed) {
|
||||||
var $bg = $inner_border.find("div.bg");
|
var $bg = $inner_border.find("div.bg");
|
||||||
if ($bg.length) {
|
if ($bg.length) {
|
||||||
$bg.height($inner_border.height());
|
$bg.height($inner_border.height());
|
||||||
@@ -180,7 +182,7 @@ Danbooru.Note = {
|
|||||||
width: Math.max(MIN_SIZE, Math.ceil(parseFloat($note_box.data("width")) * ratio)),
|
width: Math.max(MIN_SIZE, Math.ceil(parseFloat($note_box.data("width")) * ratio)),
|
||||||
height: Math.max(MIN_SIZE, Math.ceil(parseFloat($note_box.data("height")) * ratio))
|
height: Math.max(MIN_SIZE, Math.ceil(parseFloat($note_box.data("height")) * ratio))
|
||||||
});
|
});
|
||||||
Danbooru.Note.Box.resize_inner_border($note_box);
|
Note.Box.resize_inner_border($note_box);
|
||||||
},
|
},
|
||||||
|
|
||||||
scale_all: function() {
|
scale_all: function() {
|
||||||
@@ -194,7 +196,7 @@ Danbooru.Note = {
|
|||||||
container.style.display = 'none';
|
container.style.display = 'none';
|
||||||
}
|
}
|
||||||
$(".note-box").each(function(i, v) {
|
$(".note-box").each(function(i, v) {
|
||||||
Danbooru.Note.Box.scale($(v));
|
Note.Box.scale($(v));
|
||||||
});
|
});
|
||||||
if (was_visible) {
|
if (was_visible) {
|
||||||
container.style.display = 'block';
|
container.style.display = 'block';
|
||||||
@@ -220,17 +222,17 @@ Danbooru.Note = {
|
|||||||
$note_body.data("id", String(id));
|
$note_body.data("id", String(id));
|
||||||
$note_body.attr("data-id", String(id));
|
$note_body.attr("data-id", String(id));
|
||||||
$note_body.hide();
|
$note_body.hide();
|
||||||
Danbooru.Note.Body.bind_events($note_body);
|
Note.Body.bind_events($note_body);
|
||||||
return $note_body;
|
return $note_body;
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function($note_body) {
|
initialize: function($note_body) {
|
||||||
var $note_box = Danbooru.Note.Box.find($note_body.data("id"));
|
var $note_box = Note.Box.find($note_body.data("id"));
|
||||||
$note_body.css({
|
$note_body.css({
|
||||||
top: $note_box.position().top + $note_box.height() + 5,
|
top: $note_box.position().top + $note_box.height() + 5,
|
||||||
left: $note_box.position().left
|
left: $note_box.position().left
|
||||||
});
|
});
|
||||||
Danbooru.Note.Body.bound_position($note_body);
|
Note.Body.bound_position($note_body);
|
||||||
},
|
},
|
||||||
|
|
||||||
bound_position: function($note_body) {
|
bound_position: function($note_body) {
|
||||||
@@ -253,15 +255,15 @@ Danbooru.Note = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
show: function(id) {
|
show: function(id) {
|
||||||
Danbooru.Note.Body.hide_all();
|
Note.Body.hide_all();
|
||||||
Danbooru.Note.clear_timeouts();
|
Note.clear_timeouts();
|
||||||
var $note_body = Danbooru.Note.Body.find(id);
|
var $note_body = Note.Body.find(id);
|
||||||
if (!$note_body.data('resized')) {
|
if (!$note_body.data('resized')) {
|
||||||
Danbooru.Note.Body.resize($note_body);
|
Note.Body.resize($note_body);
|
||||||
$note_body.data('resized', 'true');
|
$note_body.data('resized', 'true');
|
||||||
}
|
}
|
||||||
$note_body.show();
|
$note_body.show();
|
||||||
Danbooru.Note.Body.initialize($note_body);
|
Note.Body.initialize($note_body);
|
||||||
},
|
},
|
||||||
|
|
||||||
find: function(id) {
|
find: function(id) {
|
||||||
@@ -269,8 +271,8 @@ Danbooru.Note = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
hide: function(id) {
|
hide: function(id) {
|
||||||
var $note_body = Danbooru.Note.Body.find(id);
|
var $note_body = Note.Body.find(id);
|
||||||
Danbooru.Note.timeouts.push($.timeout(250).done(function() {$note_body.hide();}));
|
Note.timeouts.push($.timeout(250).done(function() {$note_body.hide();}));
|
||||||
},
|
},
|
||||||
|
|
||||||
hide_all: function() {
|
hide_all: function() {
|
||||||
@@ -321,12 +323,12 @@ Danbooru.Note = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
set_text: function($note_body, $note_box, text) {
|
set_text: function($note_body, $note_box, text) {
|
||||||
Danbooru.Note.Body.display_text($note_body, text);
|
Note.Body.display_text($note_body, text);
|
||||||
if (Danbooru.Note.embed) {
|
if (Note.embed) {
|
||||||
Danbooru.Note.Body.display_text($note_box.children("div.note-box-inner-border"), text);
|
Note.Body.display_text($note_box.children("div.note-box-inner-border"), text);
|
||||||
}
|
}
|
||||||
Danbooru.Note.Body.resize($note_body);
|
Note.Body.resize($note_body);
|
||||||
Danbooru.Note.Body.bound_position($note_body);
|
Note.Body.bound_position($note_body);
|
||||||
},
|
},
|
||||||
|
|
||||||
display_text: function($note_body, text) {
|
display_text: function($note_body, text) {
|
||||||
@@ -339,28 +341,28 @@ Danbooru.Note = {
|
|||||||
bind_events: function($note_body) {
|
bind_events: function($note_body) {
|
||||||
$note_body.mouseover(function(e) {
|
$note_body.mouseover(function(e) {
|
||||||
var $note_body_inner = $(e.currentTarget);
|
var $note_body_inner = $(e.currentTarget);
|
||||||
Danbooru.Note.Body.show($note_body_inner.data("id"));
|
Note.Body.show($note_body_inner.data("id"));
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
|
|
||||||
$note_body.mouseout(function(e) {
|
$note_body.mouseout(function(e) {
|
||||||
var $note_body_inner = $(e.currentTarget);
|
var $note_body_inner = $(e.currentTarget);
|
||||||
Danbooru.Note.Body.hide($note_body_inner.data("id"));
|
Note.Body.hide($note_body_inner.data("id"));
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Danbooru.meta("current-user-name") !== "Anonymous") {
|
if (Utility.meta("current-user-name") !== "Anonymous") {
|
||||||
$note_body.click(function(e) {
|
$note_body.click(function(e) {
|
||||||
if (e.target.tagName !== "A") {
|
if (e.target.tagName !== "A") {
|
||||||
var $note_body_inner = $(e.currentTarget);
|
var $note_body_inner = $(e.currentTarget);
|
||||||
Danbooru.Note.Edit.show($note_body_inner);
|
Note.Edit.show($note_body_inner);
|
||||||
}
|
}
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$note_body.click(function(e) {
|
$note_body.click(function(e) {
|
||||||
if (e.target.tagName !== "A") {
|
if (e.target.tagName !== "A") {
|
||||||
Danbooru.notice("You must be logged in to edit notes");
|
Utility.notice("You must be logged in to edit notes");
|
||||||
}
|
}
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
@@ -372,18 +374,18 @@ Danbooru.Note = {
|
|||||||
show: function($note_body) {
|
show: function($note_body) {
|
||||||
var id = $note_body.data("id");
|
var id = $note_body.data("id");
|
||||||
|
|
||||||
if (Danbooru.Note.editing) {
|
if (Note.editing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$(".note-box").resizable("disable");
|
$(".note-box").resizable("disable");
|
||||||
$(".note-box").draggable("disable");
|
$(".note-box").draggable("disable");
|
||||||
|
|
||||||
if (Danbooru.Note.embed) {
|
if (Note.embed) {
|
||||||
$(".note-box").css("opacity", "0.5");
|
$(".note-box").css("opacity", "0.5");
|
||||||
}
|
}
|
||||||
|
|
||||||
$textarea = $('<textarea></textarea>');
|
let $textarea = $('<textarea></textarea>');
|
||||||
$textarea.css({
|
$textarea.css({
|
||||||
width: "97%",
|
width: "97%",
|
||||||
height: "92%",
|
height: "92%",
|
||||||
@@ -394,7 +396,7 @@ Danbooru.Note = {
|
|||||||
$textarea.val($note_body.data("original-body"));
|
$textarea.val($note_body.data("original-body"));
|
||||||
}
|
}
|
||||||
|
|
||||||
$dialog = $('<div></div>');
|
let $dialog = $('<div></div>');
|
||||||
$dialog.append($textarea);
|
$dialog.append($textarea);
|
||||||
$dialog.data("id", id);
|
$dialog.data("id", id);
|
||||||
$dialog.dialog({
|
$dialog.dialog({
|
||||||
@@ -410,11 +412,11 @@ Danbooru.Note = {
|
|||||||
},
|
},
|
||||||
title: "Edit note",
|
title: "Edit note",
|
||||||
buttons: {
|
buttons: {
|
||||||
"Save": Danbooru.Note.Edit.save,
|
"Save": Note.Edit.save,
|
||||||
"Preview": Danbooru.Note.Edit.preview,
|
"Preview": Note.Edit.preview,
|
||||||
"Cancel": Danbooru.Note.Edit.cancel,
|
"Cancel": Note.Edit.cancel,
|
||||||
"Delete": Danbooru.Note.Edit.destroy,
|
"Delete": Note.Edit.destroy,
|
||||||
"History": Danbooru.Note.Edit.history
|
"History": Note.Edit.history
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$dialog.data("uiDialog")._title = function(title) {
|
$dialog.data("uiDialog")._title = function(title) {
|
||||||
@@ -423,17 +425,17 @@ Danbooru.Note = {
|
|||||||
$dialog.dialog("option", "title", 'Edit note #' + id + ' (<a href="/wiki_pages/help:notes">view help</a>)');
|
$dialog.dialog("option", "title", 'Edit note #' + id + ' (<a href="/wiki_pages/help:notes">view help</a>)');
|
||||||
|
|
||||||
$dialog.on("dialogclose", function() {
|
$dialog.on("dialogclose", function() {
|
||||||
Danbooru.Note.editing = false;
|
Note.editing = false;
|
||||||
$(".note-box").resizable("enable");
|
$(".note-box").resizable("enable");
|
||||||
$(".note-box").draggable("enable");
|
$(".note-box").draggable("enable");
|
||||||
|
|
||||||
if (Danbooru.Note.embed) {
|
if (Note.embed) {
|
||||||
$(".note-box").css("opacity", "0.95");
|
$(".note-box").css("opacity", "0.95");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$textarea.selectEnd();
|
$textarea.selectEnd();
|
||||||
Danbooru.Note.editing = true;
|
Note.editing = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
parameterize_note: function($note_box, $note_body) {
|
parameterize_note: function($note_box, $note_body) {
|
||||||
@@ -453,25 +455,25 @@ Danbooru.Note = {
|
|||||||
|
|
||||||
if ($note_box.data("id").match(/x/)) {
|
if ($note_box.data("id").match(/x/)) {
|
||||||
hash.note.html_id = $note_box.data("id");
|
hash.note.html_id = $note_box.data("id");
|
||||||
hash.note.post_id = Danbooru.meta("post-id");
|
hash.note.post_id = Utility.meta("post-id");
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
},
|
},
|
||||||
|
|
||||||
error_handler: function(xhr, status, exception) {
|
error_handler: function(xhr, status, exception) {
|
||||||
Danbooru.error("Error: " + (xhr.responseJSON.reason || xhr.responseJSON.reasons.join("; ")));
|
Utility.error("Error: " + (xhr.responseJSON.reason || xhr.responseJSON.reasons.join("; ")));
|
||||||
},
|
},
|
||||||
|
|
||||||
success_handler: function(data, status, xhr) {
|
success_handler: function(data, status, xhr) {
|
||||||
if (data.html_id) { // new note
|
if (data.html_id) { // new note
|
||||||
var $note_body = Danbooru.Note.Body.find(data.html_id);
|
var $note_body = Note.Body.find(data.html_id);
|
||||||
var $note_box = Danbooru.Note.Box.find(data.html_id);
|
var $note_box = Note.Box.find(data.html_id);
|
||||||
$note_body.data("id", String(data.id)).attr("data-id", data.id);
|
$note_body.data("id", String(data.id)).attr("data-id", data.id);
|
||||||
$note_box.data("id", String(data.id)).attr("data-id", data.id);
|
$note_box.data("id", String(data.id)).attr("data-id", data.id);
|
||||||
$note_box.find(".note-box-inner-border").removeClass("unsaved");
|
$note_box.find(".note-box-inner-border").removeClass("unsaved");
|
||||||
} else {
|
} else {
|
||||||
var $note_box = Danbooru.Note.Box.find(data.id);
|
var $note_box = Note.Box.find(data.id);
|
||||||
$note_box.find(".note-box-inner-border").removeClass("unsaved");
|
$note_box.find(".note-box-inner-border").removeClass("unsaved");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -480,14 +482,14 @@ Danbooru.Note = {
|
|||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
var $textarea = $this.find("textarea");
|
var $textarea = $this.find("textarea");
|
||||||
var id = $this.data("id");
|
var id = $this.data("id");
|
||||||
var $note_body = Danbooru.Note.Body.find(id);
|
var $note_body = Note.Body.find(id);
|
||||||
var $note_box = Danbooru.Note.Box.find(id);
|
var $note_box = Note.Box.find(id);
|
||||||
var text = $textarea.val();
|
var text = $textarea.val();
|
||||||
$note_body.data("original-body", text);
|
$note_body.data("original-body", text);
|
||||||
Danbooru.Note.Body.set_text($note_body, $note_box, "Loading...");
|
Note.Body.set_text($note_body, $note_box, "Loading...");
|
||||||
$.get("/note_previews.json", {body: text}).then(function(data) {
|
$.get("/note_previews.json", {body: text}).then(function(data) {
|
||||||
Danbooru.Note.Body.set_text($note_body, $note_box, data.body);
|
Note.Body.set_text($note_body, $note_box, data.body);
|
||||||
Danbooru.Note.Box.resize_inner_border($note_box);
|
Note.Box.resize_inner_border($note_box);
|
||||||
$note_body.show();
|
$note_body.show();
|
||||||
});
|
});
|
||||||
$this.dialog("close");
|
$this.dialog("close");
|
||||||
@@ -495,16 +497,16 @@ Danbooru.Note = {
|
|||||||
if (id.match(/\d/)) {
|
if (id.match(/\d/)) {
|
||||||
$.ajax("/notes/" + id + ".json", {
|
$.ajax("/notes/" + id + ".json", {
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
data: Danbooru.Note.Edit.parameterize_note($note_box, $note_body),
|
data: Note.Edit.parameterize_note($note_box, $note_body),
|
||||||
error: Danbooru.Note.Edit.error_handler,
|
error: Note.Edit.error_handler,
|
||||||
success: Danbooru.Note.Edit.success_handler
|
success: Note.Edit.success_handler
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$.ajax("/notes.json", {
|
$.ajax("/notes.json", {
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: Danbooru.Note.Edit.parameterize_note($note_box, $note_body),
|
data: Note.Edit.parameterize_note($note_box, $note_body),
|
||||||
error: Danbooru.Note.Edit.error_handler,
|
error: Note.Edit.error_handler,
|
||||||
success: Danbooru.Note.Edit.success_handler
|
success: Note.Edit.success_handler
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -513,13 +515,13 @@ Danbooru.Note = {
|
|||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
var $textarea = $this.find("textarea");
|
var $textarea = $this.find("textarea");
|
||||||
var id = $this.data("id");
|
var id = $this.data("id");
|
||||||
var $note_body = Danbooru.Note.Body.find(id);
|
var $note_body = Note.Body.find(id);
|
||||||
var text = $textarea.val();
|
var text = $textarea.val();
|
||||||
var $note_box = Danbooru.Note.Box.find(id);
|
var $note_box = Note.Box.find(id);
|
||||||
$note_box.find(".note-box-inner-border").addClass("unsaved");
|
$note_box.find(".note-box-inner-border").addClass("unsaved");
|
||||||
Danbooru.Note.Body.set_text($note_body, $note_box, "Loading...");
|
Note.Body.set_text($note_body, $note_box, "Loading...");
|
||||||
$.get("/note_previews.json", {body: text}).then(function(data) {
|
$.get("/note_previews.json", {body: text}).then(function(data) {
|
||||||
Danbooru.Note.Body.set_text($note_body, $note_box, data.body);
|
Note.Body.set_text($note_body, $note_box, data.body);
|
||||||
$note_body.show();
|
$note_body.show();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -540,8 +542,8 @@ Danbooru.Note = {
|
|||||||
$.ajax("/notes/" + id + ".json", {
|
$.ajax("/notes/" + id + ".json", {
|
||||||
type: "DELETE",
|
type: "DELETE",
|
||||||
success: function() {
|
success: function() {
|
||||||
Danbooru.Note.Box.find(id).remove();
|
Note.Box.find(id).remove();
|
||||||
Danbooru.Note.Body.find(id).remove();
|
Note.Body.find(id).remove();
|
||||||
$this.dialog("close");
|
$this.dialog("close");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -562,46 +564,46 @@ Danbooru.Note = {
|
|||||||
active: false,
|
active: false,
|
||||||
|
|
||||||
toggle: function(e) {
|
toggle: function(e) {
|
||||||
if (Danbooru.Note.TranslationMode.active) {
|
if (Note.TranslationMode.active) {
|
||||||
Danbooru.Note.TranslationMode.stop(e);
|
Note.TranslationMode.stop(e);
|
||||||
} else {
|
} else {
|
||||||
Danbooru.Note.TranslationMode.start(e);
|
Note.TranslationMode.start(e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
start: function(e) {
|
start: function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (Danbooru.meta("current-user-id") == "") {
|
if (Utility.meta("current-user-id") == "") {
|
||||||
Danbooru.notice("You must be logged in to edit notes");
|
Utility.notice("You must be logged in to edit notes");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Danbooru.Note.TranslationMode.active) {
|
if (Note.TranslationMode.active) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#image").css("cursor", "crosshair");
|
$("#image").css("cursor", "crosshair");
|
||||||
Danbooru.Note.TranslationMode.active = true;
|
Note.TranslationMode.active = true;
|
||||||
$(document.body).addClass("mode-translation");
|
$(document.body).addClass("mode-translation");
|
||||||
$("#original-file-link").click();
|
$("#original-file-link").click();
|
||||||
$("#image").off("click", Danbooru.Note.Box.toggle_all);
|
$("#image").off("click", Note.Box.toggle_all);
|
||||||
$("#image").mousedown(Danbooru.Note.TranslationMode.Drag.start);
|
$("#image").mousedown(Note.TranslationMode.Drag.start);
|
||||||
$(window).mouseup(Danbooru.Note.TranslationMode.Drag.stop);
|
$(window).mouseup(Note.TranslationMode.Drag.stop);
|
||||||
$("#mark-as-translated-section").show();
|
$("#mark-as-translated-section").show();
|
||||||
|
|
||||||
Danbooru.notice('Translation mode is on. Drag on the image to create notes. <a href="#">Turn translation mode off</a> (shortcut is <span class="key">n</span>).');
|
Utility.notice('Translation mode is on. Drag on the image to create notes. <a href="#">Turn translation mode off</a> (shortcut is <span class="key">n</span>).');
|
||||||
$("#notice a:contains(Turn translation mode off)").click(Danbooru.Note.TranslationMode.stop);
|
$("#notice a:contains(Turn translation mode off)").click(Note.TranslationMode.stop);
|
||||||
},
|
},
|
||||||
|
|
||||||
stop: function(e) {
|
stop: function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
Danbooru.Note.TranslationMode.active = false;
|
Note.TranslationMode.active = false;
|
||||||
$("#image").css("cursor", "auto");
|
$("#image").css("cursor", "auto");
|
||||||
$("#image").click(Danbooru.Note.Box.toggle_all);
|
$("#image").click(Note.Box.toggle_all);
|
||||||
$("#image").off("mousedown", Danbooru.Note.TranslationMode.Drag.start);
|
$("#image").off("mousedown", Note.TranslationMode.Drag.start);
|
||||||
$(window).off("mouseup", Danbooru.Note.TranslationMode.Drag.stop);
|
$(window).off("mouseup", Note.TranslationMode.Drag.stop);
|
||||||
$(document.body).removeClass("mode-translation");
|
$(document.body).removeClass("mode-translation");
|
||||||
$("#close-notice-link").click();
|
$("#close-notice-link").click();
|
||||||
$("#mark-as-translated-section").hide();
|
$("#mark-as-translated-section").hide();
|
||||||
@@ -616,7 +618,7 @@ Danbooru.Note = {
|
|||||||
} else if (h <= 9) {
|
} else if (h <= 9) {
|
||||||
h = 10;
|
h = 10;
|
||||||
}
|
}
|
||||||
Danbooru.Note.create(x - offset.left, y - offset.top, w, h);
|
Note.create(x - offset.left, y - offset.top, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#note-container").css('visibility', 'visible');
|
$("#note-container").css('visibility', 'visible');
|
||||||
@@ -640,59 +642,59 @@ Danbooru.Note = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.preventDefault(); /* don't drag the image */
|
e.preventDefault(); /* don't drag the image */
|
||||||
$(window).mousemove(Danbooru.Note.TranslationMode.Drag.drag);
|
$(window).mousemove(Note.TranslationMode.Drag.drag);
|
||||||
Danbooru.Note.TranslationMode.Drag.dragStartX = e.pageX;
|
Note.TranslationMode.Drag.dragStartX = e.pageX;
|
||||||
Danbooru.Note.TranslationMode.Drag.dragStartY = e.pageY;
|
Note.TranslationMode.Drag.dragStartY = e.pageY;
|
||||||
},
|
},
|
||||||
|
|
||||||
drag: function (e) {
|
drag: function (e) {
|
||||||
Danbooru.Note.TranslationMode.Drag.dragDistanceX = e.pageX - Danbooru.Note.TranslationMode.Drag.dragStartX;
|
Note.TranslationMode.Drag.dragDistanceX = e.pageX - Note.TranslationMode.Drag.dragStartX;
|
||||||
Danbooru.Note.TranslationMode.Drag.dragDistanceY = e.pageY - Danbooru.Note.TranslationMode.Drag.dragStartY;
|
Note.TranslationMode.Drag.dragDistanceY = e.pageY - Note.TranslationMode.Drag.dragStartY;
|
||||||
var $image = $("#image");
|
var $image = $("#image");
|
||||||
var offset = $image.offset();
|
var offset = $image.offset();
|
||||||
var limitX1 = $image.width() - Danbooru.Note.TranslationMode.Drag.dragStartX + offset.left - 1;
|
var limitX1 = $image.width() - Note.TranslationMode.Drag.dragStartX + offset.left - 1;
|
||||||
var limitX2 = offset.left - Danbooru.Note.TranslationMode.Drag.dragStartX;
|
var limitX2 = offset.left - Note.TranslationMode.Drag.dragStartX;
|
||||||
var limitY1 = $image.height()- Danbooru.Note.TranslationMode.Drag.dragStartY + offset.top - 1;
|
var limitY1 = $image.height()- Note.TranslationMode.Drag.dragStartY + offset.top - 1;
|
||||||
var limitY2 = offset.top - Danbooru.Note.TranslationMode.Drag.dragStartY;
|
var limitY2 = offset.top - Note.TranslationMode.Drag.dragStartY;
|
||||||
|
|
||||||
if (Danbooru.Note.TranslationMode.Drag.dragDistanceX > limitX1) {
|
if (Note.TranslationMode.Drag.dragDistanceX > limitX1) {
|
||||||
Danbooru.Note.TranslationMode.Drag.dragDistanceX = limitX1;
|
Note.TranslationMode.Drag.dragDistanceX = limitX1;
|
||||||
} else if (Danbooru.Note.TranslationMode.Drag.dragDistanceX < limitX2) {
|
} else if (Note.TranslationMode.Drag.dragDistanceX < limitX2) {
|
||||||
Danbooru.Note.TranslationMode.Drag.dragDistanceX = limitX2;
|
Note.TranslationMode.Drag.dragDistanceX = limitX2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Danbooru.Note.TranslationMode.Drag.dragDistanceY > limitY1) {
|
if (Note.TranslationMode.Drag.dragDistanceY > limitY1) {
|
||||||
Danbooru.Note.TranslationMode.Drag.dragDistanceY = limitY1;
|
Note.TranslationMode.Drag.dragDistanceY = limitY1;
|
||||||
} else if (Danbooru.Note.TranslationMode.Drag.dragDistanceY < limitY2) {
|
} else if (Note.TranslationMode.Drag.dragDistanceY < limitY2) {
|
||||||
Danbooru.Note.TranslationMode.Drag.dragDistanceY = limitY2;
|
Note.TranslationMode.Drag.dragDistanceY = limitY2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Math.abs(Danbooru.Note.TranslationMode.Drag.dragDistanceX) > 9 && Math.abs(Danbooru.Note.TranslationMode.Drag.dragDistanceY) > 9) {
|
if (Math.abs(Note.TranslationMode.Drag.dragDistanceX) > 9 && Math.abs(Note.TranslationMode.Drag.dragDistanceY) > 9) {
|
||||||
Danbooru.Note.TranslationMode.Drag.dragging = true; /* must drag at least 10pixels (minimum note size) in both dimensions. */
|
Note.TranslationMode.Drag.dragging = true; /* must drag at least 10pixels (minimum note size) in both dimensions. */
|
||||||
}
|
}
|
||||||
if (Danbooru.Note.TranslationMode.Drag.dragging) {
|
if (Note.TranslationMode.Drag.dragging) {
|
||||||
if (Danbooru.Note.TranslationMode.Drag.dragDistanceX >= 0) {
|
if (Note.TranslationMode.Drag.dragDistanceX >= 0) {
|
||||||
Danbooru.Note.TranslationMode.Drag.x = Danbooru.Note.TranslationMode.Drag.dragStartX;
|
Note.TranslationMode.Drag.x = Note.TranslationMode.Drag.dragStartX;
|
||||||
Danbooru.Note.TranslationMode.Drag.w = Danbooru.Note.TranslationMode.Drag.dragDistanceX;
|
Note.TranslationMode.Drag.w = Note.TranslationMode.Drag.dragDistanceX;
|
||||||
} else {
|
} else {
|
||||||
Danbooru.Note.TranslationMode.Drag.x = Danbooru.Note.TranslationMode.Drag.dragStartX + Danbooru.Note.TranslationMode.Drag.dragDistanceX;
|
Note.TranslationMode.Drag.x = Note.TranslationMode.Drag.dragStartX + Note.TranslationMode.Drag.dragDistanceX;
|
||||||
Danbooru.Note.TranslationMode.Drag.w = -Danbooru.Note.TranslationMode.Drag.dragDistanceX;
|
Note.TranslationMode.Drag.w = -Note.TranslationMode.Drag.dragDistanceX;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Danbooru.Note.TranslationMode.Drag.dragDistanceY >= 0) {
|
if (Note.TranslationMode.Drag.dragDistanceY >= 0) {
|
||||||
Danbooru.Note.TranslationMode.Drag.y = Danbooru.Note.TranslationMode.Drag.dragStartY;
|
Note.TranslationMode.Drag.y = Note.TranslationMode.Drag.dragStartY;
|
||||||
Danbooru.Note.TranslationMode.Drag.h = Danbooru.Note.TranslationMode.Drag.dragDistanceY;
|
Note.TranslationMode.Drag.h = Note.TranslationMode.Drag.dragDistanceY;
|
||||||
} else {
|
} else {
|
||||||
Danbooru.Note.TranslationMode.Drag.y = Danbooru.Note.TranslationMode.Drag.dragStartY + Danbooru.Note.TranslationMode.Drag.dragDistanceY;
|
Note.TranslationMode.Drag.y = Note.TranslationMode.Drag.dragStartY + Note.TranslationMode.Drag.dragDistanceY;
|
||||||
Danbooru.Note.TranslationMode.Drag.h = -Danbooru.Note.TranslationMode.Drag.dragDistanceY;
|
Note.TranslationMode.Drag.h = -Note.TranslationMode.Drag.dragDistanceY;
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#note-preview').css({
|
$('#note-preview').css({
|
||||||
display: 'block',
|
display: 'block',
|
||||||
left: (Danbooru.Note.TranslationMode.Drag.x + 1),
|
left: (Note.TranslationMode.Drag.x + 1),
|
||||||
top: (Danbooru.Note.TranslationMode.Drag.y + 1),
|
top: (Note.TranslationMode.Drag.y + 1),
|
||||||
width: (Danbooru.Note.TranslationMode.Drag.w - 3),
|
width: (Note.TranslationMode.Drag.w - 3),
|
||||||
height: (Danbooru.Note.TranslationMode.Drag.h - 3)
|
height: (Note.TranslationMode.Drag.h - 3)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -701,21 +703,21 @@ Danbooru.Note = {
|
|||||||
if (e.which !== 1) {
|
if (e.which !== 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Danbooru.Note.TranslationMode.Drag.dragStartX === 0) {
|
if (Note.TranslationMode.Drag.dragStartX === 0) {
|
||||||
return; /* 'stop' is bound to window, don't create note if start wasn't triggered */
|
return; /* 'stop' is bound to window, don't create note if start wasn't triggered */
|
||||||
}
|
}
|
||||||
$(window).off("mousemove");
|
$(window).off("mousemove");
|
||||||
|
|
||||||
if (Danbooru.Note.TranslationMode.Drag.dragging) {
|
if (Note.TranslationMode.Drag.dragging) {
|
||||||
$('#note-preview').css({display:'none'});
|
$('#note-preview').css({display:'none'});
|
||||||
Danbooru.Note.TranslationMode.create_note(e, Danbooru.Note.TranslationMode.Drag.x, Danbooru.Note.TranslationMode.Drag.y, Danbooru.Note.TranslationMode.Drag.w-1, Danbooru.Note.TranslationMode.Drag.h-1);
|
Note.TranslationMode.create_note(e, Note.TranslationMode.Drag.x, Note.TranslationMode.Drag.y, Note.TranslationMode.Drag.w-1, Note.TranslationMode.Drag.h-1);
|
||||||
Danbooru.Note.TranslationMode.Drag.dragging = false; /* border of the note is pixel-perfect on the preview border */
|
Note.TranslationMode.Drag.dragging = false; /* border of the note is pixel-perfect on the preview border */
|
||||||
} else { /* no dragging -> toggle display of notes */
|
} else { /* no dragging -> toggle display of notes */
|
||||||
Danbooru.Note.Box.toggle_all();
|
Note.Box.toggle_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.Note.TranslationMode.Drag.dragStartX = 0;
|
Note.TranslationMode.Drag.dragStartX = 0;
|
||||||
Danbooru.Note.TranslationMode.Drag.dragStartY = 0;
|
Note.TranslationMode.Drag.dragStartY = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -727,8 +729,8 @@ Danbooru.Note = {
|
|||||||
pending: {},
|
pending: {},
|
||||||
|
|
||||||
add: function(container, id, x, y, w, h, original_body, sanitized_body) {
|
add: function(container, id, x, y, w, h, original_body, sanitized_body) {
|
||||||
var $note_box = Danbooru.Note.Box.create(id);
|
var $note_box = Note.Box.create(id);
|
||||||
var $note_body = Danbooru.Note.Body.create(id);
|
var $note_body = Note.Body.create(id);
|
||||||
|
|
||||||
$note_box.data('x', x);
|
$note_box.data('x', x);
|
||||||
$note_box.data('y', y);
|
$note_box.data('y', y);
|
||||||
@@ -737,44 +739,44 @@ Danbooru.Note = {
|
|||||||
container.appendChild($note_box[0]);
|
container.appendChild($note_box[0]);
|
||||||
container.appendChild($note_body[0]);
|
container.appendChild($note_body[0]);
|
||||||
$note_body.data("original-body", original_body);
|
$note_body.data("original-body", original_body);
|
||||||
Danbooru.Note.Box.scale($note_box);
|
Note.Box.scale($note_box);
|
||||||
Danbooru.Note.Body.display_text($note_body, sanitized_body);
|
Note.Body.display_text($note_body, sanitized_body);
|
||||||
if (Danbooru.Note.embed) {
|
if (Note.embed) {
|
||||||
Danbooru.Note.Body.display_text($note_box.children("div.note-box-inner-border"), sanitized_body);
|
Note.Body.display_text($note_box.children("div.note-box-inner-border"), sanitized_body);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
create: function(x, y, w, h) {
|
create: function(x, y, w, h) {
|
||||||
var $note_box = Danbooru.Note.Box.create(Danbooru.Note.id);
|
var $note_box = Note.Box.create(Note.id);
|
||||||
var $note_body = Danbooru.Note.Body.create(Danbooru.Note.id);
|
var $note_body = Note.Body.create(Note.id);
|
||||||
$note_box.css({
|
$note_box.css({
|
||||||
top: y,
|
top: y,
|
||||||
left: x,
|
left: x,
|
||||||
width: w,
|
width: w,
|
||||||
height: h
|
height: h
|
||||||
});
|
});
|
||||||
Danbooru.Note.Box.update_data_attributes($note_box);
|
Note.Box.update_data_attributes($note_box);
|
||||||
$note_box.find(".note-box-inner-border").addClass("unsaved");
|
$note_box.find(".note-box-inner-border").addClass("unsaved");
|
||||||
$note_body.html("<em>Click to edit</em>");
|
$note_body.html("<em>Click to edit</em>");
|
||||||
$("#note-container").append($note_box);
|
$("#note-container").append($note_box);
|
||||||
$("#note-container").append($note_body);
|
$("#note-container").append($note_body);
|
||||||
Danbooru.Note.Box.resize_inner_border($note_box);
|
Note.Box.resize_inner_border($note_box);
|
||||||
Danbooru.Note.id += "x";
|
Note.id += "x";
|
||||||
},
|
},
|
||||||
|
|
||||||
clear_timeouts: function() {
|
clear_timeouts: function() {
|
||||||
$.each(Danbooru.Note.timeouts, function(i, v) {
|
$.each(Note.timeouts, function(i, v) {
|
||||||
v.clear();
|
v.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
Danbooru.Note.timeouts = [];
|
Note.timeouts = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
load_all: function() {
|
load_all: function() {
|
||||||
var fragment = document.createDocumentFragment();
|
var fragment = document.createDocumentFragment();
|
||||||
$.each($("#notes article"), function(i, article) {
|
$.each($("#notes article"), function(i, article) {
|
||||||
var $article = $(article);
|
var $article = $(article);
|
||||||
Danbooru.Note.add(
|
Note.add(
|
||||||
fragment,
|
fragment,
|
||||||
$article.data("id"),
|
$article.data("id"),
|
||||||
$article.data("x"),
|
$article.data("x"),
|
||||||
@@ -786,9 +788,9 @@ Danbooru.Note = {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
$("#note-container").append(fragment);
|
$("#note-container").append(fragment);
|
||||||
if (Danbooru.Note.embed) {
|
if (Note.embed) {
|
||||||
$.each($(".note-box"), function(i, note_box) {
|
$.each($(".note-box"), function(i, note_box) {
|
||||||
Danbooru.Note.Box.resize_inner_border($(note_box));
|
Note.Box.resize_inner_border($(note_box));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -798,8 +800,8 @@ Danbooru.Note = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.Note.embed = (Danbooru.meta("post-has-embedded-notes") === "true");
|
Note.embed = (Utility.meta("post-has-embedded-notes") === "true");
|
||||||
Danbooru.Note.load_all();
|
Note.load_all();
|
||||||
|
|
||||||
this.initialize_shortcuts();
|
this.initialize_shortcuts();
|
||||||
this.initialize_highlight();
|
this.initialize_highlight();
|
||||||
@@ -808,23 +810,26 @@ Danbooru.Note = {
|
|||||||
|
|
||||||
initialize_shortcuts: function() {
|
initialize_shortcuts: function() {
|
||||||
if ($("#note-locked-notice").length == 0) {
|
if ($("#note-locked-notice").length == 0) {
|
||||||
$("#translate").click(Danbooru.Note.TranslationMode.toggle);
|
$("#translate").click(Note.TranslationMode.toggle);
|
||||||
Danbooru.keydown("n", "translation_mode", Danbooru.Note.TranslationMode.toggle);
|
Utility.keydown("n", "translation_mode", Note.TranslationMode.toggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#image").click(Danbooru.Note.Box.toggle_all);
|
$("#image").click(Note.Box.toggle_all);
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize_highlight: function() {
|
initialize_highlight: function() {
|
||||||
var matches = window.location.hash.match(/^#note-(\d+)$/);
|
var matches = window.location.hash.match(/^#note-(\d+)$/);
|
||||||
|
|
||||||
if (matches) {
|
if (matches) {
|
||||||
var $note_box = Danbooru.Note.Box.find(matches[1]);
|
var $note_box = Note.Box.find(matches[1]);
|
||||||
Danbooru.Note.Box.show_highlighted($note_box);
|
Note.Box.show_highlighted($note_box);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
Danbooru.Note.initialize_all();
|
Note.initialize_all();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export default Note
|
||||||
|
|
||||||
26
app/javascript/src/javascripts/paginator.js
Normal file
26
app/javascript/src/javascripts/paginator.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
|
||||||
|
let Paginator = {};
|
||||||
|
|
||||||
|
Paginator.next_page = function() {
|
||||||
|
var href = $(".paginator a[rel=next]").attr("href");
|
||||||
|
if (href) {
|
||||||
|
window.location = href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Paginator.prev_page = function() {
|
||||||
|
var href = $(".paginator a[rel=prev]").attr("href");
|
||||||
|
if (href) {
|
||||||
|
window.location = href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
if ($(".paginator").length) {
|
||||||
|
Utility.keydown("d right", "next_page", Paginator.next_page);
|
||||||
|
Utility.keydown("a left", "prev_page", Paginator.prev_page);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Paginator
|
||||||
65
app/javascript/src/javascripts/pools.js
Normal file
65
app/javascript/src/javascripts/pools.js
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
|
||||||
|
let Pool = {};
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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"));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Pool.initialize_shortcuts = function() {
|
||||||
|
if ($("#c-pools #a-show").length) {
|
||||||
|
Utility.keydown("e", "edit", function(e) {
|
||||||
|
$("#pool-edit a")[0].click();
|
||||||
|
});
|
||||||
|
|
||||||
|
Utility.keydown("shift+d", "delete", function(e) {
|
||||||
|
$("#pool-delete a")[0].click();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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() {
|
||||||
|
Pool.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Pool
|
||||||
44
app/javascript/src/javascripts/post_appeals.js
Normal file
44
app/javascript/src/javascripts/post_appeals.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
|
||||||
|
let PostAppeal = {};
|
||||||
|
|
||||||
|
PostAppeal.initialize_all = function() {
|
||||||
|
if ($("#c-posts").length && $("#a-show").length) {
|
||||||
|
this.initialize_appeal();
|
||||||
|
this.hide_or_show_appeal_link();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PostAppeal.hide_or_show_appeal_link = function() {
|
||||||
|
if ((Utility.meta("post-is-flagged") === "false") && (Utility.meta("post-is-deleted") === "false")) {
|
||||||
|
$("#appeal").hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
PostAppeal.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default PostAppeal
|
||||||
48
app/javascript/src/javascripts/post_flags.js
Normal file
48
app/javascript/src/javascripts/post_flags.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
|
||||||
|
let PostFlag = {};
|
||||||
|
|
||||||
|
PostFlag.initialize_all = function() {
|
||||||
|
if ($("#c-posts").length && $("#a-show").length) {
|
||||||
|
this.initialize_flag();
|
||||||
|
this.hide_or_show_flag_link();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PostFlag.hide_or_show_flag_link = function() {
|
||||||
|
if (Utility.meta("post-is-deleted") === "true") {
|
||||||
|
$("#flag").hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
PostFlag.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default PostFlag
|
||||||
191
app/javascript/src/javascripts/post_mode_menu.js
Normal file
191
app/javascript/src/javascripts/post_mode_menu.js
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
import Cookie from './cookie'
|
||||||
|
import Post from './posts.js.erb'
|
||||||
|
import Favorite from './favorites'
|
||||||
|
import TagScript from './tag_script'
|
||||||
|
|
||||||
|
let PostModeMenu = {};
|
||||||
|
|
||||||
|
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();
|
||||||
|
PostModeMenu.change();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PostModeMenu.initialize_shortcuts = function() {
|
||||||
|
Utility.keydown("1 2 3 4 5 6 7 8 9 0", "change_tag_script", PostModeMenu.change_tag_script);
|
||||||
|
}
|
||||||
|
|
||||||
|
PostModeMenu.show_notice = function(i) {
|
||||||
|
Utility.notice("Switched to tag script #" + i + ". To switch tag scripts, use the number keys.");
|
||||||
|
}
|
||||||
|
|
||||||
|
PostModeMenu.change_tag_script = function(e) {
|
||||||
|
if ($("#mode-box select").val() === "tag-script") {
|
||||||
|
var old_tag_script_id = 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 = Cookie.get("tag-script-" + new_tag_script_id);
|
||||||
|
|
||||||
|
$("#tag-script-field").val(new_tag_script);
|
||||||
|
Cookie.put("current_tag_script_id", new_tag_script_id);
|
||||||
|
if (old_tag_script_id != new_tag_script_id) {
|
||||||
|
PostModeMenu.show_notice(new_tag_script_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PostModeMenu.initialize_selector = function() {
|
||||||
|
if (Cookie.get("mode") === "") {
|
||||||
|
Cookie.put("mode", "view");
|
||||||
|
$("#mode-box select").val("view");
|
||||||
|
} else {
|
||||||
|
$("#mode-box select").val(Cookie.get("mode"));
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#mode-box select").change(function(e) {
|
||||||
|
PostModeMenu.change();
|
||||||
|
$("#tag-script-field:visible").focus().select();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
PostModeMenu.initialize_preview_link = function() {
|
||||||
|
$(".post-preview a").click(PostModeMenu.click);
|
||||||
|
}
|
||||||
|
|
||||||
|
PostModeMenu.initialize_edit_form = function() {
|
||||||
|
$("#quick-edit-div").hide();
|
||||||
|
$("#quick-edit-form input[value=Cancel]").click(function(e) {
|
||||||
|
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) {
|
||||||
|
Post.update_data(data);
|
||||||
|
Utility.notice("Post #" + data.id + " updated");
|
||||||
|
PostModeMenu.close_edit_form();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
PostModeMenu.close_edit_form = function() {
|
||||||
|
$("#quick-edit-div").slideUp("fast");
|
||||||
|
if (Utility.meta("enable-auto-complete") === "true") {
|
||||||
|
$("#post_tag_string").data("uiAutocomplete").close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PostModeMenu.initialize_tag_script_field = function() {
|
||||||
|
$("#tag-script-field").blur(function(e) {
|
||||||
|
var script = $(this).val();
|
||||||
|
|
||||||
|
if (script) {
|
||||||
|
var current_script_id = Cookie.get("current_tag_script_id");
|
||||||
|
Cookie.put("tag-script-" + current_script_id, script);
|
||||||
|
} else {
|
||||||
|
$("#mode-box select").val("view");
|
||||||
|
PostModeMenu.change();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
Cookie.put("mode", s, 1);
|
||||||
|
|
||||||
|
if (s === "tag-script") {
|
||||||
|
var current_script_id = Cookie.get("current_tag_script_id");
|
||||||
|
if (!current_script_id) {
|
||||||
|
current_script_id = "1";
|
||||||
|
Cookie.put("current_tag_script_id", current_script_id);
|
||||||
|
}
|
||||||
|
var script = Cookie.get("tag-script-" + current_script_id);
|
||||||
|
|
||||||
|
$("#tag-script-field").val(script).show();
|
||||||
|
PostModeMenu.show_notice(current_script_id);
|
||||||
|
} else {
|
||||||
|
$("#tag-script-field").hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
PostModeMenu.click = function(e) {
|
||||||
|
var s = $("#mode-box select").val();
|
||||||
|
var post_id = $(e.target).closest("article").data("id");
|
||||||
|
|
||||||
|
if (s === "add-fav") {
|
||||||
|
Favorite.create(post_id);
|
||||||
|
} else if (s === "remove-fav") {
|
||||||
|
Favorite.destroy(post_id);
|
||||||
|
} else if (s === "edit") {
|
||||||
|
PostModeMenu.open_edit(post_id);
|
||||||
|
} else if (s === 'vote-down') {
|
||||||
|
Post.vote("down", post_id);
|
||||||
|
} else if (s === 'vote-up') {
|
||||||
|
Post.vote("up", post_id);
|
||||||
|
} else if (s === 'lock-rating') {
|
||||||
|
Post.update(post_id, {"post[is_rating_locked]": "1"});
|
||||||
|
} else if (s === 'lock-note') {
|
||||||
|
Post.update(post_id, {"post[is_note_locked]": "1"});
|
||||||
|
} else if (s === 'approve') {
|
||||||
|
Post.approve(post_id);
|
||||||
|
} else if (s === 'ban') {
|
||||||
|
Post.ban(post_id);
|
||||||
|
} else if (s === "tag-script") {
|
||||||
|
var current_script_id = Cookie.get("current_tag_script_id");
|
||||||
|
var tag_script = Cookie.get("tag-script-" + current_script_id);
|
||||||
|
TagScript.run(post_id, tag_script);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
PostModeMenu.initialize();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default PostModeMenu
|
||||||
29
app/javascript/src/javascripts/post_moderation.js
Normal file
29
app/javascript/src/javascripts/post_moderation.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
|
||||||
|
let PostModeration = {};
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PostModeration.hide_or_show_approve_and_disapprove_links = function() {
|
||||||
|
if (Utility.meta("post-is-approvable") !== "true") {
|
||||||
|
$("#approve").hide();
|
||||||
|
$("#disapprove").hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PostModeration.hide_or_show_delete_and_undelete_links = function() {
|
||||||
|
if (Utility.meta("post-is-deleted") === "true") {
|
||||||
|
$("#delete").hide();
|
||||||
|
} else {
|
||||||
|
$("#undelete").hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
PostModeration.initialize_all();
|
||||||
|
});
|
||||||
38
app/javascript/src/javascripts/post_popular.js
Normal file
38
app/javascript/src/javascripts/post_popular.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
|
||||||
|
let PostPopular = {};
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
PostPopular.initialize_all = function() {
|
||||||
|
if ($("#c-explore-posts").length) {
|
||||||
|
Utility.keydown("a left", "prev_page", PostPopular.nav_prev);
|
||||||
|
Utility.keydown("d right", "next_page", PostPopular.nav_next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
PostPopular.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default PostPopular
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
Danbooru.PostTooltip = {};
|
import Utility from './utility'
|
||||||
|
|
||||||
Danbooru.PostTooltip.render_tooltip = function (event, qtip) {
|
let PostTooltip = {};
|
||||||
|
|
||||||
|
PostTooltip.render_tooltip = function (event, qtip) {
|
||||||
var post_id = $(event.target).parents("[data-id]").data("id");
|
var post_id = $(event.target).parents("[data-id]").data("id");
|
||||||
|
|
||||||
$.get("/posts/" + post_id, { variant: "tooltip" }).then(function (html) {
|
$.get("/posts/" + post_id, { variant: "tooltip" }).then(function (html) {
|
||||||
@@ -8,26 +10,26 @@ Danbooru.PostTooltip.render_tooltip = function (event, qtip) {
|
|||||||
qtip.elements.tooltip.removeClass("post-tooltip-loading");
|
qtip.elements.tooltip.removeClass("post-tooltip-loading");
|
||||||
|
|
||||||
// Hide the tooltip if the user stopped hovering before the ajax request completed.
|
// Hide the tooltip if the user stopped hovering before the ajax request completed.
|
||||||
if (Danbooru.PostTooltip.lostFocus) {
|
if (PostTooltip.lostFocus) {
|
||||||
qtip.hide();
|
qtip.hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hide the tooltip the first time it is shown, while we wait on the ajax call to complete.
|
// Hide the tooltip the first time it is shown, while we wait on the ajax call to complete.
|
||||||
Danbooru.PostTooltip.on_show = function (event, qtip) {
|
PostTooltip.on_show = function (event, qtip) {
|
||||||
if (!qtip.cache.hasBeenShown) {
|
if (!qtip.cache.hasBeenShown) {
|
||||||
qtip.elements.tooltip.addClass("post-tooltip-loading");
|
qtip.elements.tooltip.addClass("post-tooltip-loading");
|
||||||
qtip.cache.hasBeenShown = true;
|
qtip.cache.hasBeenShown = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Danbooru.PostTooltip.POST_SELECTOR = "*:not(.ui-sortable-handle) > .post-preview img";
|
PostTooltip.POST_SELECTOR = "*:not(.ui-sortable-handle) > .post-preview img";
|
||||||
|
|
||||||
// http://qtip2.com/options
|
// http://qtip2.com/options
|
||||||
Danbooru.PostTooltip.QTIP_OPTIONS = {
|
PostTooltip.QTIP_OPTIONS = {
|
||||||
style: "qtip-light post-tooltip",
|
style: "qtip-light post-tooltip",
|
||||||
content: Danbooru.PostTooltip.render_tooltip,
|
content: PostTooltip.render_tooltip,
|
||||||
overwrite: false,
|
overwrite: false,
|
||||||
position: {
|
position: {
|
||||||
viewport: true,
|
viewport: true,
|
||||||
@@ -64,38 +66,38 @@ Danbooru.PostTooltip.QTIP_OPTIONS = {
|
|||||||
event: "unfocus click mouseleave",
|
event: "unfocus click mouseleave",
|
||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
show: Danbooru.PostTooltip.on_show,
|
show: PostTooltip.on_show,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Danbooru.PostTooltip.initialize = function () {
|
PostTooltip.initialize = function () {
|
||||||
$(document).on("mouseenter", Danbooru.PostTooltip.POST_SELECTOR, function (event) {
|
$(document).on("mouseenter", PostTooltip.POST_SELECTOR, function (event) {
|
||||||
if (Danbooru.PostTooltip.disabled()) {
|
if (PostTooltip.disabled()) {
|
||||||
$(this).qtip("disable");
|
$(this).qtip("disable");
|
||||||
} else {
|
} else {
|
||||||
$(this).qtip(Danbooru.PostTooltip.QTIP_OPTIONS, event);
|
$(this).qtip(PostTooltip.QTIP_OPTIONS, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.PostTooltip.lostFocus = false;
|
PostTooltip.lostFocus = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on("mouseleave", Danbooru.PostTooltip.POST_SELECTOR, function (event) {
|
$(document).on("mouseleave", PostTooltip.POST_SELECTOR, function (event) {
|
||||||
Danbooru.PostTooltip.lostFocus = true;
|
PostTooltip.lostFocus = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on("click", ".post-tooltip-disable", Danbooru.PostTooltip.on_disable_tooltips);
|
$(document).on("click", ".post-tooltip-disable", PostTooltip.on_disable_tooltips);
|
||||||
|
|
||||||
// Hide tooltips when pressing keys or clicking thumbnails.
|
// Hide tooltips when pressing keys or clicking thumbnails.
|
||||||
$(document).on("keydown", Danbooru.PostTooltip.hide);
|
$(document).on("keydown", PostTooltip.hide);
|
||||||
$(document).on("click", Danbooru.PostTooltip.POST_SELECTOR, Danbooru.PostTooltip.hide);
|
$(document).on("click", PostTooltip.POST_SELECTOR, PostTooltip.hide);
|
||||||
|
|
||||||
// Disable tooltips on touch devices. https://developer.mozilla.org/en-US/docs/Web/API/Touch_events/Supporting_both_TouchEvent_and_MouseEvent
|
// Disable tooltips on touch devices. https://developer.mozilla.org/en-US/docs/Web/API/Touch_events/Supporting_both_TouchEvent_and_MouseEvent
|
||||||
Danbooru.PostTooltip.isTouching = false;
|
PostTooltip.isTouching = false;
|
||||||
$(document).on("touchstart", function (event) { Danbooru.PostTooltip.isTouching = true; });
|
$(document).on("touchstart", function (event) { PostTooltip.isTouching = true; });
|
||||||
$(document).on("touchend", function (event) { Danbooru.PostTooltip.isTouching = false; });
|
$(document).on("touchend", function (event) { PostTooltip.isTouching = false; });
|
||||||
};
|
};
|
||||||
|
|
||||||
Danbooru.PostTooltip.hide = function (event) {
|
PostTooltip.hide = function (event) {
|
||||||
// Hide on any key except control (user may be control-clicking link inside tooltip).
|
// Hide on any key except control (user may be control-clicking link inside tooltip).
|
||||||
if (event.type === "keydown" && event.ctrlKey === true) {
|
if (event.type === "keydown" && event.ctrlKey === true) {
|
||||||
return;
|
return;
|
||||||
@@ -104,26 +106,28 @@ Danbooru.PostTooltip.hide = function (event) {
|
|||||||
$(".post-tooltip:visible").qtip("hide");
|
$(".post-tooltip:visible").qtip("hide");
|
||||||
};
|
};
|
||||||
|
|
||||||
Danbooru.PostTooltip.disabled = function (event) {
|
PostTooltip.disabled = function (event) {
|
||||||
return Danbooru.PostTooltip.isTouching || Danbooru.meta("disable-post-tooltips") === "true";
|
return PostTooltip.isTouching || Utility.meta("disable-post-tooltips") === "true";
|
||||||
};
|
};
|
||||||
|
|
||||||
Danbooru.PostTooltip.on_disable_tooltips = function (event) {
|
PostTooltip.on_disable_tooltips = function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
$(event.target).parents(".qtip").qtip("hide");
|
$(event.target).parents(".qtip").qtip("hide");
|
||||||
|
|
||||||
if (Danbooru.meta("current-user-id") === "") {
|
if (Utility.meta("current-user-id") === "") {
|
||||||
Danbooru.notice('<a href="/session/new">Login</a> to disable tooltips permanently');
|
$(window).trigger("danbooru:notice", '<a href="/session/new">Login</a> to disable tooltips permanently');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajax("/users/" + Danbooru.meta("current-user-id") + ".json", {
|
$.ajax("/users/" + Utility.meta("current-user-id") + ".json", {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
data: { "user[disable_post_tooltips]": "true" },
|
data: { "user[disable_post_tooltips]": "true" },
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
Danbooru.notice("Tooltips disabled; check your account settings to re-enable.");
|
$(window).trigger("danbooru:notice", "Tooltips disabled; check your account settings to re-enable.");
|
||||||
location.reload();
|
location.reload();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document).ready(Danbooru.PostTooltip.initialize);
|
$(document).ready(PostTooltip.initialize);
|
||||||
|
|
||||||
|
export default PostTooltip
|
||||||
723
app/javascript/src/javascripts/posts.js.erb
Normal file
723
app/javascript/src/javascripts/posts.js.erb
Normal file
@@ -0,0 +1,723 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
import Hammer from 'hammerjs'
|
||||||
|
import RelatedTag from './related_tag.js.erb'
|
||||||
|
import Cookie from './cookie'
|
||||||
|
import Note from './notes'
|
||||||
|
import SavedSearch from './saved_searches'
|
||||||
|
|
||||||
|
let Post = {};
|
||||||
|
|
||||||
|
Post.pending_update_count = 0;
|
||||||
|
|
||||||
|
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 ((Utility.meta("always-resize-images") === "true") || (Utility.meta("viewport") && (window.screen.width <= 660))) {
|
||||||
|
$("#image-resize-to-window-link").click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($("#image").length) {
|
||||||
|
this.initialize_edit_dialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
$(window).on('danbooru:initialize_saved_seraches', () => {
|
||||||
|
Post.initialize_saved_searches();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.initialize_gestures = function() {
|
||||||
|
if (Utility.meta("disable-mobile-gestures") === "true") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var $body = $("body");
|
||||||
|
if ($body.data("hammer")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!Utility.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;
|
||||||
|
|
||||||
|
var hammer = new Hammer($body[0], {touchAction: 'pan-y', recognizers: [[Hammer.Swipe, { threshold: 20, velocity: 0.4, direction: Hammer.DIRECTION_HORIZONTAL }]], inputClass: Hammer.TouchInput});
|
||||||
|
$body.data("hammer", hammer);
|
||||||
|
|
||||||
|
if (hasPrev) {
|
||||||
|
hammer.on("swiperight", function(e) {
|
||||||
|
$("body").css({"transition-timing-function": "ease", "transition-duration": "0.2s", "opacity": "0", "transform": "translateX(150%)"});
|
||||||
|
$.timeout(200).done(function() {Post.swipe_prev(e)});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasNext) {
|
||||||
|
hammer.on("swipeleft", function(e) {
|
||||||
|
$("body").css({"transition-timing-function": "ease", "transition-duration": "0.2s", "opacity": "0", "transform": "translateX(-150%)"});
|
||||||
|
$.timeout(200).done(function() {Post.swipe_next(e)});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.initialize_edit_dialog = function(e) {
|
||||||
|
$("#open-edit-dialog").button().show().click(function(e) {
|
||||||
|
$(window).scrollTop($("#image").offset().top);
|
||||||
|
Post.open_edit_dialog();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#toggle-related-tags-link").click(function(e) {
|
||||||
|
RelatedTag.toggle();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = $("<div/>").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 (Utility.meta("enable-auto-complete") === "true") {
|
||||||
|
$tag_string.data("uiAutocomplete").close();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
close: Post.close_edit_dialog
|
||||||
|
});
|
||||||
|
dialog.dialog("widget").draggable("option", "containment", "none");
|
||||||
|
|
||||||
|
var pin_button = $("<button/>").button({icons: {primary: "ui-icon-pin-w"}, label: "pin", text: false});
|
||||||
|
pin_button.css({width: "20px", height: "20px", position: "absolute", right: "28.4px"});
|
||||||
|
dialog.parent().children(".ui-dialog-titlebar").append(pin_button);
|
||||||
|
pin_button.click(function(e) {
|
||||||
|
var dialog_widget = $('.ui-dialog:has(#edit-dialog)');
|
||||||
|
var pos = dialog_widget.offset();
|
||||||
|
|
||||||
|
if (dialog_widget.css("position") === "absolute") {
|
||||||
|
pos.left -= $(window).scrollLeft();
|
||||||
|
pos.top -= $(window).scrollTop();
|
||||||
|
dialog_widget.offset(pos).css({position:"fixed"});
|
||||||
|
dialog.dialog("option", "resize", function() { dialog_widget.css({position:"fixed"}); });
|
||||||
|
|
||||||
|
pin_button.button("option", "icons", {primary: "ui-icon-pin-s"});
|
||||||
|
} else {
|
||||||
|
pos.left += $(window).scrollLeft();
|
||||||
|
pos.top += $(window).scrollTop();
|
||||||
|
dialog_widget.offset(pos).css({position:"absolute"});
|
||||||
|
dialog.dialog("option", "resize", function() {});
|
||||||
|
|
||||||
|
pin_button.button("option", "icons", {primary: "ui-icon-pin-w"});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.parent().mouseout(function(e) {
|
||||||
|
dialog.parent().css({"opacity": 0.6, "transition": "opacity .2s ease"});
|
||||||
|
})
|
||||||
|
.mouseover(function(e) {
|
||||||
|
dialog.parent().css({"opacity": 1});
|
||||||
|
});
|
||||||
|
|
||||||
|
$tag_string.css({"resize": "none", "width": "100%"});
|
||||||
|
$tag_string.focus().selectEnd().height($tag_string[0].scrollHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.close_edit_dialog = function(e, ui) {
|
||||||
|
$("#form").appendTo($("#c-posts #edit,#c-uploads #a-new"));
|
||||||
|
$("#edit-dialog").remove();
|
||||||
|
RelatedTag.show();
|
||||||
|
$("#toggle-related-tags-link").hide();
|
||||||
|
var $tag_string = $("#post_tag_string,#upload_tag_string");
|
||||||
|
$("div.input").has($tag_string).prevAll().show();
|
||||||
|
$("#open-edit-dialog").show();
|
||||||
|
$tag_string.css({"resize": "", "width": ""});
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.initialize_similar = function() {
|
||||||
|
$("#similar-button").click(function(e) {
|
||||||
|
$.get("/iqdb_queries", {"url": $("#post_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.swipe_prev = function(e) {
|
||||||
|
if ($("#a-show").length) {
|
||||||
|
window.history.back();
|
||||||
|
} if ($(".paginator a[rel~=prev]").length) {
|
||||||
|
location.href = $("a[rel~=prev]").attr("href");
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.nav_prev = function(e) {
|
||||||
|
if ($("#search-seq-nav").length) {
|
||||||
|
var href = $("#search-seq-nav a[rel~=prev]").attr("href");
|
||||||
|
if (href) {
|
||||||
|
location.href = href;
|
||||||
|
}
|
||||||
|
} else if ($(".paginator a[rel~=prev]").length) {
|
||||||
|
location.href = $("a[rel~=prev]").attr("href");
|
||||||
|
} else {
|
||||||
|
var href = $("#pool-nav a.active[rel~=prev], #favgroup-nav a.active[rel~=prev]").attr("href");
|
||||||
|
if (href) {
|
||||||
|
location.href = href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.nav_next = function(e) {
|
||||||
|
if ($("#search-seq-nav").length) {
|
||||||
|
var href = $("#search-seq-nav a[rel~=next]").attr("href");
|
||||||
|
location.href = href;
|
||||||
|
} else if ($(".paginator a[rel~=next]").length) {
|
||||||
|
location.href = $(".paginator a[rel~=next]").attr("href");
|
||||||
|
} else {
|
||||||
|
var href = $("#pool-nav a.active[rel~=next], #favgroup-nav a.active[rel~=next]").attr("href");
|
||||||
|
if (href) {
|
||||||
|
location.href = href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.swipe_next = function(e) {
|
||||||
|
if ($(".paginator a[rel~=next ]").length) {
|
||||||
|
location.href = $(".paginator a[rel~=next]").attr("href");
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.initialize_shortcuts = function() {
|
||||||
|
if ($("#a-show").length) {
|
||||||
|
Utility.keydown("e", "edit", function(e) {
|
||||||
|
$("#post-edit-link").trigger("click");
|
||||||
|
$("#post_tag_string").focus();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (Utility.meta("current-user-can-approve-posts") === "true") {
|
||||||
|
Utility.keydown("shift+o", "approve", function(e) {
|
||||||
|
$(".approve-link").click();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility.keydown("a", "prev_page", Post.nav_prev);
|
||||||
|
Utility.keydown("d", "next_page", Post.nav_next);
|
||||||
|
Utility.keydown("f", "favorite", Post.favorite);
|
||||||
|
Utility.keydown("shift+f", "unfavorite", Post.unfavorite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.initialize_links = function() {
|
||||||
|
$("#copy-notes").click(function(e) {
|
||||||
|
var current_post_id = $("meta[name=post-id]").attr("content");
|
||||||
|
var other_post_id = parseInt(prompt("Enter the ID of the post to copy all notes to:"), 10);
|
||||||
|
|
||||||
|
if (other_post_id !== null) {
|
||||||
|
$.ajax("/posts/" + current_post_id + "/copy_notes", {
|
||||||
|
type: "PUT",
|
||||||
|
data: {
|
||||||
|
other_post_id: other_post_id
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
$(window).trigger("danbooru:notice", "Successfully copied notes to <a href='" + other_post_id + "'>post #" + other_post_id + "</a>");
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
if (data.status === 404) {
|
||||||
|
$(window).trigger("danbooru:error", "Error: Invalid destination post");
|
||||||
|
} else if (data.responseJSON && data.responseJSON.reason) {
|
||||||
|
$(window).trigger("danbooru:error", "Error: " + data.responseJSON.reason);
|
||||||
|
} else {
|
||||||
|
$(window).trigger("danbooru:error", "There was an error copying notes to <a href='" + other_post_id + "'>post #" + other_post_id + "</a>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".unvote-post-link").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.initialize_post_relationship_previews = function() {
|
||||||
|
var current_post_id = $("meta[name=post-id]").attr("content");
|
||||||
|
$("[id=post_" + current_post_id + "]").addClass("current-post");
|
||||||
|
|
||||||
|
if (Cookie.get("show-relationship-previews") === "0") {
|
||||||
|
this.toggle_relationship_preview($("#has-children-relationship-preview"), $("#has-children-relationship-preview-link"));
|
||||||
|
this.toggle_relationship_preview($("#has-parent-relationship-preview"), $("#has-parent-relationship-preview-link"));
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#has-children-relationship-preview-link").click(function(e) {
|
||||||
|
Post.toggle_relationship_preview($("#has-children-relationship-preview"), $(this));
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#has-parent-relationship-preview-link").click(function(e) {
|
||||||
|
Post.toggle_relationship_preview($("#has-parent-relationship-preview"), $(this));
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.toggle_relationship_preview = function(preview, preview_link) {
|
||||||
|
preview.toggle();
|
||||||
|
if (preview.is(":visible")) {
|
||||||
|
preview_link.html("« hide");
|
||||||
|
Cookie.put("show-relationship-previews", "1");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
preview_link.html("show »");
|
||||||
|
Cookie.put("show-relationship-previews", "0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.initialize_favlist = function() {
|
||||||
|
$("#favlist").hide();
|
||||||
|
$("#hide-favlist-link").hide();
|
||||||
|
var fav_count = $("#show-favlist-link").prev().text();
|
||||||
|
if (fav_count === "0") {
|
||||||
|
$("#show-favlist-link").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#show-favlist-link").click(function(e) {
|
||||||
|
$("#favlist").show();
|
||||||
|
$(this).hide();
|
||||||
|
$("#hide-favlist-link").show();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#hide-favlist-link").click(function(e) {
|
||||||
|
$("#favlist").hide();
|
||||||
|
$(this).hide();
|
||||||
|
$("#show-favlist-link").show();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.expand_image = function(e) {
|
||||||
|
if (Utility.test_max_width(660)) {
|
||||||
|
// just do the default behavior
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var $link = $(e.target);
|
||||||
|
var $image = $("#image");
|
||||||
|
var $notice = $("#image-resize-notice");
|
||||||
|
$image.attr("src", $link.attr("href"));
|
||||||
|
$image.css("opacity", "0.25");
|
||||||
|
$image.width($image.data("original-width"));
|
||||||
|
$image.height($image.data("original-height"));
|
||||||
|
$image.on("load", function() {
|
||||||
|
$image.css("opacity", "1");
|
||||||
|
$notice.hide();
|
||||||
|
});
|
||||||
|
$notice.children().eq(0).hide();
|
||||||
|
$notice.children().eq(1).show(); // Loading message
|
||||||
|
Note.Box.scale_all();
|
||||||
|
$image.data("scale-factor", 1);
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.initialize_post_image_resize_links = function() {
|
||||||
|
$("#image-resize-link").click(Post.expand_image);
|
||||||
|
|
||||||
|
if ($("#image-resize-notice").length) {
|
||||||
|
Utility.keydown("v", "resize", function(e) {
|
||||||
|
if ($("#image-resize-notice").is(":visible")) {
|
||||||
|
$("#image-resize-link").click();
|
||||||
|
} else {
|
||||||
|
var $image = $("#image");
|
||||||
|
var $notice = $("#image-resize-notice");
|
||||||
|
$image.attr("src", $("#image-container").data("large-file-url"));
|
||||||
|
$image.css("opacity", "0.25");
|
||||||
|
$image.width($image.data("large-width"));
|
||||||
|
$image.height($image.data("large-height"));
|
||||||
|
$notice.children().eq(0).show();
|
||||||
|
$notice.children().eq(1).hide(); // Loading message
|
||||||
|
$image.on("load", function() {
|
||||||
|
$image.css("opacity", "1");
|
||||||
|
$notice.show();
|
||||||
|
});
|
||||||
|
Note.Box.scale_all();
|
||||||
|
$image.data("scale-factor", 1);
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.resize_image_to_window = function($img) {
|
||||||
|
if (($img.data("scale-factor") === 1) || ($img.data("scale-factor") === undefined)) {
|
||||||
|
if ($(window).width() > 660) {
|
||||||
|
var sidebar_width = $("#sidebar").width() || 0;
|
||||||
|
var client_width = $(window).width() - sidebar_width - 75;
|
||||||
|
} else {
|
||||||
|
var client_width = $(window).width() - 2;
|
||||||
|
}
|
||||||
|
var client_height = $(window).height();
|
||||||
|
|
||||||
|
if ($img.width() > client_width) {
|
||||||
|
var ratio = client_width / $img.data("original-width");
|
||||||
|
$img.data("scale-factor", ratio);
|
||||||
|
$img.css("width", $img.data("original-width") * ratio);
|
||||||
|
$img.css("height", $img.data("original-height") * ratio);
|
||||||
|
Post.resize_ugoira_controls();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$img.data("scale-factor", 1);
|
||||||
|
$img.width($img.data("original-width"));
|
||||||
|
$img.height($img.data("original-height"));
|
||||||
|
Post.resize_ugoira_controls();
|
||||||
|
}
|
||||||
|
|
||||||
|
Note.Box.scale_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.initialize_post_image_resize_to_window_link = function() {
|
||||||
|
$("#image-resize-to-window-link").click(function(e) {
|
||||||
|
Post.resize_image_to_window($("#image"));
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.initialize_excerpt = function() {
|
||||||
|
$("#excerpt").hide();
|
||||||
|
|
||||||
|
$("#show-posts-link").click(function(e) {
|
||||||
|
$("#show-posts-link").parent("li").addClass("active");
|
||||||
|
$("#show-excerpt-link").parent("li").removeClass("active");
|
||||||
|
$("#posts").show();
|
||||||
|
$("#excerpt").hide();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#show-excerpt-link").click(function(e) {
|
||||||
|
if ($(this).parent("li").hasClass("active")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$("#show-posts-link").parent("li").removeClass("active");
|
||||||
|
$("#show-excerpt-link").parent("li").addClass("active");
|
||||||
|
$("#posts").hide();
|
||||||
|
$("#excerpt").show();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!$(".post-preview").length && /Nobody here but us chickens/.test($("#posts").html())) {
|
||||||
|
$("#show-excerpt-link").click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.initialize_post_sections = function() {
|
||||||
|
$("#post-sections li a").click(function(e) {
|
||||||
|
if (e.target.hash === "#comments") {
|
||||||
|
$("#comments").show();
|
||||||
|
$("#edit").hide();
|
||||||
|
$("#share").hide();
|
||||||
|
$("#recommended").hide();
|
||||||
|
} else if (e.target.hash === "#edit") {
|
||||||
|
$("#edit").show();
|
||||||
|
$("#comments").hide();
|
||||||
|
$("#share").hide();
|
||||||
|
$("#post_tag_string").focus().selectEnd().height($("#post_tag_string")[0].scrollHeight);
|
||||||
|
$("#related-tags-button").trigger("click");
|
||||||
|
$("#find-artist-button").trigger("click");
|
||||||
|
$("#recommended").hide();
|
||||||
|
} else if (e.target.hash === "#recommended") {
|
||||||
|
$("#comments").hide();
|
||||||
|
$("#edit").hide();
|
||||||
|
$("#share").hide();
|
||||||
|
$("#recommended").show();
|
||||||
|
$.get("/recommended_posts", {context: "post", post_id: Utility.meta("post-id")}, function(data) {
|
||||||
|
$("#recommended").html(data);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$("#edit").hide();
|
||||||
|
$("#comments").hide();
|
||||||
|
$("#share").show();
|
||||||
|
addthis.init();
|
||||||
|
$("#recommended").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#post-sections li").removeClass("active");
|
||||||
|
$(e.target).parent("li").addClass("active");
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#notes").hide();
|
||||||
|
$("#edit").hide();
|
||||||
|
$("#recommended").hide();
|
||||||
|
$("#post-sections li:first-child").addClass("active");
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.initialize_post_sections = function() {
|
||||||
|
$("#post-sections li a").click(function(e) {
|
||||||
|
if (e.target.hash === "#comments") {
|
||||||
|
$("#comments").show();
|
||||||
|
$("#edit").hide();
|
||||||
|
$("#share").hide();
|
||||||
|
} else if (e.target.hash === "#edit") {
|
||||||
|
$("#edit").show();
|
||||||
|
$("#comments").hide();
|
||||||
|
$("#share").hide();
|
||||||
|
$("#post_tag_string").focus().selectEnd().height($("#post_tag_string")[0].scrollHeight);
|
||||||
|
$("#related-tags-button").trigger("click");
|
||||||
|
$("#find-artist-button").trigger("click");
|
||||||
|
} else {
|
||||||
|
$("#edit").hide();
|
||||||
|
$("#comments").hide();
|
||||||
|
$("#share").show();
|
||||||
|
addthis.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#post-sections li").removeClass("active");
|
||||||
|
$(e.target).parent("li").addClass("active");
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#post-sections li:first-child").addClass("active");
|
||||||
|
$("#notes").hide();
|
||||||
|
$("#edit").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.resize_ugoira_controls = function() {
|
||||||
|
var $img = $("#image");
|
||||||
|
var width = Math.max($img.width(), 350);
|
||||||
|
$("#ugoira-control-panel").css("width", width);
|
||||||
|
$("#seek-slider").css("width", width - 81);
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.notice_update = function(x) {
|
||||||
|
if (x === "inc") {
|
||||||
|
Post.pending_update_count += 1;
|
||||||
|
$(window).trigger("danbooru:notice", "Updating posts (" + Post.pending_update_count + " pending)...", true);
|
||||||
|
} else {
|
||||||
|
Post.pending_update_count -= 1;
|
||||||
|
|
||||||
|
if (Post.pending_update_count < 1) {
|
||||||
|
$(window).trigger("danbooru:notice", "Posts updated");
|
||||||
|
} else {
|
||||||
|
$(window).trigger("danbooru:notice", "Updating posts (" + Post.pending_update_count + " pending)...", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.update_data = function(data) {
|
||||||
|
var $post = $("#post_" + data.id);
|
||||||
|
$post.attr("data-tags", data.tag_string);
|
||||||
|
$post.data("rating", data.rating);
|
||||||
|
$post.removeClass("post-status-has-parent post-status-has-children");
|
||||||
|
if (data.parent_id) {
|
||||||
|
$post.addClass("post-status-has-parent");
|
||||||
|
}
|
||||||
|
if (data.has_visible_children) {
|
||||||
|
$post.addClass("post-status-has-children");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.vote = function(score, id) {
|
||||||
|
$(window).trigger("danbooru:notice", "Voting...");
|
||||||
|
|
||||||
|
$.post("/posts/" + id + "/votes.js", {
|
||||||
|
score: score
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.update = function(post_id, params) {
|
||||||
|
Post.notice_update("inc");
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "PUT",
|
||||||
|
url: "/posts/" + post_id + ".json",
|
||||||
|
data: params,
|
||||||
|
success: function(data) {
|
||||||
|
Post.notice_update("dec");
|
||||||
|
Post.update_data(data);
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
Post.notice_update("dec");
|
||||||
|
$(window).trigger("danbooru:error", 'There was an error updating <a href="/posts/' + post_id + '">post #' + post_id + '</a>');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.ban = function(post_id) {
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "/moderator/post/posts/" + post_id + "/ban.js",
|
||||||
|
data: {
|
||||||
|
commit: "Ban"
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
$("#post_" + post_id).remove();
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
$(window).trigger("danbooru:error", 'There was an error updating <a href="/posts/' + post_id + '">post #' + post_id + '</a>');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.approve = function(post_id) {
|
||||||
|
$.post(
|
||||||
|
"/moderator/post/approval.json",
|
||||||
|
{"post_id": post_id}
|
||||||
|
).fail(function(data) {
|
||||||
|
var message = $.map(data.responseJSON.errors, function(msg, attr) { return msg; }).join("; ");
|
||||||
|
$(window).trigger("danbooru:error", "Error: " + message);
|
||||||
|
}).done(function(data) {
|
||||||
|
var $post = $("#post_" + post_id);
|
||||||
|
if ($post.length) {
|
||||||
|
$post.data("flags", $post.data("flags").replace(/pending/, ""));
|
||||||
|
$post.removeClass("post-status-pending");
|
||||||
|
$(window).trigger("danbooru:notice", "Approved post #" + post_id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.favorite = function (e) {
|
||||||
|
if ($("#add-to-favorites").is(":visible")) {
|
||||||
|
$("#add-to-favorites")[0].click();
|
||||||
|
} else {
|
||||||
|
if (Utility.meta("current-user-id") == "") {
|
||||||
|
$(window).trigger("danbooru:notice", "You must be logged in to favorite posts");
|
||||||
|
} else {
|
||||||
|
$(window).trigger("danbooru:notice", "You have already favorited this post");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Post.unfavorite = function (e) {
|
||||||
|
$.ajax("/favorites/" + Utility.meta("post-id") + ".js", {
|
||||||
|
type: "DELETE"
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Post.initialize_saved_searches = function() {
|
||||||
|
$("#new_saved_search #saved_search_label_string").autocomplete({
|
||||||
|
search: function() {
|
||||||
|
$(this).data("ui-autocomplete").menu.bindings = $();
|
||||||
|
},
|
||||||
|
source: function(req, resp) {
|
||||||
|
SavedSearch.labels(req.term).then(function(labels) {
|
||||||
|
resp(labels.map(function(label) {
|
||||||
|
return {
|
||||||
|
label: label.replace(/_/g, " "),
|
||||||
|
value: label
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#save-search-dialog").dialog({
|
||||||
|
width: 500,
|
||||||
|
modal: true,
|
||||||
|
autoOpen: false,
|
||||||
|
buttons: {
|
||||||
|
"Submit": function() {
|
||||||
|
$("#save-search-dialog form").submit();
|
||||||
|
$(this).dialog("close");
|
||||||
|
},
|
||||||
|
"Cancel": function() {
|
||||||
|
$(this).dialog("close");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#save-search").click(function(e) {
|
||||||
|
$("#save-search-dialog #saved_search_query").val($("#tags").val());
|
||||||
|
|
||||||
|
if (Utility.meta("disable-labeled-saved-searches") === "false") {
|
||||||
|
$("#save-search-dialog").dialog("open");
|
||||||
|
} else {
|
||||||
|
$.post(
|
||||||
|
"/saved_searches.js",
|
||||||
|
{
|
||||||
|
"saved_search": {
|
||||||
|
"query": $("#tags").val()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#search-dropdown #wiki-search").click(function(e) {
|
||||||
|
window.location.href = "/wiki_pages?search%5Btitle%5D=" + encodeURIComponent($("#tags").val());
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#search-dropdown #artist-search").click(function(e) {
|
||||||
|
window.location.href = "/artists?search%5Bname%5D=" + encodeURIComponent($("#tags").val());
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Post.initialize_replace_image_dialog = function() {
|
||||||
|
$("#replace-image-dialog").dialog({
|
||||||
|
autoOpen: false,
|
||||||
|
width: 700,
|
||||||
|
modal: true,
|
||||||
|
buttons: {
|
||||||
|
"Submit": function() {
|
||||||
|
$("#replace-image-dialog form").submit();
|
||||||
|
$(this).dialog("close");
|
||||||
|
},
|
||||||
|
"Cancel": function() {
|
||||||
|
$(this).dialog("close");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#replace-image-dialog form').submit(function() {
|
||||||
|
$('#replace-image-dialog').dialog('close');
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#replace-image").click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
$("#replace-image-dialog").dialog("open");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
Post.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Post
|
||||||
354
app/javascript/src/javascripts/related_tag.js.erb
Normal file
354
app/javascript/src/javascripts/related_tag.js.erb
Normal file
@@ -0,0 +1,354 @@
|
|||||||
|
import './cookie'
|
||||||
|
import './utility'
|
||||||
|
|
||||||
|
let RelatedTag = {};
|
||||||
|
|
||||||
|
RelatedTag.initialize_all = function() {
|
||||||
|
if ($("#c-posts #a-show").length || $("#c-uploads #a-new").length) {
|
||||||
|
this.initialize_buttons();
|
||||||
|
$("#artist-tags-container").hide();
|
||||||
|
$("#upload_tag_string,#post_tag_string").keyup(RelatedTag.update_selected);
|
||||||
|
$("body").on("click", "#artist-related-tags-column a.del", RelatedTag.disable_artist_url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.initialize_buttons = function() {
|
||||||
|
this.common_bind("#related-tags-button", "");
|
||||||
|
<% TagCategory.related_button_list.each do |category| %>
|
||||||
|
RelatedTag.common_bind("#related-<%= category %>-button", "<%= category %>");
|
||||||
|
<% end %>
|
||||||
|
$("#find-artist-button").click(RelatedTag.find_artist);
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.tags_include = function(name) {
|
||||||
|
var current = $("#upload_tag_string,#post_tag_string").val().toLowerCase().match(/\S+/g) || [];
|
||||||
|
if ($.inArray(name.toLowerCase(), current) > -1) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.common_bind = function(button_name, category) {
|
||||||
|
$(button_name).click(function(e) {
|
||||||
|
var $dest = $("#related-tags");
|
||||||
|
$dest.empty();
|
||||||
|
RelatedTag.build_recent_and_frequent($dest);
|
||||||
|
$dest.append("<em>Loading...</em>");
|
||||||
|
$.get("/related_tag.json", {
|
||||||
|
"query": RelatedTag.current_tag(),
|
||||||
|
"category": category
|
||||||
|
}, RelatedTag.process_response);
|
||||||
|
$("#artist-tags-container").hide();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.current_tag = function() {
|
||||||
|
// 1. abc def | -> def
|
||||||
|
// 2. abc def| -> def
|
||||||
|
// 3. abc de|f -> def
|
||||||
|
// 4. abc |def -> def
|
||||||
|
// 5. abc| def -> abc
|
||||||
|
// 6. ab|c def -> abc
|
||||||
|
// 7. |abc def -> abc
|
||||||
|
// 8. | abc def -> abc
|
||||||
|
|
||||||
|
var $field = $("#upload_tag_string,#post_tag_string");
|
||||||
|
var string = $field.val();
|
||||||
|
var n = string.length;
|
||||||
|
var a = $field.prop('selectionStart');
|
||||||
|
var b = $field.prop('selectionStart');
|
||||||
|
|
||||||
|
if ((a > 0) && (a < (n - 1)) && (!/\s/.test(string[a])) && (/\s/.test(string[a - 1]))) {
|
||||||
|
// 4 is the only case where we need to scan forward. in all other cases we
|
||||||
|
// can drag a backwards, and then drag b forwards.
|
||||||
|
|
||||||
|
while ((b < n) && (!/\s/.test(string[b]))) {
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
} else if (string.search(/\S/) > b) { // case 8
|
||||||
|
b = string.search(/\S/);
|
||||||
|
while ((b < n) && (!/\s/.test(string[b]))) {
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while ((a > 0) && ((/\s/.test(string[a])) || (string[a] === undefined))) {
|
||||||
|
a--;
|
||||||
|
b--;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((a > 0) && (!/\s/.test(string[a - 1]))) {
|
||||||
|
a--;
|
||||||
|
b--;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((b < (n - 1)) && (!/\s/.test(string[b]))) {
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b++;
|
||||||
|
return string.slice(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.process_response = function(data) {
|
||||||
|
RelatedTag.recent_search = data;
|
||||||
|
RelatedTag.build_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.update_selected = function(e) {
|
||||||
|
var current_tags = $("#upload_tag_string,#post_tag_string").val().toLowerCase().match(/\S+/g) || [];
|
||||||
|
var $all_tags = $("#related-tags a");
|
||||||
|
$all_tags.removeClass("selected");
|
||||||
|
|
||||||
|
$all_tags.each(function(i, tag) {
|
||||||
|
if (current_tags.indexOf(tag.textContent.replace(/ /g, "_")) > -1) {
|
||||||
|
$(tag).addClass("selected");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.build_all = function() {
|
||||||
|
if (RelatedTag.recent_search === null || RelatedTag.recent_search === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.show();
|
||||||
|
|
||||||
|
var query = RelatedTag.recent_search.query;
|
||||||
|
var related_tags = RelatedTag.recent_search.tags;
|
||||||
|
var wiki_page_tags = RelatedTag.recent_search.wiki_page_tags;
|
||||||
|
var other_wikis = RelatedTag.recent_search.other_wikis;
|
||||||
|
var $dest = $("#related-tags");
|
||||||
|
$dest.empty();
|
||||||
|
|
||||||
|
this.build_recent_and_frequent($dest);
|
||||||
|
|
||||||
|
$dest.append(this.build_html(query, related_tags, "general"));
|
||||||
|
this.build_translated($dest);
|
||||||
|
if (wiki_page_tags.length) {
|
||||||
|
$dest.append(RelatedTag.build_html("wiki:" + query, wiki_page_tags, "wiki"));
|
||||||
|
}
|
||||||
|
$.each(other_wikis, function(i,wiki) {
|
||||||
|
$dest.append(RelatedTag.build_html("wiki:" + wiki.title, wiki.wiki_page_tags, "otherwiki" + i.toString()));
|
||||||
|
});
|
||||||
|
if (RelatedTag.recent_artists) {
|
||||||
|
var tags = [];
|
||||||
|
if (RelatedTag.recent_artists.length === 0) {
|
||||||
|
tags.push([" none", 0]);
|
||||||
|
} else if (RelatedTag.recent_artists.length === 1) {
|
||||||
|
tags.push([RelatedTag.recent_artists[0].name, 1]);
|
||||||
|
if (RelatedTag.recent_artists[0].is_banned === true) {
|
||||||
|
tags.push(["BANNED_ARTIST", "banned"]);
|
||||||
|
}
|
||||||
|
$.each(RelatedTag.recent_artists[0].sorted_urls, function(i, url) {
|
||||||
|
var x = url.url;
|
||||||
|
if (!url.is_active) {
|
||||||
|
x = "-" + x;
|
||||||
|
}
|
||||||
|
tags.push([" " + x, 0]);
|
||||||
|
});
|
||||||
|
} else if (RelatedTag.recent_artists.length >= 10) {
|
||||||
|
tags.push([" none", 0]);
|
||||||
|
} else {
|
||||||
|
$.each(RelatedTag.recent_artists, function(i, artist) {
|
||||||
|
tags.push([artist.name, 1]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$dest.append(RelatedTag.build_html("artist", tags, "artist", true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.build_recent_and_frequent = function($dest) {
|
||||||
|
var recent_tags = Cookie.get("recent_tags_with_categories");
|
||||||
|
var favorite_tags = Cookie.get("favorite_tags_with_categories");
|
||||||
|
if (recent_tags.length) {
|
||||||
|
$dest.append(this.build_html("recent", this.other_tags(recent_tags), "recent"));
|
||||||
|
}
|
||||||
|
if (favorite_tags.length) {
|
||||||
|
$dest.append(this.build_html("frequent", this.other_tags(favorite_tags), "frequent"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.other_tags = function(string) {
|
||||||
|
if (string && string.length) {
|
||||||
|
return $.map(string.match(/\S+ \d+/g), function(x, i) {
|
||||||
|
var submatch = x.match(/(\S+) (\d+)/);
|
||||||
|
return [[submatch[1], submatch[2]]];
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.build_translated = function($dest) {
|
||||||
|
if (RelatedTag.translated_tags && RelatedTag.translated_tags.length) {
|
||||||
|
$dest.append(this.build_html("Translated Tags", RelatedTag.translated_tags, "translated"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.build_html = function(query, related_tags, name, is_wide_column) {
|
||||||
|
if (query === null || query === "") {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
query = query.replace(/_/g, " ");
|
||||||
|
var header = $("<em/>");
|
||||||
|
|
||||||
|
var match = query.match(/^wiki:(.+)/);
|
||||||
|
if (match) {
|
||||||
|
header.html($("<a/>").attr("href", "/wiki_pages?title=" + encodeURIComponent(match[1])).attr("target", "_blank").text(query));
|
||||||
|
} else {
|
||||||
|
header.text(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
var $div = $("<div/>");
|
||||||
|
$div.attr("id", name + "-related-tags-column");
|
||||||
|
$div.addClass("tag-column");
|
||||||
|
if (is_wide_column) {
|
||||||
|
$div.addClass("wide-column");
|
||||||
|
}
|
||||||
|
var $ul = $("<ul/>");
|
||||||
|
$ul.append(
|
||||||
|
$("<li/>").append(
|
||||||
|
header
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$.each(related_tags, function(i, tag) {
|
||||||
|
if (tag[0][0] !== " ") {
|
||||||
|
var $link = $("<a/>");
|
||||||
|
$link.text(tag[0].replace(/_/g, " "));
|
||||||
|
$link.addClass("tag-type-" + tag[1]);
|
||||||
|
$link.attr("href", "/posts?tags=" + encodeURIComponent(tag[0]));
|
||||||
|
$link.click(RelatedTag.toggle_tag);
|
||||||
|
if (RelatedTag.tags_include(tag[0])) {
|
||||||
|
$link.addClass("selected");
|
||||||
|
}
|
||||||
|
$ul.append(
|
||||||
|
$("<li/>").append($link)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
var text = tag[0];
|
||||||
|
if (text.match(/^ -http/)) {
|
||||||
|
text = text.substring(1, 1000);
|
||||||
|
var desc = text.replace(/^-https?:\/\//, "");
|
||||||
|
if (desc.length > 30) {
|
||||||
|
desc = desc.substring(0, 30) + "...";
|
||||||
|
}
|
||||||
|
$ul.append(
|
||||||
|
$("<li>").append(
|
||||||
|
$("<del>").text(desc)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if (text.match(/^ http/)) {
|
||||||
|
text = text.substring(1, 1000);
|
||||||
|
var desc = text.replace(/^https?:\/\//, "");
|
||||||
|
if (desc.length > 30) {
|
||||||
|
desc = desc.substring(0, 30) + "...";
|
||||||
|
}
|
||||||
|
$ul.append(
|
||||||
|
$("<li>").append([
|
||||||
|
$("<a>").text(desc).attr("href", text).attr("target", "_blank"),
|
||||||
|
" ",
|
||||||
|
$("<a>").attr("href", text).addClass("del").append(
|
||||||
|
$("<i>").addClass("fas fa-minus-circle")
|
||||||
|
)
|
||||||
|
])
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$ul.append($("<li/>").text(text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$div.append($ul);
|
||||||
|
return $div;
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.toggle_tag = function(e) {
|
||||||
|
var $field = $("#upload_tag_string,#post_tag_string");
|
||||||
|
var tag = $(e.target).html().replace(/ /g, "_").replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&");
|
||||||
|
|
||||||
|
if (RelatedTag.tags_include(tag)) {
|
||||||
|
var escaped_tag = Utility.regexp_escape(tag);
|
||||||
|
$field.val($field.val().replace(new RegExp("(^|\\s)" + escaped_tag + "($|\\s)", "gi"), "$1$2"));
|
||||||
|
} else {
|
||||||
|
$field.val($field.val() + " " + tag);
|
||||||
|
}
|
||||||
|
$field.val($field.val().trim().replace(/ +/g, " ") + " ");
|
||||||
|
|
||||||
|
RelatedTag.update_selected();
|
||||||
|
if (RelatedTag.recent_artist && $("#artist-tags-container").css("display") === "block") {
|
||||||
|
RelatedTag.process_artist(RelatedTag.recent_artist);
|
||||||
|
}
|
||||||
|
|
||||||
|
//The timeout is needed on Chrome since it will clobber the field attribute otherwise
|
||||||
|
setTimeout(function () { $field.prop('selectionStart', $field.val().length);}, 100);
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.find_artist = function(e) {
|
||||||
|
$("#artist-tags").html("<em>Loading...</em>");
|
||||||
|
var url = $("#upload_source,#post_source");
|
||||||
|
var referer_url = $("#upload_referer_url");
|
||||||
|
$.get("/artists/finder.json", {"url": url.val(), "referer_url": referer_url.val()}, RelatedTag.process_artist);
|
||||||
|
if (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.process_artist = function(data) {
|
||||||
|
RelatedTag.recent_artists = data;
|
||||||
|
RelatedTag.build_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.toggle = function() {
|
||||||
|
if ($("#related-tags").is(":visible")) {
|
||||||
|
RelatedTag.hide();
|
||||||
|
} else {
|
||||||
|
RelatedTag.show();
|
||||||
|
$("#related-tags-button").trigger("click");
|
||||||
|
$("#find-artist-button").trigger("click");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.show = function() {
|
||||||
|
$("#related-tags").show()
|
||||||
|
$("#toggle-related-tags-link").text("«");
|
||||||
|
$("#edit-dialog").height("auto");
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.hide = function() {
|
||||||
|
$("#related-tags").hide();
|
||||||
|
$("#toggle-related-tags-link").text("»");
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.disable_artist_url = function(e) {
|
||||||
|
var url = e.currentTarget.href;
|
||||||
|
$.each(RelatedTag.recent_artists[0].sorted_urls, function(k, v) {
|
||||||
|
if (v["normalized_url"] === url || v["url"] === url) {
|
||||||
|
if (!confirm("This will mark the URL as inactive. Continue?")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax("/artist_urls/" + v["id"], {
|
||||||
|
method: "PUT",
|
||||||
|
data: {
|
||||||
|
artist_url: {
|
||||||
|
is_active: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).done(RelatedTag.find_artist);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
RelatedTag.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default RelatedTag
|
||||||
|
|
||||||
20
app/javascript/src/javascripts/saved_searches.js
Normal file
20
app/javascript/src/javascripts/saved_searches.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
|
||||||
|
let SavedSearch = {};
|
||||||
|
|
||||||
|
SavedSearch.initialize_all = function() {
|
||||||
|
if ($("#c-saved-searches").length) {
|
||||||
|
Utility.sorttable($("#c-saved-searches table"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SavedSearch.labels = function(term) {
|
||||||
|
return $.getJSON("/saved_searches/labels", {
|
||||||
|
"search[label]": term + "*",
|
||||||
|
"limit": 10
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$(SavedSearch.initialize_all);
|
||||||
|
|
||||||
|
export default SavedSearch
|
||||||
59
app/javascript/src/javascripts/shortcuts.js
Normal file
59
app/javascript/src/javascripts/shortcuts.js
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
import Post from './posts.js.erb'
|
||||||
|
|
||||||
|
let Shortcuts = {};
|
||||||
|
|
||||||
|
Shortcuts.initialize = function() {
|
||||||
|
Utility.keydown("s", "scroll_down", Shortcuts.nav_scroll_down);
|
||||||
|
Utility.keydown("w", "scroll_up", Shortcuts.nav_scroll_up);
|
||||||
|
|
||||||
|
Utility.keydown("q", "focus_search", function(e) {
|
||||||
|
$("#tags, #search_name, #search_name_matches, #query").trigger("focus").selectEnd();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($("#image").length) { // post page or bookmarklet upload page
|
||||||
|
Utility.keydown("shift+e", "edit_dialog", function(e) {
|
||||||
|
if (Utility.meta("current-user-id") == "") { // anonymous
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$("#edit-dialog").length) {
|
||||||
|
$("#edit").show();
|
||||||
|
$("#comments").hide();
|
||||||
|
$("#share").hide();
|
||||||
|
$("#post-sections li").removeClass("active");
|
||||||
|
$("#post-edit-link").parent("li").addClass("active");
|
||||||
|
$("#related-tags-container").show();
|
||||||
|
|
||||||
|
Post.open_edit_dialog();
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($("#c-posts #a-index, #c-favorites #a-index").length) {
|
||||||
|
Utility.keydown("r", "random", function(e) {
|
||||||
|
$("#random-post")[0].click();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Shortcuts.nav_scroll_down = function() {
|
||||||
|
var scroll_top = $(window).scrollTop() + ($(window).height() * 0.15);
|
||||||
|
$(window).scrollTop(scroll_top);
|
||||||
|
}
|
||||||
|
|
||||||
|
Shortcuts.nav_scroll_up = function() {
|
||||||
|
var scroll_top = $(window).scrollTop() - ($(window).height() * 0.15);
|
||||||
|
if (scroll_top < 0) {
|
||||||
|
scroll_top = 0;
|
||||||
|
}
|
||||||
|
$(window).scrollTop(scroll_top);
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
Shortcuts.initialize();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Shortcuts
|
||||||
60
app/javascript/src/javascripts/tag_script.js
Normal file
60
app/javascript/src/javascripts/tag_script.js
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
import Post from './posts.js.erb'
|
||||||
|
|
||||||
|
let TagScript = {};
|
||||||
|
|
||||||
|
TagScript.parse = function(script) {
|
||||||
|
return script.match(/\[.+?\]|\S+/g);
|
||||||
|
}
|
||||||
|
|
||||||
|
TagScript.test = function(tags, predicate) {
|
||||||
|
var split_pred = predicate.match(/\S+/g);
|
||||||
|
var is_true = true;
|
||||||
|
|
||||||
|
$.each(split_pred, function(i, x) {
|
||||||
|
if (x[0] === "-") {
|
||||||
|
if ($.inArray(x.substr(1, 100), tags)) {
|
||||||
|
is_true = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!$.inArray(x, tags)) {
|
||||||
|
is_true = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return is_true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TagScript.process = function(tags, command) {
|
||||||
|
if (command.match(/^\[if/)) {
|
||||||
|
var match = command.match(/\[if\s+(.+?)\s*,\s*(.+?)\]/);
|
||||||
|
if (TagScript.test(tags, match[1])) {
|
||||||
|
return TagScript.process(tags, match[2]);
|
||||||
|
} else {
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
} else if (command === "[reset]") {
|
||||||
|
return [];
|
||||||
|
} else if (command[0] === "-" && !command.match(/^(?:-pool|-parent|-fav|-favgroup):/i)) {
|
||||||
|
return Utility.reject(tags, function(x) {return x === command.substr(1, 100)});
|
||||||
|
} else {
|
||||||
|
tags.push(command);
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TagScript.run = function(post_id, tag_script) {
|
||||||
|
var commands = TagScript.parse(tag_script);
|
||||||
|
var $post = $("#post_" + post_id);
|
||||||
|
var old_tags = $post.data("tags");
|
||||||
|
|
||||||
|
$.each(commands, function(i, x) {
|
||||||
|
var array = String($post.data("tags")).match(/\S+/g);
|
||||||
|
$post.data("tags", TagScript.process(array, x).join(" "));
|
||||||
|
});
|
||||||
|
|
||||||
|
Post.update(post_id, {"post[old_tag_string]": old_tags, "post[tag_string]": $post.data("tags")});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TagScript
|
||||||
208
app/javascript/src/javascripts/uploads.js
Normal file
208
app/javascript/src/javascripts/uploads.js
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
import Post from './posts.js.erb'
|
||||||
|
import Artist from './artists'
|
||||||
|
import RelatedTag from './related_tag.js.erb'
|
||||||
|
|
||||||
|
let Upload = {};
|
||||||
|
|
||||||
|
Upload.initialize_all = function() {
|
||||||
|
if ($("#c-uploads,#c-posts").length) {
|
||||||
|
this.initialize_enter_on_tags();
|
||||||
|
this.initialize_info_manual();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($("#c-uploads").length) {
|
||||||
|
if ($("#image").prop("complete")) {
|
||||||
|
this.initialize_image();
|
||||||
|
} else {
|
||||||
|
$("#image").on("load error", this.initialize_image);
|
||||||
|
}
|
||||||
|
this.initialize_info_bookmarklet();
|
||||||
|
this.initialize_similar();
|
||||||
|
this.initialize_shortcuts();
|
||||||
|
this.initialize_submit();
|
||||||
|
$("#related-tags-button").trigger("click");
|
||||||
|
|
||||||
|
$("#toggle-artist-commentary").click(function(e) {
|
||||||
|
Upload.toggle_commentary();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($("#iqdb-similar").length) {
|
||||||
|
this.initialize_iqdb_source();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Upload.initialize_submit = function() {
|
||||||
|
$("#form").submit(function(e) {
|
||||||
|
var error_messages = [];
|
||||||
|
if (($("#upload_file").val() === "") && ($("#upload_source").val() === "") && $("#upload_md5_confirmation").val() === "") {
|
||||||
|
error_messages.push("Must choose file or specify source");
|
||||||
|
}
|
||||||
|
if (!$("#upload_rating_s").prop("checked") && !$("#upload_rating_q").prop("checked") && !$("#upload_rating_e").prop("checked") &&
|
||||||
|
($("#upload_tag_string").val().search(/\brating:[sqe]/i) < 0)) {
|
||||||
|
error_messages.push("Must specify a rating");
|
||||||
|
}
|
||||||
|
if (error_messages.length === 0) {
|
||||||
|
$("#submit-button").prop("disabled","true");
|
||||||
|
$("#submit-button").prop("value","Submitting...");
|
||||||
|
$("#client-errors").hide();
|
||||||
|
} else {
|
||||||
|
$("#client-errors").html("<strong>Error</strong>: " + error_messages.join(", "));
|
||||||
|
$("#client-errors").show();
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Upload.initialize_shortcuts = function() {
|
||||||
|
Utility.keydown("e", "edit", function(e) {
|
||||||
|
$("#upload_tag_string").focus();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Upload.initialize_iqdb_source = function() {
|
||||||
|
if (/^https?:\/\//.test($("#normalized_url").val())) {
|
||||||
|
$.get("/iqdb_queries", {"url": $("#normalized_url").val()}).done(function(html) {$("#iqdb-similar").html(html)});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Upload.initialize_enter_on_tags = function() {
|
||||||
|
var $textarea = $("#upload_tag_string, #post_tag_string");
|
||||||
|
var $submit = $textarea.parents("form").find('input[type="submit"]');
|
||||||
|
|
||||||
|
$textarea.on("keydown.danbooru.submit", null, "return", function(e) {
|
||||||
|
$submit.click();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Upload.initialize_similar = function() {
|
||||||
|
$("#similar-button").click(function(e) {
|
||||||
|
$.get("/iqdb_queries", {"url": $("#upload_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Upload.initialize_info_bookmarklet = function() {
|
||||||
|
$("#upload_source").change(function (e) {
|
||||||
|
$("#fetch-data-manual").click();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#fetch-data-manual").click();
|
||||||
|
}
|
||||||
|
|
||||||
|
Upload.initialize_info_manual = function() {
|
||||||
|
$("#fetch-data-manual").click(function(e) {
|
||||||
|
var source = $("#upload_source,#post_source").val();
|
||||||
|
var referer = $("#upload_referer_url").val();
|
||||||
|
|
||||||
|
if (/^https?:\/\//.test(source)) {
|
||||||
|
$("#source-info span#loading-data").show();
|
||||||
|
Upload.fetch_source_data(source, referer);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Upload.fetch_source_data = function(url, referer_url) {
|
||||||
|
return $.getJSON("/source.json", { url: url, ref: referer_url })
|
||||||
|
.then(Upload.fill_source_info)
|
||||||
|
.catch(function(data) {
|
||||||
|
$("#source-info span#loading-data").html("Error: " + data.responseJSON["message"])
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Upload.fill_source_info = function(data) {
|
||||||
|
$("#source-tags").empty();
|
||||||
|
$.each(data.tags, function(i, v) {
|
||||||
|
$("<a>").attr("href", v[1]).text(v[0]).appendTo("#source-tags");
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#source-artist-profile").attr("href", data.profile_url).text(data.artist_name);
|
||||||
|
|
||||||
|
RelatedTag.process_artist(data.artists);
|
||||||
|
RelatedTag.translated_tags = data.translated_tags;
|
||||||
|
RelatedTag.build_all();
|
||||||
|
|
||||||
|
if (data.artists.length === 0) {
|
||||||
|
var new_artist_params = $.param({
|
||||||
|
artist: {
|
||||||
|
name: data.unique_id,
|
||||||
|
other_names: data.artist_name,
|
||||||
|
url_string: $.uniqueSort([data.profile_url, data.normalized_for_artist_finder_url]).join("\n")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var link = $("<a>").attr("href", "/artists/new?" + new_artist_params).text("Create new artist");
|
||||||
|
$("#source-Artists").html(link);
|
||||||
|
} else {
|
||||||
|
var artistLinks = data.artists.map(function (artist) {
|
||||||
|
return $('<a class="tag-type-1">').attr("href", "/artists/" + artist.id).text(artist.name);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#source-Artists").html(artistLinks)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.image_urls.length > 1) {
|
||||||
|
$("#gallery-warning").show();
|
||||||
|
} else {
|
||||||
|
$("#gallery-warning").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#upload_artist_commentary_title").val(data.artist_commentary.dtext_title);
|
||||||
|
$("#upload_artist_commentary_desc").val(data.artist_commentary.dtext_description);
|
||||||
|
Upload.toggle_commentary();
|
||||||
|
|
||||||
|
$("#source-info span#loading-data").hide();
|
||||||
|
$("#source-info ul").show();
|
||||||
|
}
|
||||||
|
|
||||||
|
Upload.update_scale = function() {
|
||||||
|
var $image = $("#image");
|
||||||
|
var ratio = $image.data("scale-factor");
|
||||||
|
if (ratio < 1) {
|
||||||
|
$("#scale").html("Scaled " + parseInt(100 * ratio) + "% (original: " + $image.data("original-width") + "x" + $image.data("original-height") + ")");
|
||||||
|
} else {
|
||||||
|
$("#scale").html("Original: " + $image.data("original-width") + "x" + $image.data("original-height"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Upload.initialize_image = function() {
|
||||||
|
var $image = $("#image");
|
||||||
|
if (!$image.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var width = $image.width();
|
||||||
|
var height = $image.height();
|
||||||
|
if (!width || !height) {
|
||||||
|
// try again later
|
||||||
|
$.timeout(100).done(function() {Upload.initialize_image()});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$image.data("original-width", width);
|
||||||
|
$image.data("original-height", height);
|
||||||
|
Post.resize_image_to_window($image);
|
||||||
|
Post.initialize_post_image_resize_to_window_link();
|
||||||
|
Upload.update_scale();
|
||||||
|
$("#image-resize-to-window-link").click(Upload.update_scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
Upload.toggle_commentary = function() {
|
||||||
|
if ($(".artist-commentary").is(":visible")) {
|
||||||
|
$("#toggle-artist-commentary").text("show »");
|
||||||
|
} else {
|
||||||
|
$("#toggle-artist-commentary").text("« hide");
|
||||||
|
}
|
||||||
|
|
||||||
|
$(".artist-commentary").slideToggle();
|
||||||
|
};
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
Upload.initialize_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Upload
|
||||||
182
app/javascript/src/javascripts/utility.js
Normal file
182
app/javascript/src/javascripts/utility.js
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
let Utility = {};
|
||||||
|
|
||||||
|
Utility.meta = function(key) {
|
||||||
|
return $("meta[name=" + key + "]").attr("content");
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility.test_max_width = function(width) {
|
||||||
|
if (!window.matchMedia) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var mq = window.matchMedia('(max-width: ' + width + 'px)');
|
||||||
|
return mq.matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility.scrolling = false;
|
||||||
|
|
||||||
|
Utility.scroll_to = function(element) {
|
||||||
|
if (Utility.scrolling) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
Utility.scrolling = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var top = null;
|
||||||
|
if (typeof(element) === "number") {
|
||||||
|
top = element;
|
||||||
|
} else {
|
||||||
|
top = element.offset().top - 10;
|
||||||
|
}
|
||||||
|
$('html, body').animate({scrollTop: top}, 300, "linear", function() {Utility.scrolling = false;});
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility.notice_timeout_id = undefined;
|
||||||
|
|
||||||
|
Utility.notice = function(msg, permanent) {
|
||||||
|
$('#notice').addClass("ui-state-highlight").removeClass("ui-state-error").fadeIn("fast").children("span").html(msg);
|
||||||
|
|
||||||
|
if (Utility.notice_timeout_id !== undefined) {
|
||||||
|
clearTimeout(Utility.notice_timeout_id)
|
||||||
|
}
|
||||||
|
if (!permanent) {
|
||||||
|
Utility.notice_timeout_id = setTimeout(function() {
|
||||||
|
$("#close-notice-link").click();
|
||||||
|
Utility.notice_timeout_id = undefined;
|
||||||
|
}, 6000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility.error = function(msg) {
|
||||||
|
$('#notice').removeClass("ui-state-highlight").addClass("ui-state-error").fadeIn("fast").children("span").html(msg);
|
||||||
|
|
||||||
|
if (Utility.notice_timeout_id !== undefined) {
|
||||||
|
clearTimeout(Utility.notice_timeout_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility.keydown = function(keys, namespace, handler) {
|
||||||
|
if (Utility.meta("enable-js-navigation") === "true") {
|
||||||
|
$(document).on("keydown" + ".Utility." + namespace, null, keys, handler);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Utility.is_subset = function(array, subarray) {
|
||||||
|
var all = true;
|
||||||
|
|
||||||
|
$.each(subarray, function(i, val) {
|
||||||
|
if ($.inArray(val, array) === -1) {
|
||||||
|
all = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return all;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility.intersect = function(a, b) {
|
||||||
|
a = a.slice(0).sort();
|
||||||
|
b = b.slice(0).sort();
|
||||||
|
var result = [];
|
||||||
|
while (a.length > 0 && b.length > 0)
|
||||||
|
{
|
||||||
|
if (a[0] < b[0]) {
|
||||||
|
a.shift();
|
||||||
|
} else if (a[0] > b[0]) {
|
||||||
|
b.shift();
|
||||||
|
} else {
|
||||||
|
result.push(a.shift());
|
||||||
|
b.shift();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility.without = function(array, element) {
|
||||||
|
var temp = [];
|
||||||
|
$.each(array, function(i, v) {
|
||||||
|
if (v !== element) {
|
||||||
|
temp.push(v);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility.reject = function(array, f) {
|
||||||
|
var filtered = [];
|
||||||
|
$.each(array, function(i, x) {
|
||||||
|
if (!f(x)) {
|
||||||
|
filtered.push(x);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return filtered;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility.regexp_escape = function(string) {
|
||||||
|
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
|
||||||
|
}
|
||||||
|
|
||||||
|
Utility.get_url_parameter = function(sParam) {
|
||||||
|
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
|
||||||
|
sURLVariables = sPageURL.split('&'),
|
||||||
|
sParameterName,
|
||||||
|
i;
|
||||||
|
|
||||||
|
for (i = 0; i < sURLVariables.length; i++) {
|
||||||
|
sParameterName = sURLVariables[i].split('=');
|
||||||
|
|
||||||
|
if (sParameterName[0] === sParam) {
|
||||||
|
return sParameterName[1] === undefined ? true : sParameterName[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Utility.sorttable = function(table) {
|
||||||
|
table.stupidtable();
|
||||||
|
table.bind("aftertablesort", function(event, data) {
|
||||||
|
$("#c-saved-searches table tbody tr").removeClass("even odd");
|
||||||
|
$("#c-saved-searches table tbody tr:even").addClass("even");
|
||||||
|
$("#c-saved-searches table tbody tr:odd").addClass("odd");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
String.prototype.hash = function() {
|
||||||
|
var hash = 5381, i = this.length;
|
||||||
|
|
||||||
|
while(i)
|
||||||
|
hash = (hash * 33) ^ this.charCodeAt(--i)
|
||||||
|
|
||||||
|
return hash >>> 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.fn.selectRange = function(start, end) {
|
||||||
|
return this.each(function() {
|
||||||
|
if (this.setSelectionRange) {
|
||||||
|
this.focus();
|
||||||
|
this.setSelectionRange(start, end);
|
||||||
|
} else if (this.createTextRange) {
|
||||||
|
var range = this.createTextRange();
|
||||||
|
range.collapse(true);
|
||||||
|
range.moveEnd('character', end);
|
||||||
|
range.moveStart('character', start);
|
||||||
|
range.select();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$.fn.selectEnd = function(){
|
||||||
|
if (this.length) {
|
||||||
|
this.selectRange(this.val().length, this.val().length);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
$(window).on("danbooru:notice", function(event, msg) {
|
||||||
|
Utility.notice(msg);
|
||||||
|
})
|
||||||
|
|
||||||
|
$(window).on("danbooru:error", function(event, msg) {
|
||||||
|
Utility.error(msg);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Utility
|
||||||
25
app/javascript/src/javascripts/wiki_pages.js
Normal file
25
app/javascript/src/javascripts/wiki_pages.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import Utility from './utility'
|
||||||
|
|
||||||
|
let WikiPage = {};
|
||||||
|
|
||||||
|
WikiPage.initialize_all = function() {
|
||||||
|
if ($("#c-wiki-pages,#c-wiki-page-versions").length) {
|
||||||
|
this.initialize_shortcuts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WikiPage.initialize_shortcuts = function() {
|
||||||
|
if ($("#a-show").length) {
|
||||||
|
Utility.keydown("e", "edit", function(e) {
|
||||||
|
$("#wiki-page-edit a")[0].click();
|
||||||
|
});
|
||||||
|
|
||||||
|
Utility.keydown("shift+d", "delete", function(e) {
|
||||||
|
$("#wiki-page-delete a")[0].click();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
WikiPage.initialize_all();
|
||||||
|
});
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@charset "UTF-8";
|
||||||
|
|
||||||
$menu_color: #F5F5FF;
|
$menu_color: #F5F5FF;
|
||||||
$link_color: hsl(213, 100%, 50%);
|
$link_color: hsl(213, 100%, 50%);
|
||||||
$link_hover_color: lighten($link_color, 25%);
|
$link_hover_color: lighten($link_color, 25%);
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@import "./000_vars.scss";
|
||||||
|
|
||||||
.ui-widget {
|
.ui-widget {
|
||||||
font-family: $base_font_family;
|
font-family: $base_font_family;
|
||||||
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@import "./000_vars.scss";
|
||||||
|
|
||||||
<% TagCategory.css_mapping.each do |category,cssmap| %>
|
<% TagCategory.css_mapping.each do |category,cssmap| %>
|
||||||
.category-<%= category %> a, a.tag-type-<%= category %>, .ui-state-active a.tag-type-<%= category %> {
|
.category-<%= category %> a, a.tag-type-<%= category %>, .ui-state-active a.tag-type-<%= category %> {
|
||||||
color: <%= cssmap["color"] %>;
|
color: <%= cssmap["color"] %>;
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user