Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dvhb/phone-highlight

Automatically adds tel: attribute for phone numbers on your HTML page.
https://github.com/dvhb/phone-highlight

javascript mobile-first phone-number

Last synced: about 1 month ago
JSON representation

Automatically adds tel: attribute for phone numbers on your HTML page.

Awesome Lists containing this project

README

        

# jQuery Phone highlight

jQuery plugin which helps you replace text phone numbers with `` 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](https://github.com/hgoebl/mobile-detect.js)

Check out [demo](http://dvhb.github.io/phone-highlight/) (open from mobile device or use emulation).

### Basic usage

At first, add `jquery.phone-highlight.js` into your ``.

Then, put following into in you `main.js`:

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

Or with mobile-detect.js

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

Plugin will replace text phones with `a` tag.

```HTML
Lorem ipsum dolor
+7 (3812) 78-66-44
```

*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:

```javascript
$('.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:

```HTML
999-44-22
```

### 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](./LICENSE) © [dvhb](http://dvhb.ru/)