forked from michmech/screenful
-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenful-upload.js
38 lines (36 loc) · 1.94 KB
/
screenful-upload.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
Screenful.Upload={
allowPurging: true,
start: function(){
Screenful.createEnvelope(true);
$("#envelope").html("<form id='middlebox'><div class='one'></div><div class='two' style='display: none'></div></form>");
var form="<form action='"+Screenful.Upload.url+"' method='post' enctype='multipart/form-data' target='frmUploadTarget'>";
form+="<div class='field'><input class='filebox' type='file' name='myfile'/></div>";
if(Screenful.Upload.allowPurging) form+="<div class='field'><label><input type='checkbox' name='purge'/> "+Screenful.Loc.uploadPurge+"</label></div>";
if(Screenful.Upload.instructions) form+="<div class='instructions'>"+Screenful.Upload.instructions+"</div>";
form+="<div class='field submit'><input class='button' type='submit' value='"+Screenful.Loc.upload+"'/>";
form+="<div class='error' style='display: none'>"+Screenful.Loc.uploadFail+"</div>";
form+="</form>";
$("#middlebox .one").append(form);
$("#middlebox .two").append("<div class='message'>"+Screenful.Loc.uploadSuccess+"</div>");
$("#middlebox .two").append("<div class='field ok'><button>"+Screenful.Loc.ok+"</button></div>");
$("#envelope").append("<iframe id='frmUploadTarget' name='frmUploadTarget' src='about:blank' style='width:0;height:0;border:0px solid #fff;'></iframe>");
$("#middlebox .one form").on("submit", function(){
$('#frmUploadTarget').one('load', function(){
var redirectUrl=$.trim(window.frames["frmUploadTarget"].document.body.textContent);
if(redirectUrl){
$("#middlebox .one").hide();
$("#middlebox .two").show();
$("#middlebox .two button").on("click", function(){
window.location=redirectUrl;
return false;
});
} else {
$("#middlebox .two").hide();
$("#middlebox .one").show();
$("#middlebox .one .error").show();
}
});
});
},
};
$(window).ready(Screenful.Upload.start);