UNPKG

5.29 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3/// <reference path="../summernote.d.ts" />
4var $ = require("jquery");
5require("summernote/dist/summernote");
6var core_1 = require("@angular/core");
7var forms_1 = require("@angular/forms");
8var SUMMERNOTE_VALUE_ACCESSOR = {
9 provide: forms_1.NG_VALUE_ACCESSOR,
10 useExisting: core_1.forwardRef(function () { return SummernoteComponent; }),
11 multi: true
12};
13var SummernoteComponent = (function () {
14 function SummernoteComponent(element) {
15 this.element = element;
16 this.whitespaceEmpty = false;
17 this.emptyChange = new core_1.EventEmitter();
18 this.disableImagePaste = false;
19 this.textChange = new core_1.EventEmitter();
20 this._disabled = false;
21 this.onTouched = function () { };
22 this.onChange = function () { };
23 }
24 Object.defineProperty(SummernoteComponent.prototype, "options", {
25 get: function () {
26 return this._options || {};
27 },
28 set: function (options) {
29 this._options = options;
30 this.addCallbacks();
31 this.refreshOptions();
32 },
33 enumerable: true,
34 configurable: true
35 });
36 Object.defineProperty(SummernoteComponent.prototype, "disabled", {
37 get: function () {
38 return this._disabled;
39 },
40 set: function (disabled) {
41 if (disabled != null) {
42 this._disabled = disabled;
43 $(this.element.nativeElement).find('.summernote').summernote(disabled ? 'disable' : 'enable');
44 this.refreshOptions();
45 }
46 },
47 enumerable: true,
48 configurable: true
49 });
50 Object.defineProperty(SummernoteComponent.prototype, "empty", {
51 get: function () {
52 return this._empty;
53 },
54 set: function (value) {
55 if (this._empty != value) {
56 this._empty = value;
57 this.emptyChange.emit(value);
58 }
59 },
60 enumerable: true,
61 configurable: true
62 });
63 Object.defineProperty(SummernoteComponent.prototype, "value", {
64 get: function () {
65 return this._value;
66 },
67 set: function (value) {
68 this._value = value;
69 },
70 enumerable: true,
71 configurable: true
72 });
73 SummernoteComponent.prototype.refreshOptions = function () {
74 $(this.element.nativeElement).find('.summernote').summernote(this.options);
75 if (this.options.tooltip != undefined && !this.options.tooltip)
76 $(this.element.nativeElement).find('.note-editor button.note-btn').tooltip('destroy');
77 };
78 SummernoteComponent.prototype.addCallbacks = function () {
79 var _this = this;
80 this.options.callbacks = {
81 onChange: function (contents, $editable) {
82 _this.refreshEmpty();
83 _this.onChange(contents);
84 },
85 onBlur: function () {
86 _this.onTouched();
87 }
88 };
89 if (this.disableImagePaste) {
90 this.options.callbacks['onImageUpload'] = function (data) {
91 data.pop();
92 };
93 }
94 };
95 SummernoteComponent.prototype.refreshEmpty = function () {
96 var summernote = $(this.element.nativeElement).find('.summernote');
97 if (summernote == null)
98 return;
99 this.empty = summernote.summernote('isEmpty');
100 if (this.whitespaceEmpty)
101 this.empty = this.empty || summernote.summernote('code').replace(/(<\/?[^>]+>)|(&nbsp;)/g, "").trim() === '';
102 };
103 SummernoteComponent.prototype.ngOnInit = function () {
104 if (this.options == null) {
105 this.options = {};
106 }
107 this.refreshEmpty();
108 };
109 SummernoteComponent.prototype.ngOnDestroy = function () {
110 $(this.element.nativeElement).find('.summernote').summernote('destroy');
111 };
112 SummernoteComponent.prototype.writeValue = function (code) {
113 this.value = code;
114 $(this.element.nativeElement).find('.summernote').summernote('code', code);
115 this.refreshEmpty();
116 };
117 SummernoteComponent.prototype.registerOnChange = function (fn) {
118 this.onChange = fn;
119 };
120 SummernoteComponent.prototype.registerOnTouched = function (fn) {
121 this.onTouched = fn;
122 };
123 SummernoteComponent.decorators = [
124 { type: core_1.Component, args: [{
125 selector: 'summernote',
126 template: '<div class="summernote"></div>',
127 providers: [SUMMERNOTE_VALUE_ACCESSOR]
128 },] },
129 ];
130 /** @nocollapse */
131 SummernoteComponent.ctorParameters = function () { return [
132 { type: core_1.ElementRef, },
133 ]; };
134 SummernoteComponent.propDecorators = {
135 'options': [{ type: core_1.Input },],
136 'disabled': [{ type: core_1.Input },],
137 'whitespaceEmpty': [{ type: core_1.Input },],
138 'emptyChange': [{ type: core_1.Output },],
139 'disableImagePaste': [{ type: core_1.Input },],
140 'textChange': [{ type: core_1.Output },],
141 };
142 return SummernoteComponent;
143}());
144exports.SummernoteComponent = SummernoteComponent;
145//# sourceMappingURL=summernote.component.js.map
\No newline at end of file