mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Code improvements
- shared global declarations - reduced hyperlink-related repetitive code
This commit is contained in:
@@ -15,40 +15,25 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { WidgetComponent } from './../widget.component';
|
||||
|
||||
declare var componentHandler;
|
||||
|
||||
@Component({
|
||||
moduleId: module.id,
|
||||
selector: 'hyperlink-widget',
|
||||
templateUrl: './hyperlink.widget.html',
|
||||
styleUrls: ['./hyperlink.widget.css']
|
||||
})
|
||||
export class HyperlinkWidget extends WidgetComponent {
|
||||
export class HyperlinkWidget extends WidgetComponent implements OnInit {
|
||||
|
||||
static DEFAULT_URL: string = '#';
|
||||
static DEFAULT_URL_SCHEME: string = 'http://';
|
||||
linkUrl: string;
|
||||
linkText: string;
|
||||
|
||||
get linkUrl(): string {
|
||||
let url = HyperlinkWidget.DEFAULT_URL;
|
||||
|
||||
if (this.field && this.field.hyperlinkUrl) {
|
||||
url = this.field.hyperlinkUrl;
|
||||
if (!/^https?:\/\//i.test(url)) {
|
||||
url = HyperlinkWidget.DEFAULT_URL_SCHEME + url;
|
||||
}
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
get linkText(): string {
|
||||
ngOnInit() {
|
||||
if (this.field) {
|
||||
return this.field.displayText || this.field.hyperlinkUrl;
|
||||
this.linkUrl = this.getHyperlinkUrl(this.field);
|
||||
this.linkText = this.getHyperlinkText(this.field);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user