Migrate assets to use Webpacker
This commit is contained in:
151
app/javascript/src/javascripts/artist_commentaries.js
Normal file
151
app/javascript/src/javascripts/artist_commentaries.js
Normal file
@@ -0,0 +1,151 @@
|
||||
let ArtistCommentary = {};
|
||||
|
||||
ArtistCommentary.initialize_all = function() {
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
if ($("#original-artist-commentary").length && $("#translated-artist-commentary").length) {
|
||||
this.initialize_commentary_display_tabs();
|
||||
}
|
||||
|
||||
this.initialize_edit_commentary_dialog();
|
||||
}
|
||||
}
|
||||
|
||||
ArtistCommentary.initialize_commentary_display_tabs = function() {
|
||||
$("#commentary-sections li a").click(function(e) {
|
||||
if (e.target.hash === "#original") {
|
||||
$("#original-artist-commentary").show();
|
||||
$("#translated-artist-commentary").hide();
|
||||
} else if (e.target.hash === "#translated") {
|
||||
$("#original-artist-commentary").hide();
|
||||
$("#translated-artist-commentary").show();
|
||||
}
|
||||
|
||||
$("#commentary-sections li").removeClass("active");
|
||||
$(e.target).parent("li").addClass("active");
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#commentary-sections li:last-child").addClass("active");
|
||||
$("#original-artist-commentary").hide();
|
||||
}
|
||||
|
||||
ArtistCommentary.initialize_edit_commentary_dialog = function() {
|
||||
$("#add-commentary-dialog").dialog({
|
||||
autoOpen: false,
|
||||
width: 500,
|
||||
buttons: {
|
||||
"Submit": function() {
|
||||
$("#add-commentary-dialog #edit-commentary").submit();
|
||||
$(this).dialog("close");
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#add-commentary-dialog #edit-commentary').submit(function() {
|
||||
$('#add-commentary-dialog').dialog('close');
|
||||
});
|
||||
|
||||
$("#add-commentary").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#add-commentary-dialog").dialog("open");
|
||||
});
|
||||
|
||||
$('#fetch-commentary select[name="commentary_source_type"]').change(function() {
|
||||
$("#fetch-commentary input").toggle();
|
||||
});
|
||||
|
||||
$('#fetch-commentary button[type="submit"]').click(ArtistCommentary.fetch_commentary);
|
||||
}
|
||||
|
||||
ArtistCommentary.fetch_commentary = function() {
|
||||
Utility.notice("Fetching artist commentary...");
|
||||
|
||||
var type = $('#fetch-commentary select[name="commentary_source_type"]').val();
|
||||
if (type === "Source") {
|
||||
var source = $('#fetch-commentary input[name="commentary_source"]').val();
|
||||
var commentary = ArtistCommentary.from_source(source);
|
||||
} else if (type === "Post") {
|
||||
var id = $('#fetch-commentary input[name="commentary_post_id"]').val();
|
||||
var commentary = ArtistCommentary.from_post_id(id);
|
||||
}
|
||||
|
||||
commentary.then(ArtistCommentary.fill_commentary).then(function (success) {
|
||||
var message = success ? "Artist commentary copied." : "Artist commentary copied; conflicting fields ignored.";
|
||||
Utility.notice(message);
|
||||
}).catch(function () {
|
||||
Utility.notice("Fetching artist commentary failed.");
|
||||
});
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
ArtistCommentary.from_source = function(source) {
|
||||
return $.get("/source.json?url=" + encodeURIComponent(source)).then(function(data) {
|
||||
return {
|
||||
original_title: data.artist_commentary.dtext_title,
|
||||
original_description: data.artist_commentary.dtext_description,
|
||||
source: source,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
ArtistCommentary.from_post_id = function(post_id) {
|
||||
return $.get("/posts/" + encodeURIComponent(post_id) + "/artist_commentary.json").then(function(commentary) {
|
||||
commentary.source = "post #" + post_id;
|
||||
return commentary;
|
||||
});
|
||||
};
|
||||
|
||||
ArtistCommentary.fill_commentary = function(commentary) {
|
||||
var description = ArtistCommentary.merge_commentaries($("#artist_commentary_original_description").val().trim(), commentary);
|
||||
$("#artist_commentary_original_description").val(description);
|
||||
|
||||
// Update the other fields if they're blank. Return success if none conflict.
|
||||
return [
|
||||
ArtistCommentary.update_field($("#artist_commentary_original_title"), commentary.original_title),
|
||||
ArtistCommentary.update_field($("#artist_commentary_translated_title"), commentary.translated_title),
|
||||
ArtistCommentary.update_field($("#artist_commentary_translated_description"), commentary.translated_description),
|
||||
].every(function (i) { return i; });
|
||||
};
|
||||
|
||||
// If the new description conflicts with the current description, merge them
|
||||
// by appending the new description onto the old one.
|
||||
ArtistCommentary.merge_commentaries = function(description, commentary) {
|
||||
var post_source = $('#image-container').data().source;
|
||||
var normalized_source = $("#image-container").data().normalizedSource;
|
||||
|
||||
if ((commentary.original_description && description) &&
|
||||
(commentary.original_description != description)) {
|
||||
return description
|
||||
+ "\n\n[tn]\nSource: " + normalized_source + "\n[/tn]"
|
||||
+ "\n\nh6. " + (commentary.original_title || "Untitled")
|
||||
+ "\n\n" + commentary.original_description
|
||||
+ "\n\n[tn]\nSource: " + commentary.source + "\n[/tn]";
|
||||
} else if (commentary.source != post_source) {
|
||||
return commentary.original_description + "\n\n[tn]\nSource: " + commentary.source + "\n[/tn]";
|
||||
} else {
|
||||
return commentary.original_description || description;
|
||||
}
|
||||
};
|
||||
|
||||
// Update commentary field if it's blank, signal an error if there's a conflict.
|
||||
ArtistCommentary.update_field = function($field, value) {
|
||||
if ($field.val().trim() === "") {
|
||||
$field.val(value);
|
||||
return true;
|
||||
} else if ($field.val().trim() !== value) {
|
||||
$field.effect("shake", { direction: "up", distance: 5 });
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
ArtistCommentary.initialize_all();
|
||||
});
|
||||
|
||||
export default ArtistCommentary
|
||||
46
app/javascript/src/javascripts/artists.js
Normal file
46
app/javascript/src/javascripts/artists.js
Normal file
@@ -0,0 +1,46 @@
|
||||
let Artist = {};
|
||||
|
||||
Artist.initialize_all = function() {
|
||||
if ($("#c-artists").length) {
|
||||
Artist.initialize_check_name();
|
||||
Artist.initialize_shortcuts();
|
||||
}
|
||||
}
|
||||
|
||||
Artist.initialize_check_name = function() {
|
||||
$("#artist_name").keyup(function(e) {
|
||||
if ($("#artist_name").val().length > 0) {
|
||||
$("#check-name-result").html("");
|
||||
|
||||
$.getJSON("/artists?search[name]=" + escape($("#artist_name").val()), function(data) {
|
||||
if (data.length === 0) {
|
||||
$.getJSON("/wiki_pages/" + escape($("#artist_name").val()), function(data) {
|
||||
if (data !== null) {
|
||||
$("#check-name-result").html("<a href='/wiki_pages/" + escape($("#artist_name").val()) + "'>A wiki page with this name already exists</a>. You must either move the wiki page or pick another artist name.")
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$("#check-name-result").html("An artist with this name already exists.")
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Artist.initialize_shortcuts = function() {
|
||||
if ($("#c-artists #a-show").length) {
|
||||
Utility.keydown("e", "edit", function(e) {
|
||||
$("#artist-edit a")[0].click();
|
||||
});
|
||||
|
||||
Utility.keydown("shift+d", "delete", function(e) {
|
||||
$("#artist-delete a")[0].click();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
Artist.initialize_all();
|
||||
});
|
||||
|
||||
export default Artist
|
||||
526
app/javascript/src/javascripts/autocomplete.js.erb
Normal file
526
app/javascript/src/javascripts/autocomplete.js.erb
Normal file
@@ -0,0 +1,526 @@
|
||||
export { AutoComplete }
|
||||
|
||||
import Utility from './utility'
|
||||
import SavedSearch from './saved_searches'
|
||||
|
||||
let Autocomplete = {};
|
||||
|
||||
Autocomplete.AUTOCOMPLETE_VERSION = 1;
|
||||
Autocomplete.PREFIXES = /^(-|~|<%= TagCategory.mapping.keys.map {|category| category + ':'}.join('|') %>)(.*)$/i;
|
||||
Autocomplete.METATAGS = /^(<%= Tag::METATAGS %>):(.*)$/i;
|
||||
|
||||
Autocomplete.initialize_all = function() {
|
||||
if (Utility.meta("enable-auto-complete") === "true") {
|
||||
$.widget("ui.autocomplete", $.ui.autocomplete, {
|
||||
options: {
|
||||
delay: 0,
|
||||
minLength: 1,
|
||||
autoFocus: false,
|
||||
focus: function() { return false; },
|
||||
},
|
||||
_create: function() {
|
||||
this.element.on("keydown.Autocomplete.tab", null, "tab", Autocomplete.on_tab);
|
||||
this._super();
|
||||
},
|
||||
_renderItem: Autocomplete.render_item,
|
||||
});
|
||||
|
||||
this.initialize_tag_autocomplete();
|
||||
this.initialize_mention_autocomplete($(".autocomplete-mentions textarea"));
|
||||
this.initialize_artist_autocomplete($('[data-autocomplete="artist"]'));
|
||||
this.initialize_pool_autocomplete($('[data-autocomplete="pool"]'));
|
||||
this.initialize_wiki_autocomplete($('[data-autocomplete="wiki-page"]'));
|
||||
}
|
||||
}
|
||||
|
||||
Autocomplete.initialize_mention_autocomplete = function($fields) {
|
||||
$fields.autocomplete({
|
||||
search: function() {
|
||||
$(this).data("ui-autocomplete").menu.bindings = $();
|
||||
},
|
||||
select: function(event, ui) {
|
||||
Autocomplete.insert_completion(this, ui.item.value);
|
||||
return false;
|
||||
},
|
||||
source: function(req, resp) {
|
||||
var cursor = this.element.get(0).selectionStart;
|
||||
var i;
|
||||
var name = null;
|
||||
|
||||
for (i=cursor; i>=1; --i) {
|
||||
if (req.term[i-1] === " ") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.term[i-1] === "@") {
|
||||
if (i == 1 || /[ \r\n]/.test(req.term[i-2])) {
|
||||
name = req.term.substring(i, cursor);
|
||||
break;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (name) {
|
||||
Autocomplete.user_source(name, resp, "@");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Autocomplete.initialize_tag_autocomplete = function() {
|
||||
var $fields_multiple = $('[data-autocomplete="tag-query"], [data-autocomplete="tag-edit"]');
|
||||
var $fields_single = $('[data-autocomplete="tag"]');
|
||||
|
||||
$fields_multiple.autocomplete({
|
||||
search: function() {
|
||||
if ($(this).data("ui-autocomplete")) {
|
||||
$(this).data("ui-autocomplete").menu.bindings = $();
|
||||
}
|
||||
},
|
||||
select: function(event, ui) {
|
||||
// Prevent Upload.initialize_enter_on_tags from running if the
|
||||
// Enter key is used to select a tag from the autocomplete menu.
|
||||
if (event.key === "Enter") {
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
Autocomplete.insert_completion(this, ui.item.value);
|
||||
return false;
|
||||
},
|
||||
source: function(req, resp) {
|
||||
var query = Autocomplete.parse_query(req.term, this.element.get(0).selectionStart);
|
||||
var metatag = query.metatag;
|
||||
var term = query.term;
|
||||
|
||||
if (!metatag && !term) {
|
||||
this.close();
|
||||
return;
|
||||
}
|
||||
|
||||
switch(metatag) {
|
||||
case "md5":
|
||||
case "width":
|
||||
case "height":
|
||||
case "mpixels":
|
||||
case "ratio":
|
||||
case "score":
|
||||
case "favcount":
|
||||
case "filesize":
|
||||
case "source":
|
||||
case "id":
|
||||
case "date":
|
||||
case "age":
|
||||
case "limit":
|
||||
case "tagcount":
|
||||
case "pixiv_id":
|
||||
case "pixiv":
|
||||
<% TagCategory.short_name_list.each do |category| %>
|
||||
case "<%= category %>tags":
|
||||
<% end %>
|
||||
resp([]);
|
||||
return;
|
||||
case "order":
|
||||
case "status":
|
||||
case "rating":
|
||||
case "locked":
|
||||
case "child":
|
||||
case "parent":
|
||||
case "filetype":
|
||||
Autocomplete.static_metatag_source(term, resp, metatag);
|
||||
return;
|
||||
case "user":
|
||||
case "approver":
|
||||
case "commenter":
|
||||
case "comm":
|
||||
case "noter":
|
||||
case "noteupdater":
|
||||
case "artcomm":
|
||||
case "fav":
|
||||
case "ordfav":
|
||||
case "appealer":
|
||||
case "flagger":
|
||||
case "upvote":
|
||||
case "downvote":
|
||||
Autocomplete.user_source(term, resp, metatag);
|
||||
break;
|
||||
case "pool":
|
||||
case "ordpool":
|
||||
Autocomplete.pool_source(term, resp, metatag);
|
||||
break;
|
||||
case "favgroup":
|
||||
Autocomplete.favorite_group_source(term, resp, metatag);
|
||||
break;
|
||||
case "search":
|
||||
Autocomplete.saved_search_source(term, resp);
|
||||
break;
|
||||
default:
|
||||
Autocomplete.normal_source(term, resp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$fields_single.autocomplete({
|
||||
search: function() {
|
||||
$(this).data("ui-autocomplete").menu.bindings = $();
|
||||
},
|
||||
source: function(req, resp) {
|
||||
Autocomplete.normal_source(req.term, resp);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Autocomplete.initialize_artist_autocomplete = function($fields) {
|
||||
$fields.autocomplete({
|
||||
search: function() {
|
||||
$(this).data("ui-autocomplete").menu.bindings = $();
|
||||
},
|
||||
source: function(req, resp) {
|
||||
$.ajax({
|
||||
url: "/artists.json",
|
||||
data: {
|
||||
"search[name]": req.term + "*",
|
||||
"search[is_active]": true,
|
||||
"search[order]": "post_count",
|
||||
"limit": 10,
|
||||
"expiry": 7
|
||||
},
|
||||
method: "get",
|
||||
success: function(data) {
|
||||
resp($.map(data, function(artist) {
|
||||
return {
|
||||
type: "tag",
|
||||
label: artist.name.replace(/_/g, " "),
|
||||
value: artist.name,
|
||||
category: <%= Tag.categories.artist %>,
|
||||
};
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Autocomplete.initialize_pool_autocomplete = function($fields) {
|
||||
$fields.autocomplete({
|
||||
search: function() {
|
||||
$(this).data("ui-autocomplete").menu.bindings = $();
|
||||
},
|
||||
source: function(req, resp) {
|
||||
Autocomplete.pool_source(req.term, resp);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Autocomplete.initialize_wiki_autocomplete = function($fields) {
|
||||
$fields.autocomplete({
|
||||
search: function() {
|
||||
$(this).data("ui-autocomplete").menu.bindings = $();
|
||||
},
|
||||
source: function(req, resp) {
|
||||
$.ajax({
|
||||
url: "/wiki_pages.json",
|
||||
data: {
|
||||
"search[title]": req.term + "*",
|
||||
"search[hide_deleted]": "Yes",
|
||||
"search[order]": "post_count",
|
||||
"limit": 10,
|
||||
"expiry": 7
|
||||
},
|
||||
method: "get",
|
||||
success: function(data) {
|
||||
resp($.map(data, function(wiki_page) {
|
||||
return {
|
||||
type: "tag",
|
||||
label: wiki_page.title.replace(/_/g, " "),
|
||||
value: wiki_page.title,
|
||||
category: wiki_page.category_name
|
||||
};
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Autocomplete.normal_source = function(term, resp) {
|
||||
var key = "ac-" + term.replace(/\./g,'\uFFFF');
|
||||
|
||||
$.ajax({
|
||||
url: "/tags/autocomplete.json",
|
||||
data: {
|
||||
"search[name_matches]": term,
|
||||
"expiry": 7
|
||||
},
|
||||
method: "get",
|
||||
success: function(data) {
|
||||
var d = $.map(data, function(tag) {
|
||||
return {
|
||||
type: "tag",
|
||||
label: tag.name.replace(/_/g, " "),
|
||||
antecedent: tag.antecedent_name,
|
||||
value: tag.name,
|
||||
category: tag.category,
|
||||
post_count: tag.post_count
|
||||
};
|
||||
});
|
||||
|
||||
resp(d);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Autocomplete.parse_query = function(text, caret) {
|
||||
var metatag = "";
|
||||
var term = "";
|
||||
|
||||
var before_caret_text = text.substring(0, caret);
|
||||
var match = before_caret_text.match(/\S+$/g);
|
||||
if (match) {
|
||||
term = match[0];
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (match = term.match(Autocomplete.PREFIXES)) {
|
||||
metatag = match[1].toLowerCase();
|
||||
term = match[2];
|
||||
}
|
||||
|
||||
if (match = term.match(Autocomplete.METATAGS)) {
|
||||
metatag = match[1].toLowerCase();
|
||||
term = match[2];
|
||||
}
|
||||
|
||||
return { metatag: metatag, term: term };
|
||||
};
|
||||
|
||||
// Update the input field with the item currently focused in the
|
||||
// autocomplete menu, then position the caret just after the inserted completion.
|
||||
Autocomplete.insert_completion = function(input, completion) {
|
||||
var before_caret_text = input.value.substring(0, input.selectionStart).trim();
|
||||
var after_caret_text = input.value.substring(input.selectionStart).trim();
|
||||
|
||||
var prefixes = "-|~|" + "<%= TagCategory.mapping.keys.map {|category| category + ':'}.join('|') %>";
|
||||
var regexp = new RegExp("(" + prefixes + ")?\\S+$", "g");
|
||||
before_caret_text = before_caret_text.replace(regexp, "$1") + completion + " ";
|
||||
|
||||
input.value = before_caret_text + after_caret_text;
|
||||
input.selectionStart = input.selectionEnd = before_caret_text.length;
|
||||
};
|
||||
|
||||
// If we press tab while the autocomplete menu is open but nothing is
|
||||
// focused, complete the first item and close the menu.
|
||||
Autocomplete.on_tab = function(event) {
|
||||
var input = this;
|
||||
var autocomplete = $(input).autocomplete("instance");
|
||||
var $autocomplete_menu = autocomplete.menu.element;
|
||||
|
||||
if (!$autocomplete_menu.is(":visible")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($autocomplete_menu.has(".ui-state-active").length === 0) {
|
||||
var $first_item = $autocomplete_menu.find(".ui-menu-item").first();
|
||||
var completion = $first_item.data().uiAutocompleteItem.value;
|
||||
|
||||
Autocomplete.insert_completion(input, completion);
|
||||
autocomplete.close();
|
||||
}
|
||||
|
||||
// Prevent the tab key from moving focus to the next element.
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
Autocomplete.render_item = function(list, item) {
|
||||
var $link = $("<a/>");
|
||||
$link.text(item.label);
|
||||
$link.attr("href", "/posts?tags=" + encodeURIComponent(item.value));
|
||||
$link.click(function(e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
if (item.antecedent) {
|
||||
var antecedent = item.antecedent.replace(/_/g, " ");
|
||||
var arrow = $("<span/>").html(" → ").addClass("autocomplete-arrow");
|
||||
var antecedent_element = $("<span/>").text(antecedent).addClass("autocomplete-antecedent");
|
||||
$link.prepend([
|
||||
antecedent_element,
|
||||
arrow
|
||||
]);
|
||||
}
|
||||
|
||||
if (item.post_count !== undefined) {
|
||||
var count;
|
||||
if (item.post_count >= 1000) {
|
||||
count = Math.floor(item.post_count / 1000) + "k";
|
||||
} else {
|
||||
count = item.post_count;
|
||||
}
|
||||
var $post_count = $("<span/>").addClass("post-count").css("float", "right").text(count);
|
||||
$link.append($post_count);
|
||||
}
|
||||
|
||||
if (item.type === "tag") {
|
||||
$link.addClass("tag-type-" + item.category);
|
||||
} else if (item.type === "user") {
|
||||
var level_class = "user-" + item.level.toLowerCase();
|
||||
$link.addClass(level_class);
|
||||
if (Utility.meta("style-usernames") === "true") {
|
||||
$link.addClass("with-style");
|
||||
}
|
||||
} else if (item.type === "pool") {
|
||||
$link.addClass("pool-category-" + item.category);
|
||||
}
|
||||
|
||||
var $menu_item = $("<div/>").append($link);
|
||||
return $("<li/>").data("item.autocomplete", item).append($menu_item).appendTo(list);
|
||||
};
|
||||
|
||||
Autocomplete.static_metatags = {
|
||||
order: [
|
||||
"id", "id_desc",
|
||||
"score", "score_asc",
|
||||
"favcount", "favcount_asc",
|
||||
"created_at", "created_at_asc",
|
||||
"change", "change_asc",
|
||||
"comment", "comment_asc",
|
||||
"comment_bumped", "comment_bumped_asc",
|
||||
"note", "note_asc",
|
||||
"artcomm", "artcomm_asc",
|
||||
"mpixels", "mpixels_asc",
|
||||
"portrait", "landscape",
|
||||
"filesize", "filesize_asc",
|
||||
"tagcount", "tagcount_asc",
|
||||
"rank",
|
||||
"random",
|
||||
"custom"
|
||||
].concat(<%= TagCategory.short_name_list.map {|category| [category + "tags", category + "tags_asc"]}.flatten %>),
|
||||
status: [
|
||||
"any", "deleted", "active", "pending", "flagged", "banned"
|
||||
],
|
||||
rating: [
|
||||
"safe", "questionable", "explicit"
|
||||
],
|
||||
locked: [
|
||||
"rating", "note", "status"
|
||||
],
|
||||
child: [
|
||||
"any", "none"
|
||||
],
|
||||
parent: [
|
||||
"any", "none"
|
||||
],
|
||||
filetype: [
|
||||
"jpg", "png", "gif", "swf", "zip", "webm", "mp4"
|
||||
],
|
||||
}
|
||||
|
||||
Autocomplete.static_metatag_source = function(term, resp, metatag) {
|
||||
var sub_metatags = this.static_metatags[metatag];
|
||||
|
||||
var regexp = new RegExp("^" + $.ui.autocomplete.escapeRegex(term), "i");
|
||||
var matches = $.grep(sub_metatags, function (sub_metatag) {
|
||||
return regexp.test(sub_metatag);
|
||||
});
|
||||
|
||||
resp($.map(matches, function(sub_metatag) {
|
||||
return metatag + ":" + sub_metatag;
|
||||
}));
|
||||
}
|
||||
|
||||
Autocomplete.user_source = function(term, resp, metatag) {
|
||||
$.ajax({
|
||||
url: "/users.json",
|
||||
data: {
|
||||
"search[order]": "post_upload_count",
|
||||
"search[current_user_first]": "true",
|
||||
"search[name_matches]": term + "*",
|
||||
"limit": 10
|
||||
},
|
||||
method: "get",
|
||||
success: function(data) {
|
||||
var prefix;
|
||||
var display_name;
|
||||
|
||||
if (metatag === "@") {
|
||||
prefix = "@";
|
||||
display_name = function(name) {return name;};
|
||||
} else {
|
||||
prefix = metatag + ":";
|
||||
display_name = function(name) {return name.replace(/_/g, " ");};
|
||||
}
|
||||
|
||||
resp($.map(data, function(user) {
|
||||
return {
|
||||
type: "user",
|
||||
label: display_name(user.name),
|
||||
value: prefix + user.name,
|
||||
level: user.level_string
|
||||
};
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Autocomplete.pool_source = function(term, resp, metatag) {
|
||||
$.ajax({
|
||||
url: "/pools.json",
|
||||
data: {
|
||||
"search[order]": "post_count",
|
||||
"search[name_matches]": term,
|
||||
"limit": 10
|
||||
},
|
||||
method: "get",
|
||||
success: function(data) {
|
||||
resp($.map(data, function(pool) {
|
||||
return {
|
||||
type: "pool",
|
||||
label: pool.name.replace(/_/g, " "),
|
||||
value: (metatag ? (metatag + ":" + pool.name) : pool.name),
|
||||
post_count: pool.post_count,
|
||||
category: pool.category
|
||||
};
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Autocomplete.favorite_group_source = function(term, resp, metatag) {
|
||||
$.ajax({
|
||||
url: "/favorite_groups.json",
|
||||
data: {
|
||||
"search[name_matches]": term,
|
||||
"limit": 10
|
||||
},
|
||||
method: "get",
|
||||
success: function(data) {
|
||||
resp($.map(data, function(favgroup) {
|
||||
return {
|
||||
label: favgroup.name.replace(/_/g, " "),
|
||||
value: metatag + ":" + favgroup.name,
|
||||
post_count: favgroup.post_count
|
||||
};
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Autocomplete.saved_search_source = function(term, resp) {
|
||||
return SavedSearch.labels(term).then(function(labels) {
|
||||
resp(labels.map(function(label) {
|
||||
return {
|
||||
label: label.replace(/_/g, " "),
|
||||
value: "search:" + label,
|
||||
};
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
Autocomplete.initialize_all();
|
||||
});
|
||||
203
app/javascript/src/javascripts/blacklists.js
Normal file
203
app/javascript/src/javascripts/blacklists.js
Normal file
@@ -0,0 +1,203 @@
|
||||
import Utility from './utility'
|
||||
import Cookie from './cookie'
|
||||
|
||||
let Blacklist = {};
|
||||
|
||||
Blacklist.entries = [];
|
||||
|
||||
Blacklist.parse_entry = function(string) {
|
||||
var entry = {
|
||||
"tags": string,
|
||||
"require": [],
|
||||
"exclude": [],
|
||||
"disabled": false,
|
||||
"hits": 0,
|
||||
"min_score": null
|
||||
};
|
||||
var matches = string.match(/\S+/g) || [];
|
||||
$.each(matches, function(i, tag) {
|
||||
if (tag.charAt(0) === '-') {
|
||||
entry.exclude.push(tag.slice(1));
|
||||
} else if (tag.match(/^score:<.+/)) {
|
||||
var score = tag.match(/^score:<(.+)/)[1];
|
||||
entry.min_score = parseInt(score);
|
||||
} else {
|
||||
entry.require.push(tag);
|
||||
}
|
||||
});
|
||||
return entry;
|
||||
}
|
||||
|
||||
Blacklist.parse_entries = function() {
|
||||
var entries = (Utility.meta("blacklisted-tags") || "nozomiisthebestlovelive").replace(/(rating:[qes])\w+/ig, "$1").toLowerCase().split(/,/);
|
||||
|
||||
$.each(entries, function(i, tags) {
|
||||
var entry = Blacklist.parse_entry(tags);
|
||||
Blacklist.entries.push(entry);
|
||||
});
|
||||
}
|
||||
|
||||
Blacklist.toggle_entry = function(e) {
|
||||
var tags = $(e.target).text();
|
||||
var match = $.grep(Blacklist.entries, function(entry, i) {
|
||||
return entry.tags === tags;
|
||||
})[0];
|
||||
if (match) {
|
||||
match.disabled = !match.disabled;
|
||||
if (match.disabled) {
|
||||
Blacklist.post_hide(e.target);
|
||||
} else {
|
||||
Blacklist.post_unhide(e.target);
|
||||
}
|
||||
}
|
||||
Blacklist.apply();
|
||||
}
|
||||
|
||||
Blacklist.update_sidebar = function() {
|
||||
$.each(this.entries, function(i, entry) {
|
||||
if (entry.hits === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var item = $("<li/>");
|
||||
var link = $("<a/>");
|
||||
var count = $("<span/>");
|
||||
var hash = entry.tags.hash();
|
||||
|
||||
link.text(entry.tags);
|
||||
link.click(Blacklist.toggle_entry);
|
||||
count.html(entry.hits);
|
||||
count.addClass("count");
|
||||
item.append(link);
|
||||
item.append(" ");
|
||||
item.append(count);
|
||||
|
||||
$("#blacklist-list").append(item);
|
||||
});
|
||||
|
||||
$("#blacklist-box").show();
|
||||
}
|
||||
|
||||
Blacklist.initialize_disable_all_blacklists = function() {
|
||||
if (Cookie.get("dab") === "1") {
|
||||
$("#re-enable-all-blacklists").show();
|
||||
$("#blacklist-list a:not(.blacklisted-active)").click();
|
||||
Blacklist.apply();
|
||||
} else {
|
||||
$("#disable-all-blacklists").show()
|
||||
}
|
||||
|
||||
$("#disable-all-blacklists").click(function(e) {
|
||||
$("#disable-all-blacklists").hide();
|
||||
$("#re-enable-all-blacklists").show();
|
||||
Cookie.put("dab", "1");
|
||||
$("#blacklist-list a:not(.blacklisted-active)").click();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#re-enable-all-blacklists").click(function(e) {
|
||||
$("#disable-all-blacklists").show();
|
||||
$("#re-enable-all-blacklists").hide();
|
||||
Cookie.put("dab", "0");
|
||||
$("#blacklist-list a.blacklisted-active").click();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Blacklist.apply = function() {
|
||||
$.each(this.entries, function(i, entry) {
|
||||
entry.hits = 0;
|
||||
});
|
||||
|
||||
var count = 0
|
||||
|
||||
$.each(this.posts(), function(i, post) {
|
||||
var post_count = 0;
|
||||
$.each(Blacklist.entries, function(i, entry) {
|
||||
if (Blacklist.post_match(post, entry)) {
|
||||
entry.hits += 1;
|
||||
count += 1;
|
||||
post_count += 1;
|
||||
}
|
||||
});
|
||||
if (post_count > 0) {
|
||||
Blacklist.post_hide(post);
|
||||
} else {
|
||||
Blacklist.post_unhide(post);
|
||||
}
|
||||
});
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
Blacklist.posts = function() {
|
||||
return $(".post-preview, #image-container, #c-comments .post");
|
||||
}
|
||||
|
||||
Blacklist.post_match = function(post, entry) {
|
||||
if (entry.disabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var $post = $(post);
|
||||
var score = parseInt($post.attr("data-score"));
|
||||
|
||||
if (entry.min_score !== null && score < entry.min_score) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var tags = String($post.attr("data-tags")).match(/\S+/g) || [];
|
||||
tags = tags.concat(String($post.attr("data-pools")).match(/\S+/g) || []);
|
||||
tags.push("rating:" + $post.data("rating"));
|
||||
if ($post.attr("data-uploader")) {
|
||||
tags.push("user:" + $post.attr("data-uploader").toLowerCase());
|
||||
}
|
||||
tags.push("uploaderid:" + $post.attr("data-uploader-id"));
|
||||
tags.push("toptaggerid:" + $post.attr("data-top-tagger"));
|
||||
$.each(String($post.data("flags")).match(/\S+/g) || [], function(i, v) {
|
||||
tags.push("status:" + v);
|
||||
});
|
||||
return (entry.require.length > 0 || entry.exclude.length > 0) && Utility.is_subset(tags, entry.require) && !Utility.intersect(tags, entry.exclude).length;
|
||||
}
|
||||
|
||||
Blacklist.post_hide = function(post) {
|
||||
var $post = $(post);
|
||||
$post.addClass("blacklisted").addClass("blacklisted-active");
|
||||
|
||||
var $video = $post.find("video").get(0);
|
||||
if ($video) {
|
||||
$video.pause();
|
||||
$video.currentTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Blacklist.post_unhide = function(post) {
|
||||
var $post = $(post);
|
||||
$post.addClass("blacklisted").removeClass("blacklisted-active");
|
||||
|
||||
var $video = $post.find("video").get(0);
|
||||
if ($video) {
|
||||
$video.play();
|
||||
}
|
||||
}
|
||||
|
||||
Blacklist.initialize_all = function() {
|
||||
Blacklist.parse_entries();
|
||||
|
||||
if (Blacklist.apply() > 0) {
|
||||
Blacklist.update_sidebar();
|
||||
Blacklist.initialize_disable_all_blacklists();
|
||||
} else {
|
||||
$("#blacklist-box").hide();
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
if ($("#blacklist-box").length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Blacklist.initialize_all();
|
||||
});
|
||||
|
||||
export default Blacklist
|
||||
124
app/javascript/src/javascripts/comments.js
Normal file
124
app/javascript/src/javascripts/comments.js
Normal file
@@ -0,0 +1,124 @@
|
||||
import Utility from './utility'
|
||||
import Dtext from './dtext'
|
||||
|
||||
let Comment = {};
|
||||
|
||||
Comment.initialize_all = function() {
|
||||
if ($("#c-posts").length || $("#c-comments").length) {
|
||||
this.initialize_response_link();
|
||||
this.initialize_reply_links();
|
||||
this.initialize_expand_links();
|
||||
this.initialize_vote_links();
|
||||
|
||||
if (!$("#a-edit").length) {
|
||||
this.initialize_edit_links();
|
||||
}
|
||||
}
|
||||
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
Comment.highlight_threshold_comments(Utility.meta("post-id"));
|
||||
}
|
||||
|
||||
$(window).on("danbooru:index_for_post", (post_id, current_comment_section, include_below_threshold) => {
|
||||
if (include_below_threshold) {
|
||||
$("#threshold-comments-notice-for-" + post_id).hide();
|
||||
} else {
|
||||
Comment.highlight_threshold_comments(post_id);
|
||||
}
|
||||
Comment.initialize_reply_links(current_comment_section);
|
||||
Comment.initialize_edit_links(current_comment_section);
|
||||
Comment.initialize_vote_links(current_comment_section);
|
||||
Dtext.initialize_expandables(current_comment_section);
|
||||
});
|
||||
}
|
||||
|
||||
Comment.quote = function(e) {
|
||||
$.get(
|
||||
"/comments/" + $(e.target).data('comment-id') + ".json",
|
||||
function(data) {
|
||||
var $link = $(e.target);
|
||||
var $div = $link.closest("div.comments-for-post").find(".new-comment");
|
||||
var $textarea = $div.find("textarea");
|
||||
var msg = data["quoted_response"];
|
||||
if ($textarea.val().length > 0) {
|
||||
msg = $textarea.val() + "\n\n" + msg;
|
||||
}
|
||||
$textarea.val(msg);
|
||||
$div.find("a.expand-comment-response").trigger("click");
|
||||
$textarea.selectEnd();
|
||||
}
|
||||
);
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
Comment.initialize_reply_links = function($parent) {
|
||||
$parent = $parent || $(document);
|
||||
$parent.find(".reply-link").click(Comment.quote);
|
||||
}
|
||||
|
||||
Comment.initialize_expand_links = function() {
|
||||
$(".comment-section form").hide();
|
||||
$(".comment-section input.expand-comment-response").click(function(e) {
|
||||
var post_id = $(this).closest(".comment-section").data("post-id");
|
||||
$(this).hide();
|
||||
$(".comment-section[data-post-id=" + post_id + "] form").slideDown("fast");
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Comment.initialize_response_link = function() {
|
||||
$("a.expand-comment-response").click(function(e) {
|
||||
$(e.target).hide();
|
||||
var $form = $(e.target).closest("div.new-comment").find("form");
|
||||
$form.show();
|
||||
Utility.scroll_to($form);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("div.new-comment form").hide();
|
||||
}
|
||||
|
||||
Comment.initialize_edit_links = function($parent) {
|
||||
$parent = $parent || $(document);
|
||||
$parent.find(".edit_comment").hide();
|
||||
$parent.find(".edit_comment_link").click(function(e) {
|
||||
var link_id = $(this).attr("id");
|
||||
var comment_id = link_id.match(/^edit_comment_link_(\d+)$/)[1];
|
||||
$("#edit_comment_" + comment_id).fadeToggle("fast");
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Comment.highlight_threshold_comments = function(post_id) {
|
||||
var threshold = parseInt(Utility.meta("user-comment-threshold"));
|
||||
var articles = $("article.comment[data-post-id=" + post_id + "]");
|
||||
articles.each(function(i, v) {
|
||||
var $comment = $(v);
|
||||
if (parseInt($comment.data("score")) < threshold) {
|
||||
$comment.addClass("below-threshold");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Comment.hide_threshold_comments = function(post_id) {
|
||||
var threshold = parseInt(Utility.meta("user-comment-threshold"));
|
||||
var articles = $("article.comment[data-post-id=" + post_id + "]");
|
||||
articles.each(function(i, v) {
|
||||
var $comment = $(v);
|
||||
if (parseInt($comment.data("score")) < threshold) {
|
||||
$comment.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Comment.initialize_vote_links = function($parent) {
|
||||
$parent = $parent || $(document);
|
||||
$parent.find(".unvote-comment-link").hide();
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
Comment.initialize_all();
|
||||
});
|
||||
|
||||
export default Comment
|
||||
|
||||
50
app/javascript/src/javascripts/common.js
Normal file
50
app/javascript/src/javascripts/common.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import Cookie from './cookie'
|
||||
import Utility from './utility'
|
||||
|
||||
$(function() {
|
||||
// Table striping
|
||||
$(".striped tbody tr:even").addClass("even");
|
||||
$(".striped tbody tr:odd").addClass("odd");
|
||||
|
||||
// Account notices
|
||||
$("#hide-sign-up-notice").click(function(e) {
|
||||
$("#sign-up-notice").hide();
|
||||
Cookie.put("hide_sign_up_notice", "1", 7);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#hide-upgrade-account-notice").click(function(e) {
|
||||
$("#upgrade-account-notice").hide();
|
||||
Cookie.put('hide_upgrade_account_notice', '1', 7);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#hide-dmail-notice").click(function(e) {
|
||||
var $dmail_notice = $("#dmail-notice");
|
||||
$dmail_notice.hide();
|
||||
var dmail_id = $dmail_notice.data("id");
|
||||
Cookie.put("hide_dmail_notice", dmail_id);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#close-notice-link").click(function(e) {
|
||||
$('#notice').fadeOut("fast");
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#desktop-version-link a").click(function(e) {
|
||||
e.preventDefault();
|
||||
$.ajax("/users/" + Utility.meta("current-user-id") + ".json", {
|
||||
method: "PUT",
|
||||
data: {
|
||||
"user[disable_responsive_mode]": "true"
|
||||
}
|
||||
}).then(function() {
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
global.submitInvisibleRecaptchaForm = function () {
|
||||
document.getElementById("signup-form").submit();
|
||||
}
|
||||
72
app/javascript/src/javascripts/cookie.js
Normal file
72
app/javascript/src/javascripts/cookie.js
Normal file
@@ -0,0 +1,72 @@
|
||||
let Cookie = {};
|
||||
|
||||
Cookie.put = function(name, value, days) {
|
||||
var expires = "";
|
||||
if (days !== "session") {
|
||||
if (!days) {
|
||||
days = 365;
|
||||
}
|
||||
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
expires = "expires=" + date.toGMTString() + "; ";
|
||||
}
|
||||
|
||||
var new_val = name + "=" + encodeURIComponent(value) + "; " + expires + "path=/";
|
||||
if (document.cookie.length < (4090 - new_val.length)) {
|
||||
document.cookie = new_val;
|
||||
return true;
|
||||
} else {
|
||||
Utility.error("You have too many cookies on this site. Consider deleting them all.")
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Cookie.raw_get = function(name) {
|
||||
var nameEq = name + "=";
|
||||
var ca = document.cookie.split(";");
|
||||
|
||||
for (var i = 0; i < ca.length; ++i) {
|
||||
var c = ca[i];
|
||||
|
||||
while (c.charAt(0) == " ") {
|
||||
c = c.substring(1, c.length);
|
||||
}
|
||||
|
||||
if (c.indexOf(nameEq) == 0) {
|
||||
return c.substring(nameEq.length, c.length);
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
Cookie.get = function(name) {
|
||||
return this.unescape(this.raw_get(name));
|
||||
}
|
||||
|
||||
Cookie.remove = function(name) {
|
||||
this.put(name, "", -1);
|
||||
}
|
||||
|
||||
Cookie.unescape = function(val) {
|
||||
return decodeURIComponent(val.replace(/\+/g, " "));
|
||||
}
|
||||
|
||||
Cookie.initialize = function() {
|
||||
var loc = location.href;
|
||||
|
||||
if (loc.match(/^http/)) {
|
||||
loc = loc.replace(/^https?:\/\/[^\/]+/, "");
|
||||
}
|
||||
|
||||
if (this.get("hide-upgrade-account") != "1") {
|
||||
$("#upgrade-account").show();
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
Cookie.initialize();
|
||||
});
|
||||
|
||||
export default Cookie
|
||||
68
app/javascript/src/javascripts/dtext.js
Normal file
68
app/javascript/src/javascripts/dtext.js
Normal file
@@ -0,0 +1,68 @@
|
||||
let Dtext = {};
|
||||
|
||||
Dtext.initialize_all = function() {
|
||||
Dtext.initialize_links();
|
||||
Dtext.initialize_expandables();
|
||||
}
|
||||
|
||||
Dtext.initialize_links = function() {
|
||||
$(".simple_form .dtext-preview").hide();
|
||||
$(".simple_form input[value=Preview]").click(Dtext.click_button);
|
||||
}
|
||||
|
||||
Dtext.initialize_expandables = function($parent) {
|
||||
$parent = $parent || $(document);
|
||||
$parent.find(".expandable-content").hide();
|
||||
$parent.find(".expandable-button").click(function(e) {
|
||||
var button = $(this);
|
||||
button.parent().next().fadeToggle("fast");
|
||||
if (button.val() === "Show") {
|
||||
button.val("Hide");
|
||||
} else {
|
||||
button.val("Show");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Dtext.call_preview = function(e, $button, $input, $preview) {
|
||||
$button.val("Edit");
|
||||
$input.hide();
|
||||
$preview.text("Loading...").fadeIn("fast");
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: "/dtext_preview",
|
||||
data: {
|
||||
body: $input.val()
|
||||
},
|
||||
success: function(data) {
|
||||
$preview.html(data).fadeIn("fast");
|
||||
Dtext.initialize_expandables($preview);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Dtext.call_edit = function(e, $button, $input, $preview) {
|
||||
$button.val("Preview");
|
||||
$preview.hide();
|
||||
$input.slideDown("fast");
|
||||
}
|
||||
|
||||
Dtext.click_button = function(e) {
|
||||
var $button = $(e.target);
|
||||
var $input = $("#" + $button.data("input-id"));
|
||||
var $preview = $("#" + $button.data("preview-id"));
|
||||
|
||||
if ($button.val().match(/preview/i)) {
|
||||
Dtext.call_preview(e, $button, $input, $preview);
|
||||
} else {
|
||||
Dtext.call_edit(e, $button, $input, $preview);
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
Dtext.initialize_all();
|
||||
});
|
||||
|
||||
export default Dtext
|
||||
53
app/javascript/src/javascripts/favorite_groups.js
Normal file
53
app/javascript/src/javascripts/favorite_groups.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import Utility from './utility'
|
||||
|
||||
let FavoriteGroup = {};
|
||||
|
||||
FavoriteGroup.initialize_all = function() {
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
this.initialize_add_to_favgroup_dialog();
|
||||
Utility.keydown("1 2 3 4 5 6 7 8 9 0", "add_to_favgroup", FavoriteGroup.add_to_favgroup);
|
||||
}
|
||||
}
|
||||
|
||||
FavoriteGroup.initialize_add_to_favgroup_dialog = function() {
|
||||
$("#add-to-favgroup-dialog").dialog({
|
||||
autoOpen: false,
|
||||
width: 500,
|
||||
buttons: {
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var open_favgroup_dialog = function(e) {
|
||||
if (Utility.meta("current-user-id") == "") { // anonymous
|
||||
return;
|
||||
}
|
||||
|
||||
if ($(".add-to-favgroup").length === 1) {
|
||||
// If the user only has one favorite group we don't need to ask which group to add the post to.
|
||||
$(".add-to-favgroup").click();
|
||||
} else if ($(".add-to-favgroup").length > 1) {
|
||||
$("#add-to-favgroup-dialog").dialog("open");
|
||||
}
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
Utility.keydown("g", "open_favgroup_dialog", open_favgroup_dialog);
|
||||
$("#open-favgroup-dialog-link").click(open_favgroup_dialog);
|
||||
}
|
||||
|
||||
FavoriteGroup.add_to_favgroup = function(e) {
|
||||
var favgroup_index = (e.key === "0") ? "10" : e.key;
|
||||
var link = $("#add-to-favgroup-" + favgroup_index + ":visible");
|
||||
if (link.length) {
|
||||
link.click();
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
FavoriteGroup.initialize_all();
|
||||
});
|
||||
|
||||
export default FavoriteGroup
|
||||
65
app/javascript/src/javascripts/favorites.js
Normal file
65
app/javascript/src/javascripts/favorites.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import Post from './posts.js.erb'
|
||||
import Utility from './utility'
|
||||
|
||||
let Favorite = {}
|
||||
|
||||
Favorite.initialize_all = function() {
|
||||
if ($("#c-posts").length) {
|
||||
this.hide_or_show_add_to_favorites_link();
|
||||
}
|
||||
}
|
||||
|
||||
Favorite.hide_or_show_add_to_favorites_link = function() {
|
||||
var current_user_id = Utility.meta("current-user-id");
|
||||
if (current_user_id == "") {
|
||||
$("#add-to-favorites").hide();
|
||||
$("#remove-from-favorites").hide();
|
||||
$("#add-fav-button").hide();
|
||||
$("#remove-fav-button").hide();
|
||||
return;
|
||||
}
|
||||
if ($("#image-container").length && $("#image-container").data("is-favorited") == true) {
|
||||
$("#add-to-favorites").hide();
|
||||
$("#add-fav-button").hide();
|
||||
} else {
|
||||
$("#remove-from-favorites").hide();
|
||||
$("#remove-fav-button").hide();
|
||||
}
|
||||
}
|
||||
|
||||
Favorite.create = function(post_id) {
|
||||
Post.notice_update("inc");
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/favorites.js",
|
||||
data: {
|
||||
post_id: post_id
|
||||
},
|
||||
complete: function() {
|
||||
Post.notice_update("dec");
|
||||
},
|
||||
error: function(data, status, xhr) {
|
||||
Utility.notice("Error: " + data.reason);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Favorite.destroy = function(post_id) {
|
||||
Post.notice_update("inc");
|
||||
|
||||
$.ajax({
|
||||
type: "DELETE",
|
||||
url: "/favorites/" + post_id + ".js",
|
||||
complete: function() {
|
||||
Post.notice_update("dec");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
Favorite.initialize_all();
|
||||
});
|
||||
|
||||
export default Favorite
|
||||
|
||||
47
app/javascript/src/javascripts/forum_posts.js
Normal file
47
app/javascript/src/javascripts/forum_posts.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import Utility from './utility'
|
||||
|
||||
let ForumPost = {};
|
||||
|
||||
ForumPost.initialize_all = function() {
|
||||
if ($("#c-forum-topics #a-show,#c-forum-posts #a-show").length) {;
|
||||
this.initialize_edit_links();
|
||||
|
||||
Utility.keydown("e", "edit", function(e) {
|
||||
$(".edit_forum_topic_link")[0].click();
|
||||
});
|
||||
|
||||
Utility.keydown("shift+d", "delete", function(e) {
|
||||
$("#forum-topic-delete a")[0].click();
|
||||
});
|
||||
}
|
||||
|
||||
if ($("#c-forum-topics").length) {
|
||||
Utility.keydown("shift+r", "mark_all_as_read", function(e) {
|
||||
$("#forum-topic-mark-all-as-read a")[0].click();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ForumPost.initialize_edit_links = function() {
|
||||
$(".edit_forum_post, .edit_forum_topic").hide();
|
||||
|
||||
$(".edit_forum_post_link").click(function(e) {
|
||||
var link_id = $(this).attr("id");
|
||||
var forum_post_id = link_id.match(/^edit_forum_post_link_(\d+)$/)[1];
|
||||
$("#edit_forum_post_" + forum_post_id).fadeToggle("fast");
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(".edit_forum_topic_link").click(function(e) {
|
||||
var link_id = $(this).attr("id");
|
||||
var forum_topic_id = link_id.match(/^edit_forum_topic_link_(\d+)$/)[1];
|
||||
$("#edit_forum_topic_" + forum_topic_id).fadeToggle("fast");
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
ForumPost.initialize_all();
|
||||
});
|
||||
|
||||
export default ForumPost
|
||||
29
app/javascript/src/javascripts/janitor_trials.js
Normal file
29
app/javascript/src/javascripts/janitor_trials.js
Normal file
@@ -0,0 +1,29 @@
|
||||
let JanitorTrials = {};
|
||||
|
||||
JanitorTrials.initialize_all = function() {
|
||||
if ($("#c-janitor-trials").length) {
|
||||
$("input[value=Test]").click(function(e) {
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "/janitor_trials/test.json",
|
||||
data: {
|
||||
janitor_trial: {
|
||||
user_name: $("#janitor_trial_user_name").val()
|
||||
}
|
||||
},
|
||||
success: function(data) {
|
||||
$("#test-results").html(data);
|
||||
}
|
||||
});
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
JanitorTrials.initialize_all();
|
||||
});
|
||||
|
||||
export default JanitorTrials
|
||||
67
app/javascript/src/javascripts/mod_queue.js
Normal file
67
app/javascript/src/javascripts/mod_queue.js
Normal file
@@ -0,0 +1,67 @@
|
||||
let ModQueue = {};
|
||||
|
||||
ModQueue.processed = 0;
|
||||
|
||||
ModQueue.increment_processed = function() {
|
||||
if (Utility.meta("random-mode") === "1") {
|
||||
ModQueue.processed += 1;
|
||||
|
||||
if (ModQueue.processed === 12) {
|
||||
window.location = Utility.meta("return-to");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ModQueue.initialize_hilights = function() {
|
||||
$.each($("div.post"), function(i, v) {
|
||||
var $post = $(v);
|
||||
var score = parseInt($post.data("score"));
|
||||
if (score >= 3) {
|
||||
$post.addClass("post-pos-score");
|
||||
}
|
||||
if (score <= -3) {
|
||||
$post.addClass("post-neg-score");
|
||||
}
|
||||
if ($post.data("has-children")) {
|
||||
$post.addClass("post-has-children");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ModQueue.initialize_detailed_rejection_links = function() {
|
||||
$(".detailed-rejection-link").click(ModQueue.detailed_rejection_dialog)
|
||||
}
|
||||
|
||||
ModQueue.detailed_rejection_dialog = function() {
|
||||
$("#post_disapproval_post_id").val($(this).data("post-id"));
|
||||
|
||||
$("#detailed-rejection-dialog").dialog({
|
||||
width: 500,
|
||||
buttons: {
|
||||
"Submit": function() {
|
||||
$(this).find("form").submit();
|
||||
$(this).dialog("close");
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$(function() {
|
||||
$(window).on("danbooru:modqueue_increment_processed", ModQueue.increment_processed);
|
||||
|
||||
if ($("#c-moderator-post-queues").length) {
|
||||
ModQueue.initialize_hilights();
|
||||
ModQueue.initialize_detailed_rejection_links();
|
||||
}
|
||||
|
||||
if ($("#c-posts #a-show").length) {
|
||||
ModQueue.initialize_detailed_rejection_links();
|
||||
}
|
||||
});
|
||||
|
||||
export default ModQueue
|
||||
30
app/javascript/src/javascripts/news_updates.js
Normal file
30
app/javascript/src/javascripts/news_updates.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import Cookie from './cookie'
|
||||
|
||||
let NewsUpdate = {};
|
||||
|
||||
NewsUpdate.initialize = function() {
|
||||
var key = $("#news-updates").data("id");
|
||||
|
||||
if (Cookie.get("news-ticker") == key) {
|
||||
$("#news-updates").hide();
|
||||
} else {
|
||||
$("#news-updates").show();
|
||||
|
||||
$("#close-news-ticker-link").click(function(e) {
|
||||
$("#news-updates").hide();
|
||||
Cookie.put("news-ticker", key);
|
||||
|
||||
// need to reset the more link
|
||||
var $site_map_link = $("#site-map-link");
|
||||
$("#more-links").hide().offset({top: $site_map_link.offset().top + $site_map_link.height() + 10, left: $site_map_link.offset().left});
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
NewsUpdate.initialize();
|
||||
});
|
||||
|
||||
export default NewsUpdate
|
||||
835
app/javascript/src/javascripts/notes.js
Normal file
835
app/javascript/src/javascripts/notes.js
Normal file
@@ -0,0 +1,835 @@
|
||||
import Utility from './utility'
|
||||
|
||||
let Note = {
|
||||
Box: {
|
||||
create: function(id) {
|
||||
var $inner_border = $('<div/>');
|
||||
$inner_border.addClass("note-box-inner-border");
|
||||
|
||||
var opacity = 0;
|
||||
if (Note.embed) {
|
||||
opacity = 0.95
|
||||
} else {
|
||||
opacity = 0.5
|
||||
}
|
||||
|
||||
$inner_border.css({
|
||||
opacity: opacity,
|
||||
});
|
||||
|
||||
var $note_box = $('<div/>');
|
||||
$note_box.addClass("note-box");
|
||||
|
||||
if (Note.embed) {
|
||||
$note_box.addClass("embedded");
|
||||
}
|
||||
|
||||
$note_box.data("id", String(id));
|
||||
$note_box.attr("data-id", String(id));
|
||||
$note_box.draggable({
|
||||
containment: $("#image"),
|
||||
stop: function(e, ui) {
|
||||
Note.Box.update_data_attributes($note_box);
|
||||
}
|
||||
});
|
||||
$note_box.resizable({
|
||||
containment: $("#image"),
|
||||
handles: "se, nw",
|
||||
stop: function(e, ui) {
|
||||
Note.Box.update_data_attributes($note_box);
|
||||
}
|
||||
});
|
||||
$note_box.css({position: "absolute"});
|
||||
$note_box.append($inner_border);
|
||||
Note.Box.bind_events($note_box);
|
||||
|
||||
return $note_box;
|
||||
},
|
||||
|
||||
update_data_attributes: function($note_box) {
|
||||
var $image = $("#image");
|
||||
var ratio = $image.width() / parseFloat($image.data("original-width"));
|
||||
var new_x = parseFloat($note_box.css("left"));
|
||||
var new_y = parseFloat($note_box.css("top"));
|
||||
var new_width = parseFloat($note_box.css("width"));
|
||||
var new_height = parseFloat($note_box.css("height"));
|
||||
new_x = parseInt(new_x / ratio);
|
||||
new_y = parseInt(new_y / ratio);
|
||||
new_width = parseInt(new_width / ratio);
|
||||
new_height = parseInt(new_height / ratio);
|
||||
$note_box.data("x", new_x);
|
||||
$note_box.data("y", new_y);
|
||||
$note_box.data("width", new_width);
|
||||
$note_box.data("height", new_height);
|
||||
},
|
||||
|
||||
bind_events: function($note_box) {
|
||||
$note_box.on(
|
||||
"dragstart resizestart",
|
||||
function(e) {
|
||||
var $note_box_inner = $(e.currentTarget);
|
||||
$note_box_inner.find(".note-box-inner-border").addClass("unsaved");
|
||||
Note.dragging = true;
|
||||
Note.clear_timeouts();
|
||||
Note.Body.hide_all();
|
||||
if (Note.embed) {
|
||||
var $bg = $note_box_inner.find("div.bg")
|
||||
if ($bg.length) {
|
||||
$bg.hide();
|
||||
}
|
||||
}
|
||||
e.stopPropagation();
|
||||
}
|
||||
);
|
||||
|
||||
$note_box.resize(
|
||||
function(e) {
|
||||
var $note_box_inner = $(e.currentTarget);
|
||||
Note.Box.resize_inner_border($note_box_inner);
|
||||
e.stopPropagation();
|
||||
}
|
||||
);
|
||||
|
||||
$note_box.on(
|
||||
"dragstop resizestop",
|
||||
function(e) {
|
||||
Note.dragging = false;
|
||||
if (Note.embed) {
|
||||
var $note_box_inner = $(e.currentTarget);
|
||||
var $bg = $note_box_inner.find("div.bg")
|
||||
if ($bg.length) {
|
||||
$bg.show();
|
||||
Note.Box.resize_inner_border($note_box_inner.closest(".note-box"));
|
||||
}
|
||||
}
|
||||
e.stopPropagation();
|
||||
}
|
||||
);
|
||||
|
||||
$note_box.on(
|
||||
"mouseover mouseout",
|
||||
function(e) {
|
||||
if (Note.dragging) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $note_box_inner = $(e.currentTarget);
|
||||
if (e.type === "mouseover") {
|
||||
Note.Body.show($note_box_inner.data("id"));
|
||||
if (Note.editing) {
|
||||
var $this = $(this);
|
||||
$this.resizable("enable");
|
||||
$this.draggable("enable");
|
||||
}
|
||||
} else if (e.type === "mouseout") {
|
||||
Note.Body.hide($note_box_inner.data("id"));
|
||||
if (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 + "]");
|
||||
},
|
||||
|
||||
show_highlighted: function($note_box) {
|
||||
var note_id = $note_box.data("id");
|
||||
|
||||
Note.Body.show(note_id);
|
||||
$(".note-box-highlighted").removeClass("note-box-highlighted");
|
||||
$note_box.addClass("note-box-highlighted");
|
||||
Utility.scroll_to($note_box);
|
||||
},
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
if ($inner_border.width() >= $note_box.width() - 2) {
|
||||
$note_box.width($inner_border.width() + 2);
|
||||
}
|
||||
|
||||
if ($inner_border.height() >= $note_box.height() - 2) {
|
||||
$note_box.height($inner_border.height() + 2);
|
||||
}
|
||||
|
||||
if (Note.embed) {
|
||||
var $bg = $inner_border.find("div.bg");
|
||||
if ($bg.length) {
|
||||
$bg.height($inner_border.height());
|
||||
$bg.width($inner_border.width());
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
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))
|
||||
});
|
||||
Note.Box.resize_inner_border($note_box);
|
||||
},
|
||||
|
||||
scale_all: function() {
|
||||
var container = document.getElementById('note-container');
|
||||
if (container === null) {
|
||||
return;
|
||||
}
|
||||
// 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) {
|
||||
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();
|
||||
Note.Body.bind_events($note_body);
|
||||
return $note_body;
|
||||
},
|
||||
|
||||
initialize: function($note_body) {
|
||||
var $note_box = Note.Box.find($note_body.data("id"));
|
||||
$note_body.css({
|
||||
top: $note_box.position().top + $note_box.height() + 5,
|
||||
left: $note_box.position().left
|
||||
});
|
||||
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) {
|
||||
Note.Body.hide_all();
|
||||
Note.clear_timeouts();
|
||||
var $note_body = Note.Body.find(id);
|
||||
if (!$note_body.data('resized')) {
|
||||
Note.Body.resize($note_body);
|
||||
$note_body.data('resized', 'true');
|
||||
}
|
||||
$note_body.show();
|
||||
Note.Body.initialize($note_body);
|
||||
},
|
||||
|
||||
find: function(id) {
|
||||
return $("#note-container div.note-body[data-id=" + id + "]");
|
||||
},
|
||||
|
||||
hide: function(id) {
|
||||
var $note_body = Note.Body.find(id);
|
||||
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, $note_box, text) {
|
||||
Note.Body.display_text($note_body, text);
|
||||
if (Note.embed) {
|
||||
Note.Body.display_text($note_box.children("div.note-box-inner-border"), text);
|
||||
}
|
||||
Note.Body.resize($note_body);
|
||||
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);
|
||||
Note.Body.show($note_body_inner.data("id"));
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
$note_body.mouseout(function(e) {
|
||||
var $note_body_inner = $(e.currentTarget);
|
||||
Note.Body.hide($note_body_inner.data("id"));
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
if (Utility.meta("current-user-name") !== "Anonymous") {
|
||||
$note_body.click(function(e) {
|
||||
if (e.target.tagName !== "A") {
|
||||
var $note_body_inner = $(e.currentTarget);
|
||||
Note.Edit.show($note_body_inner);
|
||||
}
|
||||
e.stopPropagation();
|
||||
});
|
||||
} else {
|
||||
$note_body.click(function(e) {
|
||||
if (e.target.tagName !== "A") {
|
||||
Utility.notice("You must be logged in to edit notes");
|
||||
}
|
||||
e.stopPropagation();
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Edit: {
|
||||
show: function($note_body) {
|
||||
var id = $note_body.data("id");
|
||||
|
||||
if (Note.editing) {
|
||||
return;
|
||||
}
|
||||
|
||||
$(".note-box").resizable("disable");
|
||||
$(".note-box").draggable("disable");
|
||||
|
||||
if (Note.embed) {
|
||||
$(".note-box").css("opacity", "0.5");
|
||||
}
|
||||
|
||||
let $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"));
|
||||
}
|
||||
|
||||
let $dialog = $('<div></div>');
|
||||
$dialog.append($textarea);
|
||||
$dialog.data("id", id);
|
||||
$dialog.dialog({
|
||||
width: 360,
|
||||
height: 210,
|
||||
position: {
|
||||
my: "right",
|
||||
at: "right-20",
|
||||
of: window
|
||||
},
|
||||
classes: {
|
||||
"ui-dialog": "note-edit-dialog",
|
||||
},
|
||||
title: "Edit note",
|
||||
buttons: {
|
||||
"Save": Note.Edit.save,
|
||||
"Preview": Note.Edit.preview,
|
||||
"Cancel": Note.Edit.cancel,
|
||||
"Delete": Note.Edit.destroy,
|
||||
"History": 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 #' + id + ' (<a href="/wiki_pages/help:notes">view help</a>)');
|
||||
|
||||
$dialog.on("dialogclose", function() {
|
||||
Note.editing = false;
|
||||
$(".note-box").resizable("enable");
|
||||
$(".note-box").draggable("enable");
|
||||
|
||||
if (Note.embed) {
|
||||
$(".note-box").css("opacity", "0.95");
|
||||
}
|
||||
});
|
||||
|
||||
$textarea.selectEnd();
|
||||
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"),
|
||||
}
|
||||
}
|
||||
|
||||
if ($note_box.data("id").match(/x/)) {
|
||||
hash.note.html_id = $note_box.data("id");
|
||||
hash.note.post_id = Utility.meta("post-id");
|
||||
}
|
||||
|
||||
return hash;
|
||||
},
|
||||
|
||||
error_handler: function(xhr, status, exception) {
|
||||
Utility.error("Error: " + (xhr.responseJSON.reason || xhr.responseJSON.reasons.join("; ")));
|
||||
},
|
||||
|
||||
success_handler: function(data, status, xhr) {
|
||||
if (data.html_id) { // new note
|
||||
var $note_body = Note.Body.find(data.html_id);
|
||||
var $note_box = Note.Box.find(data.html_id);
|
||||
$note_body.data("id", String(data.id)).attr("data-id", data.id);
|
||||
$note_box.data("id", String(data.id)).attr("data-id", data.id);
|
||||
$note_box.find(".note-box-inner-border").removeClass("unsaved");
|
||||
} else {
|
||||
var $note_box = 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 = Note.Body.find(id);
|
||||
var $note_box = Note.Box.find(id);
|
||||
var text = $textarea.val();
|
||||
$note_body.data("original-body", text);
|
||||
Note.Body.set_text($note_body, $note_box, "Loading...");
|
||||
$.get("/note_previews.json", {body: text}).then(function(data) {
|
||||
Note.Body.set_text($note_body, $note_box, data.body);
|
||||
Note.Box.resize_inner_border($note_box);
|
||||
$note_body.show();
|
||||
});
|
||||
$this.dialog("close");
|
||||
|
||||
if (id.match(/\d/)) {
|
||||
$.ajax("/notes/" + id + ".json", {
|
||||
type: "PUT",
|
||||
data: Note.Edit.parameterize_note($note_box, $note_body),
|
||||
error: Note.Edit.error_handler,
|
||||
success: Note.Edit.success_handler
|
||||
});
|
||||
} else {
|
||||
$.ajax("/notes.json", {
|
||||
type: "POST",
|
||||
data: Note.Edit.parameterize_note($note_box, $note_body),
|
||||
error: Note.Edit.error_handler,
|
||||
success: Note.Edit.success_handler
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
preview: function() {
|
||||
var $this = $(this);
|
||||
var $textarea = $this.find("textarea");
|
||||
var id = $this.data("id");
|
||||
var $note_body = Note.Body.find(id);
|
||||
var text = $textarea.val();
|
||||
var $note_box = Note.Box.find(id);
|
||||
$note_box.find(".note-box-inner-border").addClass("unsaved");
|
||||
Note.Body.set_text($note_body, $note_box, "Loading...");
|
||||
$.get("/note_previews.json", {body: text}).then(function(data) {
|
||||
Note.Body.set_text($note_body, $note_box, 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");
|
||||
|
||||
if (id.match(/\d/)) {
|
||||
$.ajax("/notes/" + id + ".json", {
|
||||
type: "DELETE",
|
||||
success: function() {
|
||||
Note.Box.find(id).remove();
|
||||
Note.Body.find(id).remove();
|
||||
$this.dialog("close");
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
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 (Note.TranslationMode.active) {
|
||||
Note.TranslationMode.stop(e);
|
||||
} else {
|
||||
Note.TranslationMode.start(e);
|
||||
}
|
||||
},
|
||||
|
||||
start: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (Utility.meta("current-user-id") == "") {
|
||||
Utility.notice("You must be logged in to edit notes");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Note.TranslationMode.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
$("#image").css("cursor", "crosshair");
|
||||
Note.TranslationMode.active = true;
|
||||
$(document.body).addClass("mode-translation");
|
||||
$("#original-file-link").click();
|
||||
$("#image").off("click", Note.Box.toggle_all);
|
||||
$("#image").mousedown(Note.TranslationMode.Drag.start);
|
||||
$(window).mouseup(Note.TranslationMode.Drag.stop);
|
||||
$("#mark-as-translated-section").show();
|
||||
|
||||
Utility.notice('Translation mode is on. Drag on the image to create notes. <a href="#">Turn translation mode off</a> (shortcut is <span class="key">n</span>).');
|
||||
$("#notice a:contains(Turn translation mode off)").click(Note.TranslationMode.stop);
|
||||
},
|
||||
|
||||
stop: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
Note.TranslationMode.active = false;
|
||||
$("#image").css("cursor", "auto");
|
||||
$("#image").click(Note.Box.toggle_all);
|
||||
$("#image").off("mousedown", Note.TranslationMode.Drag.start);
|
||||
$(window).off("mouseup", Note.TranslationMode.Drag.stop);
|
||||
$(document.body).removeClass("mode-translation");
|
||||
$("#close-notice-link").click();
|
||||
$("#mark-as-translated-section").hide();
|
||||
},
|
||||
|
||||
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;
|
||||
}
|
||||
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(Note.TranslationMode.Drag.drag);
|
||||
Note.TranslationMode.Drag.dragStartX = e.pageX;
|
||||
Note.TranslationMode.Drag.dragStartY = e.pageY;
|
||||
},
|
||||
|
||||
drag: function (e) {
|
||||
Note.TranslationMode.Drag.dragDistanceX = e.pageX - Note.TranslationMode.Drag.dragStartX;
|
||||
Note.TranslationMode.Drag.dragDistanceY = e.pageY - Note.TranslationMode.Drag.dragStartY;
|
||||
var $image = $("#image");
|
||||
var offset = $image.offset();
|
||||
var limitX1 = $image.width() - Note.TranslationMode.Drag.dragStartX + offset.left - 1;
|
||||
var limitX2 = offset.left - Note.TranslationMode.Drag.dragStartX;
|
||||
var limitY1 = $image.height()- Note.TranslationMode.Drag.dragStartY + offset.top - 1;
|
||||
var limitY2 = offset.top - Note.TranslationMode.Drag.dragStartY;
|
||||
|
||||
if (Note.TranslationMode.Drag.dragDistanceX > limitX1) {
|
||||
Note.TranslationMode.Drag.dragDistanceX = limitX1;
|
||||
} else if (Note.TranslationMode.Drag.dragDistanceX < limitX2) {
|
||||
Note.TranslationMode.Drag.dragDistanceX = limitX2;
|
||||
}
|
||||
|
||||
if (Note.TranslationMode.Drag.dragDistanceY > limitY1) {
|
||||
Note.TranslationMode.Drag.dragDistanceY = limitY1;
|
||||
} else if (Note.TranslationMode.Drag.dragDistanceY < limitY2) {
|
||||
Note.TranslationMode.Drag.dragDistanceY = limitY2;
|
||||
}
|
||||
|
||||
if (Math.abs(Note.TranslationMode.Drag.dragDistanceX) > 9 && Math.abs(Note.TranslationMode.Drag.dragDistanceY) > 9) {
|
||||
Note.TranslationMode.Drag.dragging = true; /* must drag at least 10pixels (minimum note size) in both dimensions. */
|
||||
}
|
||||
if (Note.TranslationMode.Drag.dragging) {
|
||||
if (Note.TranslationMode.Drag.dragDistanceX >= 0) {
|
||||
Note.TranslationMode.Drag.x = Note.TranslationMode.Drag.dragStartX;
|
||||
Note.TranslationMode.Drag.w = Note.TranslationMode.Drag.dragDistanceX;
|
||||
} else {
|
||||
Note.TranslationMode.Drag.x = Note.TranslationMode.Drag.dragStartX + Note.TranslationMode.Drag.dragDistanceX;
|
||||
Note.TranslationMode.Drag.w = -Note.TranslationMode.Drag.dragDistanceX;
|
||||
}
|
||||
|
||||
if (Note.TranslationMode.Drag.dragDistanceY >= 0) {
|
||||
Note.TranslationMode.Drag.y = Note.TranslationMode.Drag.dragStartY;
|
||||
Note.TranslationMode.Drag.h = Note.TranslationMode.Drag.dragDistanceY;
|
||||
} else {
|
||||
Note.TranslationMode.Drag.y = Note.TranslationMode.Drag.dragStartY + Note.TranslationMode.Drag.dragDistanceY;
|
||||
Note.TranslationMode.Drag.h = -Note.TranslationMode.Drag.dragDistanceY;
|
||||
}
|
||||
|
||||
$('#note-preview').css({
|
||||
display: 'block',
|
||||
left: (Note.TranslationMode.Drag.x + 1),
|
||||
top: (Note.TranslationMode.Drag.y + 1),
|
||||
width: (Note.TranslationMode.Drag.w - 3),
|
||||
height: (Note.TranslationMode.Drag.h - 3)
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
stop: function (e) {
|
||||
if (e.which !== 1) {
|
||||
return;
|
||||
}
|
||||
if (Note.TranslationMode.Drag.dragStartX === 0) {
|
||||
return; /* 'stop' is bound to window, don't create note if start wasn't triggered */
|
||||
}
|
||||
$(window).off("mousemove");
|
||||
|
||||
if (Note.TranslationMode.Drag.dragging) {
|
||||
$('#note-preview').css({display:'none'});
|
||||
Note.TranslationMode.create_note(e, Note.TranslationMode.Drag.x, Note.TranslationMode.Drag.y, Note.TranslationMode.Drag.w-1, Note.TranslationMode.Drag.h-1);
|
||||
Note.TranslationMode.Drag.dragging = false; /* border of the note is pixel-perfect on the preview border */
|
||||
} else { /* no dragging -> toggle display of notes */
|
||||
Note.Box.toggle_all();
|
||||
}
|
||||
|
||||
Note.TranslationMode.Drag.dragStartX = 0;
|
||||
Note.TranslationMode.Drag.dragStartY = 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
id: "x",
|
||||
dragging: false,
|
||||
editing: false,
|
||||
timeouts: [],
|
||||
pending: {},
|
||||
|
||||
add: function(container, id, x, y, w, h, original_body, sanitized_body) {
|
||||
var $note_box = Note.Box.create(id);
|
||||
var $note_body = 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", original_body);
|
||||
Note.Box.scale($note_box);
|
||||
Note.Body.display_text($note_body, sanitized_body);
|
||||
if (Note.embed) {
|
||||
Note.Body.display_text($note_box.children("div.note-box-inner-border"), sanitized_body);
|
||||
}
|
||||
},
|
||||
|
||||
create: function(x, y, w, h) {
|
||||
var $note_box = Note.Box.create(Note.id);
|
||||
var $note_body = Note.Body.create(Note.id);
|
||||
$note_box.css({
|
||||
top: y,
|
||||
left: x,
|
||||
width: w,
|
||||
height: h
|
||||
});
|
||||
Note.Box.update_data_attributes($note_box);
|
||||
$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);
|
||||
Note.Box.resize_inner_border($note_box);
|
||||
Note.id += "x";
|
||||
},
|
||||
|
||||
clear_timeouts: function() {
|
||||
$.each(Note.timeouts, function(i, v) {
|
||||
v.clear();
|
||||
});
|
||||
|
||||
Note.timeouts = [];
|
||||
},
|
||||
|
||||
load_all: function() {
|
||||
var fragment = document.createDocumentFragment();
|
||||
$.each($("#notes article"), function(i, article) {
|
||||
var $article = $(article);
|
||||
Note.add(
|
||||
fragment,
|
||||
$article.data("id"),
|
||||
$article.data("x"),
|
||||
$article.data("y"),
|
||||
$article.data("width"),
|
||||
$article.data("height"),
|
||||
$article.data("body"),
|
||||
$article.html()
|
||||
);
|
||||
});
|
||||
$("#note-container").append(fragment);
|
||||
if (Note.embed) {
|
||||
$.each($(".note-box"), function(i, note_box) {
|
||||
Note.Box.resize_inner_border($(note_box));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
initialize_all: function() {
|
||||
if ($("#c-posts #a-show #image").length == 0 || $("video#image").length) {
|
||||
return;
|
||||
}
|
||||
|
||||
Note.embed = (Utility.meta("post-has-embedded-notes") === "true");
|
||||
Note.load_all();
|
||||
|
||||
this.initialize_shortcuts();
|
||||
this.initialize_highlight();
|
||||
$(window).on("hashchange", this.initialize_highlight);
|
||||
},
|
||||
|
||||
initialize_shortcuts: function() {
|
||||
if ($("#note-locked-notice").length == 0) {
|
||||
$("#translate").click(Note.TranslationMode.toggle);
|
||||
Utility.keydown("n", "translation_mode", Note.TranslationMode.toggle);
|
||||
}
|
||||
|
||||
$("#image").click(Note.Box.toggle_all);
|
||||
},
|
||||
|
||||
initialize_highlight: function() {
|
||||
var matches = window.location.hash.match(/^#note-(\d+)$/);
|
||||
|
||||
if (matches) {
|
||||
var $note_box = Note.Box.find(matches[1]);
|
||||
Note.Box.show_highlighted($note_box);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
$(function() {
|
||||
Note.initialize_all();
|
||||
});
|
||||
|
||||
export default Note
|
||||
|
||||
26
app/javascript/src/javascripts/paginator.js
Normal file
26
app/javascript/src/javascripts/paginator.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import Utility from './utility'
|
||||
|
||||
let Paginator = {};
|
||||
|
||||
Paginator.next_page = function() {
|
||||
var href = $(".paginator a[rel=next]").attr("href");
|
||||
if (href) {
|
||||
window.location = href;
|
||||
}
|
||||
}
|
||||
|
||||
Paginator.prev_page = function() {
|
||||
var href = $(".paginator a[rel=prev]").attr("href");
|
||||
if (href) {
|
||||
window.location = href;
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
if ($(".paginator").length) {
|
||||
Utility.keydown("d right", "next_page", Paginator.next_page);
|
||||
Utility.keydown("a left", "prev_page", Paginator.prev_page);
|
||||
}
|
||||
});
|
||||
|
||||
export default Paginator
|
||||
65
app/javascript/src/javascripts/pools.js
Normal file
65
app/javascript/src/javascripts/pools.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import Utility from './utility'
|
||||
|
||||
let Pool = {};
|
||||
|
||||
Pool.initialize_all = function() {
|
||||
if ($("#c-pools").length) {
|
||||
this.initialize_shortcuts();
|
||||
}
|
||||
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
this.initialize_add_to_pool_link();
|
||||
}
|
||||
|
||||
if ($("#c-pool-orders,#c-favorite-group-orders").length) {
|
||||
this.initialize_simple_edit();
|
||||
}
|
||||
}
|
||||
|
||||
Pool.initialize_add_to_pool_link = function() {
|
||||
$("#add-to-pool-dialog").dialog({autoOpen: false});
|
||||
|
||||
$("#pool").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#add-to-pool-dialog").dialog("open");
|
||||
});
|
||||
|
||||
$("#recent-pools li").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#pool_name").val($(this).attr("data-value"));
|
||||
});
|
||||
}
|
||||
|
||||
Pool.initialize_shortcuts = function() {
|
||||
if ($("#c-pools #a-show").length) {
|
||||
Utility.keydown("e", "edit", function(e) {
|
||||
$("#pool-edit a")[0].click();
|
||||
});
|
||||
|
||||
Utility.keydown("shift+d", "delete", function(e) {
|
||||
$("#pool-delete a")[0].click();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Pool.initialize_simple_edit = function() {
|
||||
$("#sortable").sortable({
|
||||
placeholder: "ui-state-placeholder"
|
||||
});
|
||||
$("#sortable").disableSelection();
|
||||
|
||||
$("#ordering-form").submit(function(e) {
|
||||
$.ajax({
|
||||
type: "put",
|
||||
url: e.target.action,
|
||||
data: $("#sortable").sortable("serialize") + "&" + $(e.target).serialize()
|
||||
});
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
Pool.initialize_all();
|
||||
});
|
||||
|
||||
export default Pool
|
||||
44
app/javascript/src/javascripts/post_appeals.js
Normal file
44
app/javascript/src/javascripts/post_appeals.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import Utility from './utility'
|
||||
|
||||
let PostAppeal = {};
|
||||
|
||||
PostAppeal.initialize_all = function() {
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
this.initialize_appeal();
|
||||
this.hide_or_show_appeal_link();
|
||||
}
|
||||
}
|
||||
|
||||
PostAppeal.hide_or_show_appeal_link = function() {
|
||||
if ((Utility.meta("post-is-flagged") === "false") && (Utility.meta("post-is-deleted") === "false")) {
|
||||
$("#appeal").hide();
|
||||
}
|
||||
}
|
||||
|
||||
PostAppeal.initialize_appeal = function() {
|
||||
$("#appeal-dialog").dialog({
|
||||
autoOpen: false,
|
||||
width: 700,
|
||||
modal: true,
|
||||
buttons: {
|
||||
"Submit": function() {
|
||||
$("#appeal-dialog form").submit();
|
||||
$(this).dialog("close");
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("#appeal").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#appeal-dialog").dialog("open");
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
PostAppeal.initialize_all();
|
||||
});
|
||||
|
||||
export default PostAppeal
|
||||
48
app/javascript/src/javascripts/post_flags.js
Normal file
48
app/javascript/src/javascripts/post_flags.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import Utility from './utility'
|
||||
|
||||
let PostFlag = {};
|
||||
|
||||
PostFlag.initialize_all = function() {
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
this.initialize_flag();
|
||||
this.hide_or_show_flag_link();
|
||||
}
|
||||
}
|
||||
|
||||
PostFlag.hide_or_show_flag_link = function() {
|
||||
if (Utility.meta("post-is-deleted") === "true") {
|
||||
$("#flag").hide();
|
||||
}
|
||||
}
|
||||
|
||||
PostFlag.initialize_flag = function() {
|
||||
$("#flag-dialog").dialog({
|
||||
autoOpen: false,
|
||||
width: 700,
|
||||
modal: true,
|
||||
buttons: {
|
||||
"Submit": function() {
|
||||
$("#flag-dialog form").submit();
|
||||
$(this).dialog("close");
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#flag-dialog form').submit(function() {
|
||||
$('#flag-dialog').dialog('close');
|
||||
});
|
||||
|
||||
$("#flag").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#flag-dialog").dialog("open");
|
||||
});
|
||||
}
|
||||
|
||||
$(function() {
|
||||
PostFlag.initialize_all();
|
||||
});
|
||||
|
||||
export default PostFlag
|
||||
191
app/javascript/src/javascripts/post_mode_menu.js
Normal file
191
app/javascript/src/javascripts/post_mode_menu.js
Normal file
@@ -0,0 +1,191 @@
|
||||
import Utility from './utility'
|
||||
import Cookie from './cookie'
|
||||
import Post from './posts.js.erb'
|
||||
import Favorite from './favorites'
|
||||
import TagScript from './tag_script'
|
||||
|
||||
let PostModeMenu = {};
|
||||
|
||||
PostModeMenu.initialize = function() {
|
||||
if ($("#c-posts").length || $("#c-favorites").length || $("#c-pools").length) {
|
||||
this.initialize_selector();
|
||||
this.initialize_preview_link();
|
||||
this.initialize_edit_form();
|
||||
this.initialize_tag_script_field();
|
||||
this.initialize_shortcuts();
|
||||
PostModeMenu.change();
|
||||
}
|
||||
}
|
||||
|
||||
PostModeMenu.initialize_shortcuts = function() {
|
||||
Utility.keydown("1 2 3 4 5 6 7 8 9 0", "change_tag_script", PostModeMenu.change_tag_script);
|
||||
}
|
||||
|
||||
PostModeMenu.show_notice = function(i) {
|
||||
Utility.notice("Switched to tag script #" + i + ". To switch tag scripts, use the number keys.");
|
||||
}
|
||||
|
||||
PostModeMenu.change_tag_script = function(e) {
|
||||
if ($("#mode-box select").val() === "tag-script") {
|
||||
var old_tag_script_id = Cookie.get("current_tag_script_id") || "1";
|
||||
var old_tag_script = $("#tag-script-field").val();
|
||||
|
||||
var new_tag_script_id = String.fromCharCode(e.which);
|
||||
var new_tag_script = Cookie.get("tag-script-" + new_tag_script_id);
|
||||
|
||||
$("#tag-script-field").val(new_tag_script);
|
||||
Cookie.put("current_tag_script_id", new_tag_script_id);
|
||||
if (old_tag_script_id != new_tag_script_id) {
|
||||
PostModeMenu.show_notice(new_tag_script_id);
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
PostModeMenu.initialize_selector = function() {
|
||||
if (Cookie.get("mode") === "") {
|
||||
Cookie.put("mode", "view");
|
||||
$("#mode-box select").val("view");
|
||||
} else {
|
||||
$("#mode-box select").val(Cookie.get("mode"));
|
||||
}
|
||||
|
||||
$("#mode-box select").change(function(e) {
|
||||
PostModeMenu.change();
|
||||
$("#tag-script-field:visible").focus().select();
|
||||
});
|
||||
}
|
||||
|
||||
PostModeMenu.initialize_preview_link = function() {
|
||||
$(".post-preview a").click(PostModeMenu.click);
|
||||
}
|
||||
|
||||
PostModeMenu.initialize_edit_form = function() {
|
||||
$("#quick-edit-div").hide();
|
||||
$("#quick-edit-form input[value=Cancel]").click(function(e) {
|
||||
PostModeMenu.close_edit_form();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#quick-edit-form").submit(function(e) {
|
||||
$.ajax({
|
||||
type: "put",
|
||||
url: $("#quick-edit-form").attr("action"),
|
||||
data: {
|
||||
post: {
|
||||
tag_string: $("#post_tag_string").val()
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
$.rails.enableFormElements($("#quick-edit-form"));
|
||||
},
|
||||
success: function(data) {
|
||||
Post.update_data(data);
|
||||
Utility.notice("Post #" + data.id + " updated");
|
||||
PostModeMenu.close_edit_form();
|
||||
}
|
||||
});
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
PostModeMenu.close_edit_form = function() {
|
||||
$("#quick-edit-div").slideUp("fast");
|
||||
if (Utility.meta("enable-auto-complete") === "true") {
|
||||
$("#post_tag_string").data("uiAutocomplete").close();
|
||||
}
|
||||
}
|
||||
|
||||
PostModeMenu.initialize_tag_script_field = function() {
|
||||
$("#tag-script-field").blur(function(e) {
|
||||
var script = $(this).val();
|
||||
|
||||
if (script) {
|
||||
var current_script_id = Cookie.get("current_tag_script_id");
|
||||
Cookie.put("tag-script-" + current_script_id, script);
|
||||
} else {
|
||||
$("#mode-box select").val("view");
|
||||
PostModeMenu.change();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
PostModeMenu.change = function() {
|
||||
$("#quick-edit-div").slideUp("fast");
|
||||
var s = $("#mode-box select").val();
|
||||
if (s === undefined) {
|
||||
return;
|
||||
}
|
||||
var $body = $(document.body);
|
||||
$body.removeClass();
|
||||
$body.addClass("mode-" + s);
|
||||
Cookie.put("mode", s, 1);
|
||||
|
||||
if (s === "tag-script") {
|
||||
var current_script_id = Cookie.get("current_tag_script_id");
|
||||
if (!current_script_id) {
|
||||
current_script_id = "1";
|
||||
Cookie.put("current_tag_script_id", current_script_id);
|
||||
}
|
||||
var script = Cookie.get("tag-script-" + current_script_id);
|
||||
|
||||
$("#tag-script-field").val(script).show();
|
||||
PostModeMenu.show_notice(current_script_id);
|
||||
} else {
|
||||
$("#tag-script-field").hide();
|
||||
}
|
||||
}
|
||||
|
||||
PostModeMenu.open_edit = function(post_id) {
|
||||
var $post = $("#post_" + post_id);
|
||||
$("#quick-edit-div").slideDown("fast");
|
||||
$("#quick-edit-form").attr("action", "/posts/" + post_id + ".json");
|
||||
$("#post_tag_string").val($post.data("tags") + " ").focus().selectEnd();
|
||||
|
||||
/* Set height of tag edit box to fit content. */
|
||||
$("#post_tag_string").height(80); // min height: 80px.
|
||||
var padding = $("#post_tag_string").innerHeight() - $("#post_tag_string").height();
|
||||
var height = $("#post_tag_string").prop("scrollHeight") - padding;
|
||||
$("#post_tag_string").height(height);
|
||||
}
|
||||
|
||||
PostModeMenu.click = function(e) {
|
||||
var s = $("#mode-box select").val();
|
||||
var post_id = $(e.target).closest("article").data("id");
|
||||
|
||||
if (s === "add-fav") {
|
||||
Favorite.create(post_id);
|
||||
} else if (s === "remove-fav") {
|
||||
Favorite.destroy(post_id);
|
||||
} else if (s === "edit") {
|
||||
PostModeMenu.open_edit(post_id);
|
||||
} else if (s === 'vote-down') {
|
||||
Post.vote("down", post_id);
|
||||
} else if (s === 'vote-up') {
|
||||
Post.vote("up", post_id);
|
||||
} else if (s === 'lock-rating') {
|
||||
Post.update(post_id, {"post[is_rating_locked]": "1"});
|
||||
} else if (s === 'lock-note') {
|
||||
Post.update(post_id, {"post[is_note_locked]": "1"});
|
||||
} else if (s === 'approve') {
|
||||
Post.approve(post_id);
|
||||
} else if (s === 'ban') {
|
||||
Post.ban(post_id);
|
||||
} else if (s === "tag-script") {
|
||||
var current_script_id = Cookie.get("current_tag_script_id");
|
||||
var tag_script = Cookie.get("tag-script-" + current_script_id);
|
||||
TagScript.run(post_id, tag_script);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
$(function() {
|
||||
PostModeMenu.initialize();
|
||||
});
|
||||
|
||||
export default PostModeMenu
|
||||
29
app/javascript/src/javascripts/post_moderation.js
Normal file
29
app/javascript/src/javascripts/post_moderation.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import Utility from './utility'
|
||||
|
||||
let PostModeration = {};
|
||||
|
||||
PostModeration.initialize_all = function() {
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
this.hide_or_show_approve_and_disapprove_links();
|
||||
this.hide_or_show_delete_and_undelete_links();
|
||||
}
|
||||
}
|
||||
|
||||
PostModeration.hide_or_show_approve_and_disapprove_links = function() {
|
||||
if (Utility.meta("post-is-approvable") !== "true") {
|
||||
$("#approve").hide();
|
||||
$("#disapprove").hide();
|
||||
}
|
||||
}
|
||||
|
||||
PostModeration.hide_or_show_delete_and_undelete_links = function() {
|
||||
if (Utility.meta("post-is-deleted") === "true") {
|
||||
$("#delete").hide();
|
||||
} else {
|
||||
$("#undelete").hide();
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
PostModeration.initialize_all();
|
||||
});
|
||||
38
app/javascript/src/javascripts/post_popular.js
Normal file
38
app/javascript/src/javascripts/post_popular.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import Utility from './utility'
|
||||
|
||||
let PostPopular = {};
|
||||
|
||||
PostPopular.nav_prev = function(e) {
|
||||
if ($("#popular-nav-links").length) {
|
||||
var href = $("#popular-nav-links a[rel=prev]").attr("href");
|
||||
if (href) {
|
||||
location.href = href;
|
||||
}
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
PostPopular.nav_next = function(e) {
|
||||
if ($("#popular-nav-links").length) {
|
||||
var href = $("#popular-nav-links a[rel=next]").attr("href");
|
||||
if (href) {
|
||||
location.href = href;
|
||||
}
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
PostPopular.initialize_all = function() {
|
||||
if ($("#c-explore-posts").length) {
|
||||
Utility.keydown("a left", "prev_page", PostPopular.nav_prev);
|
||||
Utility.keydown("d right", "next_page", PostPopular.nav_next);
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
PostPopular.initialize_all();
|
||||
});
|
||||
|
||||
export default PostPopular
|
||||
133
app/javascript/src/javascripts/post_tooltips.js.erb
Normal file
133
app/javascript/src/javascripts/post_tooltips.js.erb
Normal file
@@ -0,0 +1,133 @@
|
||||
import Utility from './utility'
|
||||
|
||||
let PostTooltip = {};
|
||||
|
||||
PostTooltip.render_tooltip = function (event, qtip) {
|
||||
var post_id = $(event.target).parents("[data-id]").data("id");
|
||||
|
||||
$.get("/posts/" + post_id, { variant: "tooltip" }).then(function (html) {
|
||||
qtip.set("content.text", html);
|
||||
qtip.elements.tooltip.removeClass("post-tooltip-loading");
|
||||
|
||||
// Hide the tooltip if the user stopped hovering before the ajax request completed.
|
||||
if (PostTooltip.lostFocus) {
|
||||
qtip.hide();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Hide the tooltip the first time it is shown, while we wait on the ajax call to complete.
|
||||
PostTooltip.on_show = function (event, qtip) {
|
||||
if (!qtip.cache.hasBeenShown) {
|
||||
qtip.elements.tooltip.addClass("post-tooltip-loading");
|
||||
qtip.cache.hasBeenShown = true;
|
||||
}
|
||||
};
|
||||
|
||||
PostTooltip.POST_SELECTOR = "*:not(.ui-sortable-handle) > .post-preview img";
|
||||
|
||||
// http://qtip2.com/options
|
||||
PostTooltip.QTIP_OPTIONS = {
|
||||
style: "qtip-light post-tooltip",
|
||||
content: PostTooltip.render_tooltip,
|
||||
overwrite: false,
|
||||
position: {
|
||||
viewport: true,
|
||||
my: "bottom left",
|
||||
at: "top left",
|
||||
effect: false,
|
||||
adjust: {
|
||||
y: -2,
|
||||
method: "shift",
|
||||
},
|
||||
/* Position tooltip beneath mouse.
|
||||
my: "top left",
|
||||
at: "bottom left",
|
||||
target: "mouse",
|
||||
viewport: true,
|
||||
adjust: {
|
||||
mouse: false,
|
||||
y: 25,
|
||||
method: "shift",
|
||||
},
|
||||
*/
|
||||
},
|
||||
show: {
|
||||
solo: true,
|
||||
delay: 750,
|
||||
effect: false,
|
||||
ready: true,
|
||||
event: "mouseenter",
|
||||
},
|
||||
hide: {
|
||||
delay: 250,
|
||||
fixed: true,
|
||||
effect: false,
|
||||
event: "unfocus click mouseleave",
|
||||
},
|
||||
events: {
|
||||
show: PostTooltip.on_show,
|
||||
},
|
||||
};
|
||||
|
||||
PostTooltip.initialize = function () {
|
||||
$(document).on("mouseenter", PostTooltip.POST_SELECTOR, function (event) {
|
||||
if (PostTooltip.disabled()) {
|
||||
$(this).qtip("disable");
|
||||
} else {
|
||||
$(this).qtip(PostTooltip.QTIP_OPTIONS, event);
|
||||
}
|
||||
|
||||
PostTooltip.lostFocus = false;
|
||||
});
|
||||
|
||||
$(document).on("mouseleave", PostTooltip.POST_SELECTOR, function (event) {
|
||||
PostTooltip.lostFocus = true;
|
||||
});
|
||||
|
||||
$(document).on("click", ".post-tooltip-disable", PostTooltip.on_disable_tooltips);
|
||||
|
||||
// Hide tooltips when pressing keys or clicking thumbnails.
|
||||
$(document).on("keydown", PostTooltip.hide);
|
||||
$(document).on("click", PostTooltip.POST_SELECTOR, PostTooltip.hide);
|
||||
|
||||
// Disable tooltips on touch devices. https://developer.mozilla.org/en-US/docs/Web/API/Touch_events/Supporting_both_TouchEvent_and_MouseEvent
|
||||
PostTooltip.isTouching = false;
|
||||
$(document).on("touchstart", function (event) { PostTooltip.isTouching = true; });
|
||||
$(document).on("touchend", function (event) { PostTooltip.isTouching = false; });
|
||||
};
|
||||
|
||||
PostTooltip.hide = function (event) {
|
||||
// Hide on any key except control (user may be control-clicking link inside tooltip).
|
||||
if (event.type === "keydown" && event.ctrlKey === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
$(".post-tooltip:visible").qtip("hide");
|
||||
};
|
||||
|
||||
PostTooltip.disabled = function (event) {
|
||||
return PostTooltip.isTouching || Utility.meta("disable-post-tooltips") === "true";
|
||||
};
|
||||
|
||||
PostTooltip.on_disable_tooltips = function (event) {
|
||||
event.preventDefault();
|
||||
$(event.target).parents(".qtip").qtip("hide");
|
||||
|
||||
if (Utility.meta("current-user-id") === "") {
|
||||
$(window).trigger("danbooru:notice", '<a href="/session/new">Login</a> to disable tooltips permanently');
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax("/users/" + Utility.meta("current-user-id") + ".json", {
|
||||
method: "PUT",
|
||||
data: { "user[disable_post_tooltips]": "true" },
|
||||
}).then(function() {
|
||||
$(window).trigger("danbooru:notice", "Tooltips disabled; check your account settings to re-enable.");
|
||||
location.reload();
|
||||
});
|
||||
};
|
||||
|
||||
$(document).ready(PostTooltip.initialize);
|
||||
|
||||
export default PostTooltip
|
||||
723
app/javascript/src/javascripts/posts.js.erb
Normal file
723
app/javascript/src/javascripts/posts.js.erb
Normal file
@@ -0,0 +1,723 @@
|
||||
import Utility from './utility'
|
||||
import Hammer from 'hammerjs'
|
||||
import RelatedTag from './related_tag.js.erb'
|
||||
import Cookie from './cookie'
|
||||
import Note from './notes'
|
||||
import SavedSearch from './saved_searches'
|
||||
|
||||
let Post = {};
|
||||
|
||||
Post.pending_update_count = 0;
|
||||
|
||||
Post.initialize_all = function() {
|
||||
|
||||
if ($("#c-posts").length) {
|
||||
this.initialize_shortcuts();
|
||||
this.initialize_saved_searches();
|
||||
}
|
||||
|
||||
if ($("#c-posts").length && $("#a-index").length) {
|
||||
this.initialize_excerpt();
|
||||
this.initialize_gestures();
|
||||
}
|
||||
|
||||
if ($("#c-posts").length && $("#a-show").length) {
|
||||
this.initialize_links();
|
||||
this.initialize_post_relationship_previews();
|
||||
this.initialize_favlist();
|
||||
this.initialize_post_sections();
|
||||
this.initialize_post_image_resize_links();
|
||||
this.initialize_post_image_resize_to_window_link();
|
||||
this.initialize_similar();
|
||||
this.initialize_replace_image_dialog();
|
||||
this.initialize_gestures();
|
||||
|
||||
if ((Utility.meta("always-resize-images") === "true") || (Utility.meta("viewport") && (window.screen.width <= 660))) {
|
||||
$("#image-resize-to-window-link").click();
|
||||
}
|
||||
}
|
||||
|
||||
if ($("#image").length) {
|
||||
this.initialize_edit_dialog();
|
||||
}
|
||||
|
||||
$(window).on('danbooru:initialize_saved_seraches', () => {
|
||||
Post.initialize_saved_searches();
|
||||
});
|
||||
}
|
||||
|
||||
Post.initialize_gestures = function() {
|
||||
if (Utility.meta("disable-mobile-gestures") === "true") {
|
||||
return;
|
||||
}
|
||||
var $body = $("body");
|
||||
if ($body.data("hammer")) {
|
||||
return;
|
||||
}
|
||||
if (!Utility.test_max_width(660)) {
|
||||
return;
|
||||
}
|
||||
$("#image-container").css({overflow: "visible"});
|
||||
var hasPrev = $("#a-show").length || $(".paginator a[rel~=prev]").length;
|
||||
var hasNext = $("#a-index").length && $(".paginator a[rel~=next]").length;
|
||||
|
||||
var hammer = new Hammer($body[0], {touchAction: 'pan-y', recognizers: [[Hammer.Swipe, { threshold: 20, velocity: 0.4, direction: Hammer.DIRECTION_HORIZONTAL }]], inputClass: Hammer.TouchInput});
|
||||
$body.data("hammer", hammer);
|
||||
|
||||
if (hasPrev) {
|
||||
hammer.on("swiperight", function(e) {
|
||||
$("body").css({"transition-timing-function": "ease", "transition-duration": "0.2s", "opacity": "0", "transform": "translateX(150%)"});
|
||||
$.timeout(200).done(function() {Post.swipe_prev(e)});
|
||||
});
|
||||
}
|
||||
|
||||
if (hasNext) {
|
||||
hammer.on("swipeleft", function(e) {
|
||||
$("body").css({"transition-timing-function": "ease", "transition-duration": "0.2s", "opacity": "0", "transform": "translateX(-150%)"});
|
||||
$.timeout(200).done(function() {Post.swipe_next(e)});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Post.initialize_edit_dialog = function(e) {
|
||||
$("#open-edit-dialog").button().show().click(function(e) {
|
||||
$(window).scrollTop($("#image").offset().top);
|
||||
Post.open_edit_dialog();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#toggle-related-tags-link").click(function(e) {
|
||||
RelatedTag.toggle();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Post.open_edit_dialog = function() {
|
||||
var $tag_string = $("#post_tag_string,#upload_tag_string");
|
||||
$("div.input").has($tag_string).prevAll().hide();
|
||||
$("#open-edit-dialog").hide();
|
||||
|
||||
$("#toggle-related-tags-link").show().click();
|
||||
|
||||
var dialog = $("<div/>").attr("id", "edit-dialog");
|
||||
$("#form").appendTo(dialog);
|
||||
dialog.dialog({
|
||||
title: "Edit tags",
|
||||
width: $(window).width() * 0.6,
|
||||
position: {
|
||||
my: "right",
|
||||
at: "right-20",
|
||||
of: window
|
||||
},
|
||||
drag: function(e, ui) {
|
||||
if (Utility.meta("enable-auto-complete") === "true") {
|
||||
$tag_string.data("uiAutocomplete").close();
|
||||
}
|
||||
},
|
||||
close: Post.close_edit_dialog
|
||||
});
|
||||
dialog.dialog("widget").draggable("option", "containment", "none");
|
||||
|
||||
var pin_button = $("<button/>").button({icons: {primary: "ui-icon-pin-w"}, label: "pin", text: false});
|
||||
pin_button.css({width: "20px", height: "20px", position: "absolute", right: "28.4px"});
|
||||
dialog.parent().children(".ui-dialog-titlebar").append(pin_button);
|
||||
pin_button.click(function(e) {
|
||||
var dialog_widget = $('.ui-dialog:has(#edit-dialog)');
|
||||
var pos = dialog_widget.offset();
|
||||
|
||||
if (dialog_widget.css("position") === "absolute") {
|
||||
pos.left -= $(window).scrollLeft();
|
||||
pos.top -= $(window).scrollTop();
|
||||
dialog_widget.offset(pos).css({position:"fixed"});
|
||||
dialog.dialog("option", "resize", function() { dialog_widget.css({position:"fixed"}); });
|
||||
|
||||
pin_button.button("option", "icons", {primary: "ui-icon-pin-s"});
|
||||
} else {
|
||||
pos.left += $(window).scrollLeft();
|
||||
pos.top += $(window).scrollTop();
|
||||
dialog_widget.offset(pos).css({position:"absolute"});
|
||||
dialog.dialog("option", "resize", function() {});
|
||||
|
||||
pin_button.button("option", "icons", {primary: "ui-icon-pin-w"});
|
||||
}
|
||||
});
|
||||
|
||||
dialog.parent().mouseout(function(e) {
|
||||
dialog.parent().css({"opacity": 0.6, "transition": "opacity .2s ease"});
|
||||
})
|
||||
.mouseover(function(e) {
|
||||
dialog.parent().css({"opacity": 1});
|
||||
});
|
||||
|
||||
$tag_string.css({"resize": "none", "width": "100%"});
|
||||
$tag_string.focus().selectEnd().height($tag_string[0].scrollHeight);
|
||||
}
|
||||
|
||||
Post.close_edit_dialog = function(e, ui) {
|
||||
$("#form").appendTo($("#c-posts #edit,#c-uploads #a-new"));
|
||||
$("#edit-dialog").remove();
|
||||
RelatedTag.show();
|
||||
$("#toggle-related-tags-link").hide();
|
||||
var $tag_string = $("#post_tag_string,#upload_tag_string");
|
||||
$("div.input").has($tag_string).prevAll().show();
|
||||
$("#open-edit-dialog").show();
|
||||
$tag_string.css({"resize": "", "width": ""});
|
||||
}
|
||||
|
||||
Post.initialize_similar = function() {
|
||||
$("#similar-button").click(function(e) {
|
||||
$.get("/iqdb_queries", {"url": $("#post_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Post.swipe_prev = function(e) {
|
||||
if ($("#a-show").length) {
|
||||
window.history.back();
|
||||
} if ($(".paginator a[rel~=prev]").length) {
|
||||
location.href = $("a[rel~=prev]").attr("href");
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
Post.nav_prev = function(e) {
|
||||
if ($("#search-seq-nav").length) {
|
||||
var href = $("#search-seq-nav a[rel~=prev]").attr("href");
|
||||
if (href) {
|
||||
location.href = href;
|
||||
}
|
||||
} else if ($(".paginator a[rel~=prev]").length) {
|
||||
location.href = $("a[rel~=prev]").attr("href");
|
||||
} else {
|
||||
var href = $("#pool-nav a.active[rel~=prev], #favgroup-nav a.active[rel~=prev]").attr("href");
|
||||
if (href) {
|
||||
location.href = href;
|
||||
}
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
Post.nav_next = function(e) {
|
||||
if ($("#search-seq-nav").length) {
|
||||
var href = $("#search-seq-nav a[rel~=next]").attr("href");
|
||||
location.href = href;
|
||||
} else if ($(".paginator a[rel~=next]").length) {
|
||||
location.href = $(".paginator a[rel~=next]").attr("href");
|
||||
} else {
|
||||
var href = $("#pool-nav a.active[rel~=next], #favgroup-nav a.active[rel~=next]").attr("href");
|
||||
if (href) {
|
||||
location.href = href;
|
||||
}
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
Post.swipe_next = function(e) {
|
||||
if ($(".paginator a[rel~=next ]").length) {
|
||||
location.href = $(".paginator a[rel~=next]").attr("href");
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
Post.initialize_shortcuts = function() {
|
||||
if ($("#a-show").length) {
|
||||
Utility.keydown("e", "edit", function(e) {
|
||||
$("#post-edit-link").trigger("click");
|
||||
$("#post_tag_string").focus();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
if (Utility.meta("current-user-can-approve-posts") === "true") {
|
||||
Utility.keydown("shift+o", "approve", function(e) {
|
||||
$(".approve-link").click();
|
||||
});
|
||||
}
|
||||
|
||||
Utility.keydown("a", "prev_page", Post.nav_prev);
|
||||
Utility.keydown("d", "next_page", Post.nav_next);
|
||||
Utility.keydown("f", "favorite", Post.favorite);
|
||||
Utility.keydown("shift+f", "unfavorite", Post.unfavorite);
|
||||
}
|
||||
}
|
||||
|
||||
Post.initialize_links = function() {
|
||||
$("#copy-notes").click(function(e) {
|
||||
var current_post_id = $("meta[name=post-id]").attr("content");
|
||||
var other_post_id = parseInt(prompt("Enter the ID of the post to copy all notes to:"), 10);
|
||||
|
||||
if (other_post_id !== null) {
|
||||
$.ajax("/posts/" + current_post_id + "/copy_notes", {
|
||||
type: "PUT",
|
||||
data: {
|
||||
other_post_id: other_post_id
|
||||
},
|
||||
success: function(data) {
|
||||
$(window).trigger("danbooru:notice", "Successfully copied notes to <a href='" + other_post_id + "'>post #" + other_post_id + "</a>");
|
||||
},
|
||||
error: function(data) {
|
||||
if (data.status === 404) {
|
||||
$(window).trigger("danbooru:error", "Error: Invalid destination post");
|
||||
} else if (data.responseJSON && data.responseJSON.reason) {
|
||||
$(window).trigger("danbooru:error", "Error: " + data.responseJSON.reason);
|
||||
} else {
|
||||
$(window).trigger("danbooru:error", "There was an error copying notes to <a href='" + other_post_id + "'>post #" + other_post_id + "</a>");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(".unvote-post-link").hide();
|
||||
}
|
||||
|
||||
Post.initialize_post_relationship_previews = function() {
|
||||
var current_post_id = $("meta[name=post-id]").attr("content");
|
||||
$("[id=post_" + current_post_id + "]").addClass("current-post");
|
||||
|
||||
if (Cookie.get("show-relationship-previews") === "0") {
|
||||
this.toggle_relationship_preview($("#has-children-relationship-preview"), $("#has-children-relationship-preview-link"));
|
||||
this.toggle_relationship_preview($("#has-parent-relationship-preview"), $("#has-parent-relationship-preview-link"));
|
||||
}
|
||||
|
||||
$("#has-children-relationship-preview-link").click(function(e) {
|
||||
Post.toggle_relationship_preview($("#has-children-relationship-preview"), $(this));
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#has-parent-relationship-preview-link").click(function(e) {
|
||||
Post.toggle_relationship_preview($("#has-parent-relationship-preview"), $(this));
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Post.toggle_relationship_preview = function(preview, preview_link) {
|
||||
preview.toggle();
|
||||
if (preview.is(":visible")) {
|
||||
preview_link.html("« hide");
|
||||
Cookie.put("show-relationship-previews", "1");
|
||||
}
|
||||
else {
|
||||
preview_link.html("show »");
|
||||
Cookie.put("show-relationship-previews", "0");
|
||||
}
|
||||
}
|
||||
|
||||
Post.initialize_favlist = function() {
|
||||
$("#favlist").hide();
|
||||
$("#hide-favlist-link").hide();
|
||||
var fav_count = $("#show-favlist-link").prev().text();
|
||||
if (fav_count === "0") {
|
||||
$("#show-favlist-link").hide();
|
||||
}
|
||||
|
||||
$("#show-favlist-link").click(function(e) {
|
||||
$("#favlist").show();
|
||||
$(this).hide();
|
||||
$("#hide-favlist-link").show();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#hide-favlist-link").click(function(e) {
|
||||
$("#favlist").hide();
|
||||
$(this).hide();
|
||||
$("#show-favlist-link").show();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Post.expand_image = function(e) {
|
||||
if (Utility.test_max_width(660)) {
|
||||
// just do the default behavior
|
||||
return;
|
||||
}
|
||||
|
||||
var $link = $(e.target);
|
||||
var $image = $("#image");
|
||||
var $notice = $("#image-resize-notice");
|
||||
$image.attr("src", $link.attr("href"));
|
||||
$image.css("opacity", "0.25");
|
||||
$image.width($image.data("original-width"));
|
||||
$image.height($image.data("original-height"));
|
||||
$image.on("load", function() {
|
||||
$image.css("opacity", "1");
|
||||
$notice.hide();
|
||||
});
|
||||
$notice.children().eq(0).hide();
|
||||
$notice.children().eq(1).show(); // Loading message
|
||||
Note.Box.scale_all();
|
||||
$image.data("scale-factor", 1);
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
Post.initialize_post_image_resize_links = function() {
|
||||
$("#image-resize-link").click(Post.expand_image);
|
||||
|
||||
if ($("#image-resize-notice").length) {
|
||||
Utility.keydown("v", "resize", function(e) {
|
||||
if ($("#image-resize-notice").is(":visible")) {
|
||||
$("#image-resize-link").click();
|
||||
} else {
|
||||
var $image = $("#image");
|
||||
var $notice = $("#image-resize-notice");
|
||||
$image.attr("src", $("#image-container").data("large-file-url"));
|
||||
$image.css("opacity", "0.25");
|
||||
$image.width($image.data("large-width"));
|
||||
$image.height($image.data("large-height"));
|
||||
$notice.children().eq(0).show();
|
||||
$notice.children().eq(1).hide(); // Loading message
|
||||
$image.on("load", function() {
|
||||
$image.css("opacity", "1");
|
||||
$notice.show();
|
||||
});
|
||||
Note.Box.scale_all();
|
||||
$image.data("scale-factor", 1);
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Post.resize_image_to_window = function($img) {
|
||||
if (($img.data("scale-factor") === 1) || ($img.data("scale-factor") === undefined)) {
|
||||
if ($(window).width() > 660) {
|
||||
var sidebar_width = $("#sidebar").width() || 0;
|
||||
var client_width = $(window).width() - sidebar_width - 75;
|
||||
} else {
|
||||
var client_width = $(window).width() - 2;
|
||||
}
|
||||
var client_height = $(window).height();
|
||||
|
||||
if ($img.width() > client_width) {
|
||||
var ratio = client_width / $img.data("original-width");
|
||||
$img.data("scale-factor", ratio);
|
||||
$img.css("width", $img.data("original-width") * ratio);
|
||||
$img.css("height", $img.data("original-height") * ratio);
|
||||
Post.resize_ugoira_controls();
|
||||
}
|
||||
} else {
|
||||
$img.data("scale-factor", 1);
|
||||
$img.width($img.data("original-width"));
|
||||
$img.height($img.data("original-height"));
|
||||
Post.resize_ugoira_controls();
|
||||
}
|
||||
|
||||
Note.Box.scale_all();
|
||||
}
|
||||
|
||||
Post.initialize_post_image_resize_to_window_link = function() {
|
||||
$("#image-resize-to-window-link").click(function(e) {
|
||||
Post.resize_image_to_window($("#image"));
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Post.initialize_excerpt = function() {
|
||||
$("#excerpt").hide();
|
||||
|
||||
$("#show-posts-link").click(function(e) {
|
||||
$("#show-posts-link").parent("li").addClass("active");
|
||||
$("#show-excerpt-link").parent("li").removeClass("active");
|
||||
$("#posts").show();
|
||||
$("#excerpt").hide();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#show-excerpt-link").click(function(e) {
|
||||
if ($(this).parent("li").hasClass("active")) {
|
||||
return;
|
||||
}
|
||||
$("#show-posts-link").parent("li").removeClass("active");
|
||||
$("#show-excerpt-link").parent("li").addClass("active");
|
||||
$("#posts").hide();
|
||||
$("#excerpt").show();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
if (!$(".post-preview").length && /Nobody here but us chickens/.test($("#posts").html())) {
|
||||
$("#show-excerpt-link").click();
|
||||
}
|
||||
}
|
||||
|
||||
Post.initialize_post_sections = function() {
|
||||
$("#post-sections li a").click(function(e) {
|
||||
if (e.target.hash === "#comments") {
|
||||
$("#comments").show();
|
||||
$("#edit").hide();
|
||||
$("#share").hide();
|
||||
$("#recommended").hide();
|
||||
} else if (e.target.hash === "#edit") {
|
||||
$("#edit").show();
|
||||
$("#comments").hide();
|
||||
$("#share").hide();
|
||||
$("#post_tag_string").focus().selectEnd().height($("#post_tag_string")[0].scrollHeight);
|
||||
$("#related-tags-button").trigger("click");
|
||||
$("#find-artist-button").trigger("click");
|
||||
$("#recommended").hide();
|
||||
} else if (e.target.hash === "#recommended") {
|
||||
$("#comments").hide();
|
||||
$("#edit").hide();
|
||||
$("#share").hide();
|
||||
$("#recommended").show();
|
||||
$.get("/recommended_posts", {context: "post", post_id: Utility.meta("post-id")}, function(data) {
|
||||
$("#recommended").html(data);
|
||||
});
|
||||
} else {
|
||||
$("#edit").hide();
|
||||
$("#comments").hide();
|
||||
$("#share").show();
|
||||
addthis.init();
|
||||
$("#recommended").hide();
|
||||
}
|
||||
|
||||
$("#post-sections li").removeClass("active");
|
||||
$(e.target).parent("li").addClass("active");
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#notes").hide();
|
||||
$("#edit").hide();
|
||||
$("#recommended").hide();
|
||||
$("#post-sections li:first-child").addClass("active");
|
||||
}
|
||||
|
||||
Post.initialize_post_sections = function() {
|
||||
$("#post-sections li a").click(function(e) {
|
||||
if (e.target.hash === "#comments") {
|
||||
$("#comments").show();
|
||||
$("#edit").hide();
|
||||
$("#share").hide();
|
||||
} else if (e.target.hash === "#edit") {
|
||||
$("#edit").show();
|
||||
$("#comments").hide();
|
||||
$("#share").hide();
|
||||
$("#post_tag_string").focus().selectEnd().height($("#post_tag_string")[0].scrollHeight);
|
||||
$("#related-tags-button").trigger("click");
|
||||
$("#find-artist-button").trigger("click");
|
||||
} else {
|
||||
$("#edit").hide();
|
||||
$("#comments").hide();
|
||||
$("#share").show();
|
||||
addthis.init();
|
||||
}
|
||||
|
||||
$("#post-sections li").removeClass("active");
|
||||
$(e.target).parent("li").addClass("active");
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#post-sections li:first-child").addClass("active");
|
||||
$("#notes").hide();
|
||||
$("#edit").hide();
|
||||
}
|
||||
|
||||
Post.resize_ugoira_controls = function() {
|
||||
var $img = $("#image");
|
||||
var width = Math.max($img.width(), 350);
|
||||
$("#ugoira-control-panel").css("width", width);
|
||||
$("#seek-slider").css("width", width - 81);
|
||||
}
|
||||
|
||||
Post.notice_update = function(x) {
|
||||
if (x === "inc") {
|
||||
Post.pending_update_count += 1;
|
||||
$(window).trigger("danbooru:notice", "Updating posts (" + Post.pending_update_count + " pending)...", true);
|
||||
} else {
|
||||
Post.pending_update_count -= 1;
|
||||
|
||||
if (Post.pending_update_count < 1) {
|
||||
$(window).trigger("danbooru:notice", "Posts updated");
|
||||
} else {
|
||||
$(window).trigger("danbooru:notice", "Updating posts (" + Post.pending_update_count + " pending)...", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Post.update_data = function(data) {
|
||||
var $post = $("#post_" + data.id);
|
||||
$post.attr("data-tags", data.tag_string);
|
||||
$post.data("rating", data.rating);
|
||||
$post.removeClass("post-status-has-parent post-status-has-children");
|
||||
if (data.parent_id) {
|
||||
$post.addClass("post-status-has-parent");
|
||||
}
|
||||
if (data.has_visible_children) {
|
||||
$post.addClass("post-status-has-children");
|
||||
}
|
||||
}
|
||||
|
||||
Post.vote = function(score, id) {
|
||||
$(window).trigger("danbooru:notice", "Voting...");
|
||||
|
||||
$.post("/posts/" + id + "/votes.js", {
|
||||
score: score
|
||||
});
|
||||
}
|
||||
|
||||
Post.update = function(post_id, params) {
|
||||
Post.notice_update("inc");
|
||||
|
||||
$.ajax({
|
||||
type: "PUT",
|
||||
url: "/posts/" + post_id + ".json",
|
||||
data: params,
|
||||
success: function(data) {
|
||||
Post.notice_update("dec");
|
||||
Post.update_data(data);
|
||||
},
|
||||
error: function(data) {
|
||||
Post.notice_update("dec");
|
||||
$(window).trigger("danbooru:error", 'There was an error updating <a href="/posts/' + post_id + '">post #' + post_id + '</a>');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Post.ban = function(post_id) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/moderator/post/posts/" + post_id + "/ban.js",
|
||||
data: {
|
||||
commit: "Ban"
|
||||
},
|
||||
success: function(data) {
|
||||
$("#post_" + post_id).remove();
|
||||
},
|
||||
error: function(data) {
|
||||
$(window).trigger("danbooru:error", 'There was an error updating <a href="/posts/' + post_id + '">post #' + post_id + '</a>');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Post.approve = function(post_id) {
|
||||
$.post(
|
||||
"/moderator/post/approval.json",
|
||||
{"post_id": post_id}
|
||||
).fail(function(data) {
|
||||
var message = $.map(data.responseJSON.errors, function(msg, attr) { return msg; }).join("; ");
|
||||
$(window).trigger("danbooru:error", "Error: " + message);
|
||||
}).done(function(data) {
|
||||
var $post = $("#post_" + post_id);
|
||||
if ($post.length) {
|
||||
$post.data("flags", $post.data("flags").replace(/pending/, ""));
|
||||
$post.removeClass("post-status-pending");
|
||||
$(window).trigger("danbooru:notice", "Approved post #" + post_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Post.favorite = function (e) {
|
||||
if ($("#add-to-favorites").is(":visible")) {
|
||||
$("#add-to-favorites")[0].click();
|
||||
} else {
|
||||
if (Utility.meta("current-user-id") == "") {
|
||||
$(window).trigger("danbooru:notice", "You must be logged in to favorite posts");
|
||||
} else {
|
||||
$(window).trigger("danbooru:notice", "You have already favorited this post");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Post.unfavorite = function (e) {
|
||||
$.ajax("/favorites/" + Utility.meta("post-id") + ".js", {
|
||||
type: "DELETE"
|
||||
});
|
||||
};
|
||||
|
||||
Post.initialize_saved_searches = function() {
|
||||
$("#new_saved_search #saved_search_label_string").autocomplete({
|
||||
search: function() {
|
||||
$(this).data("ui-autocomplete").menu.bindings = $();
|
||||
},
|
||||
source: function(req, resp) {
|
||||
SavedSearch.labels(req.term).then(function(labels) {
|
||||
resp(labels.map(function(label) {
|
||||
return {
|
||||
label: label.replace(/_/g, " "),
|
||||
value: label
|
||||
};
|
||||
}));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$("#save-search-dialog").dialog({
|
||||
width: 500,
|
||||
modal: true,
|
||||
autoOpen: false,
|
||||
buttons: {
|
||||
"Submit": function() {
|
||||
$("#save-search-dialog form").submit();
|
||||
$(this).dialog("close");
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("#save-search").click(function(e) {
|
||||
$("#save-search-dialog #saved_search_query").val($("#tags").val());
|
||||
|
||||
if (Utility.meta("disable-labeled-saved-searches") === "false") {
|
||||
$("#save-search-dialog").dialog("open");
|
||||
} else {
|
||||
$.post(
|
||||
"/saved_searches.js",
|
||||
{
|
||||
"saved_search": {
|
||||
"query": $("#tags").val()
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#search-dropdown #wiki-search").click(function(e) {
|
||||
window.location.href = "/wiki_pages?search%5Btitle%5D=" + encodeURIComponent($("#tags").val());
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#search-dropdown #artist-search").click(function(e) {
|
||||
window.location.href = "/artists?search%5Bname%5D=" + encodeURIComponent($("#tags").val());
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Post.initialize_replace_image_dialog = function() {
|
||||
$("#replace-image-dialog").dialog({
|
||||
autoOpen: false,
|
||||
width: 700,
|
||||
modal: true,
|
||||
buttons: {
|
||||
"Submit": function() {
|
||||
$("#replace-image-dialog form").submit();
|
||||
$(this).dialog("close");
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#replace-image-dialog form').submit(function() {
|
||||
$('#replace-image-dialog').dialog('close');
|
||||
});
|
||||
|
||||
$("#replace-image").click(function(e) {
|
||||
e.preventDefault();
|
||||
$("#replace-image-dialog").dialog("open");
|
||||
});
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
Post.initialize_all();
|
||||
});
|
||||
|
||||
export default Post
|
||||
354
app/javascript/src/javascripts/related_tag.js.erb
Normal file
354
app/javascript/src/javascripts/related_tag.js.erb
Normal file
@@ -0,0 +1,354 @@
|
||||
import './cookie'
|
||||
import './utility'
|
||||
|
||||
let RelatedTag = {};
|
||||
|
||||
RelatedTag.initialize_all = function() {
|
||||
if ($("#c-posts #a-show").length || $("#c-uploads #a-new").length) {
|
||||
this.initialize_buttons();
|
||||
$("#artist-tags-container").hide();
|
||||
$("#upload_tag_string,#post_tag_string").keyup(RelatedTag.update_selected);
|
||||
$("body").on("click", "#artist-related-tags-column a.del", RelatedTag.disable_artist_url)
|
||||
}
|
||||
}
|
||||
|
||||
RelatedTag.initialize_buttons = function() {
|
||||
this.common_bind("#related-tags-button", "");
|
||||
<% TagCategory.related_button_list.each do |category| %>
|
||||
RelatedTag.common_bind("#related-<%= category %>-button", "<%= category %>");
|
||||
<% end %>
|
||||
$("#find-artist-button").click(RelatedTag.find_artist);
|
||||
}
|
||||
|
||||
RelatedTag.tags_include = function(name) {
|
||||
var current = $("#upload_tag_string,#post_tag_string").val().toLowerCase().match(/\S+/g) || [];
|
||||
if ($.inArray(name.toLowerCase(), current) > -1) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
RelatedTag.common_bind = function(button_name, category) {
|
||||
$(button_name).click(function(e) {
|
||||
var $dest = $("#related-tags");
|
||||
$dest.empty();
|
||||
RelatedTag.build_recent_and_frequent($dest);
|
||||
$dest.append("<em>Loading...</em>");
|
||||
$.get("/related_tag.json", {
|
||||
"query": RelatedTag.current_tag(),
|
||||
"category": category
|
||||
}, RelatedTag.process_response);
|
||||
$("#artist-tags-container").hide();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
RelatedTag.current_tag = function() {
|
||||
// 1. abc def | -> def
|
||||
// 2. abc def| -> def
|
||||
// 3. abc de|f -> def
|
||||
// 4. abc |def -> def
|
||||
// 5. abc| def -> abc
|
||||
// 6. ab|c def -> abc
|
||||
// 7. |abc def -> abc
|
||||
// 8. | abc def -> abc
|
||||
|
||||
var $field = $("#upload_tag_string,#post_tag_string");
|
||||
var string = $field.val();
|
||||
var n = string.length;
|
||||
var a = $field.prop('selectionStart');
|
||||
var b = $field.prop('selectionStart');
|
||||
|
||||
if ((a > 0) && (a < (n - 1)) && (!/\s/.test(string[a])) && (/\s/.test(string[a - 1]))) {
|
||||
// 4 is the only case where we need to scan forward. in all other cases we
|
||||
// can drag a backwards, and then drag b forwards.
|
||||
|
||||
while ((b < n) && (!/\s/.test(string[b]))) {
|
||||
b++;
|
||||
}
|
||||
} else if (string.search(/\S/) > b) { // case 8
|
||||
b = string.search(/\S/);
|
||||
while ((b < n) && (!/\s/.test(string[b]))) {
|
||||
b++;
|
||||
}
|
||||
} else {
|
||||
while ((a > 0) && ((/\s/.test(string[a])) || (string[a] === undefined))) {
|
||||
a--;
|
||||
b--;
|
||||
}
|
||||
|
||||
while ((a > 0) && (!/\s/.test(string[a - 1]))) {
|
||||
a--;
|
||||
b--;
|
||||
}
|
||||
|
||||
while ((b < (n - 1)) && (!/\s/.test(string[b]))) {
|
||||
b++;
|
||||
}
|
||||
}
|
||||
|
||||
b++;
|
||||
return string.slice(a, b);
|
||||
}
|
||||
|
||||
RelatedTag.process_response = function(data) {
|
||||
RelatedTag.recent_search = data;
|
||||
RelatedTag.build_all();
|
||||
}
|
||||
|
||||
RelatedTag.update_selected = function(e) {
|
||||
var current_tags = $("#upload_tag_string,#post_tag_string").val().toLowerCase().match(/\S+/g) || [];
|
||||
var $all_tags = $("#related-tags a");
|
||||
$all_tags.removeClass("selected");
|
||||
|
||||
$all_tags.each(function(i, tag) {
|
||||
if (current_tags.indexOf(tag.textContent.replace(/ /g, "_")) > -1) {
|
||||
$(tag).addClass("selected");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
RelatedTag.build_all = function() {
|
||||
if (RelatedTag.recent_search === null || RelatedTag.recent_search === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
RelatedTag.show();
|
||||
|
||||
var query = RelatedTag.recent_search.query;
|
||||
var related_tags = RelatedTag.recent_search.tags;
|
||||
var wiki_page_tags = RelatedTag.recent_search.wiki_page_tags;
|
||||
var other_wikis = RelatedTag.recent_search.other_wikis;
|
||||
var $dest = $("#related-tags");
|
||||
$dest.empty();
|
||||
|
||||
this.build_recent_and_frequent($dest);
|
||||
|
||||
$dest.append(this.build_html(query, related_tags, "general"));
|
||||
this.build_translated($dest);
|
||||
if (wiki_page_tags.length) {
|
||||
$dest.append(RelatedTag.build_html("wiki:" + query, wiki_page_tags, "wiki"));
|
||||
}
|
||||
$.each(other_wikis, function(i,wiki) {
|
||||
$dest.append(RelatedTag.build_html("wiki:" + wiki.title, wiki.wiki_page_tags, "otherwiki" + i.toString()));
|
||||
});
|
||||
if (RelatedTag.recent_artists) {
|
||||
var tags = [];
|
||||
if (RelatedTag.recent_artists.length === 0) {
|
||||
tags.push([" none", 0]);
|
||||
} else if (RelatedTag.recent_artists.length === 1) {
|
||||
tags.push([RelatedTag.recent_artists[0].name, 1]);
|
||||
if (RelatedTag.recent_artists[0].is_banned === true) {
|
||||
tags.push(["BANNED_ARTIST", "banned"]);
|
||||
}
|
||||
$.each(RelatedTag.recent_artists[0].sorted_urls, function(i, url) {
|
||||
var x = url.url;
|
||||
if (!url.is_active) {
|
||||
x = "-" + x;
|
||||
}
|
||||
tags.push([" " + x, 0]);
|
||||
});
|
||||
} else if (RelatedTag.recent_artists.length >= 10) {
|
||||
tags.push([" none", 0]);
|
||||
} else {
|
||||
$.each(RelatedTag.recent_artists, function(i, artist) {
|
||||
tags.push([artist.name, 1]);
|
||||
});
|
||||
}
|
||||
$dest.append(RelatedTag.build_html("artist", tags, "artist", true));
|
||||
}
|
||||
}
|
||||
|
||||
RelatedTag.build_recent_and_frequent = function($dest) {
|
||||
var recent_tags = Cookie.get("recent_tags_with_categories");
|
||||
var favorite_tags = Cookie.get("favorite_tags_with_categories");
|
||||
if (recent_tags.length) {
|
||||
$dest.append(this.build_html("recent", this.other_tags(recent_tags), "recent"));
|
||||
}
|
||||
if (favorite_tags.length) {
|
||||
$dest.append(this.build_html("frequent", this.other_tags(favorite_tags), "frequent"));
|
||||
}
|
||||
}
|
||||
|
||||
RelatedTag.other_tags = function(string) {
|
||||
if (string && string.length) {
|
||||
return $.map(string.match(/\S+ \d+/g), function(x, i) {
|
||||
var submatch = x.match(/(\S+) (\d+)/);
|
||||
return [[submatch[1], submatch[2]]];
|
||||
});
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
RelatedTag.build_translated = function($dest) {
|
||||
if (RelatedTag.translated_tags && RelatedTag.translated_tags.length) {
|
||||
$dest.append(this.build_html("Translated Tags", RelatedTag.translated_tags, "translated"));
|
||||
}
|
||||
}
|
||||
|
||||
RelatedTag.build_html = function(query, related_tags, name, is_wide_column) {
|
||||
if (query === null || query === "") {
|
||||
return "";
|
||||
}
|
||||
|
||||
query = query.replace(/_/g, " ");
|
||||
var header = $("<em/>");
|
||||
|
||||
var match = query.match(/^wiki:(.+)/);
|
||||
if (match) {
|
||||
header.html($("<a/>").attr("href", "/wiki_pages?title=" + encodeURIComponent(match[1])).attr("target", "_blank").text(query));
|
||||
} else {
|
||||
header.text(query);
|
||||
}
|
||||
|
||||
var $div = $("<div/>");
|
||||
$div.attr("id", name + "-related-tags-column");
|
||||
$div.addClass("tag-column");
|
||||
if (is_wide_column) {
|
||||
$div.addClass("wide-column");
|
||||
}
|
||||
var $ul = $("<ul/>");
|
||||
$ul.append(
|
||||
$("<li/>").append(
|
||||
header
|
||||
)
|
||||
);
|
||||
|
||||
$.each(related_tags, function(i, tag) {
|
||||
if (tag[0][0] !== " ") {
|
||||
var $link = $("<a/>");
|
||||
$link.text(tag[0].replace(/_/g, " "));
|
||||
$link.addClass("tag-type-" + tag[1]);
|
||||
$link.attr("href", "/posts?tags=" + encodeURIComponent(tag[0]));
|
||||
$link.click(RelatedTag.toggle_tag);
|
||||
if (RelatedTag.tags_include(tag[0])) {
|
||||
$link.addClass("selected");
|
||||
}
|
||||
$ul.append(
|
||||
$("<li/>").append($link)
|
||||
);
|
||||
} else {
|
||||
var text = tag[0];
|
||||
if (text.match(/^ -http/)) {
|
||||
text = text.substring(1, 1000);
|
||||
var desc = text.replace(/^-https?:\/\//, "");
|
||||
if (desc.length > 30) {
|
||||
desc = desc.substring(0, 30) + "...";
|
||||
}
|
||||
$ul.append(
|
||||
$("<li>").append(
|
||||
$("<del>").text(desc)
|
||||
)
|
||||
);
|
||||
} else if (text.match(/^ http/)) {
|
||||
text = text.substring(1, 1000);
|
||||
var desc = text.replace(/^https?:\/\//, "");
|
||||
if (desc.length > 30) {
|
||||
desc = desc.substring(0, 30) + "...";
|
||||
}
|
||||
$ul.append(
|
||||
$("<li>").append([
|
||||
$("<a>").text(desc).attr("href", text).attr("target", "_blank"),
|
||||
" ",
|
||||
$("<a>").attr("href", text).addClass("del").append(
|
||||
$("<i>").addClass("fas fa-minus-circle")
|
||||
)
|
||||
])
|
||||
);
|
||||
} else {
|
||||
$ul.append($("<li/>").text(text));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$div.append($ul);
|
||||
return $div;
|
||||
}
|
||||
|
||||
RelatedTag.toggle_tag = function(e) {
|
||||
var $field = $("#upload_tag_string,#post_tag_string");
|
||||
var tag = $(e.target).html().replace(/ /g, "_").replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&");
|
||||
|
||||
if (RelatedTag.tags_include(tag)) {
|
||||
var escaped_tag = Utility.regexp_escape(tag);
|
||||
$field.val($field.val().replace(new RegExp("(^|\\s)" + escaped_tag + "($|\\s)", "gi"), "$1$2"));
|
||||
} else {
|
||||
$field.val($field.val() + " " + tag);
|
||||
}
|
||||
$field.val($field.val().trim().replace(/ +/g, " ") + " ");
|
||||
|
||||
RelatedTag.update_selected();
|
||||
if (RelatedTag.recent_artist && $("#artist-tags-container").css("display") === "block") {
|
||||
RelatedTag.process_artist(RelatedTag.recent_artist);
|
||||
}
|
||||
|
||||
//The timeout is needed on Chrome since it will clobber the field attribute otherwise
|
||||
setTimeout(function () { $field.prop('selectionStart', $field.val().length);}, 100);
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
RelatedTag.find_artist = function(e) {
|
||||
$("#artist-tags").html("<em>Loading...</em>");
|
||||
var url = $("#upload_source,#post_source");
|
||||
var referer_url = $("#upload_referer_url");
|
||||
$.get("/artists/finder.json", {"url": url.val(), "referer_url": referer_url.val()}, RelatedTag.process_artist);
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
RelatedTag.process_artist = function(data) {
|
||||
RelatedTag.recent_artists = data;
|
||||
RelatedTag.build_all();
|
||||
}
|
||||
|
||||
RelatedTag.toggle = function() {
|
||||
if ($("#related-tags").is(":visible")) {
|
||||
RelatedTag.hide();
|
||||
} else {
|
||||
RelatedTag.show();
|
||||
$("#related-tags-button").trigger("click");
|
||||
$("#find-artist-button").trigger("click");
|
||||
}
|
||||
}
|
||||
|
||||
RelatedTag.show = function() {
|
||||
$("#related-tags").show()
|
||||
$("#toggle-related-tags-link").text("«");
|
||||
$("#edit-dialog").height("auto");
|
||||
}
|
||||
|
||||
RelatedTag.hide = function() {
|
||||
$("#related-tags").hide();
|
||||
$("#toggle-related-tags-link").text("»");
|
||||
}
|
||||
|
||||
RelatedTag.disable_artist_url = function(e) {
|
||||
var url = e.currentTarget.href;
|
||||
$.each(RelatedTag.recent_artists[0].sorted_urls, function(k, v) {
|
||||
if (v["normalized_url"] === url || v["url"] === url) {
|
||||
if (!confirm("This will mark the URL as inactive. Continue?")) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax("/artist_urls/" + v["id"], {
|
||||
method: "PUT",
|
||||
data: {
|
||||
artist_url: {
|
||||
is_active: false
|
||||
}
|
||||
}
|
||||
}).done(RelatedTag.find_artist);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
$(function() {
|
||||
RelatedTag.initialize_all();
|
||||
});
|
||||
|
||||
export default RelatedTag
|
||||
|
||||
7
app/javascript/src/javascripts/responsive.js
Normal file
7
app/javascript/src/javascripts/responsive.js
Normal file
@@ -0,0 +1,7 @@
|
||||
$(function() {
|
||||
$("#maintoggle").click(function() {
|
||||
$('#nav').toggle();
|
||||
$('#maintoggle-on').toggle();
|
||||
$('#maintoggle-off').toggle();
|
||||
});
|
||||
});
|
||||
20
app/javascript/src/javascripts/saved_searches.js
Normal file
20
app/javascript/src/javascripts/saved_searches.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import Utility from './utility'
|
||||
|
||||
let SavedSearch = {};
|
||||
|
||||
SavedSearch.initialize_all = function() {
|
||||
if ($("#c-saved-searches").length) {
|
||||
Utility.sorttable($("#c-saved-searches table"));
|
||||
}
|
||||
}
|
||||
|
||||
SavedSearch.labels = function(term) {
|
||||
return $.getJSON("/saved_searches/labels", {
|
||||
"search[label]": term + "*",
|
||||
"limit": 10
|
||||
});
|
||||
}
|
||||
|
||||
$(SavedSearch.initialize_all);
|
||||
|
||||
export default SavedSearch
|
||||
59
app/javascript/src/javascripts/shortcuts.js
Normal file
59
app/javascript/src/javascripts/shortcuts.js
Normal file
@@ -0,0 +1,59 @@
|
||||
import Utility from './utility'
|
||||
import Post from './posts.js.erb'
|
||||
|
||||
let Shortcuts = {};
|
||||
|
||||
Shortcuts.initialize = function() {
|
||||
Utility.keydown("s", "scroll_down", Shortcuts.nav_scroll_down);
|
||||
Utility.keydown("w", "scroll_up", Shortcuts.nav_scroll_up);
|
||||
|
||||
Utility.keydown("q", "focus_search", function(e) {
|
||||
$("#tags, #search_name, #search_name_matches, #query").trigger("focus").selectEnd();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
if ($("#image").length) { // post page or bookmarklet upload page
|
||||
Utility.keydown("shift+e", "edit_dialog", function(e) {
|
||||
if (Utility.meta("current-user-id") == "") { // anonymous
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$("#edit-dialog").length) {
|
||||
$("#edit").show();
|
||||
$("#comments").hide();
|
||||
$("#share").hide();
|
||||
$("#post-sections li").removeClass("active");
|
||||
$("#post-edit-link").parent("li").addClass("active");
|
||||
$("#related-tags-container").show();
|
||||
|
||||
Post.open_edit_dialog();
|
||||
}
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
if ($("#c-posts #a-index, #c-favorites #a-index").length) {
|
||||
Utility.keydown("r", "random", function(e) {
|
||||
$("#random-post")[0].click();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Shortcuts.nav_scroll_down = function() {
|
||||
var scroll_top = $(window).scrollTop() + ($(window).height() * 0.15);
|
||||
$(window).scrollTop(scroll_top);
|
||||
}
|
||||
|
||||
Shortcuts.nav_scroll_up = function() {
|
||||
var scroll_top = $(window).scrollTop() - ($(window).height() * 0.15);
|
||||
if (scroll_top < 0) {
|
||||
scroll_top = 0;
|
||||
}
|
||||
$(window).scrollTop(scroll_top);
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
Shortcuts.initialize();
|
||||
});
|
||||
|
||||
export default Shortcuts
|
||||
60
app/javascript/src/javascripts/tag_script.js
Normal file
60
app/javascript/src/javascripts/tag_script.js
Normal file
@@ -0,0 +1,60 @@
|
||||
import Utility from './utility'
|
||||
import Post from './posts.js.erb'
|
||||
|
||||
let TagScript = {};
|
||||
|
||||
TagScript.parse = function(script) {
|
||||
return script.match(/\[.+?\]|\S+/g);
|
||||
}
|
||||
|
||||
TagScript.test = function(tags, predicate) {
|
||||
var split_pred = predicate.match(/\S+/g);
|
||||
var is_true = true;
|
||||
|
||||
$.each(split_pred, function(i, x) {
|
||||
if (x[0] === "-") {
|
||||
if ($.inArray(x.substr(1, 100), tags)) {
|
||||
is_true = false;
|
||||
}
|
||||
} else {
|
||||
if (!$.inArray(x, tags)) {
|
||||
is_true = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return is_true;
|
||||
}
|
||||
|
||||
TagScript.process = function(tags, command) {
|
||||
if (command.match(/^\[if/)) {
|
||||
var match = command.match(/\[if\s+(.+?)\s*,\s*(.+?)\]/);
|
||||
if (TagScript.test(tags, match[1])) {
|
||||
return TagScript.process(tags, match[2]);
|
||||
} else {
|
||||
return tags;
|
||||
}
|
||||
} else if (command === "[reset]") {
|
||||
return [];
|
||||
} else if (command[0] === "-" && !command.match(/^(?:-pool|-parent|-fav|-favgroup):/i)) {
|
||||
return Utility.reject(tags, function(x) {return x === command.substr(1, 100)});
|
||||
} else {
|
||||
tags.push(command);
|
||||
return tags;
|
||||
}
|
||||
}
|
||||
|
||||
TagScript.run = function(post_id, tag_script) {
|
||||
var commands = TagScript.parse(tag_script);
|
||||
var $post = $("#post_" + post_id);
|
||||
var old_tags = $post.data("tags");
|
||||
|
||||
$.each(commands, function(i, x) {
|
||||
var array = String($post.data("tags")).match(/\S+/g);
|
||||
$post.data("tags", TagScript.process(array, x).join(" "));
|
||||
});
|
||||
|
||||
Post.update(post_id, {"post[old_tag_string]": old_tags, "post[tag_string]": $post.data("tags")});
|
||||
}
|
||||
|
||||
export default TagScript
|
||||
208
app/javascript/src/javascripts/uploads.js
Normal file
208
app/javascript/src/javascripts/uploads.js
Normal file
@@ -0,0 +1,208 @@
|
||||
import Utility from './utility'
|
||||
import Post from './posts.js.erb'
|
||||
import Artist from './artists'
|
||||
import RelatedTag from './related_tag.js.erb'
|
||||
|
||||
let Upload = {};
|
||||
|
||||
Upload.initialize_all = function() {
|
||||
if ($("#c-uploads,#c-posts").length) {
|
||||
this.initialize_enter_on_tags();
|
||||
this.initialize_info_manual();
|
||||
}
|
||||
|
||||
if ($("#c-uploads").length) {
|
||||
if ($("#image").prop("complete")) {
|
||||
this.initialize_image();
|
||||
} else {
|
||||
$("#image").on("load error", this.initialize_image);
|
||||
}
|
||||
this.initialize_info_bookmarklet();
|
||||
this.initialize_similar();
|
||||
this.initialize_shortcuts();
|
||||
this.initialize_submit();
|
||||
$("#related-tags-button").trigger("click");
|
||||
|
||||
$("#toggle-artist-commentary").click(function(e) {
|
||||
Upload.toggle_commentary();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
if ($("#iqdb-similar").length) {
|
||||
this.initialize_iqdb_source();
|
||||
}
|
||||
}
|
||||
|
||||
Upload.initialize_submit = function() {
|
||||
$("#form").submit(function(e) {
|
||||
var error_messages = [];
|
||||
if (($("#upload_file").val() === "") && ($("#upload_source").val() === "") && $("#upload_md5_confirmation").val() === "") {
|
||||
error_messages.push("Must choose file or specify source");
|
||||
}
|
||||
if (!$("#upload_rating_s").prop("checked") && !$("#upload_rating_q").prop("checked") && !$("#upload_rating_e").prop("checked") &&
|
||||
($("#upload_tag_string").val().search(/\brating:[sqe]/i) < 0)) {
|
||||
error_messages.push("Must specify a rating");
|
||||
}
|
||||
if (error_messages.length === 0) {
|
||||
$("#submit-button").prop("disabled","true");
|
||||
$("#submit-button").prop("value","Submitting...");
|
||||
$("#client-errors").hide();
|
||||
} else {
|
||||
$("#client-errors").html("<strong>Error</strong>: " + error_messages.join(", "));
|
||||
$("#client-errors").show();
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Upload.initialize_shortcuts = function() {
|
||||
Utility.keydown("e", "edit", function(e) {
|
||||
$("#upload_tag_string").focus();
|
||||
e.preventDefault();
|
||||
});
|
||||
};
|
||||
|
||||
Upload.initialize_iqdb_source = function() {
|
||||
if (/^https?:\/\//.test($("#normalized_url").val())) {
|
||||
$.get("/iqdb_queries", {"url": $("#normalized_url").val()}).done(function(html) {$("#iqdb-similar").html(html)});
|
||||
}
|
||||
}
|
||||
|
||||
Upload.initialize_enter_on_tags = function() {
|
||||
var $textarea = $("#upload_tag_string, #post_tag_string");
|
||||
var $submit = $textarea.parents("form").find('input[type="submit"]');
|
||||
|
||||
$textarea.on("keydown.danbooru.submit", null, "return", function(e) {
|
||||
$submit.click();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Upload.initialize_similar = function() {
|
||||
$("#similar-button").click(function(e) {
|
||||
$.get("/iqdb_queries", {"url": $("#upload_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Upload.initialize_info_bookmarklet = function() {
|
||||
$("#upload_source").change(function (e) {
|
||||
$("#fetch-data-manual").click();
|
||||
});
|
||||
|
||||
$("#fetch-data-manual").click();
|
||||
}
|
||||
|
||||
Upload.initialize_info_manual = function() {
|
||||
$("#fetch-data-manual").click(function(e) {
|
||||
var source = $("#upload_source,#post_source").val();
|
||||
var referer = $("#upload_referer_url").val();
|
||||
|
||||
if (/^https?:\/\//.test(source)) {
|
||||
$("#source-info span#loading-data").show();
|
||||
Upload.fetch_source_data(source, referer);
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Upload.fetch_source_data = function(url, referer_url) {
|
||||
return $.getJSON("/source.json", { url: url, ref: referer_url })
|
||||
.then(Upload.fill_source_info)
|
||||
.catch(function(data) {
|
||||
$("#source-info span#loading-data").html("Error: " + data.responseJSON["message"])
|
||||
});
|
||||
}
|
||||
|
||||
Upload.fill_source_info = function(data) {
|
||||
$("#source-tags").empty();
|
||||
$.each(data.tags, function(i, v) {
|
||||
$("<a>").attr("href", v[1]).text(v[0]).appendTo("#source-tags");
|
||||
});
|
||||
|
||||
$("#source-artist-profile").attr("href", data.profile_url).text(data.artist_name);
|
||||
|
||||
RelatedTag.process_artist(data.artists);
|
||||
RelatedTag.translated_tags = data.translated_tags;
|
||||
RelatedTag.build_all();
|
||||
|
||||
if (data.artists.length === 0) {
|
||||
var new_artist_params = $.param({
|
||||
artist: {
|
||||
name: data.unique_id,
|
||||
other_names: data.artist_name,
|
||||
url_string: $.uniqueSort([data.profile_url, data.normalized_for_artist_finder_url]).join("\n")
|
||||
}
|
||||
});
|
||||
|
||||
var link = $("<a>").attr("href", "/artists/new?" + new_artist_params).text("Create new artist");
|
||||
$("#source-Artists").html(link);
|
||||
} else {
|
||||
var artistLinks = data.artists.map(function (artist) {
|
||||
return $('<a class="tag-type-1">').attr("href", "/artists/" + artist.id).text(artist.name);
|
||||
});
|
||||
|
||||
$("#source-Artists").html(artistLinks)
|
||||
}
|
||||
|
||||
if (data.image_urls.length > 1) {
|
||||
$("#gallery-warning").show();
|
||||
} else {
|
||||
$("#gallery-warning").hide();
|
||||
}
|
||||
|
||||
$("#upload_artist_commentary_title").val(data.artist_commentary.dtext_title);
|
||||
$("#upload_artist_commentary_desc").val(data.artist_commentary.dtext_description);
|
||||
Upload.toggle_commentary();
|
||||
|
||||
$("#source-info span#loading-data").hide();
|
||||
$("#source-info ul").show();
|
||||
}
|
||||
|
||||
Upload.update_scale = function() {
|
||||
var $image = $("#image");
|
||||
var ratio = $image.data("scale-factor");
|
||||
if (ratio < 1) {
|
||||
$("#scale").html("Scaled " + parseInt(100 * ratio) + "% (original: " + $image.data("original-width") + "x" + $image.data("original-height") + ")");
|
||||
} else {
|
||||
$("#scale").html("Original: " + $image.data("original-width") + "x" + $image.data("original-height"));
|
||||
}
|
||||
}
|
||||
|
||||
Upload.initialize_image = function() {
|
||||
var $image = $("#image");
|
||||
if (!$image.length) {
|
||||
return;
|
||||
}
|
||||
var width = $image.width();
|
||||
var height = $image.height();
|
||||
if (!width || !height) {
|
||||
// try again later
|
||||
$.timeout(100).done(function() {Upload.initialize_image()});
|
||||
return;
|
||||
}
|
||||
$image.data("original-width", width);
|
||||
$image.data("original-height", height);
|
||||
Post.resize_image_to_window($image);
|
||||
Post.initialize_post_image_resize_to_window_link();
|
||||
Upload.update_scale();
|
||||
$("#image-resize-to-window-link").click(Upload.update_scale);
|
||||
}
|
||||
|
||||
Upload.toggle_commentary = function() {
|
||||
if ($(".artist-commentary").is(":visible")) {
|
||||
$("#toggle-artist-commentary").text("show »");
|
||||
} else {
|
||||
$("#toggle-artist-commentary").text("« hide");
|
||||
}
|
||||
|
||||
$(".artist-commentary").slideToggle();
|
||||
};
|
||||
|
||||
$(function() {
|
||||
Upload.initialize_all();
|
||||
});
|
||||
|
||||
export default Upload
|
||||
182
app/javascript/src/javascripts/utility.js
Normal file
182
app/javascript/src/javascripts/utility.js
Normal file
@@ -0,0 +1,182 @@
|
||||
let Utility = {};
|
||||
|
||||
Utility.meta = function(key) {
|
||||
return $("meta[name=" + key + "]").attr("content");
|
||||
}
|
||||
|
||||
Utility.test_max_width = function(width) {
|
||||
if (!window.matchMedia) {
|
||||
return false;
|
||||
}
|
||||
var mq = window.matchMedia('(max-width: ' + width + 'px)');
|
||||
return mq.matches;
|
||||
}
|
||||
|
||||
Utility.scrolling = false;
|
||||
|
||||
Utility.scroll_to = function(element) {
|
||||
if (Utility.scrolling) {
|
||||
return;
|
||||
} else {
|
||||
Utility.scrolling = true;
|
||||
}
|
||||
|
||||
var top = null;
|
||||
if (typeof(element) === "number") {
|
||||
top = element;
|
||||
} else {
|
||||
top = element.offset().top - 10;
|
||||
}
|
||||
$('html, body').animate({scrollTop: top}, 300, "linear", function() {Utility.scrolling = false;});
|
||||
}
|
||||
|
||||
Utility.notice_timeout_id = undefined;
|
||||
|
||||
Utility.notice = function(msg, permanent) {
|
||||
$('#notice').addClass("ui-state-highlight").removeClass("ui-state-error").fadeIn("fast").children("span").html(msg);
|
||||
|
||||
if (Utility.notice_timeout_id !== undefined) {
|
||||
clearTimeout(Utility.notice_timeout_id)
|
||||
}
|
||||
if (!permanent) {
|
||||
Utility.notice_timeout_id = setTimeout(function() {
|
||||
$("#close-notice-link").click();
|
||||
Utility.notice_timeout_id = undefined;
|
||||
}, 6000);
|
||||
}
|
||||
}
|
||||
|
||||
Utility.error = function(msg) {
|
||||
$('#notice').removeClass("ui-state-highlight").addClass("ui-state-error").fadeIn("fast").children("span").html(msg);
|
||||
|
||||
if (Utility.notice_timeout_id !== undefined) {
|
||||
clearTimeout(Utility.notice_timeout_id)
|
||||
}
|
||||
}
|
||||
|
||||
Utility.keydown = function(keys, namespace, handler) {
|
||||
if (Utility.meta("enable-js-navigation") === "true") {
|
||||
$(document).on("keydown" + ".Utility." + namespace, null, keys, handler);
|
||||
}
|
||||
};
|
||||
|
||||
Utility.is_subset = function(array, subarray) {
|
||||
var all = true;
|
||||
|
||||
$.each(subarray, function(i, val) {
|
||||
if ($.inArray(val, array) === -1) {
|
||||
all = false;
|
||||
}
|
||||
});
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
Utility.intersect = function(a, b) {
|
||||
a = a.slice(0).sort();
|
||||
b = b.slice(0).sort();
|
||||
var result = [];
|
||||
while (a.length > 0 && b.length > 0)
|
||||
{
|
||||
if (a[0] < b[0]) {
|
||||
a.shift();
|
||||
} else if (a[0] > b[0]) {
|
||||
b.shift();
|
||||
} else {
|
||||
result.push(a.shift());
|
||||
b.shift();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Utility.without = function(array, element) {
|
||||
var temp = [];
|
||||
$.each(array, function(i, v) {
|
||||
if (v !== element) {
|
||||
temp.push(v);
|
||||
}
|
||||
});
|
||||
return temp;
|
||||
}
|
||||
|
||||
Utility.reject = function(array, f) {
|
||||
var filtered = [];
|
||||
$.each(array, function(i, x) {
|
||||
if (!f(x)) {
|
||||
filtered.push(x);
|
||||
}
|
||||
});
|
||||
return filtered;
|
||||
}
|
||||
|
||||
Utility.regexp_escape = function(string) {
|
||||
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
|
||||
}
|
||||
|
||||
Utility.get_url_parameter = function(sParam) {
|
||||
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
|
||||
sURLVariables = sPageURL.split('&'),
|
||||
sParameterName,
|
||||
i;
|
||||
|
||||
for (i = 0; i < sURLVariables.length; i++) {
|
||||
sParameterName = sURLVariables[i].split('=');
|
||||
|
||||
if (sParameterName[0] === sParam) {
|
||||
return sParameterName[1] === undefined ? true : sParameterName[1];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Utility.sorttable = function(table) {
|
||||
table.stupidtable();
|
||||
table.bind("aftertablesort", function(event, data) {
|
||||
$("#c-saved-searches table tbody tr").removeClass("even odd");
|
||||
$("#c-saved-searches table tbody tr:even").addClass("even");
|
||||
$("#c-saved-searches table tbody tr:odd").addClass("odd");
|
||||
});
|
||||
};
|
||||
|
||||
String.prototype.hash = function() {
|
||||
var hash = 5381, i = this.length;
|
||||
|
||||
while(i)
|
||||
hash = (hash * 33) ^ this.charCodeAt(--i)
|
||||
|
||||
return hash >>> 0;
|
||||
}
|
||||
|
||||
$.fn.selectRange = function(start, end) {
|
||||
return this.each(function() {
|
||||
if (this.setSelectionRange) {
|
||||
this.focus();
|
||||
this.setSelectionRange(start, end);
|
||||
} else if (this.createTextRange) {
|
||||
var range = this.createTextRange();
|
||||
range.collapse(true);
|
||||
range.moveEnd('character', end);
|
||||
range.moveStart('character', start);
|
||||
range.select();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$.fn.selectEnd = function(){
|
||||
if (this.length) {
|
||||
this.selectRange(this.val().length, this.val().length);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
$(function() {
|
||||
$(window).on("danbooru:notice", function(event, msg) {
|
||||
Utility.notice(msg);
|
||||
})
|
||||
|
||||
$(window).on("danbooru:error", function(event, msg) {
|
||||
Utility.error(msg);
|
||||
})
|
||||
});
|
||||
|
||||
export default Utility
|
||||
25
app/javascript/src/javascripts/wiki_pages.js
Normal file
25
app/javascript/src/javascripts/wiki_pages.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import Utility from './utility'
|
||||
|
||||
let WikiPage = {};
|
||||
|
||||
WikiPage.initialize_all = function() {
|
||||
if ($("#c-wiki-pages,#c-wiki-page-versions").length) {
|
||||
this.initialize_shortcuts();
|
||||
}
|
||||
}
|
||||
|
||||
WikiPage.initialize_shortcuts = function() {
|
||||
if ($("#a-show").length) {
|
||||
Utility.keydown("e", "edit", function(e) {
|
||||
$("#wiki-page-edit a")[0].click();
|
||||
});
|
||||
|
||||
Utility.keydown("shift+d", "delete", function(e) {
|
||||
$("#wiki-page-delete a")[0].click();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
WikiPage.initialize_all();
|
||||
});
|
||||
Reference in New Issue
Block a user