2015-05-24 18:52:23 +02:00
|
|
|
Liberapay.init = function() {
|
2015-06-04 10:49:46 +02:00
|
|
|
Liberapay.forms.jsSubmit();
|
2015-09-23 16:14:00 +02:00
|
|
|
|
|
|
|
var success_re = /([?&])success=[^&]*/;
|
|
|
|
if (success_re.test(location.search)) {
|
|
|
|
history.replaceState(null, null,
|
|
|
|
location.pathname+
|
|
|
|
location.search.replace(success_re, '$1').replace(/[\?&]$/, '')+
|
|
|
|
location.hash
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$('.notification .close').click(function(){ $(this).parent().fadeOut() });
|
2015-10-01 17:49:51 +02:00
|
|
|
|
2018-01-09 18:47:12 +01:00
|
|
|
Liberapay.auto_tail_log();
|
2018-01-09 18:31:36 +01:00
|
|
|
Liberapay.charts.init();
|
2015-10-01 17:49:51 +02:00
|
|
|
Liberapay.lookup.init();
|
2018-01-10 13:03:26 +01:00
|
|
|
Liberapay.s3_uploader_init();
|
2018-07-23 11:15:16 +02:00
|
|
|
Liberapay.stripe_init();
|
2016-02-28 23:21:47 +01:00
|
|
|
|
2020-05-15 11:33:18 +02:00
|
|
|
$('div[href]').css('cursor', 'pointer').on('click auxclick', function(event) {
|
|
|
|
if (event.target.tagName == 'A') {
|
|
|
|
// Ignore clicks on links
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (event.button == 2) {
|
|
|
|
// Ignore right clicks
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
var url = this.getAttribute('href');
|
|
|
|
if (event.type == 'click' && event.ctrlKey ||
|
|
|
|
event.type == 'auxclick' && event.button == 1) {
|
|
|
|
window.open(url);
|
2020-05-14 22:00:13 -03:00
|
|
|
} else {
|
|
|
|
location.href = url;
|
|
|
|
}
|
2016-02-28 23:21:47 +01:00
|
|
|
});
|
2016-02-29 16:44:10 +01:00
|
|
|
|
2020-05-28 11:38:53 +02:00
|
|
|
$('.dropdown.dropdown-hover').removeClass('dropdown-hover');
|
2016-03-01 16:32:23 +01:00
|
|
|
|
|
|
|
$('.dropdown-toggle-form').click(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
setTimeout(function() {
|
|
|
|
$this.siblings('.dropdown-menu').find('input').eq(0).focus();
|
|
|
|
}, 10);
|
|
|
|
});
|
2016-03-01 16:36:02 +01:00
|
|
|
|
2017-01-29 11:24:44 +01:00
|
|
|
var grid_float_breakpoint = 768;
|
|
|
|
$('.navbar-nav > li > .dropdown-toggle').click(function(e) {
|
|
|
|
if ($('html').width() < grid_float_breakpoint) {
|
|
|
|
$('.navbar-collapse').collapse('hide');
|
2016-03-01 16:36:02 +01:00
|
|
|
}
|
|
|
|
});
|
2016-03-01 22:43:39 +01:00
|
|
|
|
2020-06-30 10:21:33 +02:00
|
|
|
$('input[data-required-if-checked]').each(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
var $requirer = $($this.attr('data-required-if-checked'));
|
|
|
|
$this.parents('form').find('input').on('change', function() {
|
|
|
|
$this.prop('required', $requirer.prop('checked'));
|
2020-06-24 13:12:24 -04:00
|
|
|
});
|
2020-06-30 10:29:34 +02:00
|
|
|
$requirer.trigger('change');
|
2020-06-24 13:12:24 -04:00
|
|
|
});
|
2016-03-14 10:53:02 +01:00
|
|
|
|
|
|
|
$('[data-toggle="tooltip"]').tooltip();
|
2017-04-11 09:38:03 +02:00
|
|
|
|
2020-08-05 09:09:15 +02:00
|
|
|
$('.radio input:not([type="radio"]), .radio-group input:not([type="radio"])').on('click change', function(event) {
|
|
|
|
if (event.type == 'click' && event.clientX == 0 && event.clientY == 0) {
|
|
|
|
return // This click event seems to be fake
|
|
|
|
} else if (event.type != 'click' && this.value == '') {
|
|
|
|
return // Don't act on non-click events when the <input> is empty
|
|
|
|
}
|
2020-06-24 13:12:24 -04:00
|
|
|
$(this).parents('label').children('input[type="radio"]').prop('checked', true).trigger('change');
|
2017-06-02 10:12:50 +02:00
|
|
|
});
|
2020-08-05 09:09:15 +02:00
|
|
|
$('.radio-group .list-group-item > label').on('click', function(event) {
|
|
|
|
if (event.clientX == 0 && event.clientY == 0) {
|
|
|
|
return // This click event seems to be fake
|
|
|
|
}
|
2020-06-24 13:12:24 -04:00
|
|
|
$(this).children('input[type="radio"]').prop('checked', true).trigger('change');
|
2017-04-11 09:38:03 +02:00
|
|
|
});
|
2017-07-19 14:08:33 +02:00
|
|
|
|
2024-12-12 13:55:07 +01:00
|
|
|
$('[data-toggle="enable"], [data-toggle="disable"]').each(function() {
|
|
|
|
var enable = this.getAttribute('data-toggle') == 'enable';
|
|
|
|
var $target = $(this.getAttribute('data-target'));
|
|
|
|
var $control = $(this);
|
|
|
|
(this.tagName == 'OPTION' ? $control.parent() : $control).on('change', function() {
|
|
|
|
var disable = enable ^ ($control.prop('checked') || $control.prop('selected'));
|
|
|
|
$target.prop('disabled', disable);
|
|
|
|
$target.find('input[type="checkbox"]').each(function() {
|
|
|
|
var $subelement = $(this);
|
|
|
|
if (disable) {
|
|
|
|
$subelement.data('was-checked', $subelement.prop('checked'));
|
|
|
|
$subelement.prop('checked', false);
|
|
|
|
} else {
|
|
|
|
$subelement.prop('checked', $subelement.data('was-checked'));
|
|
|
|
}
|
|
|
|
$subelement.prop('disabled', disable);
|
2023-09-25 10:16:22 +02:00
|
|
|
});
|
2024-12-12 13:55:07 +01:00
|
|
|
});
|
2017-07-19 14:08:33 +02:00
|
|
|
});
|
2018-01-10 20:28:04 +01:00
|
|
|
|
|
|
|
$('[data-email]').one('mouseover click', function () {
|
|
|
|
$(this).attr('href', 'mailto:'+$(this).data('email'));
|
|
|
|
});
|
|
|
|
$('[data-email-reveal]').one('click', function () {
|
|
|
|
$(this).html($(this).data('email-reveal'));
|
|
|
|
});
|
2018-11-18 14:48:32 +01:00
|
|
|
|
|
|
|
$('button[data-action="reload"]').on('click', function() {
|
|
|
|
location.reload();
|
|
|
|
});
|
2013-06-01 02:11:17 -04:00
|
|
|
};
|
2013-06-28 16:53:57 -04:00
|
|
|
|
2024-10-13 15:15:36 +02:00
|
|
|
$(function(){
|
|
|
|
try {
|
|
|
|
Liberapay.init();
|
|
|
|
} catch (exc) {
|
|
|
|
Liberapay.error(exc);
|
|
|
|
}
|
|
|
|
});
|
2018-01-09 11:04:04 +01:00
|
|
|
|
2024-05-31 11:26:27 +02:00
|
|
|
Liberapay.error = function(exc) {
|
|
|
|
console.error(exc);
|
|
|
|
var msg = "An error occurred (" + exc + ").\n" +
|
2015-05-24 18:52:23 +02:00
|
|
|
"Please contact support@liberapay.com if the problem persists.";
|
|
|
|
Liberapay.notification(msg, 'error', -1);
|
2015-03-02 14:50:42 +01:00
|
|
|
}
|
|
|
|
|
2024-05-31 11:26:27 +02:00
|
|
|
Liberapay.get_object_by_name = function(name) {
|
|
|
|
return name.split('.').reduce(function(o, k) {return o[k]}, window);
|
|
|
|
}
|
|
|
|
|
2015-05-24 18:52:23 +02:00
|
|
|
Liberapay.jsonml = function(jsonml) {
|
2015-05-31 11:34:06 +02:00
|
|
|
var node = document.createElement(jsonml[0]);
|
2013-06-28 16:53:57 -04:00
|
|
|
|
2015-05-31 11:34:06 +02:00
|
|
|
jQuery.each(jsonml, function(j, v) {
|
2013-06-28 16:53:57 -04:00
|
|
|
if (j === 0 || typeof v === 'undefined') return;
|
|
|
|
|
|
|
|
switch (v.constructor) {
|
|
|
|
case Object:
|
|
|
|
for (var p in v)
|
|
|
|
node.setAttribute(p, v[p]);
|
|
|
|
break;
|
|
|
|
|
2015-05-31 11:34:06 +02:00
|
|
|
case Array: node.appendChild(Liberapay.jsonml(v)); break;
|
2013-06-28 16:53:57 -04:00
|
|
|
|
2020-09-27 10:15:37 +02:00
|
|
|
default: node.appendChild(document.createTextNode(v.toString())); break;
|
2013-06-28 16:53:57 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return node;
|
|
|
|
};
|