This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 309
/
Copy pathgratipay.js
119 lines (95 loc) · 2.87 KB
/
gratipay.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
/* Main namespace.
* ===============
* Individual modules are in the gratipay/ directory.
*/
Gratipay = {};
Gratipay.getCookie = function(key) {
var o = new RegExp("(?:^|; ?)" + escape(key) + "=([^;]+)").exec(document.cookie);
return o && unescape(o[1]);
}
Gratipay.init = function() {
Gratipay.forms.initCSRF();
Gratipay.signIn();
Gratipay.signOut();
Gratipay.tips.initSupportGratipay();
};
// each/jsoncss/jsonml
// ===================
// yanked from gttp.co/v1/api.js
Gratipay.each = function(a, fn) {
for (var i=0; i<a.length; i++)
fn(a[i], i, length);
};
Gratipay.jsoncss = function(jsoncss) {
var out = '';
this.each(jsoncss, function(selector) {
if (typeof selector == 'string')
return out += selector + ';';
out += selector[0] + '{';
for (var i=1; i<selector.length; i++) {
for (var prop in selector[i])
out += prop + ':' + selector[i][prop] + ';';
}
out += '}';
});
return this.jsonml(['style', out]);
};
Gratipay.jsonml = function(jsonml) {
var node = document.createElement(jsonml[0]),
_ = this;
_.each(jsonml, function(v, j) {
if (j === 0 || typeof v === 'undefined') return;
switch (v.constructor) {
case Object:
for (var p in v)
node.setAttribute(p, v[p]);
break;
case Array: node.appendChild(_.jsonml(v)); break;
case String: case Number:
node.appendChild(document.createTextNode(v));
break;
default: node.appendChild(v); break;
}
});
return node;
};
Gratipay.signIn = function() {
$('.sign-in > .dropdown').mouseenter(function(e) {
clearTimeout($(this).data('timeoutId'));
$(this).addClass('open');
}).mouseleave(function(e) {
var $this = $(this),
timeoutId = setTimeout(function() {
$this.removeClass('open');
}, 100);
$this.data('timeoutId', timeoutId);
});
$('.dropdown-toggle').click(function(e) {
if ($('.sign-in > .dropdown').hasClass('open')) {
e.preventDefault();
return false;
}
else {
$(this).addClass('open');
}
});
// disable the tip-changed prompt when trying to sign in
$('form.auth-button').submit(function() {
$(window).off('beforeunload.tips');
});
};
Gratipay.signOut = function() {
$('a#sign-out').click(function(e) {
e.preventDefault();
jQuery.ajax({
url: '/sign-out.html',
type: 'POST',
success: function() {
window.location.href = window.location.href;
},
error: function() {
Gratipay.notification('Failed to sign out', 'error');
}
});
});
};