-
Notifications
You must be signed in to change notification settings - Fork 0
/
edgy-chess.js
88 lines (84 loc) · 2.21 KB
/
edgy-chess.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
/*
* Chess variant: Edgy Chess
*
* Version: 1.0
* Author: Marc Bernard, 2017-08-01
*
* Copyright(c) 2017-2020. All rights reserved.
*
* http://www.edgychess.com/
*/
jQuery(function ($) {
'use strict';
// Open external links in new tab
$('a').each(function() {
var a = new RegExp('/' + window.location.host + '/');
if(!a.test(this.href)) {
$(this).click(function(event) {
event.preventDefault();
event.stopPropagation();
window.open(this.href, '_blank');
});
}
});
// Mail something
function rot13(s) {
return s.replace(/[a-zA-Z]/g, function (c) {
return String.fromCharCode((c <= 'Z' ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
});
}
function fetchEmail(el) {
var email = el.getAttribute('data-enc-email');
if (!email) {
return null;
}
email = email.replace(/\[at\]/g, '@');
email = rot13(email);
return email;
}
function parseTitle(el) {
var title = el.getAttribute('title');
var email = fetchEmail(el);
if (title && email) {
title = title.replace('{{email}}', email);
el.setAttribute('title', title);
}
}
function setInputValue(el) {
var email = fetchEmail(el);
if (email) {
el.setAttribute('value', email);
}
}
function mailto(el) {
var email = fetchEmail(el);
if (email) {
window.location.href = 'mailto:' + email;
}
}
function revert(el, rtl) {
var email = fetchEmail(el);
if (email) {
rtl.text(email);
rtl.removeClass('wpml-rtl');
}
}
document.addEventListener('copy', function(e){
$('a[data-enc-email]').each(function () {
var rtl = $(this).find('.wpml-rtl');
if (rtl.text()) {
revert(this, rtl);
}
});
console.log('copy');
});
$('body').on('click', 'a[data-enc-email]', function () {
mailto(this);
});
$('a[data-enc-email]').each(function () {
parseTitle(this);
});
$('input[data-enc-email]').each(function () {
setInputValue(this);
});
});