streams/vendor/blueimp/jquery-file-upload/cors/postmessage.html

86 lines
2.3 KiB
HTML
Raw Normal View History

2020-09-24 23:45:54 +00:00
<!DOCTYPE html>
2014-10-05 08:18:50 +00:00
<!--
/*
2017-06-27 00:32:38 +00:00
* jQuery File Upload Plugin postMessage API
2014-10-05 08:18:50 +00:00
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
2017-06-27 00:32:38 +00:00
* https://opensource.org/licenses/MIT
2014-10-05 08:18:50 +00:00
*/
-->
<html lang="en">
2020-09-24 23:45:54 +00:00
<head>
<meta charset="utf-8" />
<title>jQuery File Upload Plugin postMessage API</title>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"
integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ"
crossorigin="anonymous"
></script>
</head>
<body>
<script>
'use strict';
var origin = /^https:\/\/example.org/,
target = new RegExp('^(http(s)?:)?\\/\\/' + location.host + '\\/');
$(window).on('message', function (e) {
e = e.originalEvent;
var s = e.data,
xhr = $.ajaxSettings.xhr(),
f;
if (!origin.test(e.origin)) {
throw new Error('Origin "' + e.origin + '" does not match ' + origin);
}
if (!target.test(e.data.url)) {
throw new Error(
'Target "' + e.data.url + '" does not match ' + target
);
}
$(xhr.upload).on('progress', function (ev) {
ev = ev.originalEvent;
e.source.postMessage(
{
id: s.id,
type: ev.type,
timeStamp: ev.timeStamp,
lengthComputable: ev.lengthComputable,
loaded: ev.loaded,
total: ev.total
},
e.origin
);
2014-10-05 08:18:50 +00:00
});
2020-09-24 23:45:54 +00:00
s.xhr = function () {
return xhr;
};
if (!(s.data instanceof Blob)) {
f = new FormData();
$.each(s.data, function (i, v) {
f.append(v.name, v.value);
});
s.data = f;
}
$.ajax(s).always(function (result, statusText, jqXHR) {
if (!jqXHR.done) {
2014-10-05 08:18:50 +00:00
jqXHR = result;
result = null;
2020-09-24 23:45:54 +00:00
}
e.source.postMessage(
{
id: s.id,
status: jqXHR.status,
statusText: statusText,
result: result,
headers: jqXHR.getAllResponseHeaders()
},
e.origin
);
});
});
</script>
</body>
2017-06-27 00:32:38 +00:00
</html>