New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@financial-times/o-toggle

Package Overview
Dependencies
Maintainers
14
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@financial-times/o-toggle

This utility component adds toggle (show/hide) behaviour to a `` or `` tag and a target.

  • 1.2.0
  • npm
  • Socket score

Version published
Maintainers
14
Created
Source

o-toggle CircleCI MIT licensed

This utility component adds toggle (show/hide) behaviour to a <button> or <a> tag and a target.

Quick start

Install the module:

bower install --S o-toggle

Load the JavaScript:

const oToggle = require('o-toggle');

oToggle.init();

Add some markup:

<button data-o-component="o-toggle" data-o-toggle-target=".my-toggle-target">My button</button>
<div class='my-toggle-target'>Some toggleable content</div>

Usage

JavaScript

An o-toggle object must be constructed for every element you have on your page that uses this module. You can do this for explicitly classed elements like so:

const OToggle = require('o-toggle');
const toggleEl = document.querySelector('.o-toggle');
const toggle = new OToggle(toggleEl, {
        target: '.my-target',
        callback: function(state, event) {
            if (state === 'open') {
                console.log('Target opened');
            } else if (state === 'close') {
                console.log('Target closed');
            }
        }
    });

Alternatively, an o.DOMContentLoaded event can be dispatched on the document to auto-construct an o-toggle object for each element with a data-o-component="o-toggle" attribute:

require('o-toggle');
document.addEventListener("DOMContentLoaded", function() {
    document.dispatchEvent(new CustomEvent('o.DOMContentLoaded'));
});

A second parameter can be passed to the oToggle constructor or to the .init() function with a config object that has the following options:

  • target: HTMLElement or selector of the element that will be toggled
  • callback: Function or content of a function as string that will be executed every time a toggle happens. It has the following parameters:
    • State. 'open' or 'close'
    • Click event object if it comes from the event handler on the toggle

Markup

All config options can also be passed as data attributes. These are:

  • data-o-toggle-target: Selector of the element that will be toggled
  • data-o-toggle-callback: Content of a function as string that will be executed every time a toggle happens

Contact

If you have any questions or comments about this component, or need help using it, please either raise an issue, visit #ft-origami or email Origami Support.


Licence

This software is published by the Financial Times under the MIT licence.

FAQs

Package last updated on 12 Feb 2019

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