From 67c834841ea0f8fb4d8d194c0f68802f48e764ee Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 2 Mar 2018 14:40:26 +0100 Subject: Update react-markdown, properly scroll to section for wiki internal links, consolidate scrollTo logic and make external links open in new tabs --- packages/website/ts/utils/utils.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'packages/website/ts/utils/utils.ts') diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index c38f84c92..4d04d915d 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -4,6 +4,7 @@ import deepEqual = require('deep-equal'); import isMobile = require('is-mobile'); import * as _ from 'lodash'; import * as moment from 'moment'; +import { scroller } from 'react-scroll'; import { EtherscanLinkSuffixes, Networks, @@ -290,4 +291,22 @@ export const utils = { ); return isTestNetwork; }, + getCurrentBaseUrl() { + const port = window.location.port; + const hasPort = !_.isUndefined(port); + const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}`; + return baseUrl; + }, + scrollToHash(hashWithPrefix: string, containerId: string): void { + let hash = hashWithPrefix.slice(1); + if (_.isEmpty(hash)) { + hash = configs.SCROLL_TOP_ID; // scroll to the top + } + + scroller.scrollTo(hash, { + duration: 0, + offset: 0, + containerId, + }); + }, }; -- cgit From 0fbb443e4bb3ee6d522f4a4099aacae1b3da2488 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 2 Mar 2018 17:01:46 +0100 Subject: Move onPageLoadAsync to utils --- packages/website/ts/utils/utils.ts | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'packages/website/ts/utils/utils.ts') diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index 4d04d915d..27cd87be1 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -309,4 +309,12 @@ export const utils = { containerId, }); }, + async onPageLoadAsync(): Promise { + if (document.readyState === 'complete') { + return; // Already loaded + } + return new Promise((resolve, reject) => { + window.onload = () => resolve(); + }); + }, }; -- cgit From 0afe45b3a830bfefc4f9b51823891b99be5261fa Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Sat, 3 Mar 2018 05:36:08 +0100 Subject: Hash hash instead of prefixedHash to scrollToHash function --- packages/website/ts/utils/utils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'packages/website/ts/utils/utils.ts') diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index 27cd87be1..a1e045af7 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -297,13 +297,13 @@ export const utils = { const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}`; return baseUrl; }, - scrollToHash(hashWithPrefix: string, containerId: string): void { - let hash = hashWithPrefix.slice(1); + scrollToHash(hash: string, containerId: string): void { + let finalHash = hash; if (_.isEmpty(hash)) { - hash = configs.SCROLL_TOP_ID; // scroll to the top + finalHash = configs.SCROLL_TOP_ID; // scroll to the top } - scroller.scrollTo(hash, { + scroller.scrollTo(finalHash, { duration: 0, offset: 0, containerId, -- cgit