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

@br0ken/simpletooltip

v3.3.2

Published

CSS tooltips with position control via JS.

Downloads

22

Readme

simpleTooltip

simpleTooltip - the analogue or a lite-version of Tipsy Tooltip.

Most part of the development is implemented in CSS, but the role of controller performs a small JavaScript library.

Features

  • Only 3 Kb of exhaustive code.
  • Works in most browsers.
  • Easy to use.
  • Compact and harmonious appearance.
  • Simple text prompts without additional complexity.

Usage

Use of tooltip is possible on any HTML element. Just add the data-shift and data-title attributes to it. Value of the first one must be a predefined word that affects the positioning of a tooltip relative to the element to which it's given. The second - text of a tooltip (markup isn't supported).

Possible values for the data-shift and their impact on a shift:

| Value | Tooltip direction | | ----- | ----------------- | | nw | Northwest | | north | North | | ne | Northeast | | west | West | | east | East | | sw | Southwest | | south | South | | se | Southeast |

Examples

var params = {
    shift: 'west',
    title: 'Some text for displaying'
};

/**
 * For {Element}.
 */
document.getElementById('id').simpleTooltip(params);

/**
 * For {NodeList}.
 */
document.querySelectorAll('.class a').simpleTooltip(params);

/**
 * For {jQuery}.
 */
jQuery('.class a').simpleTooltip(params);

Note, the parameter to .simpleTooltip() must be an object that might contain shift and/or title. You can reimburse lack of parameters by setting them as attributes to HTML element (data-shift and/or data-title or title).

Examples with incomplete list of parameters:

<span title="Some value"></span>
<script>
  document
    .querySelectorAll('span')
    .simpleTooltip({shift: 'south'});
</script>

<!-- CSS class is used only for example. -->
<div class="set-tooltip" data-shift="west"></div>
<script>
  document
    .querySelectorAll('.set-tooltip')
    .simpleTooltip({title: 'Some nice text'});
</script>

There's also an ability to conditionally display the tooltip. Pass a function assigned to the hideIf parameter and compute the necessity of showing the tip.

document
.querySelectorAll('.set-tooltip')
  .simpleTooltip({
    shift: 'south',
    title: 'Some nice text',
    // Show the tooltip if a text within a container is wider than its width.
    hideIf: (element) => element.offsetWidth >= element.scrollWidth,
  });

Why JavaScript is needed?

Functions of the plugin aren't numerous. Initially performs a check for positioning the elements that have a tooltip - it shouldn't be static. For this reason, all non-conforming elements receive relative positioning.

When you hover the mouse over an element, its width gets calculated. If it's not more than maximal and tooltip not directed to south or north - plugin will do nothing more, otherwise:

  • width is greater than maximal - tooltip gets a value of maximum width and a special text formatting.
  • directed to south or north - the tooltip will be aligned to the center of an element.

Crossbrowsing

  • IE 9+
  • Chrome 2.0+
  • Opera 9.0+
  • Safari 3.1+
  • Firefox 1.0+
  • Android 1.0+
  • iOS 1.0+