Add campaign custom dimension to donation form.
[wolnelektury.git] / src / club / static / club / form.js
1 $(function() {
2
3     function update_methods() {
4         $("#payment-form .payment-method").addClass("disabled");
5         $("#payment-form .payment-method input").prop("disabled", true);
6         var plan = $("#payment-form .plan:checked");
7         if (plan.length) {
8             $.each(
9                 $("#payment-form .plan:checked").attr('data-methods').trim().split(" "),
10                 function(i, slug) {
11                     $("#payment-method-" + slug).removeClass("disabled");
12                     $("#payment-method-" + slug + " input").prop("disabled", false);
13                 }
14             );
15         }
16     }
17     update_methods();
18     $("#payment-form .plan").change(update_methods);
19
20
21     function qs(key) {
22         key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&"); // escape RegEx meta chars
23         var match = location.search.match(new RegExp("[?&]"+key+"=([^&]+)(&|$)"));
24         return match && decodeURIComponent(match[1].replace(/\+/g, " "));
25     }
26
27     $("#payment-form").submit(function() {
28         let camp = qs('pk_campaign');
29         if (!camp && window.location.pathname !== "/towarzystwo/") {
30             camp = window.location.pathname;
31         }
32         let dims = camp ? {dimension2: camp} : {};
33         _paq.push(['trackGoal', 12, parseFloat($("#id_amount").val()), dims]);
34     });
35 });