-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathindex.html
218 lines (212 loc) · 5.06 KB
/
index.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>围脖是个好图床</title>
<style type="text/css" media="screen">
*{
margin:0;padding:0;
font-family:arial, sans-serif;
color:#222;
}
html,body{
height:100%;width:100%;
background:#515151;
}
#drag{
position: absolute;
top:10%;left:10%;right:10%;bottom:10%;
border:3px dashed #333;
border-radius:2px;
background:#515151;
}
#drag-text{
position: absolute;
top:50%;left:0;right:0;
margin-top:-20px;
height:40px;
line-height:40px;
text-align:center;
font-size:20px;
color:#999;
}
#drag-fileElement{
position: absolute;
display: block;
top:0;left:0;bottom:0;right:0;
opacity: 0;
-moz-opacity: 0;
filter:alpha(opacity=0);
}
#rs{
position: absolute;
top:10%;left:10%;right:10%;bottom:10%;
border-radius:2px;
background:#eee;
box-shadow:0 0 3px #000;
text-align:center;
display: none;
}
.rs-btn{
height:45px;
position: absolute;
bottom:0;left:0;right:0;
}
.rs-top{
position: absolute;
top:10px;bottom:55px;left:10px;right:10px;
}
.rs-top-va-outer{
text-align: center;
width: 100%;
height: 100%;
display: table;
}
.rs-top-va-inner{
display: table-cell;
vertical-align: middle;
}
#rs-img{
max-height:100%;
max-width:100%;
border-radius:5px;
background:#fff;
}
#rs-text{
background-color: #eee;
padding: 8px 3px;
font-size: 16px;
border: none;
box-shadow:0 0 3px #333 inset;
border-radius: 2px;
text-align: center;
width: 80%;
}
#rs-close{
position: absolute;
right:0px;top:0px;
color:#444;
width:20px;height:20px;line-height:20px;text-align:center;
cursor: pointer;
}
.about{
position: absolute;
bottom:0;left:0;right:0;height:25px;
line-height:25px;text-align:center;
font-size:10px;
color:#666;
}
</style>
</head>
<body>
<div id="drag">
<div id="drag-text">
拖拽图片到这里喵~
</div>
<input type="file" id="drag-fileElement" />
</div>
<div id="rs">
<div class="rs-top">
<!--<div class="rs-top-va-outer">-->
<!--<span class="rs-top-va-inner">-->
<img src="" id="rs-img"/>
<!--</span>-->
<!--</div>-->
</div>
<div class="rs-btn"><input type="text" id="rs-text" readonly="readonly" onclick="this.select()" onmouseover="this.select()" onfocus="this.select()"/></div>
<div id="rs-close">x</div>
</div>
<div class="about">
感谢渣浪微博 | code by zythum_朱一
</div>
<script type="text/javascript">
var drag = document.getElementById('drag');
var dragT= document.getElementById('drag-text');
var dragF= document.getElementById('drag-fileElement');
var rs = document.getElementById('rs');
var rsT = document.getElementById('rs-text');
var rsI = document.getElementById('rs-img');
var rsC = document.getElementById('rs-close');
var t1 = '拖拽图片到这里喵~';
var t2 = '图片上传中喵~';
var upLoadUrl = 'upsina.php';
var upLoadFlag = true;
var upLoad = function(file, text){
var xhr = new XMLHttpRequest();
var url = upLoadUrl;
var data;
//check
if(upLoadFlag === false){
alert('正在上传文件');
return false;
}
if(!file && !text){
alert('文件不存在,请重试');
return false;
}
if(file && file.type.indexOf('image') === -1){
alert('文件不是图片格式,请重试');
return false;
}
if(text && !/^http/i.test(text)){
alert('图片地址必须http打头');
return false;
}
//upload
data = new FormData();
file && data.append('my_uploaded_file', file);
text && data.append('my_uploaded_url', text);
xhr.open("POST", url);
xhr.onreadystatechange = function(){
var rsText;
if(xhr.readyState == 4 && xhr.status == 200){
upLoadFlag = true;
dragT.innerHTML = t1;
rsText = xhr.responseText;
rs.style.display = 'block';
rsI.src = rsT.value = rsText;
}
}
xhr.send(data);
upLoadFlag = false;
dragT.innerHTML = t2;
}
var dropHandler = function(e){
var file,text;
e.preventDefault();
text = e.dataTransfer.getData && e.dataTransfer.getData('text/html');
text = text.match(/src\=\"(http.*?)\"/i);
text = text && text[1];
file = e.dataTransfer.files && e.dataTransfer.files[0];
upLoad(file, text);
}
var inputFileHandler = function(){
var file = dragF.files[0];
upLoad(file);
}
var popCloseHandler = function(){
rs.style.display = 'none';
rsT.value = rsI.src = '';
}
//event
document.body.addEventListener('dragenter', function(e) {
e.preventDefault();
}, false);
document.body.addEventListener('dragleave', function(e) {
e.preventDefault();
}, false);
document.body.addEventListener('dragover', function(e) {
e.preventDefault();
}, false);
document.body.addEventListener('drop', function(e) {
dropHandler(e);
}, false);
dragF.addEventListener('change', function() {
inputFileHandler();
}, false);
rsC.addEventListener('click', function() {
popCloseHandler();
}, false);
</script>
</body>
</html>