1 import Ember from 'ember'; |
1 import Ember from 'ember'; |
2 import * as constants from 'corpus-common-addon/utils/constants'; |
2 import * as constants from 'corpus-common-addon/utils/constants'; |
3 import layout from '../templates/components/doc-language'; |
3 import layout from '../templates/components/doc-language'; |
4 |
4 |
5 export default Ember.Component.extend({ |
5 export default Ember.Component.extend({ |
6 layout: layout, |
6 layout: layout, |
7 tagName: "span", |
7 tagName: 'span', |
8 |
8 |
9 lexvoResolver: Ember.inject.service(), |
9 lexvoResolver: Ember.inject.service(), |
10 |
10 |
11 _resolveLexvoIds: Ember.on('init', Ember.observer('url', function() { |
11 _resolveLexvoIds: Ember.on('init', Ember.observer('url', function () { |
12 this.get('lexvoResolver').getName(this.get('url')).then(function(str) { |
12 this.get('lexvoResolver').getName(this.get('url')).then(function (str) { |
13 if (!(this.get('isDestroyed') || this.get('isDestroying'))) { |
13 if (!(this.get('isDestroyed') || this.get('isDestroying'))) { |
14 this.set('resolvedName', str); |
14 this.set('resolvedName', str); |
15 } |
15 } |
16 }.bind(this)); |
16 }.bind(this)); |
17 })), |
17 })), |
18 |
18 |
19 code: Ember.computed('url', function() { |
19 code: Ember.computed('url', function () { |
20 var rawLanguage = this.get('url'); |
20 const rawLanguage = this.get('url'); |
21 if(rawLanguage && rawLanguage.startsWith(constants.LEXVO_BASE_URL) ) { |
21 |
22 return rawLanguage.substr(constants.LEXVO_BASE_URL.length); |
22 if (this.get('isLanguageNode')) { |
23 } |
23 return constants.LANGUAGES_NODES[rawLanguage]; |
24 return rawLanguage; |
24 } |
25 }), |
25 |
26 isLanguageLink: Ember.computed.match('url', /^http\:\/\//) |
26 if (rawLanguage && rawLanguage.startsWith(constants.LEXVO_BASE_URL)) { |
|
27 return rawLanguage.substr(constants.LEXVO_BASE_URL.length); |
|
28 } |
|
29 |
|
30 return rawLanguage; |
|
31 }), |
|
32 isLanguageLink: Ember.computed.match('url', /^http\:\/\//), |
|
33 isLanguageNode: Ember.computed('url', function () { |
|
34 return this.get('url') in constants.LANGUAGES_NODES; |
|
35 }) |
27 |
36 |
28 }); |
37 }); |