| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
Autolinker.match.Mention = Autolinker.Util.extend( Autolinker.match.Match, { |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
constructor : function( cfg ) { |
| 32 |
Autolinker.match.Match.prototype.constructor.call( this, cfg ); |
| 33 |
|
| 34 |
|
| 35 |
if( !cfg.serviceName ) throw new Error( '`serviceName` cfg required' ); |
| 36 |
if( !cfg.mention ) throw new Error( '`mention` cfg required' ); |
| 37 |
|
| 38 |
|
| 39 |
this.mention = cfg.mention; |
| 40 |
this.serviceName = cfg.serviceName; |
| 41 |
}, |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
getType : function() { |
| 50 |
return 'mention'; |
| 51 |
}, |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
getMention : function() { |
| 60 |
return this.mention; |
| 61 |
}, |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
getServiceName : function() { |
| 71 |
return this.serviceName; |
| 72 |
}, |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
getAnchorHref : function() { |
| 81 |
switch( this.serviceName ) { |
| 82 |
case 'twitter' : |
| 83 |
return 'https://twitter.com/' + this.mention; |
| 84 |
case 'instagram' : |
| 85 |
return 'https://instagram.com/' + this.mention; |
| 86 |
case 'soundcloud' : |
| 87 |
return 'https://soundcloud.com/' + this.mention; |
| 88 |
|
| 89 |
default : |
| 90 |
throw new Error( 'Unknown service name to point mention to: ', this.serviceName ); |
| 91 |
} |
| 92 |
}, |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
getAnchorText : function() { |
| 101 |
return '@' + this.mention; |
| 102 |
}, |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
getCssClassSuffixes : function() { |
| 113 |
var cssClassSuffixes = Autolinker.match.Match.prototype.getCssClassSuffixes.call( this ), |
| 114 |
serviceName = this.getServiceName(); |
| 115 |
|
| 116 |
if( serviceName ) { |
| 117 |
cssClassSuffixes.push( serviceName ); |
| 118 |
} |
| 119 |
return cssClassSuffixes; |
| 120 |
} |
| 121 |
|
| 122 |
} ); |