build dist

This commit is contained in:
vitalets 2013-11-04 19:10:07 +04:00
parent 2df93f856d
commit f32802f48a
9 changed files with 780 additions and 459 deletions

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) [bug] select2: placeholder not shown if value initially empty (vitalets)
[enh #400] allow `validate` to change submitted value, also fix #354 (vitalets) [enh #400] allow `validate` to change submitted value, also fix #354 (vitalets)
[enh #396] bs3 popover: placement `auto` (vitalets) [enh #396] bs3 popover: placement `auto` (vitalets)

@ -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. 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. 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) @method submit(options)
@param {object} 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 case 'submit': //collects value, validate and submit to server for creating new record
var config = arguments[1] || {}, var config = arguments[1] || {},
$elems = this, $elems = this,
errors = this.editable('validate'), errors = this.editable('validate');
values;
// validation ok
if($.isEmptyObject(errors)) { if($.isEmptyObject(errors)) {
values = this.editable('getValue'); var ajaxOptions = {};
if(config.data) {
$.extend(values, config.data); // for single element use url, success etc from options
} if($elems.length === 1) {
var editable = $elems.data('editable');
$.ajax($.extend({ //standard params
url: config.url, var params = {
data: values, name: editable.options.name || '',
type: 'POST' value: editable.input.value2submit(editable.value),
}, config.ajaxOptions)) pk: (typeof editable.options.pk === 'function') ?
.success(function(response) { editable.options.pk.call(editable.options.scope) :
//successful response 200 OK editable.options.pk
if(typeof config.success === 'function') { };
config.success.call($elems, response, config);
} //additional params
}) if(typeof editable.options.params === 'function') {
.error(function(){ //ajax error params = editable.options.params.call(editable.options.scope, params);
if(typeof config.error === 'function') { } else {
config.error.apply($elems, arguments); //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 } else { //client-side validation error
if(typeof config.error === 'function') { if(typeof config.error === 'function') {
config.error.call($elems, errors); config.error.call($elems, errors);
@ -3897,11 +3944,11 @@ $(function(){
}(window.jQuery)); }(window.jQuery));
/** /**
* Combodate - 1.0.4 * Combodate - 1.0.5
* Dropdown date and time picker. * Dropdown date and time picker.
* Converts text input into dropdowns to pick day, month, year, hour, minute and second. * Converts text input into dropdowns to pick day, month, year, hour, minute and second.
* Uses momentjs as datetime library http://momentjs.com. * 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 * Confusion at noon and midnight - see http://en.wikipedia.org/wiki/12-hour_clock#Confusion_at_noon_and_midnight
* In combodate: * In combodate:
@ -3948,16 +3995,22 @@ $(function(){
this.initCombos(); this.initCombos();
//update original input on change //update original input on change
this.$widget.on('change', 'select', $.proxy(function(){ this.$widget.on('change', 'select', $.proxy(function(e) {
this.$element.val(this.getValue()); 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));
this.$widget.find('select').css('width', 'auto'); 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); this.$element.hide().after(this.$widget);
//set initial value // set initial value
this.setValue(this.$element.val() || this.options.value); this.setValue(this.$element.val() || this.options.value);
}, },
@ -3994,22 +4047,41 @@ $(function(){
Initialize combos that presents in template Initialize combos that presents in template
*/ */
initCombos: function() { initCombos: function() {
var that = this; for (var k in this.map) {
$.each(this.map, function(k, v) { var $c = this.$widget.find('.'+k);
var $c = that.$widget.find('.'+k), f, items; // set properties like this.$day, this.$month etc.
if($c.length) { this['$'+k] = $c.length ? $c : null;
that['$'+k] = $c; //set properties like this.$day, this.$month etc. // fill with items
f = 'fill' + k.charAt(0).toUpperCase() + k.slice(1); //define method name to fill items, e.g `fillDays` this.fillCombo(k);
items = that[f](); }
that['$'+k].html(that.renderItems(items));
}
});
}, },
/*
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 Initialize items of combos. Handles `firstItem` option
*/ */
initItems: function(key) { fillCommon: function(key) {
var values = [], var values = [],
relTime; relTime;
@ -4024,27 +4096,29 @@ $(function(){
values.push(['', '']); values.push(['', '']);
} }
return values; 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 fill day
*/ */
fillDay: function() { fillDay: function() {
var items = this.initItems('d'), name, i, var items = this.fillCommon('d'), name, i,
twoDigit = this.options.template.indexOf('DD') !== -1; twoDigit = this.options.template.indexOf('DD') !== -1,
daysCount = 31;
for(i=1; i<=31; i++) {
// 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; name = twoDigit ? this.leadZero(i) : i;
items.push([i, name]); items.push([i, name]);
} }
@ -4055,7 +4129,7 @@ $(function(){
fill month fill month
*/ */
fillMonth: function() { fillMonth: function() {
var items = this.initItems('M'), name, i, var items = this.fillCommon('M'), name, i,
longNames = this.options.template.indexOf('MMMM') !== -1, longNames = this.options.template.indexOf('MMMM') !== -1,
shortNames = this.options.template.indexOf('MMM') !== -1, shortNames = this.options.template.indexOf('MMM') !== -1,
twoDigit = this.options.template.indexOf('MM') !== -1; twoDigit = this.options.template.indexOf('MM') !== -1;
@ -4088,7 +4162,7 @@ $(function(){
items[this.options.yearDescending ? 'push' : 'unshift']([i, name]); items[this.options.yearDescending ? 'push' : 'unshift']([i, name]);
} }
items = this.initItems('y').concat(items); items = this.fillCommon('y').concat(items);
return items; return items;
}, },
@ -4097,7 +4171,7 @@ $(function(){
fill hour fill hour
*/ */
fillHour: function() { fillHour: function() {
var items = this.initItems('h'), name, i, var items = this.fillCommon('h'), name, i,
h12 = this.options.template.indexOf('h') !== -1, h12 = this.options.template.indexOf('h') !== -1,
h24 = this.options.template.indexOf('H') !== -1, h24 = this.options.template.indexOf('H') !== -1,
twoDigit = this.options.template.toLowerCase().indexOf('hh') !== -1, twoDigit = this.options.template.toLowerCase().indexOf('hh') !== -1,
@ -4115,7 +4189,7 @@ $(function(){
fill minute fill minute
*/ */
fillMinute: function() { fillMinute: function() {
var items = this.initItems('m'), name, i, var items = this.fillCommon('m'), name, i,
twoDigit = this.options.template.indexOf('mm') !== -1; twoDigit = this.options.template.indexOf('mm') !== -1;
for(i=0; i<=59; i+= this.options.minuteStep) { for(i=0; i<=59; i+= this.options.minuteStep) {
@ -4129,7 +4203,7 @@ $(function(){
fill second fill second
*/ */
fillSecond: function() { fillSecond: function() {
var items = this.initItems('s'), name, i, var items = this.fillCommon('s'), name, i,
twoDigit = this.options.template.indexOf('ss') !== -1; twoDigit = this.options.template.indexOf('ss') !== -1;
for(i=0; i<=59; i+= this.options.secondStep) { for(i=0; i<=59; i+= this.options.secondStep) {
@ -4151,7 +4225,7 @@ $(function(){
]; ];
return items; return items;
}, },
/* /*
Returns current date value from combos. Returns current date value from combos.
If format not specified - `options.format` used. If format not specified - `options.format` used.
@ -4214,63 +4288,68 @@ $(function(){
that = this, that = this,
values = {}; values = {};
//function to find nearest value in select options //function to find nearest value in select options
function getNearest($select, value) { function getNearest($select, value) {
var delta = {}; var delta = {};
$select.children('option').each(function(i, opt){ $select.children('option').each(function(i, opt){
var optValue = $(opt).attr('value'), var optValue = $(opt).attr('value'),
distance; distance;
if(optValue === '') return; if(optValue === '') return;
distance = Math.abs(optValue - value); distance = Math.abs(optValue - value);
if(typeof delta.distance === 'undefined' || distance < delta.distance) { if(typeof delta.distance === 'undefined' || distance < delta.distance) {
delta = {value: optValue, distance: distance}; delta = {value: optValue, distance: distance};
} }
}); });
return delta.value; return delta.value;
} }
if(dt.isValid()) { if(dt.isValid()) {
//read values from date object //read values from date object
$.each(this.map, function(k, v) { $.each(this.map, function(k, v) {
if(k === 'ampm') { if(k === 'ampm') {
return; return;
} }
values[k] = dt[v[1]](); values[k] = dt[v[1]]();
}); });
if(this.$ampm) { if(this.$ampm) {
//12:00 pm --> 12:00 (24-h format, midday), 12:00 am --> 00:00 (24-h format, midnight, start of day) //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) { if(values.hour >= 12) {
values.ampm = 'pm'; values.ampm = 'pm';
if(values.hour > 12) { if(values.hour > 12) {
values.hour -= 12; values.hour -= 12;
} }
} else { } else {
values.ampm = 'am'; values.ampm = 'am';
if(values.hour === 0) { if(values.hour === 0) {
values.hour = 12; values.hour = 12;
} }
} }
} }
$.each(values, function(k, v) { $.each(values, function(k, v) {
//call val() for each existing combo, e.g. this.$hour.val() //call val() for each existing combo, e.g. this.$hour.val()
if(that['$'+k]) { if(that['$'+k]) {
if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) { if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) {
v = getNearest(that['$'+k], v); v = getNearest(that['$'+k], v);
} }
if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) { if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) {
v = getNearest(that['$'+k], v); 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, secondStep: 1,
firstItem: 'empty', //'name', 'empty', 'none' firstItem: 'empty', //'name', 'empty', 'none'
errorClass: null, 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)); }(window.jQuery));

File diff suppressed because one or more lines are too long

@ -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. 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. 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) @method submit(options)
@param {object} 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 case 'submit': //collects value, validate and submit to server for creating new record
var config = arguments[1] || {}, var config = arguments[1] || {},
$elems = this, $elems = this,
errors = this.editable('validate'), errors = this.editable('validate');
values;
// validation ok
if($.isEmptyObject(errors)) { if($.isEmptyObject(errors)) {
values = this.editable('getValue'); var ajaxOptions = {};
if(config.data) {
$.extend(values, config.data); // for single element use url, success etc from options
} if($elems.length === 1) {
var editable = $elems.data('editable');
$.ajax($.extend({ //standard params
url: config.url, var params = {
data: values, name: editable.options.name || '',
type: 'POST' value: editable.input.value2submit(editable.value),
}, config.ajaxOptions)) pk: (typeof editable.options.pk === 'function') ?
.success(function(response) { editable.options.pk.call(editable.options.scope) :
//successful response 200 OK editable.options.pk
if(typeof config.success === 'function') { };
config.success.call($elems, response, config);
} //additional params
}) if(typeof editable.options.params === 'function') {
.error(function(){ //ajax error params = editable.options.params.call(editable.options.scope, params);
if(typeof config.error === 'function') { } else {
config.error.apply($elems, arguments); //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 } else { //client-side validation error
if(typeof config.error === 'function') { if(typeof config.error === 'function') {
config.error.call($elems, errors); config.error.call($elems, errors);
@ -3897,11 +3944,11 @@ $(function(){
}(window.jQuery)); }(window.jQuery));
/** /**
* Combodate - 1.0.4 * Combodate - 1.0.5
* Dropdown date and time picker. * Dropdown date and time picker.
* Converts text input into dropdowns to pick day, month, year, hour, minute and second. * Converts text input into dropdowns to pick day, month, year, hour, minute and second.
* Uses momentjs as datetime library http://momentjs.com. * 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 * Confusion at noon and midnight - see http://en.wikipedia.org/wiki/12-hour_clock#Confusion_at_noon_and_midnight
* In combodate: * In combodate:
@ -3948,16 +3995,22 @@ $(function(){
this.initCombos(); this.initCombos();
//update original input on change //update original input on change
this.$widget.on('change', 'select', $.proxy(function(){ this.$widget.on('change', 'select', $.proxy(function(e) {
this.$element.val(this.getValue()); 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));
this.$widget.find('select').css('width', 'auto'); 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); this.$element.hide().after(this.$widget);
//set initial value // set initial value
this.setValue(this.$element.val() || this.options.value); this.setValue(this.$element.val() || this.options.value);
}, },
@ -3994,22 +4047,41 @@ $(function(){
Initialize combos that presents in template Initialize combos that presents in template
*/ */
initCombos: function() { initCombos: function() {
var that = this; for (var k in this.map) {
$.each(this.map, function(k, v) { var $c = this.$widget.find('.'+k);
var $c = that.$widget.find('.'+k), f, items; // set properties like this.$day, this.$month etc.
if($c.length) { this['$'+k] = $c.length ? $c : null;
that['$'+k] = $c; //set properties like this.$day, this.$month etc. // fill with items
f = 'fill' + k.charAt(0).toUpperCase() + k.slice(1); //define method name to fill items, e.g `fillDays` this.fillCombo(k);
items = that[f](); }
that['$'+k].html(that.renderItems(items));
}
});
}, },
/*
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 Initialize items of combos. Handles `firstItem` option
*/ */
initItems: function(key) { fillCommon: function(key) {
var values = [], var values = [],
relTime; relTime;
@ -4024,27 +4096,29 @@ $(function(){
values.push(['', '']); values.push(['', '']);
} }
return values; 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 fill day
*/ */
fillDay: function() { fillDay: function() {
var items = this.initItems('d'), name, i, var items = this.fillCommon('d'), name, i,
twoDigit = this.options.template.indexOf('DD') !== -1; twoDigit = this.options.template.indexOf('DD') !== -1,
daysCount = 31;
for(i=1; i<=31; i++) {
// 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; name = twoDigit ? this.leadZero(i) : i;
items.push([i, name]); items.push([i, name]);
} }
@ -4055,7 +4129,7 @@ $(function(){
fill month fill month
*/ */
fillMonth: function() { fillMonth: function() {
var items = this.initItems('M'), name, i, var items = this.fillCommon('M'), name, i,
longNames = this.options.template.indexOf('MMMM') !== -1, longNames = this.options.template.indexOf('MMMM') !== -1,
shortNames = this.options.template.indexOf('MMM') !== -1, shortNames = this.options.template.indexOf('MMM') !== -1,
twoDigit = this.options.template.indexOf('MM') !== -1; twoDigit = this.options.template.indexOf('MM') !== -1;
@ -4088,7 +4162,7 @@ $(function(){
items[this.options.yearDescending ? 'push' : 'unshift']([i, name]); items[this.options.yearDescending ? 'push' : 'unshift']([i, name]);
} }
items = this.initItems('y').concat(items); items = this.fillCommon('y').concat(items);
return items; return items;
}, },
@ -4097,7 +4171,7 @@ $(function(){
fill hour fill hour
*/ */
fillHour: function() { fillHour: function() {
var items = this.initItems('h'), name, i, var items = this.fillCommon('h'), name, i,
h12 = this.options.template.indexOf('h') !== -1, h12 = this.options.template.indexOf('h') !== -1,
h24 = this.options.template.indexOf('H') !== -1, h24 = this.options.template.indexOf('H') !== -1,
twoDigit = this.options.template.toLowerCase().indexOf('hh') !== -1, twoDigit = this.options.template.toLowerCase().indexOf('hh') !== -1,
@ -4115,7 +4189,7 @@ $(function(){
fill minute fill minute
*/ */
fillMinute: function() { fillMinute: function() {
var items = this.initItems('m'), name, i, var items = this.fillCommon('m'), name, i,
twoDigit = this.options.template.indexOf('mm') !== -1; twoDigit = this.options.template.indexOf('mm') !== -1;
for(i=0; i<=59; i+= this.options.minuteStep) { for(i=0; i<=59; i+= this.options.minuteStep) {
@ -4129,7 +4203,7 @@ $(function(){
fill second fill second
*/ */
fillSecond: function() { fillSecond: function() {
var items = this.initItems('s'), name, i, var items = this.fillCommon('s'), name, i,
twoDigit = this.options.template.indexOf('ss') !== -1; twoDigit = this.options.template.indexOf('ss') !== -1;
for(i=0; i<=59; i+= this.options.secondStep) { for(i=0; i<=59; i+= this.options.secondStep) {
@ -4151,7 +4225,7 @@ $(function(){
]; ];
return items; return items;
}, },
/* /*
Returns current date value from combos. Returns current date value from combos.
If format not specified - `options.format` used. If format not specified - `options.format` used.
@ -4214,63 +4288,68 @@ $(function(){
that = this, that = this,
values = {}; values = {};
//function to find nearest value in select options //function to find nearest value in select options
function getNearest($select, value) { function getNearest($select, value) {
var delta = {}; var delta = {};
$select.children('option').each(function(i, opt){ $select.children('option').each(function(i, opt){
var optValue = $(opt).attr('value'), var optValue = $(opt).attr('value'),
distance; distance;
if(optValue === '') return; if(optValue === '') return;
distance = Math.abs(optValue - value); distance = Math.abs(optValue - value);
if(typeof delta.distance === 'undefined' || distance < delta.distance) { if(typeof delta.distance === 'undefined' || distance < delta.distance) {
delta = {value: optValue, distance: distance}; delta = {value: optValue, distance: distance};
} }
}); });
return delta.value; return delta.value;
} }
if(dt.isValid()) { if(dt.isValid()) {
//read values from date object //read values from date object
$.each(this.map, function(k, v) { $.each(this.map, function(k, v) {
if(k === 'ampm') { if(k === 'ampm') {
return; return;
} }
values[k] = dt[v[1]](); values[k] = dt[v[1]]();
}); });
if(this.$ampm) { if(this.$ampm) {
//12:00 pm --> 12:00 (24-h format, midday), 12:00 am --> 00:00 (24-h format, midnight, start of day) //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) { if(values.hour >= 12) {
values.ampm = 'pm'; values.ampm = 'pm';
if(values.hour > 12) { if(values.hour > 12) {
values.hour -= 12; values.hour -= 12;
} }
} else { } else {
values.ampm = 'am'; values.ampm = 'am';
if(values.hour === 0) { if(values.hour === 0) {
values.hour = 12; values.hour = 12;
} }
} }
} }
$.each(values, function(k, v) { $.each(values, function(k, v) {
//call val() for each existing combo, e.g. this.$hour.val() //call val() for each existing combo, e.g. this.$hour.val()
if(that['$'+k]) { if(that['$'+k]) {
if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) { if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) {
v = getNearest(that['$'+k], v); v = getNearest(that['$'+k], v);
} }
if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) { if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) {
v = getNearest(that['$'+k], v); 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, secondStep: 1,
firstItem: 'empty', //'name', 'empty', 'none' firstItem: 'empty', //'name', 'empty', 'none'
errorClass: null, 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)); }(window.jQuery));

File diff suppressed because one or more lines are too long

@ -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. 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. 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) @method submit(options)
@param {object} 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 case 'submit': //collects value, validate and submit to server for creating new record
var config = arguments[1] || {}, var config = arguments[1] || {},
$elems = this, $elems = this,
errors = this.editable('validate'), errors = this.editable('validate');
values;
// validation ok
if($.isEmptyObject(errors)) { if($.isEmptyObject(errors)) {
values = this.editable('getValue'); var ajaxOptions = {};
if(config.data) {
$.extend(values, config.data); // for single element use url, success etc from options
} if($elems.length === 1) {
var editable = $elems.data('editable');
$.ajax($.extend({ //standard params
url: config.url, var params = {
data: values, name: editable.options.name || '',
type: 'POST' value: editable.input.value2submit(editable.value),
}, config.ajaxOptions)) pk: (typeof editable.options.pk === 'function') ?
.success(function(response) { editable.options.pk.call(editable.options.scope) :
//successful response 200 OK editable.options.pk
if(typeof config.success === 'function') { };
config.success.call($elems, response, config);
} //additional params
}) if(typeof editable.options.params === 'function') {
.error(function(){ //ajax error params = editable.options.params.call(editable.options.scope, params);
if(typeof config.error === 'function') { } else {
config.error.apply($elems, arguments); //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 } else { //client-side validation error
if(typeof config.error === 'function') { if(typeof config.error === 'function') {
config.error.call($elems, errors); config.error.call($elems, errors);
@ -3897,11 +3944,11 @@ $(function(){
}(window.jQuery)); }(window.jQuery));
/** /**
* Combodate - 1.0.4 * Combodate - 1.0.5
* Dropdown date and time picker. * Dropdown date and time picker.
* Converts text input into dropdowns to pick day, month, year, hour, minute and second. * Converts text input into dropdowns to pick day, month, year, hour, minute and second.
* Uses momentjs as datetime library http://momentjs.com. * 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 * Confusion at noon and midnight - see http://en.wikipedia.org/wiki/12-hour_clock#Confusion_at_noon_and_midnight
* In combodate: * In combodate:
@ -3948,16 +3995,22 @@ $(function(){
this.initCombos(); this.initCombos();
//update original input on change //update original input on change
this.$widget.on('change', 'select', $.proxy(function(){ this.$widget.on('change', 'select', $.proxy(function(e) {
this.$element.val(this.getValue()); 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));
this.$widget.find('select').css('width', 'auto'); 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); this.$element.hide().after(this.$widget);
//set initial value // set initial value
this.setValue(this.$element.val() || this.options.value); this.setValue(this.$element.val() || this.options.value);
}, },
@ -3994,22 +4047,41 @@ $(function(){
Initialize combos that presents in template Initialize combos that presents in template
*/ */
initCombos: function() { initCombos: function() {
var that = this; for (var k in this.map) {
$.each(this.map, function(k, v) { var $c = this.$widget.find('.'+k);
var $c = that.$widget.find('.'+k), f, items; // set properties like this.$day, this.$month etc.
if($c.length) { this['$'+k] = $c.length ? $c : null;
that['$'+k] = $c; //set properties like this.$day, this.$month etc. // fill with items
f = 'fill' + k.charAt(0).toUpperCase() + k.slice(1); //define method name to fill items, e.g `fillDays` this.fillCombo(k);
items = that[f](); }
that['$'+k].html(that.renderItems(items));
}
});
}, },
/*
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 Initialize items of combos. Handles `firstItem` option
*/ */
initItems: function(key) { fillCommon: function(key) {
var values = [], var values = [],
relTime; relTime;
@ -4024,27 +4096,29 @@ $(function(){
values.push(['', '']); values.push(['', '']);
} }
return values; 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 fill day
*/ */
fillDay: function() { fillDay: function() {
var items = this.initItems('d'), name, i, var items = this.fillCommon('d'), name, i,
twoDigit = this.options.template.indexOf('DD') !== -1; twoDigit = this.options.template.indexOf('DD') !== -1,
daysCount = 31;
for(i=1; i<=31; i++) {
// 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; name = twoDigit ? this.leadZero(i) : i;
items.push([i, name]); items.push([i, name]);
} }
@ -4055,7 +4129,7 @@ $(function(){
fill month fill month
*/ */
fillMonth: function() { fillMonth: function() {
var items = this.initItems('M'), name, i, var items = this.fillCommon('M'), name, i,
longNames = this.options.template.indexOf('MMMM') !== -1, longNames = this.options.template.indexOf('MMMM') !== -1,
shortNames = this.options.template.indexOf('MMM') !== -1, shortNames = this.options.template.indexOf('MMM') !== -1,
twoDigit = this.options.template.indexOf('MM') !== -1; twoDigit = this.options.template.indexOf('MM') !== -1;
@ -4088,7 +4162,7 @@ $(function(){
items[this.options.yearDescending ? 'push' : 'unshift']([i, name]); items[this.options.yearDescending ? 'push' : 'unshift']([i, name]);
} }
items = this.initItems('y').concat(items); items = this.fillCommon('y').concat(items);
return items; return items;
}, },
@ -4097,7 +4171,7 @@ $(function(){
fill hour fill hour
*/ */
fillHour: function() { fillHour: function() {
var items = this.initItems('h'), name, i, var items = this.fillCommon('h'), name, i,
h12 = this.options.template.indexOf('h') !== -1, h12 = this.options.template.indexOf('h') !== -1,
h24 = this.options.template.indexOf('H') !== -1, h24 = this.options.template.indexOf('H') !== -1,
twoDigit = this.options.template.toLowerCase().indexOf('hh') !== -1, twoDigit = this.options.template.toLowerCase().indexOf('hh') !== -1,
@ -4115,7 +4189,7 @@ $(function(){
fill minute fill minute
*/ */
fillMinute: function() { fillMinute: function() {
var items = this.initItems('m'), name, i, var items = this.fillCommon('m'), name, i,
twoDigit = this.options.template.indexOf('mm') !== -1; twoDigit = this.options.template.indexOf('mm') !== -1;
for(i=0; i<=59; i+= this.options.minuteStep) { for(i=0; i<=59; i+= this.options.minuteStep) {
@ -4129,7 +4203,7 @@ $(function(){
fill second fill second
*/ */
fillSecond: function() { fillSecond: function() {
var items = this.initItems('s'), name, i, var items = this.fillCommon('s'), name, i,
twoDigit = this.options.template.indexOf('ss') !== -1; twoDigit = this.options.template.indexOf('ss') !== -1;
for(i=0; i<=59; i+= this.options.secondStep) { for(i=0; i<=59; i+= this.options.secondStep) {
@ -4151,7 +4225,7 @@ $(function(){
]; ];
return items; return items;
}, },
/* /*
Returns current date value from combos. Returns current date value from combos.
If format not specified - `options.format` used. If format not specified - `options.format` used.
@ -4214,63 +4288,68 @@ $(function(){
that = this, that = this,
values = {}; values = {};
//function to find nearest value in select options //function to find nearest value in select options
function getNearest($select, value) { function getNearest($select, value) {
var delta = {}; var delta = {};
$select.children('option').each(function(i, opt){ $select.children('option').each(function(i, opt){
var optValue = $(opt).attr('value'), var optValue = $(opt).attr('value'),
distance; distance;
if(optValue === '') return; if(optValue === '') return;
distance = Math.abs(optValue - value); distance = Math.abs(optValue - value);
if(typeof delta.distance === 'undefined' || distance < delta.distance) { if(typeof delta.distance === 'undefined' || distance < delta.distance) {
delta = {value: optValue, distance: distance}; delta = {value: optValue, distance: distance};
} }
}); });
return delta.value; return delta.value;
} }
if(dt.isValid()) { if(dt.isValid()) {
//read values from date object //read values from date object
$.each(this.map, function(k, v) { $.each(this.map, function(k, v) {
if(k === 'ampm') { if(k === 'ampm') {
return; return;
} }
values[k] = dt[v[1]](); values[k] = dt[v[1]]();
}); });
if(this.$ampm) { if(this.$ampm) {
//12:00 pm --> 12:00 (24-h format, midday), 12:00 am --> 00:00 (24-h format, midnight, start of day) //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) { if(values.hour >= 12) {
values.ampm = 'pm'; values.ampm = 'pm';
if(values.hour > 12) { if(values.hour > 12) {
values.hour -= 12; values.hour -= 12;
} }
} else { } else {
values.ampm = 'am'; values.ampm = 'am';
if(values.hour === 0) { if(values.hour === 0) {
values.hour = 12; values.hour = 12;
} }
} }
} }
$.each(values, function(k, v) { $.each(values, function(k, v) {
//call val() for each existing combo, e.g. this.$hour.val() //call val() for each existing combo, e.g. this.$hour.val()
if(that['$'+k]) { if(that['$'+k]) {
if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) { if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) {
v = getNearest(that['$'+k], v); v = getNearest(that['$'+k], v);
} }
if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) { if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) {
v = getNearest(that['$'+k], v); 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, secondStep: 1,
firstItem: 'empty', //'name', 'empty', 'none' firstItem: 'empty', //'name', 'empty', 'none'
errorClass: null, 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)); }(window.jQuery));

File diff suppressed because one or more lines are too long

@ -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. 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. 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) @method submit(options)
@param {object} 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 case 'submit': //collects value, validate and submit to server for creating new record
var config = arguments[1] || {}, var config = arguments[1] || {},
$elems = this, $elems = this,
errors = this.editable('validate'), errors = this.editable('validate');
values;
// validation ok
if($.isEmptyObject(errors)) { if($.isEmptyObject(errors)) {
values = this.editable('getValue'); var ajaxOptions = {};
if(config.data) {
$.extend(values, config.data); // for single element use url, success etc from options
} if($elems.length === 1) {
var editable = $elems.data('editable');
$.ajax($.extend({ //standard params
url: config.url, var params = {
data: values, name: editable.options.name || '',
type: 'POST' value: editable.input.value2submit(editable.value),
}, config.ajaxOptions)) pk: (typeof editable.options.pk === 'function') ?
.success(function(response) { editable.options.pk.call(editable.options.scope) :
//successful response 200 OK editable.options.pk
if(typeof config.success === 'function') { };
config.success.call($elems, response, config);
} //additional params
}) if(typeof editable.options.params === 'function') {
.error(function(){ //ajax error params = editable.options.params.call(editable.options.scope, params);
if(typeof config.error === 'function') { } else {
config.error.apply($elems, arguments); //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 } else { //client-side validation error
if(typeof config.error === 'function') { if(typeof config.error === 'function') {
config.error.call($elems, errors); config.error.call($elems, errors);
@ -3897,11 +3944,11 @@ $(function(){
}(window.jQuery)); }(window.jQuery));
/** /**
* Combodate - 1.0.4 * Combodate - 1.0.5
* Dropdown date and time picker. * Dropdown date and time picker.
* Converts text input into dropdowns to pick day, month, year, hour, minute and second. * Converts text input into dropdowns to pick day, month, year, hour, minute and second.
* Uses momentjs as datetime library http://momentjs.com. * 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 * Confusion at noon and midnight - see http://en.wikipedia.org/wiki/12-hour_clock#Confusion_at_noon_and_midnight
* In combodate: * In combodate:
@ -3948,16 +3995,22 @@ $(function(){
this.initCombos(); this.initCombos();
//update original input on change //update original input on change
this.$widget.on('change', 'select', $.proxy(function(){ this.$widget.on('change', 'select', $.proxy(function(e) {
this.$element.val(this.getValue()); 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));
this.$widget.find('select').css('width', 'auto'); 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); this.$element.hide().after(this.$widget);
//set initial value // set initial value
this.setValue(this.$element.val() || this.options.value); this.setValue(this.$element.val() || this.options.value);
}, },
@ -3994,22 +4047,41 @@ $(function(){
Initialize combos that presents in template Initialize combos that presents in template
*/ */
initCombos: function() { initCombos: function() {
var that = this; for (var k in this.map) {
$.each(this.map, function(k, v) { var $c = this.$widget.find('.'+k);
var $c = that.$widget.find('.'+k), f, items; // set properties like this.$day, this.$month etc.
if($c.length) { this['$'+k] = $c.length ? $c : null;
that['$'+k] = $c; //set properties like this.$day, this.$month etc. // fill with items
f = 'fill' + k.charAt(0).toUpperCase() + k.slice(1); //define method name to fill items, e.g `fillDays` this.fillCombo(k);
items = that[f](); }
that['$'+k].html(that.renderItems(items));
}
});
}, },
/*
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 Initialize items of combos. Handles `firstItem` option
*/ */
initItems: function(key) { fillCommon: function(key) {
var values = [], var values = [],
relTime; relTime;
@ -4024,27 +4096,29 @@ $(function(){
values.push(['', '']); values.push(['', '']);
} }
return values; 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 fill day
*/ */
fillDay: function() { fillDay: function() {
var items = this.initItems('d'), name, i, var items = this.fillCommon('d'), name, i,
twoDigit = this.options.template.indexOf('DD') !== -1; twoDigit = this.options.template.indexOf('DD') !== -1,
daysCount = 31;
for(i=1; i<=31; i++) {
// 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; name = twoDigit ? this.leadZero(i) : i;
items.push([i, name]); items.push([i, name]);
} }
@ -4055,7 +4129,7 @@ $(function(){
fill month fill month
*/ */
fillMonth: function() { fillMonth: function() {
var items = this.initItems('M'), name, i, var items = this.fillCommon('M'), name, i,
longNames = this.options.template.indexOf('MMMM') !== -1, longNames = this.options.template.indexOf('MMMM') !== -1,
shortNames = this.options.template.indexOf('MMM') !== -1, shortNames = this.options.template.indexOf('MMM') !== -1,
twoDigit = this.options.template.indexOf('MM') !== -1; twoDigit = this.options.template.indexOf('MM') !== -1;
@ -4088,7 +4162,7 @@ $(function(){
items[this.options.yearDescending ? 'push' : 'unshift']([i, name]); items[this.options.yearDescending ? 'push' : 'unshift']([i, name]);
} }
items = this.initItems('y').concat(items); items = this.fillCommon('y').concat(items);
return items; return items;
}, },
@ -4097,7 +4171,7 @@ $(function(){
fill hour fill hour
*/ */
fillHour: function() { fillHour: function() {
var items = this.initItems('h'), name, i, var items = this.fillCommon('h'), name, i,
h12 = this.options.template.indexOf('h') !== -1, h12 = this.options.template.indexOf('h') !== -1,
h24 = this.options.template.indexOf('H') !== -1, h24 = this.options.template.indexOf('H') !== -1,
twoDigit = this.options.template.toLowerCase().indexOf('hh') !== -1, twoDigit = this.options.template.toLowerCase().indexOf('hh') !== -1,
@ -4115,7 +4189,7 @@ $(function(){
fill minute fill minute
*/ */
fillMinute: function() { fillMinute: function() {
var items = this.initItems('m'), name, i, var items = this.fillCommon('m'), name, i,
twoDigit = this.options.template.indexOf('mm') !== -1; twoDigit = this.options.template.indexOf('mm') !== -1;
for(i=0; i<=59; i+= this.options.minuteStep) { for(i=0; i<=59; i+= this.options.minuteStep) {
@ -4129,7 +4203,7 @@ $(function(){
fill second fill second
*/ */
fillSecond: function() { fillSecond: function() {
var items = this.initItems('s'), name, i, var items = this.fillCommon('s'), name, i,
twoDigit = this.options.template.indexOf('ss') !== -1; twoDigit = this.options.template.indexOf('ss') !== -1;
for(i=0; i<=59; i+= this.options.secondStep) { for(i=0; i<=59; i+= this.options.secondStep) {
@ -4151,7 +4225,7 @@ $(function(){
]; ];
return items; return items;
}, },
/* /*
Returns current date value from combos. Returns current date value from combos.
If format not specified - `options.format` used. If format not specified - `options.format` used.
@ -4214,63 +4288,68 @@ $(function(){
that = this, that = this,
values = {}; values = {};
//function to find nearest value in select options //function to find nearest value in select options
function getNearest($select, value) { function getNearest($select, value) {
var delta = {}; var delta = {};
$select.children('option').each(function(i, opt){ $select.children('option').each(function(i, opt){
var optValue = $(opt).attr('value'), var optValue = $(opt).attr('value'),
distance; distance;
if(optValue === '') return; if(optValue === '') return;
distance = Math.abs(optValue - value); distance = Math.abs(optValue - value);
if(typeof delta.distance === 'undefined' || distance < delta.distance) { if(typeof delta.distance === 'undefined' || distance < delta.distance) {
delta = {value: optValue, distance: distance}; delta = {value: optValue, distance: distance};
} }
}); });
return delta.value; return delta.value;
} }
if(dt.isValid()) { if(dt.isValid()) {
//read values from date object //read values from date object
$.each(this.map, function(k, v) { $.each(this.map, function(k, v) {
if(k === 'ampm') { if(k === 'ampm') {
return; return;
} }
values[k] = dt[v[1]](); values[k] = dt[v[1]]();
}); });
if(this.$ampm) { if(this.$ampm) {
//12:00 pm --> 12:00 (24-h format, midday), 12:00 am --> 00:00 (24-h format, midnight, start of day) //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) { if(values.hour >= 12) {
values.ampm = 'pm'; values.ampm = 'pm';
if(values.hour > 12) { if(values.hour > 12) {
values.hour -= 12; values.hour -= 12;
} }
} else { } else {
values.ampm = 'am'; values.ampm = 'am';
if(values.hour === 0) { if(values.hour === 0) {
values.hour = 12; values.hour = 12;
} }
} }
} }
$.each(values, function(k, v) { $.each(values, function(k, v) {
//call val() for each existing combo, e.g. this.$hour.val() //call val() for each existing combo, e.g. this.$hour.val()
if(that['$'+k]) { if(that['$'+k]) {
if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) { if(k === 'minute' && that.options.minuteStep > 1 && that.options.roundTime) {
v = getNearest(that['$'+k], v); v = getNearest(that['$'+k], v);
} }
if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) { if(k === 'second' && that.options.secondStep > 1 && that.options.roundTime) {
v = getNearest(that['$'+k], v); 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, secondStep: 1,
firstItem: 'empty', //'name', 'empty', 'none' firstItem: 'empty', //'name', 'empty', 'none'
errorClass: null, 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)); }(window.jQuery));

File diff suppressed because one or more lines are too long