Skip to content

Commit dc1dba0

Browse files
authored
Merge pull request #9 from germanbisurgi/master
updated json editor plugins
2 parents d813f27 + a78496d commit dc1dba0

File tree

3 files changed

+57
-20
lines changed

3 files changed

+57
-20
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
],
1919
"require": {
2020
"yiisoft/yii2": "~2.0.0",
21-
"npm-asset/json-editor--json-editor": "~1.2"
21+
"npm-asset/json-editor--json-editor": "^1.3"
2222
},
2323
"autoload": {
2424
"psr-4": {

src/assets/editors/ckeditor.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,31 @@ JSONEditor.defaults.editors.ckeditor = JSONEditor.AbstractEditor.extend({
7171
this.control = this.theme.getFormControl(this.label, this.input, this.description, this.infoButton);
7272
this.container.appendChild(this.control);
7373

74-
this.initCKEditor();
74+
self.jsoneditor.on('ready',function() {
75+
self.destroyCKEditor();
76+
if (self.container) {
77+
self.initCKEditor()
78+
}
79+
});
80+
81+
self.jsoneditor.on('addRow',function() {
82+
self.destroyCKEditor();
83+
if (self.container) {
84+
self.initCKEditor()
85+
}
86+
});
87+
88+
self.jsoneditor.on('moveRow',function() {
89+
self.destroyCKEditor();
90+
self.initCKEditor();
91+
});
92+
93+
self.jsoneditor.on('deleteRow',function() {
94+
self.destroyCKEditor();
95+
if (self.container) {
96+
self.initCKEditor()
97+
}
98+
});
7599
},
76100
postBuild: function() {
77101
this._super();
@@ -80,16 +104,20 @@ JSONEditor.defaults.editors.ckeditor = JSONEditor.AbstractEditor.extend({
80104
initCKEditor: function() {
81105
var self = this;
82106
if (window.CKCONFIG) {
107+
window.CKCONFIG['extraPlugins'] = 'divarea';
83108
self.instance = CKEDITOR.replace(self.input, window.CKCONFIG);
84109
} else {
85-
self.instance = CKEDITOR.replace(self.input);
110+
self.instance = CKEDITOR.replace(self.input, {
111+
extraPlugins: 'divarea'
112+
});
86113
}
87114

88115
CKEDITOR.on('instanceReady', function(evt) {
89116
if (evt.editor === self.instance) {
90117
evt.editor.setData(self.value);
91118
}
92119
});
120+
93121
self.instance.on('change', function () {
94122
self.input.value = self.instance.getData();
95123
self.onInputChange();
@@ -99,10 +127,6 @@ JSONEditor.defaults.editors.ckeditor = JSONEditor.AbstractEditor.extend({
99127
this.setValue(this.input.value);
100128
this.onChange(true);
101129
},
102-
onMove: function() {
103-
this.destroyCKEditor();
104-
this.initCKEditor();
105-
},
106130
enable: function() {
107131
if(!this.always_disabled) {
108132
this.input.disabled = false;
@@ -121,15 +145,15 @@ JSONEditor.defaults.editors.ckeditor = JSONEditor.AbstractEditor.extend({
121145
this._super();
122146
},
123147
destroy: function() {
148+
this.destroyCKEditor();
124149
if(this.label && this.label.parentNode) this.label.parentNode.removeChild(this.label);
125150
if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description);
126151
if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input);
127-
this.destroyCKEditor();
128152
this._super();
129153
},
130154
destroyCKEditor: function() {
131155
if(this.instance) {
132-
this.instance.destroy();
156+
this.instance.destroy(false);
133157
this.instance = null;
134158
}
135159
}

src/assets/editors/filefly.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,33 @@ JSONEditor.defaults.editors.filefly = JSONEditor.AbstractEditor.extend({
7575
self.initSelectize();
7676
});
7777

78+
self.jsoneditor.on('addRow',function() {
79+
self.initSelectize();
80+
});
81+
82+
self.jsoneditor.on('moveRow',function() {
83+
self.destroySelectize();
84+
self.initSelectize();
85+
});
86+
87+
self.jsoneditor.on('deleteRow',function() {
88+
self.destroySelectize();
89+
self.initSelectize();
90+
});
91+
7892
},
7993
postBuild: function() {
8094
this._super();
8195
this.theme.afterInputReady(this.input);
8296
},
8397
initSelectize: function() {
8498
var self = this;
85-
this.path = this.schema.path || '/filefly/api';
99+
this.ajaxPath = '/filefly/api';
100+
101+
if (this.schema && this.schema.ajaxPath) {
102+
this.ajaxPath = this.schema.ajaxPath;
103+
}
104+
86105
var firstLoad = false;
87106

88107
this.selectize = $(this.input).selectize({
@@ -99,21 +118,21 @@ JSONEditor.defaults.editors.filefly = JSONEditor.AbstractEditor.extend({
99118
render: {
100119
item: function (item, escape) {
101120
return '<div class="" style="height: 70px">' +
102-
'<img class="pull-left img-responsive" alt="filefly image" style="max-width: 100px; max-height: 70px" src="' + self.path + '?action=stream&path=' + (item.path) + '" />' +
121+
'<img class="pull-left img-responsive" alt="filefly image" style="max-width: 100px; max-height: 70px" src="' + self.ajaxPath + '?action=stream&path=' + (item.path) + '" />' +
103122
'<span class="">' + escape(item.path) + '</span><br/>' +
104123
'</div>';
105124
},
106125
option: function (item, escape) {
107126
return '<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2" style="height: 150px">' +
108-
'<img class="img-responsive" alt="filefly image" style="max-height: 100px" src="' + self.path + '?action=stream&path=' + (item.path) + '" />' +
127+
'<img class="img-responsive" alt="filefly image" style="max-height: 100px" src="' + self.ajaxPath + '?action=stream&path=' + (item.path) + '" />' +
109128
'<span class="">' + escape(item.path) + '</span>' +
110129
'</div>';
111130
}
112131
},
113132
load: function (query, callback) {
114133
var selectize = this;
115134
$.ajax({
116-
url: self.path,
135+
url: self.ajaxPath,
117136
type: 'GET',
118137
dataType: 'json',
119138
data: {
@@ -125,7 +144,6 @@ JSONEditor.defaults.editors.filefly = JSONEditor.AbstractEditor.extend({
125144
console.log('error', e)
126145
},
127146
success: function (data) {
128-
//selectize.addOption({path: self.input.value, id: self.input.value, mime: ""});
129147
callback(data);
130148
if (!firstLoad) {
131149
selectize.setValue(self.input.value);
@@ -144,11 +162,6 @@ JSONEditor.defaults.editors.filefly = JSONEditor.AbstractEditor.extend({
144162
onInputChange: function() {
145163
this.value = this.input.value;
146164
this.onChange(true);
147-
148-
},
149-
onMove: function() {
150-
this.destroySelectize();
151-
this.initSelectize();
152165
},
153166
enable: function() {
154167
if(!this.always_disabled) {
@@ -168,10 +181,10 @@ JSONEditor.defaults.editors.filefly = JSONEditor.AbstractEditor.extend({
168181
this._super();
169182
},
170183
destroy: function() {
184+
this.destroySelectize();
171185
if(this.label && this.label.parentNode) this.label.parentNode.removeChild(this.label);
172186
if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description);
173187
if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input);
174-
this.destroySelectize();
175188
this._super();
176189
},
177190
destroySelectize: function() {

0 commit comments

Comments
 (0)