Skip to content

Commit

Permalink
feat: edit link
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Oct 23, 2017
1 parent cebc696 commit 89389ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/app/ngx-editor/ngx-editor.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
</button>
</div>
<div class="ngx-toolbar-set">
<button class="ngx-editor-button" *ngIf="canEnableToolbarOptions('link')" (click)="createLink()" title="Insert Link">
<button class="ngx-editor-button" *ngIf="canEnableToolbarOptions('link')" (click)="createLink()" title="Insert/Edit Link">
<i class="fa fa-link" aria-hidden="true"></i>
</button>
</div>
Expand Down
16 changes: 11 additions & 5 deletions src/app/ngx-editor/ngx-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,21 @@ export class NgxEditorComponent implements OnInit {
createLink() {
const selection = document.getSelection();

if (selection['type'] === 'None') {
this.createMessage('No selection made');
} else {
const linkURL = prompt('Enter URL', 'http://');
if (selection.anchorNode.parentElement.tagName === 'A') {
const linkURL = prompt('Enter URL', selection.anchorNode.parentElement.getAttribute('href'))
if (linkURL) {
document.execCommand('createLink', false, linkURL);
}
} else {
if (selection['type'] === 'None') {
this.createMessage('No selection made');
} else {
const linkURL = prompt('Enter URL', 'http://');
if (linkURL) {
document.execCommand('createLink', false, linkURL);
}
}
}

}

/*
Expand Down

0 comments on commit 89389ab

Please sign in to comment.