Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ndla/article-scripts

Package Overview
Dependencies
Maintainers
10
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ndla/article-scripts

A collection of functions for making article content responsive (and interactive)

  • 2.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
75
increased by7400%
Maintainers
10
Weekly downloads
 
Created
Source

ndla-article-scripts

A collection of functions for making article content responsive (and interactive)

Installation

npm install @ndla/article-scripts

or

yarn add @ndla/article-scripts

Usage

Plain javascript (embed scripts)

import { addEventListenerForResize, updateIFrameDimensions, addFactBoxClickListener } from '@ndla/article-scripts';

window.onload = () => {
  // Invoke after article content has loaded
  updateIFrameDimensions();
  addEventListenerForResize();
  addFactBoxClickListener();
};

React

import {
  addEventListenerForResize,
  updateIFrameDimensions,
  addFactBoxClickListener,
  removeEventListenerForResize,
  removeFactBoxClickListener,
} from '@ndla/article-scripts';

class Article extends Component {
  componentDidMount() {
    addEventListenerForResize();
    updateIFrameDimensions();
    addFactBoxClickListener();
  }

  componentWillUnmount() {
    removeEventListenerForResize();
    removeFactBoxClickListener();
  }

  render() {
    const { article } = this.props;
    return (
      <article>
        <h1>{article.title}</h1>
        <div dangerouslySetInnerHTML={{ __html: article.content }} />
      </article>
    );
  }
}
export default Article;

API(functions)

articleScripts.initArticleScripts()

Initialize all default article scripts.

articleScripts.updateIFrameDimensions()

Update iframe height and width to fit screen/window size.

articleScripts.addEventListenerForResize()

Adds an resize event listener on window. The listener calls updateIFrameDimensions on browser window resize.

articleScripts.removeEventListenerForResize()

Removes the event listener added by addEventListenerForResize.

articleScripts.addFactBoxClickListener()

Adds an click listener on fact box buttons for expanding the content on small screens.

articleScripts.removeFactBoxClickListener()

Removes click listeners added by addFactBoxClickListener.

articleScripts.addShowDialogClickListeners()

Adds click listeners for displaying license info popup.

articleScripts.addCloseDialogClickListeners()

Adds click listeners for closing license info popups.

articleScripts.addCopyToClipboardListeners()

Add a click listener to buttons with a data-copy-string. The value of the attribute will be copied to the clipboard on click.

articleScripts.makeFigureLicenseIconsClickable()

Adds click listeneres for displaying license text popup on license icon click

articleScripts.addEventListenersForZoom()

Adds click listners for zooming image/figure

'articleScripts.removeEventListenersForZoom()'

Removes click listeners added by addEventListenersForZoom.

Keywords

FAQs

Package last updated on 18 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc