1 | import { __extends } from "tslib";
|
---|
2 | import { Match } from './match';
|
---|
3 | /**
|
---|
4 | * @class Autolinker.match.Mention
|
---|
5 | * @extends Autolinker.match.Match
|
---|
6 | *
|
---|
7 | * Represents a Mention match found in an input string which should be Autolinked.
|
---|
8 | *
|
---|
9 | * See this class's superclass ({@link Autolinker.match.Match}) for more details.
|
---|
10 | */
|
---|
11 | var MentionMatch = /** @class */ (function (_super) {
|
---|
12 | __extends(MentionMatch, _super);
|
---|
13 | /**
|
---|
14 | * @method constructor
|
---|
15 | * @param {Object} cfg The configuration properties for the Match
|
---|
16 | * instance, specified in an Object (map).
|
---|
17 | */
|
---|
18 | function MentionMatch(cfg) {
|
---|
19 | var _this = _super.call(this, cfg) || this;
|
---|
20 | /**
|
---|
21 | * @cfg {String} serviceName
|
---|
22 | *
|
---|
23 | * The service to point mention matches to. See {@link Autolinker#mention}
|
---|
24 | * for available values.
|
---|
25 | */
|
---|
26 | _this.serviceName = 'twitter'; // default value just to get the above doc comment in the ES5 output and documentation generator
|
---|
27 | /**
|
---|
28 | * @cfg {String} mention (required)
|
---|
29 | *
|
---|
30 | * The Mention that was matched, without the '@' character.
|
---|
31 | */
|
---|
32 | _this.mention = ''; // default value just to get the above doc comment in the ES5 output and documentation generator
|
---|
33 | _this.mention = cfg.mention;
|
---|
34 | _this.serviceName = cfg.serviceName;
|
---|
35 | return _this;
|
---|
36 | }
|
---|
37 | /**
|
---|
38 | * Returns a string name for the type of match that this class represents.
|
---|
39 | * For the case of MentionMatch, returns 'mention'.
|
---|
40 | *
|
---|
41 | * @return {String}
|
---|
42 | */
|
---|
43 | MentionMatch.prototype.getType = function () {
|
---|
44 | return 'mention';
|
---|
45 | };
|
---|
46 | /**
|
---|
47 | * Returns the mention, without the '@' character.
|
---|
48 | *
|
---|
49 | * @return {String}
|
---|
50 | */
|
---|
51 | MentionMatch.prototype.getMention = function () {
|
---|
52 | return this.mention;
|
---|
53 | };
|
---|
54 | /**
|
---|
55 | * Returns the configured {@link #serviceName} to point the mention to.
|
---|
56 | * Ex: 'instagram', 'twitter', 'soundcloud'.
|
---|
57 | *
|
---|
58 | * @return {String}
|
---|
59 | */
|
---|
60 | MentionMatch.prototype.getServiceName = function () {
|
---|
61 | return this.serviceName;
|
---|
62 | };
|
---|
63 | /**
|
---|
64 | * Returns the anchor href that should be generated for the match.
|
---|
65 | *
|
---|
66 | * @return {String}
|
---|
67 | */
|
---|
68 | MentionMatch.prototype.getAnchorHref = function () {
|
---|
69 | switch (this.serviceName) {
|
---|
70 | case 'twitter':
|
---|
71 | return 'https://twitter.com/' + this.mention;
|
---|
72 | case 'instagram':
|
---|
73 | return 'https://instagram.com/' + this.mention;
|
---|
74 | case 'soundcloud':
|
---|
75 | return 'https://soundcloud.com/' + this.mention;
|
---|
76 | case 'tiktok':
|
---|
77 | return 'https://www.tiktok.com/@' + this.mention;
|
---|
78 | default:
|
---|
79 | // Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case.
|
---|
80 | throw new Error('Unknown service name to point mention to: ' + this.serviceName);
|
---|
81 | }
|
---|
82 | };
|
---|
83 | /**
|
---|
84 | * Returns the anchor text that should be generated for the match.
|
---|
85 | *
|
---|
86 | * @return {String}
|
---|
87 | */
|
---|
88 | MentionMatch.prototype.getAnchorText = function () {
|
---|
89 | return '@' + this.mention;
|
---|
90 | };
|
---|
91 | /**
|
---|
92 | * Returns the CSS class suffixes that should be used on a tag built with
|
---|
93 | * the match. See {@link Autolinker.match.Match#getCssClassSuffixes} for
|
---|
94 | * details.
|
---|
95 | *
|
---|
96 | * @return {String[]}
|
---|
97 | */
|
---|
98 | MentionMatch.prototype.getCssClassSuffixes = function () {
|
---|
99 | var cssClassSuffixes = _super.prototype.getCssClassSuffixes.call(this), serviceName = this.getServiceName();
|
---|
100 | if (serviceName) {
|
---|
101 | cssClassSuffixes.push(serviceName);
|
---|
102 | }
|
---|
103 | return cssClassSuffixes;
|
---|
104 | };
|
---|
105 | return MentionMatch;
|
---|
106 | }(Match));
|
---|
107 | export { MentionMatch };
|
---|
108 | //# sourceMappingURL=mention-match.js.map |
---|