npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

display-if

v1.0.4

Published

A jQuery module that displays or hides specified elements based on input and data.

Downloads

4

Readme

Display If

A super light & simple jQuery module that displays or hides specified elements based on data.

Requirements

  • jQuery: version 1.11.1 or higher.

Installation

Package Manager

You can install via npm, yarn, bower, etc.

npm install display-if

Cloning the File

  1. Clone this repository or simply download either js/display-if.js or js/display-if.min.js.
    • Note: display-if.min.js is a minified version of js/display-if.js. This means that it is a smaller file. If you want to update the scripts contents, then copy js/display-if.js. Otherwise, download the minified version.
  2. Include the file in your project
<script src="your/path/to/display-if.min.js"></script>

Usage

  1. Name your input/form field. For example:
<input type="text" name="displayIfText" />
  1. Add data fields to the tag that you want to hide or show depending on the input value. For example:
<div class="form-text text-muted display-if"
     data-target_name="displayIfText"
     data-target_type="text"
     data-target_value="debug">
     <small>Debug mode: active!</small>
</div>
  • In this example, when input[name=displayIfText] has a value of debug, the div above will be visible.

Data Options

To add an option to your display-if element, use the html5 data- tags. For example, if your option is named option add a data-option='...' tag to your element.

| Option | Description | | ------------------ | ----------- | | target_name | The name of the form field that the display element depends on. | | target_class | The class of the form field that the display element depends on. This value is ignored if target_name is present. | | target_matches_identifier | The name of another form field. If this option is given, then the system will check if [name=data_target_name] has the same value as [name=data_target_matches_identifier] | | target_type | Default: 'default'. Options: 'text', 'select', 'password', 'radio', 'checkbox', 'default' The type of input. | | display_if_inverse | Default: false. If true, the display requirements will show the element if the negation of the display_if is satisfied | | target_value | The value that satisfies the display requirement. If the form field value is equal to the target_value, then the display requirement is satisfied. | | target_value_not | The value that breaks the display requirement. If the form field value is equal to the target_value, then the display requirement is not satisfied. This is an alias for setting the target_value and displsy_if_inverse=true | | target_value_can_be_null | Default: false. If true, then the target_value could match with matches_identifiers if both values are null. If false, then each target and match must have some value so satisfy the display requirement. |

Demo

Click here for a live demo. Demo Gif