- 明明是单选,却整个多选框出来误导群众……
OK,继续分析,现在就开始研究正式的文件代码,先贴出解压后的代码(貌似有错误,但不影响分析),挺长的,麻烦大家拖动一下滚动条吧^_^
function imeInit() {
if (ime_close == 1) {
ime_getObj("ime_status").style.display = "block";
ime_close = 0;
return
} else ime_close = 0;
var a = navigator.userAgent.toLowerCase();
try {
if (external.max_version.indexOf("1.") == 0) {
ime_is_maxthon1 = 1
} else {
ime_is_maxthon1 = 0
}
} catch(e) {
ime_is_maxthon1 = 0
}
ime_is_safari = a.indexOf("safari") != -1;
ime_is_ie = (a.indexOf("msie") != -1 && document.all);
ime_compatMode = document.compatMode != "CSS1Compat" && ime_is_ie ? 0 : 1;
if (ime_is_ie) ime_is_ie6 = a.indexOf("msie 6") != -1 ? 1 : 0;
ime_is_opera = (a.indexOf('opera') != -1 && window.opera && document.getElementById);
if (ime_is_ie6 || !ime_compatMode) {
onscroll = imeIE6StatusScroll;
var b = document.documentElement.scrollTop || document.body.scrollTop || 0
}
d = document.createElement('div');
d.id = 'ime_status';
d.style.background = 'url("http://web.pinyin.sogou.com/web_ime/images/ime_bg.gif")';
d.style.padding = '0px';
d.style.margin = '0px';
d.style.filter = 'Alpha(Opacity=90)';
d.style.fontSize = '14px';
d.style.position = (ime_is_ie6 || !ime_compatMode) ? "absolute": "fixed";
d.style.left = 20 + "px";
d.style.top = ime_is_ie6 ? (b + 20) + "px": 20 + "px";
d.style.width = '136px';
d.style.height = '42px';
d.style.textAlign = 'center';
d.style.zIndex = 999998;
d.style.display = 'block';
d.style.opacity = "0.9";
document.body.insertBefore(d, document.body.firstChild);
var c = '<table width="100%" style="width:136px;border-collapse:separate;border-spacing:1px;text-align:center;background:transparent none repeat scroll 0% 0%;" οnmοuseοver=ime_moveobj("ime_status") cellspacing="1" cellpadding="0" ><tr><td style="padding:0px;border:none;"><img id="ime_mode_ZH" οnmοuseοver="imeModeChange(1,1)" οnmοuseοut="imeModeChange(1,2)" οnclick="imeModeChange(1,0)" οnmοusedοwn="imeModeChange(1,3)" οnmοuseup="imeModeChange(1,1)" src="http://web.pinyin.sogou.com/web_ime/images/cn1.gif" style="border:0;display:inline;padding:0px;margin-left:40px;cursor:pointer;" title="切换中/英文(Shift)"><img id="ime_mode_BJ" οnclick="imeModeChange(2,0)" οnmοuseοver="imeModeChange(2,1)" οnmοuseοut="imeModeChange(2,2)" οnmοusedοwn="imeModeChange(2,3)" οnmοuseup="imeModeChange(2,1)" src="http://web.pinyin.sogou.com/web_ime/images/ban1.gif" style="border:0;display:inline;padding:0px;cursor:pointer;" title="全/半角(Shift+Space)"><img id="ime_mode_BD" οnclick="imeModeChange(3,0)" οnmοuseοver="imeModeChange(3,1)" οnmοuseοut="imeModeChange(3,2)" οnmοusedοwn="imeModeChange(3,3)" οnmοuseup="imeModeChange(3,1)" src="http://web.pinyin.sogou.com/web_ime/images/cn_biaodian1.gif" style="border:0;display:inline;padding:0px;cursor:pointer;" title="中/英文标点(Ctrl+.)"><img src="http://web.pinyin.sogou.com/web_ime/images/ime_close1.gif" id="ime_mode_close" οnclick="imeClose();" οnmοuseοver="imeModeChange(4,1)" οnmοuseοut="imeModeChange(4,2)" οnmοusedοwn="imeModeChange(4,3)" οnmοuseup="imeModeChange(4,1)" style="display:inline;cursor:pointer;">';
ime_getObj("ime_status").innerHTML = c;
var d = document.createElement('div');
d.id = 'ime_layer';
if (typeof d.style == "undefined") return;
d.style.position = "absolute";
d.style.display = 'none';
d.style.padding = '0px';
d.style.margin = '0px';
d.style.height = '53px';
d.style.zIndex = 999999;
d.style.backgroundColor = '#FFF';
d.style.filter = 'Alpha(Opacity=96)';
d.style.display = 'none';
d.style.opacity = "0.9";
c = '<table id="layer_tab" οnmοuseοver=ime_moveobj("ime_layer") width="' + tab_len + 'px" style="width:' + tab_len + 'px;margin:0px;color:#004376;font-weight:bold;position:relative;line-height:26px;" cellspacing="0" cellpadding="0" border="0">';
c += '<tr style="vertical-align:middle;"><td rowspan="2" width="1" style="background:url(http://web.pinyin.sogou.com/web_ime/images/layer_left.gif);padding:0px;border:none;"><td id="ime_query" style="background:url(http://web.pinyin.sogou.com/web_ime/images/layer_top.gif) repeat-x;padding:0px 0px 0px 5px;font-size:16px;color:#004376;font-weight:bold;font-family:宋体,Arial;vertical-align:middle;border:none;" align=left height="27"><td width="51" rowspan="2" style="background:url(http://web.pinyin.sogou.com/web_ime/images/layer_right.gif) no-repeat;padding:0px 0px 8px 0px;position:relative;border:none;" valign=bottom>反馈<img style="border:0;display:block;margin:0px;padding:0px;float:left;position:absolute;top:34px;right:15px;" id="ime_back" οnmοuseοver="imeMouseOverPage(0);" οnmοuseοut="imeMouseOutPage(0);" οnmοusedοwn="imePageRun(0,event)" οnmοuseup="imePageStop(0)" src="http://web.pinyin.sogou.com/web_ime/images/ime_back_1.gif"><img style="border:0;display:block;float:left;position:absolute;top:34px;right:4px;margin:0px;padding:0px;" id="ime_forward" οnmοuseοver="imeMouseOverPage(1);" οnmοuseοut="imeMouseOutPage(1);" οnmοusedοwn="imePageRun(1,event)" οnmοuseup="imePageStop(1)" src="http://web.pinyin.sogou.com/web_ime/images/ime_forward_2.gif"><tr style="vertical-align:middle;"><td height="26" style="padding:0px 0px 0px 5px;font-weight:normal;background:url(http://web.pinyin.sogou.com/web_ime/images/layer_bottom.gif) repeat-x;font-size:16px;cursor:default;font-family: 宋体;vertical-align:middle;letter-spacing:0;border:none;" align=left id="ime_res">';
d.innerHTML = c;
document.body.insertBefore(d, document.body.firstChild);
imeBindInput(document)
}
function imeFeedBack() {
window.open("http://pinyin.sogou.com/fb/fillsurvey.php?sid=67&query=" + encodeURIComponent(query) + "&querylist=" + encodeURIComponent(word) + "&ref=" + encodeURIComponent(location.href), "_0")
}
function imeIE6StatusScroll() {
if (ime_close) return;
var a = document.documentElement.scrollTop || document.body.scrollTop || 0;
eval('document.getElementById("ime_status").style.top = "' + (a + ime_ie6_status_top) + 'px";')
}
function ime_getObj(a) {
if (document.getElementById) return document.getElementById(a);
else if (document.all) return document.all[a];
else if (document.layers) return document.layers[a];
else {
return null
}
}
function imeBindInput(a) {
try {
var b = a.getElementsByTagName('input');
for (var i = 0; i = 65 && a <= 90) var c = true;
else if (a >= 97 && a <= 122) {
a -= 32;
var c = false
}
if (a >= 65 && a <= 90) {
if (!ime_mode_ZH) {
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
imeOutput(b, 0, getModeInput(a, e.shiftKey || c));
if (ime_is_maxthon1) e.returnValue = false;
return
}
if ((e.shiftKey || c) && query == "") {
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
imeOutput(b, 0, ime_mode_BJ ? keyArr[a][3] : keyArr[a][4]);
if (ime_is_maxthon1) e.returnValue = false;
return
}
if (e.shiftKey || c) input = keyArr[a][3];
else input = keyArr[a][0];
query += input;
ime_query_input += input;
var f = ime_getObj('ime_layer');
var g = ime_getObj('ime_query');
if (ime_query_input.length >= 100) {
var h = ime_query_input;
for (var i = 0; i < ime_part_key.length; i++) h = h.replace(ime_part_key[i], "");
if (h.length >= 100) {
ime_query_input = ime_query_input.substring(0, ime_query_input.length - 1);
query = query.substring(0, query.length - 1)
}
}
g.innerHTML = ime_query_input;
with(ime_pos(b)) {
layer_x = x;
layer_y = y
}
if (layer_x != old_x || layer_y != old_y) {
f.style.left = (layer_x + 10) + "px";
scrollTop = document.documentElement.scrollTop || document.body.scrollTop || 0;
clientHeight = document.documentElement.clientHeight || document.body.clientHeight || 0;
if (clientHeight == 0) f.style.top = (layer_y + b.clientHeight + 3) + "px";
else if ((layer_y + b.clientHeight + 56) > (clientHeight + scrollTop)) f.style.top = (layer_y - 53) + "px";
else f.style.top = (layer_y + b.clientHeight + 3) + "px";
old_x = layer_x;
old_y = layer_y
}
f.style.display = query == "" ? "none": "block";
if (query == "") {
ime_getObj("ime_res").innerHTML = "";
ime_getObj("layer_tab").style.width = tab_len + "px"
} else {
ime_getObj("ime_query").innerHTML += '<img style="position:absolute;top:1px;" src="http://web.pinyin.sogou.com/web_ime/images/tip.gif">'
}
var j = 0;
for (var i = 0; i < ime_part_key.length; i++) {
j += ime_part_key[i][0].length
}
j += (query.length / 2);
j = 184 + j * 16;
if (j > tab_len) {
ime_getObj("layer_tab").style.width = j + "px";
tab_len = j
}
}
}
function imeOperaKeyChange(a) {
if (a == 61) return 187;
else if (a == 47) return 111;
else if (a == 42) return 106;
else if (a == 43) return 107;
else if (a == 45) return 109;
else return a
}
function imeBodyKeyDown(e) {
if (ime_close) return;
var e = window.event || e;
var a = e.which ? e.which: e.keyCode;
switch (a) {
case 27:
if (query != "") {
query = "";
ime_query_input = "";
ime_part_key = new Array;
word = new Array;
ime_getObj('ime_res').innerHTML = "";
ime_getObj("ime_layer").style.display = "none"
} else return;
break
}
}
function imeBodyMouseDown(e) {
if (ime_close) return;
var e = window.event || e;
var a = e.which ? e.which: e.keyCode;
var b = e.srcElement ? e.srcElement: e.target;
if (!b.imebind) {
if (b.tagName == "INPUT" && b.type == "text") imeBindObj(b, "INPUT");
else if (b.tagName == "TEXTAREA") imeBindObj(b, "TEXTAREA")
}
}
function imeKeyDown(e) {
if (ime_close) return;
imeMouseStopChange(e);
var e = window.event || e;
var a = e.srcElement ? e.srcElement: e.target;
ime_cur_input_obj = a;
if (!e) e = window.event;
var b = e.which ? e.which: e.keyCode;
ime_opera_allow_press = 0;
if (ime_is_opera) b = imeOperaKeyChange(b);
ime_only_shift = b == 16 ? 1 : 0;
var c = "";
if ((b == 67 || b == 86) && e.ctrlKey) return;
switch (b) {
case 46:
return;
break;
case 27:
if (query != "") {
query = "";
ime_query_input = "";
ime_part_key = new Array
} else {
ime_opera_allow_press = 1;
return
}
break;
case 8:
if (query != "") {
if (ime_part_key.length) {
var d = ime_part_key.pop();
query = d[1] + query;
ime_query_input = query;
for (var i = ime_part_key.length; i > 0; i--) {
ime_query_input = ime_part_key[i - 1][0] + ime_query_input
}
} else {
query = query.substr(0, query.length - 1);
ime_query_input = query.replace(eval("/&/g"), "&")
}
} else {
ime_opera_allow_press = 1;
return
}
if (ime_is_ie || ime_is_safari) e.returnValue = false;
break;
case 13:
if (query != "") {
imeOutput(a, 0, -1);
ime_query_input = "";
query = "";
c = "";
ime_part_key = new Array;
ime_getObj('ime_res').innerHTML = "";
word = new Array;
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
imeMouseStopChange(e);
if (ime_is_ie) e.returnValue = false;
else e.preventDefault()
} else {
ime_opera_allow_press = 1;
return
}
break;
case 32:
if (e.shiftKey) {
imeModeChange(2, 4);
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
return false
}
if (query != "") {
imeOutput(a, (focus_id - 1), "")
} else {
ime_opera_allow_press = 1;
return
}
break;
case 38:
if (query != "") {
if (ime_getObj("ime_res").innerHTML == "") {
if (ime_is_ie) e.returnValue = false;
else e.preventDefault();
return false
}
if (focus_id > 1) {
if (word[(focus_id - 2)][0] == "") return false;
focus_id--
} else {
if (ime_query_page != 1) {
ime_query_page--;
showRes(1);
focus_id = 5
} else return false
}
focusChange(focus_id);
return false
} else {
ime_opera_allow_press = 1;
return
}
break;
case 40:
if (query != "") {
if (ime_getObj("ime_res").innerHTML == "") {
if (ime_is_ie) e.returnValue = false;
else e.preventDefault();
return false
}
if (focus_id < 5) {
if (word[focus_id][0] == "") return false;
focus_id++
} else {
if (ime_query_page != ime_query_page_max) {
ime_query_page++;
showRes(1);
focus_id = 1
} else focus_id = 5
}
focusChange(focus_id);
return false
} else {
ime_opera_allow_press = 1;
return
}
break;
case 37:
if (query == "") {
ime_opera_allow_press = 1;
return
}
break;
case 39:
if (query == "") {
ime_opera_allow_press = 1;
return
}
break;
case 33:
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
else e.returnValue = false;
if (ime_query_page != 1) {
ime_query_page--;
showRes(1)
}
break;
case 188:
case 109:
case 189:
var f = /[A-Z0-9`~@#%&*$+-=\^\{\}\|_]+/;
if (f.test(query) || (query != "" && b == 109 && (ime_is_ie || ime_is_safari)) || (query != "" && e.shiftKey && (b == 109 || b == 188)) || (query != "" && e.shiftKey && b == 189 && (ime_is_ie || ime_is_opera || ime_is_safari))) {
if (b == 188) {
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
imeOutput(a, (focus_id - 1), getModeInput(b, e.shiftKey));
break
}
c = !e.shiftKey ? keyArr[b][0] : keyArr[b][3];
if (ime_is_ie) c = b == 109 ? "-": c;
else if (ime_is_opera) c = b == 109 ? "_": c;
query += c;
ime_query_input += c;
showRes(0)
} else if (query != "") {
if (ime_query_page != 1) {
ime_query_page--;
showRes(1)
}
} else imeOutput(a, 0, getModeInput(b, e.shiftKey));
break;
case 34:
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
else e.returnValue = false;
if (ime_query_page != ime_query_page_max) {
ime_query_page++;
showRes(1)
}
break;
case 190:
if (e.ctrlKey) {
imeModeChange(3, 4);
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
return
}
case 107:
case 187:
var f = /[A-Z0-9`~@#%&*$+-=\^\{\}\|_]+/;
var h = /[@]+/;
if (f.test(query) || (query != "" && b == 107 && (ime_is_ie || ime_is_opera || ime_is_safari)) || (query != "" && e.shiftKey && (b == 107 || b == 190)) || (query != "" && e.shiftKey && b == 187 && (ime_is_ie || ime_is_opera || ime_is_safari))) {
if (b == 190) {
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
imeOutput(a, (focus_id - 1), getModeInput(b, e.shiftKey));
break
}
c = !e.shiftKey ? keyArr[b][0] : keyArr[b][3];
c = b == 107 && (ime_is_ie || ime_is_opera || ime_is_safari) ? "+": c;
query += c;
ime_query_input += c;
showRes(0)
} else if (query != "") {
if (ime_query_page != ime_query_page_max) {
ime_query_page++;
showRes(1)
}
} else imeOutput(a, 0, getModeInput(b, e.shiftKey));
break;
case 192:
if (e.shiftKey) {
if (query == "") {
if (ime_mode_BJ) imeOutput(a, 0, keyArr[b][3]);
else imeOutput(a, 0, keyArr[b][4])
} else {
c = keyArr[b][3];
query += c;
ime_query_input += c
}
} else {
if (query == "") {
imeOutput(a, 0, getModeInput(b, e.shiftKey))
} else {
c = keyArr[b][0];
query += c;
ime_query_input += c
}
}
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
break;
case 220:
case 219:
case 221:
if (e.shiftKey) {
if (query == "") {
imeOutput(a, 0, getModeInput(b, e.shiftKey));
if (!ime_is_ie && !ime_is_safari) e.preventDefault()
} else {
c = keyArr[b][3];
query += c;
ime_query_input += c
}
break
} else {
imeOutput(a, (focus_id - 1), getModeInput(b, e.shiftKey));
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
break
}
case 59:
case 106:
case 110:
case 111:
case 186:
case 191:
case 220:
imeOutput(a, (focus_id - 1), getModeInput(b, e.shiftKey));
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
break;
case 222:
var j = 0;
if (ime_mode_BD) {
if (e.shiftKey) {
j = 4;
j += ime_double_quote == 0 ? 2 : 3;
ime_double_quote = ime_double_quote == 1 ? 0 : 1
} else {
j = 0;
j += ime_single_quote == 0 ? 2 : 3;
ime_single_quote = ime_single_quote == 1 ? 0 : 1
}
if (!imeOutput(a, (focus_id - 1), keyArr[222][j])) {
if (e.shiftKey) ime_double_quote = ime_double_quote == 1 ? 0 : 1;
else ime_single_quote = ime_single_quote == 1 ? 0 : 1
}
} else if (!ime_mode_BJ) {
j = e.shiftKey ? 5 : 1;
imeOutput(a, (focus_id - 1), keyArr[222][j])
} else {
j = e.shiftKey ? 4 : 0;
imeOutput(a, (focus_id - 1), keyArr[222][j])
}
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
break;
case 96:
case 97:
case 98:
case 99:
case 100:
case 101:
case 102:
case 103:
case 104:
case 105:
if (query == "") {
if (ime_mode_BJ) {
imeOutput(a, 0, keyArr[b][0]);
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
return false
} else {
imeOutput(a, 0, keyArr[b][2]);
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
return false
}
} else {
c = keyArr[b][0];
query += c;
ime_query_input += c
}
break
}
if (b >= 48 && b <= 57) {
if (e.shiftKey) {
if ((b == 50) || (b == 51) || (b == 53) || (b == 55) || (b == 56) || (b == 52)) {
if (query == "") {
if (b == 52) imeOutput(a, 0, getModeInput(b, e.shiftKey));
else imeOutput(a, 0, keyArr[b][3])
} else {
c = keyArr[b][3];
query += c;
if (b == 55) ime_query_input += "&";
else ime_query_input += c
}
} else imeOutput(a, (focus_id - 1), getModeInput(b, e.shiftKey))
} else {
if (query == "") {
if (ime_mode_BJ) {
imeOutput(a, 0, keyArr[b][0]);
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
if (ime_is_maxthon1) e.returnValue = false;
return
} else {
imeOutput(a, 0, keyArr[b][2]);
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
if (ime_is_maxthon1) e.returnValue = false;
return
}
}
c = keyArr[b][0];
var f = /[A-Z0-9`~@#%&*$+-=\^\{\}\|_]+/;
if (c > 0 && c < 6 && !f.test(query)) {
imeOutput(a, --c, "")
} else {
query += c;
ime_query_input += c
}
}
}
if (!ime_is_ie && !ime_is_safari) e.preventDefault();
if (ime_is_maxthon1) e.returnValue = false;
var l = ime_getObj('ime_layer');
var m = ime_getObj('ime_query');
if (ime_query_input.length >= 100) {
var n = ime_query_input;
for (var i = 0; i < ime_part_key.length; i++) n = n.replace(ime_part_key[i], "");
if (n.length >= 100) {
ime_query_input = ime_query_input.substring(0, ime_query_input.length - 1);
query = query.substring(0, query.length - 1)
}
}
m.innerHTML = ime_query_input;
with(ime_pos(a)) {
layer_x = x;
layer_y = y
}
if (layer_x != old_x || layer_y != old_y) {
l.style.left = (layer_x + 10) + "px";
scrollTop = document.documentElement.scrollTop || document.body.scrollTop || 0;
clientHeight = document.documentElement.clientHeight || document.body.clientHeight || 0;
if (clientHeight == 0) l.style.top = (layer_y + a.clientHeight + 3) + "px";
else if ((layer_y + a.clientHeight + 56) > (clientHeight + scrollTop)) l.style.top = (layer_y - 53) + "px";
else l.style.top = (layer_y + a.clientHeight + 3) + "px";
old_x = layer_x;
old_y = layer_y
}
l.style.display = query == "" ? "none": "block";
if (query == "") {
ime_getObj("ime_res").innerHTML = "";
ime_getObj("layer_tab").style.width = "334px"
} else {
ime_getObj("ime_query").innerHTML += '<img style="position:absolute;top:1px;" src="http://web.pinyin.sogou.com/web_ime/images/tip.gif">'
}
var o = 0;
for (var i = 0; i < ime_part_key.length; i++) {
o += ime_part_key[i][0].length
}
o += (query.length / 2);
o = 184 + o * 16;
if (o > tab_len) {
ime_getObj("layer_tab").style.width = o + "px";
tab_len = o
}
return
}
function imeOutput(a, b, c) {
if (query == "" || c == -1) {
var d = imeGetCurSor(a);
var e = d != a.value.length ? 1 : 0;
var c = c == -1 ? ime_query_input.replace(eval("/&/g"), "&") : c;
if (ime_mode_BJ) a.value = a.value.substr(0, d) + c + a.value.substr(d, a.value.length);
else a.value = a.value.substr(0, d) + imeToDBC(c) + a.value.substr(d, a.value.length);
if (e) {
movePoint(a, d + (c).length)
} else movePoint(a, a.value.length);
return true
}
if (ime_mode_ZH) {
if (word.length != 6) return false;
if (query != word[5][0]) return false
}
if (query.length == word[b][1] || c != "") {
var g = "";
for (var i = 0; i < ime_part_key.length; i++) {
g += ime_part_key[i][0]
}
var d = imeGetCurSor(a);
var e = d != a.value.length ? 1 : 0;
c = c == -2 ? "": c;
if (ime_mode_BJ) a.value = a.value.substr(0, d) + g + word[b][0] + c + a.value.substr(d, a.value.length);
else a.value = a.value.substr(0, d) + imeToDBC(g + word[b][0] + c) + a.value.substr(d, a.value.length);
if (e) movePoint(a, d + (g + word[b][0] + c).length);
else movePoint(a, a.value.length);
query = "";
ime_query_input = "";
ime_part_key = new Array;
ime_getObj('ime_res').innerHTML = "";
word = new Array;
return true
} else {
ime_part_key.push(Array(word[b][0], query.substring(0, word[b][1])));
query = query.substr(word[b][1]);
ime_query_input = "";
for (var i = 0; i < ime_part_key.length; i++) {
ime_query_input += ime_part_key[i][0]
}
ime_query_input += query;
return true
}
}
function imeMouseInput(n) {
ime_cur_input_obj.focus();
imeOutput(ime_cur_input_obj, n, "");
var a = ime_getObj('ime_query');
var b = ime_getObj('ime_layer');
a.innerHTML = ime_query_input;
b.style.display = query == "" ? "none": "block";
if (query == "") {
ime_getObj("ime_res").innerHTML = "";
ime_getObj("layer_tab").style.width = "334px"
}
var c = 0;
for (var i = 0; i < ime_part_key.length; i++) {
c += ime_part_key[i][0].length
}
c += (query.length / 2);
c = 184 + c * 16;
if (c > tab_len) {
ime_getObj("layer_tab").style.width = c + "px";
tab_len = c
}
ime_query_page = 1;
ime_query_page_max = 1;
var d = /[A-Z0-9`~@#%&*$+-=\^\{\}\|_]+/;
if (!d.test(query)) {
if (ime_request_settime != -1) clearTimeout(ime_request_settime);
eval('ime_request_settime = setTimeout(\'imeRequest(\"' + query + '\")\',25)')
} else {
showRes(0)
}
}
function imeModeChange(a, b) {
if (b == 0 || b == 4) {
switch (a) {
case 1:
if (ime_mode_ZH && query != "") imeOutput(ime_cur_input_obj, 0, -1);
if (b == 4) ime_getObj('ime_mode_ZH').src = ime_mode_ZH == 1 ? "http://web.pinyin.sogou.com/web_ime/images/en1.gif": "http://web.pinyin.sogou.com/web_ime/images/cn1.gif";
else ime_getObj('ime_mode_ZH').src = ime_mode_ZH == 1 ? "http://web.pinyin.sogou.com/web_ime/images/en2.gif": "http://web.pinyin.sogou.com/web_ime/images/cn2.gif";
ime_mode_ZH = ime_mode_ZH == 1 ? 0 : 1;
ime_getObj('ime_mode_BD').src = ime_mode_ZH == 0 ? "http://web.pinyin.sogou.com/web_ime/images/en_biaodian1.gif": "http://web.pinyin.sogou.com/web_ime/images/cn_biaodian1.gif";
ime_mode_BD = ime_mode_ZH == 1 ? 1 : 0;
ime_getObj('ime_layer').style.display = "none";
ime_getObj('ime_res').innerHTML = "";
query = "";
ime_query_input = "";
break;
case 2:
if (b == 4) ime_getObj('ime_mode_BJ').src = ime_mode_BJ == 1 ? "http://web.pinyin.sogou.com/web_ime/images/quan1.gif": "http://web.pinyin.sogou.com/web_ime/images/ban1.gif";
else ime_getObj('ime_mode_BJ').src = ime_mode_BJ == 1 ? "http://web.pinyin.sogou.com/web_ime/images/quan2.gif": "http://web.pinyin.sogou.com/web_ime/images/ban2.gif";
ime_mode_BJ = ime_mode_BJ == 1 ? 0 : 1;
break;
case 3:
if (b == 4) ime_getObj('ime_mode_BD').src = ime_mode_BD == 1 ? "http://web.pinyin.sogou.com/web_ime/images/en_biaodian1.gif": "http://web.pinyin.sogou.com/web_ime/images/cn_biaodian1.gif";
else ime_getObj('ime_mode_BD').src = ime_mode_BD == 1 ? "http://web.pinyin.sogou.com/web_ime/images/en_biaodian2.gif": "http://web.pinyin.sogou.com/web_ime/images/cn_biaodian2.gif";
ime_mode_BD = ime_mode_BD == 1 ? 0 : 1;
ime_getObj('ime_mode_ZH').src = ime_mode_BD == 1 ? "http://web.pinyin.sogou.com/web_ime/images/cn1.gif": ime_getObj('ime_mode_ZH').src;
ime_mode_ZH = ime_mode_BD == 1 ? 1 : ime_mode_ZH;
break
}
} else if (b == 1) {
switch (a) {
case 1:
ime_getObj('ime_mode_ZH').src = ime_mode_ZH == 0 ? "http://web.pinyin.sogou.com/web_ime/images/en2.gif": "http://web.pinyin.sogou.com/web_ime/images/cn2.gif";
break;
case 2:
ime_getObj('ime_mode_BJ').src = ime_mode_BJ == 0 ? "http://web.pinyin.sogou.com/web_ime/images/quan2.gif": "http://web.pinyin.sogou.com/web_ime/images/ban2.gif";
break;
case 3:
ime_getObj('ime_mode_BD').src = ime_mode_BD == 0 ? "http://web.pinyin.sogou.com/web_ime/images/en_biaodian2.gif": "http://web.pinyin.sogou.com/web_ime/images/cn_biaodian2.gif";
break;
case 4:
ime_getObj('ime_mode_close').src = "http://web.pinyin.sogou.com/web_ime/images/ime_close2.gif";
break
}
} else if (b == 2) {
switch (a) {
case 1:
ime_getObj('ime_mode_ZH').src = ime_mode_ZH == 0 ? "http://web.pinyin.sogou.com/web_ime/images/en1.gif": "http://web.pinyin.sogou.com/web_ime/images/cn1.gif";
break;
case 2:
ime_getObj('ime_mode_BJ').src = ime_mode_BJ == 0 ? "http://web.pinyin.sogou.com/web_ime/images/quan1.gif": "http://web.pinyin.sogou.com/web_ime/images/ban1.gif";
break;
case 3:
ime_getObj('ime_mode_BD').src = ime_mode_BD == 0 ? "http://web.pinyin.sogou.com/web_ime/images/en_biaodian1.gif": "http://web.pinyin.sogou.com/web_ime/images/cn_biaodian1.gif";
break;
case 4:
ime_getObj('ime_mode_close').src = "http://web.pinyin.sogou.com/web_ime/images/ime_close1.gif";
break
}
} else if (b == 3) {
switch (a) {
case 1:
ime_getObj('ime_mode_ZH').src = ime_mode_ZH == 0 ? "http://web.pinyin.sogou.com/web_ime/images/en3.gif": "http://web.pinyin.sogou.com/web_ime/images/cn3.gif";
break;
case 2:
ime_getObj('ime_mode_BJ').src = ime_mode_BJ == 0 ? "http://web.pinyin.sogou.com/web_ime/images/quan3.gif": "http://web.pinyin.sogou.com/web_ime/images/ban3.gif";
break;
case 3:
ime_getObj('ime_mode_BD').src = ime_mode_BD == 0 ? "http://web.pinyin.sogou.com/web_ime/images/en_biaodian3.gif": "http://web.pinyin.sogou.com/web_ime/images/cn_biaodian3.gif";
break
}
}
}
function imeInput(e) {
if (ime_close) return;
var e = window.event || e;
var a = document.activeElement;
var b = e.which ? e.which: e.keyCode;
if (b == 16 && ime_only_shift) {
imeModeChange(1, 4);
ime_only_shift = 0
}
if ((query != "") && ((b >= 65 && b <= 90) || (b == 8) || (b == 13) || (b == 32) || (b == 192) || (b >= 219 && b <= 221) || (b >= 48 && b <= 57) || (b >= 96 && b <= 105))) {
ime_query_page = 1;
ime_query_page_max = 1;
var c = /[A-Z0-9`~@#%&*$+-=\^\{\}\|_]+/;
if (!c.test(query)) {
if (ime_request_settime != -1) clearTimeout(ime_request_settime);
eval('ime_request_settime = setTimeout(\'imeRequest(\"' + query + '\")\',25)')
} else {
showRes(0)
}
}
}
function imeRequest(q) {
ime_request_settime = -1;
imeCreateRequest(q);
imeCheckSetTime()
}
function imeCheckSetTime() {
if (ime_settime == -1) ime_settime = setTimeout("showRes(1)", 100)
}
function imeCreateRequest(q) {
var a = document.createElement('script');
a.id = "ime_js_" + q;
a.setAttribute("type", "text/javascript");
a.src = "http://web.pinyin.sogou.com/web_ime/get_ajax/" + q + ".key";
document.body.appendChild(a);
setTimeout("imeOverRequest(\"" + q + "\")", 10000)
}
function imeOverRequest(q) {
try {
var a = ime_getObj('ime_js_' + q);
document.body.removeChild(a)
} catch(e) {}
}
function showRes(a) {
try {
ime_query_res = decodeURIComponent(ime_query_res);
ime_query_key = decodeURIComponent(ime_query_key)
} catch(e) {}
if (query == ime_query_key || !a) {
var b = ime_query_key;
if (ime_query_res == "" || !a) {
ime_query_key = a ? ime_query_key: query;
word = new Array(Array(ime_query_key, ime_query_key.length), Array(ime_query_key, ime_query_key.length), Array(ime_query_key, ime_query_key.length), Array(ime_query_key, ime_query_key.length), Array(ime_query_key, ime_query_key.length), Array(ime_query_key, ime_query_key.length));
ime_query_res = -1;
clearTimeout(ime_settime);
ime_settime = -1;
focus_id = 1;
imePageNote(0);
ime_getObj("ime_res").innerHTML = "";
var c = 0;
for (var i = 0; i < ime_part_key.length; i++) {
c += ime_part_key[i][0].length
}
tab_len = 334;
c += (query.length / 2);
c = 184 + c * 16 > tab_len ? 184 + c * 16 : tab_len;
tab_len = c;
ime_getObj("layer_tab").style.width = tab_len + "px";
return
}
var d = ime_query_res.split("\t+");
ime_query_page_max = Math.ceil(d.length * 1.0 / 5);
if (a == 2 || a == 3) imePageNote(a);
else imePageNote(1);
var c = 0;
word = new Array;
for (var i = 0, j = (ime_query_page - 1) * 5; j < ime_query_page * 5; i++, j++) {
word[i] = d[j].split(":");
c += word[i][0].length
}
while (word.length < 5) word.push(Array("", "0"));
word[5] = Array(b, b.length);
var g = 0;
for (var i = 0; i < ime_part_key.length; i++) {
g += ime_part_key[i][0].length
}
g += (query.length / 2);
if (c < 10) c = 10;
c = c > g ? c: g;
c = 184 + c * 16;
if ((a != 2 && a != 3) || parseInt(c) > parseInt(tab_len)) {
ime_getObj("layer_tab").width = c + "px";
tab_len = c
}
var h = "";
for (var i = 0; i < 5; i++) {
if (word[i][0]) {
if (word[i][0] != "") {
if (i == 0) h += "<font id='ime_item_" + (i + 1) + "' οnclick=\"imeMouseInput(" + i + ")\" style='color:#f00;cursor:pointer;font-size:16px;font-weight:normal;line-height:26px;'>" + eval(i + " + 1") + "." + word[i][0] + " ";
else h += "<font id='ime_item_" + (i + 1) + "' οnclick=\"imeMouseInput(" + i + ")\" style='color:#0082e5;cursor:pointer;font-size:16px;font-weight:normal;line-height:26px;'>" + eval(i + " + 1") + "." + word[i][0] + " "
}
}
}
focus_id = 1;
h += "\n";
var k = ime_getObj("ime_res");
ime_getObj("layer_tab").style.width = tab_len + "px";
k.innerHTML = h;
clearTimeout(ime_settime);
ime_settime = -1
} else {
setTimeout("showRes(1)", 1)
}
}
function imeCancel(e) {
var a = ime_getObj('ime_layer');
a.style.display = "none"
}
function imePageNote(a) {
if (ime_query_page != 1 && a) {
ime_getObj("ime_back").src = a == 2 ? "http://web.pinyin.sogou.com/web_ime/images/ime_back_3.gif": "http://web.pinyin.sogou.com/web_ime/images/ime_back_2.gif";
ime_getObj("ime_back").style.cursor = "pointer"
} else {
ime_getObj("ime_back").src = "http://web.pinyin.sogou.com/web_ime/images/ime_back_1.gif";
ime_getObj("ime_back").style.cursor = "default"
}
if (ime_query_page != ime_query_page_max && a) {
ime_getObj("ime_forward").src = a == 3 ? "http://web.pinyin.sogou.com/web_ime/images/ime_forward_3.gif": "http://web.pinyin.sogou.com/web_ime/images/ime_forward_2.gif";
ime_getObj("ime_forward").style.cursor = "pointer"
} else {
ime_getObj("ime_forward").src = "http://web.pinyin.sogou.com/web_ime/images/ime_forward_1.gif";
ime_getObj("ime_forward").style.cursor = "default"
}
}
function imeMouseStopChange(e) {
if (e && e.stopPropagation) { e.stopPropagation()
} else { e.cancelBubble = true
}
return false
}
function imePageRun(a, e) {
if (a == 0) ime_settime_page = setTimeout("imePageAuto(0)", 500);
else if (a == 1) ime_settime_page = setTimeout("imePageAuto(1)", 500);
imeMouseStopChange(e)
}
function imePageStop(a) {
clearTimeout(ime_settime_page);
if (a == 0 && ime_getObj("ime_back").src.indexOf("ime_back_1.gif") == -1) {
ime_query_page--;
showRes(2)
} else if (a == 1 && ime_getObj("ime_forward").src.indexOf("ime_forward_1.gif") == -1) {
ime_query_page++;
showRes(3)
}
ime_cur_input_obj.focus()
}
function imePageAuto(a) {
if (a == 0 && ime_getObj("ime_back").src.indexOf("ime_back_1.gif") == -1) {
ime_query_page--;
showRes(2);
ime_settime_page = setTimeout("imePageAuto(0)", 300)
} else if (a == 1 && ime_getObj("ime_forward").src.indexOf("ime_forward_1.gif") == -1) {
ime_query_page++;
showRes(3);
ime_settime_page = setTimeout("imePageAuto(1)", 300)
} else clearTimeout(ime_settime_page)
}
var ime_pos = function(o) {
var x = 0,
y = 0,
n;
do {
x += o.offsetLeft, y += o.offsetTop;
n = o;
o = o.offsetParent
} while ( o );
if (n = n.ownerDocument) {
for (var i = 0; i < ime_iframe_arr.length; i++) {
if (ime_iframe_arr[i].src.substring(0, 1) == "/") var a = "http://" + document.domain + ime_iframe_arr[i].src;
else if (ime_iframe_arr[i].src.substring(0, 2) == "./") var a = "http://" + document.domain + ime_iframe_arr[i].src.substring(1);
else var a = location.href.substring(0, location.href.lastIndexOf("/") + 1) + ime_iframe_arr[i].src;
if ((ime_iframe_arr[i].src == n.URL || a == n.URL) && ime_iframe_arr[i].src != "") {
o = ime_iframe_arr[i];
do {
x += o.offsetLeft, y += o.offsetTop
} while ( o = o . offsetParent );
break
}
}
}
return {
'x': x,
'y': y
}
};
function imeMouseOverPage(a) {
if (a == 0 && ime_getObj("ime_back").src.indexOf("ime_back_2.gif") != -1) {
ime_getObj("ime_back").src = "http://web.pinyin.sogou.com/web_ime/images/ime_back_3.gif"
} else if (a == 1 && ime_getObj("ime_forward").src.indexOf("ime_forward_2.gif") != -1) {
ime_getObj("ime_forward").src = "http://web.pinyin.sogou.com/web_ime/images/ime_forward_3.gif"
}
}
function imeMouseOutPage(a) {
if (a == 0 && ime_getObj("ime_back").src.indexOf("ime_back_3.gif") != -1) {
ime_getObj("ime_back").src = "http://web.pinyin.sogou.com/web_ime/images/ime_back_2.gif"
} else if (a == 1 && ime_getObj("ime_forward").src.indexOf("ime_forward_3.gif") != -1) {
ime_getObj("ime_forward").src = "http://web.pinyin.sogou.com/web_ime/images/ime_forward_2.gif"
}
}
function imeGetPos(event) {
try {
if (ime_is_opera) {
ime_x = event.clientX + window.pageXOffset;
ime_y = event.clientY + window.pageYOffset
} else if (ime_is_ie) {
ime_x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
ime_y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop
} else {
ime_x = event.clientX + window.scrollX;
ime_y = event.clientY + window.scrollY
}
} catch(x) {}
if (!ime_isInteger(ime_x)) ime_x = 200;
if (!ime_isInteger(ime_y)) ime_y = 200
}
function ime_isInteger(s) {
return (s.toString().search(/^-?[0-9]+$/) == 0)
}
function ime_moveobj(a) {
ime_getObj(a).onmousedown = function(e) {
drag_ = true;
ime_scrollTop = document.documentElement.scrollTop || document.body.scrollTop || 0;
with(this) {
if (ime_is_ie) setCapture();
if (ime_is_safari) {
document.onselectstart = function() {
return false
}
}
if (style.position == "fixed") {
style.position = "absolute";
if (a == "ime_status") style.top = parseInt(style.top.replace("px", "")) + ime_scrollTop + "px"
}
if (!ime_is_ie6) {
ime_getObj(a).style.cursor = "move"
}
temp1 = offsetLeft;
temp2 = offsetTop;
if (ime_is_ie) {
x = event.clientX;
y = event.clientY;
document.onmousemove = function(e) {
if (drag_ == false) return false;
with(this) {
if (temp1 + event.clientX - x < 0) style.left = "0px";
else if (document.documentElement.clientWidth && document.documentElement.clientWidth - temp1 - event.clientX + x < 160) style.left = document.documentElement.clientWidth - 160 + "px";
else style.left = temp1 + event.clientX - x + "px";
if (temp2 + event.clientY - y - ime_scrollTop < 0) style.top = ime_scrollTop + "px";
else if (document.documentElement.clientHeight && document.documentElement.clientHeight + ime_scrollTop - temp2 - event.clientY + y < 50) style.top = document.documentElement.clientHeight + ime_scrollTop - 50 + "px";
else style.top = temp2 + event.clientY - y + "px";
return false
}
}
} else {
x = e.pageX;
y = e.pageY;
document.onmousemove = function(e) {
if (drag_ == false) return false;
with(this) {
if (temp1 + e.pageX - x < 0) style.left = "0px";
else if (document.documentElement.clientWidth && document.documentElement.clientWidth - temp1 - e.pageX + x < 160) style.left = document.documentElement.clientWidth - 160 + "px";
else style.left = temp1 + e.pageX - x + "px";
if (temp2 + e.pageY - y < 0) style.top = "0px";
else style.top = temp2 + e.pageY - y + "px";
ime_getObj("ime_layer").focus();
ime_getObj("ime_layer").blur();
return false
}
}
}
document.onmouseup = function(e) {
drag_ = false;
with(this) {
if (ime_is_ie) {
releaseCapture();
document.onmousemove = null
}
if (ime_is_safari) document.onselectstart = null;
ime_scrollTop = document.documentElement.scrollTop || document.body.scrollTop || 0;
if (!ime_is_ie6 && ime_compatMode) {
ime_getObj(a).style.cursor = "default";
if (style.position == "absolute" && a == "ime_status" && ime_compatMode) style.top = parseInt(style.top.replace("px", "")) - ime_scrollTop + "px";
if (a == "ime_status" && ime_compatMode) style.position = "fixed"
} else style.position = "absolute";
if ((ime_is_ie6 || !ime_compatMode) && a == "ime_status") ime_ie6_status_top = parseInt((ime_getObj(a).style.top.replace("px", "")) - ime_scrollTop);
if (!ime_is_ie6 && !ime_compatMode) ime_getObj(a).style.cursor = "default"
}
}
}
}
}
function focusChange(n) {
try {
ime_getObj("ime_item_1").style.color = "#0082e5";
ime_getObj("ime_item_2").style.color = "#0082e5";
ime_getObj("ime_item_3").style.color = "#0082e5";
ime_getObj("ime_item_4").style.color = "#0082e5";
ime_getObj("ime_item_5").style.color = "#0082e5"
} catch(e) {}
ime_getObj("ime_item_" + n).style.color = "#f00"
}
function imeGetCurSor(a) {
var b = 0;
if (a.selectionStart != undefined) {
b = a.selectionStart
} else {
var c;
if (a.tagName == "TEXTAREA") {
var d = 0;
var e = a.ownerDocument.selection.createRange();
var f = a.ownerDocument.body.createTextRange();
f.moveToElementText(a);
for (d = 0; f.compareEndPoints("StartToStart", e) < 0; d++) {
f.moveStart('character', 1)
}
for (var i = 0; i <= d; i++) {
if (a.value.charAt(i) == '\n') d++
}
return d
} else {
c = document.selection.createRange()
}
c.moveStart("character", -a.value.length);
b = c.text.length
}
return b
}
function movePoint(a, n) {
if (a.selectionStart != undefined) {
a.selectionStart = n;
a.selectionEnd = n
} else {
var b = parseInt(n);
if (isNaN(b)) return;
var c = a.createTextRange();
c.moveStart("character", b);
c.collapse(true);
c.select()
}
}
function getModeInput(a, b) {
if (ime_mode_ZH) {
if (ime_mode_BJ) {
if (ime_mode_BD) {
return b ? keyArr[a][5] : keyArr[a][2]
} else return b ? keyArr[a][3] : keyArr[a][0]
} else if (ime_mode_BD) return b ? keyArr[a][5] : keyArr[a][2];
else return b ? keyArr[a][4] : keyArr[a][1]
} else {
if (ime_mode_BJ) {
return b ? keyArr[a][3] : keyArr[a][0]
} else {
return b ? keyArr[a][4] : keyArr[a][1]
}
}
}
function imeClose() {
ime_close = ime_close == 1 ? 0 : 1;
ime_getObj("ime_layer").style.display = "none";
ime_getObj("ime_query").innerHTML = "";
ime_getObj("ime_res").innerHTML = "";
query = "";
ime_query_input = "";
ime_part_key = new Array;
word = new Array;
var a = document.documentElement.scrollTop || document.body.scrollTop || 0;
ime_getObj("ime_status").style.left = 20 + "px";
ime_getObj("ime_status").style.top = ime_is_ie6 ? (a + 20) + "px": 20 + "px";
ime_getObj("ime_status").style.display = ime_close == 0 ? "": "none"
}
function imeToSBC(a, b) {
var i;
var c = '';
for (i = 0; i < 65296) {
c += String.fromCharCode(a.charCodeAt(i));
continue
}
if (str1 < 125 && !b) c += String.fromCharCode(a.charCodeAt(i));
else c += String.fromCharCode(a.charCodeAt(i) - 65248)
}
return c
}
function imeToDBC(a) {
var b = "";
for (var i = 0; i < 127) {
b = b + String.fromCharCode(a.charCodeAt(i) + 65248)
} else b += a.substr(i, 1)
}
return b
}
if (typeof(ime_close) == "undefined") {
var ime_is_opera = 0;
var ime_is_ie = 0;
var ime_is_ie6 = 0;
var ime_is_safari = 0;
var ime_is_maxthon1 = 0;
var x, y;
var layer_x = 0;
var layer_y = 0;
var old_x = 0;
var old_y = 0;
var drag_ = false;
var keyArr = new Array;
var query = "";
var layer_pos = 0;
var word = new Array();
var tab_len = 334;
var focus_id = 1;
var ime_settime = -1;
var ime_request_settime = -1;
var ime_query_key = -1;
var ime_query_res = -1;
var ime_part_key = new Array();
var ime_query_input = "";
var ime_settime_page = -1;
var ime_query_page = 1;
var ime_query_page_max = 1;
var ime_only_shift = 0;
var ime_mode_ZH = 1;
var ime_mode_BJ = 1;
var ime_mode_BD = 1;
var ime_close = 0;
var ime_cur_input_obj;
var ime_opera_allow_press = 0;
var ime_cur_rng;
var ime_cur_cursor = 0;
var ime_ie6_status_top = 20;
var ime_single_quote = 0;
var ime_double_quote = 0;
var ime_scrollTop = 0;
var ime_iframe_arr = new Array;
var ime_compatMode = 0;
keyArr[48] = Array("0", "0", "0", ")", ")", ")");
keyArr[49] = Array("1", "1", "1", "!", "!", "!");
keyArr[50] = Array("2", "2", "2", "@", "@", "@");
keyArr[51] = Array("3", "3", "3", "#", "#", "#");
keyArr[52] = Array("4", "4", "4", "$", "$", "¥");
keyArr[53] = Array("5", "5", "5", "%", "%", "%");
keyArr[54] = Array("6", "6", "6", "^", "^", "……");
keyArr[55] = Array("7", "7", "7", "&", "&", "&");
keyArr[56] = Array("8", "8", "8", "*", "*", "*");
keyArr[57] = Array("9", "9", "9", "(", "(", "(");
keyArr[59] = Array(";", ";", ";", ":", ":", ":");
keyArr[65] = Array("a", "a", "a", "A", "A", "A");
keyArr[66] = Array("b", "b", "b", "B", "B", "B");
keyArr[67] = Array("c", "c", "c", "C", "C", "C");
keyArr[68] = Array("d", "d", "d", "D", "D", "D");
keyArr[69] = Array("e", "e", "e", "E", "E", "E");
keyArr[70] = Array("f", "f", "f", "F", "F", "F");
keyArr[71] = Array("g", "g", "g", "G", "G", "G");
keyArr[72] = Array("h", "h", "h", "H", "H", "H");
keyArr[73] = Array("i", "i", "i", "I", "I", "I");
keyArr[74] = Array("j", "j", "j", "J", "J", "J");
keyArr[75] = Array("k", "k", "k", "K", "K", "K");
keyArr[76] = Array("l", "l", "l", "L", "L", "L");
keyArr[77] = Array("m", "m", "m", "M", "M", "M");
keyArr[78] = Array("n", "n", "n", "N", "N", "N");
keyArr[79] = Array("o", "o", "o", "O", "O", "O");
keyArr[80] = Array("p", "p", "p", "P", "P", "P");
keyArr[81] = Array("q", "q", "q", "Q", "Q", "Q");
keyArr[82] = Array("r", "r", "r", "R", "R", "R");
keyArr[83] = Array("s", "s", "s", "S", "S", "S");
keyArr[84] = Array("t", "t", "t", "T", "T", "T");
keyArr[85] = Array("u", "u", "u", "U", "U", "U");
keyArr[86] = Array("v", "v", "v", "V", "V", "V");
keyArr[87] = Array("w", "w", "w", "W", "W", "W");
keyArr[88] = Array("x", "x", "x", "X", "X", "X");
keyArr[89] = Array("y", "y", "y", "Y", "Y", "Y");
keyArr[90] = Array("z", "z", "z", "Z", "Z", "Z");
keyArr[96] = Array("0", "0", "0", ")", ")", ")");
keyArr[97] = Array("1", "1", "1", "!", "!", "!");
keyArr[98] = Array("2", "2", "2", "@", "@", "@");
keyArr[99] = Array("3", "3", "3", "#", "#", "#");
keyArr[100] = Array("4", "4", "4", "$", "$", "¥");
keyArr[101] = Array("5", "5", "5", "%", "%", "%");
keyArr[102] = Array("6", "6", "6", "^", "^", "……");
keyArr[103] = Array("7", "7", "7", "&", "&", "&");
keyArr[104] = Array("8", "8", "8", "*", "*", "*");
keyArr[105] = Array("9", "9", "9", "(", "(", "(");
keyArr[106] = Array("*", "*", "*", "*", "*", "*");
keyArr[107] = Array("=", "=", "=", "+", "+", "+");
keyArr[187] = Array("=", "=", "=", "+", "+", "+");
keyArr[109] = Array("-", "-", "-", "_", "_", "——");
keyArr[189] = Array("-", "-", "-", "_", "_", "——");
keyArr[110] = Array(".", ".", ".", ".", ".", ".");
keyArr[111] = Array("/", "/", "/", "/", "/", "/");
keyArr[186] = Array(";", ";", ";", ":", ":", ":");
keyArr[188] = Array(",", ",", ",", "<", "<", "《");
keyArr[190] = Array(".", ".", "。", "& gt;", ">", "》");
keyArr[191] = Array("/", "/", "、", "?", "?", "?");
keyArr[192] = Array("`", "`", "·", "~", "~", "~");
keyArr[219] = Array("[", "[", "【", "{", "{", "{");
keyArr[220] = Array("\\", "\", "、", "|", "|", "|");
keyArr[221] = Array("]", "]", "】", "}", "}", "}");
keyArr[222] = Array("'", "'", "‘", "’", " \"", """, "“", "”");
imeInit()
} else if (ime_close == 1) imeClose();
先来看代码的执行部分:
if (typeof(ime_close) == "undefined") {
// 一大堆初始化代码
imeInit()
} else if (ime_close == 1) imeClose();
可以看到这里利用了一个全局变量ime_close,来判断是否已经初始化
如果还没有载入,则执行初始化代码;
如果已经载入,则执行imeClose函数 - 这个函数看起来是关闭,其实是一个状态反转处理函数(比如从正常到关闭,关闭到正常),而每个操作都进行了状态恢复(比如面板复位,输入项清空)
先看主要的初始化过程(imeInit函数)吧。
一开始就是一个状态判断:
if (ime_close == 1) {
ime_getObj("ime_status").style.display = "block";
ime_close = 0;
return
} else ime_close = 0;
按理说,imeInit是在ime_close为undefined的情况下执行的,但为什么一开始又对ime_close==1的情况进行判断呢?
这个情况或许可以从多线程的角度来分析:用户一下子启动了多个输入法(多次点击收藏夹),那么就有可能执行了好几个imeInit函数,要使ime_close变为1,需要用户执行关闭输入法操作,而从ime_close已经初始化(即imeInit不会再被执行)到用户关闭输入法(执行imeClose函数),这个时间按理说很长,没必要在短时间内再次对ime_close进行判断才对。(当然,不排除是为了提高代码的容错能力,可以让这个函数可以随时随地执行)
接下来,又是对浏览器的判断(遨游、Safari、IE、opera),但此时对IE的浏览器为什么用到了两个条件了呢?
ime_is_ie = (a.indexOf("msie") != -1 && document.all);
可能是保险起见吧,呵呵~
另外一个重点是IE6以及IE盒式模型进行判断,如果是为IE6或者不为标准模式,则对滚动进行相关操作:
1.计算当前滚动条到页面的顶端的距离:document.documentElement.scrollTop || document.body.scrollTop || 0
2.绑定滚动回调函数:imeIE6StatusScroll(主要是进行固定位置)
进行了那么多变量初始化,也该到界面部分了,首先是主要面板,即:
d = document.createElement('div');
d.id = 'ime_status';
d.style.background = 'url("http://web.pinyin.sogou.com/web_ime/images/ime_bg.gif")';
d.style.padding = '0px';
d.style.margin = '0px';
d.style.filter = 'Alpha(Opacity=90)';
d.style.fontSize = '14px';
d.style.position = (ime_is_ie6 || !ime_compatMode) ? "absolute": "fixed";
d.style.left = 20 + "px";
d.style.top = ime_is_ie6 ? (b + 20) + "px": 20 + "px";
d.style.width = '136px';
d.style.height = '42px';
d.style.textAlign = 'center';
d.style.zIndex = 999998;
d.style.display = 'block';
d.style.opacity = "0.9";
document.body.insertBefore(d, document.body.firstChild);
这里可以学习到:
1.通用的透明设置
2.通用的固定定位方式(标准情况下将postion设置为fixed即可,特殊情况是IE6以及IE的非标准模式)
3.将元素插入成为body的第一个子元素(这个有什么用途呢?在我看来就是方便调试)
4.将元素设置为最顶层(注意,这里的zIndex是999998,是为了让步于输入框)
新建了div之后,就是往里面放入四张图片(那四张就不啰嗦了),有些不解的是为什么在外层套了一个这么复杂的table(输入法的安装页面上边用的也是table定位方式,估计作者是同一人):
<table width="100%" style="width:136px;border-collapse:separate;border-spacing:1px;text-align:center;background:transparent none repeat scroll 0% 0%;" οnmοuseοver=ime_moveobj("ime_status") cellspacing="1" cellpadding="0" >
主要重点应该是ime_moveobj这个函数,很经典的拖动处理函数(有兴趣的自己分析)。
同时也可以看出这里有个小“bug”,因为只有当鼠标放入那个table的时候,才会绑定拖动函数(动态执行代码,我喜欢,^_^),但那个table并没有覆盖整个div,而是覆盖了上半部分而已,所以一开始把鼠标放入下半部分,是没有拖动功能滴~~
接下来就是初始化输入层了,原理和上面主界面差不多,但有点不同的是:
1.输入界面统一采用绝对定位(动态计算位置)
2.透明度设置中,针对IE滤镜,设置的是96,而不是90(手误吗?)
3.if (typeof d.style == "undefined") return;(突然冒出这句又是为了什么?)
另外值得一看的就是表格的动态宽度设置(由于是table+大量内嵌的CSS,这里实在是没心思分析)
将主界面+输入界面初始化完了之后(界面上的事件函数先不进行分析了,简单但繁琐)
下一步就是绑定输入事件:imeBindInput。