Skip to content

Commit f9aa4b6

Browse files
author
heathdutton
committed
Push slider values back to JSON.
1 parent d693221 commit f9aa4b6

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

Assets/css/contactclient.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,7 @@
265265
border: 0;
266266
}
267267

268+
.slider-horizontal {
269+
max-width: 95%;
270+
margin-top: .5em;
271+
}

Assets/js/02.json_editor.js

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// Extend the bootstrap3 theme with some minor aesthetic customizations.
22
JSONEditor.defaults.themes.custom = JSONEditor.defaults.themes.bootstrap3.extend({
3+
// Support bootstrap-slider.
4+
getRangeInput: function (min, max, step) {
5+
var el = this._super(min, max, step);
6+
el.className = el.className.replace('form-control', '');
7+
return el;
8+
},
39
// Make the buttons smaller and more consistent.
410
getButton: function (text, icon, title) {
511
var el = this._super(text, icon, title);
@@ -173,8 +179,7 @@ JSONEditor.defaults.custom_validators.push(function (schema, value, path) {
173179
// 8 elements. Use "format": "select" to activate.
174180
if (schema.format === 'select') {
175181
// Get the element based on schema path.
176-
var selector = 'select[name=\'' + path.replace('root.', 'root[').split('.').join('][') + ']\']:not(.chosen-checked)';
177-
mQuery(selector).each(function () {
182+
mQuery('select[name=\'' + path.replace('root.', 'root[').split('.').join('][') + ']\']:not(.chosen-checked)').each(function () {
178183
if (mQuery(this).children('option').length > 8) {
179184
var $select = mQuery(this),
180185
changed = false;
@@ -197,13 +202,54 @@ JSONEditor.defaults.custom_validators.push(function (schema, value, path) {
197202
else {
198203
$select[0].fireEvent('onchange');
199204
}
200-
} else {
205+
}
206+
else {
201207
changed = false;
202208
}
203209
});
204210
}
205-
mQuery(this).addClass('chosen-checked');
206-
});
211+
}).addClass('chosen-checked');
207212
}
213+
// Improve the range slider with bootstrap sliders.
214+
if (schema.format === 'range') {
215+
// Get the element based on schema path.
216+
mQuery('input[type=\'range\'][name=\'' + path.replace('root.', 'root[').split('.').join('][') + ']\']:not(.slider-checked)').each(function () {
217+
var $slider = mQuery(this),
218+
min = parseInt(mQuery(this).attr('min')),
219+
max = parseInt(mQuery(this).attr('max')),
220+
step = parseInt(mQuery(this).attr('step')),
221+
value = parseInt(mQuery(this).val()),
222+
options = {
223+
'min': min,
224+
'max': max,
225+
'value': value,
226+
'step': step
227+
},
228+
changed = false;
229+
if (min === 0 && max === 100) {
230+
options.formatter = function (val) {
231+
return val + '%';
232+
};
233+
}
234+
var slider = new Slider(mQuery(this)[0], options);
235+
slider.on('change', function (o) {
236+
if (!changed) {
237+
if ('createEvent' in document) {
238+
// changed = true;
239+
var event = document.createEvent('HTMLEvents');
240+
event.initEvent('change', false, true);
241+
$slider[0].dispatchEvent(event);
242+
}
243+
else {
244+
$slider[0].fireEvent('onchange');
245+
}
246+
}
247+
else {
248+
changed = false;
249+
}
250+
});
251+
}).addClass('slider-checked');
252+
}
253+
208254
return errors;
209255
});

0 commit comments

Comments
 (0)