Skip to content

Commit 731dd3d

Browse files
committed
migrated to ES6 classes
1 parent 0f65539 commit 731dd3d

File tree

2 files changed

+100
-66
lines changed

2 files changed

+100
-66
lines changed

src/assets/editors/ckeditor.js

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
JSONEditor.defaults.editors.ckeditor = JSONEditor.AbstractEditor.extend({
2-
setValue: function(value) {
1+
var StringEditor = JSONEditor.defaults.editors.string;
2+
3+
class CKEditorEditor extends StringEditor {
4+
setValue (value) {
35
if (value === null) {
46
value = '';
57
}
@@ -10,32 +12,37 @@ JSONEditor.defaults.editors.ckeditor = JSONEditor.AbstractEditor.extend({
1012
this.input.value = value;
1113
this.value = value;
1214
this.onChange();
13-
},
14-
register: function() {
15-
this._super();
15+
}
16+
17+
register () {
18+
super.register();
1619
if(!this.input) return;
1720
this.input.setAttribute('name', this.formname);
18-
},
19-
unregister: function() {
20-
this._super();
21+
}
22+
23+
unregister () {
24+
super.unregister();
2125
if(!this.input) return;
2226
this.input.removeAttribute('name');
23-
},
24-
getNumColumns: function() {
27+
}
28+
29+
getNumColumns () {
2530
if(!this.enum_options) return 3;
2631
var longest_text = this.getTitle().length;
2732
for(var i=0; i<this.enum_options.length; i++) {
2833
longest_text = Math.max(longest_text,this.enum_options[i].length+4);
2934
}
3035
return Math.min(12,Math.max(longest_text/7,2));
31-
},
32-
getValue: function() {
36+
}
37+
38+
getValue () {
3339
if (!this.value) {
3440
this.value = '';
3541
}
3642
return this.value;
37-
},
38-
build: function() {
43+
}
44+
45+
build () {
3946
var self = this;
4047

4148
if (!this.options.compact) {
@@ -96,12 +103,14 @@ JSONEditor.defaults.editors.ckeditor = JSONEditor.AbstractEditor.extend({
96103
self.initCKEditor()
97104
}
98105
});
99-
},
100-
postBuild: function() {
101-
this._super();
106+
}
107+
108+
postBuild () {
109+
super.postBuild();
102110
this.theme.afterInputReady(this.input);
103-
},
104-
initCKEditor: function() {
111+
}
112+
113+
initCKEditor () {
105114
var self = this;
106115
if (window.CKCONFIG) {
107116
window.CKCONFIG['extraPlugins'] = 'divarea';
@@ -122,42 +131,50 @@ JSONEditor.defaults.editors.ckeditor = JSONEditor.AbstractEditor.extend({
122131
self.input.value = self.instance.getData();
123132
self.onInputChange();
124133
});
125-
},
126-
onInputChange: function() {
134+
}
135+
136+
onInputChange () {
127137
this.setValue(this.input.value);
128138
this.onChange(true);
129-
},
130-
enable: function() {
139+
}
140+
141+
enable () {
131142
if(!this.always_disabled) {
132143
this.input.disabled = false;
133144
if(this.instance) {
134145
this.instance.setReadOnly(false);
135146
}
136-
this._super();
147+
super.enable();
137148
}
138-
},
139-
disable: function(always_disabled) {
149+
}
150+
151+
disable (always_disabled) {
140152
if(always_disabled) this.always_disabled = true;
141153
this.input.disabled = true;
142154
if(this.instance) {
143155
this.instance.setReadOnly(true);
144156
}
145-
this._super();
146-
},
147-
destroy: function() {
157+
super.disable();
158+
}
159+
160+
destroy () {
148161
this.destroyCKEditor();
149162
if(this.label && this.label.parentNode) this.label.parentNode.removeChild(this.label);
150163
if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description);
151164
if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input);
152-
this._super();
153-
},
154-
destroyCKEditor: function() {
165+
super.disable();
166+
}
167+
168+
destroyCKEditor () {
155169
if(this.instance) {
156170
this.instance.destroy(false);
157171
this.instance = null;
158172
}
159173
}
160-
});
174+
};
175+
176+
JSONEditor.defaults.editors.ckeditor = CKEditorEditor
177+
161178

162179
// Make it compatible with old widgets
163180
JSONEditor.defaults.resolvers.unshift(function(schema) {

src/assets/editors/filefly.js

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
JSONEditor.defaults.editors.filefly = JSONEditor.AbstractEditor.extend({
2-
setValue: function(value) {
1+
var StringEditor = JSONEditor.defaults.editors.string;
2+
3+
4+
class FileflyEditor extends StringEditor {
5+
setValue (value) {
36
if (value === null) {
47
value = '';
58
}
@@ -10,32 +13,37 @@ JSONEditor.defaults.editors.filefly = JSONEditor.AbstractEditor.extend({
1013
this.input.value = value;
1114
this.value = value;
1215
this.onChange();
13-
},
14-
register: function() {
15-
this._super();
16+
}
17+
18+
register () {
19+
super.register();
1620
if(!this.input) return;
1721
this.input.setAttribute('name', this.formname);
18-
},
19-
unregister: function() {
20-
this._super();
22+
}
23+
24+
unregister () {
25+
super.unregister();
2126
if(!this.input) return;
2227
this.input.removeAttribute('name');
23-
},
24-
getNumColumns: function() {
28+
}
29+
30+
getNumColumns () {
2531
if(!this.enum_options) return 3;
2632
var longest_text = this.getTitle().length;
2733
for(var i=0; i<this.enum_options.length; i++) {
2834
longest_text = Math.max(longest_text,this.enum_options[i].length+4);
2935
}
3036
return Math.min(12,Math.max(longest_text/7,2));
31-
},
32-
getValue: function() {
37+
}
38+
39+
getValue () {
3340
if (!this.value) {
3441
this.value = '';
3542
}
3643
return this.value;
37-
},
38-
build: function() {
44+
}
45+
46+
build () {
3947
var self = this;
4048

4149
if (!this.options.compact) {
@@ -89,12 +97,14 @@ JSONEditor.defaults.editors.filefly = JSONEditor.AbstractEditor.extend({
8997
self.initSelectize();
9098
});
9199

92-
},
93-
postBuild: function() {
94-
this._super();
100+
}
101+
102+
postBuild () {
103+
super.postBuild();
95104
this.theme.afterInputReady(this.input);
96-
},
97-
initSelectize: function() {
105+
}
106+
107+
initSelectize () {
98108
var self = this;
99109
this.ajaxPath = '/filefly/api';
100110

@@ -162,42 +172,49 @@ JSONEditor.defaults.editors.filefly = JSONEditor.AbstractEditor.extend({
162172
self.onInputChange();
163173
}
164174
});
165-
},
166-
onInputChange: function() {
175+
}
176+
177+
onInputChange () {
167178
this.value = this.input.value;
168179
this.onChange(true);
169-
},
170-
enable: function() {
180+
}
181+
182+
enable () {
171183
if(!this.always_disabled) {
172184
this.input.disabled = false;
173185
if(this.selectize) {
174186
this.selectize[0].selectize.unlock();
175187
}
176-
this._super();
188+
super.enable();
177189
}
178-
},
179-
disable: function(always_disabled) {
190+
}
191+
192+
disable (always_disabled) {
180193
if(always_disabled) this.always_disabled = true;
181194
this.input.disabled = true;
182195
if(this.selectize) {
183196
this.selectize[0].selectize.lock();
184197
}
185-
this._super();
186-
},
187-
destroy: function() {
198+
super.disable();
199+
}
200+
201+
destroy () {
188202
this.destroySelectize();
189203
if(this.label && this.label.parentNode) this.label.parentNode.removeChild(this.label);
190204
if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description);
191205
if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input);
192-
this._super();
193-
},
194-
destroySelectize: function() {
206+
super.destroy();
207+
}
208+
209+
destroySelectize () {
195210
if(this.selectize) {
196211
this.selectize[0].selectize.destroy();
197212
this.selectize = null;
198213
}
199214
}
200-
});
215+
}
216+
217+
JSONEditor.defaults.editors.filefly = FileflyEditor
201218

202219
// Make it compatible with old widgets
203220
JSONEditor.defaults.resolvers.unshift(function(schema) {

0 commit comments

Comments
 (0)