Debian Codegraph @

src/match/Phone.js

raw symbols SCIP
1 /*global Autolinker */
2 /**
3 * @class Autolinker.match.Phone
4 * @extends Autolinker.match.Match
5 *
6 * Represents a Phone number match found in an input string which should be
7 * Autolinked.
8 *
9 * See this class's superclass ({@link Autolinker.match.Match}) for more
10 * details.
11 */
12 Autolinker.match.Phone = Autolinker.Util.extend( Autolinker.match.Match, {
13
14 /**
15 * @protected
16 * @property {String} number (required)
17 *
18 * The phone number that was matched, without any delimiter characters.
19 *
20 * Note: This is a string to allow for prefixed 0's.
21 */
22
23 /**
24 * @protected
25 * @property {Boolean} plusSign (required)
26 *
27 * `true` if the matched phone number started with a '+' sign. We'll include
28 * it in the `tel:` URL if so, as this is needed for international numbers.
29 *
30 * Ex: '+1 (123) 456 7879'
31 */
32
33
34 /**
35 * @constructor
36 * @param {Object} cfg The configuration properties for the Match
37 * instance, specified in an Object (map).
38 */
39 constructor : function( cfg ) {
40 Autolinker.match.Match.prototype.constructor.call( this, cfg );
41
42 // @if DEBUG
43 if( !cfg.number ) throw new Error( '`number` cfg required' );
44 if( cfg.plusSign == null ) throw new Error( '`plusSign` cfg required' );
45 // @endif
46
47 this.number = cfg.number;
48 this.plusSign = cfg.plusSign;
49 },
50
51
52 /**
53 * Returns a string name for the type of match that this class represents.
54 *
55 * @return {String}
56 */
57 getType : function() {
58 return 'phone';
59 },
60
61
62 /**
63 * Returns the phone number that was matched as a string, without any
64 * delimiter characters.
65 *
66 * Note: This is a string to allow for prefixed 0's.
67 *
68 * @return {String}
69 */
70 getNumber: function() {
71 return this.number;
72 },
73
74
75 /**
76 * Returns the anchor href that should be generated for the match.
77 *
78 * @return {String}
79 */
80 getAnchorHref : function() {
81 return 'tel:' + ( this.plusSign ? '+' : '' ) + this.number;
82 },
83
84
85 /**
86 * Returns the anchor text that should be generated for the match.
87 *
88 * @return {String}
89 */
90 getAnchorText : function() {
91 return this.matchedText;
92 }
93
94 } );