import CurrentUser from './current_user' import Utility from './utility' import Hammer from 'hammerjs' import Cookie from './cookie' import Note from './notes' import Ugoira from './ugoira' import Rails from '@rails/ujs' let Post = {}; Post.pending_update_count = 0; Post.SWIPE_THRESHOLD = 60; Post.SWIPE_VELOCITY = 0.6; Post.MAX_RECOMMENDATIONS = 45; // 3 rows of 9 posts at 1920x1080. Post.LOW_TAG_COUNT = 10; Post.HIGH_TAG_COUNT = 20; Post.EDIT_DIALOG_WIDTH = 720; Post.initialize_all = function() { if ($("#c-posts").length) { 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_recommended(); this.initialize_ugoira_player(); this.initialize_ruffle_player(); } if ($("#c-posts #a-show, #c-uploads #a-new").length) { this.initialize_edit_dialog(); } $(window).on('danbooru:initialize_saved_seraches', () => { Post.initialize_saved_searches(); }); } Post.initialize_gestures = function() { if (CurrentUser.data("disable-mobile-gestures")) { return; } var $body = $("body"); if ($body.data("hammer")) { return; } if (!Utility.test_max_width(660)) { return; } $(".image-container").css({overflow: "visible"}); var hasPrev = $(".paginator a[rel~=prev]").length; var hasNext = $(".paginator a[rel~=next]").length; var hammer = new Hammer($body[0], {touchAction: 'pan-y', recognizers: [[Hammer.Swipe, { threshold: Post.SWIPE_THRESHOLD, velocity: Post.SWIPE_VELOCITY, direction: Hammer.DIRECTION_HORIZONTAL }]], inputClass: Hammer.TouchInput}); $body.data("hammer", hammer); if (hasPrev) { hammer.on("swiperight", async function(e) { $("body").css({"transition-timing-function": "ease", "transition-duration": "0.2s", "opacity": "0", "transform": "translateX(150%)"}); await Utility.delay(200); Post.swipe_prev(e); }); } if (hasNext) { hammer.on("swipeleft", async function(e) { $("body").css({"transition-timing-function": "ease", "transition-duration": "0.2s", "opacity": "0", "transform": "translateX(-150%)"}); await Utility.delay(200); Post.swipe_next(e); }); } } Post.initialize_edit_dialog = function() { $("#open-edit-dialog").show().on("click.danbooru", function(e) { Post.open_edit_dialog(); e.preventDefault(); }); } Post.open_edit_dialog = function() { if ($("#edit-dialog").length === 1) { return; } $(document).trigger("danbooru:open-post-edit-dialog"); $("#edit").show(); $("#comments").hide(); $("#post-sections li").removeClass("active"); $("#post-edit-link").parent("li").addClass("active"); var $tag_string = $("#post_tag_string,#upload_tag_string"); $("#open-edit-dialog").hide(); var dialog = $("
").attr("id", "edit-dialog"); $("#form").appendTo(dialog); dialog.dialog({ title: "Edit tags", width: Post.EDIT_DIALOG_WIDTH, position: { my: "right", at: "right-20", of: window }, drag: function(e, ui) { $tag_string.data("uiAutocomplete").close(); }, close: Post.close_edit_dialog }); dialog.dialog("widget").draggable("option", "containment", "none"); var pin_button = $("