Comments (6)
Here's my take on a polyfill usage with Flash fallback for IE < 10:
<!DOCTYPE HTML>
<html>
<head>
<meta charset='utf-8'/>
<script type="text/javascript" src="lib/jquery-1.9.1.js"></script>
<script type="text/javascript" src="lib/moxie.js"></script>
<script>
$(function () {
window.mOxie.Env.swf_url = "lib/Moxie.min.swf";
if (!window.FileReader) {
window.FileReader = mOxie.FileReader;
window.XMLHttpRequest = mOxie.XMLHttpRequest;
window.getFile = function (file) {
return file;
};
} else {
window.getFile = function (file) {
return file.getSource();
}
}
var ajax = function (method, url, data, successCallback, errorCallback) {
var ajaxRequest = new XMLHttpRequest();
ajaxRequest.onload = function () {
if (ajaxRequest.status === 200 || ajaxRequest.status === 0) {
successCallback(ajaxRequest.response);
} else {
errorCallback(ajaxRequest.status);
}
};
ajaxRequest.onerror = function (e) {
errorCallback(e);
};
ajaxRequest.open(method, url, true);
ajaxRequest.setRequestHeader('Content-Type', 'application/octet-stream');
ajaxRequest.send(data);
};
var showPreview = function (file, elem) {
var $elem = $(elem);
var reader = new FileReader();
var img = document.createElement("img");
img.onload = function () {
console.log(img);
$elem.append(img);
};
reader.onload = function (e) {
img.src = e.target.result;
};
reader.readAsDataURL(file.getSource());
};
fileInput = new mOxie.FileInput({
browse_button: "button"
});
fileInput.onchange = function (e) {
var file = e.target.files[0];
showPreview(file, "#preview");
ajax("post", "/something", getFile(file), function () {
console.log("success");
}, function (e) {
console.log("error", JSON.stringify(e));
});
};
fileInput.init();
});
</script>
</head>
<body>
<div id="button">The button</div>
<div id="preview"></div>
</body>
</html>
What's in here?
- Adding mOxie elements to the window overwriting the default implementations if any
- Registering the source of the Flash fallback globally
- FileInput that allows theming of the "input field" (not necessary in HTML5 mode if you don't need theming)
and finally preview and upload for HTML5 support and for fallback.
What I don't like is the need for the getFile()
method to work around the fact that for the HTML5 case file
is not a HTML5 File instance.
from moxie.
That's quite an in-depth take on mOxie I'd say. getFile()
definitely ruins the joy, but for now it's the only way to have it all straight. Suggestions are always welcome.
One thing that we could do though and I even think that was meant to work (need to check) is to use mOxie wrappers for FileReader and XMLHttpRequest in all cases, be there native FileReader or XMLHttpRequest or not. Internally those wrappers will use native facilities (if those are available) anyway.
from moxie.
Better documentation for FileInput
: https://github.com/moxiecode/moxie/wiki/File-Picker
from moxie.
The linked documentation is missing critical bits, especially how to set the swf_url. Without this example from @cburgmer this would have been very hard to figure out. Also would be good to explain at a high level that if you are using any one of these polyfills, you probably have to use them all because the File objects that get passed around are of the wrong type otherwise.
from moxie.
+1, it's nigh on impossible to discover how to use moxie with the current documentation. this issue is the only thing that has given me hints. there's currently nothing documenting how to get started, how to run tests, etc, in the documentation. this makes contributing and writing meaningful issues very difficult because it's impossible to know if you're hitting a bug or if you're just missing something that was undocumented (expected behavior and usage is completely undocumented as of now?!)
from moxie.
I've created a simple API on top of moxie to help (at least it does help ME) working with file uploads and upload queues.
So, until we can get better documentation on moxie, feel free to take a look (test, pull request, etc...) at https://github.com/reinaldoarrosi/fileupload
from moxie.
Related Issues (20)
- Flash FormData upload to S3 generates duplicate filename param and bombs out upload
- RangeError: Maximum call stack size exceeded - moxie.js - 1974
- preview picture in ie8 HOT 1
- A lot of Preview image cause memory leak HOT 6
- mOxie .onload is not executed in plupload >= 2.2.0 HOT 2
- Bug. Runtime flash and plupload.addFile() not working HOT 2
- mOxie namespace gone? v1.5.3 HOT 14
- Can't get the size of a gif image? HOT 3
- Infinite events cycle on Angular 2 + IE9 HOT 12
- Suggestion: Modifying the XMLHttpRequest Api HOT 2
- Headers not sending on IE9 with flash HOT 5
- How to get a blob as dataurl? HOT 2
- How to install it with flash? HOT 1
- Flash Runtime support put http request? HOT 1
- Image preview error HOT 2
- File picker - multiple files. HOT 2
- In IPv6 environment, it is impossible to upload files normally
- Hide the visually hidden file input from assistive technologies
- Flash losing support in Chrome at the end of 2020. Future plans..? HOT 1
- Inefficient regular expression (js/redos)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moxie.