Skip to content

Commit

Permalink
perf: handle default values properly
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Oct 3, 2017
1 parent e6c8a9f commit 7a40862
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 73 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>NgxEditor</title><base href="ngx-editor"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico"><link href="styles.f6a07fb204943f53af55.bundle.css" rel="stylesheet"/></head><body><app-root></app-root><script async defer="defer" src="https://buttons.github.io/buttons.js"></script><script type="text/javascript" src="inline.b1bf12244992a3cb3ea1.bundle.js"></script><script type="text/javascript" src="polyfills.8eba0ab53b5457105d75.bundle.js"></script><script type="text/javascript" src="vendor.0aaa6fe23ea3764cdb3e.bundle.js"></script><script type="text/javascript" src="main.cf628fad2abd6cb02dba.bundle.js"></script></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>NgxEditor</title><base href="ngx-editor"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico"><link href="styles.f6a07fb204943f53af55.bundle.css" rel="stylesheet"/></head><body><app-root></app-root><script async defer="defer" src="https://buttons.github.io/buttons.js"></script><script type="text/javascript" src="inline.00f247e05e8abd882f87.bundle.js"></script><script type="text/javascript" src="polyfills.8eba0ab53b5457105d75.bundle.js"></script><script type="text/javascript" src="vendor.0aaa6fe23ea3764cdb3e.bundle.js"></script><script type="text/javascript" src="main.f8bd0776cef516050cd2.bundle.js"></script></body></html>
1 change: 1 addition & 0 deletions docs/inline.00f247e05e8abd882f87.bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion docs/inline.b1bf12244992a3cb3ea1.bundle.js

This file was deleted.

1 change: 0 additions & 1 deletion docs/main.cf628fad2abd6cb02dba.bundle.js

This file was deleted.

1 change: 1 addition & 0 deletions docs/main.f8bd0776cef516050cd2.bundle.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export class AppComponent implements OnInit {
editorConfig = {
editable: true,
spellcheck: false,
height: "5rem",
minHeight: "2rem",
placeholder: "Enter text here...",
translate: "no"
height: '5rem',
minHeight: '2rem',
placeholder: 'Enter text here...',
translate: 'no'
};

htmlContent = '<span>WYSIWYG Editor for Angular Applications.</span>';
Expand Down
5 changes: 2 additions & 3 deletions src/app/ngx-editor/ngx-editor.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<button *ngIf="canEnableToolbarOptions('unorderedList')" (click)="executeCommand('insertOrderedList')" title="Ordered List"><i class="fa fa-list-ol" aria-hidden="true"></i></button>
</div>
</div>
<div class="textarea" [attr.contenteditable]="getBooleanProperty('editable')" [attr.placeholder]="placeholder || config['placeholder']"
(input)="html = $event.target.innerHTML; htmlContentChange($event.target.innerHTML)" [attr.translate]="translate || config['translate']"
[attr.spellcheck]="getBooleanProperty('spellcheck')" [style.height]="height || config['height']" [style.minHeight]="minHeight || config['minHeight']"></div>
<div class="textarea" [attr.contenteditable]="config['editable']" [attr.placeholder]="config['placeholder']" (input)="html = $event.target.innerHTML; htmlContentChange($event.target.innerHTML)"
[attr.translate]="config['translate']" [attr.spellcheck]="config['spellcheck']" [style.height]="config['height']" [style.minHeight]="minHeight || config['minHeight']"></div>
</div>
10 changes: 0 additions & 10 deletions src/app/ngx-editor/ngx-editor.component.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
/*
* media screen break points
*/

$break-xtraLarge: "screen and (max-width : 1200px)";
$break-large: "screen and (max-width : 992px)";
$break-medium: "screen and (max-width : 768px)";
$break-small: "screen and (max-width : 480px)";
$break-xtra-small: "screen and (max-width : 320px)";

/*
* editor styles
*/
Expand Down
33 changes: 17 additions & 16 deletions src/app/ngx-editor/ngx-editor.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit, HostListener, Input, Output, ElementRef, EventEmitter } from '@angular/core';
import { ngxEditorConfig } from './ngx-editor.defaults';
import * as Utils from "./ngx-editor.utils";
import * as Utils from './ngx-editor.utils';

@Component({
selector: 'app-ngx-editor',
Expand All @@ -15,6 +15,14 @@ export class NgxEditorComponent implements OnInit {
_config: any;
_html: any;

@Input() editable: boolean;
@Input() spellcheck: boolean;
@Input() placeholder: string;
@Input() translate: string;
@Input() height: string;
@Input() minHeight: string;
@Input() toolbar: any;

/*
* set default values
*/
Expand All @@ -24,8 +32,13 @@ export class NgxEditorComponent implements OnInit {
set config(value: JSON) {

for (const i in ngxEditorConfig) {
if (!value.hasOwnProperty(i)) {
value[i] = ngxEditorConfig[i];
if (i) {
if (this[i]) {
value[i] = this[i];
}
if (!value.hasOwnProperty(i)) {
value[i] = ngxEditorConfig[i];
}
}
}
this._config = value;
Expand All @@ -43,12 +56,7 @@ export class NgxEditorComponent implements OnInit {
return this._html;
}

@Input() editable: boolean;
@Input() spellcheck: boolean;
@Input() placeholder: string;
@Input() translate: string;
@Input() height: string;
@Input() minHeight: string;

/*
* update html on changes in content editable
*/
Expand Down Expand Up @@ -77,13 +85,6 @@ export class NgxEditorComponent implements OnInit {
document.execCommand('formatBlock', false, 'div');
}

/*
* return values for attributes that accepts boolean
*/
getBooleanProperty(value) {
return Utils.getBooleanProperty(value, this.config);
}

/*
* enable or diable toolbar based on configuration
*/
Expand Down
16 changes: 8 additions & 8 deletions src/app/ngx-editor/ngx-editor.defaults.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export const ngxEditorConfig = {
editable: true,
spellcheck: true,
height: "auto",
minHeight: "0rem",
translate: "yes",
placeholder: "Enter text here...",
height: 'auto',
minHeight: '0rem',
translate: 'yes',
placeholder: 'Enter text here...',
toolbar: [
["bold", "italic", "underline", "strikeThrough", "superscript", "subscript"],
["justifyLeft", "justifyCenter", "justifyRight", "justifyFull", "indent", "outdent"],
["cut", "copy", "delete", "removeFormat", "undo", "redo"],
["paragraph", "blockquote", "removeBlockquote", "horizontalLine", "orderedList", "unorderedList"]
['bold', 'italic', 'underline', 'strikeThrough', 'superscript', 'subscript'],
['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'indent', 'outdent'],
['cut', 'copy', 'delete', 'removeFormat', 'undo', 'redo'],
['paragraph', 'blockquote', 'removeBlockquote', 'horizontalLine', 'orderedList', 'unorderedList']
]
};
31 changes: 2 additions & 29 deletions src/app/ngx-editor/ngx-editor.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,10 @@ export function canEnableToolbarOptions(value, toolbar) {
} else {
return toolbar.find(array => {
return array.includes(value);
})
});
}
}
else {
return false;
}
}

export function isToolbarDefault(toolbar) {

if (toolbar) {
return toolbar.find(array => {
return array.includes('default');
})
}
else {
} else {
return false;
}
}

/*
* return values for attributes that accepts boolean
*/
export function getBooleanProperty(value, config) {
if (this[value] === false) {
return false;
}
else if (this[value] === undefined) {
return config[value];
}
else {
return true;
}
}

0 comments on commit 7a40862

Please sign in to comment.