From 63e401bd05caba0938cca028cfbaf9ab4e3303aa Mon Sep 17 00:00:00 2001 From: Sibiraj Date: Wed, 11 Oct 2017 17:13:22 +0530 Subject: [PATCH] feat: insert link --- src/app/ngx-editor/ngx-editor.component.html | 15 ++++++++ src/app/ngx-editor/ngx-editor.component.scss | 21 ++++++++++- src/app/ngx-editor/ngx-editor.component.ts | 39 ++++++++++++++++++-- src/app/ngx-editor/ngx-editor.defaults.ts | 3 +- 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/src/app/ngx-editor/ngx-editor.component.html b/src/app/ngx-editor/ngx-editor.component.html index ad211338..2ea99f04 100644 --- a/src/app/ngx-editor/ngx-editor.component.html +++ b/src/app/ngx-editor/ngx-editor.component.html @@ -1,4 +1,6 @@
+ +
+
+ +
+ +
+ + +
+ {{ngxMessage}} +
+
\ No newline at end of file diff --git a/src/app/ngx-editor/ngx-editor.component.scss b/src/app/ngx-editor/ngx-editor.component.scss index 39028336..17eb97bd 100644 --- a/src/app/ngx-editor/ngx-editor.component.scss +++ b/src/app/ngx-editor/ngx-editor.component.scss @@ -29,8 +29,8 @@ border-right: 1px solid #ddd; &:hover { cursor: pointer; - background-color: #e3e3e3; - transition: 0.5s ease; + background-color: #f1f1f1; + transition: 0.2s ease; } &:focus, &.focus { @@ -39,6 +39,14 @@ &:last-child { border-right: transparent; } + &:first-child { + border-top-left-radius: 5px; + border-bottom-left-radius: 5px; + } + &:last-child { + border-top-right-radius: 5px; + border-bottom-right-radius: 5px; + } } } } @@ -59,4 +67,13 @@ padding-left: 0.5rem; } } + .ngx-editor-message { + font-size: 80%; + background-color: #f1f1f1; + border: 1px solid #ddd; + border-top: transparent; + padding: 0 0.5rem; + padding-bottom: 0.1rem; + transition: 0.5s ease-in; + } } \ No newline at end of file diff --git a/src/app/ngx-editor/ngx-editor.component.ts b/src/app/ngx-editor/ngx-editor.component.ts index 744aa09f..8e6c4cd2 100644 --- a/src/app/ngx-editor/ngx-editor.component.ts +++ b/src/app/ngx-editor/ngx-editor.component.ts @@ -17,6 +17,7 @@ export class NgxEditorComponent implements OnInit { _config: any; _html: any; _resizer: string; + ngxMessage: string; @Input() editable: boolean; @Input() spellcheck: boolean; @@ -85,13 +86,14 @@ export class NgxEditorComponent implements OnInit { constructor() { } + /* + * editor actions + */ executeCommand(commandName) { - const isExecuted = document.execCommand(commandName, false, null); + document.execCommand(commandName, false, null); } - /* - * blockquote - */ + // blockquote blockQuote() { document.execCommand('formatBlock', false, '
'); } @@ -100,6 +102,35 @@ export class NgxEditorComponent implements OnInit { document.execCommand('formatBlock', false, 'div'); } + // insert link + createLink() { + const selection = document.getSelection(); + + if (selection['type'] === 'None') { + this.createMessage('No selection made'); + } else { + const linkURL = prompt('Enter URL', 'http://'); + if (linkURL) { + document.execCommand('createLink', false, linkURL); + } + } + + } + + /* + * message box + */ + createMessage(message) { + this.ngxMessage = message; + setTimeout(() => { + this.clearMessage(); + }, 5000) + } + + clearMessage() { + this.ngxMessage = undefined; + } + /* * enable or diable toolbar based on configuration */ diff --git a/src/app/ngx-editor/ngx-editor.defaults.ts b/src/app/ngx-editor/ngx-editor.defaults.ts index c7e61fda..72c26c5d 100644 --- a/src/app/ngx-editor/ngx-editor.defaults.ts +++ b/src/app/ngx-editor/ngx-editor.defaults.ts @@ -11,6 +11,7 @@ export const ngxEditorConfig = { ['bold', 'italic', 'underline', 'strikeThrough', 'superscript', 'subscript'], ['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'indent', 'outdent'], ['cut', 'copy', 'delete', 'removeFormat', 'undo', 'redo'], - ['paragraph', 'blockquote', 'removeBlockquote', 'horizontalLine', 'orderedList', 'unorderedList'] + ['paragraph', 'blockquote', 'removeBlockquote', 'horizontalLine', 'orderedList', 'unorderedList'], + ['link'] ] };