Skip to content

Commit

Permalink
Merge pull request #9 from germanbisurgi/master
Browse files Browse the repository at this point in the history
updated json editor plugins
  • Loading branch information
handcode authored Mar 4, 2019
2 parents d813f27 + a78496d commit dc1dba0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"require": {
"yiisoft/yii2": "~2.0.0",
"npm-asset/json-editor--json-editor": "~1.2"
"npm-asset/json-editor--json-editor": "^1.3"
},
"autoload": {
"psr-4": {
Expand Down
40 changes: 32 additions & 8 deletions src/assets/editors/ckeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,31 @@ JSONEditor.defaults.editors.ckeditor = JSONEditor.AbstractEditor.extend({
this.control = this.theme.getFormControl(this.label, this.input, this.description, this.infoButton);
this.container.appendChild(this.control);

this.initCKEditor();
self.jsoneditor.on('ready',function() {
self.destroyCKEditor();
if (self.container) {
self.initCKEditor()
}
});

self.jsoneditor.on('addRow',function() {
self.destroyCKEditor();
if (self.container) {
self.initCKEditor()
}
});

self.jsoneditor.on('moveRow',function() {
self.destroyCKEditor();
self.initCKEditor();
});

self.jsoneditor.on('deleteRow',function() {
self.destroyCKEditor();
if (self.container) {
self.initCKEditor()
}
});
},
postBuild: function() {
this._super();
Expand All @@ -80,16 +104,20 @@ JSONEditor.defaults.editors.ckeditor = JSONEditor.AbstractEditor.extend({
initCKEditor: function() {
var self = this;
if (window.CKCONFIG) {
window.CKCONFIG['extraPlugins'] = 'divarea';
self.instance = CKEDITOR.replace(self.input, window.CKCONFIG);
} else {
self.instance = CKEDITOR.replace(self.input);
self.instance = CKEDITOR.replace(self.input, {
extraPlugins: 'divarea'
});
}

CKEDITOR.on('instanceReady', function(evt) {
if (evt.editor === self.instance) {
evt.editor.setData(self.value);
}
});

self.instance.on('change', function () {
self.input.value = self.instance.getData();
self.onInputChange();
Expand All @@ -99,10 +127,6 @@ JSONEditor.defaults.editors.ckeditor = JSONEditor.AbstractEditor.extend({
this.setValue(this.input.value);
this.onChange(true);
},
onMove: function() {
this.destroyCKEditor();
this.initCKEditor();
},
enable: function() {
if(!this.always_disabled) {
this.input.disabled = false;
Expand All @@ -121,15 +145,15 @@ JSONEditor.defaults.editors.ckeditor = JSONEditor.AbstractEditor.extend({
this._super();
},
destroy: function() {
this.destroyCKEditor();
if(this.label && this.label.parentNode) this.label.parentNode.removeChild(this.label);
if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description);
if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input);
this.destroyCKEditor();
this._super();
},
destroyCKEditor: function() {
if(this.instance) {
this.instance.destroy();
this.instance.destroy(false);
this.instance = null;
}
}
Expand Down
35 changes: 24 additions & 11 deletions src/assets/editors/filefly.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,33 @@ JSONEditor.defaults.editors.filefly = JSONEditor.AbstractEditor.extend({
self.initSelectize();
});

self.jsoneditor.on('addRow',function() {
self.initSelectize();
});

self.jsoneditor.on('moveRow',function() {
self.destroySelectize();
self.initSelectize();
});

self.jsoneditor.on('deleteRow',function() {
self.destroySelectize();
self.initSelectize();
});

},
postBuild: function() {
this._super();
this.theme.afterInputReady(this.input);
},
initSelectize: function() {
var self = this;
this.path = this.schema.path || '/filefly/api';
this.ajaxPath = '/filefly/api';

if (this.schema && this.schema.ajaxPath) {
this.ajaxPath = this.schema.ajaxPath;
}

var firstLoad = false;

this.selectize = $(this.input).selectize({
Expand All @@ -99,21 +118,21 @@ JSONEditor.defaults.editors.filefly = JSONEditor.AbstractEditor.extend({
render: {
item: function (item, escape) {
return '<div class="" style="height: 70px">' +
'<img class="pull-left img-responsive" alt="filefly image" style="max-width: 100px; max-height: 70px" src="' + self.path + '?action=stream&path=' + (item.path) + '" />' +
'<img class="pull-left img-responsive" alt="filefly image" style="max-width: 100px; max-height: 70px" src="' + self.ajaxPath + '?action=stream&path=' + (item.path) + '" />' +
'<span class="">' + escape(item.path) + '</span><br/>' +
'</div>';
},
option: function (item, escape) {
return '<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2" style="height: 150px">' +
'<img class="img-responsive" alt="filefly image" style="max-height: 100px" src="' + self.path + '?action=stream&path=' + (item.path) + '" />' +
'<img class="img-responsive" alt="filefly image" style="max-height: 100px" src="' + self.ajaxPath + '?action=stream&path=' + (item.path) + '" />' +
'<span class="">' + escape(item.path) + '</span>' +
'</div>';
}
},
load: function (query, callback) {
var selectize = this;
$.ajax({
url: self.path,
url: self.ajaxPath,
type: 'GET',
dataType: 'json',
data: {
Expand All @@ -125,7 +144,6 @@ JSONEditor.defaults.editors.filefly = JSONEditor.AbstractEditor.extend({
console.log('error', e)
},
success: function (data) {
//selectize.addOption({path: self.input.value, id: self.input.value, mime: ""});
callback(data);
if (!firstLoad) {
selectize.setValue(self.input.value);
Expand All @@ -144,11 +162,6 @@ JSONEditor.defaults.editors.filefly = JSONEditor.AbstractEditor.extend({
onInputChange: function() {
this.value = this.input.value;
this.onChange(true);

},
onMove: function() {
this.destroySelectize();
this.initSelectize();
},
enable: function() {
if(!this.always_disabled) {
Expand All @@ -168,10 +181,10 @@ JSONEditor.defaults.editors.filefly = JSONEditor.AbstractEditor.extend({
this._super();
},
destroy: function() {
this.destroySelectize();
if(this.label && this.label.parentNode) this.label.parentNode.removeChild(this.label);
if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description);
if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input);
this.destroySelectize();
this._super();
},
destroySelectize: function() {
Expand Down

0 comments on commit dc1dba0

Please sign in to comment.