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
@@ -1330,12 +1330,6 @@ webshims.register('dom-extend', function($, webshims, window, document, undefine
1330
1330
  }
1331
1331
 
1332
1332
  return inputValueDesc.prop._supget.call(this);
1333
- },
1334
- set: function(val){
1335
- if(val === '' && this.type == 'file' && $(this).hasClass('ws-filereader')){
1336
- webshim.data(this, 'fileList', []);
1337
- }
1338
- inputValueDesc.prop._supset.call(this);
1339
1333
  }
1340
1334
  }
1341
1335
  }
@@ -1533,10 +1527,10 @@ webshims.register('dom-extend', function($, webshims, window, document, undefine
1533
1527
  }
1534
1528
 
1535
1529
  if(!featureOptions.swfpath){
1536
- featureOptions.swfpath = shimMoxiePath+'flash/Moxie.cdn.swf';
1530
+ featureOptions.swfpath = shimMoxiePath+'flash/Moxie.min.swf';
1537
1531
  }
1538
1532
  if(!featureOptions.xappath){
1539
- featureOptions.xappath = shimMoxiePath+'silverlight/Moxie.cdn.xap';
1533
+ featureOptions.xappath = shimMoxiePath+'silverlight/Moxie.min.xap';
1540
1534
  }
1541
1535
 
1542
1536
  if($.support.cors !== false || !window.XDomainRequest){
@@ -1586,6 +1580,13 @@ webshims.register('dom-extend', function($, webshims, window, document, undefine
1586
1580
  }
1587
1581
  });
1588
1582
 
1583
+ webshim.onNodeNamesPropertyModify('input', 'value', function(value, boolVal, type){
1584
+ if(value === '' && this.type == 'file' && $(this).hasClass('ws-filereader')){
1585
+ webshim.data(this, 'fileList', []);
1586
+ }
1587
+ });
1588
+
1589
+
1589
1590
  window.FileReader = notReadyYet;
1590
1591
  window.FormData = notReadyYet;
1591
1592
  webshim.ready('moxie', function(){
@@ -1620,7 +1621,7 @@ webshims.register('dom-extend', function($, webshims, window, document, undefine
1620
1621
  if(inputName && !$(appendData[i]).is(':disabled')){
1621
1622
  files = $.prop(appendData[i], 'files') || [];
1622
1623
  if(files.length){
1623
- if(files.length > 1){
1624
+ if(files.length > 1 || (moxieData.hasBlob && moxieData.hasBlob())){
1624
1625
  webshim.error('FormData shim can only handle one file per ajax. Use multiple ajax request. One per file.');
1625
1626
  }
1626
1627
  for(fileI = 0, fileLen = files.length; fileI < fileLen; fileI++){
@@ -1845,8 +1846,8 @@ webshims.register('dom-extend', function($, webshims, window, document, undefine
1845
1846
  data.seeking = false;
1846
1847
  }, 300);
1847
1848
  },
1848
- onConnectionFailed: function(){
1849
- webshims.error('media error');
1849
+ onConnectionFailed: function(jaris, data){
1850
+ mediaelement.setError(data._elem, 'flash connection error');
1850
1851
  },
1851
1852
  onNotBuffering: function(jaris, data){
1852
1853
  setReadyState(3, data);
@@ -2762,6 +2763,13 @@ webshims.register('dom-extend', function($, webshims, window, document, undefine
2762
2763
 
2763
2764
  if(hasFlash && $.cleanData){
2764
2765
  var oldClean = $.cleanData;
2766
+ var objElem = document.createElement('object');
2767
+ var noRemove = {
2768
+ SetVariable: 1,
2769
+ GetVariable: 1,
2770
+ SetReturnValue: 1,
2771
+ GetReturnValue: 1
2772
+ };
2765
2773
  var flashNames = {
2766
2774
  object: 1,
2767
2775
  OBJECT: 1
@@ -2769,6 +2777,7 @@ webshims.register('dom-extend', function($, webshims, window, document, undefine
2769
2777
 
2770
2778
  $.cleanData = function(elems){
2771
2779
  var i, len, prop;
2780
+ var ret = oldClean.apply(this, arguments);
2772
2781
  if(elems && (len = elems.length) && loadedSwf){
2773
2782
 
2774
2783
  for(i = 0; i < len; i++){
@@ -2778,7 +2787,7 @@ webshims.register('dom-extend', function($, webshims, window, document, undefine
2778
2787
  elems[i].api_pause();
2779
2788
  if(elems[i].readyState == 4){
2780
2789
  for (prop in elems[i]) {
2781
- if (typeof elems[i][prop] == "function") {
2790
+ if (!noRemove[prop] && !objElem[prop] && typeof elems[i][prop] == "function") {
2782
2791
  elems[i][prop] = null;
2783
2792
  }
2784
2793
  }
@@ -2788,7 +2797,7 @@ webshims.register('dom-extend', function($, webshims, window, document, undefine
2788
2797
  }
2789
2798
 
2790
2799
  }
2791
- return oldClean.apply(this, arguments);
2800
+ return ret;
2792
2801
  };
2793
2802
  }
2794
2803
 
@@ -2860,62 +2869,6 @@ webshims.register('dom-extend', function($, webshims, window, document, undefine
2860
2869
  } else if(!('media' in document.createElement('source'))){
2861
2870
  webshims.reflectProperties('source', ['media']);
2862
2871
  }
2863
- if(options.experimentallyMimetypeCheck){
2864
- (function(){
2865
- var ADDBACK = $.fn.addBack ? 'addBack' : 'andSelf';
2866
- var getMimeType = function(){
2867
- var done;
2868
- var unknown = 'media/unknown please provide mime type';
2869
- var media = $(this);
2870
- var xhrs = [];
2871
- media
2872
- .not('.ws-after-check')
2873
- .find('source')
2874
- [ADDBACK]()
2875
- .filter('[data-wsrecheckmimetype]:not([type])')
2876
- .each(function(){
2877
- var source = $(this).removeAttr('data-wsrecheckmimetype');
2878
- var error = function(){
2879
- source.attr('data-type', unknown);
2880
- };
2881
- try {
2882
- xhrs.push(
2883
- $.ajax({
2884
- type: 'head',
2885
- url: $.attr(this, 'src'),
2886
- success: function(content, status, xhr){
2887
- var mime = xhr.getResponseHeader('Content-Type');
2888
- if(mime){
2889
- done = true;
2890
- }
2891
- source.attr('data-type', mime || unknown);
2892
- },
2893
- error: error
2894
- })
2895
- )
2896
- ;
2897
- } catch(er){
2898
- error();
2899
- }
2900
- })
2901
- ;
2902
- if(xhrs.length){
2903
- media.addClass('ws-after-check');
2904
- $.when.apply($, xhrs).always(function(){
2905
- media.mediaLoad();
2906
- setTimeout(function(){
2907
- media.removeClass('ws-after-check');
2908
- }, 9);
2909
- });
2910
- }
2911
- };
2912
- $('audio.media-error, video.media-error').each(getMimeType);
2913
- $(document).on('mediaerror', function(e){
2914
- getMimeType.call(e.target);
2915
- });
2916
- })();
2917
- }
2918
-
2919
2872
 
2920
2873
  if(hasNative && hasFlash && !options.preferFlash){
2921
2874
  var switchErrors = {
@@ -2924,35 +2877,38 @@ webshims.register('dom-extend', function($, webshims, window, document, undefine
2924
2877
  };
2925
2878
  var switchOptions = function(e){
2926
2879
  var media, error, parent;
2927
- if(!options.preferFlash &&
2880
+ if(
2928
2881
  ($(e.target).is('audio, video') || ((parent = e.target.parentNode) && $('source', parent).last()[0] == e.target)) &&
2929
- (media = $(e.target).closest('audio, video')) && (error = media.prop('error')) && switchErrors[error.code]
2882
+ (media = $(e.target).closest('audio, video')) && !media.is('.nonnative-api-active')
2930
2883
  ){
2931
-
2932
- if(!options.preferFlash){
2884
+ error = media.prop('error');
2885
+ setTimeout(function(){
2933
2886
  if(!media.is('.nonnative-api-active')){
2934
- options.preferFlash = true;
2935
- document.removeEventListener('error', switchOptions, true);
2936
- $('audio, video').each(function(){
2937
- webshims.mediaelement.selectSource(this);
2938
- });
2939
- webshims.error("switching mediaelements option to 'preferFlash', due to an error with native player: "+e.target.src+" Mediaerror: "+ media.prop('error')+ 'first error: '+ error);
2887
+ if(error && switchErrors[error.code]){
2888
+ options.preferFlash = true;
2889
+ document.removeEventListener('error', switchOptions, true);
2890
+ $('audio, video').each(function(){
2891
+ webshims.mediaelement.selectSource(this);
2892
+ });
2893
+ 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);
2894
+ }
2895
+ webshims.warn('There was a mediaelement error. Run the following line in your console to get more info: webshim.mediaelement.loadDebugger();')
2940
2896
  }
2941
- } else{
2942
- document.removeEventListener('error', switchOptions, true);
2943
- }
2897
+ });
2898
+
2899
+
2944
2900
  }
2945
2901
  };
2902
+
2903
+ document.addEventListener('error', switchOptions, true);
2946
2904
  setTimeout(function(){
2947
- document.addEventListener('error', switchOptions, true);
2948
2905
  $('audio, video').each(function(){
2949
2906
  var error = $.prop(this, 'error');
2950
2907
  if(error && switchErrors[error]){
2951
2908
  switchOptions({target: this});
2952
- return false;
2953
2909
  }
2954
2910
  });
2955
- }, 9);
2911
+ });
2956
2912
  }
2957
2913
 
2958
2914
  });
@@ -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,117 @@ 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;
5487
- }
5489
+ target.bind('Progress', function(e, data) {
5490
+ if (data) {
5491
+ _result += _formatData(data, op);
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] = [];
5502
+ destroy: function() {
5503
+ _result = null;
5511
5504
  }
5512
-
5513
- events[name].push({
5514
- func: func,
5515
- orig: callback, // store original callback for IE
5516
- key: key
5517
- });
5518
5505
  };
5506
+
5507
+ return (extensions.FileReader = FileReader);
5508
+ });
5509
+
5510
+ // Included from: src/javascript/runtime/flash/file/FileReaderSync.js
5511
+
5512
+ /**
5513
+ * FileReaderSync.js
5514
+ *
5515
+ * Copyright 2013, Moxiecode Systems AB
5516
+ * Released under GPL License.
5517
+ *
5518
+ * License: http://www.plupload.com/license
5519
+ * Contributing: http://www.plupload.com/contributing
5520
+ */
5521
+
5522
+ /**
5523
+ @class moxie/runtime/flash/file/FileReaderSync
5524
+ @private
5525
+ */
5526
+ define("moxie/runtime/flash/file/FileReaderSync", [
5527
+ "moxie/runtime/flash/Runtime",
5528
+ "moxie/core/utils/Encode"
5529
+ ], function(extensions, Encode) {
5519
5530
 
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;
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;
5540
5539
  }
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
- }
5540
+ return null;
5541
+ }
5542
+
5543
+ var FileReaderSync = {
5544
+ read: function(op, blob) {
5545
+ var result, self = this.getRuntime();
5546
+
5547
+ result = self.shimExec.call(this, 'FileReaderSync', 'readAsBase64', blob.uid);
5548
+ if (!result) {
5549
+ return null; // or throw ex
5559
5550
  }
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;
5551
+
5552
+ // special prefix for DataURL read mode
5553
+ if (op === 'readAsDataURL') {
5554
+ result = 'data:' + (blob.type || '') + ';base64,' + result;
5576
5555
  }
5556
+
5557
+ return _formatData(result, op, blob.type);
5577
5558
  }
5578
5559
  };
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;
5592
- }
5593
-
5594
- Basic.each(eventhash[obj[uid]], function(events, name) {
5595
- removeEvent(obj, name, key);
5596
- });
5597
- };
5598
5560
 
5599
- return {
5600
- addEvent: addEvent,
5601
- removeEvent: removeEvent,
5602
- removeAllEvents: removeAllEvents
5603
- };
5561
+ return (extensions.FileReaderSync = FileReaderSync);
5604
5562
  });
5605
5563
 
5606
- // Included from: src/javascript/runtime/html5/file/FileInput.js
5564
+ // Included from: src/javascript/runtime/Transporter.js
5607
5565
 
5608
5566
  /**
5609
- * FileInput.js
5567
+ * Transporter.js
5610
5568
  *
5611
5569
  * Copyright 2013, Moxiecode Systems AB
5612
5570
  * Released under GPL License.
@@ -5615,170 +5573,135 @@ define('moxie/core/utils/Events', [
5615
5573
  * Contributing: http://www.plupload.com/contributing
5616
5574
  */
5617
5575
 
5618
- /**
5619
- @class moxie/runtime/html5/file/FileInput
5620
- @private
5621
- */
5622
- define("moxie/runtime/html5/file/FileInput", [
5623
- "moxie/runtime/html5/Runtime",
5576
+ define("moxie/runtime/Transporter", [
5624
5577
  "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) {
5630
-
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;
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;
5637
5584
 
5638
- _options = options;
5639
- _files = [];
5585
+ RuntimeClient.call(this);
5640
5586
 
5641
- // figure out accept string
5642
- mimes = _options.accept.mimes || Mime.extList2mimes(_options.accept, I.can('filter_by_extension'));
5587
+ Basic.extend(this, {
5588
+ uid: Basic.guid('uid_'),
5643
5589
 
5644
- shimContainer = I.getShimContainer();
5590
+ state: Transporter.IDLE,
5645
5591
 
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(',') + '"' : '') + ' />';
5592
+ result: null,
5650
5593
 
5651
- input = Dom.get(I.uid);
5594
+ transport: function(data, type, options) {
5595
+ var self = this;
5652
5596
 
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
- });
5597
+ options = Basic.extend({
5598
+ chunk_size: 204798
5599
+ }, options);
5661
5600
 
5601
+ // should divide by three, base64 requires this
5602
+ if ((mod = options.chunk_size % 3)) {
5603
+ options.chunk_size += 3 - mod;
5604
+ }
5662
5605
 
5663
- browseButton = Dom.get(_options.browse_button);
5606
+ _chunk_size = options.chunk_size;
5664
5607
 
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
- }
5608
+ _reset.call(this);
5609
+ _data = data;
5610
+ _size = data.length;
5670
5611
 
5671
- zIndex = parseInt(Dom.getStyle(browseButton, 'z-index'), 10) || 1;
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
+ },
5672
5624
 
5673
- browseButton.style.zIndex = zIndex;
5674
- shimContainer.style.zIndex = zIndex - 1;
5625
+ abort: function() {
5626
+ var self = this;
5675
5627
 
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);
5628
+ self.state = Transporter.IDLE;
5629
+ if (_runtime) {
5630
+ _runtime.exec.call(self, 'Transporter', 'clear');
5631
+ self.trigger("TransportingAborted");
5683
5632
  }
5684
5633
 
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;
5634
+ _reset.call(self);
5635
+ },
5688
5636
 
5689
- Events.addEvent(top, 'mouseover', function() {
5690
- comp.trigger('mouseenter');
5691
- }, comp.uid);
5692
5637
 
5693
- Events.addEvent(top, 'mouseout', function() {
5694
- comp.trigger('mouseleave');
5695
- }, comp.uid);
5638
+ destroy: function() {
5639
+ this.unbindAll();
5640
+ _runtime = null;
5641
+ this.disconnectRuntime();
5642
+ _reset.call(this);
5643
+ }
5644
+ });
5696
5645
 
5697
- Events.addEvent(top, 'mousedown', function() {
5698
- comp.trigger('mousedown');
5699
- }, comp.uid);
5646
+ function _reset() {
5647
+ _size = _pos = 0;
5648
+ _data = this.result = null;
5649
+ }
5700
5650
 
5701
- Events.addEvent(Dom.get(_options.container), 'mouseup', function() {
5702
- comp.trigger('mouseup');
5703
- }, comp.uid);
5651
+ function _run(type, runtime) {
5652
+ var self = this;
5704
5653
 
5654
+ _runtime = runtime;
5705
5655
 
5706
- input.onchange = function onChange() { // there should be only one handler for this
5707
- _files = [];
5656
+ //self.unbind("RuntimeInit");
5708
5657
 
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
- }
5719
-
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
- };
5658
+ self.bind("TransportingProgress", function(e) {
5659
+ _pos = e.loaded;
5731
5660
 
5732
- // ready event is perfectly asynchronous
5733
- comp.trigger({
5734
- type: 'ready',
5735
- async: true
5736
- });
5661
+ if (_pos < _size && Basic.inArray(self.state, [Transporter.IDLE, Transporter.DONE]) === -1) {
5662
+ _transport.call(self);
5663
+ }
5664
+ }, 999);
5737
5665
 
5738
- shimContainer = null;
5739
- },
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);
5740
5672
 
5741
- getFiles: function() {
5742
- return _files;
5743
- },
5673
+ self.state = Transporter.BUSY;
5674
+ self.trigger("TransportingStarted");
5675
+ _transport.call(self);
5676
+ }
5744
5677
 
5745
- disable: function(state) {
5746
- var I = this.getRuntime(), input;
5678
+ function _transport() {
5679
+ var self = this,
5680
+ chunk,
5681
+ bytesLeft = _size - _pos;
5747
5682
 
5748
- if ((input = Dom.get(I.uid))) {
5749
- input.disabled = !!state;
5750
- }
5751
- },
5683
+ if (_chunk_size > bytesLeft) {
5684
+ _chunk_size = bytesLeft;
5685
+ }
5752
5686
 
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 = '';
5765
- }
5687
+ chunk = Encode.btoa(_data.substr(_pos, _chunk_size));
5688
+ _runtime.exec.call(self, 'Transporter', 'receive', chunk, _size);
5689
+ }
5690
+ }
5766
5691
 
5767
- shim.removeInstance(this.uid);
5692
+ Transporter.IDLE = 0;
5693
+ Transporter.BUSY = 1;
5694
+ Transporter.DONE = 2;
5768
5695
 
5769
- _files = _options = shimContainer = shim = null;
5770
- }
5771
- });
5772
- }
5696
+ Transporter.prototype = EventTarget.instance;
5773
5697
 
5774
- return (extensions.FileInput = FileInput);
5698
+ return Transporter;
5775
5699
  });
5776
5700
 
5777
-
5778
- // Included from: src/javascript/runtime/html5/file/FileReader.js
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
5892
- ;
5877
+ var type = 'html4', extensions = {};
5893
5878
 
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
- ;
5879
+ function Html4Runtime(options) {
5880
+ var I = this
5881
+ , Test = Runtime.capTest
5882
+ , True = Runtime.capTrue
5883
+ ;
5901
5884
 
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,723 +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
- },
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
+ }
6293
5973
 
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
- },
5974
+ function stopPropagation() {
5975
+ this.cancelBubble = true;
5976
+ }
6306
5977
 
6307
- BYTE: function(idx) {
6308
- return read(idx, 1);
6309
- },
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();
6310
5994
 
6311
- SHORT: function(idx) {
6312
- return read(idx, 2);
6313
- },
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;
6314
6003
 
6315
- LONG: function(idx, num) {
6316
- if (num === undefined) {
6317
- return read(idx, 4);
6318
- } else {
6319
- write(idx, num, 4);
6004
+ if (!evt.target) {
6005
+ evt.target = evt.srcElement;
6320
6006
  }
6321
- },
6322
-
6323
- SLONG: function(idx) { // 2's complement notation
6324
- var num = read(idx, 4);
6325
-
6326
- return (num > 2147483647 ? num - 4294967296 : num);
6327
- },
6328
-
6329
- STRING: function(idx, size) {
6330
- var str = '';
6331
6007
 
6332
- for (size += idx; idx < size; idx++) {
6333
- str += String.fromCharCode(read(idx, 1));
6334
- }
6008
+ evt.preventDefault = preventDefault;
6009
+ evt.stopPropagation = stopPropagation;
6335
6010
 
6336
- return str;
6337
- }
6338
- };
6339
- };
6340
- });
6011
+ callback(evt);
6012
+ };
6341
6013
 
6342
- // Included from: src/javascript/runtime/flash/Runtime.js
6343
-
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;
6613
- }
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');
6647
- }
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;
6684
- }
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;
6712
- }
6713
- };
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
-
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;
6014
+ obj.attachEvent('on' + name, func);
6747
6015
  }
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
6758
- }
6759
-
6760
- // special prefix for DataURL read mode
6761
- if (op === 'readAsDataURL') {
6762
- result = 'data:' + (blob.type || '') + ';base64,' + result;
6763
- }
6764
-
6765
- return _formatData(result, op, blob.type);
6016
+
6017
+ // Log event handler to objects internal mOxie registry
6018
+ if (!obj[uid]) {
6019
+ obj[uid] = Basic.guid();
6020
+ }
6021
+
6022
+ if (!eventhash.hasOwnProperty(obj[uid])) {
6023
+ eventhash[obj[uid]] = {};
6024
+ }
6025
+
6026
+ events = eventhash[obj[uid]];
6027
+
6028
+ if (!events.hasOwnProperty(name)) {
6029
+ events[name] = [];
6766
6030
  }
6031
+
6032
+ events[name].push({
6033
+ func: func,
6034
+ orig: callback, // store original callback for IE
6035
+ key: key
6036
+ });
6767
6037
  };
6768
-
6769
- return (extensions.FileReaderSync = FileReaderSync);
6770
- });
6771
-
6772
- // Included from: src/javascript/runtime/flash/xhr/XMLHttpRequest.js
6773
-
6774
- /**
6775
- * XMLHttpRequest.js
6776
- *
6777
- * Copyright 2013, Moxiecode Systems AB
6778
- * Released under GPL License.
6779
- *
6780
- * License: http://www.plupload.com/license
6781
- * Contributing: http://www.plupload.com/contributing
6782
- */
6783
-
6784
- /**
6785
- @class moxie/runtime/flash/xhr/XMLHttpRequest
6786
- @private
6787
- */
6788
- define("moxie/runtime/flash/xhr/XMLHttpRequest", [
6789
- "moxie/runtime/flash/Runtime",
6790
- "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) {
6797
6038
 
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
- }
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;
6059
+ }
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);
6859
6068
  }
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();
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;
6870
6077
  }
6871
- } else {
6872
- send();
6873
6078
  }
6874
- },
6875
-
6876
- getResponse: function(responseType) {
6877
- var frs, blob, self = this.getRuntime();
6878
-
6879
- blob = self.shimExec.call(this, 'XMLHttpRequest', 'getResponseAsBlob');
6880
-
6881
- if (blob) {
6882
- blob = new File(self.uid, blob);
6883
-
6884
- if ('blob' === responseType) {
6885
- return blob;
6886
- }
6887
-
6888
- try {
6889
- frs = new FileReaderSync();
6890
-
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();
6898
- }
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;
6899
6095
  }
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
-
6908
- this.dispatchEvent('readystatechange');
6909
- // this.dispatchEvent('progress');
6910
- this.dispatchEvent('abort');
6911
-
6912
- //if (!upload_complete_flag) {
6913
- // this.dispatchEvent('uploadprogress');
6914
- //}
6915
6096
  }
6916
6097
  };
6917
-
6918
- return (extensions.XMLHttpRequest = XMLHttpRequest);
6919
- });
6920
-
6921
- // Included from: src/javascript/runtime/flash/runtime/Transporter.js
6922
-
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
- */
6932
-
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) {
6941
-
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);
6949
- }
6950
- return null;
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;
6951
6111
  }
6112
+
6113
+ Basic.each(eventhash[obj[uid]], function(events, name) {
6114
+ removeEvent(obj, name, key);
6115
+ });
6952
6116
  };
6953
6117
 
6954
- return (extensions.Transporter = Transporter);
6118
+ return {
6119
+ addEvent: addEvent,
6120
+ removeEvent: removeEvent,
6121
+ removeAllEvents: removeAllEvents
6122
+ };
6955
6123
  });
6956
6124
 
6957
-
6958
- // Included from: src/javascript/runtime/silverlight/Runtime.js
6125
+ // Included from: src/javascript/runtime/html4/file/FileInput.js
6959
6126
 
6960
6127
  /**
6961
- * RunTime.js
6128
+ * FileInput.js
6962
6129
  *
6963
6130
  * Copyright 2013, Moxiecode Systems AB
6964
6131
  * Released under GPL License.
@@ -6967,364 +6134,239 @@ define("moxie/runtime/flash/runtime/Transporter", [
6967
6134
  * Contributing: http://www.plupload.com/contributing
6968
6135
  */
6969
6136
 
6970
- /*global ActiveXObject:true */
6971
-
6972
6137
  /**
6973
- Defines constructor for Silverlight runtime.
6974
-
6975
- @class moxie/runtime/silverlight/Runtime
6138
+ @class moxie/runtime/html4/file/FileInput
6976
6139
  @private
6977
6140
  */
6978
- define("moxie/runtime/silverlight/Runtime", [
6141
+ define("moxie/runtime/html4/file/FileInput", [
6142
+ "moxie/runtime/html4/Runtime",
6979
6143
  "moxie/core/utils/Basic",
6980
- "moxie/core/utils/Env",
6981
6144
  "moxie/core/utils/Dom",
6982
- "moxie/core/Exceptions",
6983
- "moxie/runtime/Runtime"
6984
- ], function(Basic, Env, Dom, x, Runtime) {
6145
+ "moxie/core/utils/Events",
6146
+ "moxie/core/utils/Mime",
6147
+ "moxie/core/utils/Env"
6148
+ ], function(extensions, Basic, Dom, Events, Mime, Env) {
6985
6149
 
6986
- var type = "silverlight", extensions = {};
6987
-
6988
- function isInstalled(version) {
6989
- var isVersionSupported = false, control = null, actualVer,
6990
- actualVerArray, reqVerArray, requiredVersionPart, actualVersionPart, index = 0;
6991
-
6992
- try {
6993
- try {
6994
- control = new ActiveXObject('AgControl.AgControl');
6150
+ function FileInput() {
6151
+ var _uid, _files = [], _mimes = [], _options;
6995
6152
 
6996
- if (control.IsVersionSupported(version)) {
6997
- isVersionSupported = true;
6998
- }
6153
+ function addInput() {
6154
+ var comp = this, I = comp.getRuntime(), shimContainer, browseButton, currForm, form, input, uid;
6999
6155
 
7000
- control = null;
7001
- } catch (e) {
7002
- var plugin = navigator.plugins["Silverlight Plug-In"];
6156
+ uid = Basic.guid('uid_');
7003
6157
 
7004
- if (plugin) {
7005
- actualVer = plugin.description;
6158
+ shimContainer = I.getShimContainer(); // we get new ref everytime to avoid memory leaks in IE
7006
6159
 
7007
- if (actualVer === "1.0.30226.2") {
7008
- actualVer = "2.0.30226.2";
7009
- }
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%' });
6164
+ }
6165
+ }
7010
6166
 
7011
- actualVerArray = actualVer.split(".");
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');
7012
6173
 
7013
- while (actualVerArray.length > 3) {
7014
- actualVerArray.pop();
7015
- }
6174
+ Basic.extend(form.style, {
6175
+ overflow: 'hidden',
6176
+ position: 'absolute',
6177
+ top: 0,
6178
+ left: 0,
6179
+ width: '100%',
6180
+ height: '100%'
6181
+ });
7016
6182
 
7017
- while ( actualVerArray.length < 4) {
7018
- actualVerArray.push(0);
7019
- }
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(','));
7020
6188
 
7021
- reqVerArray = version.split(".");
6189
+ Basic.extend(input.style, {
6190
+ fontSize: '999px',
6191
+ opacity: 0
6192
+ });
7022
6193
 
7023
- while (reqVerArray.length > 4) {
7024
- reqVerArray.pop();
7025
- }
6194
+ form.appendChild(input);
6195
+ shimContainer.appendChild(form);
7026
6196
 
7027
- do {
7028
- requiredVersionPart = parseInt(reqVerArray[index], 10);
7029
- actualVersionPart = parseInt(actualVerArray[index], 10);
7030
- index++;
7031
- } while (index < reqVerArray.length && requiredVersionPart === actualVersionPart);
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
+ });
7032
6205
 
7033
- if (requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart)) {
7034
- isVersionSupported = true;
7035
- }
7036
- }
6206
+ if (Env.browser === 'IE' && Env.version < 10) {
6207
+ Basic.extend(input.style, {
6208
+ filter : "progid:DXImageTransform.Microsoft.Alpha(opacity=0)"
6209
+ });
7037
6210
  }
7038
- } catch (e2) {
7039
- isVersionSupported = false;
7040
- }
7041
-
7042
- return isVersionSupported;
7043
- }
7044
-
7045
- /**
7046
- Constructor for the Silverlight Runtime
7047
6211
 
7048
- @class SilverlightRuntime
7049
- @extends Runtime
7050
- */
7051
- function SilverlightRuntime(options) {
7052
- var I = this, initTimer;
6212
+ input.onchange = function() { // there should be only one handler for this
6213
+ var file;
7053
6214
 
7054
- options = Basic.extend({ xap_url: Env.xap_url }, options);
6215
+ if (!this.value) {
6216
+ return;
6217
+ }
7055
6218
 
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;
6219
+ if (this.files) {
6220
+ file = this.files[0];
7070
6221
  } else {
7071
- return !!window.JSON;
6222
+ file = {
6223
+ name: this.value
6224
+ };
7072
6225
  }
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
- });
7112
6226
 
6227
+ _files = [file];
7113
6228
 
7114
- // minimal requirement
7115
- if (!isInstalled('2.0.31005.0') || Env.browser === 'Opera') {
7116
- this.mode = false;
7117
- }
6229
+ this.onchange = function() {}; // clear event handler
6230
+ addInput.call(comp);
7118
6231
 
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;
7119
6235
 
7120
- Basic.extend(this, {
7121
- getShim: function() {
7122
- return Dom.get(this.uid).content.Moxie;
7123
- },
6236
+ comp.unbind('change', onChange);
7124
6237
 
7125
- shimExec: function(component, action) {
7126
- var args = [].slice.call(arguments, 2);
7127
- return I.getShim().exec(this.uid, component, action, args);
7128
- },
6238
+ if (comp.files.length && input && form) {
6239
+ file = comp.files[0];
7129
6240
 
7130
- init : function() {
7131
- var container;
6241
+ input.setAttribute('id', file.uid);
6242
+ form.setAttribute('id', file.uid + '_form');
7132
6243
 
7133
- container = this.getShimContainer();
6244
+ // set upload target
6245
+ form.setAttribute('target', file.uid + '_iframe');
6246
+ }
6247
+ input = form = null;
6248
+ }, 998);
7134
6249
 
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>';
6250
+ input = form = null;
6251
+ comp.trigger('change');
6252
+ };
7142
6253
 
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));
6254
+
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();
7147
6262
  }
7148
- }, Env.OS !== 'Windows'? 10000 : 5000); // give it more time to initialize in non Windows OS (like Mac)
7149
- },
6263
+ e.preventDefault();
6264
+ }, comp.uid);
6265
+ }
6266
+
6267
+ _uid = uid;
6268
+
6269
+ shimContainer = currForm = browseButton = null;
6270
+ }
7150
6271
 
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))
6272
+ Basic.extend(this, {
6273
+ init: function(options) {
6274
+ var comp = this, I = comp.getRuntime(), shimContainer;
7158
6275
 
7159
- }, extensions);
7160
- }
6276
+ // figure out accept string
6277
+ _options = options;
6278
+ _mimes = options.accept.mimes || Mime.extList2mimes(options.accept, I.can('filter_by_extension'));
7161
6279
 
7162
- Runtime.addConstructor(type, SilverlightRuntime);
6280
+ shimContainer = I.getShimContainer();
7163
6281
 
7164
- return extensions;
7165
- });
6282
+ (function() {
6283
+ var browseButton, zIndex, top;
7166
6284
 
7167
- // Included from: src/javascript/runtime/silverlight/file/Blob.js
6285
+ browseButton = Dom.get(options.browse_button);
7168
6286
 
7169
- /**
7170
- * Blob.js
7171
- *
7172
- * Copyright 2013, Moxiecode Systems AB
7173
- * Released under GPL License.
7174
- *
7175
- * License: http://www.plupload.com/license
7176
- * Contributing: http://www.plupload.com/contributing
7177
- */
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
+ }
7178
6292
 
7179
- /**
7180
- @class moxie/runtime/silverlight/file/Blob
7181
- @private
7182
- */
7183
- define("moxie/runtime/silverlight/file/Blob", [
7184
- "moxie/runtime/silverlight/Runtime",
7185
- "moxie/core/utils/Basic",
7186
- "moxie/runtime/flash/file/Blob"
7187
- ], function(extensions, Basic, Blob) {
7188
- return (extensions.Blob = Basic.extend({}, Blob));
7189
- });
6293
+ zIndex = parseInt(Dom.getStyle(browseButton, 'z-index'), 10) || 1;
7190
6294
 
7191
- // Included from: src/javascript/runtime/silverlight/file/FileInput.js
6295
+ browseButton.style.zIndex = zIndex;
6296
+ shimContainer.style.zIndex = zIndex - 1;
6297
+ }
7192
6298
 
7193
- /**
7194
- * FileInput.js
7195
- *
7196
- * Copyright 2013, Moxiecode Systems AB
7197
- * Released under GPL License.
7198
- *
7199
- * License: http://www.plupload.com/license
7200
- * Contributing: http://www.plupload.com/contributing
7201
- */
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;
7202
6302
 
7203
- /**
7204
- @class moxie/runtime/silverlight/file/FileInput
7205
- @private
7206
- */
7207
- define("moxie/runtime/silverlight/file/FileInput", [
7208
- "moxie/runtime/silverlight/Runtime"
7209
- ], function(extensions) {
7210
-
7211
- var FileInput = {
7212
- init: function(options) {
6303
+ Events.addEvent(top, 'mouseover', function() {
6304
+ comp.trigger('mouseenter');
6305
+ }, comp.uid);
7213
6306
 
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, ';*.');
7218
- }
7219
- return filter;
7220
- }
7221
-
7222
- this.getRuntime().shimExec.call(this, 'FileInput', 'init', toFilters(options.accept), options.name, options.multiple);
7223
- this.trigger('ready');
7224
- }
7225
- };
6307
+ Events.addEvent(top, 'mouseout', function() {
6308
+ comp.trigger('mouseleave');
6309
+ }, comp.uid);
7226
6310
 
7227
- return (extensions.FileInput = FileInput);
7228
- });
6311
+ Events.addEvent(top, 'mousedown', function() {
6312
+ comp.trigger('mousedown');
6313
+ }, comp.uid);
7229
6314
 
7230
- // Included from: src/javascript/runtime/silverlight/file/FileReader.js
6315
+ Events.addEvent(Dom.get(options.container), 'mouseup', function() {
6316
+ comp.trigger('mouseup');
6317
+ }, comp.uid);
7231
6318
 
7232
- /**
7233
- * FileReader.js
7234
- *
7235
- * Copyright 2013, Moxiecode Systems AB
7236
- * Released under GPL License.
7237
- *
7238
- * License: http://www.plupload.com/license
7239
- * Contributing: http://www.plupload.com/contributing
7240
- */
6319
+ browseButton = null;
6320
+ }());
7241
6321
 
7242
- /**
7243
- @class moxie/runtime/silverlight/file/FileReader
7244
- @private
7245
- */
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));
7252
- });
6322
+ addInput.call(this);
7253
6323
 
7254
- // Included from: src/javascript/runtime/silverlight/file/FileReaderSync.js
6324
+ shimContainer = null;
7255
6325
 
7256
- /**
7257
- * FileReaderSync.js
7258
- *
7259
- * Copyright 2013, Moxiecode Systems AB
7260
- * Released under GPL License.
7261
- *
7262
- * License: http://www.plupload.com/license
7263
- * Contributing: http://www.plupload.com/contributing
7264
- */
6326
+ // trigger ready event asynchronously
6327
+ comp.trigger({
6328
+ type: 'ready',
6329
+ async: true
6330
+ });
6331
+ },
7265
6332
 
7266
- /**
7267
- @class moxie/runtime/silverlight/file/FileReaderSync
7268
- @private
7269
- */
7270
- define("moxie/runtime/silverlight/file/FileReaderSync", [
7271
- "moxie/runtime/silverlight/Runtime",
7272
- "moxie/core/utils/Basic",
7273
- "moxie/runtime/flash/file/FileReaderSync"
7274
- ], function(extensions, Basic, FileReaderSync) {
7275
- return (extensions.FileReaderSync = Basic.extend({}, FileReaderSync));
7276
- });
6333
+ getFiles: function() {
6334
+ return _files;
6335
+ },
7277
6336
 
7278
- // Included from: src/javascript/runtime/silverlight/xhr/XMLHttpRequest.js
6337
+ disable: function(state) {
6338
+ var input;
7279
6339
 
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
- */
6340
+ if ((input = Dom.get(_uid))) {
6341
+ input.disabled = !!state;
6342
+ }
6343
+ },
7289
6344
 
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
- });
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
+ }
7301
6358
 
7302
- // Included from: src/javascript/runtime/silverlight/runtime/Transporter.js
6359
+ shim.removeInstance(this.uid);
7303
6360
 
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
- */
6361
+ _uid = _files = _mimes = _options = shimContainer = shim = null;
6362
+ }
6363
+ });
6364
+ }
7313
6365
 
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));
6366
+ return (extensions.FileInput = FileInput);
7324
6367
  });
7325
6368
 
7326
-
7327
- // Included from: src/javascript/runtime/html4/Runtime.js
6369
+ // Included from: src/javascript/runtime/html5/Runtime.js
7328
6370
 
7329
6371
  /**
7330
6372
  * Runtime.js
@@ -7339,73 +6381,91 @@ define("moxie/runtime/silverlight/runtime/Transporter", [
7339
6381
  /*global File:true */
7340
6382
 
7341
6383
  /**
7342
- Defines constructor for HTML4 runtime.
6384
+ Defines constructor for HTML5 runtime.
7343
6385
 
7344
- @class moxie/runtime/html4/Runtime
6386
+ @class moxie/runtime/html5/Runtime
7345
6387
  @private
7346
6388
  */
7347
- define("moxie/runtime/html4/Runtime", [
6389
+ define("moxie/runtime/html5/Runtime", [
7348
6390
  "moxie/core/utils/Basic",
7349
6391
  "moxie/core/Exceptions",
7350
6392
  "moxie/runtime/Runtime",
7351
6393
  "moxie/core/utils/Env"
7352
6394
  ], function(Basic, x, Runtime, Env) {
7353
6395
 
7354
- var type = 'html4', extensions = {};
7355
-
7356
- function Html4Runtime(options) {
6396
+ var type = "html5", extensions = {};
6397
+
6398
+ function Html5Runtime(options) {
7357
6399
  var I = this
7358
6400
  , Test = Runtime.capTest
7359
6401
  , True = Runtime.capTrue
7360
6402
  ;
7361
6403
 
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');
7387
- },
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');
7395
- },
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
- });
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);
7406
6465
 
7407
6466
 
7408
6467
  Basic.extend(this, {
6468
+
7409
6469
  init : function() {
7410
6470
  this.trigger("Init");
7411
6471
  },
@@ -7421,15 +6481,15 @@ define("moxie/runtime/html4/Runtime", [
7421
6481
  Basic.extend(this.getShim(), extensions);
7422
6482
  }
7423
6483
 
7424
- Runtime.addConstructor(type, Html4Runtime);
6484
+ Runtime.addConstructor(type, Html5Runtime);
7425
6485
 
7426
6486
  return extensions;
7427
6487
  });
7428
6488
 
7429
- // Included from: src/javascript/runtime/html4/file/FileInput.js
6489
+ // Included from: src/javascript/runtime/html5/file/FileReader.js
7430
6490
 
7431
6491
  /**
7432
- * FileInput.js
6492
+ * FileReader.js
7433
6493
  *
7434
6494
  * Copyright 2013, Moxiecode Systems AB
7435
6495
  * Released under GPL License.
@@ -7439,241 +6499,347 @@ define("moxie/runtime/html4/Runtime", [
7439
6499
  */
7440
6500
 
7441
6501
  /**
7442
- @class moxie/runtime/html4/file/FileInput
6502
+ @class moxie/runtime/html5/file/FileReader
7443
6503
  @private
7444
6504
  */
7445
- define("moxie/runtime/html4/file/FileInput", [
7446
- "moxie/runtime/html4/Runtime",
7447
- "moxie/core/utils/Basic",
7448
- "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) {
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) {
7453
6510
 
7454
- function FileInput() {
7455
- var _uid, _files = [], _mimes = [], _options;
6511
+ function FileReader() {
6512
+ var _fr, _convertToBinary = false;
7456
6513
 
7457
- function addInput() {
7458
- var comp = this, I = comp.getRuntime(), shimContainer, browseButton, currForm, form, input, uid;
6514
+ Basic.extend(this, {
7459
6515
 
7460
- uid = Basic.guid('uid_');
6516
+ read: function(op, blob) {
6517
+ var target = this;
7461
6518
 
7462
- shimContainer = I.getShimContainer(); // we get new ref everytime to avoid memory leaks in IE
6519
+ _fr = new window.FileReader();
7463
6520
 
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%' });
7468
- }
7469
- }
6521
+ _fr.addEventListener('progress', function(e) {
6522
+ target.trigger(e);
6523
+ });
7470
6524
 
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');
6525
+ _fr.addEventListener('load', function(e) {
6526
+ target.trigger(e);
6527
+ });
7477
6528
 
7478
- Basic.extend(form.style, {
7479
- overflow: 'hidden',
7480
- position: 'absolute',
7481
- top: 0,
7482
- left: 0,
7483
- width: '100%',
7484
- height: '100%'
7485
- });
6529
+ _fr.addEventListener('error', function(e) {
6530
+ target.trigger(e, _fr.error);
6531
+ });
7486
6532
 
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(','));
6533
+ _fr.addEventListener('loadend', function() {
6534
+ _fr = null;
6535
+ });
7492
6536
 
7493
- Basic.extend(input.style, {
7494
- fontSize: '999px',
7495
- opacity: 0
7496
- });
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());
6543
+ }
6544
+ },
7497
6545
 
7498
- form.appendChild(input);
7499
- shimContainer.appendChild(form);
6546
+ getResult: function() {
6547
+ return _fr && _fr.result ? (_convertToBinary ? _toBinary(_fr.result) : _fr.result) : null;
6548
+ },
7500
6549
 
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
- });
6550
+ abort: function() {
6551
+ if (_fr) {
6552
+ _fr.abort();
6553
+ }
6554
+ },
7509
6555
 
7510
- if (Env.browser === 'IE' && Env.version < 10) {
7511
- Basic.extend(input.style, {
7512
- filter : "progid:DXImageTransform.Microsoft.Alpha(opacity=0)"
7513
- });
6556
+ destroy: function() {
6557
+ _fr = null;
7514
6558
  }
6559
+ });
7515
6560
 
7516
- input.onchange = function() { // there should be only one handler for this
7517
- var file;
6561
+ function _toBinary(str) {
6562
+ return Encode.atob(str.substring(str.indexOf('base64,') + 7));
6563
+ }
6564
+ }
7518
6565
 
7519
- if (!this.value) {
7520
- return;
7521
- }
6566
+ return (extensions.FileReader = FileReader);
6567
+ });
7522
6568
 
7523
- if (this.files) {
7524
- file = this.files[0];
7525
- } else {
7526
- file = {
7527
- name: this.value
7528
- };
7529
- }
6569
+ // Included from: src/javascript/runtime/html4/file/FileReader.js
7530
6570
 
7531
- _files = [file];
6571
+ /**
6572
+ * FileReader.js
6573
+ *
6574
+ * Copyright 2013, Moxiecode Systems AB
6575
+ * Released under GPL License.
6576
+ *
6577
+ * License: http://www.plupload.com/license
6578
+ * Contributing: http://www.plupload.com/contributing
6579
+ */
7532
6580
 
7533
- this.onchange = function() {}; // clear event handler
7534
- addInput.call(comp);
6581
+ /**
6582
+ @class moxie/runtime/html4/file/FileReader
6583
+ @private
6584
+ */
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);
6590
+ });
6591
+
6592
+ // Included from: src/javascript/runtime/html4/xhr/XMLHttpRequest.js
6593
+
6594
+ /**
6595
+ * XMLHttpRequest.js
6596
+ *
6597
+ * Copyright 2013, Moxiecode Systems AB
6598
+ * Released under GPL License.
6599
+ *
6600
+ * License: http://www.plupload.com/license
6601
+ * Contributing: http://www.plupload.com/contributing
6602
+ */
6603
+
6604
+ /**
6605
+ @class moxie/runtime/html4/xhr/XMLHttpRequest
6606
+ @private
6607
+ */
6608
+ define("moxie/runtime/html4/xhr/XMLHttpRequest", [
6609
+ "moxie/runtime/html4/Runtime",
6610
+ "moxie/core/utils/Basic",
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;
7535
6621
 
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;
6622
+ function cleanup(cb) {
6623
+ var target = this, uid, form, inputs, i, hasFile = false;
7539
6624
 
7540
- comp.unbind('change', onChange);
6625
+ if (!_iframe) {
6626
+ return;
6627
+ }
7541
6628
 
7542
- if (comp.files.length && input && form) {
7543
- file = comp.files[0];
6629
+ uid = _iframe.id.replace(/_iframe$/, '');
7544
6630
 
7545
- input.setAttribute('id', file.uid);
7546
- form.setAttribute('id', file.uid + '_form');
6631
+ form = Dom.get(uid + '_form');
6632
+ if (form) {
6633
+ inputs = form.getElementsByTagName('input');
6634
+ i = inputs.length;
7547
6635
 
7548
- // set upload target
7549
- form.setAttribute('target', file.uid + '_iframe');
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;
7550
6644
  }
7551
- input = form = null;
7552
- }, 998);
7553
-
7554
- input = form = null;
7555
- comp.trigger('change');
7556
- };
7557
-
6645
+ }
6646
+ inputs = [];
7558
6647
 
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);
6648
+ if (!hasFile) { // we need to keep the form for sake of possible retries
6649
+ form.parentNode.removeChild(form);
6650
+ }
6651
+ form = null;
7569
6652
  }
7570
6653
 
7571
- _uid = uid;
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
+ }
7572
6660
 
7573
- shimContainer = currForm = browseButton = null;
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
+ }
6666
+
6667
+ shimContainer = _iframe = null;
6668
+ cb();
6669
+ }, 1);
7574
6670
  }
7575
6671
 
7576
6672
  Basic.extend(this, {
7577
- init: function(options) {
7578
- var comp = this, I = comp.getRuntime(), shimContainer;
6673
+ send: function(meta, data) {
6674
+ var target = this, I = target.getRuntime(), uid, form, input, blob;
7579
6675
 
7580
- // figure out accept string
7581
- _options = options;
7582
- _mimes = options.accept.mimes || Mime.extList2mimes(options.accept, I.can('filter_by_extension'));
6676
+ _status = _response = null;
7583
6677
 
7584
- shimContainer = I.getShimContainer();
6678
+ function createIframe() {
6679
+ var container = I.getShimContainer() || document.body
6680
+ , temp = document.createElement('div')
6681
+ ;
7585
6682
 
7586
- (function() {
7587
- var browseButton, zIndex, top;
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);
7588
6687
 
7589
- browseButton = Dom.get(options.browse_button);
6688
+ /* _iframe.onreadystatechange = function() {
6689
+ console.info(_iframe.readyState);
6690
+ };*/
7590
6691
 
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
- }
6692
+ Events.addEvent(_iframe, 'load', function() { // _iframe.onload doesn't work in IE lte 8
6693
+ var el;
7596
6694
 
7597
- zIndex = parseInt(Dom.getStyle(browseButton, 'z-index'), 10) || 1;
6695
+ try {
6696
+ el = _iframe.contentWindow.document || _iframe.contentDocument || window.frames[_iframe.id].document;
7598
6697
 
7599
- browseButton.style.zIndex = zIndex;
7600
- shimContainer.style.zIndex = zIndex - 1;
7601
- }
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);
7602
6705
 
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;
6706
+ // we need to fire these at least once
6707
+ target.trigger({
6708
+ type: 'progress',
6709
+ loaded: _response.length,
6710
+ total: _response.length
6711
+ });
7606
6712
 
7607
- Events.addEvent(top, 'mouseover', function() {
7608
- comp.trigger('mouseenter');
7609
- }, comp.uid);
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
7610
6739
 
7611
- Events.addEvent(top, 'mouseout', function() {
7612
- comp.trigger('mouseleave');
7613
- }, comp.uid);
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_');
7614
6751
 
7615
- Events.addEvent(top, 'mousedown', function() {
7616
- comp.trigger('mousedown');
7617
- }, comp.uid);
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');
7618
6758
 
7619
- Events.addEvent(Dom.get(options.container), 'mouseup', function() {
7620
- comp.trigger('mouseup');
7621
- }, comp.uid);
6759
+ I.getShimContainer().appendChild(form);
6760
+ }
7622
6761
 
7623
- browseButton = null;
7624
- }());
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');
7625
6770
 
7626
- addInput.call(this);
6771
+ Basic.extend(hidden, {
6772
+ type : 'hidden',
6773
+ name : name,
6774
+ value : value
6775
+ });
7627
6776
 
7628
- shimContainer = null;
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
+ }
7629
6786
 
7630
- // trigger ready event asynchronously
7631
- comp.trigger({
7632
- type: 'ready',
7633
- async: true
7634
- });
6787
+ // set destination url
6788
+ form.setAttribute("action", meta.url);
6789
+
6790
+ createIframe();
6791
+ form.submit();
6792
+ target.trigger('loadstart');
7635
6793
  },
7636
6794
 
7637
- getFiles: function() {
7638
- return _files;
6795
+ getStatus: function() {
6796
+ return _status;
7639
6797
  },
7640
6798
 
7641
- disable: function(state) {
7642
- var input;
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) {
7643
6810
 
7644
- if ((input = Dom.get(_uid))) {
7645
- input.disabled = !!state;
7646
6811
  }
6812
+ return _response;
7647
6813
  },
7648
6814
 
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 = '';
6815
+ abort: function() {
6816
+ var target = this;
6817
+
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
+ }
7661
6826
  }
7662
6827
 
7663
- shim.removeInstance(this.uid);
7664
-
7665
- _uid = _files = _mimes = _options = shimContainer = shim = null;
6828
+ cleanup.call(this, function() {
6829
+ // target.dispatchEvent('readystatechange');
6830
+ target.dispatchEvent('abort');
6831
+ });
7666
6832
  }
7667
6833
  });
7668
6834
  }
7669
6835
 
7670
- return (extensions.FileInput = FileInput);
6836
+ return (extensions.XMLHttpRequest = XMLHttpRequest);
7671
6837
  });
7672
6838
 
7673
- // Included from: src/javascript/runtime/html4/file/FileReader.js
6839
+ // Included from: src/javascript/runtime/silverlight/Runtime.js
7674
6840
 
7675
6841
  /**
7676
- * FileReader.js
6842
+ * RunTime.js
7677
6843
  *
7678
6844
  * Copyright 2013, Moxiecode Systems AB
7679
6845
  * Released under GPL License.
@@ -7682,264 +6848,337 @@ define("moxie/runtime/html4/file/FileInput", [
7682
6848
  * Contributing: http://www.plupload.com/contributing
7683
6849
  */
7684
6850
 
7685
- /**
7686
- @class moxie/runtime/html4/file/FileReader
7687
- @private
7688
- */
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);
7694
- });
7695
-
7696
- // Included from: src/javascript/runtime/html4/xhr/XMLHttpRequest.js
6851
+ /*global ActiveXObject:true */
7697
6852
 
7698
6853
  /**
7699
- * XMLHttpRequest.js
7700
- *
7701
- * Copyright 2013, Moxiecode Systems AB
7702
- * Released under GPL License.
7703
- *
7704
- * License: http://www.plupload.com/license
7705
- * Contributing: http://www.plupload.com/contributing
7706
- */
6854
+ Defines constructor for Silverlight runtime.
7707
6855
 
7708
- /**
7709
- @class moxie/runtime/html4/xhr/XMLHttpRequest
6856
+ @class moxie/runtime/silverlight/Runtime
7710
6857
  @private
7711
6858
  */
7712
- define("moxie/runtime/html4/xhr/XMLHttpRequest", [
7713
- "moxie/runtime/html4/Runtime",
6859
+ define("moxie/runtime/silverlight/Runtime", [
7714
6860
  "moxie/core/utils/Basic",
6861
+ "moxie/core/utils/Env",
7715
6862
  "moxie/core/utils/Dom",
7716
- "moxie/core/utils/Url",
7717
6863
  "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) {
6864
+ "moxie/runtime/Runtime"
6865
+ ], function(Basic, Env, Dom, x, Runtime) {
7722
6866
 
7723
- function XMLHttpRequest() {
7724
- var _status, _response, _iframe;
6867
+ var type = "silverlight", extensions = {};
7725
6868
 
7726
- function cleanup(cb) {
7727
- var target = this, uid, form, inputs, i, hasFile = false;
6869
+ function isInstalled(version) {
6870
+ var isVersionSupported = false, control = null, actualVer,
6871
+ actualVerArray, reqVerArray, requiredVersionPart, actualVersionPart, index = 0;
7728
6872
 
7729
- if (!_iframe) {
7730
- return;
7731
- }
6873
+ try {
6874
+ try {
6875
+ control = new ActiveXObject('AgControl.AgControl');
7732
6876
 
7733
- uid = _iframe.id.replace(/_iframe$/, '');
6877
+ if (control.IsVersionSupported(version)) {
6878
+ isVersionSupported = true;
6879
+ }
7734
6880
 
7735
- form = Dom.get(uid + '_form');
7736
- if (form) {
7737
- inputs = form.getElementsByTagName('input');
7738
- i = inputs.length;
6881
+ control = null;
6882
+ } catch (e) {
6883
+ var plugin = navigator.plugins["Silverlight Plug-In"];
7739
6884
 
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;
6885
+ if (plugin) {
6886
+ actualVer = plugin.description;
6887
+
6888
+ if (actualVer === "1.0.30226.2") {
6889
+ actualVer = "2.0.30226.2";
7748
6890
  }
7749
- }
7750
- inputs = [];
7751
6891
 
7752
- if (!hasFile) { // we need to keep the form for sake of possible retries
7753
- form.parentNode.removeChild(form);
6892
+ actualVerArray = actualVer.split(".");
6893
+
6894
+ while (actualVerArray.length > 3) {
6895
+ actualVerArray.pop();
6896
+ }
6897
+
6898
+ while ( actualVerArray.length < 4) {
6899
+ actualVerArray.push(0);
6900
+ }
6901
+
6902
+ reqVerArray = version.split(".");
6903
+
6904
+ while (reqVerArray.length > 4) {
6905
+ reqVerArray.pop();
6906
+ }
6907
+
6908
+ do {
6909
+ requiredVersionPart = parseInt(reqVerArray[index], 10);
6910
+ actualVersionPart = parseInt(actualVerArray[index], 10);
6911
+ index++;
6912
+ } while (index < reqVerArray.length && requiredVersionPart === actualVersionPart);
6913
+
6914
+ if (requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart)) {
6915
+ isVersionSupported = true;
6916
+ }
7754
6917
  }
7755
- form = null;
7756
6918
  }
6919
+ } catch (e2) {
6920
+ isVersionSupported = false;
6921
+ }
7757
6922
 
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
- }
6923
+ return isVersionSupported;
6924
+ }
7764
6925
 
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);
6926
+ /**
6927
+ Constructor for the Silverlight Runtime
6928
+
6929
+ @class SilverlightRuntime
6930
+ @extends Runtime
6931
+ */
6932
+ function SilverlightRuntime(options) {
6933
+ var I = this, initTimer;
6934
+
6935
+ options = Basic.extend({ xap_url: Env.xap_url }, options);
6936
+
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;
7769
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'];
6991
+ }
6992
+ });
7770
6993
 
7771
- shimContainer = _iframe = null;
7772
- cb();
7773
- }, 1);
6994
+
6995
+ // minimal requirement
6996
+ if (!isInstalled('2.0.31005.0') || Env.browser === 'Opera') {
6997
+ this.mode = false;
7774
6998
  }
7775
6999
 
7000
+
7776
7001
  Basic.extend(this, {
7777
- send: function(meta, data) {
7778
- var target = this, I = target.getRuntime(), uid, form, input, blob;
7002
+ getShim: function() {
7003
+ return Dom.get(this.uid).content.Moxie;
7004
+ },
7779
7005
 
7780
- _status = _response = null;
7006
+ shimExec: function(component, action) {
7007
+ var args = [].slice.call(arguments, 2);
7008
+ return I.getShim().exec(this.uid, component, action, args);
7009
+ },
7781
7010
 
7782
- function createIframe() {
7783
- var container = I.getShimContainer() || document.body
7784
- , temp = document.createElement('div')
7785
- ;
7011
+ init : function() {
7012
+ var container;
7786
7013
 
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);
7014
+ container = this.getShimContainer();
7791
7015
 
7792
- /* _iframe.onreadystatechange = function() {
7793
- console.info(_iframe.readyState);
7794
- };*/
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>';
7795
7023
 
7796
- Events.addEvent(_iframe, 'load', function() { // _iframe.onload doesn't work in IE lte 8
7797
- var el;
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));
7028
+ }
7029
+ }, Env.OS !== 'Windows'? 10000 : 5000); // give it more time to initialize in non Windows OS (like Mac)
7030
+ },
7031
+
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))
7798
7039
 
7799
- try {
7800
- el = _iframe.contentWindow.document || _iframe.contentDocument || window.frames[_iframe.id].document;
7040
+ }, extensions);
7041
+ }
7801
7042
 
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);
7043
+ Runtime.addConstructor(type, SilverlightRuntime);
7809
7044
 
7810
- // we need to fire these at least once
7811
- target.trigger({
7812
- type: 'progress',
7813
- loaded: _response.length,
7814
- total: _response.length
7815
- });
7045
+ return extensions;
7046
+ });
7816
7047
 
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
7048
+ // Included from: src/javascript/runtime/silverlight/file/Blob.js
7843
7049
 
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_');
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
+ */
7855
7059
 
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');
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
+ });
7862
7071
 
7863
- I.getShimContainer().appendChild(form);
7864
- }
7072
+ // Included from: src/javascript/runtime/silverlight/file/FileInput.js
7865
7073
 
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');
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
+ */
7874
7083
 
7875
- Basic.extend(hidden, {
7876
- type : 'hidden',
7877
- name : name,
7878
- value : value
7879
- });
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) {
7880
7094
 
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
- });
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, ';*.');
7889
7099
  }
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
+ };
7890
7107
 
7891
- // set destination url
7892
- form.setAttribute("action", meta.url);
7108
+ return (extensions.FileInput = FileInput);
7109
+ });
7893
7110
 
7894
- createIframe();
7895
- form.submit();
7896
- target.trigger('loadstart');
7897
- },
7111
+ // Included from: src/javascript/runtime/silverlight/file/FileReader.js
7898
7112
 
7899
- getStatus: function() {
7900
- return _status;
7901
- },
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
+ */
7902
7122
 
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) {
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));
7133
+ });
7914
7134
 
7915
- }
7916
- return _response;
7917
- },
7135
+ // Included from: src/javascript/runtime/silverlight/file/FileReaderSync.js
7918
7136
 
7919
- abort: function() {
7920
- var target = this;
7137
+ /**
7138
+ * FileReaderSync.js
7139
+ *
7140
+ * Copyright 2013, Moxiecode Systems AB
7141
+ * Released under GPL License.
7142
+ *
7143
+ * License: http://www.plupload.com/license
7144
+ * Contributing: http://www.plupload.com/contributing
7145
+ */
7921
7146
 
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
- }
7147
+ /**
7148
+ @class moxie/runtime/silverlight/file/FileReaderSync
7149
+ @private
7150
+ */
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));
7157
+ });
7931
7158
 
7932
- cleanup.call(this, function() {
7933
- // target.dispatchEvent('readystatechange');
7934
- target.dispatchEvent('abort');
7935
- });
7936
- }
7937
- });
7938
- }
7159
+ // Included from: src/javascript/runtime/silverlight/xhr/XMLHttpRequest.js
7939
7160
 
7940
- return (extensions.XMLHttpRequest = XMLHttpRequest);
7941
- });
7161
+ /**
7162
+ * XMLHttpRequest.js
7163
+ *
7164
+ * Copyright 2013, Moxiecode Systems AB
7165
+ * Released under GPL License.
7166
+ *
7167
+ * License: http://www.plupload.com/license
7168
+ * Contributing: http://www.plupload.com/contributing
7169
+ */
7942
7170
 
7171
+ /**
7172
+ @class moxie/runtime/silverlight/xhr/XMLHttpRequest
7173
+ @private
7174
+ */
7175
+ define("moxie/runtime/silverlight/xhr/XMLHttpRequest", [
7176
+ "moxie/runtime/silverlight/Runtime",
7177
+ "moxie/core/utils/Basic",
7178
+ "moxie/runtime/flash/xhr/XMLHttpRequest"
7179
+ ], function(extensions, Basic, XMLHttpRequest) {
7180
+ return (extensions.XMLHttpRequest = Basic.extend({}, XMLHttpRequest));
7181
+ });
7943
7182
 
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);/**
@@ -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);
@@ -8103,12 +7342,6 @@ Globally exposed namespace with the most frequently used public classes and hand
8103
7342
  }
8104
7343
 
8105
7344
  return inputValueDesc.prop._supget.call(this);
8106
- },
8107
- set: function(val){
8108
- if(val === '' && this.type == 'file' && $(this).hasClass('ws-filereader')){
8109
- webshim.data(this, 'fileList', []);
8110
- }
8111
- inputValueDesc.prop._supset.call(this);
8112
7345
  }
8113
7346
  }
8114
7347
  }
@@ -8306,10 +7539,10 @@ Globally exposed namespace with the most frequently used public classes and hand
8306
7539
  }
8307
7540
 
8308
7541
  if(!featureOptions.swfpath){
8309
- featureOptions.swfpath = shimMoxiePath+'flash/Moxie.cdn.swf';
7542
+ featureOptions.swfpath = shimMoxiePath+'flash/Moxie.min.swf';
8310
7543
  }
8311
7544
  if(!featureOptions.xappath){
8312
- featureOptions.xappath = shimMoxiePath+'silverlight/Moxie.cdn.xap';
7545
+ featureOptions.xappath = shimMoxiePath+'silverlight/Moxie.min.xap';
8313
7546
  }
8314
7547
 
8315
7548
  if($.support.cors !== false || !window.XDomainRequest){
@@ -8359,6 +7592,13 @@ Globally exposed namespace with the most frequently used public classes and hand
8359
7592
  }
8360
7593
  });
8361
7594
 
7595
+ webshim.onNodeNamesPropertyModify('input', 'value', function(value, boolVal, type){
7596
+ if(value === '' && this.type == 'file' && $(this).hasClass('ws-filereader')){
7597
+ webshim.data(this, 'fileList', []);
7598
+ }
7599
+ });
7600
+
7601
+
8362
7602
  window.FileReader = notReadyYet;
8363
7603
  window.FormData = notReadyYet;
8364
7604
  webshim.ready('moxie', function(){
@@ -8393,7 +7633,7 @@ Globally exposed namespace with the most frequently used public classes and hand
8393
7633
  if(inputName && !$(appendData[i]).is(':disabled')){
8394
7634
  files = $.prop(appendData[i], 'files') || [];
8395
7635
  if(files.length){
8396
- if(files.length > 1){
7636
+ if(files.length > 1 || (moxieData.hasBlob && moxieData.hasBlob())){
8397
7637
  webshim.error('FormData shim can only handle one file per ajax. Use multiple ajax request. One per file.');
8398
7638
  }
8399
7639
  for(fileI = 0, fileLen = files.length; fileI < fileLen; fileI++){