vendor/assets/javascripts/webshims/shims/combos/27.js in webshims-rails-1.14.6 vs vendor/assets/javascripts/webshims/shims/combos/27.js in webshims-rails-1.15.2
- old
+ new
@@ -1248,15 +1248,15 @@
})();
})();
});
-;webshim.register('filereader', function($, webshim, window, document, undefined, featureOptions){
+;webshim.register('filereader-xhr', function($, webshim, window, document, undefined, featureOptions){
"use strict";
var mOxie, moxie, hasXDomain;
- var FormData = $.noop;
- var sel = 'input[type="file"].ws-filereader';
+ var sel = 'input[type="file"].ws-filereader, input[type="file"].ws-capture';
+ var hasFlash = swfmini.hasFlashPlayerVersion('10.3');
var loadMoxie = function (){
webshim.loader.loadList(['moxie']);
};
var _createFilePicker = function(){
var $input, picker, $parent, onReset;
@@ -1364,11 +1364,11 @@
}
}
}
);
var shimMoxiePath = webshim.cfg.basePath+'moxie/';
- var crossXMLMessage = 'You nedd a crossdomain.xml to get all "filereader" / "XHR2" / "CORS" features to work. Or host moxie.swf/moxie.xap on your server an configure filereader options: "swfpath"/"xappath"';
+ var crossXMLMessage = 'You nedd a crossdomain.xml to get all "filereader" / "XHR2" / "CORS" features to work. Or host moxie.swf on your server an configure filereader options: "swfpath"';
var testMoxie = function(options){
return (options.wsType == 'moxie' || (options.data && options.data instanceof mOxie.FormData) || (options.crossDomain && $.support.cors !== false && hasXDomain != 'no' && !noxhr.test(options.dataType || '')));
};
var createMoxieTransport = function (options){
@@ -1547,10 +1547,14 @@
return tmpTransport;
}
}
};
+ webshim.loader.addModule('moxie', {
+ src: 'moxie/js/moxie-'+ (hasFlash ? 'swf' : 'html4')
+ });
+
if(!featureOptions.progress){
featureOptions.progress = 'onprogress';
}
if(!featureOptions.uploadprogress){
@@ -1558,13 +1562,10 @@
}
if(!featureOptions.swfpath){
featureOptions.swfpath = shimMoxiePath+'flash/Moxie.min.swf';
}
- if(!featureOptions.xappath){
- featureOptions.xappath = shimMoxiePath+'silverlight/Moxie.min.xap';
- }
if($.support.cors !== false || !window.XDomainRequest){
delete transports.xdomain;
}
@@ -1587,12 +1588,12 @@
webshim.defineNodeNameProperty('input', 'files', {
prop: {
writeable: false,
get: function(){
if(this.type != 'file'){return null;}
- if(!$(this).hasClass('ws-filereader')){
- webshim.info("please add the 'ws-filereader' class to your input[type='file'] to implement files-property");
+ if(!$(this).is('.ws-filereader, .ws-capture')){
+ webshim.info("please add the 'ws-filereader'/'ws-capture' class to your input[type='file'] to implement files-property");
}
return webshim.data(this, 'fileList') || [];
}
}
}
@@ -1610,25 +1611,79 @@
picker.disable(boolVal);
}
});
webshim.onNodeNamesPropertyModify('input', 'value', function(value, boolVal, type){
- if(value === '' && this.type == 'file' && $(this).hasClass('ws-filereader')){
+ if(value === '' && this.type == 'file' && $(this).is('.ws-filereader, .ws-capture')){
webshim.data(this, 'fileList', []);
}
});
+ if(!document.createElement('canvas').toBlob){
+ webshim.defineNodeNameProperty('canvas', 'toBlob', {
+ prop: {
+ value: function(cb, type, qualitiy){
+ var dataURL;
+ var $canvas = $(this);
+ if(!type){
+ type = 'image/jpeg';
+ }
+ if(type == 'image/jpeg' && !qualitiy){
+ qualitiy = 0.8;
+ }
+ loadMoxie();
+ setTimeout(function(){
+ dataURL = $canvas.callProp('getAsDataURL', [type, qualitiy]);
+ webshim.ready('moxie', function(){
+ var img = new mOxie.Image();
+
+ img.onload = function() {
+ var blob = img.getAsBlob();
+ webshim.defineProperty(blob, '_wsDataURL', {
+ value: dataURL,
+ enumerable: false
+ });
+ cb(blob);
+ };
+ img.load(dataURL);
+ });
+ }, 9);
+ }
+ }
+ });
+
+ webshim.ready('url', function(){
+ var _nativeCreateObjectURL = URL.createObjectURL;
+ var _nativeRevokeObjectURL = URL.revokeObjectURL;
+
+ URL.createObjectURL = function(obj){
+ var url = obj;
+ if(obj._wsimgDataURL) {
+ url = obj._wsimgDataURL;
+ } else if(_nativeCreateObjectURL){
+ return _nativeCreateObjectURL.apply(this, arguments);
+ }
+ return url;
+ };
+
+ URL.revokeObjectURL = function(url){
+ if (_nativeRevokeObjectURL){
+ return _nativeRevokeObjectURL.apply(this, arguments);
+ }
+ };
+ });
+ }
+
window.FileReader = notReadyYet;
window.FormData = notReadyYet;
webshim.ready('moxie', function(){
var wsMimes = 'application/xml,xml';
moxie = window.moxie;
mOxie = window.mOxie;
mOxie.Env.swf_url = featureOptions.swfpath;
- mOxie.Env.xap_url = featureOptions.xappath;
window.FileReader = mOxie.FileReader;
window.FormData = function(form){
var appendData, i, len, files, fileI, fileLen, inputName;
@@ -1663,10 +1718,9 @@
}
}
return moxieData;
};
- FormData = window.FormData;
createFilePicker = _createFilePicker;
transports.moxie = createMoxieTransport;
featureOptions.mimeTypes = (featureOptions.mimeTypes) ? wsMimes+','+featureOptions.mimeTypes : wsMimes;