| | |
| | | window.showToast = function(message, type='success', actions={}){ |
| | | window.jvbNotifications.showToast(message, type, actions); |
| | | } |
| | | window.dateFormatter = new Intl.DateTimeFormat('en-CA', { |
| | | year: 'numeric', |
| | | month: 'long', |
| | | day: 'numeric', |
| | | hour: '2-digit', |
| | | minute: '2-digit', |
| | | second: '2-digit', |
| | | timeZoneName: 'short' |
| | | }); |
| | | |
| | | window.formatDate = function(date) { |
| | | if (!(date instanceof Date && !isNaN(date))) { |
| | | date = new Date(date); |
| | | } |
| | | return window.dateFormatter.format(date); |
| | | } |
| | | |
| | | /** |
| | | * Outputs the set text as if a typewriter were writing it |
| | |
| | | |
| | | schedule(key, callback, delay = 1000) { |
| | | this.cancel(key); |
| | | console.log('Scheduling action: ', key); |
| | | console.log('With callback', callback); |
| | | this.timeouts.set(key, setTimeout(() => { |
| | | callback(); |
| | | this.timeouts.delete(key); |
| | |
| | | |
| | | cancel(key) { |
| | | if (this.timeouts.has(key)) { |
| | | console.log('Cancelling ', key); |
| | | clearTimeout(this.timeouts.get(key)); |
| | | this.timeouts.delete(key); |
| | | } |
| | |
| | | |
| | | cleanup() { |
| | | for (let timeout of this.timeouts.values()) { |
| | | console.log('clearing timeout: ', timeout); |
| | | clearTimeout(timeout); |
| | | } |
| | | this.timeouts.clear(); |