diff options
Diffstat (limited to 'www/wiki/extensions/UploadWizard/resources/mw.fileApi.js')
-rw-r--r-- | www/wiki/extensions/UploadWizard/resources/mw.fileApi.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/www/wiki/extensions/UploadWizard/resources/mw.fileApi.js b/www/wiki/extensions/UploadWizard/resources/mw.fileApi.js new file mode 100644 index 00000000..86e1af04 --- /dev/null +++ b/www/wiki/extensions/UploadWizard/resources/mw.fileApi.js @@ -0,0 +1,35 @@ +/* miscellaneous fileApi routines -- partially copied from mediawiki.special.upload.js, must refactor... */ + +( function ( mw, $ ) { + + mw.fileApi = { + + /** + * Check if this is a recognizable image type... + * Also excludes files over 10M to avoid going insane on memory usage. + * + * TODO is there a way we can ask the browser what's supported in <img>s? + * TODO put SVG back after working around Firefox 7 bug <https://bugzilla.wikimedia.org/show_bug.cgi?id=31643> + * + * @param {File} file + * @return {boolean} + */ + isPreviewableFile: function ( file ) { + var known = [ 'image/png', 'image/gif', 'image/jpeg' ], + tooHuge = 10 * 1024 * 1024; + return this.isPreviewableVideo( file ) || ( $.inArray( file.type, known ) !== -1 ) && file.size > 0 && file.size < tooHuge; + }, + + /** + * Check if this is a recognizable video type... + * + * @param {File} file + * @return {boolean} + */ + isPreviewableVideo: function ( file ) { + var video = document.createElement( 'video' ); + return video.canPlayType && video.canPlayType( file.type ).replace( 'no', '' ) !== ''; + } + + }; +}( mediaWiki, jQuery ) ); |