-
Notifications
You must be signed in to change notification settings - Fork 1
/
$wVg.js
138 lines (125 loc) · 3.58 KB
/
$wVg.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/************************************************************
$ W V G
*************************************************************
*
* Copyright (c) 2016, Johnjimy Som, Shinesunny Som
*
* SwVG is released under WTFPL license
*
************************************************************/
jQuery.fn.swag = function() {
// $wVG mapping
var swag = [
["a", "ɐ"],
["b", "ß"],
["c", "¢"],
["d", "₫"],
["e", "€"],
["f", "ƒ"],
["g", "₲"],
["h", "ħ"],
["i", "ї"],
["j", "ℑ"],
["k", "₭"],
["l", "ℓ"],
["m", "₥"],
["n", "Π"],
["o", "ö"],
["p", "¶"],
["q", "ℚ"],
["r", "®"],
["s", "$"],
["t", "τ"],
["u", "μ"],
["v", "℣"],
["w", "ω"],
["x", "ж"],
["y", "ÿ"],
["z", "ζ"],
["A", "∀"],
["B", "ß"],
["C", "℃"],
["D", "₫"],
["E", "Σ"],
["F", "£"],
["G", "₲"],
["H", "Ḧ"],
["I", "エ"],
["J", "⅃"],
["K", "₭"],
["L", "∫"],
["M", "ℳ"],
["N", "Π"],
["O", "Θ"],
["P", "¶"],
["Q", "ℚ"],
["R", "ℜ"],
["S", "§"],
["T", "₸"],
["U", "℧"],
["V", "℣"],
["W", "@"],
["X", "χ"],
["Y", "λ"],
["Z", "ζ"]
]; //end $WVg mapping
// For every letter, convert to the text if possible
this.keyup(function() {
var input_field_string = this.value;
var speed_offset_error = 0;
// for each array iterate through the swag map and replace the input string
// if it matches, the letter are rewritten
for (var i = 0; i < swag.length; i++) {
input_field_string = input_field_string.replace(swag[i][0], swag[i][1]);
if (input_field_string != this.value)
//if no letters match the map, do nothing.
break;
} // end for loop
// setting the correct cursor location
if (input_field_string != this.value) {
var original_string = this.value.split("");
// replace the letters with "swag" symbols in the textfield
this.value = input_field_string;
var new_string = input_field_string.split("");
var tmp_new_length = new_string.length;
//typing cursor position error fix
for (var i = 0; i < new_string.length; i++) {
var char_value = new_string[i].charCodeAt(0);
if (
(char_value >= 65 && char_value <= 90) ||
(char_value >= 97 && char_value <= 122)
)
speed_offset_error = 1;
} //end for
// calculate cursor position
for (var i = original_string.length - 1; i >= 0; i--) {
var j = tmp_new_length - 1;
if (original_string[i] != new_string[j]) {
var offset = original_string.length - i;
var current_position =
new_string.length - offset + 1 + speed_offset_error;
break;
} //end if
tmp_new_length--;
} //end for loop
//resets cursor position
$(this).setCursorPosition(current_position);
} //end if loop
}); //end jQuery function $wVg
};
// reset cursor position (next to letters-$wVg conversion location)
jQuery.fn.setCursorPosition = function(current_position) {
return this.each(function() {
if (this.setSelectionRange) {
this.focus();
this.setSelectionRange(current_position, current_position);
} else if (this.createTextRange) {
//end if
var range = this.createTextRange();
range.collapse(true);
range.moveEnd("character", current_position);
range.moveStart("character", current_position);
range.select();
} //end if else function
}); //end return function
}; //end jQuery function