Fork me on GitHub

jQuery Phone Hightlight

Query 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

Demo

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

Download
Source on GitHub

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',
    minLenWithoutCodes: 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 minLenWithoutCodes 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.

Change log

Version 41.2

Released 28 November, 2016

Removes the align dialog asking if you want to align layers precisely
When aligning, the bottom-most layer is no longer treated as the key object
Fixes a bug where copying and pasting Symbols with a nested override to a new document would not copy over the nested Symbols
Version 41.1

Released 12 November, 2016

Fixes a bug where using complex documents could cras the map
Version 41

Released 02 November, 2016

If a Page has a grid set, but contains Artboards, we will no longer render the grid for the Page to avoid confusion
Resetting Symbol instances to their original size is now also enabled for multiple selection
Hidden layers are no longer taken into account when using the Center Canvas option in the View menu
Adds a new “Paste with Style” menu item for when you want to paste Rich Text into Sketch
Improves the accuracy of boolean operations
Improves shapes converted to outlines by removing overlapping paths and superfluous points
The alignment actions in the menu, inspector and contextual menu are now consistently labelled
Improves boolean operations by removing obsolete points
Symbol Masters can now be converted back to regular Artboards by using the Detach menu item
The align buttons in the Inspector now show their correct image when aligning vector points in the shape editor

License