/* global addthis */ 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() { $("#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() { if ($("#edit-dialog").length === 1) { return; } $("#edit").show(); $("#comments").hide(); $("#share").hide(); $("#post-sections li").removeClass("active"); $("#post-edit-link").parent("li").addClass("active"); $("#related-tags-container").show(); var $tag_string = $("#post_tag_string,#upload_tag_string"); $("div.input").has($tag_string).prevAll().hide(); $("#open-edit-dialog").hide(); $("#toggle-related-tags-link").show().click(); var dialog = $("
").attr("id", "edit-dialog"); $("#form").appendTo(dialog); dialog.dialog({ title: "Edit tags", width: $(window).width() * 0.6, position: { my: "right", at: "right-20", of: window }, drag: function(e, ui) { if (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 = $("