fixes #2243
This commit is contained in:
61
app/assets/javascripts/default/artist_commentaries.js
Normal file
61
app/assets/javascripts/default/artist_commentaries.js
Normal file
@@ -0,0 +1,61 @@
|
||||
(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 form").submit();
|
||||
$(this).dialog("close");
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#add-commentary-dialog form').submit(function() {
|
||||
$('#add-commentary-dialog').dialog('close');
|
||||
});
|
||||
|
||||
$("#add-commentary").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#add-commentary-dialog").dialog("open");
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
$(function() {
|
||||
Danbooru.ArtistCommentary.initialize_all();
|
||||
});
|
||||
74
app/assets/javascripts/default/artists.js
Normal file
74
app/assets/javascripts/default/artists.js
Normal file
@@ -0,0 +1,74 @@
|
||||
(function() {
|
||||
Danbooru.Artist = {};
|
||||
|
||||
Danbooru.Artist.initialize_all = function() {
|
||||
if ($("#c-artists").length) {
|
||||
Danbooru.Artist.initialize_check_name_link();
|
||||
|
||||
if (Danbooru.meta("enable-auto-complete") === "true") {
|
||||
Danbooru.Artist.initialize_autocomplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Artist.initialize_autocomplete = function() {
|
||||
var $fields = $("#search_name,#quick_search_name");
|
||||
|
||||
$fields.autocomplete({
|
||||
minLength: 1,
|
||||
source: function(req, resp) {
|
||||
$.ajax({
|
||||
url: "/artists.json",
|
||||
data: {
|
||||
"search[name]": "*" + req.term + "*",
|
||||
"limit": 10
|
||||
},
|
||||
method: "get",
|
||||
success: function(data) {
|
||||
resp($.map(data, function(artist) {
|
||||
return {
|
||||
label: artist.name.replace(/_/g, " "),
|
||||
value: artist.name
|
||||
};
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var render_artist = function(list, artist) {
|
||||
var $link = $("<a/>").addClass("tag-type-1").text(artist.label);
|
||||
return $("<li/>").data("item.autocomplete", artist).append($link).appendTo(list);
|
||||
};
|
||||
|
||||
$fields.each(function(i, field) {
|
||||
$(field).data("uiAutocomplete")._renderItem = render_artist;
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.Artist.initialize_check_name_link = function() {
|
||||
$("#check-name-link").click(function(e) {
|
||||
var artist_name = $("#artist_name").val();
|
||||
|
||||
if (artist_name.length === 0) {
|
||||
$("#check-name-result").html("OK");
|
||||
}
|
||||
|
||||
$.get("/artists.json?name=" + artist_name,
|
||||
function(data) {
|
||||
if (data.length) {
|
||||
$("#check-name-result").html("Taken");
|
||||
} else {
|
||||
$("#check-name-result").html("OK");
|
||||
}
|
||||
}
|
||||
);
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
Danbooru.Artist.initialize_all();
|
||||
});
|
||||
354
app/assets/javascripts/default/autocomplete.js
Normal file
354
app/assets/javascripts/default/autocomplete.js
Normal file
@@ -0,0 +1,354 @@
|
||||
(function() {
|
||||
Danbooru.Autocomplete = {};
|
||||
|
||||
Danbooru.Autocomplete.initialize_all = function() {
|
||||
if (Danbooru.meta("enable-auto-complete") === "true") {
|
||||
Danbooru.Autocomplete.enable_local_storage = this.test_local_storage();
|
||||
this.initialize_tag_autocomplete();
|
||||
this.prune_local_storage();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Autocomplete.test_local_storage = function() {
|
||||
try {
|
||||
$.localStorage.set("test", "test");
|
||||
$.localStorage.remove("test");
|
||||
return true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Autocomplete.prune_local_storage = function() {
|
||||
if (this.enable_local_storage) {
|
||||
if ($.localStorage.keys().length > 4000) {
|
||||
$.localStorage.removeAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Autocomplete.initialize_tag_autocomplete = function() {
|
||||
var $fields_multiple = $(
|
||||
"#tags,#post_tag_string,#upload_tag_string,#tag-script-field,#c-moderator-post-queues #query," +
|
||||
"#user_blacklisted_tags,#user_favorite_tags,#tag_subscription_tag_query,#search_post_tags_match"
|
||||
);
|
||||
var $fields_single = $(
|
||||
"#c-tags #search_name_matches,#c-tag-aliases #query,#c-tag-implications #query," +
|
||||
"#wiki_page_title,#artist_name," +
|
||||
"#tag_alias_request_antecedent_name,#tag_alias_request_consequent_name," +
|
||||
"#tag_implication_request_antecedent_name,#tag_implication_request_consequent_name," +
|
||||
"#tag_alias_antecedent_name,#tag_alias_consequent_name," +
|
||||
"#tag_implication_antecedent_name,#tag_implication_consequent_name"
|
||||
);
|
||||
|
||||
var prefixes = "-|~|general:|gen:|artist:|art:|copyright:|copy:|co:|character:|char:|ch:";
|
||||
var metatags = "order|-status|status|-rating|rating|-locked|locked|child|" +
|
||||
"-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-fav|fav|ordfav|" +
|
||||
"sub|-pool|pool|ordpool";
|
||||
|
||||
$fields_multiple.autocomplete({
|
||||
delay: 100,
|
||||
autoFocus: true,
|
||||
focus: function() {
|
||||
return false;
|
||||
},
|
||||
select: function(event, ui) {
|
||||
var before_caret_text = this.value.substring(0, this.selectionStart);
|
||||
var after_caret_text = this.value.substring(this.selectionStart);
|
||||
|
||||
var regexp = new RegExp("(" + prefixes + ")?\\S+$", "g");
|
||||
this.value = before_caret_text.replace(regexp, "$1" + ui.item.value + " ");
|
||||
|
||||
// Preserve original caret position to prevent it from jumping to the end
|
||||
var original_start = this.selectionStart;
|
||||
this.value += after_caret_text;
|
||||
this.selectionStart = this.selectionEnd = original_start;
|
||||
|
||||
return false;
|
||||
},
|
||||
source: function(req, resp) {
|
||||
var before_caret_text = req.term.substring(0, this.element.get(0).selectionStart);
|
||||
|
||||
if (before_caret_text.match(/ $/)) {
|
||||
this.close();
|
||||
return;
|
||||
}
|
||||
|
||||
var term = before_caret_text.match(/\S+/g).pop();
|
||||
var regexp = new RegExp("^(?:" + prefixes + ")(.*)$", "i");
|
||||
var match = term.match(regexp);
|
||||
if (match) {
|
||||
term = match[1];
|
||||
}
|
||||
if (term === "") {
|
||||
return;
|
||||
}
|
||||
|
||||
regexp = new RegExp("^(" + metatags + "):(.*)$", "i");
|
||||
var match = term.match(regexp);
|
||||
var metatag;
|
||||
if (match) {
|
||||
metatag = match[1].toLowerCase();
|
||||
term = match[2];
|
||||
}
|
||||
|
||||
switch(metatag) {
|
||||
case "order":
|
||||
case "status":
|
||||
case "-status":
|
||||
case "rating":
|
||||
case "-rating":
|
||||
case "locked":
|
||||
case "-locked":
|
||||
case "child":
|
||||
Danbooru.Autocomplete.static_metatag_source(term, resp, metatag);
|
||||
return;
|
||||
}
|
||||
|
||||
if (term === "") {
|
||||
return;
|
||||
}
|
||||
|
||||
switch(metatag) {
|
||||
case "user":
|
||||
case "-user":
|
||||
case "approver":
|
||||
case "-approver":
|
||||
case "commenter":
|
||||
case "comm":
|
||||
case "noter":
|
||||
case "noteupdater":
|
||||
case "artcomm":
|
||||
case "fav":
|
||||
case "-fav":
|
||||
case "ordfav":
|
||||
Danbooru.Autocomplete.user_source(term, resp, metatag);
|
||||
break;
|
||||
case "sub":
|
||||
Danbooru.Autocomplete.subscription_source(term, resp);
|
||||
break;
|
||||
case "pool":
|
||||
case "-pool":
|
||||
case "ordpool":
|
||||
Danbooru.Autocomplete.pool_source(term, resp, metatag);
|
||||
break;
|
||||
default:
|
||||
Danbooru.Autocomplete.normal_source(term, resp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$fields_multiple.on("autocompleteselect", function() {
|
||||
Danbooru.autocompleting = true;
|
||||
});
|
||||
|
||||
$fields_multiple.on("autocompleteclose", function() {
|
||||
// this is needed otherwise the var is disabled by the time the
|
||||
// keydown is triggered
|
||||
setTimeout(function() {Danbooru.autocompleting = false;}, 100);
|
||||
});
|
||||
|
||||
$fields_single.autocomplete({
|
||||
minLength: 1,
|
||||
autoFocus: true,
|
||||
source: function(req, resp) {
|
||||
Danbooru.Autocomplete.normal_source(req.term, resp);
|
||||
}
|
||||
});
|
||||
|
||||
$.merge($fields_multiple, $fields_single).each(function(i, field) {
|
||||
$(field).data("uiAutocomplete")._renderItem = Danbooru.Autocomplete.render_item;
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.Autocomplete.normal_source = function(term, resp) {
|
||||
var key = "ac-" + term;
|
||||
if (this.enable_local_storage) {
|
||||
var cached = $.localStorage.get(key);
|
||||
if (cached) {
|
||||
resp(cached.value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: "/tags.json",
|
||||
data: {
|
||||
"search[order]": "count",
|
||||
"search[name_matches]": term + "*",
|
||||
"limit": 10
|
||||
},
|
||||
method: "get",
|
||||
success: function(data) {
|
||||
var data = $.map(data, function(tag) {
|
||||
return {
|
||||
type: "tag",
|
||||
label: tag.name.replace(/_/g, " "),
|
||||
value: tag.name,
|
||||
category: tag.category,
|
||||
post_count: tag.post_count
|
||||
};
|
||||
});
|
||||
|
||||
if (Danbooru.Autocomplete.enable_local_storage) {
|
||||
var expiry = new Date();
|
||||
expiry.setDate(expiry.getDate() + 7);
|
||||
$.localStorage.set(key, {"value": data, "expires": expiry});
|
||||
}
|
||||
resp(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.Autocomplete.render_item = function(list, item) {
|
||||
var $link = $("<a/>").text(item.label);
|
||||
$link.attr("href", "/posts?tags=" + encodeURIComponent(item.value));
|
||||
$link.click(function(e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return $("<li/>").data("item.autocomplete", item).append($link).appendTo(list);
|
||||
};
|
||||
|
||||
Danbooru.Autocomplete.static_metatags = {
|
||||
order: [
|
||||
"id", "id_desc",
|
||||
"score", "score_asc",
|
||||
"favcount", "favcount_asc",
|
||||
"change", "change_asc",
|
||||
"comment", "comment_asc",
|
||||
"note", "note_asc",
|
||||
"artcomm", "artcomm_asc",
|
||||
"mpixels", "mpixels_asc",
|
||||
"portrait", "landscape",
|
||||
"filesize", "filesize_asc",
|
||||
"rank"
|
||||
],
|
||||
status: [
|
||||
"any", "deleted", "active", "pending", "flagged", "banned"
|
||||
],
|
||||
rating: [
|
||||
"safe", "questionable", "explicit"
|
||||
],
|
||||
locked: [
|
||||
"rating", "note", "status"
|
||||
],
|
||||
child: [
|
||||
"any", "none"
|
||||
]
|
||||
}
|
||||
|
||||
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[name_matches]": term + "*",
|
||||
"limit": 10,
|
||||
},
|
||||
method: "get",
|
||||
success: function(data) {
|
||||
resp($.map(data, function(user) {
|
||||
return {
|
||||
type: "user",
|
||||
label: user.name.replace(/_/g, " "),
|
||||
value: metatag + ":" + user.name,
|
||||
level: user.level_string
|
||||
};
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.Autocomplete.subscription_source = function(term, resp) {
|
||||
var match = term.match(/^(.+?):(.*)$/);
|
||||
if (match) {
|
||||
var user_name = match[1];
|
||||
var subscription_name = match[2];
|
||||
|
||||
$.ajax({
|
||||
url: "/tag_subscriptions.json",
|
||||
data: {
|
||||
"search[creator_name]": user_name,
|
||||
"search[name_matches]": subscription_name + "*",
|
||||
"limit": 10
|
||||
},
|
||||
method: "get",
|
||||
success: function(data) {
|
||||
resp($.map(data, function(subscription) {
|
||||
return {
|
||||
label: subscription.name.replace(/_/g, " "),
|
||||
value: "sub:" + user_name + ":" + subscription.name
|
||||
};
|
||||
}));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Danbooru.Autocomplete.user_source(term, resp, "sub");
|
||||
}
|
||||
}
|
||||
|
||||
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 + ":" + pool.name,
|
||||
post_count: pool.post_count,
|
||||
category: pool.category
|
||||
};
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
$(document).ready(function() {
|
||||
Danbooru.Autocomplete.initialize_all();
|
||||
});
|
||||
137
app/assets/javascripts/default/blacklists.js
Normal file
137
app/assets/javascripts/default/blacklists.js
Normal file
@@ -0,0 +1,137 @@
|
||||
(function() {
|
||||
Danbooru.Blacklist = {};
|
||||
|
||||
Danbooru.Blacklist.entries = [];
|
||||
|
||||
Danbooru.Blacklist.parse_entry = function(string) {
|
||||
var entry = {
|
||||
"tags": string,
|
||||
"require": [],
|
||||
"exclude": [],
|
||||
"disabled": false,
|
||||
"hits": 0
|
||||
};
|
||||
var matches = string.match(/\S+/g) || [];
|
||||
$.each(matches, function(i, tag) {
|
||||
if (tag.charAt(0) === '-') {
|
||||
entry.exclude.push(tag.slice(1));
|
||||
} 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) {
|
||||
$(e.target).addClass("blacklisted-active");
|
||||
} else {
|
||||
$(e.target).removeClass("blacklisted-active");
|
||||
}
|
||||
}
|
||||
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/>");
|
||||
|
||||
link.text(entry.tags);
|
||||
link.click(Danbooru.Blacklist.toggle_entry);
|
||||
count.html(entry.hits);
|
||||
item.append(link);
|
||||
item.append(" ");
|
||||
item.append(count);
|
||||
|
||||
$("#blacklist-list").append(item);
|
||||
});
|
||||
|
||||
$("#blacklist-box").show();
|
||||
}
|
||||
|
||||
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 {
|
||||
$(post).removeClass("blacklisted-active");
|
||||
}
|
||||
});
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
Danbooru.Blacklist.posts = function() {
|
||||
return $(".post-preview, #image-container");
|
||||
}
|
||||
|
||||
Danbooru.Blacklist.post_match = function(post, entry) {
|
||||
if (entry.disabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var $post = $(post);
|
||||
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"));
|
||||
tags.push("user:" + $post.attr("data-uploader").toLowerCase().replace(/ /g, "_"));
|
||||
$.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");
|
||||
}
|
||||
|
||||
Danbooru.Blacklist.initialize_all = function() {
|
||||
Danbooru.Blacklist.parse_entries();
|
||||
|
||||
if (Danbooru.Blacklist.apply() > 0) {
|
||||
Danbooru.Blacklist.update_sidebar();
|
||||
} else {
|
||||
$("#blacklist-box").hide();
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
$(document).ready(function() {
|
||||
Danbooru.Blacklist.initialize_all();
|
||||
});
|
||||
124
app/assets/javascripts/default/comments.js
Normal file
124
app/assets/javascripts/default/comments.js
Normal file
@@ -0,0 +1,124 @@
|
||||
(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_message = function(data) {
|
||||
var blocks = data["body"].match(/\[\/?quote\]|.|\n|\r/gm);
|
||||
var n = 0;
|
||||
var stripped_body = "";
|
||||
$.each(blocks, function(i, block) {
|
||||
if (block === "[quote]") {
|
||||
n += 1;
|
||||
} else if (block == "[/quote]") {
|
||||
n -= 1;
|
||||
} else if (n === 0) {
|
||||
stripped_body += block;
|
||||
}
|
||||
});
|
||||
return "[quote]\n" + data["creator_name"] + " said:\n\n" + stripped_body + "\n[/quote]\n\n";
|
||||
}
|
||||
|
||||
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 = Danbooru.Comment.quote_message(data);
|
||||
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();
|
||||
});
|
||||
62
app/assets/javascripts/default/cookie.js
Normal file
62
app/assets/javascripts/default/cookie.js
Normal file
@@ -0,0 +1,62 @@
|
||||
(function() {
|
||||
Danbooru.Cookie = {};
|
||||
|
||||
Danbooru.Cookie.put = function(name, value, days) {
|
||||
if (days == null) {
|
||||
days = 365;
|
||||
}
|
||||
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
var expires = "; expires=" + date.toGMTString();
|
||||
document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
|
||||
}
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
68
app/assets/javascripts/default/dtext.js
Normal file
68
app/assets/javascripts/default/dtext.js
Normal file
@@ -0,0 +1,68 @@
|
||||
(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();
|
||||
});
|
||||
59
app/assets/javascripts/default/favorites.js
Normal file
59
app/assets/javascripts/default/favorites.js
Normal file
@@ -0,0 +1,59 @@
|
||||
(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 favorites = Danbooru.meta("favorites");
|
||||
var current_user_id = Danbooru.meta("current-user-id");
|
||||
if (current_user_id == "") {
|
||||
$("#add-to-favorites").hide();
|
||||
$("#remove-from-favorites").hide();
|
||||
return;
|
||||
}
|
||||
var regexp = new RegExp("\\bfav:" + current_user_id + "\\b");
|
||||
if ((favorites != undefined) && (favorites.match(regexp))) {
|
||||
$("#add-to-favorites").hide();
|
||||
} else {
|
||||
$("#remove-from-favorites").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();
|
||||
});
|
||||
31
app/assets/javascripts/default/forum_posts.js
Normal file
31
app/assets/javascripts/default/forum_posts.js
Normal file
@@ -0,0 +1,31 @@
|
||||
(function() {
|
||||
Danbooru.ForumPost = {};
|
||||
|
||||
Danbooru.ForumPost.initialize_all = function() {
|
||||
if ($("#c-forum-topics").length && $("#a-show").length) {;
|
||||
this.initialize_edit_links();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
});
|
||||
29
app/assets/javascripts/default/janitor_trials.js
Normal file
29
app/assets/javascripts/default/janitor_trials.js
Normal file
@@ -0,0 +1,29 @@
|
||||
(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();
|
||||
});
|
||||
52
app/assets/javascripts/default/mod_queue.js
Normal file
52
app/assets/javascripts/default/mod_queue.js
Normal file
@@ -0,0 +1,52 @@
|
||||
(function() {
|
||||
Danbooru.ModQueue = {};
|
||||
|
||||
Danbooru.ModQueue.initialize_approve_all_button = function() {
|
||||
$("#approve-all-button").click(function(e) {
|
||||
if (!confirm("Are you sure you want to approve every post on this page?")) {
|
||||
return;
|
||||
}
|
||||
|
||||
$(".approve-link").trigger("click");
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.ModQueue.initialize_hide_all_button = function() {
|
||||
$("#hide-all-button").click(function(e) {
|
||||
if (!confirm("Are you sure you want to hide every post on this page?")) {
|
||||
return;
|
||||
}
|
||||
|
||||
$(".disapprove-link").trigger("click");
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.ModQueue.initialize_hilights = function() {
|
||||
$.each($("article.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");
|
||||
}
|
||||
if ($post.data("has-dup")) {
|
||||
$post.addClass("post-has-dup");
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
$(function() {
|
||||
if ($("#c-moderator-post-queues").length) {
|
||||
Danbooru.ModQueue.initialize_approve_all_button();
|
||||
Danbooru.ModQueue.initialize_hide_all_button();
|
||||
Danbooru.ModQueue.initialize_hilights();
|
||||
}
|
||||
});
|
||||
28
app/assets/javascripts/default/news_updates.js
Normal file
28
app/assets/javascripts/default/news_updates.js
Normal file
@@ -0,0 +1,28 @@
|
||||
(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();
|
||||
});
|
||||
693
app/assets/javascripts/default/notes.js
Normal file
693
app/assets/javascripts/default/notes.js
Normal file
@@ -0,0 +1,693 @@
|
||||
Danbooru.Note = {
|
||||
Box: {
|
||||
create: function(id) {
|
||||
var $inner_border = $('<div/>');
|
||||
$inner_border.addClass("note-box-inner-border");
|
||||
|
||||
$inner_border.css({
|
||||
opacity: 0.5,
|
||||
"-ms-filter": "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)",
|
||||
"filter": "alpha(opacity=50)",
|
||||
zoom: 1
|
||||
});
|
||||
|
||||
var $note_box = $('<div/>');
|
||||
$note_box.addClass("note-box");
|
||||
$note_box.data("id", String(id));
|
||||
$note_box.attr("data-id", String(id));
|
||||
$note_box.draggable({containment: $("#image")});
|
||||
$note_box.resizable({
|
||||
containment: $("#image"),
|
||||
handles: "se"
|
||||
});
|
||||
$note_box.css({position: "absolute"});
|
||||
$note_box.append($inner_border);
|
||||
Danbooru.Note.Box.bind_events($note_box);
|
||||
|
||||
return $note_box;
|
||||
},
|
||||
|
||||
bind_events: function($note_box) {
|
||||
$note_box.bind(
|
||||
"dragstart resizestart",
|
||||
function(e) {
|
||||
var $note_box_inner = $(e.currentTarget);
|
||||
$note_box_inner.find(".note-box-inner-border").addClass("unsaved");
|
||||
Danbooru.Note.dragging = true;
|
||||
Danbooru.Note.clear_timeouts();
|
||||
Danbooru.Note.Body.hide_all();
|
||||
e.stopPropagation();
|
||||
}
|
||||
);
|
||||
|
||||
$note_box.bind(
|
||||
"resize",
|
||||
function(e) {
|
||||
var $note_box_inner = $(e.currentTarget);
|
||||
Danbooru.Note.Box.resize_inner_border($note_box_inner);
|
||||
e.stopPropagation();
|
||||
}
|
||||
);
|
||||
|
||||
$note_box.bind(
|
||||
"dragstop resizestop",
|
||||
function(e) {
|
||||
Danbooru.Note.dragging = false;
|
||||
e.stopPropagation();
|
||||
}
|
||||
);
|
||||
|
||||
$note_box.bind(
|
||||
"mouseover mouseout",
|
||||
function(e) {
|
||||
if (Danbooru.Note.dragging) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $note_box_inner = $(e.currentTarget);
|
||||
if (e.type === "mouseover") {
|
||||
Danbooru.Note.Body.show($note_box_inner.data("id"));
|
||||
if (Danbooru.Note.editing) {
|
||||
var $this = $(this);
|
||||
$this.resizable("enable");
|
||||
$this.draggable("enable");
|
||||
}
|
||||
} else if (e.type === "mouseout") {
|
||||
Danbooru.Note.Body.hide($note_box_inner.data("id"));
|
||||
if (Danbooru.Note.editing) {
|
||||
var $this = $(this);
|
||||
$this.resizable("disable");
|
||||
$this.draggable("disable");
|
||||
}
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
find: function(id) {
|
||||
return $("#note-container div.note-box[data-id=" + id + "]");
|
||||
},
|
||||
|
||||
resize_inner_border: function($note_box) {
|
||||
var $inner_border = $note_box.find("div.note-box-inner-border");
|
||||
$inner_border.css({
|
||||
height: $note_box.height() - 2,
|
||||
width: $note_box.width() - 2
|
||||
});
|
||||
},
|
||||
|
||||
scale: function($note_box) {
|
||||
var $image = $("#image");
|
||||
var ratio = $image.width() / parseFloat($image.data("original-width"));
|
||||
var MIN_SIZE = 5;
|
||||
$note_box.css({
|
||||
top: Math.ceil(parseFloat($note_box.data("y")) * ratio),
|
||||
left: Math.ceil(parseFloat($note_box.data("x")) * 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))
|
||||
});
|
||||
Danbooru.Note.Box.resize_inner_border($note_box);
|
||||
},
|
||||
|
||||
scale_all: function() {
|
||||
var container = document.getElementById('note-container');
|
||||
// Hide notes while rescaling, to prevent unnecessary reflowing
|
||||
var was_visible = container.style.display != 'none';
|
||||
if (was_visible) container.style.display = 'none';
|
||||
$(".note-box").each(function(i, v) {
|
||||
Danbooru.Note.Box.scale($(v));
|
||||
});
|
||||
if (was_visible) container.style.display = 'block';
|
||||
},
|
||||
|
||||
toggle_all: function() {
|
||||
var $note_container = $("#note-container");
|
||||
var is_hidden = ($note_container.css('visibility') === 'hidden');
|
||||
|
||||
if (is_hidden) {
|
||||
$note_container.css('visibility', 'visible');
|
||||
} else {
|
||||
$note_container.css('visibility', 'hidden');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Body: {
|
||||
create: function(id) {
|
||||
var $note_body = $('<div></div>');
|
||||
$note_body.addClass("note-body");
|
||||
$note_body.data("id", String(id));
|
||||
$note_body.attr("data-id", String(id));
|
||||
$note_body.hide();
|
||||
Danbooru.Note.Body.bind_events($note_body);
|
||||
return $note_body;
|
||||
},
|
||||
|
||||
initialize: function($note_body) {
|
||||
var $note_box = Danbooru.Note.Box.find($note_body.data("id"));
|
||||
$note_body.css({
|
||||
top: $note_box.position().top + $note_box.height() + 5,
|
||||
left: $note_box.position().left
|
||||
});
|
||||
Danbooru.Note.Body.bound_position($note_body);
|
||||
},
|
||||
|
||||
bound_position: function($note_body) {
|
||||
var $image = $("#image");
|
||||
var doc_width = $image.offset().left + $image.width();
|
||||
|
||||
while ($note_body[0].clientHeight < $note_body[0].scrollHeight) {
|
||||
$note_body.css({height: $note_body.height() + 5});
|
||||
}
|
||||
|
||||
while ($note_body[0].clientWidth < $note_body[0].scrollWidth) {
|
||||
$note_body.css({width: $note_body.width() + 5});
|
||||
}
|
||||
|
||||
if ($note_body.offset().left + $note_body.width() > doc_width) {
|
||||
$note_body.css({
|
||||
left: $note_body.position().left - 10 - ($note_body.offset().left + $note_body.width() - doc_width)
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
show: function(id) {
|
||||
Danbooru.Note.Body.hide_all();
|
||||
Danbooru.Note.clear_timeouts();
|
||||
var $note_body = Danbooru.Note.Body.find(id);
|
||||
if (!$note_body.data('resized')) {
|
||||
Danbooru.Note.Body.resize($note_body);
|
||||
$note_body.data('resized', 'true');
|
||||
}
|
||||
$note_body.show();
|
||||
Danbooru.Note.Body.initialize($note_body);
|
||||
},
|
||||
|
||||
find: function(id) {
|
||||
return $("#note-container div.note-body[data-id=" + id + "]");
|
||||
},
|
||||
|
||||
hide: function(id) {
|
||||
var $note_body = Danbooru.Note.Body.find(id);
|
||||
Danbooru.Note.timeouts.push($.timeout(250).done(function() {$note_body.hide();}));
|
||||
},
|
||||
|
||||
hide_all: function() {
|
||||
$("#note-container div.note-body").hide();
|
||||
},
|
||||
|
||||
resize: function($note_body) {
|
||||
$note_body.css("min-width", "");
|
||||
var w = $note_body.width();
|
||||
var h = $note_body.height();
|
||||
var golden_ratio = 1.6180339887;
|
||||
var last = 0;
|
||||
var x = 0;
|
||||
|
||||
if ((w / h) < golden_ratio) {
|
||||
var lo = 140;
|
||||
var hi = 400;
|
||||
do {
|
||||
last = w;
|
||||
x = (lo + hi) / 2;
|
||||
$note_body.css("min-width", x);
|
||||
w = $note_body.width();
|
||||
h = $note_body.height();
|
||||
|
||||
if ((w / h) < golden_ratio) {
|
||||
lo = x;
|
||||
} else {
|
||||
hi = x;
|
||||
}
|
||||
} while ((lo < hi) && (w > last));
|
||||
} else if ($note_body[0].scrollWidth <= $note_body.width()) {
|
||||
var lo = 20;
|
||||
var hi = w;
|
||||
|
||||
do {
|
||||
x = (lo + hi) / 2;
|
||||
$note_body.css("min-width", x);
|
||||
if ($note_body.height() > h) {
|
||||
lo = x
|
||||
} else {
|
||||
hi = x;
|
||||
}
|
||||
} while ((hi - lo) > 4);
|
||||
if ($note_body.height() > h) {
|
||||
$note_body.css("min-width", hi);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
set_text: function($note_body, text) {
|
||||
Danbooru.Note.Body.display_text($note_body, text);
|
||||
Danbooru.Note.Body.resize($note_body);
|
||||
Danbooru.Note.Body.bound_position($note_body);
|
||||
},
|
||||
|
||||
display_text: function($note_body, text) {
|
||||
text = text.replace(/<tn>/g, '<p class="tn">');
|
||||
text = text.replace(/<\/tn>/g, '</p>');
|
||||
text = text.replace(/\n/g, '<br>');
|
||||
$note_body.html(text);
|
||||
},
|
||||
|
||||
bind_events: function($note_body) {
|
||||
$note_body.mouseover(function(e) {
|
||||
var $note_body_inner = $(e.currentTarget);
|
||||
Danbooru.Note.Body.show($note_body_inner.data("id"));
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
$note_body.mouseout(function(e) {
|
||||
var $note_body_inner = $(e.currentTarget);
|
||||
Danbooru.Note.Body.hide($note_body_inner.data("id"));
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
if (Danbooru.meta("current-user-name") !== "Anonymous") {
|
||||
$note_body.click(function(e) {
|
||||
if (e.target.tagName !== "A") {
|
||||
var $note_body_inner = $(e.currentTarget);
|
||||
Danbooru.Note.Edit.show($note_body_inner);
|
||||
}
|
||||
e.stopPropagation();
|
||||
});
|
||||
} else {
|
||||
$note_body.click(function(e) {
|
||||
if (e.target.tagName !== "A") {
|
||||
Danbooru.notice("You must be logged in to edit notes");
|
||||
}
|
||||
e.stopPropagation();
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Edit: {
|
||||
show: function($note_body) {
|
||||
if (Danbooru.Note.editing) {
|
||||
return;
|
||||
}
|
||||
|
||||
$(".note-box").resizable("disable");
|
||||
$(".note-box").draggable("disable");
|
||||
|
||||
$textarea = $('<textarea></textarea>');
|
||||
$textarea.css({
|
||||
width: "97%",
|
||||
height: "92%",
|
||||
resize: "none",
|
||||
});
|
||||
|
||||
if ($note_body.html() !== "<em>Click to edit</em>") {
|
||||
$textarea.val($note_body.data("original-body"));
|
||||
}
|
||||
|
||||
$dialog = $('<div></div>');
|
||||
$dialog.append($textarea);
|
||||
$dialog.data("id", $note_body.data("id"));
|
||||
$dialog.dialog({
|
||||
width: 360,
|
||||
height: 210,
|
||||
position: {
|
||||
my: "right",
|
||||
at: "right-20",
|
||||
of: window
|
||||
},
|
||||
dialogClass: "note-edit-dialog",
|
||||
title: "Edit note",
|
||||
buttons: {
|
||||
"Save": Danbooru.Note.Edit.save,
|
||||
"Preview": Danbooru.Note.Edit.preview,
|
||||
"Cancel": Danbooru.Note.Edit.cancel,
|
||||
"Delete": Danbooru.Note.Edit.destroy,
|
||||
"History": Danbooru.Note.Edit.history
|
||||
}
|
||||
});
|
||||
$dialog.data("uiDialog")._title = function(title) {
|
||||
title.html(this.options.title); // Allow unescaped html in dialog title
|
||||
}
|
||||
$dialog.dialog("option", "title", 'Edit note (<a href="/wiki_pages/help:notes">view help</a>)');
|
||||
|
||||
$dialog.bind("dialogclose", function() {
|
||||
Danbooru.Note.editing = false;
|
||||
$(".note-box").resizable("enable");
|
||||
$(".note-box").draggable("enable");
|
||||
});
|
||||
|
||||
$textarea.selectEnd();
|
||||
Danbooru.Note.editing = true;
|
||||
},
|
||||
|
||||
parameterize_note: function($note_box, $note_body) {
|
||||
var $image = $("#image");
|
||||
var original_width = parseInt($image.data("original-width"));
|
||||
var ratio = parseInt($image.width()) / original_width;
|
||||
|
||||
var hash = {
|
||||
note: {
|
||||
x: $note_box.position().left / ratio,
|
||||
y: $note_box.position().top / ratio,
|
||||
width: $note_box.width() / ratio,
|
||||
height: $note_box.height() / ratio,
|
||||
body: $note_body.data("original-body"),
|
||||
post_id: Danbooru.meta("post-id")
|
||||
}
|
||||
}
|
||||
|
||||
if ($note_box.data("id").match(/x/)) {
|
||||
hash.note.html_id = $note_box.data("id");
|
||||
}
|
||||
|
||||
return hash;
|
||||
},
|
||||
|
||||
error_handler: function(xhr, status, exception) {
|
||||
Danbooru.error("There was an error saving the note");
|
||||
},
|
||||
|
||||
success_handler: function(data, status, xhr) {
|
||||
if (data.html_id) { // new note
|
||||
var $note_body = Danbooru.Note.Body.find(data.html_id);
|
||||
var $note_box = Danbooru.Note.Box.find(data.html_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.find(".note-box-inner-border").removeClass("unsaved");
|
||||
} else {
|
||||
var $note_box = Danbooru.Note.Box.find(data.id);
|
||||
$note_box.find(".note-box-inner-border").removeClass("unsaved");
|
||||
}
|
||||
},
|
||||
|
||||
save: function() {
|
||||
var $this = $(this);
|
||||
var $textarea = $this.find("textarea");
|
||||
var id = $this.data("id");
|
||||
var $note_body = Danbooru.Note.Body.find(id);
|
||||
var $note_box = Danbooru.Note.Box.find(id);
|
||||
var text = $textarea.val();
|
||||
$note_body.data("original-body", text);
|
||||
Danbooru.Note.Body.set_text($note_body, "Loading...");
|
||||
$.get("/note_previews.json", {body: text}).success(function(data) {
|
||||
Danbooru.Note.Body.set_text($note_body, data.body);
|
||||
$note_body.show();
|
||||
});
|
||||
$this.dialog("close");
|
||||
|
||||
if (id.match(/\d/)) {
|
||||
$.ajax("/notes/" + id + ".json", {
|
||||
type: "PUT",
|
||||
data: Danbooru.Note.Edit.parameterize_note($note_box, $note_body),
|
||||
error: Danbooru.Note.Edit.error_handler,
|
||||
success: Danbooru.Note.Edit.success_handler
|
||||
});
|
||||
} else {
|
||||
$.ajax("/notes.json", {
|
||||
type: "POST",
|
||||
data: Danbooru.Note.Edit.parameterize_note($note_box, $note_body),
|
||||
error: Danbooru.Note.Edit.error_handler,
|
||||
success: Danbooru.Note.Edit.success_handler
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
preview: function() {
|
||||
var $this = $(this);
|
||||
var $textarea = $this.find("textarea");
|
||||
var id = $this.data("id");
|
||||
var $note_body = Danbooru.Note.Body.find(id);
|
||||
var text = $textarea.val();
|
||||
var $note_box = Danbooru.Note.Box.find(id);
|
||||
$note_box.find(".note-box-inner-border").addClass("unsaved");
|
||||
Danbooru.Note.Body.set_text($note_body, "Loading...");
|
||||
$.get("/note_previews.json", {body: text}).success(function(data) {
|
||||
Danbooru.Note.Body.set_text($note_body, data.body);
|
||||
$note_body.show();
|
||||
});
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
$(this).dialog("close");
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
if (!confirm("Do you really want to delete this note?")) {
|
||||
return
|
||||
}
|
||||
|
||||
var $this = $(this);
|
||||
var id = $this.data("id");
|
||||
Danbooru.Note.Box.find(id).remove();
|
||||
Danbooru.Note.Body.find(id).remove();
|
||||
$this.dialog("close");
|
||||
|
||||
if (id.match(/\d/)) {
|
||||
$.ajax("/notes/" + id + ".js", {
|
||||
type: "DELETE"
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
history: function() {
|
||||
var $this = $(this);
|
||||
var id = $this.data("id");
|
||||
if (id.match(/\d/)) {
|
||||
window.location.href = "/note_versions?search[note_id]=" + id;
|
||||
}
|
||||
$(this).dialog("close");
|
||||
}
|
||||
},
|
||||
|
||||
TranslationMode: {
|
||||
active: false,
|
||||
|
||||
toggle: function(e) {
|
||||
if (Danbooru.Note.TranslationMode.active) {
|
||||
Danbooru.Note.TranslationMode.stop(e);
|
||||
} else {
|
||||
Danbooru.Note.TranslationMode.start(e);
|
||||
}
|
||||
},
|
||||
|
||||
start: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (Danbooru.Note.TranslationMode.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
$("#image").css("cursor", "crosshair");
|
||||
Danbooru.Note.TranslationMode.active = true;
|
||||
$(document.body).addClass("mode-translation");
|
||||
$("#original-file-link").click();
|
||||
$("#image").unbind("click", Danbooru.Note.Box.toggle_all);
|
||||
$("#image").bind("mousedown", Danbooru.Note.TranslationMode.Drag.start);
|
||||
$(window).bind("mouseup", Danbooru.Note.TranslationMode.Drag.stop);
|
||||
|
||||
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>).');
|
||||
$("#notice a:contains(Turn translation mode off)").click(function(e) {
|
||||
Danbooru.Note.TranslationMode.stop();
|
||||
e.preventDefault();
|
||||
});
|
||||
},
|
||||
|
||||
stop: function() {
|
||||
Danbooru.Note.TranslationMode.active = false;
|
||||
$("#image").css("cursor", "auto");
|
||||
$("#image").bind("click", Danbooru.Note.Box.toggle_all);
|
||||
$("#image").unbind("mousedown", Danbooru.Note.TranslationMode.Drag.start);
|
||||
$(window).unbind("mouseup", Danbooru.Note.TranslationMode.Drag.stop);
|
||||
$(document.body).removeClass("mode-translation");
|
||||
$("#close-notice-link").click();
|
||||
},
|
||||
|
||||
create_note: function(e, x, y, w, h) {
|
||||
var offset = $("#image").offset();
|
||||
|
||||
if (w > 9 || h > 9) { /* minimum note size: 10px */
|
||||
if (w <= 9) {
|
||||
w = 10;
|
||||
} else if (h <= 9) {
|
||||
h = 10;
|
||||
}
|
||||
Danbooru.Note.create(x - offset.left, y - offset.top, w, h);
|
||||
}
|
||||
|
||||
$("#note-container").css('visibility', 'visible');
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
},
|
||||
|
||||
Drag: {
|
||||
dragging: false,
|
||||
dragStartX: 0,
|
||||
dragStartY: 0,
|
||||
dragDistanceX: 0,
|
||||
dragDistanceY: 0,
|
||||
x: 0,
|
||||
y: 0,
|
||||
w: 0,
|
||||
h: 0,
|
||||
|
||||
start: function (e) {
|
||||
if (e.which !== 1) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault(); /* don't drag the image */
|
||||
$(window).mousemove(Danbooru.Note.TranslationMode.Drag.drag);
|
||||
Danbooru.Note.TranslationMode.Drag.dragStartX = e.pageX;
|
||||
Danbooru.Note.TranslationMode.Drag.dragStartY = e.pageY;
|
||||
},
|
||||
|
||||
drag: function (e) {
|
||||
Danbooru.Note.TranslationMode.Drag.dragDistanceX = e.pageX - Danbooru.Note.TranslationMode.Drag.dragStartX;
|
||||
Danbooru.Note.TranslationMode.Drag.dragDistanceY = e.pageY - Danbooru.Note.TranslationMode.Drag.dragStartY;
|
||||
var $image = $("#image");
|
||||
var offset = $image.offset();
|
||||
var limitX1 = $image.width() - Danbooru.Note.TranslationMode.Drag.dragStartX + offset.left - 1;
|
||||
var limitX2 = offset.left - Danbooru.Note.TranslationMode.Drag.dragStartX;
|
||||
var limitY1 = $image.height()- Danbooru.Note.TranslationMode.Drag.dragStartY + offset.top - 1;
|
||||
var limitY2 = offset.top - Danbooru.Note.TranslationMode.Drag.dragStartY;
|
||||
|
||||
if (Danbooru.Note.TranslationMode.Drag.dragDistanceX > limitX1) {
|
||||
Danbooru.Note.TranslationMode.Drag.dragDistanceX = limitX1;
|
||||
} else if (Danbooru.Note.TranslationMode.Drag.dragDistanceX < limitX2) {
|
||||
Danbooru.Note.TranslationMode.Drag.dragDistanceX = limitX2;
|
||||
}
|
||||
|
||||
if (Danbooru.Note.TranslationMode.Drag.dragDistanceY > limitY1) {
|
||||
Danbooru.Note.TranslationMode.Drag.dragDistanceY = limitY1;
|
||||
} else if (Danbooru.Note.TranslationMode.Drag.dragDistanceY < limitY2) {
|
||||
Danbooru.Note.TranslationMode.Drag.dragDistanceY = limitY2;
|
||||
}
|
||||
|
||||
if (Math.abs(Danbooru.Note.TranslationMode.Drag.dragDistanceX) > 9 && Math.abs(Danbooru.Note.TranslationMode.Drag.dragDistanceY) > 9) {
|
||||
Danbooru.Note.TranslationMode.Drag.dragging = true; /* must drag at least 10pixels (minimum note size) in both dimensions. */
|
||||
}
|
||||
if (Danbooru.Note.TranslationMode.Drag.dragging) {
|
||||
if (Danbooru.Note.TranslationMode.Drag.dragDistanceX >= 0) {
|
||||
Danbooru.Note.TranslationMode.Drag.x = Danbooru.Note.TranslationMode.Drag.dragStartX;
|
||||
Danbooru.Note.TranslationMode.Drag.w = Danbooru.Note.TranslationMode.Drag.dragDistanceX;
|
||||
} else {
|
||||
Danbooru.Note.TranslationMode.Drag.x = Danbooru.Note.TranslationMode.Drag.dragStartX + Danbooru.Note.TranslationMode.Drag.dragDistanceX;
|
||||
Danbooru.Note.TranslationMode.Drag.w = -Danbooru.Note.TranslationMode.Drag.dragDistanceX;
|
||||
}
|
||||
|
||||
if (Danbooru.Note.TranslationMode.Drag.dragDistanceY >= 0) {
|
||||
Danbooru.Note.TranslationMode.Drag.y = Danbooru.Note.TranslationMode.Drag.dragStartY;
|
||||
Danbooru.Note.TranslationMode.Drag.h = Danbooru.Note.TranslationMode.Drag.dragDistanceY;
|
||||
} else {
|
||||
Danbooru.Note.TranslationMode.Drag.y = Danbooru.Note.TranslationMode.Drag.dragStartY + Danbooru.Note.TranslationMode.Drag.dragDistanceY;
|
||||
Danbooru.Note.TranslationMode.Drag.h = -Danbooru.Note.TranslationMode.Drag.dragDistanceY;
|
||||
}
|
||||
|
||||
$('#note-preview').css({
|
||||
display: 'block',
|
||||
left: (Danbooru.Note.TranslationMode.Drag.x + 1),
|
||||
top: (Danbooru.Note.TranslationMode.Drag.y + 1),
|
||||
width: (Danbooru.Note.TranslationMode.Drag.w - 3),
|
||||
height: (Danbooru.Note.TranslationMode.Drag.h - 3)
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
stop: function (e) {
|
||||
if (e.which !== 1) {
|
||||
return;
|
||||
}
|
||||
if (Danbooru.Note.TranslationMode.Drag.dragStartX === 0) {
|
||||
return; /* 'stop' is bound to window, don't create note if start wasn't triggered */
|
||||
}
|
||||
$(window).unbind("mousemove");
|
||||
|
||||
if (Danbooru.Note.TranslationMode.Drag.dragging) {
|
||||
$('#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);
|
||||
Danbooru.Note.TranslationMode.Drag.dragging = false; /* border of the note is pixel-perfect on the preview border */
|
||||
} else { /* no dragging -> toggle display of notes */
|
||||
Danbooru.Note.Box.toggle_all();
|
||||
}
|
||||
|
||||
Danbooru.Note.TranslationMode.Drag.dragStartX = 0;
|
||||
Danbooru.Note.TranslationMode.Drag.dragStartY = 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
id: "x",
|
||||
dragging: false,
|
||||
editing: false,
|
||||
timeouts: [],
|
||||
pending: {},
|
||||
|
||||
add: function(container, id, x, y, w, h, text) {
|
||||
var $note_box = Danbooru.Note.Box.create(id);
|
||||
var $note_body = Danbooru.Note.Body.create(id);
|
||||
|
||||
$note_box.data('x', x);
|
||||
$note_box.data('y', y);
|
||||
$note_box.data('width', w);
|
||||
$note_box.data('height', h);
|
||||
container.appendChild($note_box[0]);
|
||||
container.appendChild($note_body[0]);
|
||||
$note_body.data("original-body", text);
|
||||
Danbooru.Note.Box.scale($note_box);
|
||||
Danbooru.Note.Body.display_text($note_body, text);
|
||||
},
|
||||
|
||||
create: function(x, y, w, h) {
|
||||
var $note_box = Danbooru.Note.Box.create(Danbooru.Note.id);
|
||||
var $note_body = Danbooru.Note.Body.create(Danbooru.Note.id);
|
||||
$note_box.css({
|
||||
top: y,
|
||||
left: x,
|
||||
width: w,
|
||||
height: h
|
||||
});
|
||||
$note_box.find(".note-box-inner-border").addClass("unsaved");
|
||||
$note_body.html("<em>Click to edit</em>");
|
||||
$("#note-container").append($note_box);
|
||||
$("#note-container").append($note_body);
|
||||
Danbooru.Note.Box.resize_inner_border($note_box);
|
||||
Danbooru.Note.id += "x";
|
||||
},
|
||||
|
||||
clear_timeouts: function() {
|
||||
$.each(Danbooru.Note.timeouts, function(i, v) {
|
||||
v.clear();
|
||||
});
|
||||
|
||||
Danbooru.Note.timeouts = [];
|
||||
},
|
||||
|
||||
load_all: function() {
|
||||
var fragment = document.createDocumentFragment();
|
||||
$.each($("#notes article"), function(i, article) {
|
||||
var $article = $(article);
|
||||
Danbooru.Note.add(
|
||||
fragment,
|
||||
$article.data("id"),
|
||||
$article.data("x"),
|
||||
$article.data("y"),
|
||||
$article.data("width"),
|
||||
$article.data("height"),
|
||||
$article.html()
|
||||
);
|
||||
});
|
||||
$("#note-container").append(fragment);
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
if ($("#c-posts").length && $("#a-show").length && $("#image").length) {
|
||||
if ($("#note-locked-notice").length == 0) {
|
||||
$("#translate").bind("click", Danbooru.Note.TranslationMode.toggle);
|
||||
$(document).bind("keypress", "n", Danbooru.Note.TranslationMode.toggle);
|
||||
}
|
||||
Danbooru.Note.load_all();
|
||||
$("#image").bind("click", Danbooru.Note.Box.toggle_all);
|
||||
}
|
||||
});
|
||||
25
app/assets/javascripts/default/paginator.js
Normal file
25
app/assets/javascripts/default/paginator.js
Normal file
@@ -0,0 +1,25 @@
|
||||
(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.meta("enable-js-navigation") === "true")) {
|
||||
$(document).bind("keypress", "d", Danbooru.Paginator.next_page);
|
||||
$(document).bind("keypress", "a", Danbooru.Paginator.prev_page);
|
||||
}
|
||||
});
|
||||
|
||||
92
app/assets/javascripts/default/pools.js
Normal file
92
app/assets/javascripts/default/pools.js
Normal file
@@ -0,0 +1,92 @@
|
||||
(function() {
|
||||
Danbooru.Pool = {};
|
||||
|
||||
Danbooru.Pool.initialize_all = function() {
|
||||
if ($("#c-pools").length) {
|
||||
if (Danbooru.meta("enable-auto-complete") === "true") {
|
||||
this.initialize_autocomplete_for("#search_name_matches,#quick_search_name_matches");
|
||||
}
|
||||
}
|
||||
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
this.initialize_add_to_pool_link();
|
||||
}
|
||||
|
||||
if ($("#c-pool-orders").length) {
|
||||
this.initialize_simple_edit();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Pool.initialize_autocomplete_for = function(selector) {
|
||||
var $fields = $(selector);
|
||||
|
||||
$fields.autocomplete({
|
||||
minLength: 1,
|
||||
source: function(req, resp) {
|
||||
$.ajax({
|
||||
url: "/pools.json",
|
||||
data: {
|
||||
"search[is_active]": "true",
|
||||
"search[name_matches]": req.term,
|
||||
"limit": 10
|
||||
},
|
||||
method: "get",
|
||||
success: function(data) {
|
||||
resp($.map(data, function(pool) {
|
||||
return {
|
||||
label: pool.name.replace(/_/g, " "),
|
||||
value: pool.name,
|
||||
category: pool.category
|
||||
};
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var render_pool = function(list, pool) {
|
||||
var $link = $("<a/>").addClass("pool-category-" + pool.category).text(pool.label);
|
||||
return $("<li/>").data("item.autocomplete", pool).append($link).appendTo(list);
|
||||
};
|
||||
|
||||
$fields.each(function(i, field) {
|
||||
$(field).data("uiAutocomplete")._renderItem = render_pool;
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.Pool.initialize_add_to_pool_link = function() {
|
||||
$("#add-to-pool-dialog").dialog({autoOpen: false});
|
||||
|
||||
this.initialize_autocomplete_for("#add-to-pool-dialog input[type=text]");
|
||||
|
||||
$("#pool").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#add-to-pool-dialog").dialog("open");
|
||||
});
|
||||
|
||||
$("#recent-pools li").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#pool_name").val($(this).html());
|
||||
});
|
||||
}
|
||||
|
||||
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();
|
||||
});
|
||||
42
app/assets/javascripts/default/post_appeals.js
Normal file
42
app/assets/javascripts/default/post_appeals.js
Normal file
@@ -0,0 +1,42 @@
|
||||
(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();
|
||||
});
|
||||
46
app/assets/javascripts/default/post_flags.js
Normal file
46
app/assets/javascripts/default/post_flags.js
Normal file
@@ -0,0 +1,46 @@
|
||||
(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();
|
||||
});
|
||||
181
app/assets/javascripts/default/post_mode_menu.js
Normal file
181
app/assets/javascripts/default/post_mode_menu.js
Normal file
@@ -0,0 +1,181 @@
|
||||
(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() {
|
||||
$(document).bind("keypress", "1 2 3 4 5 6 7 8 9 0", 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()
|
||||
}
|
||||
},
|
||||
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().height($("#post_tag_string")[0].scrollHeight);
|
||||
}
|
||||
|
||||
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 === 'rating-q') {
|
||||
Danbooru.Post.update(post_id, {"post[rating]": "q"});
|
||||
} else if (s === 'rating-s') {
|
||||
Danbooru.Post.update(post_id, {"post[rating]": "s"});
|
||||
} else if (s === 'rating-e') {
|
||||
Danbooru.Post.update(post_id, {"post[rating]": "e"});
|
||||
} 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 === "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();
|
||||
});
|
||||
29
app/assets/javascripts/default/post_moderation.js
Normal file
29
app/assets/javascripts/default/post_moderation.js
Normal file
@@ -0,0 +1,29 @@
|
||||
(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();
|
||||
});
|
||||
41
app/assets/javascripts/default/post_popular.js
Normal file
41
app/assets/javascripts/default/post_popular.js
Normal file
@@ -0,0 +1,41 @@
|
||||
(function() {
|
||||
Danbooru.PostPopular = {};
|
||||
|
||||
Danbooru.PostPopular.nav_prev = function() {
|
||||
if ($("#popular-nav-links").length) {
|
||||
var href = $("#popular-nav-links a[rel=prev]").attr("href");
|
||||
if (href) {
|
||||
location.href = href;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.PostPopular.nav_next = function() {
|
||||
if ($("#popular-nav-links").length) {
|
||||
var href = $("#popular-nav-links a[rel=next]").attr("href");
|
||||
if (href) {
|
||||
location.href = href;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.PostPopular.initialize_all = function() {
|
||||
if ($("#c-explore-posts").length) {
|
||||
if (Danbooru.meta("enable-js-navigation") === "true") {
|
||||
$(document).bind("keypress", "a", function(e) {
|
||||
Danbooru.PostPopular.nav_prev();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(document).bind("keypress", "d", function(e) {
|
||||
Danbooru.PostPopular.nav_next();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
$(document).ready(function() {
|
||||
Danbooru.PostPopular.initialize_all();
|
||||
});
|
||||
517
app/assets/javascripts/default/posts.js
Normal file
517
app/assets/javascripts/default/posts.js
Normal file
@@ -0,0 +1,517 @@
|
||||
(function() {
|
||||
Danbooru.Post = {};
|
||||
|
||||
Danbooru.Post.pending_update_count = 0;
|
||||
|
||||
Danbooru.Post.initialize_all = function() {
|
||||
this.initialize_post_previews();
|
||||
|
||||
if ($("#c-posts").length) {
|
||||
if (Danbooru.meta("enable-js-navigation") === "true") {
|
||||
this.initialize_shortcuts();
|
||||
}
|
||||
}
|
||||
|
||||
if ($("#c-posts").length && $("#a-index").length) {
|
||||
this.initialize_excerpt();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
if (Danbooru.meta("always-resize-images") === "true") {
|
||||
$("#image-resize-to-window-link").click();
|
||||
}
|
||||
}
|
||||
|
||||
if ($("#image").length) {
|
||||
this.initialize_edit_dialog();
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
var $related_tags = $("#related-tags");
|
||||
if ($related_tags.is(":visible")) {
|
||||
$related_tags.hide();
|
||||
$(e.target).html("»");
|
||||
} else {
|
||||
$related_tags.show();
|
||||
$("#related-tags-button").trigger("click");
|
||||
$("#find-artist-button").trigger("click");
|
||||
$(e.target).html("«");
|
||||
}
|
||||
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() / 3,
|
||||
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});
|
||||
})
|
||||
.mouseover(function(e) {
|
||||
dialog.parent().css({"opacity": 1});
|
||||
});
|
||||
|
||||
$tag_string.css({"resize": "none", "width": "100%"});
|
||||
$tag_string.focus().selectEnd().height($tag_string[0].scrollHeight);
|
||||
|
||||
var $image = $("#c-uploads .ui-wrapper #image, #c-uploads .ui-wrapper:has(#image)");
|
||||
$image.height($image.resizable("option", "maxHeight"));
|
||||
$image.width($image.resizable("option", "maxWidth"));
|
||||
}
|
||||
|
||||
Danbooru.Post.close_edit_dialog = function(e, ui) {
|
||||
$("#form").appendTo($("#c-posts #edit,#c-uploads #a-new"));
|
||||
$("#edit-dialog").remove();
|
||||
$("#related-tags").show();
|
||||
$("#toggle-related-tags-link").html("»").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) {
|
||||
$.post("/iqdb_queries", {"url": $("#post_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.Post.nav_prev = function() {
|
||||
if ($("#search-seq-nav").length) {
|
||||
var href = $("#search-seq-nav a[rel=prev]").attr("href");
|
||||
if (href) {
|
||||
location.href = href;
|
||||
}
|
||||
} else {
|
||||
var href = $("#pool-nav a.active[rel=prev]").attr("href");
|
||||
if (href) {
|
||||
location.href = href;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Post.nav_next = function() {
|
||||
if ($("#search-seq-nav").length) {
|
||||
var href = $("#search-seq-nav a[rel=next]").attr("href");
|
||||
location.href = href;
|
||||
} else {
|
||||
var href = $("#pool-nav a.active[rel=next]").attr("href");
|
||||
if (href) {
|
||||
location.href = href;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Post.initialize_shortcuts = function() {
|
||||
if ($("#a-show").length) {
|
||||
$(document).bind("keypress", "e", function(e) {
|
||||
$("#post-edit-link").trigger("click");
|
||||
$("#post_tag_string").focus();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(document).bind("keypress", "a", function(e) {
|
||||
Danbooru.Post.nav_prev();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(document).bind("keypress", "d", function(e) {
|
||||
Danbooru.Post.nav_next();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(document).bind("keypress", "f", function(e) {
|
||||
if ($("#add-to-favorites").is(":visible")) {
|
||||
$("#add-to-favorites").click();
|
||||
} else {
|
||||
Danbooru.notice("You have already favorited this post")
|
||||
}
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Post.initialize_links = function() {
|
||||
$("#side-edit-link").click(function(e) {
|
||||
$("#post-edit-link").trigger("click");
|
||||
$("#post_tag_string").trigger("focus");
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#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.initialize_post_previews = function() {
|
||||
$(".post-preview").each(function(i, v) {
|
||||
Danbooru.Post.initialize_title_for(v);
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.Post.initialize_title_for = function(post) {
|
||||
var $post = $(post);
|
||||
var $img = $post.find("img");
|
||||
$img.attr("title", $post.attr("data-tags") + " user:" + $post.attr("data-uploader") + " rating:" + $post.data("rating") + " score:" + $post.data("score"));
|
||||
}
|
||||
|
||||
Danbooru.Post.initialize_post_image_resize_links = function() {
|
||||
$("#image-resize-link").click(function(e) {
|
||||
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();
|
||||
});
|
||||
|
||||
if ($("#image-resize-notice").length && Danbooru.meta("enable-js-navigation") === "true") {
|
||||
$(document).bind("keypress", "v", 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.initialize_post_image_resize_to_window_link = function() {
|
||||
$("#image-resize-to-window-link").click(function(e) {
|
||||
var $img = $("#image");
|
||||
|
||||
if (($img.data("scale_factor") === 1) || ($img.data("scale_factor") === undefined)) {
|
||||
$img.data("original_width", $img.width());
|
||||
$img.data("original_height", $img.height());
|
||||
var client_width = $(window).width() - $("#sidebar").width() - 75;
|
||||
var client_height = $(window).height();
|
||||
|
||||
if ($img.width() > client_width) {
|
||||
var ratio = client_width / $img.width();
|
||||
$img.data("scale_factor", ratio);
|
||||
$img.css("width", $img.width() * ratio);
|
||||
$img.css("height", $img.height() * ratio);
|
||||
}
|
||||
} else {
|
||||
$img.data("scale_factor", 1);
|
||||
$img.width($img.data("original_width"));
|
||||
$img.height($img.data("original_height"));
|
||||
}
|
||||
|
||||
Danbooru.Note.Box.scale_all();
|
||||
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()) && !/Deleted posts/.test($("#related-box").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();
|
||||
} 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();
|
||||
}
|
||||
|
||||
$("#post-sections li").removeClass("active");
|
||||
$(e.target).parent("li").addClass("active");
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#post-sections li:first-child").addClass("active");
|
||||
$("#notes").hide();
|
||||
$("#edit").hide();
|
||||
}
|
||||
|
||||
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_children) {
|
||||
$post.addClass("post-status-has-children");
|
||||
}
|
||||
Danbooru.Post.initialize_title_for($post);
|
||||
}
|
||||
|
||||
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>');
|
||||
$("#post_" + post_id).effect("shake", {distance: 5, times: 1}, 100);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.Post.approve = function(post_id) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/moderator/post/approval.json",
|
||||
data: {"post_id": post_id},
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
if (!data.success) {
|
||||
Danbooru.error("Error: " + data.reason);
|
||||
} else {
|
||||
var $post = $("#post_" + post_id);
|
||||
$post.data("flags", $post.data("flags").replace(/pending/, ""));
|
||||
$post.removeClass("post-status-pending");
|
||||
Danbooru.notice("Approved post #" + post_id);
|
||||
$("#pending-approval-notice").hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.Post.save_search = function() {
|
||||
$.post(
|
||||
"/saved_searches.js",
|
||||
{"saved_search[tag_query]": $("#tags").val()}
|
||||
);
|
||||
}
|
||||
})();
|
||||
|
||||
$(document).ready(function() {
|
||||
Danbooru.Post.initialize_all();
|
||||
});
|
||||
269
app/assets/javascripts/default/related_tag.js
Normal file
269
app/assets/javascripts/default/related_tag.js
Normal file
@@ -0,0 +1,269 @@
|
||||
(function() {
|
||||
Danbooru.RelatedTag = {};
|
||||
|
||||
Danbooru.RelatedTag.initialize_all = function() {
|
||||
if ($("#c-posts").length || $("#c-uploads").length) {
|
||||
this.initialize_buttons();
|
||||
$("#related-tags-container").hide();
|
||||
$("#artist-tags-container").hide();
|
||||
$("#upload_tag_string,#post_tag_string").keyup(Danbooru.RelatedTag.update_selected);
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.RelatedTag.initialize_buttons = function() {
|
||||
this.common_bind("#related-tags-button", "");
|
||||
this.common_bind("#related-artists-button", "artist");
|
||||
this.common_bind("#related-characters-button", "character");
|
||||
this.common_bind("#related-copyrights-button", "copyright");
|
||||
$("#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>");
|
||||
$("#related-tags-container").show();
|
||||
$.get("/related_tag.json", {
|
||||
"query": Danbooru.RelatedTag.current_tag(),
|
||||
"category": category
|
||||
}).success(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.get(0).selectionStart;
|
||||
var b = $field.get(0).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;
|
||||
}
|
||||
|
||||
$("#related-tags").show();
|
||||
$("#toggle-related-tags-link").html("«");
|
||||
|
||||
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 $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"));
|
||||
}
|
||||
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].urls, function(i, url) {
|
||||
tags.push([" " + url.url, 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 {
|
||||
$ul.append($("<li/>").text(tag[0]));
|
||||
}
|
||||
});
|
||||
|
||||
$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, " ") + " ");
|
||||
|
||||
$field[0].selectionStart = $field.val().length;
|
||||
Danbooru.RelatedTag.update_selected();
|
||||
if (Danbooru.RelatedTag.recent_artist && $("#artist-tags-container").css("display") === "block") {
|
||||
Danbooru.RelatedTag.process_artist(Danbooru.RelatedTag.recent_artist);
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
Danbooru.RelatedTag.find_artist = function(e) {
|
||||
$("#artist-tags").html("<em>Loading...</em>");
|
||||
var url = $("#upload_source,#post_source");
|
||||
$.get("/artists/finder.json", {"url": url.val()}).success(Danbooru.RelatedTag.process_artist);
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
Danbooru.RelatedTag.process_artist = function(data) {
|
||||
Danbooru.RelatedTag.recent_artists = data;
|
||||
Danbooru.RelatedTag.build_all();
|
||||
}
|
||||
})();
|
||||
|
||||
$(function() {
|
||||
Danbooru.RelatedTag.initialize_all();
|
||||
});
|
||||
70
app/assets/javascripts/default/shortcuts.js
Normal file
70
app/assets/javascripts/default/shortcuts.js
Normal file
@@ -0,0 +1,70 @@
|
||||
(function() {
|
||||
Danbooru.Shortcuts = {};
|
||||
|
||||
Danbooru.Shortcuts.initialize = function() {
|
||||
$(document).bind("keypress", "s", function(e) {
|
||||
Danbooru.Shortcuts.nav_scroll_down();
|
||||
});
|
||||
|
||||
$(document).bind("keypress", "w", function(e) {
|
||||
Danbooru.Shortcuts.nav_scroll_up();
|
||||
});
|
||||
|
||||
$(document).bind("keypress", "q", function(e) {
|
||||
$("#tags, #search_name, #search_name_matches, #query").trigger("focus").selectEnd();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
if ($("#image").length) { // post page or bookmarklet upload page
|
||||
$(document).bind("keypress", "shift+e", function(e) {
|
||||
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").length && $("#a-show").length) {
|
||||
$(document).bind("keypress", "shift+o", function(e) {
|
||||
Danbooru.Post.approve(Danbooru.meta("post-id"));
|
||||
});
|
||||
|
||||
$(document).bind("keypress", "r", function(e) {
|
||||
$("#random-post")[0].click();
|
||||
});
|
||||
}
|
||||
|
||||
if ($("#c-posts").length && $("#a-index").length) {
|
||||
$(document).bind("keypress", "r", 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() {
|
||||
if (Danbooru.meta("enable-js-navigation") === "true") {
|
||||
Danbooru.Shortcuts.initialize();
|
||||
}
|
||||
});
|
||||
11
app/assets/javascripts/default/sources.js
Normal file
11
app/assets/javascripts/default/sources.js
Normal file
@@ -0,0 +1,11 @@
|
||||
(function() {
|
||||
Danbooru.Sources = {};
|
||||
|
||||
Danbooru.Sources.get = function(url) {
|
||||
$.get("/sources.json", {
|
||||
url: url
|
||||
}).success(function(data) {
|
||||
}).error(function(data) {
|
||||
});
|
||||
}
|
||||
})();
|
||||
57
app/assets/javascripts/default/tag_script.js
Normal file
57
app/assets/javascripts/default/tag_script.js
Normal file
@@ -0,0 +1,57 @@
|
||||
(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):/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")});
|
||||
}
|
||||
})();
|
||||
128
app/assets/javascripts/default/uploads.js
Normal file
128
app/assets/javascripts/default/uploads.js
Normal file
@@ -0,0 +1,128 @@
|
||||
(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) {
|
||||
this.initialize_image();
|
||||
this.initialize_info_bookmarklet();
|
||||
this.initialize_similar();
|
||||
$("#related-tags-button").trigger("click");
|
||||
$("#find-artist-button").trigger("click");
|
||||
}
|
||||
|
||||
if ($("#iqdb-similar").length) {
|
||||
this.initialize_iqdb_source();
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Upload.initialize_iqdb_source = function() {
|
||||
if (/^https?:\/\//.test($("#normalized_url").val())) {
|
||||
$.post("/iqdb_queries", {"url": $("#normalized_url").val()}).done(function(html) {$("#iqdb-similar").html(html)});
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.Upload.initialize_enter_on_tags = function() {
|
||||
$("#upload_tag_string,#post_tag_string").bind("keydown", "return", function(e) {
|
||||
if (!Danbooru.autocompleting) {
|
||||
$("#form").trigger("submit");
|
||||
$("#quick-edit-form").trigger("submit");
|
||||
}
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.Upload.initialize_similar = function() {
|
||||
$("#similar-button").click(function(e) {
|
||||
$.post("/iqdb_queries", {"url": $("#upload_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.Upload.initialize_info_bookmarklet = function() {
|
||||
$("#source-info ul").hide();
|
||||
$("#fetch-data-bookmarklet").click(function(e) {
|
||||
$.get(e.target.href).success(Danbooru.Upload.fill_source_info);
|
||||
e.preventDefault();
|
||||
});
|
||||
$("#fetch-data-bookmarklet").trigger("click");
|
||||
}
|
||||
|
||||
Danbooru.Upload.initialize_info_manual = function() {
|
||||
$("#source-info ul").hide();
|
||||
|
||||
$("#fetch-data-manual").click(function(e) {
|
||||
var source = $("#upload_source,#post_source").val();
|
||||
if (!/\S/.test(source)) {
|
||||
Danbooru.error("Error: You must enter a URL into the source field to get its data");
|
||||
} else if (!/^https?:\/\//.test(source)) {
|
||||
Danbooru.error("Error: Source is not a URL");
|
||||
} else {
|
||||
$("#source-info span#loading-data").show();
|
||||
$.get("/source.json?url=" + encodeURIComponent(source)).success(Danbooru.Upload.fill_source_info);
|
||||
}
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.Upload.fill_source_info = function(data) {
|
||||
var tag_html = "";
|
||||
$.each(data.tags, function(i, v) {
|
||||
tag_html += ('<a href="' + v[1] + '">' + v[0] + '</a> ');
|
||||
});
|
||||
|
||||
$("#source-artist").html('<a href="' + data.profile_url + '">' + data.artist_name + '</a>');
|
||||
$("#source-tags").html(tag_html);
|
||||
|
||||
Danbooru.RelatedTag.translated_tags = data.translated_tags;
|
||||
Danbooru.RelatedTag.build_all();
|
||||
|
||||
var new_artist_link = '<a target="_blank" href="/artists/new?other_names=' + data.artist_name + '&urls=' + encodeURIComponent(data.profile_url + '\n' + data.image_url) + '">new</a>';
|
||||
|
||||
$("#source-record").html(new_artist_link);
|
||||
|
||||
if (data.page_count > 1) {
|
||||
$("#gallery-warning").show();
|
||||
} else {
|
||||
$("#gallery-warning").hide();
|
||||
}
|
||||
|
||||
$("#source-info span#loading-data").hide();
|
||||
$("#source-info ul").show();
|
||||
}
|
||||
|
||||
Danbooru.Upload.initialize_image = function() {
|
||||
var $image = $("#image");
|
||||
if ($image.size() > 0) {
|
||||
var height = $image.height();
|
||||
var width = $image.width();
|
||||
if (height > 400) {
|
||||
var ratio = 400.0 / height;
|
||||
$image.height(height * ratio);
|
||||
$image.width(width * ratio);
|
||||
$("#scale").html("Scaled " + parseInt(100 * ratio) + "% (original: " + width + "x" + height + ")");
|
||||
$image.resizable({
|
||||
maxHeight: height,
|
||||
maxWidth: width,
|
||||
aspectRatio: width/height,
|
||||
handles: "e, s, se",
|
||||
resize: function( event, ui ){
|
||||
var origin_width = ui.element.resizable("option","maxWidth");
|
||||
var origin_height = ui.element.resizable("option","maxHeight");
|
||||
var height = ui.size.height;
|
||||
var ratio = height/origin_height;
|
||||
$("#scale").html("Scaled " + parseInt(100 * ratio) + "% (original: " + origin_width + "x" + origin_height + ")");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
$(function() {
|
||||
Danbooru.Upload.initialize_all();
|
||||
});
|
||||
123
app/assets/javascripts/default/utility.js
Normal file
123
app/assets/javascripts/default/utility.js
Normal file
@@ -0,0 +1,123 @@
|
||||
(function() {
|
||||
Danbooru.meta = function(key) {
|
||||
return $("meta[name=" + key + "]").attr("content");
|
||||
}
|
||||
|
||||
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.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");
|
||||
}
|
||||
|
||||
$.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;
|
||||
}
|
||||
})();
|
||||
64
app/assets/javascripts/default/wiki_pages.js
Normal file
64
app/assets/javascripts/default/wiki_pages.js
Normal file
@@ -0,0 +1,64 @@
|
||||
(function() {
|
||||
Danbooru.WikiPage = {};
|
||||
|
||||
Danbooru.WikiPage.initialize_all = function() {
|
||||
if ($("#c-wiki-pages").length) {
|
||||
if (Danbooru.meta("enable-auto-complete") === "true") {
|
||||
this.initialize_autocomplete();
|
||||
}
|
||||
|
||||
if (Danbooru.meta("enable-js-navigation") === "true") {
|
||||
this.initialize_shortcuts();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Danbooru.WikiPage.initialize_autocomplete = function() {
|
||||
var $fields = $("#search_title,#quick_search_title");
|
||||
|
||||
$fields.autocomplete({
|
||||
minLength: 1,
|
||||
source: function(req, resp) {
|
||||
$.ajax({
|
||||
url: "/wiki_pages.json",
|
||||
data: {
|
||||
"search[title]": "*" + req.term + "*",
|
||||
"limit": 10
|
||||
},
|
||||
method: "get",
|
||||
success: function(data) {
|
||||
resp($.map(data, function(wiki_page) {
|
||||
return {
|
||||
label: wiki_page.title.replace(/_/g, " "),
|
||||
value: wiki_page.title,
|
||||
category: wiki_page.category_name
|
||||
};
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var render_wiki_page = function(list, wiki_page) {
|
||||
var $link = $("<a/>").addClass("tag-type-" + wiki_page.category).text(wiki_page.label);
|
||||
return $("<li/>").data("item.autocomplete", wiki_page).append($link).appendTo(list);
|
||||
};
|
||||
|
||||
$fields.each(function(i, field) {
|
||||
$(field).data("uiAutocomplete")._renderItem = render_wiki_page;
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.WikiPage.initialize_shortcuts = function() {
|
||||
if ($("#a-show").length) {
|
||||
$(document).bind("keypress", "e", function(e) {
|
||||
$("#wiki-page-edit-link")[0].click();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
$(document).ready(function() {
|
||||
Danbooru.WikiPage.initialize_all();
|
||||
});
|
||||
Reference in New Issue
Block a user