DEV: Remove safari hacks (#6)

This commit is contained in:
Joe 2019-11-27 03:32:57 +08:00 committed by GitHub
parent 13dfd68bc9
commit 34fd9dff66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 12 deletions

View File

@ -1,11 +1,10 @@
<script type="text/discourse-plugin" version="0.1"> <script type="text/discourse-plugin"
version="0.1">
const minimumOffset = require("discourse/lib/offset-calculator").minimumOffset; const minimumOffset = require("discourse/lib/offset-calculator").minimumOffset;
const { iconHTML } = require("discourse-common/lib/icon-library"); const { iconHTML } = require("discourse-common/lib/icon-library");
const { run } = Ember; const { run } = Ember;
const mobileView = $("html").hasClass("mobile-view"); const mobileView = $("html").hasClass("mobile-view");
const isSafari = !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/);
const scrollElemnt = isSafari ? "body" : "html";
const linkIcon = iconHTML("hashtag"); const linkIcon = iconHTML("hashtag");
const closeIcon = iconHTML("times"); const closeIcon = iconHTML("times");
@ -168,7 +167,7 @@
}, },
highlightItemsOnScroll: self => { highlightItemsOnScroll: self => {
$(scrollElemnt) $('html, body')
.promise() .promise()
.done(function() { .done(function() {
const winScrollTop = $(window).scrollTop(); const winScrollTop = $(window).scrollTop();
@ -226,21 +225,17 @@
.not(elem) .not(elem)
.not(elem.parent(".d-toc-subheading:has(.d-toc-active)")); .not(elem.parent(".d-toc-subheading:has(.d-toc-active)"));
return isSafari return target.slideUp(TOC_ANIMATION_SPEED);
? target.fadeOut(TOC_ANIMATION_SPEED)
: target.slideUp(TOC_ANIMATION_SPEED);
}, },
show: function(elem) { show: function(elem) {
return isSafari return elem.slideDown(TOC_ANIMATION_SPEED);
? elem.fadeIn(TOC_ANIMATION_SPEED)
: elem.slideDown(TOC_ANIMATION_SPEED);
}, },
scrollTo: function(elem) { scrollTo: function(elem) {
const currentDiv = $(`[data-d-toc="${elem.attr("data-d-toc")}"]`); const currentDiv = $(`[data-d-toc="${elem.attr("data-d-toc")}"]`);
$(scrollElemnt).animate( $('html, body').animate(
{ {
scrollTop: `${currentDiv.offset().top - minimumOffset()}` scrollTop: `${currentDiv.offset().top - minimumOffset()}`
}, },
@ -391,4 +386,4 @@
} }
}); });
} }
</script> </script>