-
Notifications
You must be signed in to change notification settings - Fork 0
/
encodeComponent.html
95 lines (95 loc) · 3.08 KB
/
encodeComponent.html
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
<!doctype html>
<html>
<head>
<meta charset="gbk" />
<title>encodeComponent | http://omiga.org/</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="robots" content="all" />
<meta name="author" content="wondger" />
<style type="text/css">
.i_text{width:200px;}
</style>
</head>
<body>
<h1>encodeComponent</h1>
<div class="form">
<input class="i_text" type="text" id="J_source" value="" />
<select id="J_type">
<option value="gbk">gbk</option>
<option value="utf8" selected>utf8</option>
</select>
<br />
<button class="btn" id="btn_encode">ת »»</button>
<br />
<textarea type="text" id="J_out" value="" disabled cols="40" rows="10"></textarea>
</div>
<script type="text/javascript">
//<![CDATA[
var EC = {
tid:'',
form:null,
iframe:null,
bind:function(obj,evt,fn){
if(obj.addEventListener){
obj.addEventListener(evt,function(){fn.call(obj)},false);
EC.addEvent = function(ele,evt,fn,index){
ele.addEventListener(evt,function(){fn.call(obj)},false);
};
}else if(obj.attachEvent){
obj.attachEvent('on'+evt,function(){fn.call(obj)},false);
EC.bind = function(ele,evt,fn,index){
ele.attachEvent('on'+evt,function(){fn.call(obj)},false);
};
}
},
createForm:function(src){
EC.tid = 'J_'+new Date().getTime();
var form = document.createElement('form');
form.target = EC.tid;
form.method = 'get';
form.style.display = 'none';
var input = document.createElement('input');
input.type = 'text';
input.name = 'encode_source';
input.value = src;
EC.form = form;
form.appendChild(input);
document.body.appendChild(form);
},
createIframe:function(callback){
var iframe = document.createElement('iframe');
iframe.name = EC.tid;
iframe.src = "about:blank";
iframe.width = iframe.height = iframe.frameBorder = iframe.border = 0;
document.body.appendChild(iframe);
EC.iframe = iframe;
/*
if(self.frames[EC.tid] != undefined && self.frames[EC.tid].name != EC.tid){
//hack for ie
self.frames[EC.tid].name = EC.tid;
}
*/
EC.bind(iframe,'load',function(){
callback.call(this,window.frames[EC.tid].location.href.split('encode_source=')[1]);
});
},
encode:function(src,callback,type){
var type = type ? (type.toLowerCase() == 'gbk' ? 'gbk' : 'utf8') : 'utf8';
if(type=='gbk'){
EC.createForm(src);
EC.createIframe(callback);
EC.form.submit();
}else{
callback.call(this,encodeURIComponent(src));
}
}
};
function $(id){return document.getElementById(id)};
$('btn_encode').onclick = function(){
EC.encode($('J_source').value,function(out){$('J_out').value = out;},$('J_type').value);
}
//]]>
</script>
</body>
</html>