Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to have info buttons #702

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/editors/base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ JSONEditor.defaults.editors.base64 = JSONEditor.AbstractEditor.extend({
build: function() {
var self = this;
this.title = this.header = this.label = this.theme.getFormInputLabel(this.getTitle());
if(this.options.infoText) this.infoButton = this.theme.getInfoButton(this.options.infoText);

// Input that holds the base64 string
this.input = this.theme.getFormInputField('hidden');
Expand Down Expand Up @@ -37,7 +38,7 @@ JSONEditor.defaults.editors.base64 = JSONEditor.AbstractEditor.extend({
this.preview = this.theme.getFormInputDescription(this.schema.description);
this.container.appendChild(this.preview);

this.control = this.theme.getFormControl(this.label, this.uploader||this.input, this.preview);
this.control = this.theme.getFormControl(this.label, this.uploader||this.input, this.preview, this.infoButton);
this.container.appendChild(this.control);
},
refreshPreview: function() {
Expand Down
3 changes: 2 additions & 1 deletion src/editors/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ JSONEditor.defaults.editors.checkbox = JSONEditor.AbstractEditor.extend({
this.label = this.header = this.theme.getCheckboxLabel(this.getTitle());
}
if(this.schema.description) this.description = this.theme.getFormInputDescription(this.schema.description);
if(this.options.infoText) this.infoButton = this.theme.getInfoButton(this.options.infoText);
if(this.options.compact) this.container.className += ' compact';

this.input = this.theme.getCheckbox();
this.control = this.theme.getFormControl(this.label, this.input, this.description);
this.control = this.theme.getFormControl(this.label, this.input, this.description, this.infoButton);

if(this.schema.readOnly || this.schema.readonly) {
this.always_disabled = true;
Expand Down
4 changes: 2 additions & 2 deletions src/editors/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ JSONEditor.defaults.editors.select = JSONEditor.AbstractEditor.extend({
var self = this;
if(!this.options.compact) this.header = this.label = this.theme.getFormInputLabel(this.getTitle());
if(this.schema.description) this.description = this.theme.getFormInputDescription(this.schema.description);

if(this.options.infoText) this.infoButton = this.theme.getInfoButton(this.options.infoText);
if(this.options.compact) this.container.className += ' compact';

this.input = this.theme.getSelectInput(this.enum_options);
Expand All @@ -173,7 +173,7 @@ JSONEditor.defaults.editors.select = JSONEditor.AbstractEditor.extend({
self.onInputChange();
});

this.control = this.theme.getFormControl(this.label, this.input, this.description);
this.control = this.theme.getFormControl(this.label, this.input, this.description, this.infoButton);
this.container.appendChild(this.control);

this.value = this.enum_values[0];
Expand Down
3 changes: 2 additions & 1 deletion src/editors/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ JSONEditor.defaults.editors.selectize = JSONEditor.AbstractEditor.extend({
var self = this;
if(!this.options.compact) this.header = this.label = this.theme.getFormInputLabel(this.getTitle());
if(this.schema.description) this.description = this.theme.getFormInputDescription(this.schema.description);
if(this.options.infoText) this.infoButton = this.theme.getInfoButton(this.options.infoText);

if(this.options.compact) this.container.className += ' compact';

Expand All @@ -163,7 +164,7 @@ JSONEditor.defaults.editors.selectize = JSONEditor.AbstractEditor.extend({
self.onInputChange();
});

this.control = this.theme.getFormControl(this.label, this.input, this.description);
this.control = this.theme.getFormControl(this.label, this.input, this.description, this.infoButton);
this.container.appendChild(this.control);

this.value = this.enum_values[0];
Expand Down
3 changes: 2 additions & 1 deletion src/editors/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({
var self = this, i;
if(!this.options.compact) this.header = this.label = this.theme.getFormInputLabel(this.getTitle());
if(this.schema.description) this.description = this.theme.getFormInputDescription(this.schema.description);
if(this.options.infoText) this.infoButton = this.theme.getInfoButton(this.options.infoText);

this.format = this.schema.format;
if(!this.format && this.schema.media && this.schema.media.type) {
Expand Down Expand Up @@ -252,7 +253,7 @@ JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({

if(this.format) this.input.setAttribute('data-schemaformat',this.format);

this.control = this.theme.getFormControl(this.label, this.input, this.description);
this.control = this.theme.getFormControl(this.label, this.input, this.description, this.infoButton);
this.container.appendChild(this.control);

// Any special formatting that needs to happen after the input is added to the dom
Expand Down
37 changes: 36 additions & 1 deletion src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,39 @@ JSONEditor.AbstractTheme = Class.extend({
enableLabel: function(label) {
label.style.color = '';
},
getInfoButton: function(text) {
var icon = document.createElement('span');
icon.innerText = "ⓘ";
icon.style.fontSize = "16px";
icon.style.fontWeight = "bold";
icon.style.padding = ".25rem";
icon.style.position = "relative";
icon.style.display = "inline-block";

var tooltip = document.createElement('span');
tooltip.style.fontSize = "12px";
icon.style.fontWeight = "normal";
tooltip.style["font-family"] = "sans-serif";
tooltip.style.visibility = "hidden";
tooltip.style["background-color"] = "rgba(50, 50, 50, .75)";
tooltip.style.margin = "0 .25rem";
tooltip.style.color = "#FAFAFA";
tooltip.style.padding = ".5rem 1rem";
tooltip.style["border-radius"] = ".25rem";
tooltip.style.width = "20rem";
tooltip.style.position = "absolute";
tooltip.innerText = text;
icon.onmouseover = function() {
tooltip.style.visibility = "visible";
};
icon.onmouseleave = function() {
tooltip.style.visibility = "hidden";
};

icon.appendChild(tooltip);

return icon;
},
getFormInputLabel: function(text) {
var el = document.createElement('label');
el.appendChild(document.createTextNode(text));
Expand Down Expand Up @@ -166,14 +199,16 @@ JSONEditor.AbstractTheme = Class.extend({
afterInputReady: function(input) {

},
getFormControl: function(label, input, description) {
getFormControl: function(label, input, description, infoText) {
var el = document.createElement('div');
el.className = 'form-control';
if(label) el.appendChild(label);
if(input.type === 'checkbox') {
label.insertBefore(input,label.firstChild);
if(infoText) label.appendChild(infoText);
}
else {
if(infoText) label.appendChild(infoText);
el.appendChild(input);
}

Expand Down
34 changes: 33 additions & 1 deletion src/themes/bootstrap2.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,43 @@ JSONEditor.defaults.themes.bootstrap2 = JSONEditor.AbstractTheme.extend({
el.style.paddingBottom = 0;
return el;
},
getInfoButton: function(text) {
var icon = document.createElement('span');
icon.className = "icon-info-sign pull-right";
icon.style.padding = ".25rem";
icon.style.position = "relative";
icon.style.display = "inline-block";

var tooltip = document.createElement('span');
tooltip.style["font-family"] = "sans-serif";
tooltip.style.visibility = "hidden";
tooltip.style["background-color"] = "rgba(50, 50, 50, .75)";
tooltip.style.margin = "0 .25rem";
tooltip.style.color = "#FAFAFA";
tooltip.style.padding = ".5rem 1rem";
tooltip.style["border-radius"] = ".25rem";
tooltip.style.width = "25rem";
tooltip.style.transform = "translateX(-27rem) translateY(-.5rem)";
tooltip.style.position = "absolute";
tooltip.innerText = text;
icon.onmouseover = function() {
tooltip.style.visibility = "visible";
};
icon.onmouseleave = function() {
tooltip.style.visibility = "hidden";
};

icon.appendChild(tooltip);

return icon;
},
getFormInputDescription: function(text) {
var el = document.createElement('p');
el.className = 'help-inline';
el.textContent = text;
return el;
},
getFormControl: function(label, input, description) {
getFormControl: function(label, input, description, infoText) {
var ret = document.createElement('div');
ret.className = 'control-group';

Expand All @@ -69,13 +99,15 @@ JSONEditor.defaults.themes.bootstrap2 = JSONEditor.AbstractTheme.extend({
label.className += ' checkbox';
label.appendChild(input);
controls.appendChild(label);
if(infoText) controls.appendChild(infoText);
controls.style.height = '30px';
}
else {
if(label) {
label.className += ' control-label';
ret.appendChild(label);
}
if(infoText) controls.appendChild(infoText);
controls.appendChild(input);
ret.appendChild(controls);
}
Expand Down
35 changes: 34 additions & 1 deletion src/themes/bootstrap3.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ JSONEditor.defaults.themes.bootstrap3 = JSONEditor.AbstractTheme.extend({
}
return el;
},
getFormControl: function(label, input, description) {
getFormControl: function(label, input, description, infoText) {
var group = document.createElement('div');

if(label && input.type === 'checkbox') {
group.className += ' checkbox';
label.appendChild(input);
label.style.fontSize = '14px';
group.style.marginTop = '0';
if(infoText) group.appendChild(infoText);
group.appendChild(label);
input.style.position = 'relative';
input.style.cssFloat = 'left';
Expand All @@ -51,6 +52,8 @@ JSONEditor.defaults.themes.bootstrap3 = JSONEditor.AbstractTheme.extend({
label.className += ' control-label';
group.appendChild(label);
}

if(infoText) group.appendChild(infoText);
group.appendChild(input);
}

Expand All @@ -64,6 +67,36 @@ JSONEditor.defaults.themes.bootstrap3 = JSONEditor.AbstractTheme.extend({
el.style.paddingBottom = 0;
return el;
},
getInfoButton: function(text) {
var icon = document.createElement('span');
icon.className = "glyphicon glyphicon-info-sign pull-right";
icon.style.padding = ".25rem";
icon.style.position = "relative";
icon.style.display = "inline-block";

var tooltip = document.createElement('span');
tooltip.style["font-family"] = "sans-serif";
tooltip.style.visibility = "hidden";
tooltip.style["background-color"] = "rgba(50, 50, 50, .75)";
tooltip.style.margin = "0 .25rem";
tooltip.style.color = "#FAFAFA";
tooltip.style.padding = ".5rem 1rem";
tooltip.style["border-radius"] = ".25rem";
tooltip.style.width = "25rem";
tooltip.style.transform = "translateX(-27rem) translateY(-.5rem)";
tooltip.style.position = "absolute";
tooltip.innerText = text;
icon.onmouseover = function() {
tooltip.style.visibility = "visible";
};
icon.onmouseleave = function() {
tooltip.style.visibility = "hidden";
};

icon.appendChild(tooltip);

return icon;
},
getFormInputDescription: function(text) {
var el = document.createElement('p');
el.className = 'help-block';
Expand Down
4 changes: 3 additions & 1 deletion src/themes/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,18 @@ JSONEditor.defaults.themes.foundation6 = JSONEditor.defaults.themes.foundation5.
el.style.display = 'block';
return el;
},
getFormControl: function(label, input, description) {
getFormControl: function(label, input, description, infoText) {
var el = document.createElement('div');
el.className = 'form-control';
if(label) el.appendChild(label);
if(input.type === 'checkbox') {
label.insertBefore(input,label.firstChild);
}
else if (label) {
if(infoText) label.appendChild(infoText);
label.appendChild(input);
} else {
if(infoText) el.appendChild(infoText);
el.appendChild(input);
}

Expand Down
4 changes: 2 additions & 2 deletions src/themes/jqueryui.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ JSONEditor.defaults.themes.jqueryui = JSONEditor.AbstractTheme.extend({
el.style.display = 'inline-block';
return el;
},
getFormControl: function(label, input, description) {
var el = this._super(label,input,description);
getFormControl: function(label, input, description, infoText) {
var el = this._super(label,input,description, infoText);
if(input.type === 'checkbox') {
el.style.lineHeight = '25px';

Expand Down