forked from EleRam/trello-rtl-support
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
74 lines (62 loc) · 1.75 KB
/
script.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
/*
* trello-rtl-support
* https://github.com/ykh/trello-rtl-support
* This script is a solution to trello can detect rtl content and apply correct behaviors
* Licensed under the GNU GPL v2 license.
*/
(function ($, document) {
var doms = 'h1, h2, h3, p ,a',
inputs = 'textarea, input[type=text]';
$(document).ajaxComplete(function () {
$(doms).each(function () {
updateStyle($(this));
});
});
$(document).ready(function () {
$(doms).each(function () {
updateStyle($(this));
});
});
$('body').on('input blur focus', inputs, function (e) {
updateStyle($(this));
});
function updateStyle(target) {
var regex = [],
matched,
value,
tagName = target[0].tagName,
rtl,
ltr;
rtl = {
'direction': 'rtl',
'text-align': 'right'
};
ltr = {
'direction': 'ltr',
'text-align': 'left'
};
value = target.text();
if (target.is('textarea') || target.is('input[type=text]')) {
value = target.val();
}
if (target.is('a') || tagName === 'H1' || tagName === 'H2' || tagName === 'H3') {
rtl['unicode-bidi'] = 'embed';
ltr['unicode-bidi'] = '';
}
// Persian, Arabic
regex.push(/[\u0600-\u06FF]/);
// Hebrew
regex.push(/[\u0590-\u05FF]/);
for (var i = 0; i < regex.length; i++) {
matched = value.match(regex[i]);
if (matched) {
break;
}
}
if (matched) {
target.css(rtl);
} else {
target.css(ltr);
}
}
})($, document);