mybuddy/babybuddy/static_src/js/babybuddy.js

79 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-10-22 18:00:42 +00:00
if (typeof jQuery === 'undefined') {
throw new Error('Baby Buddy requires jQuery.')
}
2020-01-27 22:56:37 +00:00
if (typeof moment === 'undefined') {
throw new Error('Baby Buddy requires moment.js.')
}
2017-10-22 18:00:42 +00:00
2020-01-27 22:56:37 +00:00
/**
* Baby Buddy Namespace
*
* Default namespace for the Baby Buddy app.
2020-02-04 18:52:05 +00:00
*
* @type {{}}
2020-01-27 22:56:37 +00:00
*/
2017-10-22 18:00:42 +00:00
var BabyBuddy = function () {
2020-01-27 22:56:37 +00:00
return {};
2017-10-22 18:00:42 +00:00
}();
2020-01-27 22:56:37 +00:00
/**
2020-02-04 18:52:05 +00:00
* Datetime Picker.
2020-01-27 22:56:37 +00:00
*
* Provides modifications and defaults for the base datetime picker widget.
2020-02-04 18:52:05 +00:00
*
* @type {{init: BabyBuddy.DatetimePicker.init}}
2020-01-27 22:56:37 +00:00
*/
BabyBuddy.DatetimePicker = function ($, moment) {
return {
init: function (element, options) {
var defaultOptions = {
allowInputToggle: true,
buttons: { showToday: true, showClose: true },
2020-01-27 22:56:37 +00:00
defaultDate: 'now',
format: 'L LT',
ignoreReadonly: true,
locale: moment.locale(),
useCurrent: false,
icons: {
time: 'icon-clock',
date: 'icon-calendar',
up: 'icon-arrow-up',
down: 'icon-arrow-down',
previous: 'icon-angle-circled-left',
next: 'icon-angle-circled-right',
today: 'icon-today',
clear: 'icon-delete',
close: 'icon-cancel'
},
2020-01-27 22:56:37 +00:00
};
element.datetimepicker($.extend(defaultOptions, options));
}
};
}(jQuery, moment);
2020-02-04 18:52:05 +00:00
/**
* Pull to refresh.
*
* @type {{init: BabyBuddy.PullToRefresh.init, onRefresh: BabyBuddy.PullToRefresh.onRefresh}}
*/
BabyBuddy.PullToRefresh = function(ptr) {
return {
init: function () {
ptr.init({
mainElement: 'body',
onRefresh: this.onRefresh
});
},
onRefresh: function() {
window.location.reload();
}
};
}(PullToRefresh);
/**
* Fix for duplicate form submission from double pressing submit
*/
$("form").on("submit", function() {
$(this).find("button[type='submit']").prop('disabled', true);
});