-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.hyphen.ru.js
25 lines (24 loc) · 1011 Bytes
/
jquery.hyphen.ru.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
$.fn.hyphenate = function() {
var RusA = "[абвгдеёжзийклмнопрстуфхцчшщъыьэюя]";
var RusV = "[аеёиоуыэю\я]";
var RusN = "[бвгджзклмнпрстфхцчшщ]";
var RusX = "[йъь]";
var Hyphen = "\xAD";
var re1 = new RegExp("("+RusX+")("+RusA+RusA+")","ig");
var re2 = new RegExp("("+RusV+")("+RusV+RusA+")","ig");
var re3 = new RegExp("("+RusV+RusN+")("+RusN+RusV+")","ig");
var re4 = new RegExp("("+RusN+RusV+")("+RusN+RusV+")","ig");
var re5 = new RegExp("("+RusV+RusN+")("+RusN+RusN+RusV+")","ig");
var re6 = new RegExp("("+RusV+RusN+RusN+")("+RusN+RusN+RusV+")","ig");
console.log(this);
this.each(function(){
var text=$(this).html();
text = text.replace(re1, "$1"+Hyphen+"$2");
text = text.replace(re2, "$1"+Hyphen+"$2");
text = text.replace(re3, "$1"+Hyphen+"$2");
text = text.replace(re4, "$1"+Hyphen+"$2");
text = text.replace(re5, "$1"+Hyphen+"$2");
text = text.replace(re6, "$1"+Hyphen+"$2");
$(this).html(text);
});
};