From b44cb3f491d869772b822b2bba82235a35795dc6 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Sun, 29 Oct 2017 02:00:21 +0000 Subject: [PATCH] Prevent scrolling at embed load for those info channels --- webapp/titanembeds/static/js/embed.js | 19 +++++++++++++++++-- .../templates/card_queryparams.html.j2 | 12 ++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js index bff425e..92c93d7 100644 --- a/webapp/titanembeds/static/js/embed.js +++ b/webapp/titanembeds/static/js/embed.js @@ -20,6 +20,7 @@ var user_def_css; // Saves the user defined css var has_already_been_initially_resized = false; // keep track if the embed initially been resized + var has_handled_noscroll = false; // Prevent scrolling to bottom of embed at load if false var logintimer; // timer to keep track of user inactivity after hitting login var last_message_id; // last message tracked var selected_channel = null; // user selected channel @@ -237,11 +238,20 @@ $("#modal_invite_btn").attr("href", data.instant_invite); }); + if (getParameterByName("noscroll") != "true") { + has_handled_noscroll = true; + } + $(window).resize(function(){ // For those who decides to hide the embed at first load (display: none), resulting in the messages being not scrolled down. if (!has_already_been_initially_resized) { has_already_been_initially_resized = true; - $("html, body").animate({ scrollTop: $(document).height() }, "fast"); + if (has_handled_noscroll) { + $("html, body").animate({ scrollTop: $(document).height() }, "fast"); + } else { + has_handled_noscroll = true; + Materialize.toast('Continue scrolling to read on...', 5000); + } } }); @@ -880,7 +890,12 @@ last = message.id; } if (replace == null && jumpscroll) { - $("html, body").animate({ scrollTop: $(document).height() }, "slow"); + if (!has_handled_noscroll) { + has_handled_noscroll = true; + Materialize.toast('Continue scrolling to read on...', 5000); + } else { + $("html, body").animate({ scrollTop: $(document).height() }, "slow"); + } } $('#chatcontent').linkify({ target: "_blank" diff --git a/webapp/titanembeds/templates/card_queryparams.html.j2 b/webapp/titanembeds/templates/card_queryparams.html.j2 index 1387e0d..b4b9d19 100644 --- a/webapp/titanembeds/templates/card_queryparams.html.j2 +++ b/webapp/titanembeds/templates/card_queryparams.html.j2 @@ -18,6 +18,18 @@ Instead of having the top channel as the first channel your users see, you may change it. Enable Discord's Developer mode in the Appearances tab of the User Settings and copy the channel ID.
Eg: defaultchannel=1234567890 +
  • + noscroll=<boolean>
    + Prevents the embed from scrolling down on first load. Useful for those who wants to set #info -typed channels as their default channel. Gotta have those good reads! +
    + Avaliable Options: + +
    + Eg: noscroll=true +
  • theme=<string>
    Want your embed to use one of our premade themes? Look no further!