Skip to content

Commit

Permalink
Add sticky media support
Browse files Browse the repository at this point in the history
  • Loading branch information
onattech committed Feb 26, 2023
1 parent 374e296 commit acc8906
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
26 changes: 26 additions & 0 deletions docusaurus-plugin/stickyMedia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'

const instantiateStickyMedia = () => {
new StickyMedia()
}

// On route change
export function onRouteDidUpdate({ location, previousLocation }) {
// Don't execute if we are still on the same page; the lifecycle may be fired
// because the hash changes (e.g. when navigating between headings)
if (location.pathname === previousLocation?.pathname) return
setTimeout(instantiateStickyMedia, 100)
}

// On load
if (ExecutionEnvironment.canUseDOM) {
window.addEventListener('load', () => {
// Remove stale video info
localStorage.removeItem('videoID')
localStorage.removeItem('videoModalFlag')
localStorage.removeItem('videoModalTime')
localStorage.setItem('videoModalView', 'fullscreen-mode')

setTimeout(instantiateStickyMedia, 100)
})
}
16 changes: 9 additions & 7 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ const config = {
onBrokenLinks: 'throw',
onBrokenMarkdownLinks: 'warn',

// EmailJS
// customFields: {
// EMAILJS_SERVER_ID: process.env.EMAILJS_SERVER_ID,
// EMAILJS_TEMPLATE_ID: process.env.EMAILJS_TEMPLATE_ID,
// EMAILJS_PUBLIC_KEY: process.env.EMAILJS_PUBLIC_KEY,
// },

customFields: { ...customFields },

// Even if you don't use internalization, you can use this field to set useful
Expand All @@ -49,6 +42,15 @@ const config = {
locales: ['en'],
},

scripts: [
{
src: '//cdn.jsdelivr.net/gh/app-generator/sticky-media@0.0.13/dist/index.min.js',
async: true,
},
],

clientModules: [require.resolve('./docusaurus-plugin/stickyMedia.js')],

presets: [
[
'classic',
Expand Down
8 changes: 8 additions & 0 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
--ifm-background-color: #f8f9fa;
--ifm-navbar-background-color: #f8f9fa;
--ifm-font-family-base: 'Roboto', 'Helvetica', 'Arial', sans-serif;
--docusaurus-highlighted-code-line-bg: rgb(76, 218, 251, 0.1);
}

/* For readability concerns, you should choose a lighter palette in dark mode. */
Expand All @@ -43,3 +44,10 @@
box-sizing: content-box;
padding: 2px;
}

.sticky-video-modal {
width: 100%;
height: 100%;
right: 0;
bottom: 0;
}
30 changes: 30 additions & 0 deletions versioned_docs/version-0.1/tutorial-extras/sticky-media.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
sidebar_position: 3
---

# Sticky media

You may add a sticky video by giving `sticky-popup` class to an `a` tag.

```html
<!-- md content above -->

<a
// highlight-next-line
class="sticky-popup"
target="_blank"
href="https://www.youtube.com/watch?v=G1OM2L7XK5Y"
>Sticky video</a
>

<!-- md content below -->
```

## Try it!

<a
class="sticky-popup"
target="_blank"
href="https://www.youtube.com/watch?v=G1OM2L7XK5Y"
data-video-id="G1OM2L7XK5Y"
>Sticky video</a>

0 comments on commit acc8906

Please sign in to comment.