forked from CGM_Public/pretix_original
* Vendor vue.js * Refactor item_group_by_category to support vouchers * Widget: Show product list * Widget: free prices * Widget: pictures and loading indicator * Widget: First iframe steps * Widget: Do not rerender iframe * Widget: Error handling * Improve widget * Widget: localization tech * Fix invoice style * Voucher attribute and waiting list * Add some iframe chrome * First step to namespaced carts * More isolation steps * More cart isolation things * More cart isolation things * Mobile stuff * Show cart on checkout pages * PayPal and Stripe support * Enable downloads * Locale handling * change text "save URL to this exact page" * Widget: voucher redemption * Widget: CSS * CSS: Responsive * Widget: CSS improvements * Widget: Add embedding code generator * Widget: Error messages and SSL check * First tests * Widget: tests * Don't use IDs in widgets * Widget: static files caching
This commit is contained in:
@@ -1,33 +1,45 @@
|
||||
/*global $,gettext,ngettext */
|
||||
|
||||
var cart = {
|
||||
_deadline: null,
|
||||
_deadline_interval: null,
|
||||
_deadline_call: 0,
|
||||
|
||||
draw_deadline: function () {
|
||||
function pad(n, width, z) {
|
||||
z = z || '0';
|
||||
n = n + '';
|
||||
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
|
||||
}
|
||||
|
||||
cart._deadline_call++;
|
||||
if ((typeof django === 'undefined' || typeof django.gettext === 'undefined') && cart._deadline_call < 5) {
|
||||
// Language files are not loaded yet, don't run during the first seconds
|
||||
return;
|
||||
}
|
||||
var diff = Math.floor(cart._deadline.diff(moment()) / 1000 / 60);
|
||||
if (diff < 0) {
|
||||
var diff_minutes = Math.floor(cart._deadline.diff(moment()) / 1000 / 60);
|
||||
var diff_seconds = Math.floor(cart._deadline.diff(moment()) / 1000 % 60);
|
||||
if (diff_minutes < 0) {
|
||||
$("#cart-deadline").text(gettext("The items in your cart are no longer reserved for you."));
|
||||
$("#cart-deadline-short").text(
|
||||
gettext("Cart expired")
|
||||
);
|
||||
window.clearInterval(cart._deadline_interval);
|
||||
} else {
|
||||
$("#cart-deadline").text(ngettext(
|
||||
"The items in your cart are reserved for you for one minute.",
|
||||
"The items in your cart are reserved for you for {num} minutes.",
|
||||
diff
|
||||
).replace(/\{num\}/g, diff));
|
||||
diff_minutes
|
||||
).replace(/\{num\}/g, diff_minutes));
|
||||
$("#cart-deadline-short").text(
|
||||
pad(diff_minutes.toString(), 2) + ':' + pad(diff_seconds.toString(), 2)
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
init: function () {
|
||||
"use strict";
|
||||
cart._deadline = moment($("#cart-deadline").attr("data-expires"));
|
||||
cart._deadline_interval = window.setInterval(cart.draw_deadline, 2000);
|
||||
cart._deadline_interval = window.setInterval(cart.draw_deadline, 500);
|
||||
cart.draw_deadline();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user