|
1 var LATIN_MAP = { |
|
2 'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', 'Å': 'A', 'Æ': 'AE', 'Ç': |
|
3 'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I', 'Î': 'I', |
|
4 'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O', 'Õ': 'O', 'Ö': |
|
5 'O', 'Ő': 'O', 'Ø': 'O', 'Ù': 'U', 'Ú': 'U', 'Û': 'U', 'Ü': 'U', 'Ű': 'U', |
|
6 'Ý': 'Y', 'Þ': 'TH', 'ß': 'ss', 'à':'a', 'á':'a', 'â': 'a', 'ã': 'a', 'ä': |
|
7 'a', 'å': 'a', 'æ': 'ae', 'ç': 'c', 'è': 'e', 'é': 'e', 'ê': 'e', 'ë': 'e', |
|
8 'ì': 'i', 'í': 'i', 'î': 'i', 'ï': 'i', 'ð': 'd', 'ñ': 'n', 'ò': 'o', 'ó': |
|
9 'o', 'ô': 'o', 'õ': 'o', 'ö': 'o', 'ő': 'o', 'ø': 'o', 'ù': 'u', 'ú': 'u', |
|
10 'û': 'u', 'ü': 'u', 'ű': 'u', 'ý': 'y', 'þ': 'th', 'ÿ': 'y' |
|
11 } |
|
12 var LATIN_SYMBOLS_MAP = { |
|
13 '©':'(c)' |
|
14 } |
|
15 var GREEK_MAP = { |
|
16 'α':'a', 'β':'b', 'γ':'g', 'δ':'d', 'ε':'e', 'ζ':'z', 'η':'h', 'θ':'8', |
|
17 'ι':'i', 'κ':'k', 'λ':'l', 'μ':'m', 'ν':'n', 'ξ':'3', 'ο':'o', 'π':'p', |
|
18 'ρ':'r', 'σ':'s', 'τ':'t', 'υ':'y', 'φ':'f', 'χ':'x', 'ψ':'ps', 'ω':'w', |
|
19 'ά':'a', 'έ':'e', 'ί':'i', 'ό':'o', 'ύ':'y', 'ή':'h', 'ώ':'w', 'ς':'s', |
|
20 'ϊ':'i', 'ΰ':'y', 'ϋ':'y', 'ΐ':'i', |
|
21 'Α':'A', 'Β':'B', 'Γ':'G', 'Δ':'D', 'Ε':'E', 'Ζ':'Z', 'Η':'H', 'Θ':'8', |
|
22 'Ι':'I', 'Κ':'K', 'Λ':'L', 'Μ':'M', 'Ν':'N', 'Ξ':'3', 'Ο':'O', 'Π':'P', |
|
23 'Ρ':'R', 'Σ':'S', 'Τ':'T', 'Υ':'Y', 'Φ':'F', 'Χ':'X', 'Ψ':'PS', 'Ω':'W', |
|
24 'Ά':'A', 'Έ':'E', 'Ί':'I', 'Ό':'O', 'Ύ':'Y', 'Ή':'H', 'Ώ':'W', 'Ϊ':'I', |
|
25 'Ϋ':'Y' |
|
26 } |
|
27 var TURKISH_MAP = { |
|
28 'ş':'s', 'Ş':'S', 'ı':'i', 'İ':'I', 'ç':'c', 'Ç':'C', 'ü':'u', 'Ü':'U', |
|
29 'ö':'o', 'Ö':'O', 'ğ':'g', 'Ğ':'G' |
|
30 } |
|
31 var RUSSIAN_MAP = { |
|
32 'а':'a', 'б':'b', 'в':'v', 'г':'g', 'д':'d', 'е':'e', 'ё':'yo', 'ж':'zh', |
|
33 'з':'z', 'и':'i', 'й':'j', 'к':'k', 'л':'l', 'м':'m', 'н':'n', 'о':'o', |
|
34 'п':'p', 'р':'r', 'с':'s', 'т':'t', 'у':'u', 'ф':'f', 'х':'h', 'ц':'c', |
|
35 'ч':'ch', 'ш':'sh', 'щ':'sh', 'ъ':'', 'ы':'y', 'ь':'', 'э':'e', 'ю':'yu', |
|
36 'я':'ya', |
|
37 'А':'A', 'Б':'B', 'В':'V', 'Г':'G', 'Д':'D', 'Е':'E', 'Ё':'Yo', 'Ж':'Zh', |
|
38 'З':'Z', 'И':'I', 'Й':'J', 'К':'K', 'Л':'L', 'М':'M', 'Н':'N', 'О':'O', |
|
39 'П':'P', 'Р':'R', 'С':'S', 'Т':'T', 'У':'U', 'Ф':'F', 'Х':'H', 'Ц':'C', |
|
40 'Ч':'Ch', 'Ш':'Sh', 'Щ':'Sh', 'Ъ':'', 'Ы':'Y', 'Ь':'', 'Э':'E', 'Ю':'Yu', |
|
41 'Я':'Ya' |
|
42 } |
|
43 var UKRAINIAN_MAP = { |
|
44 'Є':'Ye', 'І':'I', 'Ї':'Yi', 'Ґ':'G', 'є':'ye', 'і':'i', 'ї':'yi', 'ґ':'g' |
|
45 } |
|
46 var CZECH_MAP = { |
|
47 'č':'c', 'ď':'d', 'ě':'e', 'ň': 'n', 'ř':'r', 'š':'s', 'ť':'t', 'ů':'u', |
|
48 'ž':'z', 'Č':'C', 'Ď':'D', 'Ě':'E', 'Ň': 'N', 'Ř':'R', 'Š':'S', 'Ť':'T', |
|
49 'Ů':'U', 'Ž':'Z' |
|
50 } |
|
51 |
|
52 var POLISH_MAP = { |
|
53 'ą':'a', 'ć':'c', 'ę':'e', 'ł':'l', 'ń':'n', 'ó':'o', 'ś':'s', 'ź':'z', |
|
54 'ż':'z', 'Ą':'A', 'Ć':'C', 'Ę':'e', 'Ł':'L', 'Ń':'N', 'Ó':'o', 'Ś':'S', |
|
55 'Ź':'Z', 'Ż':'Z' |
|
56 } |
|
57 |
|
58 var LATVIAN_MAP = { |
|
59 'ā':'a', 'č':'c', 'ē':'e', 'ģ':'g', 'ī':'i', 'ķ':'k', 'ļ':'l', 'ņ':'n', |
|
60 'š':'s', 'ū':'u', 'ž':'z', 'Ā':'A', 'Č':'C', 'Ē':'E', 'Ģ':'G', 'Ī':'i', |
|
61 'Ķ':'k', 'Ļ':'L', 'Ņ':'N', 'Š':'S', 'Ū':'u', 'Ž':'Z' |
|
62 } |
|
63 |
|
64 var ALL_DOWNCODE_MAPS=new Array() |
|
65 ALL_DOWNCODE_MAPS[0]=LATIN_MAP |
|
66 ALL_DOWNCODE_MAPS[1]=LATIN_SYMBOLS_MAP |
|
67 ALL_DOWNCODE_MAPS[2]=GREEK_MAP |
|
68 ALL_DOWNCODE_MAPS[3]=TURKISH_MAP |
|
69 ALL_DOWNCODE_MAPS[4]=RUSSIAN_MAP |
|
70 ALL_DOWNCODE_MAPS[5]=UKRAINIAN_MAP |
|
71 ALL_DOWNCODE_MAPS[6]=CZECH_MAP |
|
72 ALL_DOWNCODE_MAPS[7]=POLISH_MAP |
|
73 ALL_DOWNCODE_MAPS[8]=LATVIAN_MAP |
|
74 |
|
75 var Downcoder = new Object(); |
|
76 Downcoder.Initialize = function() |
|
77 { |
|
78 if (Downcoder.map) // already made |
|
79 return ; |
|
80 Downcoder.map ={} |
|
81 Downcoder.chars = '' ; |
|
82 for(var i in ALL_DOWNCODE_MAPS) |
|
83 { |
|
84 var lookup = ALL_DOWNCODE_MAPS[i] |
|
85 for (var c in lookup) |
|
86 { |
|
87 Downcoder.map[c] = lookup[c] ; |
|
88 Downcoder.chars += c ; |
|
89 } |
|
90 } |
|
91 Downcoder.regex = new RegExp('[' + Downcoder.chars + ']|[^' + Downcoder.chars + ']+','g') ; |
|
92 } |
|
93 |
|
94 downcode= function( slug ) |
|
95 { |
|
96 Downcoder.Initialize() ; |
|
97 var downcoded ="" |
|
98 var pieces = slug.match(Downcoder.regex); |
|
99 if(pieces) |
|
100 { |
|
101 for (var i = 0 ; i < pieces.length ; i++) |
|
102 { |
|
103 if (pieces[i].length == 1) |
|
104 { |
|
105 var mapped = Downcoder.map[pieces[i]] ; |
|
106 if (mapped != null) |
|
107 { |
|
108 downcoded+=mapped; |
|
109 continue ; |
|
110 } |
|
111 } |
|
112 downcoded+=pieces[i]; |
|
113 } |
|
114 } |
|
115 else |
|
116 { |
|
117 downcoded = slug; |
|
118 } |
|
119 return downcoded; |
|
120 } |
|
121 |
|
122 |
|
123 function URLify(s, num_chars) { |
|
124 // changes, e.g., "Petty theft" to "petty_theft" |
|
125 // remove all these words from the string before urlifying |
|
126 s = downcode(s); |
|
127 removelist = ["a", "an", "as", "at", "before", "but", "by", "for", "from", |
|
128 "is", "in", "into", "like", "of", "off", "on", "onto", "per", |
|
129 "since", "than", "the", "this", "that", "to", "up", "via", |
|
130 "with"]; |
|
131 r = new RegExp('\\b(' + removelist.join('|') + ')\\b', 'gi'); |
|
132 s = s.replace(r, ''); |
|
133 // if downcode doesn't hit, the char will be stripped here |
|
134 s = s.replace(/[^-\w\s]/g, ''); // remove unneeded chars |
|
135 s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces |
|
136 s = s.replace(/[-\s]+/g, '-'); // convert spaces to hyphens |
|
137 s = s.toLowerCase(); // convert to lowercase |
|
138 return s.substring(0, num_chars);// trim to first num_chars chars |
|
139 } |
|
140 |