-
-
Notifications
You must be signed in to change notification settings - Fork 475
/
Copy pathapp.js
88 lines (77 loc) · 2.53 KB
/
app.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
import Plausible from 'plausible-tracker'
import './jquery';
import notifier from './notifier';
import './search';
import './view';
import './submitPackage';
import '../css/app.scss';
import 'bootstrap';
(function ($) {
"use strict";
/**
* Ajax error handler
*/
$.ajaxSetup({
error: function (xhr) {
var resp, message, details = undefined;
notifier.remove();
if (xhr.responseText) {
try {
resp = JSON.parse(xhr.responseText);
if (resp.status && resp.status === 'error') {
message = resp.message;
details = resp.details;
}
} catch (e) {
message = "We're so sorry, something is wrong on our end.";
}
}
notifier.log(message, {}, details);
}
});
/**
* API Token visibility toggling
*/
$('.btn-show-api-token, .api-token').each(function() {
$(this).click(function (e) {
const parent = $(this).closest('.api-token-group');
const token = parent.find('.api-token');
token.val(token.data('api-token'));
token.select();
const button = parent.find('.btn-show-api-token').first();
button.text(button.text().replace('Show', 'Your'));
e.preventDefault();
});
});
$('.btn-rotate-api-token').click(function (e) {
if (!window.confirm('Are you sure? This will revoke your current API tokens and generate new ones.')) {
e.preventDefault();
}
});
$('.toc a').click(function (e) {
setTimeout(function () {
scrollTo(0, $($(e.target).attr('href')).offset().top - 65);
}, 0);
});
let currentBannerId = $('.banner .banner-close').data('banner-id');
$('.banner .banner-close').click(function () {
$('.banner').addClass('hidden');
try {
window.localStorage.setItem('banner-read', currentBannerId);
} catch (e) {}
});
if (currentBannerId !== undefined) {
try {
if (window.localStorage.getItem('banner-read') !== currentBannerId) {
$('.banner').removeClass('hidden');
}
} catch (e) {}
}
})(jQuery);
if (window.trackPageload !== false && location.host === 'packagist.org') {
const plausible = Plausible({
domain: 'packagist.org',
apiHost: 'https://packagist.org',
});
plausible.trackPageview();
}