-
Notifications
You must be signed in to change notification settings - Fork 15
Reset top banner local storage entry every 30 days #651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dgarcia360
merged 2 commits into
scylladb:master
from
dgarcia360:set-localstorage-expiration
Dec 13, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| export const openExternalLinksNewBrowserTab = () => { | ||
| const isExternal = new RegExp("^(?:[a-z]+:)?//", "i"); | ||
| $("a.reference").each(function () { | ||
| $(this).removeClass("internal external"); | ||
|
|
||
| if (isExternal.test($(this).attr("href"))) { | ||
| $(this).addClass("external"); | ||
| $(this).attr("target", "_blank"); | ||
| } else { | ||
| $(this).addClass("internal"); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| export const createResponsiveTables = () => { | ||
| const tables = $("table.docutils"); | ||
| tables.wrap("<div class='table-wrapper'></div>"); | ||
|
|
||
| tables.each(function () { | ||
| if ($(this).find("thead tr").length > 1) { | ||
| $(this).addClass("thead-border"); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| export const createEnlargeImagesButtons = () => { | ||
| $(".content img[width], .content img[style]").each(function () { | ||
| // Update parent css | ||
| const revealID = (Math.random() + 1).toString(36).substring(7); | ||
| $(this).wrap( | ||
| `<span class="enlarge-image" data-open="` + revealID + `"></div>` | ||
| ); | ||
| // Add image reveal | ||
| const imageReveal = | ||
| ` | ||
| <div class="reveal enlarge-image-reveal" id="` + | ||
| revealID + | ||
| `" data-reveal> | ||
| <img src="` + | ||
| $(this).attr("src") + | ||
| `" data-close aria-label="Close modal"> | ||
| </div> | ||
| `; | ||
| $(this).after(imageReveal); | ||
| }); | ||
| $(".content a.image-reference").click(function (event) { | ||
| if ($(this).children(".enlarge-image").length > 0) { | ||
| event.preventDefault(); | ||
| } | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* Collapse navigation */ | ||
| const localStorageKey = "scylla-docs-collapse-side-nav"; | ||
|
|
||
| const calculateCollapsibleNavigationButtonPosition = () => { | ||
| const collapsibleButton = $(".collapsible-button"); | ||
| const footer = $(".footer"); | ||
| const offset = 10; | ||
| const footerOffset = footer.offset(); | ||
| const footerTop = footerOffset.top; | ||
| const footerBottom = footerTop + footer.outerHeight(); | ||
| const screenBottom = $(window).scrollTop() + $(window).innerHeight(); | ||
| const screenTop = $(window).scrollTop(); | ||
| if (screenBottom > footerTop && screenTop < footerBottom) { | ||
| collapsibleButton.css("bottom", screenBottom - footerTop + offset); | ||
| } else { | ||
| collapsibleButton.css("bottom", offset); | ||
| } | ||
| }; | ||
|
|
||
| const collapseNavigation = () => { | ||
| new Foundation.Tooltip($(".collapsible-button"), { | ||
| position: "top", | ||
| tipText: "Expand", | ||
| }); | ||
| localStorage.setItem(localStorageKey, "1"); | ||
| $("#side-nav").addClass("side-nav--collapsed"); | ||
| $(".content").addClass("content--collapsed"); | ||
| }; | ||
|
|
||
| const expandNavigation = () => { | ||
| new Foundation.Tooltip($(".collapsible-button"), { | ||
| position: "top", | ||
| tipText: "Collapse", | ||
| }); | ||
| localStorage.setItem(localStorageKey, "0"); | ||
| $("#side-nav").removeClass("side-nav--collapsed"); | ||
| $(".content").removeClass("content--collapsed"); | ||
| }; | ||
|
|
||
| export const loadCollapsibleNavigation = () => { | ||
| if (localStorage.getItem(localStorageKey) == "1") { | ||
| collapseNavigation(); | ||
| } else { | ||
| expandNavigation(); | ||
| } | ||
| calculateCollapsibleNavigationButtonPosition(); | ||
| }; | ||
|
|
||
| export const onClickCollapsibleNavigationButton = () => { | ||
| $(".collapsible-button").on("click", function () { | ||
| $(".collapsible-button").foundation("destroy"); | ||
| if ($("#side-nav").hasClass("side-nav--collapsed")) { | ||
| expandNavigation(); | ||
| } else { | ||
| collapseNavigation(); | ||
| } | ||
| calculateCollapsibleNavigationButtonPosition(); | ||
| }); | ||
| }; | ||
|
|
||
| export const onScrollCollapsibleNavigation = () => { | ||
| $(window).scroll(function () { | ||
| calculateCollapsibleNavigationButtonPosition(); | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| const localStorageKey = "scylladb-docs-hide-banner"; | ||
|
|
||
| const setItemWithExpiry = (key, value, days) => { | ||
| const now = new Date(); | ||
| const ttl = days * 24 * 60 * 60 * 1000; | ||
| const item = { | ||
| value: value, | ||
| expiry: now.getTime() + ttl, | ||
| }; | ||
| localStorage.setItem(key, JSON.stringify(item)); | ||
| }; | ||
|
|
||
| function getItemWithExpiry(key) { | ||
| const itemStr = localStorage.getItem(key); | ||
| if (!itemStr) { | ||
| return null; | ||
| } | ||
| const item = JSON.parse(itemStr); | ||
| const now = new Date(); | ||
|
|
||
| if (now.getTime() > item.expiry) { | ||
| localStorage.removeItem(key); | ||
| return null; | ||
| } | ||
| return item.value; | ||
| } | ||
|
|
||
| export const hideBanner = () => { | ||
| const promoBanner = $(".promo-banner"); | ||
| const promoBannerHeight = promoBanner.outerHeight(); | ||
| if (promoBanner.length && !getItemWithExpiry(localStorageKey)) { | ||
| promoBanner.show(); | ||
| $("body").css("margin-top", promoBannerHeight); | ||
| $(".side-nav").css("margin-top", promoBannerHeight); | ||
| $(".secondary-side-nav").css("margin-top", promoBannerHeight); | ||
| $(".layout").addClass("layout--has-banner"); | ||
| } else { | ||
| promoBanner.hide(); | ||
| } | ||
| }; | ||
|
|
||
| export const onCloseBanner = () => { | ||
| $(".promo-banner__close").on("click", function () { | ||
| setItemWithExpiry(localStorageKey, "1", 30); | ||
| $("body").css("margin-top", 0); | ||
| $(".side-nav").css("margin-top", 0); | ||
| $(".secondary-side-nav").css("margin-top", 0); | ||
| $(".promo-banner").hide(); | ||
| $(".layout").removeClass("layout--has-banner"); | ||
| }); | ||
| }; | ||
|
|
||
| export const onResizeBanner = () => { | ||
| $(window).resize(function () { | ||
| const promoBanner = $(".promo-banner"); | ||
| const promoBannerHeight = promoBanner.outerHeight(); | ||
| if (promoBanner.is(":visible")) { | ||
| $("body").css("margin-top", promoBannerHeight); | ||
| $(".side-nav").css("margin-top", promoBannerHeight); | ||
| $(".secondary-side-nav").css("margin-top", promoBannerHeight); | ||
| } | ||
| }); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move this value to config.py?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible. If necessary, we can work on it as part of a separate issue.