-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrJS.js
464 lines (447 loc) · 19.1 KB
/
drJS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
//Declare app url
var redirectDomain = "https://script.google.com/macros/s/AKfycbzICEw1n1BrsBsCgPMDL1VQ7bS9ka7O49s1pS4zkTLbM4g_CRNr/exec";
//Declare all the response codes in an array
var responseCodes = ["1F4", "3F8", "5DC", "7D0", "9C4", "BB8", "6D6", "FA0", "DAC"];
/* Transaction */
//Flag initialization
window.perkTokenBeenCalled = false;
window.perkButtonEnd = false;
window.perkToggleState = null;
//Capitalizes first letter, lower case the rest
function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
//Closes spinner while waiting stripe charge information
function closeWaitDiv(id) {
id = "#" + id;
$(id).hide();
}
//Resets perk with ID blocks to the initial state
function perkBlocksReset(id) {
$("#" + id).find(".perkCustomDonationAmount").hide();
$("#" + id).find(".perkPostFlight").hide();
$("#" + id).find(".perkCustomButton").hide();
$("#" + id).find(".perkBody").css("border-bottom", "none");
$("#" + id).find(".perkToggle").css("pointer-events", "none");
}
// Close Checkout on page navigation
$(window).on('popstate', function() {
handler.close();
});
//checks if user has closed stripe window before submit
$(document).on("DOMNodeRemoved", ".stripe_checkout_app", close);
//Stripe declaration
var handler = StripeCheckout.configure({
key: 'pk_test_AfqpiD3DBLtXD8u39JwGErf8',
image: 'https://estonoesunaescuela.squarespace.com/s/anagrama_peq_color_whitebckgrnd_small.png',
locale: 'auto',
currency: "EUR",
panelLabel: "Dona {{amount}}",
allowRememberMe: "false",
receipt_email: window.eneueSupporterEmail,
token: function(token, args) {
window.perkTokenBeenCalled = true;
var Query = "stripeEmail=" + token.email + "&stripeToken=" + token.id + "&amount=" + window.amountCents + "&itemID=" + window.perkCode + "&localizer=" + window.eneueTransactionLocalizer;
var eQuery = window.btoa(unescape(encodeURIComponent(Query)));
var Query = {
e: eQuery
};
var request = $.ajax({
type: 'get',
url: redirectDomain,
jsonpCallback: 'callback',
contentType: "application/json",
dataType: 'jsonp',
data: Query
});
//Show Ajax spinner
$('.perkWait').show();
$('.eneuePerks').hide();
request.done(function(resultJson) {
//Hide Ajax spinner
$('.perkWait').hide();
//Check if lock has been acquired
var date = new Date();
var n = date.toLocaleDateString();
var t = date.toLocaleTimeString();
var now = "El día " + n + " a las " + t;
var beenLocked = false;
if(resultJson.responsecode == responseCodes[8]){
beenLocked = true;
}
if (beenHacked) {
$('.eneueSuccessAjax').html('Se ha producido un error en el servidor. Inténtelo más tarde.');
} else if (beenLocked) {
$('.eneueSuccessAjax').html('El servidor está ocupado en este momento. Vuelve a intentarlo en un minuto.');
}
else {
window.amountR = resultJson.amount / 100;
window.last4 = resultJson.last4;
window.eMail = resultJson.eMail;
window.localizer = resultJson.localizer;
$('.eneueSuccessAjax').find(".perkAmountShow").html(window.amountR);
$('.eneueSuccessAjax').find(".perkUlt4Show").html(window.last4);
$('.eneueSuccessAjax').find(".perkEmailShow").html(window.eMail);
$('.eneueSuccessAjax').find(".perkLocalizerShow").html(window.localizer);
$('.eneueSuccessAjax').find(".perkDate").html(now);
var chain = "<br>No has concursado en la rifa";
window.perkTokenBeenCalled = false;
window.perkButtonEnd = true;
window.beenShared = false;
$('.eneueSuccessAjax').show();
}
});
}
});
//When clicking on perk selection
$(document).on('click', '.perkRadio', function(e) {
$(".perkSend").hide();
$(".perkPostFlight").hide();
$(".perkCustomButton").hide();
$(".perkBody").css("border-bottom", "none");
window.containerID = e.currentTarget.attributes._parent.value;
$("#" + window.containerID).siblings().css("border", "none");
$("#" + window.containerID).siblings().css("box-shadow", "none");
$("#" + window.containerID).css("border", "2px solid #AB0096");
$("#" + window.containerID).css("box-shadow", "2px 2px 8px 1px #766896");
$("#" + window.containerID).find(".perkCustomDonationAmount").on('input', function() {
var amount = $(this).val();
});
window.amount = $("#" + window.containerID).find(".perkCustomDonationAmount").val();
$(".perkContenedor").css("height", "auto");
$("#" + window.containerID).find(".perkCustomButton").html("Continuar");
$("#" + window.containerID).find(".perkBody").css("border-bottom", "dashed 1px lightgrey");
$("#" + window.containerID).find(".perkCustomDonationAmount").css("display", "block");
$("#" + window.containerID).find(".perkCustomButton").show();
$("#" + window.containerID).find(".perkCustomDonationAmount").show();
$("#" + window.containerID).find(".perkSend").show();
$("#" + window.containerID).find(".perkPreFlight").show();
});
//When clicking on pay button
$(document).on('click', '.perkCustomButton', function(e) {
var perkRoot = window.containerID;
perkRoot = perkRoot.replace('div', '');
var inputBoxId = $("#" + window.containerID).find(".perkCustomDonationAmount").attr("id");
var inputBoxMin = parseInt($("#" + window.containerID).find(".perkCustomDonationAmount").attr("min"), 10);
if (parseInt($("#" + inputBoxId).val(), 10) < inputBoxMin) {
$("#" + inputBoxId).val(inputBoxMin);
}
if (window.perkButtonEnd == false) {
window.amount = $("#" + window.containerID).find(".perkCustomDonationAmount").val();
window.amountCents = window.amount * 100;
window.perkCode = $("#" + window.containerID).attr("name");
window.perkDescription = $('#' + window.containerID).find('span#span' + perkRoot + 'Description').text();
handler.open({
name: '@noesunaescuela',
description: window.perkDescription,
amount: window.amountCents
});
} else if (window.perkButtonEnd == true) {
perkBlocksReset(window.containerID);
window.perkButtonEnd = false;
}
});
$(document).ready(function() {
//Asigna atributo "name" a todos los campos para que lo pueda interceptar serialize
var names = ["nombre", "apellidos", "DNI", "creditos", "dir1", "dir2", "ciudad", "cp"];
//Esconde el segundo formulario
$("#block-yui_3_17_2_21_1454415124886_5895").hide();
//Esconde el botón de recargar
$("#block-yui_3_17_2_2_1455033745983_13062").hide();
//Esconde el botón de mostrar formulario 2
$("#block-yui_3_17_2_2_1456637596700_7472").hide();
//Hide html sections that shouldn't be visible on load
$(".updateFormContainer").hide();
$(".updateFormNoData").hide();
$(".eneueContributionData").hide();
$(".eneuePerks").hide();
$(".eneueUpdatedData").hide();
//Asigna atributo "name" al campo "localizer" para que lo pueda interceptar serialize
$("#block-yui_3_17_2_22_1454415124886_463220").find("form").find("input.text").attr('name', 'localizer');
//Intercepta los datos enviados desde el primer formulario
$("#block-yui_3_17_2_22_1454415124886_463220").find("form").submit(function(e, data) {
$theForm = $(this);
window.updateCustomerData = $theForm.serialize();
});
$("#block-yui_3_17_2_21_1454415124886_5895").find("form").find("input.text").each(function(i) {
$(this).attr('name', names[i])
});
//Intercepta los datos enviados desde el segundo formulario
$("#block-yui_3_17_2_21_1454415124886_5895").find("form").submit(function(e, data) {
$theForm = $(this);
window.updateCustomerDataQuery = $theForm.serialize();
});
//End of Document Ready
});
//Cuando se pulsa el botón con id @block-yui_3_17_2_2_1455033745983_13062 se recarga la página en el navegador
$("#block-yui_3_17_2_2_1455033745983_13062").find("a").click(function(e) {
e.preventDefault();
location.reload(true);
});
//Clicking on this button shows form 2 and present data id="block-yui_3_17_2_2_1456637596700_7472"
$("#block-yui_3_17_2_2_1456637596700_7472").find("a").click(function(e) {
e.preventDefault();
$("#block-yui_3_17_2_21_1454415124886_5895").show();
$(".eneueContributionData").show();
$(".eneueUpdatedData").show();
$("#block-yui_3_17_2_2_1456637596700_7472").hide();
});
//Filtering function. Filters @arr considering @criteria in object form
function filterById(arr, criteria) {
return arr.filter(function(obj) {
return Object.keys(criteria).every(function(c) {
return obj[c] == criteria[c];
});
});
}
/*
//Creates a DOM object from an array of objects @perksJson [{delivery=xxx, perkAmount=n, description=abc, perkID=abc, soldItems=n, perkTitle=zzz},...]
function generatePerks(perksJson, classDef) {
//Check perksJson is not an empty array
if (perksJson.length > 0) {
var mainContainerSection = $("." + classDef);
var containerSection = $('<section/>')
.addClass("outPerks")
.appendTo(mainContainerSection);
var containerArticle = $("<article/>")
.addClass("perksContainerBody")
.appendTo(containerSection);
var containerHeader = $("<header/>")
.appendTo(containerArticle);
//Declare array with static values por Perks (description, delivery, conditions) !!Update if necessary
var perkCFValues = [{
'perkID': "PERK5",
perkDescription: "No quieres regalos, ni que tu nombre aparezca en ningún sitio. Te entendemos. Por eso queremos permitirte la posibilidad de que puedas donar a esta campaña y que se respete tu voluntad. Por encima de €3 tú eliges cuánto.",
perkConditions: "",
perkDelivery: ""
}, {
'perkID': "PERK3",
perkDescription: "Todos los viajes comienzan con un pequeño paso. Te queremos agradecer que hayas iniciado el tuyo con nosotras publicando tu nombre en la web del documental.",
perkConditions: "",
perkDelivery: "Entrega prevista para "
}, {
'perkID': "PERK4",
perkDescription: "Si eres de las que te quedas en la sala de cine mirando los créditos cuando ya se ha ido todo el mundo estás de suerte. En la siguiente línea podrías salir tú.",
perkConditions: "",
perkDelivery: "Entrega prevista para "
}, {
'perkID': "PERK20",
perkDescription: "<strong>El libro que inspiró nuestro viaje y revolucionó nuestra visión de la educación.</strong> Su autor, Peter Gray, es catedrático de Psicología, y un defensor infatigable y tremendamente lúcido de una educación que responda de verdad a las necesidades de los niños y jóvenes.<br><br>Recibirás como regalo por tu donación \"Aprender en libertad\" y además tu nombre saldrá en los agradecimientos de la web y en los créditos del documental.<br><br>280 páginas aprox., traducción al español del original en edición de bolsillo con tapas blandas e impreso en papel ecológico.",
perkConditions: "Sólo para España. Gastos de envío <em>incluidos</em>.",
perkDelivery: "Entrega prevista para "
}, {
'perkID': "PERK10",
perkDescription: "Cuando conocimos esta historia supimos que <strong>de niños hubiéramos querido que alguien nos la contara.</strong> \"Los náufragos de Tonga\" es una edición exclusiva de un cuento escrito por Ana García-Castellano e ilustrado por Alicia Borges.<br><br>Recibirás como regalo por tu donación \"Los náufragos de Tonga\", y además tu nombre saldrá en los agradecimientos de la web y en los créditos del documental.<br><br>Tapas duras, 32 páginas, impreso en papel ecológico a todo color.",
perkConditions: "Sólo para España. Gastos de envío <em>incluidos</em>.",
perkDelivery: "Entrega prevista para "
}, {
'perkID': "PERK22",
perkDescription: "Los dos libros que te presentamos son <strong>ediciones que no se encuentran actualmente en el mercado</strong>, y que editaremos exclusivamente para esta campaña. Ambos narran historias reales que dan un giro a la concepción tradicional de la infancia y la educación.<br><br>Recibirás como regalo por tu donación los dos libros que editamos, \"Los náufragos de Tonga\" y \"Aprender en libertad\", y tu nombre aparecerá en los agradecimientos de la web así como en los créditos del documental.",
perkConditions: "Sólo para España. Gastos de envío <em>incluidos</em>.",
perkDelivery: "Entrega prevista para "
}];
//Update post flight section
//Declares post flight section
var postFlightSection = $('.eneueSuccessAjax');
//Adds the post flight section
var perkSection = $("<section/>")
.appendTo(postFlightSection);
div = $('<div/>')
.addClass('divPerkResponse')
.appendTo(perkSection);
p = $('<p/>')
.addClass('perkCenterFont')
.appendTo(div);
$('<strong/>')
.text('¡Muchas gracias!')
.appendTo(p);
$('<br/>')
.after('Este proyecto no existiría sin tu ayuda.').
appendTo(p);
p = $('<p/>')
.text('En las próximas horas recibirás un email en la dirección que nos indicaste al autorizar el cargo en tu tarjeta. Si transcurridas 72h no lo has recibido comprueba tu bandeja de spam, podría estar ahí. En caso de que no esté escríbenos a:')
.addClass('perkFontSmall')
.appendTo(div);
$('<br/>')
.appendTo(p);
$('<br/>')
.appendTo(p);
$('<a/>')
.attr('href', 'mailto:[email protected]')
.attr('target', '_top')
.text('[email protected]')
.appendTo(p);
$('<br/>')
.appendTo(p);
$('<br/>')
.after('indicándonos el número de referencia de tu donación y nos pondremos en contacto contigo.')
.appendTo(p);
p = $('<p/>')
.appendTo(div);
$('<span/>')
.addClass('perkDate')
.appendTo(p)
p = $('<p/>')
.text('Has realizado una donación de €')
.appendTo(div);
strong = $('<strong/>')
.appendTo(p);
$('<span/>')
.addClass('perkAmountShow')
.appendTo(strong);
$('<span/>')
.text(' para la producción de un documental sobre educación con los siguientes datos:')
.appendTo(p);
p = $('<p/>')
.text('Correo electrónico:')
.appendTo(div);
strong = $('<strong/>')
.appendTo(p);
$('<span/>')
.addClass('perkEmailShow')
.appendTo(strong);
p = $('<p/>')
.text('Tarjeta de crédito: **** **** **** ')
.appendTo(div);
strong = $('<strong/>')
.appendTo(p);
$('<span/>')
.addClass('perkUlt4Show')
.appendTo(strong);
p = $('<p/>')
.text('Número de referencia (conviene que lo anotes): ')
.appendTo(div);
strong = $('<strong/>')
.appendTo(p);
$('<span/>')
.addClass('perkLocalizerShow')
.appendTo(strong);
//Update the json object with @perkCFValues
for (var i = 0; i < perksJson.length; i++) {
//Gets the extra values for each perk
var perkCFvalue = filterById(perkCFValues, {
perkID: perksJson[i].perkID
});
//Extract number of perk
var perkID = perksJson[i].perkID;
var perkIDNumber = perkID.replace("PERK", "");
//Adds main section for each perk
var sectionPerkN = $("<section/>")
.addClass("perkContenedor clearfix")
.attr('id', 'divPerk' + perkIDNumber)
.attr('name', 'PERK' + perkIDNumber)
.appendTo(containerHeader);
//Adds the header
var perkHeader = $("<header/>")
.addClass('headerMain')
.attr('id', 'divPerk' + perkIDNumber + 'HeaderMain')
.appendTo(sectionPerkN);
var perkSubHeader = $("<header/>")
.addClass('header')
.attr('id', 'divPerk' + perkIDNumber + "Header")
.appendTo(perkHeader);
var div = $('<div/>')
.addClass('perkTitle')
.attr('id', 'divPerk' + perkIDNumber + 'Title')
.appendTo(perkSubHeader);
var h4 = $('<h4/>')
.appendTo(div);
$('<input/>')
.attr('type', 'radio')
.attr('name', 'perkRadio')
.attr('_parent', 'divPerk' + perkIDNumber)
.attr('id', 'togglePerk' + perkIDNumber)
.addClass('perkRadio')
.appendTo(h4);
var label = $('<label/>')
.attr('for', 'togglePerk' + perkIDNumber)
.text('Dona €')
.appendTo(h4);
//I have my concerns with this....
$('<span/>')
.attr('id', 'spanPerk' + perkIDNumber + 'Price')
.text(perksJson[i].perkAmount)
.appendTo(label);
$('<span/>')
.text(' o más | ')
.appendTo(label);
$('<span/>')
.attr('id', 'spanPerk' + perkIDNumber + 'Description')
.text(perksJson[i].perkTitle)
.appendTo(label);
div = $('<div/>')
.addClass('perkStats')
.attr('id', 'divPerk' + perkIDNumber + 'Stats')
.appendTo(perkSubHeader);
var p = $('<p/>')
.appendTo(div);
$('<span/>')
.attr('id', 'spanPerk' + perkIDNumber + "SoldItems")
.text(perksJson[i].soldItems)
.appendTo(p);
$('<span/>')
.text(' apoyos')
.appendTo(p);
//Adds the SubSection
var section = $('<section/>')
.addClass('perkBody')
.attr('id', 'divPerk' + perkIDNumber + 'Body')
.appendTo(perkHeader);
div = $('<div/>')
.addClass('perkDesc')
.attr('id', 'divPerk' + perkIDNumber + 'Desc1')
.appendTo(section);
$('<p/>')
.html(perkCFvalue[0].perkDescription)
.appendTo(div);
div = $('<div/>')
.addClass('perkDelivery')
.attr('id', 'divPerk' + perkIDNumber + 'Delivery')
.appendTo(section);
var p = $('<p/>')
.text(perkCFvalue[0].perkDelivery)
.appendTo(div);
$('<span/>')
.text(perksJson[i].delivery)
.attr('id', 'spanPerk' + perkIDNumber + 'Delivery')
.appendTo(p);
$('<br/>')
.appendTo(p);
$('<span/>')
.html(perkCFvalue[0].perkConditions)
.appendTo(p);
//Adds the footer
var perkFooter = $("<footer/>")
.addClass('perkSend perkDivHidden')
.attr('id', 'divPerk' + perkIDNumber + 'Send')
.appendTo(sectionPerkN);
header = $('<header/>')
.addClass('perkAmount')
.attr('id', 'divPerk' + perkIDNumber + 'Amount')
.appendTo(perkFooter);
$('<label/>')
.attr('for', 'divPerk' + perkIDNumber + 'customDonationAmount')
.addClass('amountLabel')
.text('Cantidad €')
.appendTo(header);
$('<input/>')
.addClass('perkCustomDonationAmount perkDivHidden')
.attr('type', 'number')
.attr('id', 'divPerk' + perkIDNumber + 'customDonationAmount')
.attr('step', '5')
.attr('name', 'perkAmount')
.attr('pattern', '[0-9]*')
.attr('min', perksJson[i].perkAmount)
.attr('title', 'Introduce una cantidad mayor de €' + perksJson.perkAmount)
.attr('placeholder', 'p.ej. € ' + (perksJson[i].perkAmount + 10))
.appendTo(header);
$('#' + 'divPerk' + perkIDNumber + 'customDonationAmount').val(perksJson[i].perkAmount);
$('<div/>')
.addClass('perkCustomButton perkButton perkBUttonDisplayNone perkPointer')
.attr('id', 'divPerk' + perkIDNumber + 'CustomButton')
.appendTo(perkFooter);
}
}
}*/