webshims-rails 1.14.1 → 1.14.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/lib/webshims-rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/webshims/extras/modernizr-custom.js +0 -0
  4. data/vendor/assets/javascripts/webshims/polyfiller.js +3 -8
  5. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/canvas2png.js +0 -0
  6. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/flashcanvas.js +0 -0
  7. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/flashcanvas.swf +0 -0
  8. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/proxy.php +0 -0
  9. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/save.php +0 -0
  10. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/canvas2png.js +0 -0
  11. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/flash10canvas.swf +0 -0
  12. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/flash9canvas.swf +0 -0
  13. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/flashcanvas.js +0 -0
  14. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/proxy.php +0 -0
  15. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/save.php +0 -0
  16. data/vendor/assets/javascripts/webshims/shims/color-picker.js +2 -2
  17. data/vendor/assets/javascripts/webshims/shims/combos/1.js +66 -43
  18. data/vendor/assets/javascripts/webshims/shims/combos/10.js +66 -31
  19. data/vendor/assets/javascripts/webshims/shims/combos/11.js +66 -31
  20. data/vendor/assets/javascripts/webshims/shims/combos/12.js +96 -59
  21. data/vendor/assets/javascripts/webshims/shims/combos/13.js +96 -59
  22. data/vendor/assets/javascripts/webshims/shims/combos/14.js +0 -0
  23. data/vendor/assets/javascripts/webshims/shims/combos/15.js +4 -1
  24. data/vendor/assets/javascripts/webshims/shims/combos/16.js +70 -44
  25. data/vendor/assets/javascripts/webshims/shims/combos/17.js +66 -31
  26. data/vendor/assets/javascripts/webshims/shims/combos/18.js +1241 -1126
  27. data/vendor/assets/javascripts/webshims/shims/combos/19.js +1272 -1214
  28. data/vendor/assets/javascripts/webshims/shims/combos/2.js +66 -43
  29. data/vendor/assets/javascripts/webshims/shims/combos/20.js +1272 -1214
  30. data/vendor/assets/javascripts/webshims/shims/combos/21.js +61 -92
  31. data/vendor/assets/javascripts/webshims/shims/combos/22.js +30 -16
  32. data/vendor/assets/javascripts/webshims/shims/combos/23.js +66 -43
  33. data/vendor/assets/javascripts/webshims/shims/combos/25.js +41 -85
  34. data/vendor/assets/javascripts/webshims/shims/combos/26.js +1556 -2316
  35. data/vendor/assets/javascripts/webshims/shims/combos/27.js +12 -10
  36. data/vendor/assets/javascripts/webshims/shims/combos/28.js +4 -1
  37. data/vendor/assets/javascripts/webshims/shims/combos/29.js +0 -0
  38. data/vendor/assets/javascripts/webshims/shims/combos/3.js +0 -0
  39. data/vendor/assets/javascripts/webshims/shims/combos/30.js +0 -0
  40. data/vendor/assets/javascripts/webshims/shims/combos/31.js +0 -0
  41. data/vendor/assets/javascripts/webshims/shims/combos/32.js +1175 -1095
  42. data/vendor/assets/javascripts/webshims/shims/combos/33.js +0 -0
  43. data/vendor/assets/javascripts/webshims/shims/combos/34.js +30 -16
  44. data/vendor/assets/javascripts/webshims/shims/combos/4.js +0 -0
  45. data/vendor/assets/javascripts/webshims/shims/combos/5.js +66 -31
  46. data/vendor/assets/javascripts/webshims/shims/combos/6.js +66 -31
  47. data/vendor/assets/javascripts/webshims/shims/combos/7.js +66 -43
  48. data/vendor/assets/javascripts/webshims/shims/combos/8.js +66 -43
  49. data/vendor/assets/javascripts/webshims/shims/combos/9.js +66 -31
  50. data/vendor/assets/javascripts/webshims/shims/combos/97.js +63 -28
  51. data/vendor/assets/javascripts/webshims/shims/combos/98.js +149 -74
  52. data/vendor/assets/javascripts/webshims/shims/combos/99.js +149 -74
  53. data/vendor/assets/javascripts/webshims/shims/combos/comboinfo.json +1 -1
  54. data/vendor/assets/javascripts/webshims/shims/details.js +0 -0
  55. data/vendor/assets/javascripts/webshims/shims/dom-extend.js +0 -0
  56. data/vendor/assets/javascripts/webshims/shims/es5.js +1175 -1095
  57. data/vendor/assets/javascripts/webshims/shims/excanvas.js +0 -0
  58. data/vendor/assets/javascripts/webshims/shims/filereader.js +10 -9
  59. data/vendor/assets/javascripts/webshims/shims/form-combat.js +0 -0
  60. data/vendor/assets/javascripts/webshims/shims/form-core.js +0 -0
  61. data/vendor/assets/javascripts/webshims/shims/form-datalist-lazy.js +0 -0
  62. data/vendor/assets/javascripts/webshims/shims/form-datalist.js +0 -0
  63. data/vendor/assets/javascripts/webshims/shims/form-fixrangechange.js +0 -0
  64. data/vendor/assets/javascripts/webshims/shims/form-message.js +0 -0
  65. data/vendor/assets/javascripts/webshims/shims/form-native-extend.js +0 -0
  66. data/vendor/assets/javascripts/webshims/shims/form-number-date-api.js +0 -0
  67. data/vendor/assets/javascripts/webshims/shims/form-number-date-ui.js +40 -11
  68. data/vendor/assets/javascripts/webshims/shims/form-shim-extend.js +4 -1
  69. data/vendor/assets/javascripts/webshims/shims/form-shim-extend2.js +2 -1
  70. data/vendor/assets/javascripts/webshims/shims/form-validation.js +80 -47
  71. data/vendor/assets/javascripts/webshims/shims/form-validators.js +19 -8
  72. data/vendor/assets/javascripts/webshims/shims/forms-picker.js +21 -1
  73. data/vendor/assets/javascripts/webshims/shims/geolocation.js +0 -0
  74. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-ar.js +0 -0
  75. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-ch-CN.js +0 -0
  76. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-cs.js +0 -0
  77. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-de.js +0 -0
  78. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-el.js +0 -0
  79. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-en.js +0 -0
  80. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-es.js +0 -0
  81. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-fa.js +130 -0
  82. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-fr.js +0 -0
  83. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-he.js +0 -0
  84. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-hi.js +0 -0
  85. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-hu.js +0 -0
  86. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-it.js +0 -0
  87. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-ja.js +0 -0
  88. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-lt.js +0 -0
  89. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-nl.js +0 -0
  90. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-pl.js +0 -0
  91. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-pt-BR.js +0 -0
  92. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-pt-PT.js +0 -0
  93. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-pt.js +0 -0
  94. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-ru.js +0 -0
  95. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-sv.js +0 -0
  96. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-zh-CN.js +0 -0
  97. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-zh-TW.js +130 -0
  98. data/vendor/assets/javascripts/webshims/shims/jajax.js +0 -0
  99. data/vendor/assets/javascripts/webshims/shims/jme/_icons.scss +186 -0
  100. data/vendor/assets/javascripts/webshims/shims/jme/b.js +63 -28
  101. data/vendor/assets/javascripts/webshims/shims/jme/c.js +86 -46
  102. data/vendor/assets/javascripts/webshims/shims/jme/controls.css +317 -211
  103. data/vendor/assets/javascripts/webshims/shims/jme/controls.scss +59 -223
  104. data/vendor/assets/javascripts/webshims/shims/jme/jme.eot +0 -0
  105. data/vendor/assets/javascripts/webshims/shims/jme/jme.svg +0 -0
  106. data/vendor/assets/javascripts/webshims/shims/jme/jme.ttf +0 -0
  107. data/vendor/assets/javascripts/webshims/shims/jme/jme.woff +0 -0
  108. data/vendor/assets/javascripts/webshims/shims/jme/mediacontrols-lazy.js +66 -14
  109. data/vendor/assets/javascripts/webshims/shims/jme/p.js +0 -0
  110. data/vendor/assets/javascripts/webshims/shims/jpicker/ChangeLog.txt +0 -0
  111. data/vendor/assets/javascripts/webshims/shims/jpicker/ReadMe.txt +0 -0
  112. data/vendor/assets/javascripts/webshims/shims/jpicker/images/AlphaBar.png +0 -0
  113. data/vendor/assets/javascripts/webshims/shims/jpicker/images/Bars.png +0 -0
  114. data/vendor/assets/javascripts/webshims/shims/jpicker/images/Maps.png +0 -0
  115. data/vendor/assets/javascripts/webshims/shims/jpicker/images/NoColor.png +0 -0
  116. data/vendor/assets/javascripts/webshims/shims/jpicker/images/bar-opacity.png +0 -0
  117. data/vendor/assets/javascripts/webshims/shims/jpicker/images/map-opacity.png +0 -0
  118. data/vendor/assets/javascripts/webshims/shims/jpicker/images/mappoint.gif +0 -0
  119. data/vendor/assets/javascripts/webshims/shims/jpicker/images/picker.gif +0 -0
  120. data/vendor/assets/javascripts/webshims/shims/jpicker/images/preview-opacity.png +0 -0
  121. data/vendor/assets/javascripts/webshims/shims/jpicker/images/rangearrows.gif +0 -0
  122. data/vendor/assets/javascripts/webshims/shims/jpicker/jpicker.css +55 -48
  123. data/vendor/assets/javascripts/webshims/shims/mediaelement-core.js +66 -43
  124. data/vendor/assets/javascripts/webshims/shims/mediaelement-debug.js +833 -0
  125. data/vendor/assets/javascripts/webshims/shims/mediaelement-jaris.js +31 -76
  126. data/vendor/assets/javascripts/webshims/shims/mediaelement-native-fix.js +0 -0
  127. data/vendor/assets/javascripts/webshims/shims/mediaelement-yt.js +0 -0
  128. data/vendor/assets/javascripts/webshims/shims/moxie/flash/Moxie.cdn.swf +0 -0
  129. data/vendor/assets/javascripts/webshims/shims/moxie/flash/Moxie.min.swf +0 -0
  130. data/vendor/assets/javascripts/webshims/shims/moxie/js/moxie.js +1542 -2303
  131. data/vendor/assets/javascripts/webshims/shims/moxie/silverlight/Moxie.cdn.xap +0 -0
  132. data/vendor/assets/javascripts/webshims/shims/moxie/silverlight/Moxie.min.xap +0 -0
  133. data/vendor/assets/javascripts/webshims/shims/picture.js +160 -79
  134. data/vendor/assets/javascripts/webshims/shims/plugins/jquery.ui.position.js +0 -0
  135. data/vendor/assets/javascripts/webshims/shims/promise.js +0 -0
  136. data/vendor/assets/javascripts/webshims/shims/range-ui.js +26 -20
  137. data/vendor/assets/javascripts/webshims/shims/sizzle.js +0 -0
  138. data/vendor/assets/javascripts/webshims/shims/styles/color-picker.png +0 -0
  139. data/vendor/assets/javascripts/webshims/shims/styles/forms-ext.css +444 -326
  140. data/vendor/assets/javascripts/webshims/shims/styles/forms-picker.css +379 -300
  141. data/vendor/assets/javascripts/webshims/shims/styles/progress.gif +0 -0
  142. data/vendor/assets/javascripts/webshims/shims/styles/progress.png +0 -0
  143. data/vendor/assets/javascripts/webshims/shims/styles/scss/_api-forms-ext.scss +8 -8
  144. data/vendor/assets/javascripts/webshims/shims/styles/scss/_api-shim.scss +0 -0
  145. data/vendor/assets/javascripts/webshims/shims/styles/scss/_extends.scss +0 -14
  146. data/vendor/assets/javascripts/webshims/shims/styles/scss/forms-ext.scss +104 -85
  147. data/vendor/assets/javascripts/webshims/shims/styles/scss/forms-picker.scss +20 -32
  148. data/vendor/assets/javascripts/webshims/shims/styles/scss/shim-ext.scss +0 -0
  149. data/vendor/assets/javascripts/webshims/shims/styles/scss/shim.scss +14 -34
  150. data/vendor/assets/javascripts/webshims/shims/styles/shim-ext.css +920 -728
  151. data/vendor/assets/javascripts/webshims/shims/styles/shim.css +471 -391
  152. data/vendor/assets/javascripts/webshims/shims/styles/widget.eot +0 -0
  153. data/vendor/assets/javascripts/webshims/shims/styles/widget.svg +0 -0
  154. data/vendor/assets/javascripts/webshims/shims/styles/widget.ttf +0 -0
  155. data/vendor/assets/javascripts/webshims/shims/styles/widget.woff +0 -0
  156. data/vendor/assets/javascripts/webshims/shims/swf/JarisFLVPlayer.swf +0 -0
  157. data/vendor/assets/javascripts/webshims/shims/swfmini-embed.js +0 -0
  158. data/vendor/assets/javascripts/webshims/shims/swfmini.js +0 -0
  159. data/vendor/assets/javascripts/webshims/shims/track-ui.js +0 -0
  160. data/vendor/assets/javascripts/webshims/shims/track.js +30 -16
  161. metadata +8 -4
  162. data/vendor/assets/javascripts/webshims/shims/styles/config.rb +0 -12
  163. data/vendor/assets/javascripts/webshims/shims/swf/filereader.swf +0 -0
@@ -156,8 +156,8 @@ webshims.register('mediaelement-jaris', function($, webshims, window, document,
156
156
  data.seeking = false;
157
157
  }, 300);
158
158
  },
159
- onConnectionFailed: function(){
160
- webshims.error('media error');
159
+ onConnectionFailed: function(jaris, data){
160
+ mediaelement.setError(data._elem, 'flash connection error');
161
161
  },
162
162
  onNotBuffering: function(jaris, data){
163
163
  setReadyState(3, data);
@@ -1073,6 +1073,13 @@ webshims.register('mediaelement-jaris', function($, webshims, window, document,
1073
1073
 
1074
1074
  if(hasFlash && $.cleanData){
1075
1075
  var oldClean = $.cleanData;
1076
+ var objElem = document.createElement('object');
1077
+ var noRemove = {
1078
+ SetVariable: 1,
1079
+ GetVariable: 1,
1080
+ SetReturnValue: 1,
1081
+ GetReturnValue: 1
1082
+ };
1076
1083
  var flashNames = {
1077
1084
  object: 1,
1078
1085
  OBJECT: 1
@@ -1080,6 +1087,7 @@ webshims.register('mediaelement-jaris', function($, webshims, window, document,
1080
1087
 
1081
1088
  $.cleanData = function(elems){
1082
1089
  var i, len, prop;
1090
+ var ret = oldClean.apply(this, arguments);
1083
1091
  if(elems && (len = elems.length) && loadedSwf){
1084
1092
 
1085
1093
  for(i = 0; i < len; i++){
@@ -1089,7 +1097,7 @@ webshims.register('mediaelement-jaris', function($, webshims, window, document,
1089
1097
  elems[i].api_pause();
1090
1098
  if(elems[i].readyState == 4){
1091
1099
  for (prop in elems[i]) {
1092
- if (typeof elems[i][prop] == "function") {
1100
+ if (!noRemove[prop] && !objElem[prop] && typeof elems[i][prop] == "function") {
1093
1101
  elems[i][prop] = null;
1094
1102
  }
1095
1103
  }
@@ -1099,7 +1107,7 @@ webshims.register('mediaelement-jaris', function($, webshims, window, document,
1099
1107
  }
1100
1108
 
1101
1109
  }
1102
- return oldClean.apply(this, arguments);
1110
+ return ret;
1103
1111
  };
1104
1112
  }
1105
1113
 
@@ -1171,62 +1179,6 @@ webshims.register('mediaelement-jaris', function($, webshims, window, document,
1171
1179
  } else if(!('media' in document.createElement('source'))){
1172
1180
  webshims.reflectProperties('source', ['media']);
1173
1181
  }
1174
- if(options.experimentallyMimetypeCheck){
1175
- (function(){
1176
- var ADDBACK = $.fn.addBack ? 'addBack' : 'andSelf';
1177
- var getMimeType = function(){
1178
- var done;
1179
- var unknown = 'media/unknown please provide mime type';
1180
- var media = $(this);
1181
- var xhrs = [];
1182
- media
1183
- .not('.ws-after-check')
1184
- .find('source')
1185
- [ADDBACK]()
1186
- .filter('[data-wsrecheckmimetype]:not([type])')
1187
- .each(function(){
1188
- var source = $(this).removeAttr('data-wsrecheckmimetype');
1189
- var error = function(){
1190
- source.attr('data-type', unknown);
1191
- };
1192
- try {
1193
- xhrs.push(
1194
- $.ajax({
1195
- type: 'head',
1196
- url: $.attr(this, 'src'),
1197
- success: function(content, status, xhr){
1198
- var mime = xhr.getResponseHeader('Content-Type');
1199
- if(mime){
1200
- done = true;
1201
- }
1202
- source.attr('data-type', mime || unknown);
1203
- },
1204
- error: error
1205
- })
1206
- )
1207
- ;
1208
- } catch(er){
1209
- error();
1210
- }
1211
- })
1212
- ;
1213
- if(xhrs.length){
1214
- media.addClass('ws-after-check');
1215
- $.when.apply($, xhrs).always(function(){
1216
- media.mediaLoad();
1217
- setTimeout(function(){
1218
- media.removeClass('ws-after-check');
1219
- }, 9);
1220
- });
1221
- }
1222
- };
1223
- $('audio.media-error, video.media-error').each(getMimeType);
1224
- $(document).on('mediaerror', function(e){
1225
- getMimeType.call(e.target);
1226
- });
1227
- })();
1228
- }
1229
-
1230
1182
 
1231
1183
  if(hasNative && hasFlash && !options.preferFlash){
1232
1184
  var switchErrors = {
@@ -1235,35 +1187,38 @@ webshims.register('mediaelement-jaris', function($, webshims, window, document,
1235
1187
  };
1236
1188
  var switchOptions = function(e){
1237
1189
  var media, error, parent;
1238
- if(!options.preferFlash &&
1190
+ if(
1239
1191
  ($(e.target).is('audio, video') || ((parent = e.target.parentNode) && $('source', parent).last()[0] == e.target)) &&
1240
- (media = $(e.target).closest('audio, video')) && (error = media.prop('error')) && switchErrors[error.code]
1192
+ (media = $(e.target).closest('audio, video')) && !media.is('.nonnative-api-active')
1241
1193
  ){
1242
-
1243
- if(!options.preferFlash){
1194
+ error = media.prop('error');
1195
+ setTimeout(function(){
1244
1196
  if(!media.is('.nonnative-api-active')){
1245
- options.preferFlash = true;
1246
- document.removeEventListener('error', switchOptions, true);
1247
- $('audio, video').each(function(){
1248
- webshims.mediaelement.selectSource(this);
1249
- });
1250
- webshims.error("switching mediaelements option to 'preferFlash', due to an error with native player: "+e.target.src+" Mediaerror: "+ media.prop('error')+ 'first error: '+ error);
1197
+ if(error && switchErrors[error.code]){
1198
+ options.preferFlash = true;
1199
+ document.removeEventListener('error', switchOptions, true);
1200
+ $('audio, video').each(function(){
1201
+ webshims.mediaelement.selectSource(this);
1202
+ });
1203
+ webshims.error("switching mediaelements option to 'preferFlash', due to an error with native player: "+e.target.currentSrc+" Mediaerror: "+ media.prop('error')+ ' error.code: '+ error.code);
1204
+ }
1205
+ webshims.warn('There was a mediaelement error. Run the following line in your console to get more info: webshim.mediaelement.loadDebugger();')
1251
1206
  }
1252
- } else{
1253
- document.removeEventListener('error', switchOptions, true);
1254
- }
1207
+ });
1208
+
1209
+
1255
1210
  }
1256
1211
  };
1212
+
1213
+ document.addEventListener('error', switchOptions, true);
1257
1214
  setTimeout(function(){
1258
- document.addEventListener('error', switchOptions, true);
1259
1215
  $('audio, video').each(function(){
1260
1216
  var error = $.prop(this, 'error');
1261
1217
  if(error && switchErrors[error]){
1262
1218
  switchOptions({target: this});
1263
- return false;
1264
1219
  }
1265
1220
  });
1266
- }, 9);
1221
+ });
1267
1222
  }
1268
1223
 
1269
1224
  });
@@ -3159,6 +3159,15 @@ define('moxie/file/File', [
3159
3159
  @default UID
3160
3160
  */
3161
3161
  name: name || Basic.guid('file_'),
3162
+
3163
+ /**
3164
+ Relative path to the file inside a directory
3165
+
3166
+ @property relativePath
3167
+ @type {String}
3168
+ @default ''
3169
+ */
3170
+ relativePath: '',
3162
3171
 
3163
3172
  /**
3164
3173
  Date of last modification
@@ -3513,7 +3522,6 @@ define('moxie/file/FileInput', [
3513
3522
  return FileInput;
3514
3523
  });
3515
3524
 
3516
-
3517
3525
  // Included from: src/javascript/runtime/RuntimeTarget.js
3518
3526
 
3519
3527
  /**
@@ -5123,10 +5131,10 @@ define("moxie/xhr/XMLHttpRequest", [
5123
5131
  return XMLHttpRequest;
5124
5132
  });
5125
5133
 
5126
- // Included from: src/javascript/runtime/Transporter.js
5134
+ // Included from: src/javascript/runtime/flash/Runtime.js
5127
5135
 
5128
5136
  /**
5129
- * Transporter.js
5137
+ * Runtime.js
5130
5138
  *
5131
5139
  * Copyright 2013, Moxiecode Systems AB
5132
5140
  * Released under GPL License.
@@ -5135,136 +5143,226 @@ define("moxie/xhr/XMLHttpRequest", [
5135
5143
  * Contributing: http://www.plupload.com/contributing
5136
5144
  */
5137
5145
 
5138
- define("moxie/runtime/Transporter", [
5139
- "moxie/core/utils/Basic",
5140
- "moxie/core/utils/Encode",
5141
- "moxie/runtime/RuntimeClient",
5142
- "moxie/core/EventTarget"
5143
- ], function(Basic, Encode, RuntimeClient, EventTarget) {
5144
- function Transporter() {
5145
- var mod, _runtime, _data, _size, _pos, _chunk_size;
5146
-
5147
- RuntimeClient.call(this);
5146
+ /*global ActiveXObject:true */
5148
5147
 
5149
- Basic.extend(this, {
5150
- uid: Basic.guid('uid_'),
5148
+ /**
5149
+ Defines constructor for Flash runtime.
5151
5150
 
5152
- state: Transporter.IDLE,
5151
+ @class moxie/runtime/flash/Runtime
5152
+ @private
5153
+ */
5154
+ define("moxie/runtime/flash/Runtime", [
5155
+ "moxie/core/utils/Basic",
5156
+ "moxie/core/utils/Env",
5157
+ "moxie/core/utils/Dom",
5158
+ "moxie/core/Exceptions",
5159
+ "moxie/runtime/Runtime"
5160
+ ], function(Basic, Env, Dom, x, Runtime) {
5161
+
5162
+ var type = 'flash', extensions = {};
5153
5163
 
5154
- result: null,
5164
+ /**
5165
+ Get the version of the Flash Player
5155
5166
 
5156
- transport: function(data, type, options) {
5157
- var self = this;
5167
+ @method getShimVersion
5168
+ @private
5169
+ @return {Number} Flash Player version
5170
+ */
5171
+ function getShimVersion() {
5172
+ var version;
5158
5173
 
5159
- options = Basic.extend({
5160
- chunk_size: 204798
5161
- }, options);
5174
+ try {
5175
+ version = navigator.plugins['Shockwave Flash'];
5176
+ version = version.description;
5177
+ } catch (e1) {
5178
+ try {
5179
+ version = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
5180
+ } catch (e2) {
5181
+ version = '0.0';
5182
+ }
5183
+ }
5184
+ version = version.match(/\d+/g);
5185
+ return parseFloat(version[0] + '.' + version[1]);
5186
+ }
5162
5187
 
5163
- // should divide by three, base64 requires this
5164
- if ((mod = options.chunk_size % 3)) {
5165
- options.chunk_size += 3 - mod;
5166
- }
5188
+ /**
5189
+ Constructor for the Flash Runtime
5167
5190
 
5168
- _chunk_size = options.chunk_size;
5191
+ @class FlashRuntime
5192
+ @extends Runtime
5193
+ */
5194
+ function FlashRuntime(options) {
5195
+ var I = this, initTimer;
5169
5196
 
5170
- _reset.call(this);
5171
- _data = data;
5172
- _size = data.length;
5197
+ options = Basic.extend({ swf_url: Env.swf_url }, options);
5173
5198
 
5174
- if (Basic.typeOf(options) === 'string' || options.ruid) {
5175
- _run.call(self, type, this.connectRuntime(options));
5176
- } else {
5177
- // we require this to run only once
5178
- var cb = function(e, runtime) {
5179
- self.unbind("RuntimeInit", cb);
5180
- _run.call(self, type, runtime);
5181
- };
5182
- this.bind("RuntimeInit", cb);
5183
- this.connectRuntime(options);
5184
- }
5199
+ Runtime.call(this, options, type, {
5200
+ access_binary: function(value) {
5201
+ return value && I.mode === 'browser';
5202
+ },
5203
+ access_image_binary: function(value) {
5204
+ return value && I.mode === 'browser';
5205
+ },
5206
+ display_media: Runtime.capTrue,
5207
+ do_cors: Runtime.capTrue,
5208
+ drag_and_drop: false,
5209
+ report_upload_progress: function() {
5210
+ return I.mode === 'client';
5211
+ },
5212
+ resize_image: Runtime.capTrue,
5213
+ return_response_headers: false,
5214
+ return_response_type: function(responseType) {
5215
+ if (responseType === 'json' && !!window.JSON) {
5216
+ return true;
5217
+ }
5218
+ return !Basic.arrayDiff(responseType, ['', 'text', 'document']) || I.mode === 'browser';
5219
+ },
5220
+ return_status_code: function(code) {
5221
+ return I.mode === 'browser' || !Basic.arrayDiff(code, [200, 404]);
5222
+ },
5223
+ select_file: Runtime.capTrue,
5224
+ select_multiple: Runtime.capTrue,
5225
+ send_binary_string: function(value) {
5226
+ return value && I.mode === 'browser';
5227
+ },
5228
+ send_browser_cookies: function(value) {
5229
+ return value && I.mode === 'browser';
5230
+ },
5231
+ send_custom_headers: function(value) {
5232
+ return value && I.mode === 'browser';
5233
+ },
5234
+ send_multipart: Runtime.capTrue,
5235
+ slice_blob: function(value) {
5236
+ return value && I.mode === 'browser';
5237
+ },
5238
+ stream_upload: function(value) {
5239
+ return value && I.mode === 'browser';
5240
+ },
5241
+ summon_file_dialog: false,
5242
+ upload_filesize: function(size) {
5243
+ return Basic.parseSizeStr(size) <= 2097152 || I.mode === 'client';
5244
+ },
5245
+ use_http_method: function(methods) {
5246
+ return !Basic.arrayDiff(methods, ['GET', 'POST']);
5247
+ }
5248
+ }, {
5249
+ // capabilities that require specific mode
5250
+ access_binary: function(value) {
5251
+ return value ? 'browser' : 'client';
5252
+ },
5253
+ access_image_binary: function(value) {
5254
+ return value ? 'browser' : 'client';
5255
+ },
5256
+ report_upload_progress: function(value) {
5257
+ return value ? 'browser' : 'client';
5258
+ },
5259
+ return_response_type: function(responseType) {
5260
+ return Basic.arrayDiff(responseType, ['', 'text', 'json', 'document']) ? 'browser' : ['client', 'browser'];
5261
+ },
5262
+ return_status_code: function(code) {
5263
+ return Basic.arrayDiff(code, [200, 404]) ? 'browser' : ['client', 'browser'];
5264
+ },
5265
+ send_binary_string: function(value) {
5266
+ return value ? 'browser' : 'client';
5267
+ },
5268
+ send_browser_cookies: function(value) {
5269
+ return value ? 'browser' : 'client';
5270
+ },
5271
+ send_custom_headers: function(value) {
5272
+ return value ? 'browser' : 'client';
5273
+ },
5274
+ stream_upload: function(value) {
5275
+ return value ? 'client' : 'browser';
5185
5276
  },
5277
+ upload_filesize: function(size) {
5278
+ return Basic.parseSizeStr(size) >= 2097152 ? 'client' : 'browser';
5279
+ }
5280
+ }, 'client');
5186
5281
 
5187
- abort: function() {
5188
- var self = this;
5189
5282
 
5190
- self.state = Transporter.IDLE;
5191
- if (_runtime) {
5192
- _runtime.exec.call(self, 'Transporter', 'clear');
5193
- self.trigger("TransportingAborted");
5194
- }
5283
+ // minimal requirement for Flash Player version
5284
+ if (getShimVersion() < 10) {
5285
+ this.mode = false; // with falsy mode, runtime won't operable, no matter what the mode was before
5286
+ }
5195
5287
 
5196
- _reset.call(self);
5197
- },
5198
5288
 
5289
+ Basic.extend(this, {
5199
5290
 
5200
- destroy: function() {
5201
- this.unbindAll();
5202
- _runtime = null;
5203
- this.disconnectRuntime();
5204
- _reset.call(this);
5205
- }
5206
- });
5291
+ getShim: function() {
5292
+ return Dom.get(this.uid);
5293
+ },
5207
5294
 
5208
- function _reset() {
5209
- _size = _pos = 0;
5210
- _data = this.result = null;
5211
- }
5295
+ shimExec: function(component, action) {
5296
+ var args = [].slice.call(arguments, 2);
5297
+ return I.getShim().exec(this.uid, component, action, args);
5298
+ },
5212
5299
 
5213
- function _run(type, runtime) {
5214
- var self = this;
5300
+ init: function() {
5301
+ var html, el, container;
5215
5302
 
5216
- _runtime = runtime;
5303
+ container = this.getShimContainer();
5217
5304
 
5218
- //self.unbind("RuntimeInit");
5305
+ // if not the minimal height, shims are not initialized in older browsers (e.g FF3.6, IE6,7,8, Safari 4.0,5.0, etc)
5306
+ Basic.extend(container.style, {
5307
+ position: 'absolute',
5308
+ top: '-8px',
5309
+ left: '-8px',
5310
+ width: '9px',
5311
+ height: '9px',
5312
+ overflow: 'hidden'
5313
+ });
5219
5314
 
5220
- self.bind("TransportingProgress", function(e) {
5221
- _pos = e.loaded;
5315
+ // insert flash object
5316
+ html = '<object id="' + this.uid + '" type="application/x-shockwave-flash" data="' + options.swf_url + '" ';
5222
5317
 
5223
- if (_pos < _size && Basic.inArray(self.state, [Transporter.IDLE, Transporter.DONE]) === -1) {
5224
- _transport.call(self);
5318
+ if (Env.browser === 'IE') {
5319
+ html += 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
5225
5320
  }
5226
- }, 999);
5227
5321
 
5228
- self.bind("TransportingComplete", function() {
5229
- _pos = _size;
5230
- self.state = Transporter.DONE;
5231
- _data = null; // clean a bit
5232
- self.result = _runtime.exec.call(self, 'Transporter', 'getAsBlob', type || '');
5233
- }, 999);
5322
+ html += 'width="100%" height="100%" style="outline:0">' +
5323
+ '<param name="movie" value="' + options.swf_url + '" />' +
5324
+ '<param name="flashvars" value="uid=' + escape(this.uid) + '&target=' + Env.global_event_dispatcher + '" />' +
5325
+ '<param name="wmode" value="transparent" />' +
5326
+ '<param name="allowscriptaccess" value="always" />' +
5327
+ '</object>';
5234
5328
 
5235
- self.state = Transporter.BUSY;
5236
- self.trigger("TransportingStarted");
5237
- _transport.call(self);
5238
- }
5329
+ if (Env.browser === 'IE') {
5330
+ el = document.createElement('div');
5331
+ container.appendChild(el);
5332
+ el.outerHTML = html;
5333
+ el = container = null; // just in case
5334
+ } else {
5335
+ container.innerHTML = html;
5336
+ }
5239
5337
 
5240
- function _transport() {
5241
- var self = this,
5242
- chunk,
5243
- bytesLeft = _size - _pos;
5338
+ // Init is dispatched by the shim
5339
+ initTimer = setTimeout(function() {
5340
+ if (I && !I.initialized) { // runtime might be already destroyed by this moment
5341
+ I.trigger("Error", new x.RuntimeError(x.RuntimeError.NOT_INIT_ERR));
5342
+ }
5343
+ }, 5000);
5344
+ },
5244
5345
 
5245
- if (_chunk_size > bytesLeft) {
5246
- _chunk_size = bytesLeft;
5247
- }
5346
+ destroy: (function(destroy) { // extend default destroy method
5347
+ return function() {
5348
+ destroy.call(I);
5349
+ clearTimeout(initTimer); // initialization check might be still onwait
5350
+ options = initTimer = destroy = I = null;
5351
+ };
5352
+ }(this.destroy))
5248
5353
 
5249
- chunk = Encode.btoa(_data.substr(_pos, _chunk_size));
5250
- _runtime.exec.call(self, 'Transporter', 'receive', chunk, _size);
5251
- }
5354
+ }, extensions);
5252
5355
  }
5253
5356
 
5254
- Transporter.IDLE = 0;
5255
- Transporter.BUSY = 1;
5256
- Transporter.DONE = 2;
5257
-
5258
- Transporter.prototype = EventTarget.instance;
5357
+ Runtime.addConstructor(type, FlashRuntime);
5259
5358
 
5260
- return Transporter;
5359
+ return extensions;
5261
5360
  });
5262
5361
 
5263
-
5264
- // Included from: src/javascript/runtime/html5/Runtime.js
5362
+ // Included from: src/javascript/runtime/flash/file/Blob.js
5265
5363
 
5266
5364
  /**
5267
- * Runtime.js
5365
+ * Blob.js
5268
5366
  *
5269
5367
  * Copyright 2013, Moxiecode Systems AB
5270
5368
  * Released under GPL License.
@@ -5273,118 +5371,47 @@ define("moxie/runtime/Transporter", [
5273
5371
  * Contributing: http://www.plupload.com/contributing
5274
5372
  */
5275
5373
 
5276
- /*global File:true */
5277
-
5278
5374
  /**
5279
- Defines constructor for HTML5 runtime.
5280
-
5281
- @class moxie/runtime/html5/Runtime
5375
+ @class moxie/runtime/flash/file/Blob
5282
5376
  @private
5283
5377
  */
5284
- define("moxie/runtime/html5/Runtime", [
5285
- "moxie/core/utils/Basic",
5286
- "moxie/core/Exceptions",
5287
- "moxie/runtime/Runtime",
5288
- "moxie/core/utils/Env"
5289
- ], function(Basic, x, Runtime, Env) {
5290
-
5291
- var type = "html5", extensions = {};
5292
-
5293
- function Html5Runtime(options) {
5294
- var I = this
5295
- , Test = Runtime.capTest
5296
- , True = Runtime.capTrue
5297
- ;
5298
-
5299
- var caps = Basic.extend({
5300
- access_binary: Test(window.FileReader || window.File && window.File.getAsDataURL),
5301
- access_image_binary: function() {
5302
- return I.can('access_binary') && !!extensions.Image;
5303
- },
5304
- display_media: Test(Env.can('create_canvas') || Env.can('use_data_uri_over32kb')),
5305
- do_cors: Test(window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest()),
5306
- drag_and_drop: Test(function() {
5307
- // this comes directly from Modernizr: http://www.modernizr.com/
5308
- var div = document.createElement('div');
5309
- // IE has support for drag and drop since version 5, but doesn't support dropping files from desktop
5310
- return (('draggable' in div) || ('ondragstart' in div && 'ondrop' in div)) && (Env.browser !== 'IE' || Env.version > 9);
5311
- }()),
5312
- filter_by_extension: Test(function() { // if you know how to feature-detect this, please suggest
5313
- return (Env.browser === 'Chrome' && Env.version >= 28) || (Env.browser === 'IE' && Env.version >= 10);
5314
- }()),
5315
- return_response_headers: True,
5316
- return_response_type: function(responseType) {
5317
- if (responseType === 'json' && !!window.JSON) { // we can fake this one even if it's not supported
5318
- return true;
5319
- }
5320
- return Env.can('return_response_type', responseType);
5321
- },
5322
- return_status_code: True,
5323
- report_upload_progress: Test(window.XMLHttpRequest && new XMLHttpRequest().upload),
5324
- resize_image: function() {
5325
- return I.can('access_binary') && Env.can('create_canvas');
5326
- },
5327
- select_file: function() {
5328
- return Env.can('use_fileinput') && window.File;
5329
- },
5330
- select_folder: function() {
5331
- return I.can('select_file') && Env.browser === 'Chrome' && Env.version >= 21;
5332
- },
5333
- select_multiple: function() {
5334
- // it is buggy on Safari Windows and iOS
5335
- return I.can('select_file') &&
5336
- !(Env.browser === 'Safari' && Env.os === 'Windows') &&
5337
- !(Env.os === 'iOS' && Env.verComp(Env.osVersion, "7.0.4", '<'));
5338
- },
5339
- send_binary_string: Test(window.XMLHttpRequest && (new XMLHttpRequest().sendAsBinary || (window.Uint8Array && window.ArrayBuffer))),
5340
- send_custom_headers: Test(window.XMLHttpRequest),
5341
- send_multipart: function() {
5342
- return !!(window.XMLHttpRequest && new XMLHttpRequest().upload && window.FormData) || I.can('send_binary_string');
5343
- },
5344
- slice_blob: Test(window.File && (File.prototype.mozSlice || File.prototype.webkitSlice || File.prototype.slice)),
5345
- stream_upload: function(){
5346
- return I.can('slice_blob') && I.can('send_multipart');
5347
- },
5348
- summon_file_dialog: Test(function() { // yeah... some dirty sniffing here...
5349
- return (Env.browser === 'Firefox' && Env.version >= 4) ||
5350
- (Env.browser === 'Opera' && Env.version >= 12) ||
5351
- (Env.browser === 'IE' && Env.version >= 10) ||
5352
- !!~Basic.inArray(Env.browser, ['Chrome', 'Safari']);
5353
- }()),
5354
- upload_filesize: True
5355
- },
5356
- arguments[2]
5357
- );
5358
-
5359
- Runtime.call(this, options, (arguments[1] || type), caps);
5360
-
5378
+ define("moxie/runtime/flash/file/Blob", [
5379
+ "moxie/runtime/flash/Runtime",
5380
+ "moxie/file/Blob"
5381
+ ], function(extensions, Blob) {
5361
5382
 
5362
- Basic.extend(this, {
5383
+ var FlashBlob = {
5384
+ slice: function(blob, start, end, type) {
5385
+ var self = this.getRuntime();
5363
5386
 
5364
- init : function() {
5365
- this.trigger("Init");
5366
- },
5387
+ if (start < 0) {
5388
+ start = Math.max(blob.size + start, 0);
5389
+ } else if (start > 0) {
5390
+ start = Math.min(start, blob.size);
5391
+ }
5367
5392
 
5368
- destroy: (function(destroy) { // extend default destroy method
5369
- return function() {
5370
- destroy.call(I);
5371
- destroy = I = null;
5372
- };
5373
- }(this.destroy))
5374
- });
5393
+ if (end < 0) {
5394
+ end = Math.max(blob.size + end, 0);
5395
+ } else if (end > 0) {
5396
+ end = Math.min(end, blob.size);
5397
+ }
5375
5398
 
5376
- Basic.extend(this.getShim(), extensions);
5377
- }
5399
+ blob = self.shimExec.call(this, 'Blob', 'slice', start, end, type || '');
5378
5400
 
5379
- Runtime.addConstructor(type, Html5Runtime);
5401
+ if (blob) {
5402
+ blob = new Blob(self.uid, blob);
5403
+ }
5404
+ return blob;
5405
+ }
5406
+ };
5380
5407
 
5381
- return extensions;
5408
+ return (extensions.Blob = FlashBlob);
5382
5409
  });
5383
5410
 
5384
- // Included from: src/javascript/runtime/html5/file/Blob.js
5411
+ // Included from: src/javascript/runtime/flash/file/FileInput.js
5385
5412
 
5386
5413
  /**
5387
- * Blob.js
5414
+ * FileInput.js
5388
5415
  *
5389
5416
  * Copyright 2013, Moxiecode Systems AB
5390
5417
  * Released under GPL License.
@@ -5394,46 +5421,31 @@ define("moxie/runtime/html5/Runtime", [
5394
5421
  */
5395
5422
 
5396
5423
  /**
5397
- @class moxie/runtime/html5/file/Blob
5424
+ @class moxie/runtime/flash/file/FileInput
5398
5425
  @private
5399
5426
  */
5400
- define("moxie/runtime/html5/file/Blob", [
5401
- "moxie/runtime/html5/Runtime",
5402
- "moxie/file/Blob"
5403
- ], function(extensions, Blob) {
5404
-
5405
- function HTML5Blob() {
5406
- function w3cBlobSlice(blob, start, end) {
5407
- var blobSlice;
5408
-
5409
- if (window.File.prototype.slice) {
5410
- try {
5411
- blob.slice(); // depricated version will throw WRONG_ARGUMENTS_ERR exception
5412
- return blob.slice(start, end);
5413
- } catch (e) {
5414
- // depricated slice method
5415
- return blob.slice(start, end - start);
5416
- }
5417
- // slice method got prefixed: https://bugzilla.mozilla.org/show_bug.cgi?id=649672
5418
- } else if ((blobSlice = window.File.prototype.webkitSlice || window.File.prototype.mozSlice)) {
5419
- return blobSlice.call(blob, start, end);
5420
- } else {
5421
- return null; // or throw some exception
5422
- }
5427
+ define("moxie/runtime/flash/file/FileInput", [
5428
+ "moxie/runtime/flash/Runtime"
5429
+ ], function(extensions) {
5430
+
5431
+ var FileInput = {
5432
+ init: function(options) {
5433
+ this.getRuntime().shimExec.call(this, 'FileInput', 'init', {
5434
+ name: options.name,
5435
+ accept: options.accept,
5436
+ multiple: options.multiple
5437
+ });
5438
+ this.trigger('ready');
5423
5439
  }
5440
+ };
5424
5441
 
5425
- this.slice = function() {
5426
- return new Blob(this.getRuntime().uid, w3cBlobSlice.apply(this, arguments));
5427
- };
5428
- }
5429
-
5430
- return (extensions.Blob = HTML5Blob);
5442
+ return (extensions.FileInput = FileInput);
5431
5443
  });
5432
5444
 
5433
- // Included from: src/javascript/core/utils/Events.js
5445
+ // Included from: src/javascript/runtime/flash/file/FileReader.js
5434
5446
 
5435
5447
  /**
5436
- * Events.js
5448
+ * FileReader.js
5437
5449
  *
5438
5450
  * Copyright 2013, Moxiecode Systems AB
5439
5451
  * Released under GPL License.
@@ -5442,171 +5454,63 @@ define("moxie/runtime/html5/file/Blob", [
5442
5454
  * Contributing: http://www.plupload.com/contributing
5443
5455
  */
5444
5456
 
5445
- define('moxie/core/utils/Events', [
5446
- 'moxie/core/utils/Basic'
5447
- ], function(Basic) {
5448
- var eventhash = {}, uid = 'moxie_' + Basic.guid();
5449
-
5450
- // IE W3C like event funcs
5451
- function preventDefault() {
5452
- this.returnValue = false;
5453
- }
5457
+ /**
5458
+ @class moxie/runtime/flash/file/FileReader
5459
+ @private
5460
+ */
5461
+ define("moxie/runtime/flash/file/FileReader", [
5462
+ "moxie/runtime/flash/Runtime",
5463
+ "moxie/core/utils/Encode"
5464
+ ], function(extensions, Encode) {
5454
5465
 
5455
- function stopPropagation() {
5456
- this.cancelBubble = true;
5466
+ var _result = '';
5467
+
5468
+ function _formatData(data, op) {
5469
+ switch (op) {
5470
+ case 'readAsText':
5471
+ return Encode.atob(data, 'utf8');
5472
+ case 'readAsBinaryString':
5473
+ return Encode.atob(data);
5474
+ case 'readAsDataURL':
5475
+ return data;
5476
+ }
5477
+ return null;
5457
5478
  }
5458
5479
 
5459
- /**
5460
- Adds an event handler to the specified object and store reference to the handler
5461
- in objects internal Plupload registry (@see removeEvent).
5462
-
5463
- @method addEvent
5464
- @for Utils
5465
- @static
5466
- @param {Object} obj DOM element like object to add handler to.
5467
- @param {String} name Name to add event listener to.
5468
- @param {Function} callback Function to call when event occurs.
5469
- @param {String} [key] that might be used to add specifity to the event record.
5470
- */
5471
- var addEvent = function(obj, name, callback, key) {
5472
- var func, events;
5473
-
5474
- name = name.toLowerCase();
5480
+ var FileReader = {
5481
+ read: function(op, blob) {
5482
+ var target = this, self = target.getRuntime();
5475
5483
 
5476
- // Add event listener
5477
- if (obj.addEventListener) {
5478
- func = callback;
5479
-
5480
- obj.addEventListener(name, func, false);
5481
- } else if (obj.attachEvent) {
5482
- func = function() {
5483
- var evt = window.event;
5484
+ // special prefix for DataURL read mode
5485
+ if (op === 'readAsDataURL') {
5486
+ _result = 'data:' + (blob.type || '') + ';base64,';
5487
+ }
5484
5488
 
5485
- if (!evt.target) {
5486
- evt.target = evt.srcElement;
5489
+ target.bind('Progress', function(e, data) {
5490
+ if (data) {
5491
+ _result += _formatData(data, op);
5487
5492
  }
5493
+ });
5488
5494
 
5489
- evt.preventDefault = preventDefault;
5490
- evt.stopPropagation = stopPropagation;
5495
+ return self.shimExec.call(this, 'FileReader', 'readAsBase64', blob.uid);
5496
+ },
5491
5497
 
5492
- callback(evt);
5493
- };
5498
+ getResult: function() {
5499
+ return _result;
5500
+ },
5494
5501
 
5495
- obj.attachEvent('on' + name, func);
5496
- }
5497
-
5498
- // Log event handler to objects internal mOxie registry
5499
- if (!obj[uid]) {
5500
- obj[uid] = Basic.guid();
5501
- }
5502
-
5503
- if (!eventhash.hasOwnProperty(obj[uid])) {
5504
- eventhash[obj[uid]] = {};
5505
- }
5506
-
5507
- events = eventhash[obj[uid]];
5508
-
5509
- if (!events.hasOwnProperty(name)) {
5510
- events[name] = [];
5511
- }
5512
-
5513
- events[name].push({
5514
- func: func,
5515
- orig: callback, // store original callback for IE
5516
- key: key
5517
- });
5518
- };
5519
-
5520
-
5521
- /**
5522
- Remove event handler from the specified object. If third argument (callback)
5523
- is not specified remove all events with the specified name.
5524
-
5525
- @method removeEvent
5526
- @static
5527
- @param {Object} obj DOM element to remove event listener(s) from.
5528
- @param {String} name Name of event listener to remove.
5529
- @param {Function|String} [callback] might be a callback or unique key to match.
5530
- */
5531
- var removeEvent = function(obj, name, callback) {
5532
- var type, undef;
5533
-
5534
- name = name.toLowerCase();
5535
-
5536
- if (obj[uid] && eventhash[obj[uid]] && eventhash[obj[uid]][name]) {
5537
- type = eventhash[obj[uid]][name];
5538
- } else {
5539
- return;
5540
- }
5541
-
5542
- for (var i = type.length - 1; i >= 0; i--) {
5543
- // undefined or not, key should match
5544
- if (type[i].orig === callback || type[i].key === callback) {
5545
- if (obj.removeEventListener) {
5546
- obj.removeEventListener(name, type[i].func, false);
5547
- } else if (obj.detachEvent) {
5548
- obj.detachEvent('on'+name, type[i].func);
5549
- }
5550
-
5551
- type[i].orig = null;
5552
- type[i].func = null;
5553
- type.splice(i, 1);
5554
-
5555
- // If callback was passed we are done here, otherwise proceed
5556
- if (callback !== undef) {
5557
- break;
5558
- }
5559
- }
5560
- }
5561
-
5562
- // If event array got empty, remove it
5563
- if (!type.length) {
5564
- delete eventhash[obj[uid]][name];
5565
- }
5566
-
5567
- // If mOxie registry has become empty, remove it
5568
- if (Basic.isEmptyObj(eventhash[obj[uid]])) {
5569
- delete eventhash[obj[uid]];
5570
-
5571
- // IE doesn't let you remove DOM object property with - delete
5572
- try {
5573
- delete obj[uid];
5574
- } catch(e) {
5575
- obj[uid] = undef;
5576
- }
5577
- }
5578
- };
5579
-
5580
-
5581
- /**
5582
- Remove all kind of events from the specified object
5583
-
5584
- @method removeAllEvents
5585
- @static
5586
- @param {Object} obj DOM element to remove event listeners from.
5587
- @param {String} [key] unique key to match, when removing events.
5588
- */
5589
- var removeAllEvents = function(obj, key) {
5590
- if (!obj || !obj[uid]) {
5591
- return;
5502
+ destroy: function() {
5503
+ _result = null;
5592
5504
  }
5593
-
5594
- Basic.each(eventhash[obj[uid]], function(events, name) {
5595
- removeEvent(obj, name, key);
5596
- });
5597
5505
  };
5598
5506
 
5599
- return {
5600
- addEvent: addEvent,
5601
- removeEvent: removeEvent,
5602
- removeAllEvents: removeAllEvents
5603
- };
5507
+ return (extensions.FileReader = FileReader);
5604
5508
  });
5605
5509
 
5606
- // Included from: src/javascript/runtime/html5/file/FileInput.js
5510
+ // Included from: src/javascript/runtime/flash/file/FileReaderSync.js
5607
5511
 
5608
5512
  /**
5609
- * FileInput.js
5513
+ * FileReaderSync.js
5610
5514
  *
5611
5515
  * Copyright 2013, Moxiecode Systems AB
5612
5516
  * Released under GPL License.
@@ -5616,169 +5520,188 @@ define('moxie/core/utils/Events', [
5616
5520
  */
5617
5521
 
5618
5522
  /**
5619
- @class moxie/runtime/html5/file/FileInput
5523
+ @class moxie/runtime/flash/file/FileReaderSync
5620
5524
  @private
5621
5525
  */
5622
- define("moxie/runtime/html5/file/FileInput", [
5623
- "moxie/runtime/html5/Runtime",
5624
- "moxie/core/utils/Basic",
5625
- "moxie/core/utils/Dom",
5626
- "moxie/core/utils/Events",
5627
- "moxie/core/utils/Mime",
5628
- "moxie/core/utils/Env"
5629
- ], function(extensions, Basic, Dom, Events, Mime, Env) {
5526
+ define("moxie/runtime/flash/file/FileReaderSync", [
5527
+ "moxie/runtime/flash/Runtime",
5528
+ "moxie/core/utils/Encode"
5529
+ ], function(extensions, Encode) {
5630
5530
 
5631
- function FileInput() {
5632
- var _files = [], _options;
5633
-
5634
- Basic.extend(this, {
5635
- init: function(options) {
5636
- var comp = this, I = comp.getRuntime(), input, shimContainer, mimes, browseButton, zIndex, top;
5637
-
5638
- _options = options;
5639
- _files = [];
5640
-
5641
- // figure out accept string
5642
- mimes = _options.accept.mimes || Mime.extList2mimes(_options.accept, I.can('filter_by_extension'));
5531
+ function _formatData(data, op) {
5532
+ switch (op) {
5533
+ case 'readAsText':
5534
+ return Encode.atob(data, 'utf8');
5535
+ case 'readAsBinaryString':
5536
+ return Encode.atob(data);
5537
+ case 'readAsDataURL':
5538
+ return data;
5539
+ }
5540
+ return null;
5541
+ }
5643
5542
 
5644
- shimContainer = I.getShimContainer();
5543
+ var FileReaderSync = {
5544
+ read: function(op, blob) {
5545
+ var result, self = this.getRuntime();
5645
5546
 
5646
- shimContainer.innerHTML = '<input id="' + I.uid +'" type="file" style="font-size:999px;opacity:0;"' +
5647
- (_options.multiple && I.can('select_multiple') ? 'multiple' : '') +
5648
- (_options.directory && I.can('select_folder') ? 'webkitdirectory directory' : '') + // Chrome 11+
5649
- (mimes ? ' accept="' + mimes.join(',') + '"' : '') + ' />';
5547
+ result = self.shimExec.call(this, 'FileReaderSync', 'readAsBase64', blob.uid);
5548
+ if (!result) {
5549
+ return null; // or throw ex
5550
+ }
5650
5551
 
5651
- input = Dom.get(I.uid);
5552
+ // special prefix for DataURL read mode
5553
+ if (op === 'readAsDataURL') {
5554
+ result = 'data:' + (blob.type || '') + ';base64,' + result;
5555
+ }
5652
5556
 
5653
- // prepare file input to be placed underneath the browse_button element
5654
- Basic.extend(input.style, {
5655
- position: 'absolute',
5656
- top: 0,
5657
- left: 0,
5658
- width: '100%',
5659
- height: '100%'
5660
- });
5557
+ return _formatData(result, op, blob.type);
5558
+ }
5559
+ };
5661
5560
 
5561
+ return (extensions.FileReaderSync = FileReaderSync);
5562
+ });
5662
5563
 
5663
- browseButton = Dom.get(_options.browse_button);
5564
+ // Included from: src/javascript/runtime/Transporter.js
5664
5565
 
5665
- // Route click event to the input[type=file] element for browsers that support such behavior
5666
- if (I.can('summon_file_dialog')) {
5667
- if (Dom.getStyle(browseButton, 'position') === 'static') {
5668
- browseButton.style.position = 'relative';
5669
- }
5566
+ /**
5567
+ * Transporter.js
5568
+ *
5569
+ * Copyright 2013, Moxiecode Systems AB
5570
+ * Released under GPL License.
5571
+ *
5572
+ * License: http://www.plupload.com/license
5573
+ * Contributing: http://www.plupload.com/contributing
5574
+ */
5670
5575
 
5671
- zIndex = parseInt(Dom.getStyle(browseButton, 'z-index'), 10) || 1;
5576
+ define("moxie/runtime/Transporter", [
5577
+ "moxie/core/utils/Basic",
5578
+ "moxie/core/utils/Encode",
5579
+ "moxie/runtime/RuntimeClient",
5580
+ "moxie/core/EventTarget"
5581
+ ], function(Basic, Encode, RuntimeClient, EventTarget) {
5582
+ function Transporter() {
5583
+ var mod, _runtime, _data, _size, _pos, _chunk_size;
5672
5584
 
5673
- browseButton.style.zIndex = zIndex;
5674
- shimContainer.style.zIndex = zIndex - 1;
5585
+ RuntimeClient.call(this);
5675
5586
 
5676
- Events.addEvent(browseButton, 'click', function(e) {
5677
- var input = Dom.get(I.uid);
5678
- if (input && !input.disabled) { // for some reason FF (up to 8.0.1 so far) lets to click disabled input[type=file]
5679
- input.click();
5680
- }
5681
- e.preventDefault();
5682
- }, comp.uid);
5683
- }
5587
+ Basic.extend(this, {
5588
+ uid: Basic.guid('uid_'),
5684
5589
 
5685
- /* Since we have to place input[type=file] on top of the browse_button for some browsers,
5686
- browse_button loses interactivity, so we restore it here */
5687
- top = I.can('summon_file_dialog') ? browseButton : shimContainer;
5590
+ state: Transporter.IDLE,
5688
5591
 
5689
- Events.addEvent(top, 'mouseover', function() {
5690
- comp.trigger('mouseenter');
5691
- }, comp.uid);
5592
+ result: null,
5692
5593
 
5693
- Events.addEvent(top, 'mouseout', function() {
5694
- comp.trigger('mouseleave');
5695
- }, comp.uid);
5594
+ transport: function(data, type, options) {
5595
+ var self = this;
5696
5596
 
5697
- Events.addEvent(top, 'mousedown', function() {
5698
- comp.trigger('mousedown');
5699
- }, comp.uid);
5597
+ options = Basic.extend({
5598
+ chunk_size: 204798
5599
+ }, options);
5700
5600
 
5701
- Events.addEvent(Dom.get(_options.container), 'mouseup', function() {
5702
- comp.trigger('mouseup');
5703
- }, comp.uid);
5601
+ // should divide by three, base64 requires this
5602
+ if ((mod = options.chunk_size % 3)) {
5603
+ options.chunk_size += 3 - mod;
5604
+ }
5704
5605
 
5606
+ _chunk_size = options.chunk_size;
5705
5607
 
5706
- input.onchange = function onChange() { // there should be only one handler for this
5707
- _files = [];
5608
+ _reset.call(this);
5609
+ _data = data;
5610
+ _size = data.length;
5708
5611
 
5709
- if (_options.directory) {
5710
- // folders are represented by dots, filter them out (Chrome 11+)
5711
- Basic.each(this.files, function(file) {
5712
- if (file.name !== ".") { // if it doesn't looks like a folder
5713
- _files.push(file);
5714
- }
5715
- });
5716
- } else {
5717
- _files = [].slice.call(this.files);
5718
- }
5612
+ if (Basic.typeOf(options) === 'string' || options.ruid) {
5613
+ _run.call(self, type, this.connectRuntime(options));
5614
+ } else {
5615
+ // we require this to run only once
5616
+ var cb = function(e, runtime) {
5617
+ self.unbind("RuntimeInit", cb);
5618
+ _run.call(self, type, runtime);
5619
+ };
5620
+ this.bind("RuntimeInit", cb);
5621
+ this.connectRuntime(options);
5622
+ }
5623
+ },
5719
5624
 
5720
- // clearing the value enables the user to select the same file again if they want to
5721
- if (Env.browser !== 'IE' && Env.browser !== 'IEMobile') {
5722
- this.value = '';
5723
- } else {
5724
- // in IE input[type="file"] is read-only so the only way to reset it is to re-insert it
5725
- var clone = this.cloneNode(true);
5726
- this.parentNode.replaceChild(clone, this);
5727
- clone.onchange = onChange;
5728
- }
5729
- comp.trigger('change');
5730
- };
5625
+ abort: function() {
5626
+ var self = this;
5731
5627
 
5732
- // ready event is perfectly asynchronous
5733
- comp.trigger({
5734
- type: 'ready',
5735
- async: true
5736
- });
5628
+ self.state = Transporter.IDLE;
5629
+ if (_runtime) {
5630
+ _runtime.exec.call(self, 'Transporter', 'clear');
5631
+ self.trigger("TransportingAborted");
5632
+ }
5737
5633
 
5738
- shimContainer = null;
5634
+ _reset.call(self);
5739
5635
  },
5740
5636
 
5741
- getFiles: function() {
5742
- return _files;
5743
- },
5744
5637
 
5745
- disable: function(state) {
5746
- var I = this.getRuntime(), input;
5638
+ destroy: function() {
5639
+ this.unbindAll();
5640
+ _runtime = null;
5641
+ this.disconnectRuntime();
5642
+ _reset.call(this);
5643
+ }
5644
+ });
5747
5645
 
5748
- if ((input = Dom.get(I.uid))) {
5749
- input.disabled = !!state;
5750
- }
5751
- },
5646
+ function _reset() {
5647
+ _size = _pos = 0;
5648
+ _data = this.result = null;
5649
+ }
5752
5650
 
5753
- destroy: function() {
5754
- var I = this.getRuntime()
5755
- , shim = I.getShim()
5756
- , shimContainer = I.getShimContainer()
5757
- ;
5758
-
5759
- Events.removeAllEvents(shimContainer, this.uid);
5760
- Events.removeAllEvents(_options && Dom.get(_options.container), this.uid);
5761
- Events.removeAllEvents(_options && Dom.get(_options.browse_button), this.uid);
5762
-
5763
- if (shimContainer) {
5764
- shimContainer.innerHTML = '';
5651
+ function _run(type, runtime) {
5652
+ var self = this;
5653
+
5654
+ _runtime = runtime;
5655
+
5656
+ //self.unbind("RuntimeInit");
5657
+
5658
+ self.bind("TransportingProgress", function(e) {
5659
+ _pos = e.loaded;
5660
+
5661
+ if (_pos < _size && Basic.inArray(self.state, [Transporter.IDLE, Transporter.DONE]) === -1) {
5662
+ _transport.call(self);
5765
5663
  }
5664
+ }, 999);
5766
5665
 
5767
- shim.removeInstance(this.uid);
5666
+ self.bind("TransportingComplete", function() {
5667
+ _pos = _size;
5668
+ self.state = Transporter.DONE;
5669
+ _data = null; // clean a bit
5670
+ self.result = _runtime.exec.call(self, 'Transporter', 'getAsBlob', type || '');
5671
+ }, 999);
5672
+
5673
+ self.state = Transporter.BUSY;
5674
+ self.trigger("TransportingStarted");
5675
+ _transport.call(self);
5676
+ }
5677
+
5678
+ function _transport() {
5679
+ var self = this,
5680
+ chunk,
5681
+ bytesLeft = _size - _pos;
5768
5682
 
5769
- _files = _options = shimContainer = shim = null;
5683
+ if (_chunk_size > bytesLeft) {
5684
+ _chunk_size = bytesLeft;
5770
5685
  }
5771
- });
5686
+
5687
+ chunk = Encode.btoa(_data.substr(_pos, _chunk_size));
5688
+ _runtime.exec.call(self, 'Transporter', 'receive', chunk, _size);
5689
+ }
5772
5690
  }
5773
5691
 
5774
- return (extensions.FileInput = FileInput);
5775
- });
5692
+ Transporter.IDLE = 0;
5693
+ Transporter.BUSY = 1;
5694
+ Transporter.DONE = 2;
5776
5695
 
5696
+ Transporter.prototype = EventTarget.instance;
5777
5697
 
5778
- // Included from: src/javascript/runtime/html5/file/FileReader.js
5698
+ return Transporter;
5699
+ });
5700
+
5701
+ // Included from: src/javascript/runtime/flash/xhr/XMLHttpRequest.js
5779
5702
 
5780
5703
  /**
5781
- * FileReader.js
5704
+ * XMLHttpRequest.js
5782
5705
  *
5783
5706
  * Copyright 2013, Moxiecode Systems AB
5784
5707
  * Released under GPL License.
@@ -5788,77 +5711,146 @@ define("moxie/runtime/html5/file/FileInput", [
5788
5711
  */
5789
5712
 
5790
5713
  /**
5791
- @class moxie/runtime/html5/file/FileReader
5714
+ @class moxie/runtime/flash/xhr/XMLHttpRequest
5792
5715
  @private
5793
5716
  */
5794
- define("moxie/runtime/html5/file/FileReader", [
5795
- "moxie/runtime/html5/Runtime",
5796
- "moxie/core/utils/Encode",
5797
- "moxie/core/utils/Basic"
5798
- ], function(extensions, Encode, Basic) {
5717
+ define("moxie/runtime/flash/xhr/XMLHttpRequest", [
5718
+ "moxie/runtime/flash/Runtime",
5719
+ "moxie/core/utils/Basic",
5720
+ "moxie/file/Blob",
5721
+ "moxie/file/File",
5722
+ "moxie/file/FileReaderSync",
5723
+ "moxie/xhr/FormData",
5724
+ "moxie/runtime/Transporter"
5725
+ ], function(extensions, Basic, Blob, File, FileReaderSync, FormData, Transporter) {
5799
5726
 
5800
- function FileReader() {
5801
- var _fr, _convertToBinary = false;
5727
+ var XMLHttpRequest = {
5802
5728
 
5803
- Basic.extend(this, {
5729
+ send: function(meta, data) {
5730
+ var target = this, self = target.getRuntime();
5804
5731
 
5805
- read: function(op, blob) {
5806
- var target = this;
5732
+ function send() {
5733
+ meta.transport = self.mode;
5734
+ self.shimExec.call(target, 'XMLHttpRequest', 'send', meta, data);
5735
+ }
5807
5736
 
5808
- _fr = new window.FileReader();
5809
5737
 
5810
- _fr.addEventListener('progress', function(e) {
5811
- target.trigger(e);
5738
+ function appendBlob(name, blob) {
5739
+ self.shimExec.call(target, 'XMLHttpRequest', 'appendBlob', name, blob.uid);
5740
+ data = null;
5741
+ send();
5742
+ }
5743
+
5744
+
5745
+ function attachBlob(blob, cb) {
5746
+ var tr = new Transporter();
5747
+
5748
+ tr.bind("TransportingComplete", function() {
5749
+ cb(this.result);
5812
5750
  });
5813
5751
 
5814
- _fr.addEventListener('load', function(e) {
5815
- target.trigger(e);
5752
+ tr.transport(blob.getSource(), blob.type, {
5753
+ ruid: self.uid
5816
5754
  });
5755
+ }
5817
5756
 
5818
- _fr.addEventListener('error', function(e) {
5819
- target.trigger(e, _fr.error);
5757
+ // copy over the headers if any
5758
+ if (!Basic.isEmptyObj(meta.headers)) {
5759
+ Basic.each(meta.headers, function(value, header) {
5760
+ self.shimExec.call(target, 'XMLHttpRequest', 'setRequestHeader', header, value.toString()); // Silverlight doesn't accept integers into the arguments of type object
5820
5761
  });
5762
+ }
5821
5763
 
5822
- _fr.addEventListener('loadend', function() {
5823
- _fr = null;
5764
+ // transfer over multipart params and blob itself
5765
+ if (data instanceof FormData) {
5766
+ var blobField;
5767
+ data.each(function(value, name) {
5768
+ if (value instanceof Blob) {
5769
+ blobField = name;
5770
+ } else {
5771
+ self.shimExec.call(target, 'XMLHttpRequest', 'append', name, value);
5772
+ }
5824
5773
  });
5825
5774
 
5826
- if (Basic.typeOf(_fr[op]) === 'function') {
5827
- _convertToBinary = false;
5828
- _fr[op](blob.getSource());
5829
- } else if (op === 'readAsBinaryString') { // readAsBinaryString is depricated in general and never existed in IE10+
5830
- _convertToBinary = true;
5831
- _fr.readAsDataURL(blob.getSource());
5775
+ if (!data.hasBlob()) {
5776
+ data = null;
5777
+ send();
5778
+ } else {
5779
+ var blob = data.getBlob();
5780
+ if (blob.isDetached()) {
5781
+ attachBlob(blob, function(attachedBlob) {
5782
+ blob.destroy();
5783
+ appendBlob(blobField, attachedBlob);
5784
+ });
5785
+ } else {
5786
+ appendBlob(blobField, blob);
5787
+ }
5832
5788
  }
5833
- },
5789
+ } else if (data instanceof Blob) {
5790
+ if (data.isDetached()) {
5791
+ attachBlob(data, function(attachedBlob) {
5792
+ data.destroy();
5793
+ data = attachedBlob.uid;
5794
+ send();
5795
+ });
5796
+ } else {
5797
+ data = data.uid;
5798
+ send();
5799
+ }
5800
+ } else {
5801
+ send();
5802
+ }
5803
+ },
5834
5804
 
5835
- getResult: function() {
5836
- return _fr && _fr.result ? (_convertToBinary ? _toBinary(_fr.result) : _fr.result) : null;
5837
- },
5805
+ getResponse: function(responseType) {
5806
+ var frs, blob, self = this.getRuntime();
5838
5807
 
5839
- abort: function() {
5840
- if (_fr) {
5841
- _fr.abort();
5808
+ blob = self.shimExec.call(this, 'XMLHttpRequest', 'getResponseAsBlob');
5809
+
5810
+ if (blob) {
5811
+ blob = new File(self.uid, blob);
5812
+
5813
+ if ('blob' === responseType) {
5814
+ return blob;
5842
5815
  }
5843
- },
5844
5816
 
5845
- destroy: function() {
5846
- _fr = null;
5817
+ try {
5818
+ frs = new FileReaderSync();
5819
+
5820
+ if (!!~Basic.inArray(responseType, ["", "text"])) {
5821
+ return frs.readAsText(blob);
5822
+ } else if ('json' === responseType && !!window.JSON) {
5823
+ return JSON.parse(frs.readAsText(blob));
5824
+ }
5825
+ } finally {
5826
+ blob.destroy();
5827
+ }
5847
5828
  }
5848
- });
5829
+ return null;
5830
+ },
5849
5831
 
5850
- function _toBinary(str) {
5851
- return Encode.atob(str.substring(str.indexOf('base64,') + 7));
5832
+ abort: function(upload_complete_flag) {
5833
+ var self = this.getRuntime();
5834
+
5835
+ self.shimExec.call(this, 'XMLHttpRequest', 'abort');
5836
+
5837
+ this.dispatchEvent('readystatechange');
5838
+ // this.dispatchEvent('progress');
5839
+ this.dispatchEvent('abort');
5840
+
5841
+ //if (!upload_complete_flag) {
5842
+ // this.dispatchEvent('uploadprogress');
5843
+ //}
5852
5844
  }
5853
- }
5845
+ };
5854
5846
 
5855
- return (extensions.FileReader = FileReader);
5847
+ return (extensions.XMLHttpRequest = XMLHttpRequest);
5856
5848
  });
5857
5849
 
5858
- // Included from: src/javascript/runtime/html5/xhr/XMLHttpRequest.js
5850
+ // Included from: src/javascript/runtime/html4/Runtime.js
5859
5851
 
5860
5852
  /**
5861
- * XMLHttpRequest.js
5853
+ * Runtime.js
5862
5854
  *
5863
5855
  * Copyright 2013, Moxiecode Systems AB
5864
5856
  * Released under GPL License.
@@ -5867,373 +5859,100 @@ define("moxie/runtime/html5/file/FileReader", [
5867
5859
  * Contributing: http://www.plupload.com/contributing
5868
5860
  */
5869
5861
 
5870
- /*global ActiveXObject:true */
5862
+ /*global File:true */
5871
5863
 
5872
5864
  /**
5873
- @class moxie/runtime/html5/xhr/XMLHttpRequest
5865
+ Defines constructor for HTML4 runtime.
5866
+
5867
+ @class moxie/runtime/html4/Runtime
5874
5868
  @private
5875
5869
  */
5876
- define("moxie/runtime/html5/xhr/XMLHttpRequest", [
5877
- "moxie/runtime/html5/Runtime",
5870
+ define("moxie/runtime/html4/Runtime", [
5878
5871
  "moxie/core/utils/Basic",
5879
- "moxie/core/utils/Mime",
5880
- "moxie/core/utils/Url",
5881
- "moxie/file/File",
5882
- "moxie/file/Blob",
5883
- "moxie/xhr/FormData",
5884
5872
  "moxie/core/Exceptions",
5873
+ "moxie/runtime/Runtime",
5885
5874
  "moxie/core/utils/Env"
5886
- ], function(extensions, Basic, Mime, Url, File, Blob, FormData, x, Env) {
5875
+ ], function(Basic, x, Runtime, Env) {
5887
5876
 
5888
- function XMLHttpRequest() {
5889
- var self = this
5890
- , _xhr
5891
- , _filename
5877
+ var type = 'html4', extensions = {};
5878
+
5879
+ function Html4Runtime(options) {
5880
+ var I = this
5881
+ , Test = Runtime.capTest
5882
+ , True = Runtime.capTrue
5892
5883
  ;
5893
5884
 
5894
- Basic.extend(this, {
5895
- send: function(meta, data) {
5896
- var target = this
5897
- , isGecko2_5_6 = (Env.browser === 'Mozilla' && Env.version >= 4 && Env.version < 7)
5898
- , isAndroidBrowser = Env.browser === 'Android Browser'
5899
- , mustSendAsBinary = false
5900
- ;
5901
-
5902
- // extract file name
5903
- _filename = meta.url.replace(/^.+?\/([\w\-\.]+)$/, '$1').toLowerCase();
5904
-
5905
- _xhr = _getNativeXHR();
5906
- _xhr.open(meta.method, meta.url, meta.async, meta.user, meta.password);
5907
-
5908
-
5909
- // prepare data to be sent
5910
- if (data instanceof Blob) {
5911
- if (data.isDetached()) {
5912
- mustSendAsBinary = true;
5913
- }
5914
- data = data.getSource();
5915
- } else if (data instanceof FormData) {
5916
-
5917
- if (data.hasBlob()) {
5918
- if (data.getBlob().isDetached()) {
5919
- data = _prepareMultipart.call(target, data); // _xhr must be instantiated and be in OPENED state
5920
- mustSendAsBinary = true;
5921
- } else if ((isGecko2_5_6 || isAndroidBrowser) && Basic.typeOf(data.getBlob().getSource()) === 'blob' && window.FileReader) {
5922
- // Gecko 2/5/6 can't send blob in FormData: https://bugzilla.mozilla.org/show_bug.cgi?id=649150
5923
- // Android browsers (default one and Dolphin) seem to have the same issue, see: #613
5924
- _preloadAndSend.call(target, meta, data);
5925
- return; // _preloadAndSend will reinvoke send() with transmutated FormData =%D
5926
- }
5927
- }
5928
-
5929
- // transfer fields to real FormData
5930
- if (data instanceof FormData) { // if still a FormData, e.g. not mangled by _prepareMultipart()
5931
- var fd = new window.FormData();
5932
- data.each(function(value, name) {
5933
- if (value instanceof Blob) {
5934
- fd.append(name, value.getSource());
5935
- } else {
5936
- fd.append(name, value);
5937
- }
5938
- });
5939
- data = fd;
5940
- }
5941
- }
5942
-
5943
-
5944
- // if XHR L2
5945
- if (_xhr.upload) {
5946
- if (meta.withCredentials) {
5947
- _xhr.withCredentials = true;
5948
- }
5949
-
5950
- _xhr.addEventListener('load', function(e) {
5951
- target.trigger(e);
5952
- });
5953
-
5954
- _xhr.addEventListener('error', function(e) {
5955
- target.trigger(e);
5956
- });
5957
-
5958
- // additionally listen to progress events
5959
- _xhr.addEventListener('progress', function(e) {
5960
- target.trigger(e);
5961
- });
5962
-
5963
- _xhr.upload.addEventListener('progress', function(e) {
5964
- target.trigger({
5965
- type: 'UploadProgress',
5966
- loaded: e.loaded,
5967
- total: e.total
5968
- });
5969
- });
5970
- // ... otherwise simulate XHR L2
5971
- } else {
5972
- _xhr.onreadystatechange = function onReadyStateChange() {
5973
-
5974
- // fake Level 2 events
5975
- switch (_xhr.readyState) {
5976
-
5977
- case 1: // XMLHttpRequest.OPENED
5978
- // readystatechanged is fired twice for OPENED state (in IE and Mozilla) - neu
5979
- break;
5980
-
5981
- // looks like HEADERS_RECEIVED (state 2) is not reported in Opera (or it's old versions) - neu
5982
- case 2: // XMLHttpRequest.HEADERS_RECEIVED
5983
- break;
5984
-
5985
- case 3: // XMLHttpRequest.LOADING
5986
- // try to fire progress event for not XHR L2
5987
- var total, loaded;
5988
-
5989
- try {
5990
- if (Url.hasSameOrigin(meta.url)) { // Content-Length not accessible for cross-domain on some browsers
5991
- total = _xhr.getResponseHeader('Content-Length') || 0; // old Safari throws an exception here
5992
- }
5993
-
5994
- if (_xhr.responseText) { // responseText was introduced in IE7
5995
- loaded = _xhr.responseText.length;
5996
- }
5997
- } catch(ex) {
5998
- total = loaded = 0;
5999
- }
6000
-
6001
- target.trigger({
6002
- type: 'progress',
6003
- lengthComputable: !!total,
6004
- total: parseInt(total, 10),
6005
- loaded: loaded
6006
- });
6007
- break;
6008
-
6009
- case 4: // XMLHttpRequest.DONE
6010
- // release readystatechange handler (mostly for IE)
6011
- _xhr.onreadystatechange = function() {};
6012
-
6013
- // usually status 0 is returned when server is unreachable, but FF also fails to status 0 for 408 timeout
6014
- if (_xhr.status === 0) {
6015
- target.trigger('error');
6016
- } else {
6017
- target.trigger('load');
6018
- }
6019
- break;
6020
- }
6021
- };
6022
- }
6023
-
6024
-
6025
- // set request headers
6026
- if (!Basic.isEmptyObj(meta.headers)) {
6027
- Basic.each(meta.headers, function(value, header) {
6028
- _xhr.setRequestHeader(header, value);
6029
- });
6030
- }
6031
-
6032
- // request response type
6033
- if ("" !== meta.responseType && 'responseType' in _xhr) {
6034
- if ('json' === meta.responseType && !Env.can('return_response_type', 'json')) { // we can fake this one
6035
- _xhr.responseType = 'text';
6036
- } else {
6037
- _xhr.responseType = meta.responseType;
6038
- }
6039
- }
6040
-
6041
- // send ...
6042
- if (!mustSendAsBinary) {
6043
- _xhr.send(data);
6044
- } else {
6045
- if (_xhr.sendAsBinary) { // Gecko
6046
- _xhr.sendAsBinary(data);
6047
- } else { // other browsers having support for typed arrays
6048
- (function() {
6049
- // mimic Gecko's sendAsBinary
6050
- var ui8a = new Uint8Array(data.length);
6051
- for (var i = 0; i < data.length; i++) {
6052
- ui8a[i] = (data.charCodeAt(i) & 0xff);
6053
- }
6054
- _xhr.send(ui8a.buffer);
6055
- }());
6056
- }
6057
- }
6058
-
6059
- target.trigger('loadstart');
5885
+ Runtime.call(this, options, type, {
5886
+ access_binary: Test(window.FileReader || window.File && File.getAsDataURL),
5887
+ access_image_binary: false,
5888
+ display_media: Test(extensions.Image && (Env.can('create_canvas') || Env.can('use_data_uri_over32kb'))),
5889
+ do_cors: false,
5890
+ drag_and_drop: false,
5891
+ filter_by_extension: Test(function() { // if you know how to feature-detect this, please suggest
5892
+ return (Env.browser === 'Chrome' && Env.version >= 28) || (Env.browser === 'IE' && Env.version >= 10);
5893
+ }()),
5894
+ resize_image: function() {
5895
+ return extensions.Image && I.can('access_binary') && Env.can('create_canvas');
6060
5896
  },
6061
-
6062
- getStatus: function() {
6063
- // according to W3C spec it should return 0 for readyState < 3, but instead it throws an exception
6064
- try {
6065
- if (_xhr) {
6066
- return _xhr.status;
6067
- }
6068
- } catch(ex) {}
6069
- return 0;
5897
+ report_upload_progress: false,
5898
+ return_response_headers: false,
5899
+ return_response_type: function(responseType) {
5900
+ if (responseType === 'json' && !!window.JSON) {
5901
+ return true;
5902
+ }
5903
+ return !!~Basic.inArray(responseType, ['text', 'document', '']);
6070
5904
  },
6071
-
6072
- getResponse: function(responseType) {
6073
- var I = this.getRuntime();
6074
-
6075
- try {
6076
- switch (responseType) {
6077
- case 'blob':
6078
- var file = new File(I.uid, _xhr.response);
6079
-
6080
- // try to extract file name from content-disposition if possible (might be - not, if CORS for example)
6081
- var disposition = _xhr.getResponseHeader('Content-Disposition');
6082
- if (disposition) {
6083
- // extract filename from response header if available
6084
- var match = disposition.match(/filename=([\'\"'])([^\1]+)\1/);
6085
- if (match) {
6086
- _filename = match[2];
6087
- }
6088
- }
6089
- file.name = _filename;
6090
-
6091
- // pre-webkit Opera doesn't set type property on the blob response
6092
- if (!file.type) {
6093
- file.type = Mime.getFileMime(_filename);
6094
- }
6095
- return file;
6096
-
6097
- case 'json':
6098
- if (!Env.can('return_response_type', 'json')) {
6099
- return _xhr.status === 200 && !!window.JSON ? JSON.parse(_xhr.responseText) : null;
6100
- }
6101
- return _xhr.response;
6102
-
6103
- case 'document':
6104
- return _getDocument(_xhr);
6105
-
6106
- default:
6107
- return _xhr.responseText !== '' ? _xhr.responseText : null; // against the specs, but for consistency across the runtimes
6108
- }
6109
- } catch(ex) {
6110
- return null;
6111
- }
5905
+ return_status_code: function(code) {
5906
+ return !Basic.arrayDiff(code, [200, 404]);
6112
5907
  },
6113
-
6114
- getAllResponseHeaders: function() {
6115
- try {
6116
- return _xhr.getAllResponseHeaders();
6117
- } catch(ex) {}
6118
- return '';
5908
+ select_file: function() {
5909
+ return Env.can('use_fileinput');
6119
5910
  },
6120
-
6121
- abort: function() {
6122
- if (_xhr) {
6123
- _xhr.abort();
6124
- }
5911
+ select_multiple: false,
5912
+ send_binary_string: false,
5913
+ send_custom_headers: false,
5914
+ send_multipart: true,
5915
+ slice_blob: false,
5916
+ stream_upload: function() {
5917
+ return I.can('select_file');
6125
5918
  },
6126
-
6127
- destroy: function() {
6128
- self = _filename = null;
5919
+ summon_file_dialog: Test(function() { // yeah... some dirty sniffing here...
5920
+ return (Env.browser === 'Firefox' && Env.version >= 4) ||
5921
+ (Env.browser === 'Opera' && Env.version >= 12) ||
5922
+ !!~Basic.inArray(Env.browser, ['Chrome', 'Safari']);
5923
+ }()),
5924
+ upload_filesize: True,
5925
+ use_http_method: function(methods) {
5926
+ return !Basic.arrayDiff(methods, ['GET', 'POST']);
6129
5927
  }
6130
5928
  });
6131
5929
 
6132
5930
 
6133
- // here we go... ugly fix for ugly bug
6134
- function _preloadAndSend(meta, data) {
6135
- var target = this, blob, fr;
6136
-
6137
- // get original blob
6138
- blob = data.getBlob().getSource();
6139
-
6140
- // preload blob in memory to be sent as binary string
6141
- fr = new window.FileReader();
6142
- fr.onload = function() {
6143
- // overwrite original blob
6144
- data.append(data.getBlobName(), new Blob(null, {
6145
- type: blob.type,
6146
- data: fr.result
6147
- }));
6148
- // invoke send operation again
6149
- self.send.call(target, meta, data);
6150
- };
6151
- fr.readAsBinaryString(blob);
6152
- }
6153
-
6154
-
6155
- function _getNativeXHR() {
6156
- if (window.XMLHttpRequest && !(Env.browser === 'IE' && Env.version < 8)) { // IE7 has native XHR but it's buggy
6157
- return new window.XMLHttpRequest();
6158
- } else {
6159
- return (function() {
6160
- var progIDs = ['Msxml2.XMLHTTP.6.0', 'Microsoft.XMLHTTP']; // if 6.0 available, use it, otherwise failback to default 3.0
6161
- for (var i = 0; i < progIDs.length; i++) {
6162
- try {
6163
- return new ActiveXObject(progIDs[i]);
6164
- } catch (ex) {}
6165
- }
6166
- })();
6167
- }
6168
- }
6169
-
6170
- // @credits Sergey Ilinsky (http://www.ilinsky.com/)
6171
- function _getDocument(xhr) {
6172
- var rXML = xhr.responseXML;
6173
- var rText = xhr.responseText;
6174
-
6175
- // Try parsing responseText (@see: http://www.ilinsky.com/articles/XMLHttpRequest/#bugs-ie-responseXML-content-type)
6176
- if (Env.browser === 'IE' && rText && rXML && !rXML.documentElement && /[^\/]+\/[^\+]+\+xml/.test(xhr.getResponseHeader("Content-Type"))) {
6177
- rXML = new window.ActiveXObject("Microsoft.XMLDOM");
6178
- rXML.async = false;
6179
- rXML.validateOnParse = false;
6180
- rXML.loadXML(rText);
6181
- }
6182
-
6183
- // Check if there is no error in document
6184
- if (rXML) {
6185
- if ((Env.browser === 'IE' && rXML.parseError !== 0) || !rXML.documentElement || rXML.documentElement.tagName === "parsererror") {
6186
- return null;
6187
- }
6188
- }
6189
- return rXML;
6190
- }
6191
-
6192
-
6193
- function _prepareMultipart(fd) {
6194
- var boundary = '----moxieboundary' + new Date().getTime()
6195
- , dashdash = '--'
6196
- , crlf = '\r\n'
6197
- , multipart = ''
6198
- , I = this.getRuntime()
6199
- ;
6200
-
6201
- if (!I.can('send_binary_string')) {
6202
- throw new x.RuntimeError(x.RuntimeError.NOT_SUPPORTED_ERR);
6203
- }
6204
-
6205
- _xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
6206
-
6207
- // append multipart parameters
6208
- fd.each(function(value, name) {
6209
- // Firefox 3.6 failed to convert multibyte characters to UTF-8 in sendAsBinary(),
6210
- // so we try it here ourselves with: unescape(encodeURIComponent(value))
6211
- if (value instanceof Blob) {
6212
- // Build RFC2388 blob
6213
- multipart += dashdash + boundary + crlf +
6214
- 'Content-Disposition: form-data; name="' + name + '"; filename="' + unescape(encodeURIComponent(value.name || 'blob')) + '"' + crlf +
6215
- 'Content-Type: ' + (value.type || 'application/octet-stream') + crlf + crlf +
6216
- value.getSource() + crlf;
6217
- } else {
6218
- multipart += dashdash + boundary + crlf +
6219
- 'Content-Disposition: form-data; name="' + name + '"' + crlf + crlf +
6220
- unescape(encodeURIComponent(value)) + crlf;
6221
- }
6222
- });
5931
+ Basic.extend(this, {
5932
+ init : function() {
5933
+ this.trigger("Init");
5934
+ },
6223
5935
 
6224
- multipart += dashdash + boundary + dashdash + crlf;
5936
+ destroy: (function(destroy) { // extend default destroy method
5937
+ return function() {
5938
+ destroy.call(I);
5939
+ destroy = I = null;
5940
+ };
5941
+ }(this.destroy))
5942
+ });
6225
5943
 
6226
- return multipart;
6227
- }
5944
+ Basic.extend(this.getShim(), extensions);
6228
5945
  }
6229
5946
 
6230
- return (extensions.XMLHttpRequest = XMLHttpRequest);
5947
+ Runtime.addConstructor(type, Html4Runtime);
5948
+
5949
+ return extensions;
6231
5950
  });
6232
5951
 
6233
- // Included from: src/javascript/runtime/html5/utils/BinaryReader.js
5952
+ // Included from: src/javascript/core/utils/Events.js
6234
5953
 
6235
5954
  /**
6236
- * BinaryReader.js
5955
+ * Events.js
6237
5956
  *
6238
5957
  * Copyright 2013, Moxiecode Systems AB
6239
5958
  * Released under GPL License.
@@ -6242,537 +5961,171 @@ define("moxie/runtime/html5/xhr/XMLHttpRequest", [
6242
5961
  * Contributing: http://www.plupload.com/contributing
6243
5962
  */
6244
5963
 
6245
- /**
6246
- @class moxie/runtime/html5/utils/BinaryReader
6247
- @private
6248
- */
6249
- define("moxie/runtime/html5/utils/BinaryReader", [], function() {
6250
- return function() {
6251
- var II = false, bin;
6252
-
6253
- // Private functions
6254
- function read(idx, size) {
6255
- var mv = II ? 0 : -8 * (size - 1), sum = 0, i;
6256
-
6257
- for (i = 0; i < size; i++) {
6258
- sum |= (bin.charCodeAt(idx + i) << Math.abs(mv + i*8));
6259
- }
6260
-
6261
- return sum;
6262
- }
6263
-
6264
- function putstr(segment, idx, length) {
6265
- length = arguments.length === 3 ? length : bin.length - idx - 1;
6266
- bin = bin.substr(0, idx) + segment + bin.substr(length + idx);
6267
- }
6268
-
6269
- function write(idx, num, size) {
6270
- var str = '', mv = II ? 0 : -8 * (size - 1), i;
6271
-
6272
- for (i = 0; i < size; i++) {
6273
- str += String.fromCharCode((num >> Math.abs(mv + i*8)) & 255);
6274
- }
6275
-
6276
- putstr(str, idx, size);
6277
- }
6278
-
6279
- // Public functions
6280
- return {
6281
- II: function(order) {
6282
- if (order === undefined) {
6283
- return II;
6284
- } else {
6285
- II = order;
6286
- }
6287
- },
6288
-
6289
- init: function(binData) {
6290
- II = false;
6291
- bin = binData;
6292
- },
6293
-
6294
- SEGMENT: function(idx, length, segment) {
6295
- switch (arguments.length) {
6296
- case 1:
6297
- return bin.substr(idx, bin.length - idx - 1);
6298
- case 2:
6299
- return bin.substr(idx, length);
6300
- case 3:
6301
- putstr(segment, idx, length);
6302
- break;
6303
- default: return bin;
6304
- }
6305
- },
6306
-
6307
- BYTE: function(idx) {
6308
- return read(idx, 1);
6309
- },
6310
-
6311
- SHORT: function(idx) {
6312
- return read(idx, 2);
6313
- },
6314
-
6315
- LONG: function(idx, num) {
6316
- if (num === undefined) {
6317
- return read(idx, 4);
6318
- } else {
6319
- write(idx, num, 4);
6320
- }
6321
- },
5964
+ define('moxie/core/utils/Events', [
5965
+ 'moxie/core/utils/Basic'
5966
+ ], function(Basic) {
5967
+ var eventhash = {}, uid = 'moxie_' + Basic.guid();
5968
+
5969
+ // IE W3C like event funcs
5970
+ function preventDefault() {
5971
+ this.returnValue = false;
5972
+ }
6322
5973
 
6323
- SLONG: function(idx) { // 2's complement notation
6324
- var num = read(idx, 4);
5974
+ function stopPropagation() {
5975
+ this.cancelBubble = true;
5976
+ }
6325
5977
 
6326
- return (num > 2147483647 ? num - 4294967296 : num);
6327
- },
5978
+ /**
5979
+ Adds an event handler to the specified object and store reference to the handler
5980
+ in objects internal Plupload registry (@see removeEvent).
5981
+
5982
+ @method addEvent
5983
+ @for Utils
5984
+ @static
5985
+ @param {Object} obj DOM element like object to add handler to.
5986
+ @param {String} name Name to add event listener to.
5987
+ @param {Function} callback Function to call when event occurs.
5988
+ @param {String} [key] that might be used to add specifity to the event record.
5989
+ */
5990
+ var addEvent = function(obj, name, callback, key) {
5991
+ var func, events;
5992
+
5993
+ name = name.toLowerCase();
6328
5994
 
6329
- STRING: function(idx, size) {
6330
- var str = '';
5995
+ // Add event listener
5996
+ if (obj.addEventListener) {
5997
+ func = callback;
5998
+
5999
+ obj.addEventListener(name, func, false);
6000
+ } else if (obj.attachEvent) {
6001
+ func = function() {
6002
+ var evt = window.event;
6331
6003
 
6332
- for (size += idx; idx < size; idx++) {
6333
- str += String.fromCharCode(read(idx, 1));
6004
+ if (!evt.target) {
6005
+ evt.target = evt.srcElement;
6334
6006
  }
6335
6007
 
6336
- return str;
6337
- }
6338
- };
6339
- };
6340
- });
6008
+ evt.preventDefault = preventDefault;
6009
+ evt.stopPropagation = stopPropagation;
6341
6010
 
6342
- // Included from: src/javascript/runtime/flash/Runtime.js
6011
+ callback(evt);
6012
+ };
6343
6013
 
6344
- /**
6345
- * Runtime.js
6346
- *
6347
- * Copyright 2013, Moxiecode Systems AB
6348
- * Released under GPL License.
6349
- *
6350
- * License: http://www.plupload.com/license
6351
- * Contributing: http://www.plupload.com/contributing
6352
- */
6353
-
6354
- /*global ActiveXObject:true */
6355
-
6356
- /**
6357
- Defines constructor for Flash runtime.
6358
-
6359
- @class moxie/runtime/flash/Runtime
6360
- @private
6361
- */
6362
- define("moxie/runtime/flash/Runtime", [
6363
- "moxie/core/utils/Basic",
6364
- "moxie/core/utils/Env",
6365
- "moxie/core/utils/Dom",
6366
- "moxie/core/Exceptions",
6367
- "moxie/runtime/Runtime"
6368
- ], function(Basic, Env, Dom, x, Runtime) {
6369
-
6370
- var type = 'flash', extensions = {};
6371
-
6372
- /**
6373
- Get the version of the Flash Player
6374
-
6375
- @method getShimVersion
6376
- @private
6377
- @return {Number} Flash Player version
6378
- */
6379
- function getShimVersion() {
6380
- var version;
6381
-
6382
- try {
6383
- version = navigator.plugins['Shockwave Flash'];
6384
- version = version.description;
6385
- } catch (e1) {
6386
- try {
6387
- version = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
6388
- } catch (e2) {
6389
- version = '0.0';
6390
- }
6391
- }
6392
- version = version.match(/\d+/g);
6393
- return parseFloat(version[0] + '.' + version[1]);
6394
- }
6395
-
6396
- /**
6397
- Constructor for the Flash Runtime
6398
-
6399
- @class FlashRuntime
6400
- @extends Runtime
6401
- */
6402
- function FlashRuntime(options) {
6403
- var I = this, initTimer;
6404
-
6405
- options = Basic.extend({ swf_url: Env.swf_url }, options);
6406
-
6407
- Runtime.call(this, options, type, {
6408
- access_binary: function(value) {
6409
- return value && I.mode === 'browser';
6410
- },
6411
- access_image_binary: function(value) {
6412
- return value && I.mode === 'browser';
6413
- },
6414
- display_media: Runtime.capTrue,
6415
- do_cors: Runtime.capTrue,
6416
- drag_and_drop: false,
6417
- report_upload_progress: function() {
6418
- return I.mode === 'client';
6419
- },
6420
- resize_image: Runtime.capTrue,
6421
- return_response_headers: false,
6422
- return_response_type: function(responseType) {
6423
- if (responseType === 'json' && !!window.JSON) {
6424
- return true;
6425
- }
6426
- return !Basic.arrayDiff(responseType, ['', 'text', 'document']) || I.mode === 'browser';
6427
- },
6428
- return_status_code: function(code) {
6429
- return I.mode === 'browser' || !Basic.arrayDiff(code, [200, 404]);
6430
- },
6431
- select_file: Runtime.capTrue,
6432
- select_multiple: Runtime.capTrue,
6433
- send_binary_string: function(value) {
6434
- return value && I.mode === 'browser';
6435
- },
6436
- send_browser_cookies: function(value) {
6437
- return value && I.mode === 'browser';
6438
- },
6439
- send_custom_headers: function(value) {
6440
- return value && I.mode === 'browser';
6441
- },
6442
- send_multipart: Runtime.capTrue,
6443
- slice_blob: function(value) {
6444
- return value && I.mode === 'browser';
6445
- },
6446
- stream_upload: function(value) {
6447
- return value && I.mode === 'browser';
6448
- },
6449
- summon_file_dialog: false,
6450
- upload_filesize: function(size) {
6451
- return Basic.parseSizeStr(size) <= 2097152 || I.mode === 'client';
6452
- },
6453
- use_http_method: function(methods) {
6454
- return !Basic.arrayDiff(methods, ['GET', 'POST']);
6455
- }
6456
- }, {
6457
- // capabilities that require specific mode
6458
- access_binary: function(value) {
6459
- return value ? 'browser' : 'client';
6460
- },
6461
- access_image_binary: function(value) {
6462
- return value ? 'browser' : 'client';
6463
- },
6464
- report_upload_progress: function(value) {
6465
- return value ? 'browser' : 'client';
6466
- },
6467
- return_response_type: function(responseType) {
6468
- return Basic.arrayDiff(responseType, ['', 'text', 'json', 'document']) ? 'browser' : ['client', 'browser'];
6469
- },
6470
- return_status_code: function(code) {
6471
- return Basic.arrayDiff(code, [200, 404]) ? 'browser' : ['client', 'browser'];
6472
- },
6473
- send_binary_string: function(value) {
6474
- return value ? 'browser' : 'client';
6475
- },
6476
- send_browser_cookies: function(value) {
6477
- return value ? 'browser' : 'client';
6478
- },
6479
- send_custom_headers: function(value) {
6480
- return value ? 'browser' : 'client';
6481
- },
6482
- stream_upload: function(value) {
6483
- return value ? 'client' : 'browser';
6484
- },
6485
- upload_filesize: function(size) {
6486
- return Basic.parseSizeStr(size) >= 2097152 ? 'client' : 'browser';
6487
- }
6488
- }, 'client');
6489
-
6490
-
6491
- // minimal requirement for Flash Player version
6492
- if (getShimVersion() < 10) {
6493
- this.mode = false; // with falsy mode, runtime won't operable, no matter what the mode was before
6494
- }
6495
-
6496
-
6497
- Basic.extend(this, {
6498
-
6499
- getShim: function() {
6500
- return Dom.get(this.uid);
6501
- },
6502
-
6503
- shimExec: function(component, action) {
6504
- var args = [].slice.call(arguments, 2);
6505
- return I.getShim().exec(this.uid, component, action, args);
6506
- },
6507
-
6508
- init: function() {
6509
- var html, el, container;
6510
-
6511
- container = this.getShimContainer();
6512
-
6513
- // if not the minimal height, shims are not initialized in older browsers (e.g FF3.6, IE6,7,8, Safari 4.0,5.0, etc)
6514
- Basic.extend(container.style, {
6515
- position: 'absolute',
6516
- top: '-8px',
6517
- left: '-8px',
6518
- width: '9px',
6519
- height: '9px',
6520
- overflow: 'hidden'
6521
- });
6522
-
6523
- // insert flash object
6524
- html = '<object id="' + this.uid + '" type="application/x-shockwave-flash" data="' + options.swf_url + '" ';
6525
-
6526
- if (Env.browser === 'IE') {
6527
- html += 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
6528
- }
6529
-
6530
- html += 'width="100%" height="100%" style="outline:0">' +
6531
- '<param name="movie" value="' + options.swf_url + '" />' +
6532
- '<param name="flashvars" value="uid=' + escape(this.uid) + '&target=' + Env.global_event_dispatcher + '" />' +
6533
- '<param name="wmode" value="transparent" />' +
6534
- '<param name="allowscriptaccess" value="always" />' +
6535
- '</object>';
6536
-
6537
- if (Env.browser === 'IE') {
6538
- el = document.createElement('div');
6539
- container.appendChild(el);
6540
- el.outerHTML = html;
6541
- el = container = null; // just in case
6542
- } else {
6543
- container.innerHTML = html;
6544
- }
6545
-
6546
- // Init is dispatched by the shim
6547
- initTimer = setTimeout(function() {
6548
- if (I && !I.initialized) { // runtime might be already destroyed by this moment
6549
- I.trigger("Error", new x.RuntimeError(x.RuntimeError.NOT_INIT_ERR));
6550
- }
6551
- }, 5000);
6552
- },
6553
-
6554
- destroy: (function(destroy) { // extend default destroy method
6555
- return function() {
6556
- destroy.call(I);
6557
- clearTimeout(initTimer); // initialization check might be still onwait
6558
- options = initTimer = destroy = I = null;
6559
- };
6560
- }(this.destroy))
6561
-
6562
- }, extensions);
6563
- }
6564
-
6565
- Runtime.addConstructor(type, FlashRuntime);
6566
-
6567
- return extensions;
6568
- });
6569
-
6570
- // Included from: src/javascript/runtime/flash/file/Blob.js
6571
-
6572
- /**
6573
- * Blob.js
6574
- *
6575
- * Copyright 2013, Moxiecode Systems AB
6576
- * Released under GPL License.
6577
- *
6578
- * License: http://www.plupload.com/license
6579
- * Contributing: http://www.plupload.com/contributing
6580
- */
6581
-
6582
- /**
6583
- @class moxie/runtime/flash/file/Blob
6584
- @private
6585
- */
6586
- define("moxie/runtime/flash/file/Blob", [
6587
- "moxie/runtime/flash/Runtime",
6588
- "moxie/file/Blob"
6589
- ], function(extensions, Blob) {
6590
-
6591
- var FlashBlob = {
6592
- slice: function(blob, start, end, type) {
6593
- var self = this.getRuntime();
6594
-
6595
- if (start < 0) {
6596
- start = Math.max(blob.size + start, 0);
6597
- } else if (start > 0) {
6598
- start = Math.min(start, blob.size);
6599
- }
6600
-
6601
- if (end < 0) {
6602
- end = Math.max(blob.size + end, 0);
6603
- } else if (end > 0) {
6604
- end = Math.min(end, blob.size);
6605
- }
6606
-
6607
- blob = self.shimExec.call(this, 'Blob', 'slice', start, end, type || '');
6608
-
6609
- if (blob) {
6610
- blob = new Blob(self.uid, blob);
6611
- }
6612
- return blob;
6014
+ obj.attachEvent('on' + name, func);
6613
6015
  }
6614
- };
6615
-
6616
- return (extensions.Blob = FlashBlob);
6617
- });
6618
-
6619
- // Included from: src/javascript/runtime/flash/file/FileInput.js
6620
-
6621
- /**
6622
- * FileInput.js
6623
- *
6624
- * Copyright 2013, Moxiecode Systems AB
6625
- * Released under GPL License.
6626
- *
6627
- * License: http://www.plupload.com/license
6628
- * Contributing: http://www.plupload.com/contributing
6629
- */
6630
-
6631
- /**
6632
- @class moxie/runtime/flash/file/FileInput
6633
- @private
6634
- */
6635
- define("moxie/runtime/flash/file/FileInput", [
6636
- "moxie/runtime/flash/Runtime"
6637
- ], function(extensions) {
6638
-
6639
- var FileInput = {
6640
- init: function(options) {
6641
- this.getRuntime().shimExec.call(this, 'FileInput', 'init', {
6642
- name: options.name,
6643
- accept: options.accept,
6644
- multiple: options.multiple
6645
- });
6646
- this.trigger('ready');
6016
+
6017
+ // Log event handler to objects internal mOxie registry
6018
+ if (!obj[uid]) {
6019
+ obj[uid] = Basic.guid();
6647
6020
  }
6648
- };
6649
-
6650
- return (extensions.FileInput = FileInput);
6651
- });
6652
-
6653
- // Included from: src/javascript/runtime/flash/file/FileReader.js
6654
-
6655
- /**
6656
- * FileReader.js
6657
- *
6658
- * Copyright 2013, Moxiecode Systems AB
6659
- * Released under GPL License.
6660
- *
6661
- * License: http://www.plupload.com/license
6662
- * Contributing: http://www.plupload.com/contributing
6663
- */
6664
-
6665
- /**
6666
- @class moxie/runtime/flash/file/FileReader
6667
- @private
6668
- */
6669
- define("moxie/runtime/flash/file/FileReader", [
6670
- "moxie/runtime/flash/Runtime",
6671
- "moxie/core/utils/Encode"
6672
- ], function(extensions, Encode) {
6673
-
6674
- var _result = '';
6675
-
6676
- function _formatData(data, op) {
6677
- switch (op) {
6678
- case 'readAsText':
6679
- return Encode.atob(data, 'utf8');
6680
- case 'readAsBinaryString':
6681
- return Encode.atob(data);
6682
- case 'readAsDataURL':
6683
- return data;
6021
+
6022
+ if (!eventhash.hasOwnProperty(obj[uid])) {
6023
+ eventhash[obj[uid]] = {};
6684
6024
  }
6685
- return null;
6686
- }
6687
-
6688
- var FileReader = {
6689
- read: function(op, blob) {
6690
- var target = this, self = target.getRuntime();
6691
-
6692
- // special prefix for DataURL read mode
6693
- if (op === 'readAsDataURL') {
6694
- _result = 'data:' + (blob.type || '') + ';base64,';
6695
- }
6696
-
6697
- target.bind('Progress', function(e, data) {
6698
- if (data) {
6699
- _result += _formatData(data, op);
6700
- }
6701
- });
6702
-
6703
- return self.shimExec.call(this, 'FileReader', 'readAsBase64', blob.uid);
6704
- },
6705
-
6706
- getResult: function() {
6707
- return _result;
6708
- },
6709
-
6710
- destroy: function() {
6711
- _result = null;
6025
+
6026
+ events = eventhash[obj[uid]];
6027
+
6028
+ if (!events.hasOwnProperty(name)) {
6029
+ events[name] = [];
6712
6030
  }
6031
+
6032
+ events[name].push({
6033
+ func: func,
6034
+ orig: callback, // store original callback for IE
6035
+ key: key
6036
+ });
6713
6037
  };
6714
-
6715
- return (extensions.FileReader = FileReader);
6716
- });
6717
-
6718
- // Included from: src/javascript/runtime/flash/file/FileReaderSync.js
6719
-
6720
- /**
6721
- * FileReaderSync.js
6722
- *
6723
- * Copyright 2013, Moxiecode Systems AB
6724
- * Released under GPL License.
6725
- *
6726
- * License: http://www.plupload.com/license
6727
- * Contributing: http://www.plupload.com/contributing
6728
- */
6729
-
6730
- /**
6731
- @class moxie/runtime/flash/file/FileReaderSync
6732
- @private
6733
- */
6734
- define("moxie/runtime/flash/file/FileReaderSync", [
6735
- "moxie/runtime/flash/Runtime",
6736
- "moxie/core/utils/Encode"
6737
- ], function(extensions, Encode) {
6738
6038
 
6739
- function _formatData(data, op) {
6740
- switch (op) {
6741
- case 'readAsText':
6742
- return Encode.atob(data, 'utf8');
6743
- case 'readAsBinaryString':
6744
- return Encode.atob(data);
6745
- case 'readAsDataURL':
6746
- return data;
6039
+
6040
+ /**
6041
+ Remove event handler from the specified object. If third argument (callback)
6042
+ is not specified remove all events with the specified name.
6043
+
6044
+ @method removeEvent
6045
+ @static
6046
+ @param {Object} obj DOM element to remove event listener(s) from.
6047
+ @param {String} name Name of event listener to remove.
6048
+ @param {Function|String} [callback] might be a callback or unique key to match.
6049
+ */
6050
+ var removeEvent = function(obj, name, callback) {
6051
+ var type, undef;
6052
+
6053
+ name = name.toLowerCase();
6054
+
6055
+ if (obj[uid] && eventhash[obj[uid]] && eventhash[obj[uid]][name]) {
6056
+ type = eventhash[obj[uid]][name];
6057
+ } else {
6058
+ return;
6747
6059
  }
6748
- return null;
6749
- }
6750
-
6751
- var FileReaderSync = {
6752
- read: function(op, blob) {
6753
- var result, self = this.getRuntime();
6754
-
6755
- result = self.shimExec.call(this, 'FileReaderSync', 'readAsBase64', blob.uid);
6756
- if (!result) {
6757
- return null; // or throw ex
6060
+
6061
+ for (var i = type.length - 1; i >= 0; i--) {
6062
+ // undefined or not, key should match
6063
+ if (type[i].orig === callback || type[i].key === callback) {
6064
+ if (obj.removeEventListener) {
6065
+ obj.removeEventListener(name, type[i].func, false);
6066
+ } else if (obj.detachEvent) {
6067
+ obj.detachEvent('on'+name, type[i].func);
6068
+ }
6069
+
6070
+ type[i].orig = null;
6071
+ type[i].func = null;
6072
+ type.splice(i, 1);
6073
+
6074
+ // If callback was passed we are done here, otherwise proceed
6075
+ if (callback !== undef) {
6076
+ break;
6077
+ }
6758
6078
  }
6759
-
6760
- // special prefix for DataURL read mode
6761
- if (op === 'readAsDataURL') {
6762
- result = 'data:' + (blob.type || '') + ';base64,' + result;
6079
+ }
6080
+
6081
+ // If event array got empty, remove it
6082
+ if (!type.length) {
6083
+ delete eventhash[obj[uid]][name];
6084
+ }
6085
+
6086
+ // If mOxie registry has become empty, remove it
6087
+ if (Basic.isEmptyObj(eventhash[obj[uid]])) {
6088
+ delete eventhash[obj[uid]];
6089
+
6090
+ // IE doesn't let you remove DOM object property with - delete
6091
+ try {
6092
+ delete obj[uid];
6093
+ } catch(e) {
6094
+ obj[uid] = undef;
6763
6095
  }
6764
-
6765
- return _formatData(result, op, blob.type);
6766
6096
  }
6767
6097
  };
6098
+
6099
+
6100
+ /**
6101
+ Remove all kind of events from the specified object
6102
+
6103
+ @method removeAllEvents
6104
+ @static
6105
+ @param {Object} obj DOM element to remove event listeners from.
6106
+ @param {String} [key] unique key to match, when removing events.
6107
+ */
6108
+ var removeAllEvents = function(obj, key) {
6109
+ if (!obj || !obj[uid]) {
6110
+ return;
6111
+ }
6112
+
6113
+ Basic.each(eventhash[obj[uid]], function(events, name) {
6114
+ removeEvent(obj, name, key);
6115
+ });
6116
+ };
6768
6117
 
6769
- return (extensions.FileReaderSync = FileReaderSync);
6118
+ return {
6119
+ addEvent: addEvent,
6120
+ removeEvent: removeEvent,
6121
+ removeAllEvents: removeAllEvents
6122
+ };
6770
6123
  });
6771
6124
 
6772
- // Included from: src/javascript/runtime/flash/xhr/XMLHttpRequest.js
6125
+ // Included from: src/javascript/runtime/html4/file/FileInput.js
6773
6126
 
6774
6127
  /**
6775
- * XMLHttpRequest.js
6128
+ * FileInput.js
6776
6129
  *
6777
6130
  * Copyright 2013, Moxiecode Systems AB
6778
6131
  * Released under GPL License.
@@ -6782,392 +6135,241 @@ define("moxie/runtime/flash/file/FileReaderSync", [
6782
6135
  */
6783
6136
 
6784
6137
  /**
6785
- @class moxie/runtime/flash/xhr/XMLHttpRequest
6138
+ @class moxie/runtime/html4/file/FileInput
6786
6139
  @private
6787
6140
  */
6788
- define("moxie/runtime/flash/xhr/XMLHttpRequest", [
6789
- "moxie/runtime/flash/Runtime",
6141
+ define("moxie/runtime/html4/file/FileInput", [
6142
+ "moxie/runtime/html4/Runtime",
6790
6143
  "moxie/core/utils/Basic",
6791
- "moxie/file/Blob",
6792
- "moxie/file/File",
6793
- "moxie/file/FileReaderSync",
6794
- "moxie/xhr/FormData",
6795
- "moxie/runtime/Transporter"
6796
- ], function(extensions, Basic, Blob, File, FileReaderSync, FormData, Transporter) {
6144
+ "moxie/core/utils/Dom",
6145
+ "moxie/core/utils/Events",
6146
+ "moxie/core/utils/Mime",
6147
+ "moxie/core/utils/Env"
6148
+ ], function(extensions, Basic, Dom, Events, Mime, Env) {
6797
6149
 
6798
- var XMLHttpRequest = {
6799
-
6800
- send: function(meta, data) {
6801
- var target = this, self = target.getRuntime();
6802
-
6803
- function send() {
6804
- meta.transport = self.mode;
6805
- self.shimExec.call(target, 'XMLHttpRequest', 'send', meta, data);
6806
- }
6807
-
6808
-
6809
- function appendBlob(name, blob) {
6810
- self.shimExec.call(target, 'XMLHttpRequest', 'appendBlob', name, blob.uid);
6811
- data = null;
6812
- send();
6813
- }
6814
-
6815
-
6816
- function attachBlob(blob, cb) {
6817
- var tr = new Transporter();
6818
-
6819
- tr.bind("TransportingComplete", function() {
6820
- cb(this.result);
6821
- });
6822
-
6823
- tr.transport(blob.getSource(), blob.type, {
6824
- ruid: self.uid
6825
- });
6826
- }
6827
-
6828
- // copy over the headers if any
6829
- if (!Basic.isEmptyObj(meta.headers)) {
6830
- Basic.each(meta.headers, function(value, header) {
6831
- self.shimExec.call(target, 'XMLHttpRequest', 'setRequestHeader', header, value.toString()); // Silverlight doesn't accept integers into the arguments of type object
6832
- });
6833
- }
6834
-
6835
- // transfer over multipart params and blob itself
6836
- if (data instanceof FormData) {
6837
- var blobField;
6838
- data.each(function(value, name) {
6839
- if (value instanceof Blob) {
6840
- blobField = name;
6841
- } else {
6842
- self.shimExec.call(target, 'XMLHttpRequest', 'append', name, value);
6843
- }
6844
- });
6845
-
6846
- if (!data.hasBlob()) {
6847
- data = null;
6848
- send();
6849
- } else {
6850
- var blob = data.getBlob();
6851
- if (blob.isDetached()) {
6852
- attachBlob(blob, function(attachedBlob) {
6853
- blob.destroy();
6854
- appendBlob(blobField, attachedBlob);
6855
- });
6856
- } else {
6857
- appendBlob(blobField, blob);
6858
- }
6859
- }
6860
- } else if (data instanceof Blob) {
6861
- if (data.isDetached()) {
6862
- attachBlob(data, function(attachedBlob) {
6863
- data.destroy();
6864
- data = attachedBlob.uid;
6865
- send();
6866
- });
6867
- } else {
6868
- data = data.uid;
6869
- send();
6870
- }
6871
- } else {
6872
- send();
6873
- }
6874
- },
6875
-
6876
- getResponse: function(responseType) {
6877
- var frs, blob, self = this.getRuntime();
6878
-
6879
- blob = self.shimExec.call(this, 'XMLHttpRequest', 'getResponseAsBlob');
6150
+ function FileInput() {
6151
+ var _uid, _files = [], _mimes = [], _options;
6880
6152
 
6881
- if (blob) {
6882
- blob = new File(self.uid, blob);
6153
+ function addInput() {
6154
+ var comp = this, I = comp.getRuntime(), shimContainer, browseButton, currForm, form, input, uid;
6883
6155
 
6884
- if ('blob' === responseType) {
6885
- return blob;
6886
- }
6156
+ uid = Basic.guid('uid_');
6887
6157
 
6888
- try {
6889
- frs = new FileReaderSync();
6158
+ shimContainer = I.getShimContainer(); // we get new ref everytime to avoid memory leaks in IE
6890
6159
 
6891
- if (!!~Basic.inArray(responseType, ["", "text"])) {
6892
- return frs.readAsText(blob);
6893
- } else if ('json' === responseType && !!window.JSON) {
6894
- return JSON.parse(frs.readAsText(blob));
6895
- }
6896
- } finally {
6897
- blob.destroy();
6160
+ if (_uid) { // move previous form out of the view
6161
+ currForm = Dom.get(_uid + '_form');
6162
+ if (currForm) {
6163
+ Basic.extend(currForm.style, { top: '100%' });
6898
6164
  }
6899
6165
  }
6900
- return null;
6901
- },
6902
-
6903
- abort: function(upload_complete_flag) {
6904
- var self = this.getRuntime();
6905
-
6906
- self.shimExec.call(this, 'XMLHttpRequest', 'abort');
6907
6166
 
6908
- this.dispatchEvent('readystatechange');
6909
- // this.dispatchEvent('progress');
6910
- this.dispatchEvent('abort');
6167
+ // build form in DOM, since innerHTML version not able to submit file for some reason
6168
+ form = document.createElement('form');
6169
+ form.setAttribute('id', uid + '_form');
6170
+ form.setAttribute('method', 'post');
6171
+ form.setAttribute('enctype', 'multipart/form-data');
6172
+ form.setAttribute('encoding', 'multipart/form-data');
6911
6173
 
6912
- //if (!upload_complete_flag) {
6913
- // this.dispatchEvent('uploadprogress');
6914
- //}
6915
- }
6916
- };
6174
+ Basic.extend(form.style, {
6175
+ overflow: 'hidden',
6176
+ position: 'absolute',
6177
+ top: 0,
6178
+ left: 0,
6179
+ width: '100%',
6180
+ height: '100%'
6181
+ });
6917
6182
 
6918
- return (extensions.XMLHttpRequest = XMLHttpRequest);
6919
- });
6183
+ input = document.createElement('input');
6184
+ input.setAttribute('id', uid);
6185
+ input.setAttribute('type', 'file');
6186
+ input.setAttribute('name', _options.name || 'Filedata');
6187
+ input.setAttribute('accept', _mimes.join(','));
6920
6188
 
6921
- // Included from: src/javascript/runtime/flash/runtime/Transporter.js
6189
+ Basic.extend(input.style, {
6190
+ fontSize: '999px',
6191
+ opacity: 0
6192
+ });
6922
6193
 
6923
- /**
6924
- * Transporter.js
6925
- *
6926
- * Copyright 2013, Moxiecode Systems AB
6927
- * Released under GPL License.
6928
- *
6929
- * License: http://www.plupload.com/license
6930
- * Contributing: http://www.plupload.com/contributing
6931
- */
6194
+ form.appendChild(input);
6195
+ shimContainer.appendChild(form);
6932
6196
 
6933
- /**
6934
- @class moxie/runtime/flash/runtime/Transporter
6935
- @private
6936
- */
6937
- define("moxie/runtime/flash/runtime/Transporter", [
6938
- "moxie/runtime/flash/Runtime",
6939
- "moxie/file/Blob"
6940
- ], function(extensions, Blob) {
6197
+ // prepare file input to be placed underneath the browse_button element
6198
+ Basic.extend(input.style, {
6199
+ position: 'absolute',
6200
+ top: 0,
6201
+ left: 0,
6202
+ width: '100%',
6203
+ height: '100%'
6204
+ });
6941
6205
 
6942
- var Transporter = {
6943
- getAsBlob: function(type) {
6944
- var self = this.getRuntime()
6945
- , blob = self.shimExec.call(this, 'Transporter', 'getAsBlob', type)
6946
- ;
6947
- if (blob) {
6948
- return new Blob(self.uid, blob);
6206
+ if (Env.browser === 'IE' && Env.version < 10) {
6207
+ Basic.extend(input.style, {
6208
+ filter : "progid:DXImageTransform.Microsoft.Alpha(opacity=0)"
6209
+ });
6949
6210
  }
6950
- return null;
6951
- }
6952
- };
6953
6211
 
6954
- return (extensions.Transporter = Transporter);
6955
- });
6212
+ input.onchange = function() { // there should be only one handler for this
6213
+ var file;
6956
6214
 
6215
+ if (!this.value) {
6216
+ return;
6217
+ }
6957
6218
 
6958
- // Included from: src/javascript/runtime/silverlight/Runtime.js
6219
+ if (this.files) {
6220
+ file = this.files[0];
6221
+ } else {
6222
+ file = {
6223
+ name: this.value
6224
+ };
6225
+ }
6959
6226
 
6960
- /**
6961
- * RunTime.js
6962
- *
6963
- * Copyright 2013, Moxiecode Systems AB
6964
- * Released under GPL License.
6965
- *
6966
- * License: http://www.plupload.com/license
6967
- * Contributing: http://www.plupload.com/contributing
6968
- */
6227
+ _files = [file];
6969
6228
 
6970
- /*global ActiveXObject:true */
6229
+ this.onchange = function() {}; // clear event handler
6230
+ addInput.call(comp);
6971
6231
 
6972
- /**
6973
- Defines constructor for Silverlight runtime.
6232
+ // after file is initialized as o.File, we need to update form and input ids
6233
+ comp.bind('change', function onChange() {
6234
+ var input = Dom.get(uid), form = Dom.get(uid + '_form'), file;
6974
6235
 
6975
- @class moxie/runtime/silverlight/Runtime
6976
- @private
6977
- */
6978
- define("moxie/runtime/silverlight/Runtime", [
6979
- "moxie/core/utils/Basic",
6980
- "moxie/core/utils/Env",
6981
- "moxie/core/utils/Dom",
6982
- "moxie/core/Exceptions",
6983
- "moxie/runtime/Runtime"
6984
- ], function(Basic, Env, Dom, x, Runtime) {
6985
-
6986
- var type = "silverlight", extensions = {};
6236
+ comp.unbind('change', onChange);
6987
6237
 
6988
- function isInstalled(version) {
6989
- var isVersionSupported = false, control = null, actualVer,
6990
- actualVerArray, reqVerArray, requiredVersionPart, actualVersionPart, index = 0;
6238
+ if (comp.files.length && input && form) {
6239
+ file = comp.files[0];
6991
6240
 
6992
- try {
6993
- try {
6994
- control = new ActiveXObject('AgControl.AgControl');
6241
+ input.setAttribute('id', file.uid);
6242
+ form.setAttribute('id', file.uid + '_form');
6995
6243
 
6996
- if (control.IsVersionSupported(version)) {
6997
- isVersionSupported = true;
6998
- }
6244
+ // set upload target
6245
+ form.setAttribute('target', file.uid + '_iframe');
6246
+ }
6247
+ input = form = null;
6248
+ }, 998);
6999
6249
 
7000
- control = null;
7001
- } catch (e) {
7002
- var plugin = navigator.plugins["Silverlight Plug-In"];
6250
+ input = form = null;
6251
+ comp.trigger('change');
6252
+ };
7003
6253
 
7004
- if (plugin) {
7005
- actualVer = plugin.description;
7006
6254
 
7007
- if (actualVer === "1.0.30226.2") {
7008
- actualVer = "2.0.30226.2";
6255
+ // route click event to the input
6256
+ if (I.can('summon_file_dialog')) {
6257
+ browseButton = Dom.get(_options.browse_button);
6258
+ Events.removeEvent(browseButton, 'click', comp.uid);
6259
+ Events.addEvent(browseButton, 'click', function(e) {
6260
+ if (input && !input.disabled) { // for some reason FF (up to 8.0.1 so far) lets to click disabled input[type=file]
6261
+ input.click();
7009
6262
  }
6263
+ e.preventDefault();
6264
+ }, comp.uid);
6265
+ }
7010
6266
 
7011
- actualVerArray = actualVer.split(".");
6267
+ _uid = uid;
7012
6268
 
7013
- while (actualVerArray.length > 3) {
7014
- actualVerArray.pop();
7015
- }
6269
+ shimContainer = currForm = browseButton = null;
6270
+ }
7016
6271
 
7017
- while ( actualVerArray.length < 4) {
7018
- actualVerArray.push(0);
7019
- }
6272
+ Basic.extend(this, {
6273
+ init: function(options) {
6274
+ var comp = this, I = comp.getRuntime(), shimContainer;
7020
6275
 
7021
- reqVerArray = version.split(".");
6276
+ // figure out accept string
6277
+ _options = options;
6278
+ _mimes = options.accept.mimes || Mime.extList2mimes(options.accept, I.can('filter_by_extension'));
7022
6279
 
7023
- while (reqVerArray.length > 4) {
7024
- reqVerArray.pop();
7025
- }
6280
+ shimContainer = I.getShimContainer();
7026
6281
 
7027
- do {
7028
- requiredVersionPart = parseInt(reqVerArray[index], 10);
7029
- actualVersionPart = parseInt(actualVerArray[index], 10);
7030
- index++;
7031
- } while (index < reqVerArray.length && requiredVersionPart === actualVersionPart);
6282
+ (function() {
6283
+ var browseButton, zIndex, top;
7032
6284
 
7033
- if (requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart)) {
7034
- isVersionSupported = true;
6285
+ browseButton = Dom.get(options.browse_button);
6286
+
6287
+ // Route click event to the input[type=file] element for browsers that support such behavior
6288
+ if (I.can('summon_file_dialog')) {
6289
+ if (Dom.getStyle(browseButton, 'position') === 'static') {
6290
+ browseButton.style.position = 'relative';
6291
+ }
6292
+
6293
+ zIndex = parseInt(Dom.getStyle(browseButton, 'z-index'), 10) || 1;
6294
+
6295
+ browseButton.style.zIndex = zIndex;
6296
+ shimContainer.style.zIndex = zIndex - 1;
7035
6297
  }
7036
- }
7037
- }
7038
- } catch (e2) {
7039
- isVersionSupported = false;
7040
- }
7041
6298
 
7042
- return isVersionSupported;
7043
- }
6299
+ /* Since we have to place input[type=file] on top of the browse_button for some browsers,
6300
+ browse_button loses interactivity, so we restore it here */
6301
+ top = I.can('summon_file_dialog') ? browseButton : shimContainer;
7044
6302
 
7045
- /**
7046
- Constructor for the Silverlight Runtime
6303
+ Events.addEvent(top, 'mouseover', function() {
6304
+ comp.trigger('mouseenter');
6305
+ }, comp.uid);
7047
6306
 
7048
- @class SilverlightRuntime
7049
- @extends Runtime
7050
- */
7051
- function SilverlightRuntime(options) {
7052
- var I = this, initTimer;
6307
+ Events.addEvent(top, 'mouseout', function() {
6308
+ comp.trigger('mouseleave');
6309
+ }, comp.uid);
7053
6310
 
7054
- options = Basic.extend({ xap_url: Env.xap_url }, options);
6311
+ Events.addEvent(top, 'mousedown', function() {
6312
+ comp.trigger('mousedown');
6313
+ }, comp.uid);
7055
6314
 
7056
- Runtime.call(this, options, type, {
7057
- access_binary: Runtime.capTrue,
7058
- access_image_binary: Runtime.capTrue,
7059
- display_media: Runtime.capTrue,
7060
- do_cors: Runtime.capTrue,
7061
- drag_and_drop: false,
7062
- report_upload_progress: Runtime.capTrue,
7063
- resize_image: Runtime.capTrue,
7064
- return_response_headers: function(value) {
7065
- return value && I.mode === 'client';
7066
- },
7067
- return_response_type: function(responseType) {
7068
- if (responseType !== 'json') {
7069
- return true;
7070
- } else {
7071
- return !!window.JSON;
7072
- }
7073
- },
7074
- return_status_code: function(code) {
7075
- return I.mode === 'client' || !Basic.arrayDiff(code, [200, 404]);
7076
- },
7077
- select_file: Runtime.capTrue,
7078
- select_multiple: Runtime.capTrue,
7079
- send_binary_string: Runtime.capTrue,
7080
- send_browser_cookies: function(value) {
7081
- return value && I.mode === 'browser';
7082
- },
7083
- send_custom_headers: function(value) {
7084
- return value && I.mode === 'client';
7085
- },
7086
- send_multipart: Runtime.capTrue,
7087
- slice_blob: Runtime.capTrue,
7088
- stream_upload: true,
7089
- summon_file_dialog: false,
7090
- upload_filesize: Runtime.capTrue,
7091
- use_http_method: function(methods) {
7092
- return I.mode === 'client' || !Basic.arrayDiff(methods, ['GET', 'POST']);
7093
- }
7094
- }, {
7095
- // capabilities that require specific mode
7096
- return_response_headers: function(value) {
7097
- return value ? 'client' : 'browser';
7098
- },
7099
- return_status_code: function(code) {
7100
- return Basic.arrayDiff(code, [200, 404]) ? 'client' : ['client', 'browser'];
7101
- },
7102
- send_browser_cookies: function(value) {
7103
- return value ? 'browser' : 'client';
7104
- },
7105
- send_custom_headers: function(value) {
7106
- return value ? 'client' : 'browser';
7107
- },
7108
- use_http_method: function(methods) {
7109
- return Basic.arrayDiff(methods, ['GET', 'POST']) ? 'client' : ['client', 'browser'];
7110
- }
7111
- });
6315
+ Events.addEvent(Dom.get(options.container), 'mouseup', function() {
6316
+ comp.trigger('mouseup');
6317
+ }, comp.uid);
7112
6318
 
6319
+ browseButton = null;
6320
+ }());
7113
6321
 
7114
- // minimal requirement
7115
- if (!isInstalled('2.0.31005.0') || Env.browser === 'Opera') {
7116
- this.mode = false;
7117
- }
6322
+ addInput.call(this);
7118
6323
 
6324
+ shimContainer = null;
7119
6325
 
7120
- Basic.extend(this, {
7121
- getShim: function() {
7122
- return Dom.get(this.uid).content.Moxie;
6326
+ // trigger ready event asynchronously
6327
+ comp.trigger({
6328
+ type: 'ready',
6329
+ async: true
6330
+ });
7123
6331
  },
7124
6332
 
7125
- shimExec: function(component, action) {
7126
- var args = [].slice.call(arguments, 2);
7127
- return I.getShim().exec(this.uid, component, action, args);
6333
+ getFiles: function() {
6334
+ return _files;
7128
6335
  },
7129
6336
 
7130
- init : function() {
7131
- var container;
7132
-
7133
- container = this.getShimContainer();
7134
-
7135
- container.innerHTML = '<object id="' + this.uid + '" data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%" style="outline:none;">' +
7136
- '<param name="source" value="' + options.xap_url + '"/>' +
7137
- '<param name="background" value="Transparent"/>' +
7138
- '<param name="windowless" value="true"/>' +
7139
- '<param name="enablehtmlaccess" value="true"/>' +
7140
- '<param name="initParams" value="uid=' + this.uid + ',target=' + Env.global_event_dispatcher + '"/>' +
7141
- '</object>';
6337
+ disable: function(state) {
6338
+ var input;
7142
6339
 
7143
- // Init is dispatched by the shim
7144
- initTimer = setTimeout(function() {
7145
- if (I && !I.initialized) { // runtime might be already destroyed by this moment
7146
- I.trigger("Error", new x.RuntimeError(x.RuntimeError.NOT_INIT_ERR));
7147
- }
7148
- }, Env.OS !== 'Windows'? 10000 : 5000); // give it more time to initialize in non Windows OS (like Mac)
6340
+ if ((input = Dom.get(_uid))) {
6341
+ input.disabled = !!state;
6342
+ }
7149
6343
  },
7150
6344
 
7151
- destroy: (function(destroy) { // extend default destroy method
7152
- return function() {
7153
- destroy.call(I);
7154
- clearTimeout(initTimer); // initialization check might be still onwait
7155
- options = initTimer = destroy = I = null;
7156
- };
7157
- }(this.destroy))
6345
+ destroy: function() {
6346
+ var I = this.getRuntime()
6347
+ , shim = I.getShim()
6348
+ , shimContainer = I.getShimContainer()
6349
+ ;
6350
+
6351
+ Events.removeAllEvents(shimContainer, this.uid);
6352
+ Events.removeAllEvents(_options && Dom.get(_options.container), this.uid);
6353
+ Events.removeAllEvents(_options && Dom.get(_options.browse_button), this.uid);
6354
+
6355
+ if (shimContainer) {
6356
+ shimContainer.innerHTML = '';
6357
+ }
7158
6358
 
7159
- }, extensions);
7160
- }
6359
+ shim.removeInstance(this.uid);
7161
6360
 
7162
- Runtime.addConstructor(type, SilverlightRuntime);
6361
+ _uid = _files = _mimes = _options = shimContainer = shim = null;
6362
+ }
6363
+ });
6364
+ }
7163
6365
 
7164
- return extensions;
6366
+ return (extensions.FileInput = FileInput);
7165
6367
  });
7166
6368
 
7167
- // Included from: src/javascript/runtime/silverlight/file/Blob.js
6369
+ // Included from: src/javascript/runtime/html5/Runtime.js
7168
6370
 
7169
6371
  /**
7170
- * Blob.js
6372
+ * Runtime.js
7171
6373
  *
7172
6374
  * Copyright 2013, Moxiecode Systems AB
7173
6375
  * Released under GPL License.
@@ -7176,22 +6378,118 @@ define("moxie/runtime/silverlight/Runtime", [
7176
6378
  * Contributing: http://www.plupload.com/contributing
7177
6379
  */
7178
6380
 
6381
+ /*global File:true */
6382
+
7179
6383
  /**
7180
- @class moxie/runtime/silverlight/file/Blob
6384
+ Defines constructor for HTML5 runtime.
6385
+
6386
+ @class moxie/runtime/html5/Runtime
7181
6387
  @private
7182
6388
  */
7183
- define("moxie/runtime/silverlight/file/Blob", [
7184
- "moxie/runtime/silverlight/Runtime",
6389
+ define("moxie/runtime/html5/Runtime", [
7185
6390
  "moxie/core/utils/Basic",
7186
- "moxie/runtime/flash/file/Blob"
7187
- ], function(extensions, Basic, Blob) {
7188
- return (extensions.Blob = Basic.extend({}, Blob));
6391
+ "moxie/core/Exceptions",
6392
+ "moxie/runtime/Runtime",
6393
+ "moxie/core/utils/Env"
6394
+ ], function(Basic, x, Runtime, Env) {
6395
+
6396
+ var type = "html5", extensions = {};
6397
+
6398
+ function Html5Runtime(options) {
6399
+ var I = this
6400
+ , Test = Runtime.capTest
6401
+ , True = Runtime.capTrue
6402
+ ;
6403
+
6404
+ var caps = Basic.extend({
6405
+ access_binary: Test(window.FileReader || window.File && window.File.getAsDataURL),
6406
+ access_image_binary: function() {
6407
+ return I.can('access_binary') && !!extensions.Image;
6408
+ },
6409
+ display_media: Test(Env.can('create_canvas') || Env.can('use_data_uri_over32kb')),
6410
+ do_cors: Test(window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest()),
6411
+ drag_and_drop: Test(function() {
6412
+ // this comes directly from Modernizr: http://www.modernizr.com/
6413
+ var div = document.createElement('div');
6414
+ // IE has support for drag and drop since version 5, but doesn't support dropping files from desktop
6415
+ return (('draggable' in div) || ('ondragstart' in div && 'ondrop' in div)) && (Env.browser !== 'IE' || Env.version > 9);
6416
+ }()),
6417
+ filter_by_extension: Test(function() { // if you know how to feature-detect this, please suggest
6418
+ return (Env.browser === 'Chrome' && Env.version >= 28) || (Env.browser === 'IE' && Env.version >= 10);
6419
+ }()),
6420
+ return_response_headers: True,
6421
+ return_response_type: function(responseType) {
6422
+ if (responseType === 'json' && !!window.JSON) { // we can fake this one even if it's not supported
6423
+ return true;
6424
+ }
6425
+ return Env.can('return_response_type', responseType);
6426
+ },
6427
+ return_status_code: True,
6428
+ report_upload_progress: Test(window.XMLHttpRequest && new XMLHttpRequest().upload),
6429
+ resize_image: function() {
6430
+ return I.can('access_binary') && Env.can('create_canvas');
6431
+ },
6432
+ select_file: function() {
6433
+ return Env.can('use_fileinput') && window.File;
6434
+ },
6435
+ select_folder: function() {
6436
+ return I.can('select_file') && Env.browser === 'Chrome' && Env.version >= 21;
6437
+ },
6438
+ select_multiple: function() {
6439
+ // it is buggy on Safari Windows and iOS
6440
+ return I.can('select_file') &&
6441
+ !(Env.browser === 'Safari' && Env.os === 'Windows') &&
6442
+ !(Env.os === 'iOS' && Env.verComp(Env.osVersion, "7.0.4", '<'));
6443
+ },
6444
+ send_binary_string: Test(window.XMLHttpRequest && (new XMLHttpRequest().sendAsBinary || (window.Uint8Array && window.ArrayBuffer))),
6445
+ send_custom_headers: Test(window.XMLHttpRequest),
6446
+ send_multipart: function() {
6447
+ return !!(window.XMLHttpRequest && new XMLHttpRequest().upload && window.FormData) || I.can('send_binary_string');
6448
+ },
6449
+ slice_blob: Test(window.File && (File.prototype.mozSlice || File.prototype.webkitSlice || File.prototype.slice)),
6450
+ stream_upload: function(){
6451
+ return I.can('slice_blob') && I.can('send_multipart');
6452
+ },
6453
+ summon_file_dialog: Test(function() { // yeah... some dirty sniffing here...
6454
+ return (Env.browser === 'Firefox' && Env.version >= 4) ||
6455
+ (Env.browser === 'Opera' && Env.version >= 12) ||
6456
+ (Env.browser === 'IE' && Env.version >= 10) ||
6457
+ !!~Basic.inArray(Env.browser, ['Chrome', 'Safari']);
6458
+ }()),
6459
+ upload_filesize: True
6460
+ },
6461
+ arguments[2]
6462
+ );
6463
+
6464
+ Runtime.call(this, options, (arguments[1] || type), caps);
6465
+
6466
+
6467
+ Basic.extend(this, {
6468
+
6469
+ init : function() {
6470
+ this.trigger("Init");
6471
+ },
6472
+
6473
+ destroy: (function(destroy) { // extend default destroy method
6474
+ return function() {
6475
+ destroy.call(I);
6476
+ destroy = I = null;
6477
+ };
6478
+ }(this.destroy))
6479
+ });
6480
+
6481
+ Basic.extend(this.getShim(), extensions);
6482
+ }
6483
+
6484
+ Runtime.addConstructor(type, Html5Runtime);
6485
+
6486
+ return extensions;
7189
6487
  });
7190
6488
 
7191
- // Included from: src/javascript/runtime/silverlight/file/FileInput.js
6489
+ // Included from: src/javascript/runtime/html5/file/FileReader.js
7192
6490
 
7193
6491
  /**
7194
- * FileInput.js
6492
+ * FileReader.js
7195
6493
  *
7196
6494
  * Copyright 2013, Moxiecode Systems AB
7197
6495
  * Released under GPL License.
@@ -7201,33 +6499,74 @@ define("moxie/runtime/silverlight/file/Blob", [
7201
6499
  */
7202
6500
 
7203
6501
  /**
7204
- @class moxie/runtime/silverlight/file/FileInput
6502
+ @class moxie/runtime/html5/file/FileReader
7205
6503
  @private
7206
6504
  */
7207
- define("moxie/runtime/silverlight/file/FileInput", [
7208
- "moxie/runtime/silverlight/Runtime"
7209
- ], function(extensions) {
6505
+ define("moxie/runtime/html5/file/FileReader", [
6506
+ "moxie/runtime/html5/Runtime",
6507
+ "moxie/core/utils/Encode",
6508
+ "moxie/core/utils/Basic"
6509
+ ], function(extensions, Encode, Basic) {
7210
6510
 
7211
- var FileInput = {
7212
- init: function(options) {
6511
+ function FileReader() {
6512
+ var _fr, _convertToBinary = false;
7213
6513
 
7214
- function toFilters(accept) {
7215
- var filter = '';
7216
- for (var i = 0; i < accept.length; i++) {
7217
- filter += (filter !== '' ? '|' : '') + accept[i].title + " | *." + accept[i].extensions.replace(/,/g, ';*.');
6514
+ Basic.extend(this, {
6515
+
6516
+ read: function(op, blob) {
6517
+ var target = this;
6518
+
6519
+ _fr = new window.FileReader();
6520
+
6521
+ _fr.addEventListener('progress', function(e) {
6522
+ target.trigger(e);
6523
+ });
6524
+
6525
+ _fr.addEventListener('load', function(e) {
6526
+ target.trigger(e);
6527
+ });
6528
+
6529
+ _fr.addEventListener('error', function(e) {
6530
+ target.trigger(e, _fr.error);
6531
+ });
6532
+
6533
+ _fr.addEventListener('loadend', function() {
6534
+ _fr = null;
6535
+ });
6536
+
6537
+ if (Basic.typeOf(_fr[op]) === 'function') {
6538
+ _convertToBinary = false;
6539
+ _fr[op](blob.getSource());
6540
+ } else if (op === 'readAsBinaryString') { // readAsBinaryString is depricated in general and never existed in IE10+
6541
+ _convertToBinary = true;
6542
+ _fr.readAsDataURL(blob.getSource());
7218
6543
  }
7219
- return filter;
6544
+ },
6545
+
6546
+ getResult: function() {
6547
+ return _fr && _fr.result ? (_convertToBinary ? _toBinary(_fr.result) : _fr.result) : null;
6548
+ },
6549
+
6550
+ abort: function() {
6551
+ if (_fr) {
6552
+ _fr.abort();
6553
+ }
6554
+ },
6555
+
6556
+ destroy: function() {
6557
+ _fr = null;
7220
6558
  }
7221
-
7222
- this.getRuntime().shimExec.call(this, 'FileInput', 'init', toFilters(options.accept), options.name, options.multiple);
7223
- this.trigger('ready');
6559
+ });
6560
+
6561
+ function _toBinary(str) {
6562
+ return Encode.atob(str.substring(str.indexOf('base64,') + 7));
7224
6563
  }
7225
- };
6564
+ }
7226
6565
 
7227
- return (extensions.FileInput = FileInput);
6566
+ return (extensions.FileReader = FileReader);
7228
6567
  });
7229
6568
 
7230
- // Included from: src/javascript/runtime/silverlight/file/FileReader.js
6569
+ // Included from: src/javascript/runtime/html4/file/FileReader.js
7231
6570
 
7232
6571
  /**
7233
6572
  * FileReader.js
@@ -7240,21 +6579,20 @@ define("moxie/runtime/silverlight/file/FileInput", [
7240
6579
  */
7241
6580
 
7242
6581
  /**
7243
- @class moxie/runtime/silverlight/file/FileReader
6582
+ @class moxie/runtime/html4/file/FileReader
7244
6583
  @private
7245
6584
  */
7246
- define("moxie/runtime/silverlight/file/FileReader", [
7247
- "moxie/runtime/silverlight/Runtime",
7248
- "moxie/core/utils/Basic",
7249
- "moxie/runtime/flash/file/FileReader"
7250
- ], function(extensions, Basic, FileReader) {
7251
- return (extensions.FileReader = Basic.extend({}, FileReader));
6585
+ define("moxie/runtime/html4/file/FileReader", [
6586
+ "moxie/runtime/html4/Runtime",
6587
+ "moxie/runtime/html5/file/FileReader"
6588
+ ], function(extensions, FileReader) {
6589
+ return (extensions.FileReader = FileReader);
7252
6590
  });
7253
6591
 
7254
- // Included from: src/javascript/runtime/silverlight/file/FileReaderSync.js
6592
+ // Included from: src/javascript/runtime/html4/xhr/XMLHttpRequest.js
7255
6593
 
7256
6594
  /**
7257
- * FileReaderSync.js
6595
+ * XMLHttpRequest.js
7258
6596
  *
7259
6597
  * Copyright 2013, Moxiecode Systems AB
7260
6598
  * Released under GPL License.
@@ -7264,172 +6602,244 @@ define("moxie/runtime/silverlight/file/FileReader", [
7264
6602
  */
7265
6603
 
7266
6604
  /**
7267
- @class moxie/runtime/silverlight/file/FileReaderSync
6605
+ @class moxie/runtime/html4/xhr/XMLHttpRequest
7268
6606
  @private
7269
6607
  */
7270
- define("moxie/runtime/silverlight/file/FileReaderSync", [
7271
- "moxie/runtime/silverlight/Runtime",
6608
+ define("moxie/runtime/html4/xhr/XMLHttpRequest", [
6609
+ "moxie/runtime/html4/Runtime",
7272
6610
  "moxie/core/utils/Basic",
7273
- "moxie/runtime/flash/file/FileReaderSync"
7274
- ], function(extensions, Basic, FileReaderSync) {
7275
- return (extensions.FileReaderSync = Basic.extend({}, FileReaderSync));
7276
- });
6611
+ "moxie/core/utils/Dom",
6612
+ "moxie/core/utils/Url",
6613
+ "moxie/core/Exceptions",
6614
+ "moxie/core/utils/Events",
6615
+ "moxie/file/Blob",
6616
+ "moxie/xhr/FormData"
6617
+ ], function(extensions, Basic, Dom, Url, x, Events, Blob, FormData) {
6618
+
6619
+ function XMLHttpRequest() {
6620
+ var _status, _response, _iframe;
7277
6621
 
7278
- // Included from: src/javascript/runtime/silverlight/xhr/XMLHttpRequest.js
6622
+ function cleanup(cb) {
6623
+ var target = this, uid, form, inputs, i, hasFile = false;
7279
6624
 
7280
- /**
7281
- * XMLHttpRequest.js
7282
- *
7283
- * Copyright 2013, Moxiecode Systems AB
7284
- * Released under GPL License.
7285
- *
7286
- * License: http://www.plupload.com/license
7287
- * Contributing: http://www.plupload.com/contributing
7288
- */
6625
+ if (!_iframe) {
6626
+ return;
6627
+ }
7289
6628
 
7290
- /**
7291
- @class moxie/runtime/silverlight/xhr/XMLHttpRequest
7292
- @private
7293
- */
7294
- define("moxie/runtime/silverlight/xhr/XMLHttpRequest", [
7295
- "moxie/runtime/silverlight/Runtime",
7296
- "moxie/core/utils/Basic",
7297
- "moxie/runtime/flash/xhr/XMLHttpRequest"
7298
- ], function(extensions, Basic, XMLHttpRequest) {
7299
- return (extensions.XMLHttpRequest = Basic.extend({}, XMLHttpRequest));
7300
- });
6629
+ uid = _iframe.id.replace(/_iframe$/, '');
7301
6630
 
7302
- // Included from: src/javascript/runtime/silverlight/runtime/Transporter.js
6631
+ form = Dom.get(uid + '_form');
6632
+ if (form) {
6633
+ inputs = form.getElementsByTagName('input');
6634
+ i = inputs.length;
7303
6635
 
7304
- /**
7305
- * Transporter.js
7306
- *
7307
- * Copyright 2013, Moxiecode Systems AB
7308
- * Released under GPL License.
7309
- *
7310
- * License: http://www.plupload.com/license
7311
- * Contributing: http://www.plupload.com/contributing
7312
- */
6636
+ while (i--) {
6637
+ switch (inputs[i].getAttribute('type')) {
6638
+ case 'hidden':
6639
+ inputs[i].parentNode.removeChild(inputs[i]);
6640
+ break;
6641
+ case 'file':
6642
+ hasFile = true; // flag the case for later
6643
+ break;
6644
+ }
6645
+ }
6646
+ inputs = [];
7313
6647
 
7314
- /**
7315
- @class moxie/runtime/silverlight/runtime/Transporter
7316
- @private
7317
- */
7318
- define("moxie/runtime/silverlight/runtime/Transporter", [
7319
- "moxie/runtime/silverlight/Runtime",
7320
- "moxie/core/utils/Basic",
7321
- "moxie/runtime/flash/runtime/Transporter"
7322
- ], function(extensions, Basic, Transporter) {
7323
- return (extensions.Transporter = Basic.extend({}, Transporter));
7324
- });
6648
+ if (!hasFile) { // we need to keep the form for sake of possible retries
6649
+ form.parentNode.removeChild(form);
6650
+ }
6651
+ form = null;
6652
+ }
7325
6653
 
6654
+ // without timeout, request is marked as canceled (in console)
6655
+ setTimeout(function() {
6656
+ Events.removeEvent(_iframe, 'load', target.uid);
6657
+ if (_iframe.parentNode) { // #382
6658
+ _iframe.parentNode.removeChild(_iframe);
6659
+ }
7326
6660
 
7327
- // Included from: src/javascript/runtime/html4/Runtime.js
6661
+ // check if shim container has any other children, if - not, remove it as well
6662
+ var shimContainer = target.getRuntime().getShimContainer();
6663
+ if (!shimContainer.children.length) {
6664
+ shimContainer.parentNode.removeChild(shimContainer);
6665
+ }
7328
6666
 
7329
- /**
7330
- * Runtime.js
7331
- *
7332
- * Copyright 2013, Moxiecode Systems AB
7333
- * Released under GPL License.
7334
- *
7335
- * License: http://www.plupload.com/license
7336
- * Contributing: http://www.plupload.com/contributing
7337
- */
6667
+ shimContainer = _iframe = null;
6668
+ cb();
6669
+ }, 1);
6670
+ }
7338
6671
 
7339
- /*global File:true */
6672
+ Basic.extend(this, {
6673
+ send: function(meta, data) {
6674
+ var target = this, I = target.getRuntime(), uid, form, input, blob;
7340
6675
 
7341
- /**
7342
- Defines constructor for HTML4 runtime.
6676
+ _status = _response = null;
7343
6677
 
7344
- @class moxie/runtime/html4/Runtime
7345
- @private
7346
- */
7347
- define("moxie/runtime/html4/Runtime", [
7348
- "moxie/core/utils/Basic",
7349
- "moxie/core/Exceptions",
7350
- "moxie/runtime/Runtime",
7351
- "moxie/core/utils/Env"
7352
- ], function(Basic, x, Runtime, Env) {
7353
-
7354
- var type = 'html4', extensions = {};
6678
+ function createIframe() {
6679
+ var container = I.getShimContainer() || document.body
6680
+ , temp = document.createElement('div')
6681
+ ;
6682
+
6683
+ // IE 6 won't be able to set the name using setAttribute or iframe.name
6684
+ temp.innerHTML = '<iframe id="' + uid + '_iframe" name="' + uid + '_iframe" src="javascript:&quot;&quot;" style="display:none"></iframe>';
6685
+ _iframe = temp.firstChild;
6686
+ container.appendChild(_iframe);
6687
+
6688
+ /* _iframe.onreadystatechange = function() {
6689
+ console.info(_iframe.readyState);
6690
+ };*/
6691
+
6692
+ Events.addEvent(_iframe, 'load', function() { // _iframe.onload doesn't work in IE lte 8
6693
+ var el;
6694
+
6695
+ try {
6696
+ el = _iframe.contentWindow.document || _iframe.contentDocument || window.frames[_iframe.id].document;
6697
+
6698
+ // try to detect some standard error pages
6699
+ if (/^4(0[0-9]|1[0-7]|2[2346])\s/.test(el.title)) { // test if title starts with 4xx HTTP error
6700
+ _status = el.title.replace(/^(\d+).*$/, '$1');
6701
+ } else {
6702
+ _status = 200;
6703
+ // get result
6704
+ _response = Basic.trim(el.body.innerHTML);
6705
+
6706
+ // we need to fire these at least once
6707
+ target.trigger({
6708
+ type: 'progress',
6709
+ loaded: _response.length,
6710
+ total: _response.length
6711
+ });
6712
+
6713
+ if (blob) { // if we were uploading a file
6714
+ target.trigger({
6715
+ type: 'uploadprogress',
6716
+ loaded: blob.size || 1025,
6717
+ total: blob.size || 1025
6718
+ });
6719
+ }
6720
+ }
6721
+ } catch (ex) {
6722
+ if (Url.hasSameOrigin(meta.url)) {
6723
+ // if response is sent with error code, iframe in IE gets redirected to res://ieframe.dll/http_x.htm
6724
+ // which obviously results to cross domain error (wtf?)
6725
+ _status = 404;
6726
+ } else {
6727
+ cleanup.call(target, function() {
6728
+ target.trigger('error');
6729
+ });
6730
+ return;
6731
+ }
6732
+ }
6733
+
6734
+ cleanup.call(target, function() {
6735
+ target.trigger('load');
6736
+ });
6737
+ }, target.uid);
6738
+ } // end createIframe
6739
+
6740
+ // prepare data to be sent and convert if required
6741
+ if (data instanceof FormData && data.hasBlob()) {
6742
+ blob = data.getBlob();
6743
+ uid = blob.uid;
6744
+ input = Dom.get(uid);
6745
+ form = Dom.get(uid + '_form');
6746
+ if (!form) {
6747
+ throw new x.DOMException(x.DOMException.NOT_FOUND_ERR);
6748
+ }
6749
+ } else {
6750
+ uid = Basic.guid('uid_');
6751
+
6752
+ form = document.createElement('form');
6753
+ form.setAttribute('id', uid + '_form');
6754
+ form.setAttribute('method', meta.method);
6755
+ form.setAttribute('enctype', 'multipart/form-data');
6756
+ form.setAttribute('encoding', 'multipart/form-data');
6757
+ form.setAttribute('target', uid + '_iframe');
6758
+
6759
+ I.getShimContainer().appendChild(form);
6760
+ }
6761
+
6762
+ if (data instanceof FormData) {
6763
+ data.each(function(value, name) {
6764
+ if (value instanceof Blob) {
6765
+ if (input) {
6766
+ input.setAttribute('name', name);
6767
+ }
6768
+ } else {
6769
+ var hidden = document.createElement('input');
6770
+
6771
+ Basic.extend(hidden, {
6772
+ type : 'hidden',
6773
+ name : name,
6774
+ value : value
6775
+ });
6776
+
6777
+ // make sure that input[type="file"], if it's there, comes last
6778
+ if (input) {
6779
+ form.insertBefore(hidden, input);
6780
+ } else {
6781
+ form.appendChild(hidden);
6782
+ }
6783
+ }
6784
+ });
6785
+ }
7355
6786
 
7356
- function Html4Runtime(options) {
7357
- var I = this
7358
- , Test = Runtime.capTest
7359
- , True = Runtime.capTrue
7360
- ;
6787
+ // set destination url
6788
+ form.setAttribute("action", meta.url);
7361
6789
 
7362
- Runtime.call(this, options, type, {
7363
- access_binary: Test(window.FileReader || window.File && File.getAsDataURL),
7364
- access_image_binary: false,
7365
- display_media: Test(extensions.Image && (Env.can('create_canvas') || Env.can('use_data_uri_over32kb'))),
7366
- do_cors: false,
7367
- drag_and_drop: false,
7368
- filter_by_extension: Test(function() { // if you know how to feature-detect this, please suggest
7369
- return (Env.browser === 'Chrome' && Env.version >= 28) || (Env.browser === 'IE' && Env.version >= 10);
7370
- }()),
7371
- resize_image: function() {
7372
- return extensions.Image && I.can('access_binary') && Env.can('create_canvas');
7373
- },
7374
- report_upload_progress: false,
7375
- return_response_headers: false,
7376
- return_response_type: function(responseType) {
7377
- if (responseType === 'json' && !!window.JSON) {
7378
- return true;
7379
- }
7380
- return !!~Basic.inArray(responseType, ['text', 'document', '']);
7381
- },
7382
- return_status_code: function(code) {
7383
- return !Basic.arrayDiff(code, [200, 404]);
7384
- },
7385
- select_file: function() {
7386
- return Env.can('use_fileinput');
6790
+ createIframe();
6791
+ form.submit();
6792
+ target.trigger('loadstart');
7387
6793
  },
7388
- select_multiple: false,
7389
- send_binary_string: false,
7390
- send_custom_headers: false,
7391
- send_multipart: true,
7392
- slice_blob: false,
7393
- stream_upload: function() {
7394
- return I.can('select_file');
6794
+
6795
+ getStatus: function() {
6796
+ return _status;
7395
6797
  },
7396
- summon_file_dialog: Test(function() { // yeah... some dirty sniffing here...
7397
- return (Env.browser === 'Firefox' && Env.version >= 4) ||
7398
- (Env.browser === 'Opera' && Env.version >= 12) ||
7399
- !!~Basic.inArray(Env.browser, ['Chrome', 'Safari']);
7400
- }()),
7401
- upload_filesize: True,
7402
- use_http_method: function(methods) {
7403
- return !Basic.arrayDiff(methods, ['GET', 'POST']);
7404
- }
7405
- });
7406
6798
 
6799
+ getResponse: function(responseType) {
6800
+ if ('json' === responseType) {
6801
+ // strip off <pre>..</pre> tags that might be enclosing the response
6802
+ if (Basic.typeOf(_response) === 'string' && !!window.JSON) {
6803
+ try {
6804
+ return JSON.parse(_response.replace(/^\s*<pre[^>]*>/, '').replace(/<\/pre>\s*$/, ''));
6805
+ } catch (ex) {
6806
+ return null;
6807
+ }
6808
+ }
6809
+ } else if ('document' === responseType) {
7407
6810
 
7408
- Basic.extend(this, {
7409
- init : function() {
7410
- this.trigger("Init");
6811
+ }
6812
+ return _response;
7411
6813
  },
7412
6814
 
7413
- destroy: (function(destroy) { // extend default destroy method
7414
- return function() {
7415
- destroy.call(I);
7416
- destroy = I = null;
7417
- };
7418
- }(this.destroy))
7419
- });
6815
+ abort: function() {
6816
+ var target = this;
7420
6817
 
7421
- Basic.extend(this.getShim(), extensions);
7422
- }
6818
+ if (_iframe && _iframe.contentWindow) {
6819
+ if (_iframe.contentWindow.stop) { // FireFox/Safari/Chrome
6820
+ _iframe.contentWindow.stop();
6821
+ } else if (_iframe.contentWindow.document.execCommand) { // IE
6822
+ _iframe.contentWindow.document.execCommand('Stop');
6823
+ } else {
6824
+ _iframe.src = "about:blank";
6825
+ }
6826
+ }
7423
6827
 
7424
- Runtime.addConstructor(type, Html4Runtime);
6828
+ cleanup.call(this, function() {
6829
+ // target.dispatchEvent('readystatechange');
6830
+ target.dispatchEvent('abort');
6831
+ });
6832
+ }
6833
+ });
6834
+ }
7425
6835
 
7426
- return extensions;
6836
+ return (extensions.XMLHttpRequest = XMLHttpRequest);
7427
6837
  });
7428
6838
 
7429
- // Included from: src/javascript/runtime/html4/file/FileInput.js
6839
+ // Included from: src/javascript/runtime/silverlight/Runtime.js
7430
6840
 
7431
6841
  /**
7432
- * FileInput.js
6842
+ * RunTime.js
7433
6843
  *
7434
6844
  * Copyright 2013, Moxiecode Systems AB
7435
6845
  * Released under GPL License.
@@ -7438,242 +6848,294 @@ define("moxie/runtime/html4/Runtime", [
7438
6848
  * Contributing: http://www.plupload.com/contributing
7439
6849
  */
7440
6850
 
6851
+ /*global ActiveXObject:true */
6852
+
7441
6853
  /**
7442
- @class moxie/runtime/html4/file/FileInput
6854
+ Defines constructor for Silverlight runtime.
6855
+
6856
+ @class moxie/runtime/silverlight/Runtime
7443
6857
  @private
7444
6858
  */
7445
- define("moxie/runtime/html4/file/FileInput", [
7446
- "moxie/runtime/html4/Runtime",
6859
+ define("moxie/runtime/silverlight/Runtime", [
7447
6860
  "moxie/core/utils/Basic",
6861
+ "moxie/core/utils/Env",
7448
6862
  "moxie/core/utils/Dom",
7449
- "moxie/core/utils/Events",
7450
- "moxie/core/utils/Mime",
7451
- "moxie/core/utils/Env"
7452
- ], function(extensions, Basic, Dom, Events, Mime, Env) {
6863
+ "moxie/core/Exceptions",
6864
+ "moxie/runtime/Runtime"
6865
+ ], function(Basic, Env, Dom, x, Runtime) {
7453
6866
 
7454
- function FileInput() {
7455
- var _uid, _files = [], _mimes = [], _options;
7456
-
7457
- function addInput() {
7458
- var comp = this, I = comp.getRuntime(), shimContainer, browseButton, currForm, form, input, uid;
6867
+ var type = "silverlight", extensions = {};
7459
6868
 
7460
- uid = Basic.guid('uid_');
6869
+ function isInstalled(version) {
6870
+ var isVersionSupported = false, control = null, actualVer,
6871
+ actualVerArray, reqVerArray, requiredVersionPart, actualVersionPart, index = 0;
7461
6872
 
7462
- shimContainer = I.getShimContainer(); // we get new ref everytime to avoid memory leaks in IE
6873
+ try {
6874
+ try {
6875
+ control = new ActiveXObject('AgControl.AgControl');
7463
6876
 
7464
- if (_uid) { // move previous form out of the view
7465
- currForm = Dom.get(_uid + '_form');
7466
- if (currForm) {
7467
- Basic.extend(currForm.style, { top: '100%' });
6877
+ if (control.IsVersionSupported(version)) {
6878
+ isVersionSupported = true;
7468
6879
  }
7469
- }
7470
6880
 
7471
- // build form in DOM, since innerHTML version not able to submit file for some reason
7472
- form = document.createElement('form');
7473
- form.setAttribute('id', uid + '_form');
7474
- form.setAttribute('method', 'post');
7475
- form.setAttribute('enctype', 'multipart/form-data');
7476
- form.setAttribute('encoding', 'multipart/form-data');
6881
+ control = null;
6882
+ } catch (e) {
6883
+ var plugin = navigator.plugins["Silverlight Plug-In"];
7477
6884
 
7478
- Basic.extend(form.style, {
7479
- overflow: 'hidden',
7480
- position: 'absolute',
7481
- top: 0,
7482
- left: 0,
7483
- width: '100%',
7484
- height: '100%'
7485
- });
6885
+ if (plugin) {
6886
+ actualVer = plugin.description;
7486
6887
 
7487
- input = document.createElement('input');
7488
- input.setAttribute('id', uid);
7489
- input.setAttribute('type', 'file');
7490
- input.setAttribute('name', _options.name || 'Filedata');
7491
- input.setAttribute('accept', _mimes.join(','));
6888
+ if (actualVer === "1.0.30226.2") {
6889
+ actualVer = "2.0.30226.2";
6890
+ }
7492
6891
 
7493
- Basic.extend(input.style, {
7494
- fontSize: '999px',
7495
- opacity: 0
7496
- });
6892
+ actualVerArray = actualVer.split(".");
7497
6893
 
7498
- form.appendChild(input);
7499
- shimContainer.appendChild(form);
6894
+ while (actualVerArray.length > 3) {
6895
+ actualVerArray.pop();
6896
+ }
7500
6897
 
7501
- // prepare file input to be placed underneath the browse_button element
7502
- Basic.extend(input.style, {
7503
- position: 'absolute',
7504
- top: 0,
7505
- left: 0,
7506
- width: '100%',
7507
- height: '100%'
7508
- });
6898
+ while ( actualVerArray.length < 4) {
6899
+ actualVerArray.push(0);
6900
+ }
7509
6901
 
7510
- if (Env.browser === 'IE' && Env.version < 10) {
7511
- Basic.extend(input.style, {
7512
- filter : "progid:DXImageTransform.Microsoft.Alpha(opacity=0)"
7513
- });
7514
- }
6902
+ reqVerArray = version.split(".");
7515
6903
 
7516
- input.onchange = function() { // there should be only one handler for this
7517
- var file;
6904
+ while (reqVerArray.length > 4) {
6905
+ reqVerArray.pop();
6906
+ }
7518
6907
 
7519
- if (!this.value) {
7520
- return;
7521
- }
6908
+ do {
6909
+ requiredVersionPart = parseInt(reqVerArray[index], 10);
6910
+ actualVersionPart = parseInt(actualVerArray[index], 10);
6911
+ index++;
6912
+ } while (index < reqVerArray.length && requiredVersionPart === actualVersionPart);
7522
6913
 
7523
- if (this.files) {
7524
- file = this.files[0];
7525
- } else {
7526
- file = {
7527
- name: this.value
7528
- };
6914
+ if (requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart)) {
6915
+ isVersionSupported = true;
6916
+ }
7529
6917
  }
6918
+ }
6919
+ } catch (e2) {
6920
+ isVersionSupported = false;
6921
+ }
7530
6922
 
7531
- _files = [file];
7532
-
7533
- this.onchange = function() {}; // clear event handler
7534
- addInput.call(comp);
7535
-
7536
- // after file is initialized as o.File, we need to update form and input ids
7537
- comp.bind('change', function onChange() {
7538
- var input = Dom.get(uid), form = Dom.get(uid + '_form'), file;
7539
-
7540
- comp.unbind('change', onChange);
7541
-
7542
- if (comp.files.length && input && form) {
7543
- file = comp.files[0];
7544
-
7545
- input.setAttribute('id', file.uid);
7546
- form.setAttribute('id', file.uid + '_form');
6923
+ return isVersionSupported;
6924
+ }
7547
6925
 
7548
- // set upload target
7549
- form.setAttribute('target', file.uid + '_iframe');
7550
- }
7551
- input = form = null;
7552
- }, 998);
6926
+ /**
6927
+ Constructor for the Silverlight Runtime
7553
6928
 
7554
- input = form = null;
7555
- comp.trigger('change');
7556
- };
6929
+ @class SilverlightRuntime
6930
+ @extends Runtime
6931
+ */
6932
+ function SilverlightRuntime(options) {
6933
+ var I = this, initTimer;
7557
6934
 
6935
+ options = Basic.extend({ xap_url: Env.xap_url }, options);
7558
6936
 
7559
- // route click event to the input
7560
- if (I.can('summon_file_dialog')) {
7561
- browseButton = Dom.get(_options.browse_button);
7562
- Events.removeEvent(browseButton, 'click', comp.uid);
7563
- Events.addEvent(browseButton, 'click', function(e) {
7564
- if (input && !input.disabled) { // for some reason FF (up to 8.0.1 so far) lets to click disabled input[type=file]
7565
- input.click();
7566
- }
7567
- e.preventDefault();
7568
- }, comp.uid);
6937
+ Runtime.call(this, options, type, {
6938
+ access_binary: Runtime.capTrue,
6939
+ access_image_binary: Runtime.capTrue,
6940
+ display_media: Runtime.capTrue,
6941
+ do_cors: Runtime.capTrue,
6942
+ drag_and_drop: false,
6943
+ report_upload_progress: Runtime.capTrue,
6944
+ resize_image: Runtime.capTrue,
6945
+ return_response_headers: function(value) {
6946
+ return value && I.mode === 'client';
6947
+ },
6948
+ return_response_type: function(responseType) {
6949
+ if (responseType !== 'json') {
6950
+ return true;
6951
+ } else {
6952
+ return !!window.JSON;
6953
+ }
6954
+ },
6955
+ return_status_code: function(code) {
6956
+ return I.mode === 'client' || !Basic.arrayDiff(code, [200, 404]);
6957
+ },
6958
+ select_file: Runtime.capTrue,
6959
+ select_multiple: Runtime.capTrue,
6960
+ send_binary_string: Runtime.capTrue,
6961
+ send_browser_cookies: function(value) {
6962
+ return value && I.mode === 'browser';
6963
+ },
6964
+ send_custom_headers: function(value) {
6965
+ return value && I.mode === 'client';
6966
+ },
6967
+ send_multipart: Runtime.capTrue,
6968
+ slice_blob: Runtime.capTrue,
6969
+ stream_upload: true,
6970
+ summon_file_dialog: false,
6971
+ upload_filesize: Runtime.capTrue,
6972
+ use_http_method: function(methods) {
6973
+ return I.mode === 'client' || !Basic.arrayDiff(methods, ['GET', 'POST']);
6974
+ }
6975
+ }, {
6976
+ // capabilities that require specific mode
6977
+ return_response_headers: function(value) {
6978
+ return value ? 'client' : 'browser';
6979
+ },
6980
+ return_status_code: function(code) {
6981
+ return Basic.arrayDiff(code, [200, 404]) ? 'client' : ['client', 'browser'];
6982
+ },
6983
+ send_browser_cookies: function(value) {
6984
+ return value ? 'browser' : 'client';
6985
+ },
6986
+ send_custom_headers: function(value) {
6987
+ return value ? 'client' : 'browser';
6988
+ },
6989
+ use_http_method: function(methods) {
6990
+ return Basic.arrayDiff(methods, ['GET', 'POST']) ? 'client' : ['client', 'browser'];
7569
6991
  }
6992
+ });
7570
6993
 
7571
- _uid = uid;
7572
6994
 
7573
- shimContainer = currForm = browseButton = null;
6995
+ // minimal requirement
6996
+ if (!isInstalled('2.0.31005.0') || Env.browser === 'Opera') {
6997
+ this.mode = false;
7574
6998
  }
7575
6999
 
7576
- Basic.extend(this, {
7577
- init: function(options) {
7578
- var comp = this, I = comp.getRuntime(), shimContainer;
7579
-
7580
- // figure out accept string
7581
- _options = options;
7582
- _mimes = options.accept.mimes || Mime.extList2mimes(options.accept, I.can('filter_by_extension'));
7583
7000
 
7584
- shimContainer = I.getShimContainer();
7001
+ Basic.extend(this, {
7002
+ getShim: function() {
7003
+ return Dom.get(this.uid).content.Moxie;
7004
+ },
7585
7005
 
7586
- (function() {
7587
- var browseButton, zIndex, top;
7006
+ shimExec: function(component, action) {
7007
+ var args = [].slice.call(arguments, 2);
7008
+ return I.getShim().exec(this.uid, component, action, args);
7009
+ },
7588
7010
 
7589
- browseButton = Dom.get(options.browse_button);
7011
+ init : function() {
7012
+ var container;
7590
7013
 
7591
- // Route click event to the input[type=file] element for browsers that support such behavior
7592
- if (I.can('summon_file_dialog')) {
7593
- if (Dom.getStyle(browseButton, 'position') === 'static') {
7594
- browseButton.style.position = 'relative';
7595
- }
7014
+ container = this.getShimContainer();
7596
7015
 
7597
- zIndex = parseInt(Dom.getStyle(browseButton, 'z-index'), 10) || 1;
7016
+ container.innerHTML = '<object id="' + this.uid + '" data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%" style="outline:none;">' +
7017
+ '<param name="source" value="' + options.xap_url + '"/>' +
7018
+ '<param name="background" value="Transparent"/>' +
7019
+ '<param name="windowless" value="true"/>' +
7020
+ '<param name="enablehtmlaccess" value="true"/>' +
7021
+ '<param name="initParams" value="uid=' + this.uid + ',target=' + Env.global_event_dispatcher + '"/>' +
7022
+ '</object>';
7598
7023
 
7599
- browseButton.style.zIndex = zIndex;
7600
- shimContainer.style.zIndex = zIndex - 1;
7024
+ // Init is dispatched by the shim
7025
+ initTimer = setTimeout(function() {
7026
+ if (I && !I.initialized) { // runtime might be already destroyed by this moment
7027
+ I.trigger("Error", new x.RuntimeError(x.RuntimeError.NOT_INIT_ERR));
7601
7028
  }
7029
+ }, Env.OS !== 'Windows'? 10000 : 5000); // give it more time to initialize in non Windows OS (like Mac)
7030
+ },
7602
7031
 
7603
- /* Since we have to place input[type=file] on top of the browse_button for some browsers,
7604
- browse_button loses interactivity, so we restore it here */
7605
- top = I.can('summon_file_dialog') ? browseButton : shimContainer;
7606
-
7607
- Events.addEvent(top, 'mouseover', function() {
7608
- comp.trigger('mouseenter');
7609
- }, comp.uid);
7032
+ destroy: (function(destroy) { // extend default destroy method
7033
+ return function() {
7034
+ destroy.call(I);
7035
+ clearTimeout(initTimer); // initialization check might be still onwait
7036
+ options = initTimer = destroy = I = null;
7037
+ };
7038
+ }(this.destroy))
7610
7039
 
7611
- Events.addEvent(top, 'mouseout', function() {
7612
- comp.trigger('mouseleave');
7613
- }, comp.uid);
7040
+ }, extensions);
7041
+ }
7614
7042
 
7615
- Events.addEvent(top, 'mousedown', function() {
7616
- comp.trigger('mousedown');
7617
- }, comp.uid);
7043
+ Runtime.addConstructor(type, SilverlightRuntime);
7618
7044
 
7619
- Events.addEvent(Dom.get(options.container), 'mouseup', function() {
7620
- comp.trigger('mouseup');
7621
- }, comp.uid);
7045
+ return extensions;
7046
+ });
7622
7047
 
7623
- browseButton = null;
7624
- }());
7048
+ // Included from: src/javascript/runtime/silverlight/file/Blob.js
7625
7049
 
7626
- addInput.call(this);
7050
+ /**
7051
+ * Blob.js
7052
+ *
7053
+ * Copyright 2013, Moxiecode Systems AB
7054
+ * Released under GPL License.
7055
+ *
7056
+ * License: http://www.plupload.com/license
7057
+ * Contributing: http://www.plupload.com/contributing
7058
+ */
7627
7059
 
7628
- shimContainer = null;
7060
+ /**
7061
+ @class moxie/runtime/silverlight/file/Blob
7062
+ @private
7063
+ */
7064
+ define("moxie/runtime/silverlight/file/Blob", [
7065
+ "moxie/runtime/silverlight/Runtime",
7066
+ "moxie/core/utils/Basic",
7067
+ "moxie/runtime/flash/file/Blob"
7068
+ ], function(extensions, Basic, Blob) {
7069
+ return (extensions.Blob = Basic.extend({}, Blob));
7070
+ });
7629
7071
 
7630
- // trigger ready event asynchronously
7631
- comp.trigger({
7632
- type: 'ready',
7633
- async: true
7634
- });
7635
- },
7072
+ // Included from: src/javascript/runtime/silverlight/file/FileInput.js
7636
7073
 
7637
- getFiles: function() {
7638
- return _files;
7639
- },
7074
+ /**
7075
+ * FileInput.js
7076
+ *
7077
+ * Copyright 2013, Moxiecode Systems AB
7078
+ * Released under GPL License.
7079
+ *
7080
+ * License: http://www.plupload.com/license
7081
+ * Contributing: http://www.plupload.com/contributing
7082
+ */
7640
7083
 
7641
- disable: function(state) {
7642
- var input;
7084
+ /**
7085
+ @class moxie/runtime/silverlight/file/FileInput
7086
+ @private
7087
+ */
7088
+ define("moxie/runtime/silverlight/file/FileInput", [
7089
+ "moxie/runtime/silverlight/Runtime"
7090
+ ], function(extensions) {
7091
+
7092
+ var FileInput = {
7093
+ init: function(options) {
7643
7094
 
7644
- if ((input = Dom.get(_uid))) {
7645
- input.disabled = !!state;
7095
+ function toFilters(accept) {
7096
+ var filter = '';
7097
+ for (var i = 0; i < accept.length; i++) {
7098
+ filter += (filter !== '' ? '|' : '') + accept[i].title + " | *." + accept[i].extensions.replace(/,/g, ';*.');
7646
7099
  }
7647
- },
7100
+ return filter;
7101
+ }
7102
+
7103
+ this.getRuntime().shimExec.call(this, 'FileInput', 'init', toFilters(options.accept), options.name, options.multiple);
7104
+ this.trigger('ready');
7105
+ }
7106
+ };
7648
7107
 
7649
- destroy: function() {
7650
- var I = this.getRuntime()
7651
- , shim = I.getShim()
7652
- , shimContainer = I.getShimContainer()
7653
- ;
7654
-
7655
- Events.removeAllEvents(shimContainer, this.uid);
7656
- Events.removeAllEvents(_options && Dom.get(_options.container), this.uid);
7657
- Events.removeAllEvents(_options && Dom.get(_options.browse_button), this.uid);
7658
-
7659
- if (shimContainer) {
7660
- shimContainer.innerHTML = '';
7661
- }
7108
+ return (extensions.FileInput = FileInput);
7109
+ });
7662
7110
 
7663
- shim.removeInstance(this.uid);
7111
+ // Included from: src/javascript/runtime/silverlight/file/FileReader.js
7664
7112
 
7665
- _uid = _files = _mimes = _options = shimContainer = shim = null;
7666
- }
7667
- });
7668
- }
7113
+ /**
7114
+ * FileReader.js
7115
+ *
7116
+ * Copyright 2013, Moxiecode Systems AB
7117
+ * Released under GPL License.
7118
+ *
7119
+ * License: http://www.plupload.com/license
7120
+ * Contributing: http://www.plupload.com/contributing
7121
+ */
7669
7122
 
7670
- return (extensions.FileInput = FileInput);
7123
+ /**
7124
+ @class moxie/runtime/silverlight/file/FileReader
7125
+ @private
7126
+ */
7127
+ define("moxie/runtime/silverlight/file/FileReader", [
7128
+ "moxie/runtime/silverlight/Runtime",
7129
+ "moxie/core/utils/Basic",
7130
+ "moxie/runtime/flash/file/FileReader"
7131
+ ], function(extensions, Basic, FileReader) {
7132
+ return (extensions.FileReader = Basic.extend({}, FileReader));
7671
7133
  });
7672
7134
 
7673
- // Included from: src/javascript/runtime/html4/file/FileReader.js
7135
+ // Included from: src/javascript/runtime/silverlight/file/FileReaderSync.js
7674
7136
 
7675
7137
  /**
7676
- * FileReader.js
7138
+ * FileReaderSync.js
7677
7139
  *
7678
7140
  * Copyright 2013, Moxiecode Systems AB
7679
7141
  * Released under GPL License.
@@ -7683,17 +7145,18 @@ define("moxie/runtime/html4/file/FileInput", [
7683
7145
  */
7684
7146
 
7685
7147
  /**
7686
- @class moxie/runtime/html4/file/FileReader
7148
+ @class moxie/runtime/silverlight/file/FileReaderSync
7687
7149
  @private
7688
7150
  */
7689
- define("moxie/runtime/html4/file/FileReader", [
7690
- "moxie/runtime/html4/Runtime",
7691
- "moxie/runtime/html5/file/FileReader"
7692
- ], function(extensions, FileReader) {
7693
- return (extensions.FileReader = FileReader);
7151
+ define("moxie/runtime/silverlight/file/FileReaderSync", [
7152
+ "moxie/runtime/silverlight/Runtime",
7153
+ "moxie/core/utils/Basic",
7154
+ "moxie/runtime/flash/file/FileReaderSync"
7155
+ ], function(extensions, Basic, FileReaderSync) {
7156
+ return (extensions.FileReaderSync = Basic.extend({}, FileReaderSync));
7694
7157
  });
7695
7158
 
7696
- // Included from: src/javascript/runtime/html4/xhr/XMLHttpRequest.js
7159
+ // Included from: src/javascript/runtime/silverlight/xhr/XMLHttpRequest.js
7697
7160
 
7698
7161
  /**
7699
7162
  * XMLHttpRequest.js
@@ -7706,241 +7169,17 @@ define("moxie/runtime/html4/file/FileReader", [
7706
7169
  */
7707
7170
 
7708
7171
  /**
7709
- @class moxie/runtime/html4/xhr/XMLHttpRequest
7172
+ @class moxie/runtime/silverlight/xhr/XMLHttpRequest
7710
7173
  @private
7711
7174
  */
7712
- define("moxie/runtime/html4/xhr/XMLHttpRequest", [
7713
- "moxie/runtime/html4/Runtime",
7175
+ define("moxie/runtime/silverlight/xhr/XMLHttpRequest", [
7176
+ "moxie/runtime/silverlight/Runtime",
7714
7177
  "moxie/core/utils/Basic",
7715
- "moxie/core/utils/Dom",
7716
- "moxie/core/utils/Url",
7717
- "moxie/core/Exceptions",
7718
- "moxie/core/utils/Events",
7719
- "moxie/file/Blob",
7720
- "moxie/xhr/FormData"
7721
- ], function(extensions, Basic, Dom, Url, x, Events, Blob, FormData) {
7722
-
7723
- function XMLHttpRequest() {
7724
- var _status, _response, _iframe;
7725
-
7726
- function cleanup(cb) {
7727
- var target = this, uid, form, inputs, i, hasFile = false;
7728
-
7729
- if (!_iframe) {
7730
- return;
7731
- }
7732
-
7733
- uid = _iframe.id.replace(/_iframe$/, '');
7734
-
7735
- form = Dom.get(uid + '_form');
7736
- if (form) {
7737
- inputs = form.getElementsByTagName('input');
7738
- i = inputs.length;
7739
-
7740
- while (i--) {
7741
- switch (inputs[i].getAttribute('type')) {
7742
- case 'hidden':
7743
- inputs[i].parentNode.removeChild(inputs[i]);
7744
- break;
7745
- case 'file':
7746
- hasFile = true; // flag the case for later
7747
- break;
7748
- }
7749
- }
7750
- inputs = [];
7751
-
7752
- if (!hasFile) { // we need to keep the form for sake of possible retries
7753
- form.parentNode.removeChild(form);
7754
- }
7755
- form = null;
7756
- }
7757
-
7758
- // without timeout, request is marked as canceled (in console)
7759
- setTimeout(function() {
7760
- Events.removeEvent(_iframe, 'load', target.uid);
7761
- if (_iframe.parentNode) { // #382
7762
- _iframe.parentNode.removeChild(_iframe);
7763
- }
7764
-
7765
- // check if shim container has any other children, if - not, remove it as well
7766
- var shimContainer = target.getRuntime().getShimContainer();
7767
- if (!shimContainer.children.length) {
7768
- shimContainer.parentNode.removeChild(shimContainer);
7769
- }
7770
-
7771
- shimContainer = _iframe = null;
7772
- cb();
7773
- }, 1);
7774
- }
7775
-
7776
- Basic.extend(this, {
7777
- send: function(meta, data) {
7778
- var target = this, I = target.getRuntime(), uid, form, input, blob;
7779
-
7780
- _status = _response = null;
7781
-
7782
- function createIframe() {
7783
- var container = I.getShimContainer() || document.body
7784
- , temp = document.createElement('div')
7785
- ;
7786
-
7787
- // IE 6 won't be able to set the name using setAttribute or iframe.name
7788
- temp.innerHTML = '<iframe id="' + uid + '_iframe" name="' + uid + '_iframe" src="javascript:&quot;&quot;" style="display:none"></iframe>';
7789
- _iframe = temp.firstChild;
7790
- container.appendChild(_iframe);
7791
-
7792
- /* _iframe.onreadystatechange = function() {
7793
- console.info(_iframe.readyState);
7794
- };*/
7795
-
7796
- Events.addEvent(_iframe, 'load', function() { // _iframe.onload doesn't work in IE lte 8
7797
- var el;
7798
-
7799
- try {
7800
- el = _iframe.contentWindow.document || _iframe.contentDocument || window.frames[_iframe.id].document;
7801
-
7802
- // try to detect some standard error pages
7803
- if (/^4(0[0-9]|1[0-7]|2[2346])\s/.test(el.title)) { // test if title starts with 4xx HTTP error
7804
- _status = el.title.replace(/^(\d+).*$/, '$1');
7805
- } else {
7806
- _status = 200;
7807
- // get result
7808
- _response = Basic.trim(el.body.innerHTML);
7809
-
7810
- // we need to fire these at least once
7811
- target.trigger({
7812
- type: 'progress',
7813
- loaded: _response.length,
7814
- total: _response.length
7815
- });
7816
-
7817
- if (blob) { // if we were uploading a file
7818
- target.trigger({
7819
- type: 'uploadprogress',
7820
- loaded: blob.size || 1025,
7821
- total: blob.size || 1025
7822
- });
7823
- }
7824
- }
7825
- } catch (ex) {
7826
- if (Url.hasSameOrigin(meta.url)) {
7827
- // if response is sent with error code, iframe in IE gets redirected to res://ieframe.dll/http_x.htm
7828
- // which obviously results to cross domain error (wtf?)
7829
- _status = 404;
7830
- } else {
7831
- cleanup.call(target, function() {
7832
- target.trigger('error');
7833
- });
7834
- return;
7835
- }
7836
- }
7837
-
7838
- cleanup.call(target, function() {
7839
- target.trigger('load');
7840
- });
7841
- }, target.uid);
7842
- } // end createIframe
7843
-
7844
- // prepare data to be sent and convert if required
7845
- if (data instanceof FormData && data.hasBlob()) {
7846
- blob = data.getBlob();
7847
- uid = blob.uid;
7848
- input = Dom.get(uid);
7849
- form = Dom.get(uid + '_form');
7850
- if (!form) {
7851
- throw new x.DOMException(x.DOMException.NOT_FOUND_ERR);
7852
- }
7853
- } else {
7854
- uid = Basic.guid('uid_');
7855
-
7856
- form = document.createElement('form');
7857
- form.setAttribute('id', uid + '_form');
7858
- form.setAttribute('method', meta.method);
7859
- form.setAttribute('enctype', 'multipart/form-data');
7860
- form.setAttribute('encoding', 'multipart/form-data');
7861
- form.setAttribute('target', uid + '_iframe');
7862
-
7863
- I.getShimContainer().appendChild(form);
7864
- }
7865
-
7866
- if (data instanceof FormData) {
7867
- data.each(function(value, name) {
7868
- if (value instanceof Blob) {
7869
- if (input) {
7870
- input.setAttribute('name', name);
7871
- }
7872
- } else {
7873
- var hidden = document.createElement('input');
7874
-
7875
- Basic.extend(hidden, {
7876
- type : 'hidden',
7877
- name : name,
7878
- value : value
7879
- });
7880
-
7881
- // make sure that input[type="file"], if it's there, comes last
7882
- if (input) {
7883
- form.insertBefore(hidden, input);
7884
- } else {
7885
- form.appendChild(hidden);
7886
- }
7887
- }
7888
- });
7889
- }
7890
-
7891
- // set destination url
7892
- form.setAttribute("action", meta.url);
7893
-
7894
- createIframe();
7895
- form.submit();
7896
- target.trigger('loadstart');
7897
- },
7898
-
7899
- getStatus: function() {
7900
- return _status;
7901
- },
7902
-
7903
- getResponse: function(responseType) {
7904
- if ('json' === responseType) {
7905
- // strip off <pre>..</pre> tags that might be enclosing the response
7906
- if (Basic.typeOf(_response) === 'string' && !!window.JSON) {
7907
- try {
7908
- return JSON.parse(_response.replace(/^\s*<pre[^>]*>/, '').replace(/<\/pre>\s*$/, ''));
7909
- } catch (ex) {
7910
- return null;
7911
- }
7912
- }
7913
- } else if ('document' === responseType) {
7914
-
7915
- }
7916
- return _response;
7917
- },
7918
-
7919
- abort: function() {
7920
- var target = this;
7921
-
7922
- if (_iframe && _iframe.contentWindow) {
7923
- if (_iframe.contentWindow.stop) { // FireFox/Safari/Chrome
7924
- _iframe.contentWindow.stop();
7925
- } else if (_iframe.contentWindow.document.execCommand) { // IE
7926
- _iframe.contentWindow.document.execCommand('Stop');
7927
- } else {
7928
- _iframe.src = "about:blank";
7929
- }
7930
- }
7931
-
7932
- cleanup.call(this, function() {
7933
- // target.dispatchEvent('readystatechange');
7934
- target.dispatchEvent('abort');
7935
- });
7936
- }
7937
- });
7938
- }
7939
-
7940
- return (extensions.XMLHttpRequest = XMLHttpRequest);
7178
+ "moxie/runtime/flash/xhr/XMLHttpRequest"
7179
+ ], function(extensions, Basic, XMLHttpRequest) {
7180
+ return (extensions.XMLHttpRequest = Basic.extend({}, XMLHttpRequest));
7941
7181
  });
7942
7182
 
7943
-
7944
7183
  expose(["moxie/core/utils/Basic","moxie/core/I18n","moxie/core/utils/Mime","moxie/core/utils/Env","moxie/core/utils/Dom","moxie/core/Exceptions","moxie/core/EventTarget","moxie/core/utils/Encode","moxie/runtime/Runtime","moxie/runtime/RuntimeClient","moxie/file/Blob","moxie/file/File","moxie/file/FileInput","moxie/runtime/RuntimeTarget","moxie/file/FileReader","moxie/core/utils/Url","moxie/file/FileReaderSync","moxie/xhr/FormData","moxie/xhr/XMLHttpRequest","moxie/runtime/Transporter","moxie/core/utils/Events"]);
7945
7184
  })(this);/**
7946
7185
  * o.js
@@ -7987,8 +7226,8 @@ Globally exposed namespace with the most frequently used public classes and hand
7987
7226
 
7988
7227
  // expose globally
7989
7228
  exports.mOxie = o;
7990
- if (window != exports && !exports.o) {
7991
- //exports.o = o;
7229
+ if (!exports.o) {
7230
+ exports.o = o;
7992
7231
  }
7993
7232
  return o;
7994
7233
  })(this);