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

@dvhb/phone-highlight

v0.1.5

Published

Automatically adds tel: attribute for phone numbers on your html page

Downloads

3

Readme

jQuery Phone highlight

jQuery plugin which helps you replace text phone numbers with <a href="tel:..."> tag.

It may be useful if you want to add user friendly markup on mobile devices, but want to keep text phone numbers in desktop version.

This plugin don't have library for detecting mobiles devices as a hard dependency. You are free to use your favorite one. For example mobile-detect.js

Check out demo (open from mobile device or use emulation).

Basic usage

At first, add jquery.phone-highlight.js into your <head>.

Then, put following into in you main.js:

$('p.containing-phones').phoneHighlight();

Or with mobile-detect.js

var md = new MobileDetect(window.navigator.userAgent);
if (md.mobile()) {
    $('.phones').phoneHighlight();
}

Plugin will replace text phones with a tag.

Lorem ipsum dolor <a href="tel:+73812786644" class="phone">+7 (3812) 78-66-44</a>

NOTE! Do not execute plugin on whole body or other huge/interactive parts of the page! It may break other scripts or cause perfomance issues.

Configuring

Plugin have 3 options which can be passed into its call:

$('.phone').phoneHighlight({
	countrycode: '+7',
	citycode: '3812',
	minLenWithouCodes: 7
});

How it works

It tooks text content of marked nodes and removes all symbols excepting digits and leading plus sign.

Then plugin checks format of obtained result. There are 2 possible cases:

  1. Current result already starts with plus sign or its length is greater than minLenWithouCodes option value. In this case countrycode and citycode won't be added to phone.
  2. Otherwise phone will be concatinated with countrycode and citycode Note, that default values of countrycode and citycode options is empty strings.

You can also override global code options by setting appropriate data attributes:

<span class="phone" data-countrycode="+1" data-citycode="123">999-44-22</span>

Running tests

At firts, you have to install dependencies by running npm install and bower install. Now execute npm run test command.

License

MIT License © dvhb