build dist
This commit is contained in:
parent
2df93f856d
commit
f32802f48a
dist
3
dist/CHANGELOG.txt
vendored
3
dist/CHANGELOG.txt
vendored
@ -2,8 +2,9 @@ X-editable changelog
|
||||
=============================
|
||||
|
||||
|
||||
Version 1.5.1 wip
|
||||
Version 1.5.1 Nov 4, 2013
|
||||
----------------------------
|
||||
[enh #371] submit single field (vitalets)
|
||||
[bug] select2: placeholder not shown if value initially empty (vitalets)
|
||||
[enh #400] allow `validate` to change submitted value, also fix #354 (vitalets)
|
||||
[enh #396] bs3 popover: placement `auto` (vitalets)
|
||||
|
304
dist/bootstrap-editable/js/bootstrap-editable.js
vendored
304
dist/bootstrap-editable/js/bootstrap-editable.js
vendored
@ -2027,7 +2027,9 @@ Makes editable any HTML element on the page. Applied as jQuery method.
|
||||
/**
|
||||
This method collects values from several editable elements and submit them all to server.
|
||||
Internally it runs client-side validation for all fields and submits only in case of success.
|
||||
See <a href="#newrecord">creating new records</a> for details.
|
||||
See <a href="#newrecord">creating new records</a> for details.
|
||||
Since 1.5.1 `submit` can be applied to single element to send data programmatically. In that case
|
||||
`url`, `success` and `error` is taken from initial options and you can just call `$('#username').editable('submit')`.
|
||||
|
||||
@method submit(options)
|
||||
@param {object} options
|
||||
@ -2041,31 +2043,76 @@ Makes editable any HTML element on the page. Applied as jQuery method.
|
||||
case 'submit': //collects value, validate and submit to server for creating new record
|
||||
var config = arguments[1] || {},
|
||||
$elems = this,
|
||||
errors = this.editable('validate'),
|
||||
values;
|
||||
errors = this.editable('validate');
|
||||
|
||||
// validation ok
|
||||
if($.isEmptyObject(errors)) {
|
||||
values = this.editable('getValue');
|
||||
if(config.data) {
|
||||
$.extend(values, config.data);
|
||||
}
|
||||
|
||||
$.ajax($.extend({
|
||||
url: config.url,
|
||||
data: values,
|
||||
type: 'POST'
|
||||
}, config.ajaxOptions))
|
||||
.success(function(response) {
|
||||
//successful response 200 OK
|
||||
if(typeof config.success === 'function') {
|
||||
config.success.call($elems, response, config);
|
||||
}
|
||||
})
|
||||
.error(function(){ //ajax error
|
||||
if(typeof config.error === 'function') {
|
||||
config.error.apply($elems, arguments);
|
||||
var ajaxOptions = {};
|
||||
|
||||
// for single element use url, success etc from options
|
||||
if($elems.length === 1) {
|
||||
var editable = $elems.data('editable');
|
||||
//standard params
|
||||
var params = {
|
||||
name: editable.options.name || '',
|
||||
value: editable.input.value2submit(editable.value),
|
||||
pk: (typeof editable.options.pk === 'function') ?
|
||||
editable.options.pk.call(editable.options.scope) :
|
||||
editable.options.pk
|
||||
};
|
||||
|
||||
//additional params
|
||||
if(typeof editable.options.params === 'function') {
|
||||
params = editable.options.params.call(editable.options.scope, params);
|
||||
} else {
|
||||
//try parse json in single quotes (from data-params attribute)
|
||||
editable.options.params = $.fn.editableutils.tryParseJson(editable.options.params, true);
|
||||
$.extend(params, editable.options.params);
|
||||
}
|
||||
});
|
||||
|
||||
ajaxOptions = {
|
||||
url: editable.options.url,
|
||||
data: params,
|
||||
type: 'POST'
|
||||
};
|
||||
|
||||
// use success / error from options
|
||||
config.success = config.success || editable.options.success;
|
||||
config.error = config.error || editable.options.error;
|
||||
|
||||
// multiple elements
|
||||
} else {
|
||||
var values = this.editable('getValue');
|
||||
|
||||
ajaxOptions = {
|
||||
url: config.url,
|
||||
data: values,
|
||||
type: 'POST'
|
||||
};
|
||||
}
|
||||
|
||||
// ajax success callabck (response 200 OK)
|
||||
ajaxOptions.success = typeof config.success === 'function' ? function(response) {
|
||||
config.success.call($elems, response, config);
|
||||
} : $.noop;
|
||||
|
||||
// ajax error callabck
|
||||
ajaxOptions.error = typeof config.error === 'function' ? function() {
|
||||
config.error.apply($elems, arguments);
|
||||
} : $.noop;
|
||||
|
||||
// extend ajaxOptions
|
||||
if(config.ajaxOptions) {
|
||||
$.extend(ajaxOptions, config.ajaxOptions);
|
||||
}
|
||||
|
||||
// extra data
|
||||
if(config.data) {
|
||||
$.extend(ajaxOptions.data, config.data);
|
||||
}
|
||||
|
||||
// perform ajax request
|
||||
$.ajax(ajaxOptions);
|
||||
} else { //client-side validation error
|
||||
if(typeof config.error === 'function') {
|
||||
config.error.call($elems, errors);
|
||||
@ -3897,11 +3944,11 @@ $(function(){
|
||||
}(window.jQuery));
|
||||
|
||||
/**
|
||||
* Combodate - 1.0.4
|
||||
* Combodate - 1.0.5
|
||||
* Dropdown date and time picker.
|
||||
* Converts text input into dropdowns to pick day, month, year, hour, minute and second.
|
||||
* Uses momentjs as datetime library http://momentjs.com.
|
||||
* For internalization include corresponding file from https://github.com/timrwood/moment/tree/master/lang
|
||||
* For i18n include corresponding file from https://github.com/timrwood/moment/tree/master/lang
|
||||
*
|
||||
* Confusion at noon and midnight - see http://en.wikipedia.org/wiki/12-hour_clock#Confusion_at_noon_and_midnight
|
||||
* In combodate:
|
||||
@ -3948,16 +3995,22 @@ $(function(){
|
||||
this.initCombos();
|
||||
|
||||
//update original input on change
|
||||
this.$widget.on('change', 'select', $.proxy(function(){
|
||||
this.$element.val(this.getValue());
|
||||
this.$widget.on('change', 'select', $.proxy(function(e) {
|
||||
this.$element.val(this.getValue()).change();
|
||||
// update days count if month or year changes
|
||||
if (this.options.smartDays) {
|
||||
if ($(e.target).is('.month') || $(e.target).is('.year')) {
|
||||
this.fillCombo('day');
|
||||
}
|
||||
}
|
||||
}, this));
|
||||
|
||||
this.$widget.find('select').css('width', 'auto');
|
||||
|
||||
//hide original input and insert widget
|
||||
// hide original input and insert widget
|
||||
this.$element.hide().after(this.$widget);
|
||||
|
||||
//set initial value
|
||||
// set initial value
|
||||
this.setValue(this.$element.val() || this.options.value);
|
||||
},
|
||||
|
||||
@ -3994,22 +4047,41 @@ $(function(){
|
||||
Initialize combos that presents in template
|
||||
*/
|
||||
initCombos: function() {
|
||||
var that = this;
|
||||
$.each(this.map, function(k, v) {
|
||||
var $c = that.$widget.find('.'+k), f, items;
|
||||
if($c.length) {
|
||||
that['$'+k] = $c; //set properties like this.$day, this.$month etc.
|
||||
f = 'fill' + k.charAt(0).toUpperCase() + k.slice(1); //define method name to fill items, e.g `fillDays`
|
||||
items = that[f]();
|
||||
that['$'+k].html(that.renderItems(items));
|
||||
}
|
||||
});
|
||||
for (var k in this.map) {
|
||||
var $c = this.$widget.find('.'+k);
|
||||
// set properties like this.$day, this.$month etc.
|
||||
this['$'+k] = $c.length ? $c : null;
|
||||
// fill with items
|
||||
this.fillCombo(k);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
Fill combo with items
|
||||
*/
|
||||
fillCombo: function(k) {
|
||||
var $combo = this['$'+k];
|
||||
if (!$combo) {
|
||||
return;
|
||||
}
|
||||
|
||||
// define method name to fill items, e.g `fillDays`
|
||||
var f = 'fill' + k.charAt(0).toUpperCase() + k.slice(1);
|
||||
var items = this[f]();
|
||||
var value = $combo.val();
|
||||
|
||||
$combo.empty();
|
||||
for(var i=0; i<items.length; i++) {
|
||||
$combo.append('<option value="'+items[i][0]+'">'+items[i][1]+'</option>');
|
||||
}
|
||||
|
||||
$combo.val(value);
|
||||
},
|
||||
|
||||
/*
|
||||
Initialize items of combos. Handles `firstItem` option
|
||||
*/
|
||||
initItems: function(key) {
|
||||
fillCommon: function(key) {
|
||||
var values = [],
|
||||
relTime;
|
||||
|
||||
@ -4024,27 +4096,29 @@ $(function(){
|
||||
values.push(['', '']);
|
||||
}
|
||||
return values;
|
||||
},
|
||||
|
||||
/*
|
||||
render items to string of <option> tags
|
||||
*/
|
||||
renderItems: function(items) {
|
||||
var str = [];
|
||||
for(var i=0; i<items.length; i++) {
|
||||
str.push('<option value="'+items[i][0]+'">'+items[i][1]+'</option>');
|
||||
}
|
||||
return str.join("\n");
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
fill day
|
||||
*/
|
||||
fillDay: function() {
|
||||
var items = this.initItems('d'), name, i,
|
||||
twoDigit = this.options.template.indexOf('DD') !== -1;
|
||||
|
||||
for(i=1; i<=31; i++) {
|
||||
var items = this.fillCommon('d'), name, i,
|
||||
twoDigit = this.options.template.indexOf('DD') !== -1,
|
||||
daysCount = 31;
|
||||
|
||||
// detect days count (depends on month and year)
|
||||
// originally https://github.com/vitalets/combodate/pull/7
|
||||
if (this.options.smartDays && this.$month && this.$year) {
|
||||
var month = parseInt(this.$month.val(), 10);
|
||||
var year = parseInt(this.$year.val(), 10);
|
||||
|
||||
if (!isNaN(month) && !isNaN(year)) {
|
||||
daysCount = moment([year, month]).daysInMonth();
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 1; i <= daysCount; i++) {
|
||||
name = twoDigit ? this.leadZero(i) : i;
|
||||
items.push([i, name]);
|
||||
}
|
||||
@ -4055,7 +4129,7 @@ $(function(){
|
||||
fill month
|
||||
*/
|
||||
fillMonth: function() {
|
||||
var items = this.initItems('M'), name, i,
|
||||
var items = this.fillCommon('M'), name, i,
|
||||
longNames = this.options.template.indexOf('MMMM') !== -1,
|
||||
shortNames = this.options.template.indexOf('MMM') !== -1,
|
||||
twoDigit = this.options.template.indexOf('MM') !== -1;
|
||||
@ -4088,7 +4162,7 @@ $(function(){
|
||||
items[this.options.yearDescending ? 'push' : 'unshift']([i, name]);
|
||||
}
|
||||
|
||||
items = this.initItems('y').concat(items);
|
||||
items = this.fillCommon('y').concat(items);
|
||||
|
||||
return items;
|
||||
},
|
||||
@ -4097,7 +4171,7 @@ $(function(){
|
||||
fill hour
|
||||
*/
|
||||
fillHour: function() {
|
||||
var items = this.initItems('h'), name, i,
|
||||
var items = this.fillCommon('h'), name, i,
|
||||
h12 = this.options.template.indexOf('h') !== -1,
|
||||
h24 = this.options.template.indexOf('H') !== -1,
|
||||
twoDigit = this.options.template.toLowerCase().indexOf('hh') !== -1,
|
||||
@ -4115,7 +4189,7 @@ $(function(){
|
||||
fill minute
|
||||
*/
|
||||
fillMinute: function() {
|
||||
var items = this.initItems('m'), name, i,
|
||||
var items = this.fillCommon('m'), name, i,
|
||||
twoDigit = this.options.template.indexOf('mm') !== -1;
|
||||
|
||||
for(i=0; i<=59; i+= this.options.minuteStep) {
|
||||
@ -4129,7 +4203,7 @@ $(function(){
|
||||
fill second
|
||||
*/
|
||||
fillSecond: function() {
|
||||
var items = this.initItems('s'), name, i,
|
||||
var items = this.fillCommon('s'), name, i,
|
||||
twoDigit = this.options.template.indexOf('ss') !== -1;
|
||||
|
||||
for(i=0; i<=59; i+= this.options.secondStep) {
|
||||
@ -4151,7 +4225,7 @@ $(function(){
|
||||
];
|
||||
return items;
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
Returns current date value from combos.
|
||||
If format not specified - `options.format` used.
|
||||
@ -4214,63 +4288,68 @@ $(function(){
|
||||
that = this,
|
||||
values = {};
|
||||
|
||||
//function to find nearest value in select options
|
||||
function getNearest($select, value) {
|
||||
var delta = {};
|
||||
$select.children('option').each(function(i, opt){
|
||||
var optValue = $(opt).attr('value'),
|
||||
distance;
|
||||
//function to find nearest value in select options
|
||||
function getNearest($select, value) {
|
||||
var delta = {};
|
||||
$select.children('option').each(function(i, opt){
|
||||
var optValue = $(opt).attr('value'),
|
||||
distance;
|
||||
|
||||
if(optValue === '') return;
|
||||
distance = Math.abs(optValue - value);
|
||||
if(typeof delta.distance === 'undefined' || distance < delta.distance) {
|
||||
delta = {value: optValue, distance: distance};
|
||||
}
|
||||
});
|
||||
return delta.value;
|
||||
}
|
||||
if(optValue === '') return;
|
||||
distance = Math.abs(optValue - value);
|
||||
if(typeof delta.distance === 'undefined' || distance < delta.distance) {
|
||||
delta = {value: optValue, distance: distance};
|
||||
}
|
||||
});
|
||||
return delta.value;
|
||||
}
|
||||
|
||||
if(dt.isValid()) {
|
||||
//read values from date object
|
||||
$.each(this.map, function(k, v) {
|
||||
if(k === 'ampm') {
|
||||
return;
|
||||
}
|
||||
values[k] = dt[v[1]]();
|
||||
});
|
||||
//read values from date object
|
||||
$.each(this.map, function(k, v) {
|
||||
if(k === 'ampm') {
|
||||
return;
|
||||
}
|
||||
values[k] = dt[v[1]]();
|
||||
});
|
||||
|
||||
if(this.$ampm) {
|
||||
//12:00 pm --> 12:00 (24-h format, midday), 12:00 am --> 00:00 (24-h format, midnight, start of day)
|
||||
if(values.hour >= 12) {
|
||||
values.ampm = 'pm';
|
||||
if(values.hour > 12) {
|
||||
values.hour -= 12;
|
||||
}
|
||||
} else {
|
||||
values.ampm = 'am';
|
||||
if(values.hour === 0) {
|
||||
values.hour = 12;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this.$ampm) {
|
||||
//12:00 pm --> 12:00 (24-h format, midday), 12:00 am --> 00:00 (24-h format, midnight, start of day)
|
||||
if(values.hour >= 12) {
|
||||
values.ampm = 'pm';
|
||||
if(values.hour > 12) {
|
||||
values.hour -= 12;
|
||||
}
|
||||
} else {
|
||||
values.ampm = 'am';
|
||||
if(values.hour === 0) {
|
||||
values.hour = 12;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$.each(values, function(k, v) {
|
||||
//call val() for each existing combo, e.g. this.$hour.val()
|
||||
if(that['$'+k]) {
|
||||
$.each(values, function(k, v) {
|
||||
//call val() for each existing combo, e.g. this.$hour.val()
|
||||
if(that['$'+k]) {
|
||||
|
||||
if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
|
||||
if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
|
||||
that['$'+k].val(v);
|
||||
}
|
||||
});
|
||||
that['$'+k].val(v);
|
||||
}
|
||||
});
|
||||
|
||||
// update days count
|
||||
if (this.options.smartDays) {
|
||||
this.fillCombo('day');
|
||||
}
|
||||
|
||||
this.$element.val(dt.format(this.options.format));
|
||||
this.$element.val(dt.format(this.options.format)).change();
|
||||
}
|
||||
},
|
||||
|
||||
@ -4345,7 +4424,8 @@ $(function(){
|
||||
secondStep: 1,
|
||||
firstItem: 'empty', //'name', 'empty', 'none'
|
||||
errorClass: null,
|
||||
roundTime: true //whether to round minutes and seconds if step > 1
|
||||
roundTime: true, // whether to round minutes and seconds if step > 1
|
||||
smartDays: false // whether days in combo depend on selected month: 31, 30, 28
|
||||
};
|
||||
|
||||
}(window.jQuery));
|
||||
|
File diff suppressed because one or more lines are too long
304
dist/bootstrap3-editable/js/bootstrap-editable.js
vendored
304
dist/bootstrap3-editable/js/bootstrap-editable.js
vendored
@ -2027,7 +2027,9 @@ Makes editable any HTML element on the page. Applied as jQuery method.
|
||||
/**
|
||||
This method collects values from several editable elements and submit them all to server.
|
||||
Internally it runs client-side validation for all fields and submits only in case of success.
|
||||
See <a href="#newrecord">creating new records</a> for details.
|
||||
See <a href="#newrecord">creating new records</a> for details.
|
||||
Since 1.5.1 `submit` can be applied to single element to send data programmatically. In that case
|
||||
`url`, `success` and `error` is taken from initial options and you can just call `$('#username').editable('submit')`.
|
||||
|
||||
@method submit(options)
|
||||
@param {object} options
|
||||
@ -2041,31 +2043,76 @@ Makes editable any HTML element on the page. Applied as jQuery method.
|
||||
case 'submit': //collects value, validate and submit to server for creating new record
|
||||
var config = arguments[1] || {},
|
||||
$elems = this,
|
||||
errors = this.editable('validate'),
|
||||
values;
|
||||
errors = this.editable('validate');
|
||||
|
||||
// validation ok
|
||||
if($.isEmptyObject(errors)) {
|
||||
values = this.editable('getValue');
|
||||
if(config.data) {
|
||||
$.extend(values, config.data);
|
||||
}
|
||||
|
||||
$.ajax($.extend({
|
||||
url: config.url,
|
||||
data: values,
|
||||
type: 'POST'
|
||||
}, config.ajaxOptions))
|
||||
.success(function(response) {
|
||||
//successful response 200 OK
|
||||
if(typeof config.success === 'function') {
|
||||
config.success.call($elems, response, config);
|
||||
}
|
||||
})
|
||||
.error(function(){ //ajax error
|
||||
if(typeof config.error === 'function') {
|
||||
config.error.apply($elems, arguments);
|
||||
var ajaxOptions = {};
|
||||
|
||||
// for single element use url, success etc from options
|
||||
if($elems.length === 1) {
|
||||
var editable = $elems.data('editable');
|
||||
//standard params
|
||||
var params = {
|
||||
name: editable.options.name || '',
|
||||
value: editable.input.value2submit(editable.value),
|
||||
pk: (typeof editable.options.pk === 'function') ?
|
||||
editable.options.pk.call(editable.options.scope) :
|
||||
editable.options.pk
|
||||
};
|
||||
|
||||
//additional params
|
||||
if(typeof editable.options.params === 'function') {
|
||||
params = editable.options.params.call(editable.options.scope, params);
|
||||
} else {
|
||||
//try parse json in single quotes (from data-params attribute)
|
||||
editable.options.params = $.fn.editableutils.tryParseJson(editable.options.params, true);
|
||||
$.extend(params, editable.options.params);
|
||||
}
|
||||
});
|
||||
|
||||
ajaxOptions = {
|
||||
url: editable.options.url,
|
||||
data: params,
|
||||
type: 'POST'
|
||||
};
|
||||
|
||||
// use success / error from options
|
||||
config.success = config.success || editable.options.success;
|
||||
config.error = config.error || editable.options.error;
|
||||
|
||||
// multiple elements
|
||||
} else {
|
||||
var values = this.editable('getValue');
|
||||
|
||||
ajaxOptions = {
|
||||
url: config.url,
|
||||
data: values,
|
||||
type: 'POST'
|
||||
};
|
||||
}
|
||||
|
||||
// ajax success callabck (response 200 OK)
|
||||
ajaxOptions.success = typeof config.success === 'function' ? function(response) {
|
||||
config.success.call($elems, response, config);
|
||||
} : $.noop;
|
||||
|
||||
// ajax error callabck
|
||||
ajaxOptions.error = typeof config.error === 'function' ? function() {
|
||||
config.error.apply($elems, arguments);
|
||||
} : $.noop;
|
||||
|
||||
// extend ajaxOptions
|
||||
if(config.ajaxOptions) {
|
||||
$.extend(ajaxOptions, config.ajaxOptions);
|
||||
}
|
||||
|
||||
// extra data
|
||||
if(config.data) {
|
||||
$.extend(ajaxOptions.data, config.data);
|
||||
}
|
||||
|
||||
// perform ajax request
|
||||
$.ajax(ajaxOptions);
|
||||
} else { //client-side validation error
|
||||
if(typeof config.error === 'function') {
|
||||
config.error.call($elems, errors);
|
||||
@ -3897,11 +3944,11 @@ $(function(){
|
||||
}(window.jQuery));
|
||||
|
||||
/**
|
||||
* Combodate - 1.0.4
|
||||
* Combodate - 1.0.5
|
||||
* Dropdown date and time picker.
|
||||
* Converts text input into dropdowns to pick day, month, year, hour, minute and second.
|
||||
* Uses momentjs as datetime library http://momentjs.com.
|
||||
* For internalization include corresponding file from https://github.com/timrwood/moment/tree/master/lang
|
||||
* For i18n include corresponding file from https://github.com/timrwood/moment/tree/master/lang
|
||||
*
|
||||
* Confusion at noon and midnight - see http://en.wikipedia.org/wiki/12-hour_clock#Confusion_at_noon_and_midnight
|
||||
* In combodate:
|
||||
@ -3948,16 +3995,22 @@ $(function(){
|
||||
this.initCombos();
|
||||
|
||||
//update original input on change
|
||||
this.$widget.on('change', 'select', $.proxy(function(){
|
||||
this.$element.val(this.getValue());
|
||||
this.$widget.on('change', 'select', $.proxy(function(e) {
|
||||
this.$element.val(this.getValue()).change();
|
||||
// update days count if month or year changes
|
||||
if (this.options.smartDays) {
|
||||
if ($(e.target).is('.month') || $(e.target).is('.year')) {
|
||||
this.fillCombo('day');
|
||||
}
|
||||
}
|
||||
}, this));
|
||||
|
||||
this.$widget.find('select').css('width', 'auto');
|
||||
|
||||
//hide original input and insert widget
|
||||
// hide original input and insert widget
|
||||
this.$element.hide().after(this.$widget);
|
||||
|
||||
//set initial value
|
||||
// set initial value
|
||||
this.setValue(this.$element.val() || this.options.value);
|
||||
},
|
||||
|
||||
@ -3994,22 +4047,41 @@ $(function(){
|
||||
Initialize combos that presents in template
|
||||
*/
|
||||
initCombos: function() {
|
||||
var that = this;
|
||||
$.each(this.map, function(k, v) {
|
||||
var $c = that.$widget.find('.'+k), f, items;
|
||||
if($c.length) {
|
||||
that['$'+k] = $c; //set properties like this.$day, this.$month etc.
|
||||
f = 'fill' + k.charAt(0).toUpperCase() + k.slice(1); //define method name to fill items, e.g `fillDays`
|
||||
items = that[f]();
|
||||
that['$'+k].html(that.renderItems(items));
|
||||
}
|
||||
});
|
||||
for (var k in this.map) {
|
||||
var $c = this.$widget.find('.'+k);
|
||||
// set properties like this.$day, this.$month etc.
|
||||
this['$'+k] = $c.length ? $c : null;
|
||||
// fill with items
|
||||
this.fillCombo(k);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
Fill combo with items
|
||||
*/
|
||||
fillCombo: function(k) {
|
||||
var $combo = this['$'+k];
|
||||
if (!$combo) {
|
||||
return;
|
||||
}
|
||||
|
||||
// define method name to fill items, e.g `fillDays`
|
||||
var f = 'fill' + k.charAt(0).toUpperCase() + k.slice(1);
|
||||
var items = this[f]();
|
||||
var value = $combo.val();
|
||||
|
||||
$combo.empty();
|
||||
for(var i=0; i<items.length; i++) {
|
||||
$combo.append('<option value="'+items[i][0]+'">'+items[i][1]+'</option>');
|
||||
}
|
||||
|
||||
$combo.val(value);
|
||||
},
|
||||
|
||||
/*
|
||||
Initialize items of combos. Handles `firstItem` option
|
||||
*/
|
||||
initItems: function(key) {
|
||||
fillCommon: function(key) {
|
||||
var values = [],
|
||||
relTime;
|
||||
|
||||
@ -4024,27 +4096,29 @@ $(function(){
|
||||
values.push(['', '']);
|
||||
}
|
||||
return values;
|
||||
},
|
||||
|
||||
/*
|
||||
render items to string of <option> tags
|
||||
*/
|
||||
renderItems: function(items) {
|
||||
var str = [];
|
||||
for(var i=0; i<items.length; i++) {
|
||||
str.push('<option value="'+items[i][0]+'">'+items[i][1]+'</option>');
|
||||
}
|
||||
return str.join("\n");
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
fill day
|
||||
*/
|
||||
fillDay: function() {
|
||||
var items = this.initItems('d'), name, i,
|
||||
twoDigit = this.options.template.indexOf('DD') !== -1;
|
||||
|
||||
for(i=1; i<=31; i++) {
|
||||
var items = this.fillCommon('d'), name, i,
|
||||
twoDigit = this.options.template.indexOf('DD') !== -1,
|
||||
daysCount = 31;
|
||||
|
||||
// detect days count (depends on month and year)
|
||||
// originally https://github.com/vitalets/combodate/pull/7
|
||||
if (this.options.smartDays && this.$month && this.$year) {
|
||||
var month = parseInt(this.$month.val(), 10);
|
||||
var year = parseInt(this.$year.val(), 10);
|
||||
|
||||
if (!isNaN(month) && !isNaN(year)) {
|
||||
daysCount = moment([year, month]).daysInMonth();
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 1; i <= daysCount; i++) {
|
||||
name = twoDigit ? this.leadZero(i) : i;
|
||||
items.push([i, name]);
|
||||
}
|
||||
@ -4055,7 +4129,7 @@ $(function(){
|
||||
fill month
|
||||
*/
|
||||
fillMonth: function() {
|
||||
var items = this.initItems('M'), name, i,
|
||||
var items = this.fillCommon('M'), name, i,
|
||||
longNames = this.options.template.indexOf('MMMM') !== -1,
|
||||
shortNames = this.options.template.indexOf('MMM') !== -1,
|
||||
twoDigit = this.options.template.indexOf('MM') !== -1;
|
||||
@ -4088,7 +4162,7 @@ $(function(){
|
||||
items[this.options.yearDescending ? 'push' : 'unshift']([i, name]);
|
||||
}
|
||||
|
||||
items = this.initItems('y').concat(items);
|
||||
items = this.fillCommon('y').concat(items);
|
||||
|
||||
return items;
|
||||
},
|
||||
@ -4097,7 +4171,7 @@ $(function(){
|
||||
fill hour
|
||||
*/
|
||||
fillHour: function() {
|
||||
var items = this.initItems('h'), name, i,
|
||||
var items = this.fillCommon('h'), name, i,
|
||||
h12 = this.options.template.indexOf('h') !== -1,
|
||||
h24 = this.options.template.indexOf('H') !== -1,
|
||||
twoDigit = this.options.template.toLowerCase().indexOf('hh') !== -1,
|
||||
@ -4115,7 +4189,7 @@ $(function(){
|
||||
fill minute
|
||||
*/
|
||||
fillMinute: function() {
|
||||
var items = this.initItems('m'), name, i,
|
||||
var items = this.fillCommon('m'), name, i,
|
||||
twoDigit = this.options.template.indexOf('mm') !== -1;
|
||||
|
||||
for(i=0; i<=59; i+= this.options.minuteStep) {
|
||||
@ -4129,7 +4203,7 @@ $(function(){
|
||||
fill second
|
||||
*/
|
||||
fillSecond: function() {
|
||||
var items = this.initItems('s'), name, i,
|
||||
var items = this.fillCommon('s'), name, i,
|
||||
twoDigit = this.options.template.indexOf('ss') !== -1;
|
||||
|
||||
for(i=0; i<=59; i+= this.options.secondStep) {
|
||||
@ -4151,7 +4225,7 @@ $(function(){
|
||||
];
|
||||
return items;
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
Returns current date value from combos.
|
||||
If format not specified - `options.format` used.
|
||||
@ -4214,63 +4288,68 @@ $(function(){
|
||||
that = this,
|
||||
values = {};
|
||||
|
||||
//function to find nearest value in select options
|
||||
function getNearest($select, value) {
|
||||
var delta = {};
|
||||
$select.children('option').each(function(i, opt){
|
||||
var optValue = $(opt).attr('value'),
|
||||
distance;
|
||||
//function to find nearest value in select options
|
||||
function getNearest($select, value) {
|
||||
var delta = {};
|
||||
$select.children('option').each(function(i, opt){
|
||||
var optValue = $(opt).attr('value'),
|
||||
distance;
|
||||
|
||||
if(optValue === '') return;
|
||||
distance = Math.abs(optValue - value);
|
||||
if(typeof delta.distance === 'undefined' || distance < delta.distance) {
|
||||
delta = {value: optValue, distance: distance};
|
||||
}
|
||||
});
|
||||
return delta.value;
|
||||
}
|
||||
if(optValue === '') return;
|
||||
distance = Math.abs(optValue - value);
|
||||
if(typeof delta.distance === 'undefined' || distance < delta.distance) {
|
||||
delta = {value: optValue, distance: distance};
|
||||
}
|
||||
});
|
||||
return delta.value;
|
||||
}
|
||||
|
||||
if(dt.isValid()) {
|
||||
//read values from date object
|
||||
$.each(this.map, function(k, v) {
|
||||
if(k === 'ampm') {
|
||||
return;
|
||||
}
|
||||
values[k] = dt[v[1]]();
|
||||
});
|
||||
//read values from date object
|
||||
$.each(this.map, function(k, v) {
|
||||
if(k === 'ampm') {
|
||||
return;
|
||||
}
|
||||
values[k] = dt[v[1]]();
|
||||
});
|
||||
|
||||
if(this.$ampm) {
|
||||
//12:00 pm --> 12:00 (24-h format, midday), 12:00 am --> 00:00 (24-h format, midnight, start of day)
|
||||
if(values.hour >= 12) {
|
||||
values.ampm = 'pm';
|
||||
if(values.hour > 12) {
|
||||
values.hour -= 12;
|
||||
}
|
||||
} else {
|
||||
values.ampm = 'am';
|
||||
if(values.hour === 0) {
|
||||
values.hour = 12;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this.$ampm) {
|
||||
//12:00 pm --> 12:00 (24-h format, midday), 12:00 am --> 00:00 (24-h format, midnight, start of day)
|
||||
if(values.hour >= 12) {
|
||||
values.ampm = 'pm';
|
||||
if(values.hour > 12) {
|
||||
values.hour -= 12;
|
||||
}
|
||||
} else {
|
||||
values.ampm = 'am';
|
||||
if(values.hour === 0) {
|
||||
values.hour = 12;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$.each(values, function(k, v) {
|
||||
//call val() for each existing combo, e.g. this.$hour.val()
|
||||
if(that['$'+k]) {
|
||||
$.each(values, function(k, v) {
|
||||
//call val() for each existing combo, e.g. this.$hour.val()
|
||||
if(that['$'+k]) {
|
||||
|
||||
if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
|
||||
if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
|
||||
that['$'+k].val(v);
|
||||
}
|
||||
});
|
||||
that['$'+k].val(v);
|
||||
}
|
||||
});
|
||||
|
||||
// update days count
|
||||
if (this.options.smartDays) {
|
||||
this.fillCombo('day');
|
||||
}
|
||||
|
||||
this.$element.val(dt.format(this.options.format));
|
||||
this.$element.val(dt.format(this.options.format)).change();
|
||||
}
|
||||
},
|
||||
|
||||
@ -4345,7 +4424,8 @@ $(function(){
|
||||
secondStep: 1,
|
||||
firstItem: 'empty', //'name', 'empty', 'none'
|
||||
errorClass: null,
|
||||
roundTime: true //whether to round minutes and seconds if step > 1
|
||||
roundTime: true, // whether to round minutes and seconds if step > 1
|
||||
smartDays: false // whether days in combo depend on selected month: 31, 30, 28
|
||||
};
|
||||
|
||||
}(window.jQuery));
|
||||
|
File diff suppressed because one or more lines are too long
304
dist/jquery-editable/js/jquery-editable-poshytip.js
vendored
304
dist/jquery-editable/js/jquery-editable-poshytip.js
vendored
@ -2027,7 +2027,9 @@ Makes editable any HTML element on the page. Applied as jQuery method.
|
||||
/**
|
||||
This method collects values from several editable elements and submit them all to server.
|
||||
Internally it runs client-side validation for all fields and submits only in case of success.
|
||||
See <a href="#newrecord">creating new records</a> for details.
|
||||
See <a href="#newrecord">creating new records</a> for details.
|
||||
Since 1.5.1 `submit` can be applied to single element to send data programmatically. In that case
|
||||
`url`, `success` and `error` is taken from initial options and you can just call `$('#username').editable('submit')`.
|
||||
|
||||
@method submit(options)
|
||||
@param {object} options
|
||||
@ -2041,31 +2043,76 @@ Makes editable any HTML element on the page. Applied as jQuery method.
|
||||
case 'submit': //collects value, validate and submit to server for creating new record
|
||||
var config = arguments[1] || {},
|
||||
$elems = this,
|
||||
errors = this.editable('validate'),
|
||||
values;
|
||||
errors = this.editable('validate');
|
||||
|
||||
// validation ok
|
||||
if($.isEmptyObject(errors)) {
|
||||
values = this.editable('getValue');
|
||||
if(config.data) {
|
||||
$.extend(values, config.data);
|
||||
}
|
||||
|
||||
$.ajax($.extend({
|
||||
url: config.url,
|
||||
data: values,
|
||||
type: 'POST'
|
||||
}, config.ajaxOptions))
|
||||
.success(function(response) {
|
||||
//successful response 200 OK
|
||||
if(typeof config.success === 'function') {
|
||||
config.success.call($elems, response, config);
|
||||
}
|
||||
})
|
||||
.error(function(){ //ajax error
|
||||
if(typeof config.error === 'function') {
|
||||
config.error.apply($elems, arguments);
|
||||
var ajaxOptions = {};
|
||||
|
||||
// for single element use url, success etc from options
|
||||
if($elems.length === 1) {
|
||||
var editable = $elems.data('editable');
|
||||
//standard params
|
||||
var params = {
|
||||
name: editable.options.name || '',
|
||||
value: editable.input.value2submit(editable.value),
|
||||
pk: (typeof editable.options.pk === 'function') ?
|
||||
editable.options.pk.call(editable.options.scope) :
|
||||
editable.options.pk
|
||||
};
|
||||
|
||||
//additional params
|
||||
if(typeof editable.options.params === 'function') {
|
||||
params = editable.options.params.call(editable.options.scope, params);
|
||||
} else {
|
||||
//try parse json in single quotes (from data-params attribute)
|
||||
editable.options.params = $.fn.editableutils.tryParseJson(editable.options.params, true);
|
||||
$.extend(params, editable.options.params);
|
||||
}
|
||||
});
|
||||
|
||||
ajaxOptions = {
|
||||
url: editable.options.url,
|
||||
data: params,
|
||||
type: 'POST'
|
||||
};
|
||||
|
||||
// use success / error from options
|
||||
config.success = config.success || editable.options.success;
|
||||
config.error = config.error || editable.options.error;
|
||||
|
||||
// multiple elements
|
||||
} else {
|
||||
var values = this.editable('getValue');
|
||||
|
||||
ajaxOptions = {
|
||||
url: config.url,
|
||||
data: values,
|
||||
type: 'POST'
|
||||
};
|
||||
}
|
||||
|
||||
// ajax success callabck (response 200 OK)
|
||||
ajaxOptions.success = typeof config.success === 'function' ? function(response) {
|
||||
config.success.call($elems, response, config);
|
||||
} : $.noop;
|
||||
|
||||
// ajax error callabck
|
||||
ajaxOptions.error = typeof config.error === 'function' ? function() {
|
||||
config.error.apply($elems, arguments);
|
||||
} : $.noop;
|
||||
|
||||
// extend ajaxOptions
|
||||
if(config.ajaxOptions) {
|
||||
$.extend(ajaxOptions, config.ajaxOptions);
|
||||
}
|
||||
|
||||
// extra data
|
||||
if(config.data) {
|
||||
$.extend(ajaxOptions.data, config.data);
|
||||
}
|
||||
|
||||
// perform ajax request
|
||||
$.ajax(ajaxOptions);
|
||||
} else { //client-side validation error
|
||||
if(typeof config.error === 'function') {
|
||||
config.error.call($elems, errors);
|
||||
@ -3897,11 +3944,11 @@ $(function(){
|
||||
}(window.jQuery));
|
||||
|
||||
/**
|
||||
* Combodate - 1.0.4
|
||||
* Combodate - 1.0.5
|
||||
* Dropdown date and time picker.
|
||||
* Converts text input into dropdowns to pick day, month, year, hour, minute and second.
|
||||
* Uses momentjs as datetime library http://momentjs.com.
|
||||
* For internalization include corresponding file from https://github.com/timrwood/moment/tree/master/lang
|
||||
* For i18n include corresponding file from https://github.com/timrwood/moment/tree/master/lang
|
||||
*
|
||||
* Confusion at noon and midnight - see http://en.wikipedia.org/wiki/12-hour_clock#Confusion_at_noon_and_midnight
|
||||
* In combodate:
|
||||
@ -3948,16 +3995,22 @@ $(function(){
|
||||
this.initCombos();
|
||||
|
||||
//update original input on change
|
||||
this.$widget.on('change', 'select', $.proxy(function(){
|
||||
this.$element.val(this.getValue());
|
||||
this.$widget.on('change', 'select', $.proxy(function(e) {
|
||||
this.$element.val(this.getValue()).change();
|
||||
// update days count if month or year changes
|
||||
if (this.options.smartDays) {
|
||||
if ($(e.target).is('.month') || $(e.target).is('.year')) {
|
||||
this.fillCombo('day');
|
||||
}
|
||||
}
|
||||
}, this));
|
||||
|
||||
this.$widget.find('select').css('width', 'auto');
|
||||
|
||||
//hide original input and insert widget
|
||||
// hide original input and insert widget
|
||||
this.$element.hide().after(this.$widget);
|
||||
|
||||
//set initial value
|
||||
// set initial value
|
||||
this.setValue(this.$element.val() || this.options.value);
|
||||
},
|
||||
|
||||
@ -3994,22 +4047,41 @@ $(function(){
|
||||
Initialize combos that presents in template
|
||||
*/
|
||||
initCombos: function() {
|
||||
var that = this;
|
||||
$.each(this.map, function(k, v) {
|
||||
var $c = that.$widget.find('.'+k), f, items;
|
||||
if($c.length) {
|
||||
that['$'+k] = $c; //set properties like this.$day, this.$month etc.
|
||||
f = 'fill' + k.charAt(0).toUpperCase() + k.slice(1); //define method name to fill items, e.g `fillDays`
|
||||
items = that[f]();
|
||||
that['$'+k].html(that.renderItems(items));
|
||||
}
|
||||
});
|
||||
for (var k in this.map) {
|
||||
var $c = this.$widget.find('.'+k);
|
||||
// set properties like this.$day, this.$month etc.
|
||||
this['$'+k] = $c.length ? $c : null;
|
||||
// fill with items
|
||||
this.fillCombo(k);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
Fill combo with items
|
||||
*/
|
||||
fillCombo: function(k) {
|
||||
var $combo = this['$'+k];
|
||||
if (!$combo) {
|
||||
return;
|
||||
}
|
||||
|
||||
// define method name to fill items, e.g `fillDays`
|
||||
var f = 'fill' + k.charAt(0).toUpperCase() + k.slice(1);
|
||||
var items = this[f]();
|
||||
var value = $combo.val();
|
||||
|
||||
$combo.empty();
|
||||
for(var i=0; i<items.length; i++) {
|
||||
$combo.append('<option value="'+items[i][0]+'">'+items[i][1]+'</option>');
|
||||
}
|
||||
|
||||
$combo.val(value);
|
||||
},
|
||||
|
||||
/*
|
||||
Initialize items of combos. Handles `firstItem` option
|
||||
*/
|
||||
initItems: function(key) {
|
||||
fillCommon: function(key) {
|
||||
var values = [],
|
||||
relTime;
|
||||
|
||||
@ -4024,27 +4096,29 @@ $(function(){
|
||||
values.push(['', '']);
|
||||
}
|
||||
return values;
|
||||
},
|
||||
|
||||
/*
|
||||
render items to string of <option> tags
|
||||
*/
|
||||
renderItems: function(items) {
|
||||
var str = [];
|
||||
for(var i=0; i<items.length; i++) {
|
||||
str.push('<option value="'+items[i][0]+'">'+items[i][1]+'</option>');
|
||||
}
|
||||
return str.join("\n");
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
fill day
|
||||
*/
|
||||
fillDay: function() {
|
||||
var items = this.initItems('d'), name, i,
|
||||
twoDigit = this.options.template.indexOf('DD') !== -1;
|
||||
|
||||
for(i=1; i<=31; i++) {
|
||||
var items = this.fillCommon('d'), name, i,
|
||||
twoDigit = this.options.template.indexOf('DD') !== -1,
|
||||
daysCount = 31;
|
||||
|
||||
// detect days count (depends on month and year)
|
||||
// originally https://github.com/vitalets/combodate/pull/7
|
||||
if (this.options.smartDays && this.$month && this.$year) {
|
||||
var month = parseInt(this.$month.val(), 10);
|
||||
var year = parseInt(this.$year.val(), 10);
|
||||
|
||||
if (!isNaN(month) && !isNaN(year)) {
|
||||
daysCount = moment([year, month]).daysInMonth();
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 1; i <= daysCount; i++) {
|
||||
name = twoDigit ? this.leadZero(i) : i;
|
||||
items.push([i, name]);
|
||||
}
|
||||
@ -4055,7 +4129,7 @@ $(function(){
|
||||
fill month
|
||||
*/
|
||||
fillMonth: function() {
|
||||
var items = this.initItems('M'), name, i,
|
||||
var items = this.fillCommon('M'), name, i,
|
||||
longNames = this.options.template.indexOf('MMMM') !== -1,
|
||||
shortNames = this.options.template.indexOf('MMM') !== -1,
|
||||
twoDigit = this.options.template.indexOf('MM') !== -1;
|
||||
@ -4088,7 +4162,7 @@ $(function(){
|
||||
items[this.options.yearDescending ? 'push' : 'unshift']([i, name]);
|
||||
}
|
||||
|
||||
items = this.initItems('y').concat(items);
|
||||
items = this.fillCommon('y').concat(items);
|
||||
|
||||
return items;
|
||||
},
|
||||
@ -4097,7 +4171,7 @@ $(function(){
|
||||
fill hour
|
||||
*/
|
||||
fillHour: function() {
|
||||
var items = this.initItems('h'), name, i,
|
||||
var items = this.fillCommon('h'), name, i,
|
||||
h12 = this.options.template.indexOf('h') !== -1,
|
||||
h24 = this.options.template.indexOf('H') !== -1,
|
||||
twoDigit = this.options.template.toLowerCase().indexOf('hh') !== -1,
|
||||
@ -4115,7 +4189,7 @@ $(function(){
|
||||
fill minute
|
||||
*/
|
||||
fillMinute: function() {
|
||||
var items = this.initItems('m'), name, i,
|
||||
var items = this.fillCommon('m'), name, i,
|
||||
twoDigit = this.options.template.indexOf('mm') !== -1;
|
||||
|
||||
for(i=0; i<=59; i+= this.options.minuteStep) {
|
||||
@ -4129,7 +4203,7 @@ $(function(){
|
||||
fill second
|
||||
*/
|
||||
fillSecond: function() {
|
||||
var items = this.initItems('s'), name, i,
|
||||
var items = this.fillCommon('s'), name, i,
|
||||
twoDigit = this.options.template.indexOf('ss') !== -1;
|
||||
|
||||
for(i=0; i<=59; i+= this.options.secondStep) {
|
||||
@ -4151,7 +4225,7 @@ $(function(){
|
||||
];
|
||||
return items;
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
Returns current date value from combos.
|
||||
If format not specified - `options.format` used.
|
||||
@ -4214,63 +4288,68 @@ $(function(){
|
||||
that = this,
|
||||
values = {};
|
||||
|
||||
//function to find nearest value in select options
|
||||
function getNearest($select, value) {
|
||||
var delta = {};
|
||||
$select.children('option').each(function(i, opt){
|
||||
var optValue = $(opt).attr('value'),
|
||||
distance;
|
||||
//function to find nearest value in select options
|
||||
function getNearest($select, value) {
|
||||
var delta = {};
|
||||
$select.children('option').each(function(i, opt){
|
||||
var optValue = $(opt).attr('value'),
|
||||
distance;
|
||||
|
||||
if(optValue === '') return;
|
||||
distance = Math.abs(optValue - value);
|
||||
if(typeof delta.distance === 'undefined' || distance < delta.distance) {
|
||||
delta = {value: optValue, distance: distance};
|
||||
}
|
||||
});
|
||||
return delta.value;
|
||||
}
|
||||
if(optValue === '') return;
|
||||
distance = Math.abs(optValue - value);
|
||||
if(typeof delta.distance === 'undefined' || distance < delta.distance) {
|
||||
delta = {value: optValue, distance: distance};
|
||||
}
|
||||
});
|
||||
return delta.value;
|
||||
}
|
||||
|
||||
if(dt.isValid()) {
|
||||
//read values from date object
|
||||
$.each(this.map, function(k, v) {
|
||||
if(k === 'ampm') {
|
||||
return;
|
||||
}
|
||||
values[k] = dt[v[1]]();
|
||||
});
|
||||
//read values from date object
|
||||
$.each(this.map, function(k, v) {
|
||||
if(k === 'ampm') {
|
||||
return;
|
||||
}
|
||||
values[k] = dt[v[1]]();
|
||||
});
|
||||
|
||||
if(this.$ampm) {
|
||||
//12:00 pm --> 12:00 (24-h format, midday), 12:00 am --> 00:00 (24-h format, midnight, start of day)
|
||||
if(values.hour >= 12) {
|
||||
values.ampm = 'pm';
|
||||
if(values.hour > 12) {
|
||||
values.hour -= 12;
|
||||
}
|
||||
} else {
|
||||
values.ampm = 'am';
|
||||
if(values.hour === 0) {
|
||||
values.hour = 12;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this.$ampm) {
|
||||
//12:00 pm --> 12:00 (24-h format, midday), 12:00 am --> 00:00 (24-h format, midnight, start of day)
|
||||
if(values.hour >= 12) {
|
||||
values.ampm = 'pm';
|
||||
if(values.hour > 12) {
|
||||
values.hour -= 12;
|
||||
}
|
||||
} else {
|
||||
values.ampm = 'am';
|
||||
if(values.hour === 0) {
|
||||
values.hour = 12;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$.each(values, function(k, v) {
|
||||
//call val() for each existing combo, e.g. this.$hour.val()
|
||||
if(that['$'+k]) {
|
||||
$.each(values, function(k, v) {
|
||||
//call val() for each existing combo, e.g. this.$hour.val()
|
||||
if(that['$'+k]) {
|
||||
|
||||
if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
|
||||
if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
|
||||
that['$'+k].val(v);
|
||||
}
|
||||
});
|
||||
that['$'+k].val(v);
|
||||
}
|
||||
});
|
||||
|
||||
// update days count
|
||||
if (this.options.smartDays) {
|
||||
this.fillCombo('day');
|
||||
}
|
||||
|
||||
this.$element.val(dt.format(this.options.format));
|
||||
this.$element.val(dt.format(this.options.format)).change();
|
||||
}
|
||||
},
|
||||
|
||||
@ -4345,7 +4424,8 @@ $(function(){
|
||||
secondStep: 1,
|
||||
firstItem: 'empty', //'name', 'empty', 'none'
|
||||
errorClass: null,
|
||||
roundTime: true //whether to round minutes and seconds if step > 1
|
||||
roundTime: true, // whether to round minutes and seconds if step > 1
|
||||
smartDays: false // whether days in combo depend on selected month: 31, 30, 28
|
||||
};
|
||||
|
||||
}(window.jQuery));
|
||||
|
File diff suppressed because one or more lines are too long
304
dist/jqueryui-editable/js/jqueryui-editable.js
vendored
304
dist/jqueryui-editable/js/jqueryui-editable.js
vendored
@ -2027,7 +2027,9 @@ Makes editable any HTML element on the page. Applied as jQuery method.
|
||||
/**
|
||||
This method collects values from several editable elements and submit them all to server.
|
||||
Internally it runs client-side validation for all fields and submits only in case of success.
|
||||
See <a href="#newrecord">creating new records</a> for details.
|
||||
See <a href="#newrecord">creating new records</a> for details.
|
||||
Since 1.5.1 `submit` can be applied to single element to send data programmatically. In that case
|
||||
`url`, `success` and `error` is taken from initial options and you can just call `$('#username').editable('submit')`.
|
||||
|
||||
@method submit(options)
|
||||
@param {object} options
|
||||
@ -2041,31 +2043,76 @@ Makes editable any HTML element on the page. Applied as jQuery method.
|
||||
case 'submit': //collects value, validate and submit to server for creating new record
|
||||
var config = arguments[1] || {},
|
||||
$elems = this,
|
||||
errors = this.editable('validate'),
|
||||
values;
|
||||
errors = this.editable('validate');
|
||||
|
||||
// validation ok
|
||||
if($.isEmptyObject(errors)) {
|
||||
values = this.editable('getValue');
|
||||
if(config.data) {
|
||||
$.extend(values, config.data);
|
||||
}
|
||||
|
||||
$.ajax($.extend({
|
||||
url: config.url,
|
||||
data: values,
|
||||
type: 'POST'
|
||||
}, config.ajaxOptions))
|
||||
.success(function(response) {
|
||||
//successful response 200 OK
|
||||
if(typeof config.success === 'function') {
|
||||
config.success.call($elems, response, config);
|
||||
}
|
||||
})
|
||||
.error(function(){ //ajax error
|
||||
if(typeof config.error === 'function') {
|
||||
config.error.apply($elems, arguments);
|
||||
var ajaxOptions = {};
|
||||
|
||||
// for single element use url, success etc from options
|
||||
if($elems.length === 1) {
|
||||
var editable = $elems.data('editable');
|
||||
//standard params
|
||||
var params = {
|
||||
name: editable.options.name || '',
|
||||
value: editable.input.value2submit(editable.value),
|
||||
pk: (typeof editable.options.pk === 'function') ?
|
||||
editable.options.pk.call(editable.options.scope) :
|
||||
editable.options.pk
|
||||
};
|
||||
|
||||
//additional params
|
||||
if(typeof editable.options.params === 'function') {
|
||||
params = editable.options.params.call(editable.options.scope, params);
|
||||
} else {
|
||||
//try parse json in single quotes (from data-params attribute)
|
||||
editable.options.params = $.fn.editableutils.tryParseJson(editable.options.params, true);
|
||||
$.extend(params, editable.options.params);
|
||||
}
|
||||
});
|
||||
|
||||
ajaxOptions = {
|
||||
url: editable.options.url,
|
||||
data: params,
|
||||
type: 'POST'
|
||||
};
|
||||
|
||||
// use success / error from options
|
||||
config.success = config.success || editable.options.success;
|
||||
config.error = config.error || editable.options.error;
|
||||
|
||||
// multiple elements
|
||||
} else {
|
||||
var values = this.editable('getValue');
|
||||
|
||||
ajaxOptions = {
|
||||
url: config.url,
|
||||
data: values,
|
||||
type: 'POST'
|
||||
};
|
||||
}
|
||||
|
||||
// ajax success callabck (response 200 OK)
|
||||
ajaxOptions.success = typeof config.success === 'function' ? function(response) {
|
||||
config.success.call($elems, response, config);
|
||||
} : $.noop;
|
||||
|
||||
// ajax error callabck
|
||||
ajaxOptions.error = typeof config.error === 'function' ? function() {
|
||||
config.error.apply($elems, arguments);
|
||||
} : $.noop;
|
||||
|
||||
// extend ajaxOptions
|
||||
if(config.ajaxOptions) {
|
||||
$.extend(ajaxOptions, config.ajaxOptions);
|
||||
}
|
||||
|
||||
// extra data
|
||||
if(config.data) {
|
||||
$.extend(ajaxOptions.data, config.data);
|
||||
}
|
||||
|
||||
// perform ajax request
|
||||
$.ajax(ajaxOptions);
|
||||
} else { //client-side validation error
|
||||
if(typeof config.error === 'function') {
|
||||
config.error.call($elems, errors);
|
||||
@ -3897,11 +3944,11 @@ $(function(){
|
||||
}(window.jQuery));
|
||||
|
||||
/**
|
||||
* Combodate - 1.0.4
|
||||
* Combodate - 1.0.5
|
||||
* Dropdown date and time picker.
|
||||
* Converts text input into dropdowns to pick day, month, year, hour, minute and second.
|
||||
* Uses momentjs as datetime library http://momentjs.com.
|
||||
* For internalization include corresponding file from https://github.com/timrwood/moment/tree/master/lang
|
||||
* For i18n include corresponding file from https://github.com/timrwood/moment/tree/master/lang
|
||||
*
|
||||
* Confusion at noon and midnight - see http://en.wikipedia.org/wiki/12-hour_clock#Confusion_at_noon_and_midnight
|
||||
* In combodate:
|
||||
@ -3948,16 +3995,22 @@ $(function(){
|
||||
this.initCombos();
|
||||
|
||||
//update original input on change
|
||||
this.$widget.on('change', 'select', $.proxy(function(){
|
||||
this.$element.val(this.getValue());
|
||||
this.$widget.on('change', 'select', $.proxy(function(e) {
|
||||
this.$element.val(this.getValue()).change();
|
||||
// update days count if month or year changes
|
||||
if (this.options.smartDays) {
|
||||
if ($(e.target).is('.month') || $(e.target).is('.year')) {
|
||||
this.fillCombo('day');
|
||||
}
|
||||
}
|
||||
}, this));
|
||||
|
||||
this.$widget.find('select').css('width', 'auto');
|
||||
|
||||
//hide original input and insert widget
|
||||
// hide original input and insert widget
|
||||
this.$element.hide().after(this.$widget);
|
||||
|
||||
//set initial value
|
||||
// set initial value
|
||||
this.setValue(this.$element.val() || this.options.value);
|
||||
},
|
||||
|
||||
@ -3994,22 +4047,41 @@ $(function(){
|
||||
Initialize combos that presents in template
|
||||
*/
|
||||
initCombos: function() {
|
||||
var that = this;
|
||||
$.each(this.map, function(k, v) {
|
||||
var $c = that.$widget.find('.'+k), f, items;
|
||||
if($c.length) {
|
||||
that['$'+k] = $c; //set properties like this.$day, this.$month etc.
|
||||
f = 'fill' + k.charAt(0).toUpperCase() + k.slice(1); //define method name to fill items, e.g `fillDays`
|
||||
items = that[f]();
|
||||
that['$'+k].html(that.renderItems(items));
|
||||
}
|
||||
});
|
||||
for (var k in this.map) {
|
||||
var $c = this.$widget.find('.'+k);
|
||||
// set properties like this.$day, this.$month etc.
|
||||
this['$'+k] = $c.length ? $c : null;
|
||||
// fill with items
|
||||
this.fillCombo(k);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
Fill combo with items
|
||||
*/
|
||||
fillCombo: function(k) {
|
||||
var $combo = this['$'+k];
|
||||
if (!$combo) {
|
||||
return;
|
||||
}
|
||||
|
||||
// define method name to fill items, e.g `fillDays`
|
||||
var f = 'fill' + k.charAt(0).toUpperCase() + k.slice(1);
|
||||
var items = this[f]();
|
||||
var value = $combo.val();
|
||||
|
||||
$combo.empty();
|
||||
for(var i=0; i<items.length; i++) {
|
||||
$combo.append('<option value="'+items[i][0]+'">'+items[i][1]+'</option>');
|
||||
}
|
||||
|
||||
$combo.val(value);
|
||||
},
|
||||
|
||||
/*
|
||||
Initialize items of combos. Handles `firstItem` option
|
||||
*/
|
||||
initItems: function(key) {
|
||||
fillCommon: function(key) {
|
||||
var values = [],
|
||||
relTime;
|
||||
|
||||
@ -4024,27 +4096,29 @@ $(function(){
|
||||
values.push(['', '']);
|
||||
}
|
||||
return values;
|
||||
},
|
||||
|
||||
/*
|
||||
render items to string of <option> tags
|
||||
*/
|
||||
renderItems: function(items) {
|
||||
var str = [];
|
||||
for(var i=0; i<items.length; i++) {
|
||||
str.push('<option value="'+items[i][0]+'">'+items[i][1]+'</option>');
|
||||
}
|
||||
return str.join("\n");
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
fill day
|
||||
*/
|
||||
fillDay: function() {
|
||||
var items = this.initItems('d'), name, i,
|
||||
twoDigit = this.options.template.indexOf('DD') !== -1;
|
||||
|
||||
for(i=1; i<=31; i++) {
|
||||
var items = this.fillCommon('d'), name, i,
|
||||
twoDigit = this.options.template.indexOf('DD') !== -1,
|
||||
daysCount = 31;
|
||||
|
||||
// detect days count (depends on month and year)
|
||||
// originally https://github.com/vitalets/combodate/pull/7
|
||||
if (this.options.smartDays && this.$month && this.$year) {
|
||||
var month = parseInt(this.$month.val(), 10);
|
||||
var year = parseInt(this.$year.val(), 10);
|
||||
|
||||
if (!isNaN(month) && !isNaN(year)) {
|
||||
daysCount = moment([year, month]).daysInMonth();
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 1; i <= daysCount; i++) {
|
||||
name = twoDigit ? this.leadZero(i) : i;
|
||||
items.push([i, name]);
|
||||
}
|
||||
@ -4055,7 +4129,7 @@ $(function(){
|
||||
fill month
|
||||
*/
|
||||
fillMonth: function() {
|
||||
var items = this.initItems('M'), name, i,
|
||||
var items = this.fillCommon('M'), name, i,
|
||||
longNames = this.options.template.indexOf('MMMM') !== -1,
|
||||
shortNames = this.options.template.indexOf('MMM') !== -1,
|
||||
twoDigit = this.options.template.indexOf('MM') !== -1;
|
||||
@ -4088,7 +4162,7 @@ $(function(){
|
||||
items[this.options.yearDescending ? 'push' : 'unshift']([i, name]);
|
||||
}
|
||||
|
||||
items = this.initItems('y').concat(items);
|
||||
items = this.fillCommon('y').concat(items);
|
||||
|
||||
return items;
|
||||
},
|
||||
@ -4097,7 +4171,7 @@ $(function(){
|
||||
fill hour
|
||||
*/
|
||||
fillHour: function() {
|
||||
var items = this.initItems('h'), name, i,
|
||||
var items = this.fillCommon('h'), name, i,
|
||||
h12 = this.options.template.indexOf('h') !== -1,
|
||||
h24 = this.options.template.indexOf('H') !== -1,
|
||||
twoDigit = this.options.template.toLowerCase().indexOf('hh') !== -1,
|
||||
@ -4115,7 +4189,7 @@ $(function(){
|
||||
fill minute
|
||||
*/
|
||||
fillMinute: function() {
|
||||
var items = this.initItems('m'), name, i,
|
||||
var items = this.fillCommon('m'), name, i,
|
||||
twoDigit = this.options.template.indexOf('mm') !== -1;
|
||||
|
||||
for(i=0; i<=59; i+= this.options.minuteStep) {
|
||||
@ -4129,7 +4203,7 @@ $(function(){
|
||||
fill second
|
||||
*/
|
||||
fillSecond: function() {
|
||||
var items = this.initItems('s'), name, i,
|
||||
var items = this.fillCommon('s'), name, i,
|
||||
twoDigit = this.options.template.indexOf('ss') !== -1;
|
||||
|
||||
for(i=0; i<=59; i+= this.options.secondStep) {
|
||||
@ -4151,7 +4225,7 @@ $(function(){
|
||||
];
|
||||
return items;
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
Returns current date value from combos.
|
||||
If format not specified - `options.format` used.
|
||||
@ -4214,63 +4288,68 @@ $(function(){
|
||||
that = this,
|
||||
values = {};
|
||||
|
||||
//function to find nearest value in select options
|
||||
function getNearest($select, value) {
|
||||
var delta = {};
|
||||
$select.children('option').each(function(i, opt){
|
||||
var optValue = $(opt).attr('value'),
|
||||
distance;
|
||||
//function to find nearest value in select options
|
||||
function getNearest($select, value) {
|
||||
var delta = {};
|
||||
$select.children('option').each(function(i, opt){
|
||||
var optValue = $(opt).attr('value'),
|
||||
distance;
|
||||
|
||||
if(optValue === '') return;
|
||||
distance = Math.abs(optValue - value);
|
||||
if(typeof delta.distance === 'undefined' || distance < delta.distance) {
|
||||
delta = {value: optValue, distance: distance};
|
||||
}
|
||||
});
|
||||
return delta.value;
|
||||
}
|
||||
if(optValue === '') return;
|
||||
distance = Math.abs(optValue - value);
|
||||
if(typeof delta.distance === 'undefined' || distance < delta.distance) {
|
||||
delta = {value: optValue, distance: distance};
|
||||
}
|
||||
});
|
||||
return delta.value;
|
||||
}
|
||||
|
||||
if(dt.isValid()) {
|
||||
//read values from date object
|
||||
$.each(this.map, function(k, v) {
|
||||
if(k === 'ampm') {
|
||||
return;
|
||||
}
|
||||
values[k] = dt[v[1]]();
|
||||
});
|
||||
//read values from date object
|
||||
$.each(this.map, function(k, v) {
|
||||
if(k === 'ampm') {
|
||||
return;
|
||||
}
|
||||
values[k] = dt[v[1]]();
|
||||
});
|
||||
|
||||
if(this.$ampm) {
|
||||
//12:00 pm --> 12:00 (24-h format, midday), 12:00 am --> 00:00 (24-h format, midnight, start of day)
|
||||
if(values.hour >= 12) {
|
||||
values.ampm = 'pm';
|
||||
if(values.hour > 12) {
|
||||
values.hour -= 12;
|
||||
}
|
||||
} else {
|
||||
values.ampm = 'am';
|
||||
if(values.hour === 0) {
|
||||
values.hour = 12;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this.$ampm) {
|
||||
//12:00 pm --> 12:00 (24-h format, midday), 12:00 am --> 00:00 (24-h format, midnight, start of day)
|
||||
if(values.hour >= 12) {
|
||||
values.ampm = 'pm';
|
||||
if(values.hour > 12) {
|
||||
values.hour -= 12;
|
||||
}
|
||||
} else {
|
||||
values.ampm = 'am';
|
||||
if(values.hour === 0) {
|
||||
values.hour = 12;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$.each(values, function(k, v) {
|
||||
//call val() for each existing combo, e.g. this.$hour.val()
|
||||
if(that['$'+k]) {
|
||||
$.each(values, function(k, v) {
|
||||
//call val() for each existing combo, e.g. this.$hour.val()
|
||||
if(that['$'+k]) {
|
||||
|
||||
if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
|
||||
if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) {
|
||||
v = getNearest(that['$'+k], v);
|
||||
}
|
||||
|
||||
that['$'+k].val(v);
|
||||
}
|
||||
});
|
||||
that['$'+k].val(v);
|
||||
}
|
||||
});
|
||||
|
||||
// update days count
|
||||
if (this.options.smartDays) {
|
||||
this.fillCombo('day');
|
||||
}
|
||||
|
||||
this.$element.val(dt.format(this.options.format));
|
||||
this.$element.val(dt.format(this.options.format)).change();
|
||||
}
|
||||
},
|
||||
|
||||
@ -4345,7 +4424,8 @@ $(function(){
|
||||
secondStep: 1,
|
||||
firstItem: 'empty', //'name', 'empty', 'none'
|
||||
errorClass: null,
|
||||
roundTime: true //whether to round minutes and seconds if step > 1
|
||||
roundTime: true, // whether to round minutes and seconds if step > 1
|
||||
smartDays: false // whether days in combo depend on selected month: 31, 30, 28
|
||||
};
|
||||
|
||||
}(window.jQuery));
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user