plupload.dev.js
113 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
/**
* Plupload - multi-runtime File Uploader
* v3.1.2
*
* Copyright 2018, Ephox
* Released under AGPLv3 License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*
* Date: 2018-02-20
*/
;(function (global, factory) {
var extract = function() {
var ctx = {};
factory.apply(ctx, arguments);
return ctx.plupload;
};
if (typeof define === "function" && define.amd) {
define("plupload", ['./moxie'], extract);
} else if (typeof module === "object" && module.exports) {
module.exports = extract(require('./moxie'));
} else {
global.plupload = extract(global.moxie);
}
}(this || window, function(moxie) {
/**
* Compiled inline version. (Library mode)
*/
/*jshint smarttabs:true, undef:true, latedef:true, curly:true, bitwise:true, camelcase:true */
/*globals $code */
(function(exports, undefined) {
"use strict";
var modules = {};
function require(ids, callback) {
var module, defs = [];
for (var i = 0; i < ids.length; ++i) {
module = modules[ids[i]] || resolve(ids[i]);
if (!module) {
throw 'module definition dependecy not found: ' + ids[i];
}
defs.push(module);
}
callback.apply(null, defs);
}
function define(id, dependencies, definition) {
if (typeof id !== 'string') {
throw 'invalid module definition, module id must be defined and be a string';
}
if (dependencies === undefined) {
throw 'invalid module definition, dependencies must be specified';
}
if (definition === undefined) {
throw 'invalid module definition, definition function must be specified';
}
require(dependencies, function() {
modules[id] = definition.apply(null, arguments);
});
}
function defined(id) {
return !!modules[id];
}
function resolve(id) {
var target = exports;
var fragments = id.split(/[.\/]/);
for (var fi = 0; fi < fragments.length; ++fi) {
if (!target[fragments[fi]]) {
return;
}
target = target[fragments[fi]];
}
return target;
}
function expose(ids) {
for (var i = 0; i < ids.length; i++) {
var target = exports;
var id = ids[i];
var fragments = id.split(/[.\/]/);
for (var fi = 0; fi < fragments.length - 1; ++fi) {
if (target[fragments[fi]] === undefined) {
target[fragments[fi]] = {};
}
target = target[fragments[fi]];
}
target[fragments[fragments.length - 1]] = modules[id];
}
}
// Included from: src/plupload.js
/**
* plupload.js
*
* Copyright 2017, Ephox
* Released under AGPLv3 License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*/
/**
Namespace for all Plupload related classes, methods and properties.
@class plupload
@public
@static
*/
define('plupload', [], function() {
var o = moxie;
var u = o.core.utils;
// redifine event dispatcher for Flash/Silverlight runtimes
u.Env.global_event_dispatcher = 'plupload.EventTarget.instance.dispatchEvent';
return {
/**
* Plupload version will be replaced on build.
*
* @property VERSION
* @static
* @final
*/
VERSION: '3.1.2',
/**
* The state of the queue before it has started and after it has finished
*
* @property STOPPED
* @static
* @final
*/
STOPPED: 1,
/**
* Upload process is running
*
* @property STARTED
* @static
* @final
*/
STARTED: 2,
/**
File is queued for upload
@property QUEUED
@static
@final
*/
QUEUED: 1,
/**
File is being uploaded
@property UPLOADING
@static
@final
*/
UPLOADING: 2,
/**
File has failed to be uploaded
@property FAILED
@static
@final
*/
FAILED: 4,
/**
File has been uploaded successfully
@property DONE
@static
@final
*/
DONE: 5,
// Error constants used by the Error event
/**
* Generic error for example if an exception is thrown inside Silverlight.
*
* @property GENERIC_ERROR
* @static
* @final
*/
GENERIC_ERROR: -100,
/**
* HTTP transport error. For example if the server produces a HTTP status other than 200.
*
* @property HTTP_ERROR
* @static
* @final
*/
HTTP_ERROR: -200,
/**
* Generic I/O error. For example if it wasn't possible to open the file stream on local machine.
*
* @property IO_ERROR
* @static
* @final
*/
IO_ERROR: -300,
/**
* @property SECURITY_ERROR
* @static
* @final
*/
SECURITY_ERROR: -400,
/**
* Initialization error. Will be triggered if no runtime was initialized.
*
* @property INIT_ERROR
* @static
* @final
*/
INIT_ERROR: -500,
/**
* File size error. If the user selects a file that is too large it will be blocked and an error of this type will be triggered.
*
* @property FILE_SIZE_ERROR
* @static
* @final
*/
FILE_SIZE_ERROR: -600,
/**
* File extension error. If the user selects a file that isn't valid according to the filters setting.
*
* @property FILE_EXTENSION_ERROR
* @static
* @final
*/
FILE_EXTENSION_ERROR: -601,
/**
* Duplicate file error. If prevent_duplicates is set to true and user selects the same file again.
*
* @property FILE_DUPLICATE_ERROR
* @static
* @final
*/
FILE_DUPLICATE_ERROR: -602,
/**
* Runtime will try to detect if image is proper one. Otherwise will throw this error.
*
* @property IMAGE_FORMAT_ERROR
* @static
* @final
*/
IMAGE_FORMAT_ERROR: -700,
/**
* While working on files runtime may run out of memory and will throw this error.
*
* @since 2.1.2
* @property MEMORY_ERROR
* @static
* @final
*/
MEMORY_ERROR: -701,
/**
* Each runtime has an upper limit on a dimension of the image it can handle. If bigger, will throw this error.
*
* @property IMAGE_DIMENSIONS_ERROR
* @static
* @final
*/
IMAGE_DIMENSIONS_ERROR: -702,
/**
Invalid option error. Will be thrown if user tries to alter the option that cannot be changed without
uploader reinitialisation.
@property OPTION_ERROR
@static
@final
*/
OPTION_ERROR: -800,
/**
* Expose whole moxie (#1469).
*
* @property moxie
* @type Object
* @final
*/
moxie: o,
/**
* In some cases sniffing is the only way around :(
*/
ua: u.Env,
/**
* Gets the true type of the built-in object (better version of typeof).
* @credits Angus Croll (http://javascriptweblog.wordpress.com/)
*
* @method typeOf
* @static
* @param {Object} o Object to check.
* @return {String} Object [[Class]]
*/
typeOf: u.Basic.typeOf,
clone: u.Basic.clone,
inherit: u.Basic.inherit,
/**
* Extends the specified object with another object.
*
* @method extend
* @static
* @param {Object} target Object to extend.
* @param {Object..} obj Multiple objects to extend with.
* @return {Object} Same as target, the extended object.
*/
extend: u.Basic.extend,
extendImmutable: u.Basic.extendImmutable,
/**
Extends the specified object with another object(s), but only if the property exists in the target.
@method extendIf
@static
@param {Object} target Object to extend.
@param {Object} [obj]* Multiple objects to extend with.
@return {Object} Same as target, the extended object.
*/
extendIf: u.Basic.extendIf,
/**
Recieve an array of functions (usually async) to call in sequence, each function
receives a callback as first argument that it should call, when it completes. Finally,
after everything is complete, main callback is called. Passing truthy value to the
callback as a first argument will interrupt the sequence and invoke main callback
immediately.
@method inSeries
@static
@param {Array} queue Array of functions to call in sequence
@param {Function} cb Main callback that is called in the end, or in case of error
*/
inSeries: u.Basic.inSeries,
/**
Recieve an array of functions (usually async) to call in parallel, each function
receives a callback as first argument that it should call, when it completes. After
everything is complete, main callback is called. Passing truthy value to the
callback as a first argument will interrupt the process and invoke main callback
immediately.
@method inParallel
@static
@param {Array} queue Array of functions to call in sequence
@param {Function} cb Main callback that is called in the end, or in case of erro
*/
inParallel: u.Basic.inParallel,
/**
* Generates an unique ID. This is 99.99% unique since it takes the current time and 5 random numbers.
* The only way a user would be able to get the same ID is if the two persons at the same exact millisecond manages
* to get 5 the same random numbers between 0-65535 it also uses a counter so each call will be guaranteed to be page unique.
* It's more probable for the earth to be hit with an asteriod. You can also if you want to be 100% sure set the plupload.guidPrefix property
* to an user unique key.
*
* @method guid
* @static
* @return {String} Virtually unique id.
*/
guid: u.Basic.guid,
/**
* Get array of DOM Elements by their ids.
*
* @method get
* @param {String} id Identifier of the DOM Element
* @return {Array}
*/
getAll: function get(ids) {
var els = [],
el;
if (u.Basic.typeOf(ids) !== 'array') {
ids = [ids];
}
var i = ids.length;
while (i--) {
el = u.Dom.get(ids[i]);
if (el) {
els.push(el);
}
}
return els.length ? els : null;
},
/**
Get DOM element by id
@method get
@param {String} id Identifier of the DOM Element
@return {Node}
*/
get: u.Dom.get,
/**
* Executes the callback function for each item in array/object. If you return false in the
* callback it will break the loop.
*
* @method each
* @static
* @param {Object} obj Object to iterate.
* @param {function} callback Callback function to execute for each item.
*/
each: u.Basic.each,
/**
* Returns the absolute x, y position of an Element. The position will be returned in a object with x, y fields.
*
* @method getPos
* @static
* @param {Element} node HTML element or element id to get x, y position from.
* @param {Element} root Optional root element to stop calculations at.
* @return {object} Absolute position of the specified element object with x, y fields.
*/
getPos: u.Dom.getPos,
/**
* Returns the size of the specified node in pixels.
*
* @method getSize
* @static
* @param {Node} node Node to get the size of.
* @return {Object} Object with a w and h property.
*/
getSize: u.Dom.getSize,
/**
* Encodes the specified string.
*
* @method xmlEncode
* @static
* @param {String} s String to encode.
* @return {String} Encoded string.
*/
xmlEncode: function(str) {
var xmlEncodeChars = {
'<': 'lt',
'>': 'gt',
'&': 'amp',
'"': 'quot',
'\'': '#39'
},
xmlEncodeRegExp = /[<>&\"\']/g;
return str ? ('' + str).replace(xmlEncodeRegExp, function(chr) {
return xmlEncodeChars[chr] ? '&' + xmlEncodeChars[chr] + ';' : chr;
}) : str;
},
/**
* Forces anything into an array.
*
* @method toArray
* @static
* @param {Object} obj Object with length field.
* @return {Array} Array object containing all items.
*/
toArray: u.Basic.toArray,
/**
* Find an element in array and return its index if present, otherwise return -1.
*
* @method inArray
* @static
* @param {mixed} needle Element to find
* @param {Array} array
* @return {Int} Index of the element, or -1 if not found
*/
inArray: u.Basic.inArray,
/**
* Extends the language pack object with new items.
*
* @method addI18n
* @static
* @param {Object} pack Language pack items to add.
* @return {Object} Extended language pack object.
*/
addI18n: o.core.I18n.addI18n,
/**
* Translates the specified string by checking for the english string in the language pack lookup.
*
* @method translate
* @static
* @param {String} str String to look for.
* @return {String} Translated string or the input string if it wasn't found.
*/
translate: o.core.I18n.translate,
/**
* Pseudo sprintf implementation - simple way to replace tokens with specified values.
*
* @param {String} str String with tokens
* @return {String} String with replaced tokens
*/
sprintf: u.Basic.sprintf,
/**
* Checks if object is empty.
*
* @method isEmptyObj
* @static
* @param {Object} obj Object to check.
* @return {Boolean}
*/
isEmptyObj: u.Basic.isEmptyObj,
/**
* Checks if specified DOM element has specified class.
*
* @method hasClass
* @static
* @param {Object} obj DOM element like object to add handler to.
* @param {String} name Class name
*/
hasClass: u.Dom.hasClass,
/**
* Adds specified className to specified DOM element.
*
* @method addClass
* @static
* @param {Object} obj DOM element like object to add handler to.
* @param {String} name Class name
*/
addClass: u.Dom.addClass,
/**
* Removes specified className from specified DOM element.
*
* @method removeClass
* @static
* @param {Object} obj DOM element like object to add handler to.
* @param {String} name Class name
*/
removeClass: u.Dom.removeClass,
/**
* Returns a given computed style of a DOM element.
*
* @method getStyle
* @static
* @param {Object} obj DOM element like object.
* @param {String} name Style you want to get from the DOM element
*/
getStyle: u.Dom.getStyle,
/**
* Adds an event handler to the specified object and store reference to the handler
* in objects internal Plupload registry (@see removeEvent).
*
* @method addEvent
* @static
* @param {Object} obj DOM element like object to add handler to.
* @param {String} name Name to add event listener to.
* @param {Function} callback Function to call when event occurs.
* @param {String} (optional) key that might be used to add specifity to the event record.
*/
addEvent: u.Events.addEvent,
/**
* Remove event handler from the specified object. If third argument (callback)
* is not specified remove all events with the specified name.
*
* @method removeEvent
* @static
* @param {Object} obj DOM element to remove event listener(s) from.
* @param {String} name Name of event listener to remove.
* @param {Function|String} (optional) might be a callback or unique key to match.
*/
removeEvent: u.Events.removeEvent,
/**
* Remove all kind of events from the specified object
*
* @method removeAllEvents
* @static
* @param {Object} obj DOM element to remove event listeners from.
* @param {String} (optional) unique key to match, when removing events.
*/
removeAllEvents: u.Events.removeAllEvents,
/**
* Cleans the specified name from national characters (diacritics). The result will be a name with only a-z, 0-9 and _.
*
* @method cleanName
* @static
* @param {String} s String to clean up.
* @return {String} Cleaned string.
*/
cleanName: function(name) {
var i, lookup;
// Replace diacritics
lookup = [
/[\300-\306]/g, 'A', /[\340-\346]/g, 'a',
/\307/g, 'C', /\347/g, 'c',
/[\310-\313]/g, 'E', /[\350-\353]/g, 'e',
/[\314-\317]/g, 'I', /[\354-\357]/g, 'i',
/\321/g, 'N', /\361/g, 'n',
/[\322-\330]/g, 'O', /[\362-\370]/g, 'o',
/[\331-\334]/g, 'U', /[\371-\374]/g, 'u'
];
for (i = 0; i < lookup.length; i += 2) {
name = name.replace(lookup[i], lookup[i + 1]);
}
// Replace whitespace
name = name.replace(/\s+/g, '_');
// Remove anything else
name = name.replace(/[^a-z0-9_\-\.]+/gi, '');
return name;
},
/**
* Builds a full url out of a base URL and an object with items to append as query string items.
*
* @method buildUrl
* @static
* @param {String} url Base URL to append query string items to.
* @param {Object} items Name/value object to serialize as a querystring.
* @return {String} String with url + serialized query string items.
*/
buildUrl: function(url, items) {
var query = '';
u.Basic.each(items, function(value, name) {
query += (query ? '&' : '') + encodeURIComponent(name) + '=' + encodeURIComponent(value);
});
if (query) {
url += (url.indexOf('?') > 0 ? '&' : '?') + query;
}
return url;
},
/**
* Formats the specified number as a size string for example 1024 becomes 1 KB.
*
* @method formatSize
* @static
* @param {Number} size Size to format as string.
* @return {String} Formatted size string.
*/
formatSize: function(size) {
var self = this;
function round(num, precision) {
return Math.round(num * Math.pow(10, precision)) / Math.pow(10, precision);
}
size = parseInt(size, 10);
if (isNaN(size)) {
return self.translate('N/A');
}
var boundary = Math.pow(1024, 4);
// TB
if (size > boundary) {
return round(size / boundary, 1) + " " + self.translate('tb');
}
// GB
if (size > (boundary /= 1024)) {
return round(size / boundary, 1) + " " + self.translate('gb');
}
// MB
if (size > (boundary /= 1024)) {
return round(size / boundary, 1) + " " + self.translate('mb');
}
// KB
if (size > 1024) {
return Math.round(size / 1024) + " " + self.translate('kb');
}
return size + " " + self.translate('b');
},
/**
* @private
*/
mimes2extList: moxie.core.utils.Mime.mimes2extList,
/**
Resolve url - among other things will turn relative url to absolute
@method resolveUrl
@static
@param {String|Object} url Either absolute or relative, or a result of parseUrl call
@return {String} Resolved, absolute url
*/
resolveUrl: u.Url.resolveUrl,
/**
* Parses the specified size string into a byte value. For example 10kb becomes 10240.
*
* @method parseSize
* @static
* @param {String|Number} size String to parse or number to just pass through.
* @return {Number} Size in bytes.
*/
parseSize: u.Basic.parseSizeStr,
delay: u.Basic.delay,
/**
Parent object for all event dispatching components and objects
@class plupload.EventTarget
@private
@constructor
*/
EventTarget: moxie.core.EventTarget,
/**
Common set of methods and properties for every runtime instance
@class plupload.Runtime
@private
@param {Object} options
@param {String} type Sanitized name of the runtime
@param {Object} [caps] Set of capabilities that differentiate specified runtime
@param {Object} [modeCaps] Set of capabilities that do require specific operational mode
@param {String} [preferredMode='browser'] Preferred operational mode to choose if no required capabilities were requested
*/
Runtime: moxie.runtime.Runtime,
/**
Provides a convenient way to create cross-browser file-picker. Generates file selection dialog on click,
converts selected files to _File_ objects, to be used in conjunction with _Image_, preloaded in memory
with _FileReader_ or uploaded to a server through _XMLHttpRequest_.
@class plupload.FileInput
@private
@constructor
@extends EventTarget
@uses RuntimeClient
@param {Object|String|DOMElement} options If options is string or node, argument is considered as _browse\_button_.
@param {String|DOMElement} options.browse_button DOM Element to turn into file picker.
@param {Array} [options.accept] Array of mime types to accept. By default accepts all.
@param {String} [options.file='file'] Name of the file field (not the filename).
@param {Boolean} [options.multiple=false] Enable selection of multiple files.
@param {Boolean} [options.directory=false] Turn file input into the folder input (cannot be both at the same time).
@param {String|DOMElement} [options.container] DOM Element to use as a container for file-picker. Defaults to parentNode
for _browse\_button_.
@param {Object|String} [options.required_caps] Set of required capabilities, that chosen runtime must support.
*/
FileInput: moxie.file.FileInput,
/**
Utility for preloading o.Blob/o.File objects in memory. By design closely follows [W3C FileReader](http://www.w3.org/TR/FileAPI/#dfn-filereader)
interface. Where possible uses native FileReader, where - not falls back to shims.
@class plupload.FileReader
@private
@constructor
@extends EventTarget
@uses RuntimeClient
*/
FileReader: moxie.file.FileReader
};
});
// Included from: src/core/Collection.js
/**
* Collection.js
*
* Copyright 2017, Ephox
* Released under AGPLv3 License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*/
/**
Helper collection class - in a way a mix of object and array
@contsructor
@class plupload.core.Collection
@private
*/
define('plupload/core/Collection', [
'plupload'
], function(Basic) {
var Collection = function() {
var _registry = {};
var _length = 0;
var _last;
plupload.extend(this, {
count: function() {
return _length;
},
hasKey: function(key) {
return _registry.hasOwnProperty(key)
},
get: function(key) {
return _registry[key];
},
first: function() {
for (var key in _registry) {
return _registry[key];
}
},
last: function() {
return _last;
},
toObject: function() {
return _registry;
},
add: function(key, obj) {
var self = this;
if (typeof(key) === 'object' && !obj) {
return plupload.each(key, function(obj, key) {
self.add(key, obj);
});
}
if (_registry.hasOwnProperty(key)) {
return self.update.apply(self, arguments);
}
_registry[key] = _last = obj;
_length++;
},
remove: function(key) {
if (this.hasKey(key)) {
var last = _registry[key];
delete _registry[key];
_length--;
// renew ref to the last added item if necessary
if (_last === last) {
_last = findLast();
}
}
},
extract: function(key) {
var item = this.get(key);
this.remove(key);
return item;
},
shift: function() {
var self = this,
first, key;
for (key in _registry) {
first = _registry[key];
self.remove(key);
return first;
}
},
update: function(key, obj) {
_registry[key] = obj;
},
each: function(cb) {
plupload.each(_registry, cb);
},
combineWith: function() {
var newCol = new Collection();
newCol.add(_registry);
plupload.each(arguments, function(col) {
if (col instanceof Collection) {
newCol.add(col.toObject());
}
});
return newCol;
},
clear: function() {
_registry = {};
_last = null;
_length = 0;
}
});
function findLast() {
var key;
for (key in _registry) {}
return _registry[key];
}
};
return Collection;
});
// Included from: src/core/ArrCollection.js
/**
* ArrCollection.js
*
* Copyright 2017, Ephox
* Released under AGPLv3 License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*/
/**
@contsructor
@class plupload.core.ArrCollection
@private
*/
define('plupload/core/ArrCollection', [
'plupload'
], function(plupload) {
var ArrCollection = function() {
var _registry = [];
plupload.extend(this, {
count: function() {
return _registry.length;
},
hasKey: function(key) {
return this.getIdx(key) > -1;
},
get: function(key) {
var idx = this.getIdx(key);
return idx > -1 ? _registry[idx] : null;
},
getIdx: function(key) {
for (var i = 0, length = _registry.length; i < length; i++) {
if (_registry[i].uid === key) {
return i;
}
}
return -1;
},
getByIdx: function(idx) {
return _registry[idx]
},
first: function() {
return _registry[0];
},
last: function() {
return _registry[_registry.length - 1];
},
add: function(obj) {
obj = arguments[1] || obj; // make it compatible with Collection.add()
var idx = this.getIdx(obj.uid);
if (idx > -1) {
_registry[idx] = obj;
return idx;
}
_registry.push(obj);
return _registry.length - 1;
},
remove: function(key) {
return !!this.extract(key);
},
splice: function(start, length) {
start = plupload.typeOf(start) === 'undefinded' ? 0 : Math.max(start, 0);
length = plupload.typeOf(length) !== 'undefinded' && start + length < _registry.length ? length : _registry.length - start;
return _registry.splice(start, length);
},
extract: function(key) {
var idx = this.getIdx(key);
if (idx > -1) {
return _registry.splice(idx, 1);
}
return null;
},
shift: function() {
return _registry.shift();
},
update: function(key, obj) {
var idx = this.getIdx(key);
if (idx > -1) {
_registry[idx] = obj;
return true;
}
return false;
},
each: function(cb) {
plupload.each(_registry, cb);
},
combineWith: function() {
return Array.prototype.concat.apply(this.toArray(), arguments);
},
sort: function(cb) {
_registry.sort(cb || function(a, b) {
return a.priority - b.priority;
});
},
clear: function() {
_registry = [];
},
toObject: function() {
var obj = {};
for (var i = 0, length = _registry.length; i < length; i++) {
obj[_registry[i].uid] = _registry[i];
}
return obj;
},
toArray: function() {
return Array.prototype.slice.call(_registry);
}
});
};
return ArrCollection;
});
// Included from: src/core/Optionable.js
/**
* Optionable.js
*
* Copyright 2017, Ephox
* Released under AGPLv3 License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*/
/**
@contsructor
@class plupload.core.Optionable
@private
@since 3.0
*/
define('plupload/core/Optionable', [
'plupload'
], function(plupload) {
var EventTarget = moxie.core.EventTarget;
var dispatches = [
/**
* Dispatched when option is being changed.
*
* @event OptionChanged
* @param {Object} event
* @param {String} name Name of the option being changed
* @param {Mixed} value
* @param {Mixed} oldValue
*/
'OptionChanged'
];
return (function(Parent) {
/**
* @class Optionable
* @constructor
* @extends EventTarget
*/
function Optionable() {
Parent.apply(this, arguments);
this._options = {};
}
plupload.inherit(Optionable, Parent);
plupload.extend(Optionable.prototype, {
/**
* Set the value for the specified option(s).
*
* @method setOption
* @since 2.1
* @param {String|Object} option Name of the option to change or the set of key/value pairs
* @param {Mixed} [value] Value for the option (is ignored, if first argument is object)
* @param {Boolean} [mustBeDefined] if truthy, any option that is not in defaults will be ignored
*/
setOption: function(option, value, mustBeDefined) {
var self = this;
var oldValue;
if (typeof(option) === 'object') {
mustBeDefined = value;
plupload.each(option, function(value, option) {
self.setOption(option, value, mustBeDefined);
});
return;
}
if (mustBeDefined && !self._options.hasOwnProperty(option)) {
return;
}
oldValue = plupload.clone(self._options[option]);
//! basically if an option is of type object extend it rather than replace
if (plupload.typeOf(value) === 'object' && plupload.typeOf(self._options[option]) === 'object') {
// having some options as objects was a bad idea, prefixes is the way
plupload.extend(self._options[option], value);
} else {
self._options[option] = value;
}
self.trigger('OptionChanged', option, value, oldValue);
},
/**
* Get the value for the specified option or the whole configuration, if not specified.
*
* @method getOption
* @since 2.1
* @param {String} [option] Name of the option to get
* @return {Mixed} Value for the option or the whole set
*/
getOption: function(option) {
if (!option) {
return this._options;
}
var value = this._options[option];
if (plupload.inArray(plupload.typeOf(value), ['array', 'object']) > -1) {
return plupload.extendImmutable({}, value);
} else {
return value;
}
},
/**
* Set many options as once.
*
* @method setOptions
* @param {Object} options
* @param {Boolean} [mustBeDefined] if truthy, any option that is not in defaults will be ignored
*/
setOptions: function(options, mustBeDefined) {
if (typeof(options) !== 'object') {
return;
}
this.setOption(options, mustBeDefined);
},
/**
Gets all options.
@method getOptions
@return {Object}
*/
getOptions: function() {
return this.getOption();
}
});
return Optionable;
}(EventTarget));
});
// Included from: src/core/Queueable.js
/**
* Queueable.js
*
* Copyright 2017, Ephox
* Released under AGPLv3 License.se.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*/
/**
Every queue item must have properties, implement methods and fire events defined in this class
@contsructor
@class plupload.core.Queueable
@private
@decorator
@extends EventTarget
*/
define('plupload/core/Queueable', [
'plupload',
'plupload/core/Optionable'
], function(plupload, Optionable) {
var dispatches = [
/**
* Dispatched every time the state of queue changes
*
* @event statechanged
* @param {Object} event
* @param {Number} state New state
* @param {Number} prevState Previous state
*/
'statechanged',
/**
* Dispatched when the item is put on pending list
*
* @event queued
* @param {Object} event
*/
'queued',
/**
* Dispatched as soon as activity starts
*
* @event started
* @param {Object} event
*/
'started',
'paused',
'resumed',
'stopped',
/**
* Dispatched as the activity progresses
*
* @event
* @param {Object} event
* @param {Number} event.percent
* @param {Number} [event.processed]
* @param {Number} [event.total]
*/
'progress',
'failed',
'done',
'processed',
'destroy'
];
return (function(Parent) {
function Queueable() {
Parent.apply(this, arguments);
/**
Unique identifier
@property uid
@type {String}
*/
this.uid = plupload.guid();
this.state = Queueable.IDLE;
this.processed = 0;
this.total = 0;
this.percent = 0;
this.retries = 0;
/**
* Can be 0-Infinity - item with higher priority will have well... higher priority
* @property [priority=0]
* @type {Number}
*/
this.priority = 0;
this.startedTimestamp = 0;
/**
* Set when item becomes Queueable.DONE or Queueable.FAILED.
* Used to calculate proper processedPerSec for the queue stats.
* @property processedTimestamp
* @type {Number}
*/
this.processedTimestamp = 0;
if (MXI_DEBUG) {
this.bind('StateChanged', function(e, state, oldState) {
var self = this;
var stateToString = function(code) {
switch (code) {
case Queueable.IDLE:
return 'IDLE';
case Queueable.PROCESSING:
return 'PROCESSING';
case Queueable.PAUSED:
return 'PAUSED';
case Queueable.RESUMED:
return 'RESUMED';
case Queueable.DONE:
return 'DONE';
case Queueable.FAILED:
return 'FAILED';
case Queueable.DESTROYED:
return 'DESTROYED';
}
};
var indent = function() {
switch (self.ctorName) {
case 'File':
return "\t".repeat(2);
case 'QueueUpload':
case 'QueueResize':
return "\t";
case 'FileUploader':
return "\t".repeat(3);
case 'ChunkUploader':
return "\t".repeat(4);
default:
return "\t";
}
};
plupload.ua.log("StateChanged:" + indent() + self.ctorName + '::' + self.uid + ' (' + stateToString(oldState) + ' to ' + stateToString(state) + ')');
}, 999);
}
}
Queueable.IDLE = 1;
Queueable.PROCESSING = 2;
Queueable.PAUSED = 6;
Queueable.RESUMED = 7;
Queueable.DONE = 5;
Queueable.FAILED = 4;
Queueable.DESTROYED = 8;
plupload.inherit(Queueable, Parent);
plupload.extend(Queueable.prototype, {
start: function() {
var prevState = this.state;
if (this.state === Queueable.PROCESSING) {
return false;
}
if (!this.startedTimestamp) {
this.startedTimestamp = +new Date();
}
this.state = Queueable.PROCESSING;
this.trigger('statechanged', this.state, prevState);
this.trigger('started');
return true;
},
pause: function() {
var prevState = this.state;
if (plupload.inArray(this.state, [Queueable.IDLE, Queueable.RESUMED, Queueable.PROCESSING]) === -1) {
return false;
}
this.processed = this.percent = 0; // by default reset all progress
this.loaded = this.processed; // for backward compatibility
this.state = Queueable.PAUSED;
this.trigger('statechanged', this.state, prevState);
this.trigger('paused');
return true;
},
resume: function() {
var prevState = this.state;
if (this.state !== Queueable.PAUSED && this.state !== Queueable.RESUMED) {
return false;
}
this.state = Queueable.RESUMED;
this.trigger('statechanged', this.state, prevState);
this.trigger('resumed');
return true;
},
stop: function() {
var prevState = this.state;
if (this.state === Queueable.IDLE) {
return false;
}
this.processed = this.percent = 0;
this.loaded = this.processed; // for backward compatibility
this.startedTimestamp = 0;
this.state = Queueable.IDLE;
this.trigger('statechanged', this.state, prevState);
this.trigger('stopped');
return true;
},
done: function(result) {
var prevState = this.state;
if (this.state === Queueable.DONE) {
return false;
}
this.processed = this.total;
this.loaded = this.processed; // for backward compatibility
this.percent = 100;
this.processedTimestamp = +new Date();
this.state = Queueable.DONE;
this.trigger('statechanged', this.state, prevState);
this.trigger('done', result);
this.trigger('processed');
return true;
},
failed: function(result) {
var prevState = this.state;
if (this.state === Queueable.FAILED) {
return false;
}
this.processed = this.percent = 0; // reset the progress
this.loaded = this.processed; // for backward compatibility
this.processedTimestamp = +new Date();
this.state = Queueable.FAILED;
this.trigger('statechanged', this.state, prevState);
this.trigger('failed', result);
this.trigger('processed');
return true;
},
progress: function(processed, total) {
if (total) {
this.total = total; // is this even required?
}
this.processed = Math.min(processed, this.total);
this.loaded = this.processed; // for backward compatibility
this.percent = Math.ceil(this.processed / this.total * 100);
this.trigger({
type: 'progress',
loaded: this.processed,
total: this.total
});
},
destroy: function() {
var prevState = this.state;
if (this.state === Queueable.DESTROYED) {
return false; // already destroyed
}
this.state = Queueable.DESTROYED;
this.trigger('statechanged', this.state, prevState);
this.trigger('destroy');
this.unbindAll();
return true;
}
});
return Queueable;
}(Optionable));
});
// Included from: src/core/Stats.js
/**
@class plupload.core.Stats
@constructor
@private
*/
define('plupload/core/Stats', [], function() {
return function() {
var self = this;
/**
* Total queue file size.
*
* @property size
* @deprecated use total
* @type Number
*/
self.size = 0;
/**
* Total size of the queue in units.
*
* @property total
* @since 3.0
* @type Number
*/
self.total = 0;
/**
* Total bytes uploaded.
*
* @property loaded
* @type Number
*/
self.loaded = 0;
/**
* Number of files uploaded successfully.
*
* @property uploaded
* @deprecated use done
* @type Number
*/
self.uploaded = 0;
/**
* Number of items processed successfully.
*
* @property done
* @since 3.0
* @type Number
*/
self.done = 0;
/**
* Number of failed items.
*
* @property failed
* @type Number
*/
self.failed = 0;
/**
* Number of items yet to be processed.
*
* @property queued
* @type Number
*/
self.queued = 0;
/**
* Number of items currently paused.
*
* @property paused
* @type Number
*/
self.paused = 0;
/**
* Number of items being processed.
*
* @property processing
* @type Number
*/
self.processing = 0;
/**
* Number of items being paused.
*
* @property paused
* @type Number
*/
self.paused = 0;
/**
* Percent of processed units.
*
* @property percent
* @type Number
*/
self.percent = 0;
/**
* Bytes processed per second.
*
* @property bytesPerSec
* @deprecated use processedPerSec
* @type Number
*/
self.bytesPerSec = 0;
/**
* Units processed per second.
*
* @property processedPerSec
* @since 3.0
* @type Number
*/
self.processedPerSec = 0;
/**
* Resets the progress to its initial values.
*
* @method reset
*/
self.reset = function() {
self.size = // deprecated
self.total =
self.loaded = // deprecated
self.processed =
self.uploaded = // deprecated
self.done =
self.failed =
self.queued =
self.processing =
self.paused =
self.percent =
self.bytesPerSec = // deprecated
self.processedPerSec = 0;
};
};
});
// Included from: src/core/Queue.js
/**
* Queue.js
*
* Copyright 2017, Ephox
* Released under AGPLv3 License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*/
/**
@contsructor
@class plupload.core.Queue
@private
*/
define('plupload/core/Queue', [
'plupload',
'plupload/core/ArrCollection',
'plupload/core/Queueable',
'plupload/core/Stats'
], function(plupload, ArrCollection, Queueable, Stats) {
var dispatches = [
/**
* Dispatched as soon as activity starts
*
* @event started
* @param {Object} event
*/
'Started',
/**
* Dispatched as activity progresses
*
* @event progress
* @param {Object} event
* @param {Number} processed
* @param {Number} total
* @param {plupload.core.Stats} stats
*/
'Progress',
/**
* Dispatched when activity is paused
*
* @event paused
* @param {Object} event
*/
'Paused',
/**
* Dispatched when there's no more items in processing
*
* @event done
* @param {Object} event
*/
'Done',
/**
* Dispatched as soon as activity ends
*
* @event stopped
* @param {Object} event
*/
'Stopped',
/**
* Dispatched when queue is destroyed
*
* @event destroy
* @param {Object} event
*/
'Destroy'
];
/**
* @class Queue
* @constructor
* @extends EventTarget
*/
return (function(Parent) {
plupload.inherit(Queue, Parent);
function Queue(options) {
Parent.apply(this, arguments);
/**
@property _queue
@type {Collection}
@private
*/
this._queue = new ArrCollection();
/**
@property stats
@type {Stats}
@readOnly
*/
this.stats = new Stats();
this._options = plupload.extend({}, this._options, {
max_slots: 1,
max_retries: 0,
auto_start: false,
finish_active: false
}, options);
}
plupload.extend(Queue.prototype, {
/**
* Returns number of items in the queue
*
* @method count
* @returns {Number}
*/
count: function() {
return this._queue.count();
},
/**
* Start the queue
*
* @method start
*/
start: function() {
if (!Queue.parent.start.call(this)) {
return false;
}
return processNext.call(this);
},
pause: function() {
if (!Queue.parent.pause.call(this)) {
return false;
}
this.forEachItem(function(item) {
item.pause();
});
},
/**
* Stop the queue. If `finish_active=true` the queue will wait until active items are done, before
* stopping.
*
* @method stop
*/
stop: function() {
if (!Queue.parent.stop.call(this) || this.getOption('finish_active')) {
return false;
}
if (this.isActive()) {
this.forEachItem(function(item) {
item.stop();
});
}
},
forEachItem: function(cb) {
this._queue.each(cb);
},
getItem: function(uid) {
return this._queue.get(uid);
},
/**
* Add instance of Queueable to the queue. If `auto_start=true` queue will start as well.
*
* @method addItem
* @param {Queueable} item
*/
addItem: function(item) {
var self = this;
item.bind('Started', function() {
if (self.calcStats()) {
plupload.delay.call(self, processNext);
}
});
item.bind('Resumed',function() {
self.start();
});
item.bind('Paused', function() {
if (self.calcStats()) {
plupload.delay.call(self, function() {
if (!processNext.call(self) && !self.stats.processing) {
self.pause();
}
});
}
});
item.bind('Processed Stopped', function() {
if (self.calcStats()) {
plupload.delay.call(self, function() {
if (!processNext.call(self) && !this.isStopped() && !this.isActive()) {
self.stop();
}
});
}
});
item.bind('Progress', function() {
if (self.calcStats()) {
self.trigger('Progress', self.stats.processed, self.stats.total, self.stats);
}
});
item.bind('Failed', function() {
if (self.getOption('max_retries') && this.retries < self.getOption('max_retries')) {
this.stop();
this.retries++;
}
});
this._queue.add(item.uid, item);
this.calcStats();
item.trigger('Queued');
if (self.getOption('auto_start') || self.state === Queueable.PAUSED) {
plupload.delay.call(this, this.start);
}
},
/**
* Extracts item from the queue by its uid and returns it.
*
* @method extractItem
* @param {String} uid
* @return {Queueable} Item that was removed
*/
extractItem: function(uid) {
var item = this._queue.get(uid);
if (item) {
this.stopItem(item.uid);
this._queue.remove(uid);
this.calcStats();
}
return item;
},
/**
* Removes item from the queue and destroys it
*
* @method removeItem
* @param {String} uid
* @returns {Boolean} Result of the operation
*/
removeItem: function(uid) {
var item = this.extractItem(uid);
if (item) {
item.destroy();
return true;
}
return false;
},
stopItem: function(uid) {
var item = this._queue.get(uid);
if (item) {
return item.stop();
} else {
return false;
}
},
pauseItem: function(uid) {
var item = this._queue.get(uid);
if (item) {
return item.pause();
} else {
return false;
}
},
resumeItem: function(uid) {
var item = this._queue.get(uid);
if (item) {
plupload.delay.call(this, function() {
this.start(); // start() will know if it needs to restart the queue
});
return item.resume();
} else {
return false;
}
},
splice: function(start, length) {
return this._queue.splice(start, length);
},
isActive: function() {
return this.stats && (this.stats.processing || this.stats.paused);
},
isStopped: function() {
return this.state === Queueable.IDLE || this.state === Queueable.DESTROYED;
},
countSpareSlots: function() {
return Math.max(this.getOption('max_slots') - this.stats.processing, 0);
},
toArray: function() {
return this._queue.toArray();
},
clear: function() {
var self = this;
if (self.state !== Queueable.IDLE) {
// stop the active queue first
self.bindOnce('Stopped', function() {
self.clear();
});
return self.stop();
} else {
self._queue.clear();
self.stats.reset();
}
},
calcStats: function() {
var self = this;
var stats = self.stats;
var processed = 0;
var processedDuringThisSession = 0;
if (!stats) {
return false; // maybe queue is destroyed
}
stats.reset();
self.forEachItem(function(item) {
switch (item.state) {
case Queueable.DONE:
stats.done++;
stats.uploaded = stats.done; // for backward compatibility
break;
case Queueable.FAILED:
stats.failed++;
break;
case Queueable.PROCESSING:
stats.processing++;
break;
case Queueable.PAUSED:
stats.paused++;
break;
default:
stats.queued++;
}
processed += item.processed;
if (!item.processedTimestamp || item.processedTimestamp > self.startedTimestamp) {
processedDuringThisSession += processed;
}
stats.processedPerSec = Math.ceil(processedDuringThisSession / ((+new Date() - self.startedTimestamp || 1) / 1000.0));
stats.processed = processed;
stats.total += item.total;
if (stats.total) {
stats.percent = Math.ceil(stats.processed / stats.total * 100);
}
});
// enable properties inherited from Queueable
/* TODO: this is good but it currently conflicts with deprecated total property in Uploader
self.processed = stats.processed;
self.total = stats.total;
*/
self.percent = stats.percent;
// for backward compatibility
stats.loaded = stats.processed;
stats.size = stats.total;
stats.bytesPerSec = stats.processedPerSec;
return true;
},
destroy: function() {
var self = this;
if (self.state === Queueable.DESTROYED) {
return false; // already destroyed
}
if (self.state !== Queueable.IDLE) {
// stop the active queue first
self.bindOnce('Stopped', function() {
plupload.delay.call(self, self.destroy);
});
return self.stop();
} else {
self.clear();
Queue.parent.destroy.call(this);
self._queue = self.stats = null;
}
return true;
}
});
/**
* Returns another Queueable.IDLE or Queueable.RESUMED item, or null.
*/
function getNextIdleItem() {
var nextItem;
this.forEachItem(function(item) {
if (item.state === Queueable.IDLE || item.state === Queueable.RESUMED) {
nextItem = item;
return false;
}
});
return nextItem ? nextItem : null;
}
function processNext() {
var item;
if (this.state !== Queueable.PROCESSING && this.state !== Queueable.PAUSED) {
return false;
}
if (this.stats.processing < this.getOption('max_slots')) {
item = getNextIdleItem.call(this);
if (item) {
if (item.trigger('beforestart')) {
item.setOptions(this.getOptions());
return item.start();
} else {
item.pause();
// we need to call it sync, otherwise another thread may pick up the same file, while it is processed in beforestart handler
processNext.call(this);
}
}
}
return false;
}
return Queue;
}(Queueable));
});
// Included from: src/QueueUpload.js
/**
* QueueUpload.js
*
* Copyright 2017, Ephox
* Released under AGPLv3 License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*/
/**
@class plupload.QueueUpload
@extends plupload.core.Queue
@constructor
@private
@final
@since 3.0
@param {Object} options
*/
define('plupload/QueueUpload', [
'plupload',
'plupload/core/Queue'
], function(plupload, Queue) {
return (function(Parent) {
plupload.inherit(QueueUpload, Parent);
function QueueUpload(options) {
Queue.call(this, {
max_slots: 1,
max_retries: 0,
auto_start: false,
finish_active: false,
url: false,
chunk_size: 0,
multipart: true,
http_method: 'POST',
params: {},
headers: false,
file_data_name: 'file',
send_file_name: true,
stop_on_fail: true
});
this.setOption = function(option, value) {
if (typeof(option) !== 'object') {
if (option == 'max_upload_slots') {
option = 'max_slots';
}
}
QueueUpload.prototype.setOption.call(this, option, value, true);
};
this.setOptions(options);
}
return QueueUpload;
}(Queue));
});
// Included from: src/QueueResize.js
/**
* QueueResize.js
*
* Copyright 2017, Ephox
* Released under AGPLv3 License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*/
/**
@class plupload.QueueResize
@extends plupload.core.Queue
@constructor
@private
@final
@since 3.0
@param {Object} options
*/
define('plupload/QueueResize', [
'plupload',
'plupload/core/Queue'
], function(plupload, Queue) {
return (function(Parent) {
plupload.inherit(QueueResize, Parent);
function QueueResize(options) {
Queue.call(this, {
max_slots: 1,
max_retries: 0,
auto_start: false,
finish_active: false,
resize: {}
});
this.setOption = function(option, value) {
if (typeof(option) !== 'object') {
if (option == 'max_resize_slots') {
option = 'max_slots';
}
}
QueueResize.prototype.setOption.call(this, option, value, true);
};
this.setOptions(options);
}
return QueueResize;
}(Queue));
});
// Included from: src/ChunkUploader.js
/**
* ChunkUploader.js
*
* Copyright 2017, Ephox
* Released under AGPLv3 License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*/
/**
* @class plupload.ChunkUploader
* @extends plupload.core.Queueable
* @constructor
* @private
* @final
* @constructor
*/
define('plupload/ChunkUploader', [
'plupload',
'plupload/core/Collection',
'plupload/core/Queueable'
], function(plupload, Collection, Queueable) {
var XMLHttpRequest = moxie.xhr.XMLHttpRequest;
var FormData = moxie.xhr.FormData;
function ChunkUploader(blob) {
var _xhr;
Queueable.call(this);
this._options = {
file_data_name: 'file',
headers: false,
http_method: 'POST',
multipart: true,
params: {},
send_file_name: true,
url: false
};
plupload.extend(this, {
start: function() {
var self = this;
var url;
var formData;
var prevState = this.state;
var options = self._options;
if (this.state === Queueable.PROCESSING) {
return false;
}
if (!this.startedTimestamp) {
this.startedTimestamp = +new Date();
}
this.state = Queueable.PROCESSING;
this.trigger('statechanged', this.state, prevState);
_xhr = new XMLHttpRequest();
if (_xhr.upload) {
_xhr.upload.onprogress = function(e) {
self.progress(e.loaded, e.total);
};
}
_xhr.onload = function() {
var result = {
response: this.responseText,
status: this.status,
responseHeaders: this.getAllResponseHeaders()
};
if (this.status < 200 || this.status >= 400) { // assume error
return self.failed(result);
}
self.done(result);
};
_xhr.onerror = function() {
self.failed(); // TODO: reason here
};
_xhr.onloadend = function() {
// we do not need _xhr anymore, so destroy it
setTimeout(function() { // we detach to sustain reference until all handlers are done
if (_xhr) {
_xhr.destroy();
_xhr = null;
}
}, 1);
};
try {
url = options.multipart ? options.url : buildUrl(options.url, options.params);
_xhr.open(options.http_method, url, true);
// headers must be set after request is already opened, otherwise INVALID_STATE_ERR exception will raise
if (!plupload.isEmptyObj(options.headers)) {
plupload.each(options.headers, function(val, key) {
_xhr.setRequestHeader(key, val);
});
}
if (options.multipart) {
formData = new FormData();
if (!plupload.isEmptyObj(options.params)) {
plupload.each(options.params, function(val, key) {
formData.append(key, val);
});
}
formData.append(options.file_data_name, blob);
_xhr.send(formData);
} else { // if no multipart, send as binary stream
if (plupload.isEmptyObj(options.headers) || !_xhr.hasRequestHeader('content-type')) {
_xhr.setRequestHeader('content-type', 'application/octet-stream'); // binary stream header
}
_xhr.send(blob);
}
this.trigger('started');
} catch(ex) {
self.failed();
}
},
stop: function() {
if (_xhr) {
_xhr.abort();
_xhr.destroy();
_xhr = null;
}
ChunkUploader.prototype.stop.call(this);
},
setOption: function(option, value) {
ChunkUploader.prototype.setOption.call(this, option, value, true);
},
setOptions: function(options) {
ChunkUploader.prototype.setOption.call(this, options, true);
},
destroy: function() {
this.stop();
ChunkUploader.prototype.destroy.call(this);
}
});
/**
* Builds a full url out of a base URL and an object with items to append as query string items.
*
* @method buildUrl
* @private
* @param {String} url Base URL to append query string items to.
* @param {Object} items Name/value object to serialize as a querystring.
* @return {String} String with url + serialized query string items.
*/
function buildUrl(url, items) {
var query = '';
plupload.each(items, function(value, name) {
query += (query ? '&' : '') + encodeURIComponent(name) + '=' + encodeURIComponent(value);
});
if (query) {
url += (url.indexOf('?') > 0 ? '&' : '?') + query;
}
return url;
}
}
plupload.inherit(ChunkUploader, Queueable);
return ChunkUploader;
});
// Included from: src/FileUploader.js
/**
* FileUploader.js
*
* Copyright 2017, Ephox
* Released under AGPLv3 License.se.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*/
/**
* @class plupload.FileUploader
* @extends plupload.core.Queueable
* @constructor
* @since 3.0
* @final
*/
define('plupload/FileUploader', [
'plupload',
'plupload/core/Collection',
'plupload/core/Queueable',
'plupload/ChunkUploader'
], function(plupload, Collection, Queueable, ChunkUploader) {
function FileUploader(file, queue) {
var _chunks = new Collection();
var _totalChunks = 1;
Queueable.call(this);
this._options = {
chunk_size: 0,
params: {},
send_file_name: true,
stop_on_fail: true
};
plupload.extend(this, {
/**
When send_file_name is set to true, will be sent with the request as `name` param.
Can be used on server-side to override original file name.
@property name
@type {String}
*/
name: file.name,
start: function() {
var self = this;
var prevState = this.state;
var up;
if (this.state === Queueable.PROCESSING) {
return false;
}
if (!this.startedTimestamp) {
this.startedTimestamp = +new Date();
}
this.state = Queueable.PROCESSING;
this.trigger('statechanged', this.state, prevState);
// send additional 'name' parameter only if required or explicitly requested
if (self._options.send_file_name) {
self._options.params.name = self.target_name || self.name;
}
if (self._options.chunk_size) {
_totalChunks = Math.ceil(file.size / self._options.chunk_size);
self.uploadChunk(false, true);
} else {
up = new ChunkUploader(file);
up.bind('progress', function(e) {
self.progress(e.loaded, e.total);
});
up.bind('done', function(e, result) {
self.done(result);
});
up.bind('failed', function(e, result) {
self.failed(result);
});
up.setOptions(self._options);
queue.addItem(up);
}
this.trigger('started');
},
uploadChunk: function(seq, dontStop) {
var self = this;
var chunkSize = this.getOption('chunk_size');
var up;
var chunk = {};
var _options;
chunk.seq = parseInt(seq, 10) || getNextChunk();
chunk.start = chunk.seq * chunkSize;
chunk.end = Math.min(chunk.start + chunkSize, file.size);
chunk.total = file.size;
// do not proceed for weird chunks
if (chunk.start < 0 || chunk.start >= file.size) {
return false;
}
_options = plupload.extendImmutable({}, this.getOptions(), {
params: {
chunk: chunk.seq,
chunks: _totalChunks
}
});
up = new ChunkUploader(file.slice(chunk.start, chunk.end, file.type));
up.bind('progress', function(e) {
self.progress(calcProcessed() + e.loaded, file.size);
});
up.bind('failed', function(e, result) {
_chunks.add(chunk.seq, plupload.extend({
state: Queueable.FAILED
}, chunk));
self.trigger('chunkuploadfailed', plupload.extendImmutable({}, chunk, result));
if (_options.stop_on_fail) {
self.failed(result);
}
});
up.bind('done', function(e, result) {
_chunks.add(chunk.seq, plupload.extend({
state: Queueable.DONE
}, chunk));
self.trigger('chunkuploaded', plupload.extendImmutable({}, chunk, result));
if (calcProcessed() >= file.size) {
self.progress(file.size, file.size);
self.done(result); // obviously we are done
} else if (dontStop) {
plupload.delay(function() {
self.uploadChunk(getNextChunk(), dontStop);
});
}
});
up.bind('processed', function() {
this.destroy();
});
up.setOptions(_options);
_chunks.add(chunk.seq, plupload.extend({
state: Queueable.PROCESSING
}, chunk));
queue.addItem(up);
// enqueue even more chunks if slots available
if (dontStop && queue.countSpareSlots()) {
self.uploadChunk(getNextChunk(), dontStop);
}
return true;
},
destroy: function() {
FileUploader.prototype.destroy.call(this);
_chunks.clear();
}
});
function calcProcessed() {
var processed = 0;
_chunks.each(function(item) {
if (item.state === Queueable.DONE) {
processed += (item.end - item.start);
}
});
return processed;
}
function getNextChunk() {
var i = 0;
while (i < _totalChunks && _chunks.hasKey(i)) {
i++;
}
return i;
}
}
plupload.inherit(FileUploader, Queueable);
return FileUploader;
});
// Included from: src/ImageResizer.js
/**
* ImageResizer.js
*
* Copyright 2017, Ephox
* Released under AGPLv3 License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*/
/**
@class plupload.ImageResizer
@extends plupload.core.Queueable
@constructor
@private
@final
@since 3.0
@param {plupload.File} fileRef
*/
define("plupload/ImageResizer", [
'plupload',
'plupload/core/Queueable'
], function(plupload, Queueable) {
var mxiImage = moxie.image.Image;
function ImageResizer(fileRef) {
Queueable.call(this);
this._options = {
type: 'image/jpeg',
quality: 90,
crop: false,
fit: true,
preserveHeaders: true,
resample: 'default',
multipass: true
};
this.setOption = function(option, value) {
if (typeof(option) !== 'object' && !this._options.hasOwnProperty(option)) {
return;
}
ImageResizer.prototype.setOption.apply(this, arguments);
};
this.start = function(options) {
var self = this;
var img;
if (options) {
this.setOptions(options.resize);
}
img = new mxiImage();
img.bind('load', function() {
this.resize(self.getOptions());
});
img.bind('resize', function() {
self.done(this.getAsBlob(self.getOption('type'), self.getOption('quality')));
this.destroy();
});
img.bind('error', function() {
self.failed();
this.destroy();
});
img.load(fileRef, self.getOption('runtimeOptions'));
};
}
plupload.inherit(ImageResizer, Queueable);
// ImageResizer is only included for builds with Image manipulation support, so we add plupload.Image here manually
plupload.Image = mxiImage;
return ImageResizer;
});
// Included from: src/File.js
/**
* File.js
*
* Copyright 2017, Ephox
* Released under AGPLv3 License.se.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*/
/**
* @class plupload.File
* @extends plupload.core.Queueable
* @constructor
* @since 3.0
* @final
*/
define('plupload/File', [
'plupload',
'plupload/core/Queueable',
'plupload/FileUploader',
'plupload/ImageResizer'
], function(plupload, Queueable, FileUploader, ImageResizer) {
function File(file, queueUpload, queueResize) {
Queueable.call(this);
plupload.extend(this, {
/**
* For backward compatibility
*
* @property id
* @type {String}
* @deprecated
*/
id: this.uid,
/**
When send_file_name is set to true, will be sent with the request as `name` param.
Can be used on server-side to override original file name.
@property name
@type {String}
*/
name: file.name,
/**
@property target_name
@type {String}
@deprecated use name
*/
target_name: null,
/**
* File type, `e.g image/jpeg`
*
* @property type
* @type String
*/
type: file.type,
/**
* File size in bytes (may change after client-side manupilation).
*
* @property size
* @type Number
*/
size: file.size,
/**
* Original file size in bytes.
*
* @property origSize
* @type Number
*/
origSize: file.size,
start: function() {
var prevState = this.state;
if (this.state === Queueable.PROCESSING) {
return false;
}
this.state = Queueable.PROCESSING;
this.trigger('statechanged', this.state, prevState);
this.trigger('started');
if (!plupload.isEmptyObj(this._options.resize) && isImage(this.type) && runtimeCan(file, 'send_binary_string')) {
this.resizeAndUpload();
} else {
this.upload();
}
return true;
},
/**
* Get the file for which this File is responsible
*
* @method getSource
* @returns {moxie.file.File}
*/
getSource: function() {
return file;
},
/**
* Returns file representation of the current runtime. For HTML5 runtime
* this is going to be native browser File object
* (for backward compatibility)
*
* @method getNative
* @deprecated
* @returns {File|Blob|Object}
*/
getNative: function() {
return this.getFile().getSource();
},
resizeAndUpload: function() {
var self = this;
var opts = self.getOptions();
var rszr = new ImageResizer(file);
rszr.bind('progress', function(e) {
self.progress(e.loaded, e.total);
});
rszr.bind('done', function(e, file) {
file = file;
self.upload();
});
rszr.bind('failed', function() {
self.upload();
});
rszr.setOption('runtimeOptions', {
runtime_order: opts.runtimes,
required_caps: opts.required_features,
preferred_caps: opts.preferred_caps,
swf_url: opts.flash_swf_url,
xap_url: opts.silverlight_xap_url
});
queueResize.addItem(rszr);
},
upload: function() {
var self = this;
var up = new FileUploader(file, queueUpload);
up.bind('paused', function() {
self.pause();
});
up.bind('resumed', function() {
this.start();
});
up.bind('started', function() {
self.trigger('startupload');
});
up.bind('progress', function(e) {
self.progress(e.loaded, e.total);
});
up.bind('done', function(e, result) {
self.done(result);
});
up.bind('failed', function(e, result) {
self.failed(result);
});
up.setOptions(self.getOptions());
up.start();
},
destroy: function() {
File.prototype.destroy.call(this);
file = null;
}
});
}
function isImage(type) {
return plupload.inArray(type, ['image/jpeg', 'image/png']) > -1;
}
function runtimeCan(blob, cap) {
if (blob.ruid) {
var info = plupload.Runtime.getInfo(blob.ruid);
if (info) {
return info.can(cap);
}
}
return false;
}
plupload.inherit(File, Queueable);
return File;
});
// Included from: src/Uploader.js
/**
* Uploader.js
*
* Copyright 2017, Ephox
* Released under AGPLv3 License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*/
/**
@class plupload.Uploader
@extends plupload.core.Queue
@constructor
@public
@final
@param {Object} settings For detailed information about each option check documentation.
@param {String|DOMElement} settings.browse_button id of the DOM element or DOM element itself to use as file dialog trigger.
@param {Number|String} [settings.chunk_size=0] Chunk size in bytes to slice the file into. Shorcuts with b, kb, mb, gb, tb suffixes also supported. `e.g. 204800 or "204800b" or "200kb"`. By default - disabled.
@param {Boolean} [settings.send_chunk_number=true] Whether to send chunks and chunk numbers, or total and offset bytes.
@param {String|DOMElement} [settings.container] id of the DOM element or DOM element itself that will be used to wrap uploader structures. Defaults to immediate parent of the `browse_button` element.
@param {String|DOMElement} [settings.drop_element] id of the DOM element or DOM element itself to use as a drop zone for Drag-n-Drop.
@param {String} [settings.file_data_name="file"] Name for the file field in Multipart formated message.
@param {Object} [settings.filters={}] Set of file type filters.
@param {Array} [settings.filters.mime_types=[]] List of file types to accept, each one defined by title and list of extensions. `e.g. {title : "Image files", extensions : "jpg,jpeg,gif,png"}`. Dispatches `plupload.FILE_EXTENSION_ERROR`
@param {String|Number} [settings.filters.max_file_size=0] Maximum file size that the user can pick, in bytes. Optionally supports b, kb, mb, gb, tb suffixes. `e.g. "10mb" or "1gb"`. By default - not set. Dispatches `plupload.FILE_SIZE_ERROR`.
@param {Boolean} [settings.filters.prevent_duplicates=false] Do not let duplicates into the queue. Dispatches `plupload.FILE_DUPLICATE_ERROR`.
@param {String} [settings.flash_swf_url] URL of the Flash swf.
@param {Object} [settings.headers] Custom headers to send with the upload. Hash of name/value pairs.
@param {String} [settings.http_method="POST"] HTTP method to use during upload (only PUT or POST allowed).
@param {Number} [settings.max_retries=0] How many times to retry the chunk or file, before triggering Error event.
@param {Boolean} [settings.multipart=true] Whether to send file and additional parameters as Multipart formated message.
@param {Boolean} [settings.multi_selection=true] Enable ability to select multiple files at once in file dialog.
@param {Object} [settings.params] Hash of key/value pairs to send with every file upload.
@param {String|Object} [settings.required_features] Either comma-separated list or hash of required features that chosen runtime should absolutely possess.
@param {Object} [settings.resize] Enable resizing of images on client-side. Applies to `image/jpeg` and `image/png` only. `e.g. {width : 200, height : 200, quality : 90, crop: true}`
@param {Number} settings.resize.width Resulting width
@param {Number} [settings.resize.height=width] Resulting height (optional, if not supplied will default to width)
@param {String} [settings.resize.type='image/jpeg'] MIME type of the resulting image
@param {Number} [settings.resize.quality=90] In the case of JPEG, controls the quality of resulting image
@param {Boolean} [settings.resize.crop='cc'] If not falsy, image will be cropped, by default from center
@param {Boolean} [settings.resize.fit=true] In case of crop whether to upscale the image to fit the exact dimensions
@param {Boolean} [settings.resize.preserveHeaders=true] Whether to preserve meta headers (on JPEGs after resize)
@param {String} [settings.resize.resample='default'] Resampling algorithm to use during resize
@param {Boolean} [settings.resize.multipass=true] Whether to scale the image in steps (results in better quality)
@param {String} [settings.runtimes="html5,flash,silverlight,html4"] Comma separated list of runtimes, that Plupload will try in turn, moving to the next if previous fails.
@param {Boolean} [settings.send_file_name=true] Whether to send file name as additional argument - 'name' (required for chunked uploads and some other cases where file name cannot be sent via normal ways).
@param {String} [settings.silverlight_xap_url] URL of the Silverlight xap.
@param {Boolean} [settings.unique_names=false] If true will generate unique filenames for uploaded files.
@param {String} settings.url URL of the server-side upload handler.
*/
/**
Fires when the current RunTime has been initialized.
@event Init
@param {plupload.Uploader} uploader Uploader instance sending the event.
*/
/**
Fires after the init event incase you need to perform actions there.
@event PostInit
@param {plupload.Uploader} uploader Uploader instance sending the event.
*/
/**
Fires when the option is changed in via uploader.setOption().
@event OptionChanged
@since 2.1
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {String} name Name of the option that was changed
@param {Mixed} value New value for the specified option
@param {Mixed} oldValue Previous value of the option
*/
/**
Fires when the silverlight/flash or other shim needs to move.
@event Refresh
@param {plupload.Uploader} uploader Uploader instance sending the event.
*/
/**
Fires when the overall state is being changed for the upload queue.
@event StateChanged
@param {plupload.Uploader} uploader Uploader instance sending the event.
*/
/**
Fires when browse_button is clicked and browse dialog shows.
@event Browse
@since 2.1.2
@param {plupload.Uploader} uploader Uploader instance sending the event.
*/
/**
Fires for every filtered file before it is added to the queue.
@event FileFiltered
@since 2.1
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {plupload.File} file Another file that has to be added to the queue.
*/
/**
Fires when the file queue is changed. In other words when files are added/removed to the files array of the uploader instance.
@event QueueChanged
@param {plupload.Uploader} uploader Uploader instance sending the event.
*/
/**
Fires after files were filtered and added to the queue.
@event FilesAdded
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {Array} files Array of FileUploader objects that were added to the queue by user.
*/
/**
Fires when file is removed from the queue.
@event FilesRemoved
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {Array} files Array of files that got removed.
*/
/**
Fires just before a file is uploaded. Can be used to cancel upload of the current file
by returning false from the handler.
@event BeforeUpload
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {plupload.File} file File to be uploaded.
*/
/**
Fires when a file is to be uploaded by the runtime.
@event UploadFile
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {plupload.File} file File to be uploaded.
*/
/**
Fires while a file is being uploaded. Use this event to update the current file upload progress.
@event UploadProgress
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {plupload.File} file File that is currently being uploaded.
*/
/**
Fires when file chunk is uploaded.
@event ChunkUploaded
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {plupload.File} file File that the chunk was uploaded for.
@param {Object} result Object with response properties.
@param {Number} result.offset The amount of bytes the server has received so far, including this chunk.
@param {Number} result.total The size of the file.
@param {String} result.response The response body sent by the server.
@param {Number} result.status The HTTP status code sent by the server.
@param {String} result.responseHeaders All the response headers as a single string.
*/
/**
Fires when a file is successfully uploaded.
@event FileUploaded
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {plupload.File} file File that was uploaded.
@param {Object} result Object with response properties.
@param {String} result.response The response body sent by the server.
@param {Number} result.status The HTTP status code sent by the server.
@param {String} result.responseHeaders All the response headers as a single string.
*/
/**
Fires when all files in a queue are uploaded
@event UploadComplete
@param {plupload.Uploader} uploader Uploader instance sending the event.
*/
/**
Fires whenever upload is aborted for some reason
@event CancelUpload
@param {plupload.Uploader} uploader Uploader instance sending the event.
*/
/**
Fires when a error occurs.
@event Error
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {Object} error Contains code, message and sometimes file and other details.
@param {Number} error.code The plupload error code.
@param {String} error.message Description of the error (uses i18n).
*/
/**
Fires when destroy method is called.
@event Destroy
@param {plupload.Uploader} uploader Uploader instance sending the event.
*/
define('plupload/Uploader', [
'plupload',
'plupload/core/Collection',
'plupload/core/Queue',
'plupload/QueueUpload',
'plupload/QueueResize',
'plupload/File'
], function(plupload, Collection, Queue, QueueUpload, QueueResize, PluploadFile) {
var fileFilters = {};
var undef;
function Uploader(options) {
var _fileInputs = [];
var _fileDrops = [];
var _queueUpload, _queueResize;
var _initialized = false;
var _disabled = false;
var _options = normalizeOptions(plupload.extend({
backward_compatibility: true,
chunk_size: 0,
file_data_name: 'file',
filters: {
mime_types: '*',
prevent_duplicates: false,
max_file_size: 0
},
flash_swf_url: 'js/Moxie.swf',
// @since 2.3
http_method: 'POST',
// headers: false, // Plupload had a required feature with the same name, comment it to avoid confusion
max_resize_slots: 1,
max_retries: 0,
max_upload_slots: 1,
multipart: true,
multipart_params: {}, // deprecated, use - params,
multi_selection: true,
// @since 3
params: {},
resize: false,
runtimes: plupload.Runtime.order,
send_chunk_number: true, // whether to send chunks and chunk numbers, instead of total and offset bytes
send_file_name: true,
silverlight_xap_url: 'js/Moxie.xap',
// during normalization, these should be processed last
required_features: false,
preferred_caps: false
}, options));
Queue.call(this);
// Add public methods
plupload.extend(this, {
_options: _options,
/**
* Unique id for the Uploader instance.
*
* @property id
* @type String
*/
id: this.uid,
/**
* Current state of the total uploading progress. This one can either be plupload.STARTED or plupload.STOPPED.
* These states are controlled by the stop/start methods. The default value is STOPPED.
*
* @property state
* @type Number
*/
state: plupload.STOPPED,
/**
* Map of features that are available for the uploader runtime. Features will be filled
* before the init event is called, these features can then be used to alter the UI for the end user.
* Some of the current features that might be in this map is: dragdrop, chunks, jpgresize, pngresize.
*
* @property features
* @type Object
* @deprecated
*/
features: {},
/**
* Object with name/value settings.
*
* @property settings
* @type Object
* @deprecated Use `getOption()/setOption()`
*/
settings : _options,
/**
* Current runtime name
*
* @property runtime
* @type String
* @deprecated There might be multiple runtimes per uploader
*/
runtime: null,
/**
* Current upload queue, an array of File instances
*
* @property files
* @deprecated use forEachItem(callback) to cycle over the items in the queue
* @type Array
*/
files: [],
/**
* Total progess information. How many files has been uploaded, total percent etc.
*
* @property total
* @deprecated use stats
*/
total: this.stats,
/**
* Initializes the Uploader instance and adds internal event listeners.
*
* @method init
*/
init: function() {
var self = this, preinitOpt, err;
preinitOpt = self.getOption('preinit');
if (typeof(preinitOpt) == "function") {
preinitOpt(self);
} else {
plupload.each(preinitOpt, function(func, name) {
self.bind(name, func);
});
}
bindEventListeners.call(self);
// Check for required options
plupload.each(['container', 'browse_button', 'drop_element'], function(el) {
if (self.getOption(el) === null) {
err = {
code: plupload.INIT_ERROR,
message: plupload.sprintf(plupload.translate("%s specified, but cannot be found."), el)
}
return false;
}
});
if (err) {
return self.trigger('Error', err);
}
if (!self.getOption('browse_button') && !self.getOption('drop_element')) {
return self.trigger('Error', {
code: plupload.INIT_ERROR,
message: plupload.translate("You must specify either browse_button or drop_element.")
});
}
initControls.call(self, function(initialized) {
var runtime;
var initOpt = self.getOption('init');
var queueOpts = plupload.extendImmutable({}, self.getOption(), { auto_start: true });
if (typeof(initOpt) == "function") {
initOpt(self);
} else {
plupload.each(initOpt, function(func, name) {
self.bind(name, func);
});
}
if (initialized) {
_initialized = true;
runtime = plupload.Runtime.getInfo(getRUID());
_queueUpload = new QueueUpload(queueOpts);
_queueResize = new QueueResize(queueOpts);
self.trigger('Init', {
ruid: runtime.uid,
runtime: self.runtime = runtime.type
});
self.trigger('PostInit');
} else {
self.trigger('Error', {
code: plupload.INIT_ERROR,
message: plupload.translate('Init error.')
});
}
});
},
/**
* Set the value for the specified option(s).
*
* @method setOption
* @since 2.1
* @param {String|Object} option Name of the option to change or the set of key/value pairs
* @param {Mixed} [value] Value for the option (is ignored, if first argument is object)
*/
setOption: function(option, value) {
if (_initialized) {
// following options cannot be changed after initialization
if (plupload.inArray(option, [
'container',
'browse_button',
'drop_element',
'runtimes',
'multi_selection',
'flash_swf_url',
'silverlight_xap_url'
]) > -1) {
return this.trigger('Error', {
code: plupload.OPTION_ERROR,
message: plupload.sprintf(plupload.translate("%s option cannot be changed.")),
option: option
});
}
}
if (typeof(option) !== 'object') {
value = normalizeOption(option, value, this._options);
// queues will take in only appropriate options
if (_queueUpload) {
_queueUpload.setOption(option, value);
}
if (_queueResize) {
_queueResize.setOption(option, value);
}
}
Uploader.prototype.setOption.call(this, option, value);
},
/**
* Refreshes the upload instance by dispatching out a refresh event to all runtimes.
* This would for example reposition flash/silverlight shims on the page.
*
* @method refresh
*/
refresh: function() {
if (_fileInputs.length) {
plupload.each(_fileInputs, function(fileInput) {
fileInput.trigger('Refresh');
});
}
if (_fileDrops.length) {
plupload.each(_fileDrops, function(fileDrops) {
fileDrops.trigger('Refresh');
});
}
this.trigger('Refresh');
},
/**
* Stops the upload of the queued files.
*
* @method stop
*/
stop: function() {
if (Uploader.prototype.stop.call(this) && this.state != plupload.STOPPED) {
this.trigger('CancelUpload');
}
},
/**
* Disables/enables browse button on request.
*
* @method disableBrowse
* @param {Boolean} disable Whether to disable or enable (default: true)
*/
disableBrowse: function() {
_disabled = arguments[0] !== undef ? arguments[0] : true;
if (_fileInputs.length) {
plupload.each(_fileInputs, function(fileInput) {
fileInput.disable(_disabled);
});
}
this.trigger('DisableBrowse', _disabled);
},
/**
* Returns the specified FileUploader object by id
*
* @method getFile
* @deprecated use getItem()
* @param {String} id FileUploader id to look for
* @return {plupload.FileUploader}
*/
getFile: function(id) {
return this.getItem(id);
},
/**
* Adds file to the queue programmatically. Can be native file, instance of Plupload.File,
* instance of mOxie.File, input[type="file"] element, or array of these. Fires FilesAdded,
* if any files were added to the queue. Otherwise nothing happens.
*
* @method addFile
* @since 2.0
* @param {plupload.File|mOxie.File|File|Node|Array} file File or files to add to the queue.
* @param {String} [fileName] If specified, will be used as a name for the file
*/
addFile: function(file, fileName) {
var self = this;
var queue = [];
var ruid; // spare runtime uid, for those files that do not have their own
var filesAdded = []; // here we track the files that got filtered and are added to the queue
function bindListeners(fileUp) {
fileUp.bind('beforestart', function(e) {
return self.trigger('BeforeUpload', e.target);
});
fileUp.bind('startupload', function() {
self.trigger('UploadFile', this);
});
fileUp.bind('progress', function() {
self.trigger('UploadProgress', this);
});
fileUp.bind('done', function(e, args) {
self.trigger('FileUploaded', this, args);
});
fileUp.bind('failed', function(e, err) {
self.trigger('Error', plupload.extend({
code: plupload.HTTP_ERROR,
message: plupload.translate('HTTP Error.'),
file: this
}, err));
});
}
function filterFile(file, cb) {
var queue = [];
plupload.each(self.getOption('filters'), function(rule, name) {
if (fileFilters[name]) {
queue.push(function(cb) {
fileFilters[name].call(self, rule, file, function(res) {
cb(!res);
});
});
}
});
plupload.inParallel(queue, cb);
}
/**
* @method resolveFile
* @private
* @param {mxiFile|mxiBlob|FileUploader|File|Blob|input[type="file"]} file
*/
function resolveFile(file) {
var type = plupload.typeOf(file);
// mxiFile (final step for other conditional branches)
if (file instanceof moxie.file.File) {
if (!file.ruid && !file.isDetached()) {
if (!ruid) { // weird case
return false;
}
file.ruid = ruid;
file.connectRuntime(ruid);
}
queue.push(function(cb) {
// run through the internal and user-defined filters, if any
filterFile(file, function(err) {
var fileUp;
if (!err) {
fileUp = new PluploadFile(file, _queueUpload, _queueResize);
if (fileName) {
fileUp.name = fileName;
}
bindListeners(fileUp);
self.addItem(fileUp); // make files available for the filters by updating the main queue directly
filesAdded.push(fileUp);
self.trigger("FileFiltered", fileUp);
}
plupload.delay(cb); // do not build up recursions or eventually we might hit the limits
});
});
}
// mxiBlob
else if (file instanceof moxie.file.Blob) {
resolveFile(file.getSource());
file.destroy();
}
// native File or blob
else if (plupload.inArray(type, ['file', 'blob']) !== -1) {
resolveFile(new moxie.file.File(null, file));
}
// input[type="file"]
else if (type === 'node' && plupload.typeOf(file.files) === 'filelist') {
// if we are dealing with input[type="file"]
plupload.each(file.files, resolveFile);
}
// mixed array of any supported types (see above)
else if (type === 'array') {
fileName = null; // should never happen, but unset anyway to avoid funny situations
plupload.each(file, resolveFile);
}
}
ruid = getRUID();
resolveFile(file);
if (queue.length) {
plupload.inParallel(queue, function() {
// if any files left after filtration, trigger FilesAdded
if (filesAdded.length) {
self.trigger("FilesAdded", filesAdded);
}
});
}
},
/**
* Removes a specific item from the queue
*
* @method removeFile
* @param {plupload.FileUploader|String} file
*/
removeFile: function(file) {
var item = this.extractItem(typeof(file) === 'string' ? file : file.uid);
if (item) {
this.trigger("FilesRemoved", [item]);
item.destroy();
}
},
/**
* Removes part of the queue and returns removed files.
* Triggers FilesRemoved and consequently QueueChanged events.
*
* @method splice
* @param {Number} [start=0] Start index to remove from
* @param {Number} [length] Length of items to remove
*/
splice: function() {
var i = 0;
var shouldRestart = plupload.STARTED == this.state;
var removed = Queue.prototype.splice.apply(this, arguments);
if (removed.length) {
this.trigger("FilesRemoved", removed);
if (shouldRestart) {
this.stop();
}
for (i = 0; i < removed.length; i++) {
removed[i].destroy();
}
if (shouldRestart) {
this.start();
}
}
},
/**
Dispatches the specified event name and its arguments to all listeners.
@method trigger
@param {String} name Event name to fire.
@param {Object..} Multiple arguments to pass along to the listener functions.
*/
// override the parent method to match Plupload-like event logic
dispatchEvent: function(type) {
var list, args, result;
type = type.toLowerCase();
list = this.hasEventListener(type);
if (list) {
// sort event list by priority
list.sort(function(a, b) {
return b.priority - a.priority;
});
// first argument should be current plupload.Uploader instance
args = [].slice.call(arguments);
args.shift();
args.unshift(this);
for (var i = 0; i < list.length; i++) {
// Fire event, break chain if false is returned
if (list[i].fn.apply(list[i].scope, args) === false) {
return false;
}
}
}
return true;
},
/**
Check whether uploader has any listeners to the specified event.
@method hasEventListener
@param {String} name Event name to check for.
*/
/**
Adds an event listener by name.
@method bind
@param {String} name Event name to listen for.
@param {function} fn Function to call ones the event gets fired.
@param {Object} [scope] Optional scope to execute the specified function in.
@param {Number} [priority=0] Priority of the event handler - handlers with higher priorities will be called first
*/
bind: function(name, fn, scope, priority) {
// adapt moxie EventTarget style to Plupload-like
plupload.Uploader.prototype.bind.call(this, name, fn, priority, scope);
}
/**
Removes the specified event listener.
@method unbind
@param {String} name Name of event to remove.
@param {function} fn Function to remove from listener.
*/
/**
Removes all event listeners.
@method unbindAll
*/
});
// keep alive deprecated properties
if (_options.backward_compatibility) {
this.bind('FilesAdded FilesRemoved', function (up) {
up.files = up.toArray();
}, this, 999);
this.bind('OptionChanged', function (up, name, value) {
up.settings[name] = typeof(value) == 'object' ? plupload.extend({}, value) : value;
}, this, 999);
}
function getRUID() {
var ctrl = _fileInputs[0] || _fileDrops[0];
if (ctrl) {
return ctrl.getRuntime().uid;
}
return false;
}
function bindEventListeners() {
this.bind('FilesAdded FilesRemoved', function(up) {
up.trigger('QueueChanged');
up.refresh();
}, this, 999);
this.bind('BeforeUpload', onBeforeUpload);
this.bind('Stopped', function(up) {
up.trigger('UploadComplete');
});
this.bind('Error', onError);
this.bind('Destroy', onDestroy);
}
function initControls(cb) {
var self = this;
var initialized = 0;
var queue = [];
// common settings
var options = {
runtime_order: self.getOption('runtimes'),
required_caps: self.getOption('required_features'),
preferred_caps: self.getOption('preferred_caps'),
swf_url: self.getOption('flash_swf_url'),
xap_url: self.getOption('silverlight_xap_url')
};
// add runtime specific options if any
plupload.each(self.getOption('runtimes').split(/\s*,\s*/), function(runtime) {
if (self.getOption(runtime)) {
options[runtime] = self.getOption(runtime);
}
});
// initialize file pickers - there can be many
if (self.getOption('browse_button')) {
plupload.each(self.getOption('browse_button'), function(el) {
queue.push(function(cb) {
var fileInput = new moxie.file.FileInput(plupload.extend({}, options, {
accept: self.getOption('filters').mime_types,
name: self.getOption('file_data_name'),
multiple: self.getOption('multi_selection'),
container: self.getOption('container'),
browse_button: el
}));
fileInput.onready = function() {
var info = plupload.Runtime.getInfo(this.ruid);
// for backward compatibility
plupload.extend(self.features, {
chunks: info.can('slice_blob'),
multipart: info.can('send_multipart'),
multi_selection: info.can('select_multiple')
});
initialized++;
_fileInputs.push(this);
cb();
};
fileInput.onchange = function() {
self.addFile(this.files);
};
fileInput.bind('mouseenter mouseleave mousedown mouseup', function(e) {
if (!_disabled) {
if (self.getOption('browse_button_hover')) {
if ('mouseenter' === e.type) {
plupload.addClass(el, self.getOption('browse_button_hover'));
} else if ('mouseleave' === e.type) {
plupload.removeClass(el, self.getOption('browse_button_hover'));
}
}
if (self.getOption('browse_button_active')) {
if ('mousedown' === e.type) {
plupload.addClass(el, self.getOption('browse_button_active'));
} else if ('mouseup' === e.type) {
plupload.removeClass(el, self.getOption('browse_button_active'));
}
}
}
});
fileInput.bind('mousedown', function() {
self.trigger('Browse');
});
fileInput.bind('error runtimeerror', function() {
fileInput = null;
cb();
});
fileInput.init();
});
});
}
// initialize drop zones
if (self.getOption('drop_element')) {
plupload.each(self.getOption('drop_element'), function(el) {
queue.push(function(cb) {
var fileDrop = new moxie.file.FileDrop(plupload.extend({}, options, {
drop_zone: el
}));
fileDrop.onready = function() {
var info = plupload.Runtime.getInfo(this.ruid);
// for backward compatibility
plupload.extend(self.features, {
chunks: info.can('slice_blob'),
multipart: info.can('send_multipart'),
dragdrop: info.can('drag_and_drop')
});
initialized++;
_fileDrops.push(this);
cb();
};
fileDrop.ondrop = function() {
self.addFile(this.files);
};
fileDrop.bind('error runtimeerror', function() {
fileDrop = null;
cb();
});
fileDrop.init();
});
});
}
plupload.inParallel(queue, function() {
if (typeof(cb) === 'function') {
cb(initialized);
}
});
}
// Internal event handlers
function onBeforeUpload(up, file) {
// Generate unique target filenames
if (up.getOption('unique_names')) {
var matches = file.name.match(/\.([^.]+)$/),
ext = "part";
if (matches) {
ext = matches[1];
}
file.target_name = file.id + '.' + ext;
}
}
function onError(up, err) {
if (err.code === plupload.INIT_ERROR) {
up.destroy();
}
else if (err.code === plupload.HTTP_ERROR && up.state == plupload.STARTED) {
up.trigger('CancelUpload');
}
}
function onDestroy(up) {
up.forEachItem(function(file) {
file.destroy();
});
if (_fileInputs.length) {
plupload.each(_fileInputs, function(fileInput) {
fileInput.destroy();
});
_fileInputs = [];
}
if (_fileDrops.length) {
plupload.each(_fileDrops, function(fileDrop) {
fileDrop.destroy();
});
_fileDrops = [];
}
_initialized = false;
if (_queueUpload) {
_queueUpload.destroy();
}
if (_queueResize) {
_queueResize.destroy();
}
_options = _queueUpload = _queueResize = null; // purge these exclusively
}
}
// convert plupload features to caps acceptable by mOxie
function normalizeCaps(settings) {
var features = settings.required_features,
caps = {};
function resolve(feature, value, strict) {
// Feature notation is deprecated, use caps (this thing here is required for backward compatibility)
var map = {
chunks: 'slice_blob',
jpgresize: 'send_binary_string',
pngresize: 'send_binary_string',
progress: 'report_upload_progress',
multi_selection: 'select_multiple',
dragdrop: 'drag_and_drop',
drop_element: 'drag_and_drop',
headers: 'send_custom_headers',
urlstream_upload: 'send_binary_string',
canSendBinary: 'send_binary',
triggerDialog: 'summon_file_dialog'
};
if (map[feature]) {
caps[map[feature]] = value;
} else if (!strict) {
caps[feature] = value;
}
}
if (typeof(features) === 'string') {
plupload.each(features.split(/\s*,\s*/), function(feature) {
resolve(feature, true);
});
} else if (typeof(features) === 'object') {
plupload.each(features, function(value, feature) {
resolve(feature, value);
});
} else if (features === true) {
// check settings for required features
if (settings.chunk_size && settings.chunk_size > 0) {
caps.slice_blob = true;
}
if (!plupload.isEmptyObj(settings.resize) || settings.multipart === false) {
caps.send_binary_string = true;
}
if (settings.http_method) {
caps.use_http_method = settings.http_method;
}
plupload.each(settings, function(value, feature) {
resolve(feature, !!value, true); // strict check
});
}
return caps;
}
function normalizeOptions(options) {
plupload.each(options, function(value, option) {
options[option] = normalizeOption(option, value, options);
});
return options;
}
/**
Normalize an option.
@method normalizeOption
@private
@param {String} option Name of the option to normalize
@param {Mixed} value
@param {Object} options The whole set of options, that might be modified during normalization (see max_file_size or unique_names)!
*/
function normalizeOption(option, value, options) {
switch (option) {
case 'chunk_size':
if (value = plupload.parseSize(value)) {
options.send_file_name = true;
}
break;
case 'headers':
var headers = {};
if (typeof(value) === 'object') {
plupload.each(value, function(value, key) {
headers[key.toLowerCase()] = value;
});
}
return headers;
case 'http_method':
return value.toUpperCase() === 'PUT' ? 'PUT' : 'POST';
case 'filters':
if (plupload.typeOf(value) === 'array') { // for backward compatibility
value = {
mime_types: value
};
}
// if file format filters are being updated, regenerate the matching expressions
if (value.mime_types) {
if (plupload.typeOf(value.mime_types) === 'string') {
value.mime_types = plupload.mimes2extList(value.mime_types);
}
// generate and cache regular expression for filtering file extensions
options.re_ext_filter = (function(filters) {
var extensionsRegExp = [];
plupload.each(filters, function(filter) {
plupload.each(filter.extensions.split(/,/), function(ext) {
if (/^\s*\*\s*$/.test(ext)) {
extensionsRegExp.push('\\.*');
} else {
extensionsRegExp.push('\\.' + ext.replace(new RegExp('[' + ('/^$.*+?|()[]{}\\'.replace(/./g, '\\$&')) + ']', 'g'), '\\$&'));
}
});
});
return new RegExp('(' + extensionsRegExp.join('|') + ')$', 'i');
}(value.mime_types));
}
return value;
case 'max_file_size':
if (options && !options.filters) {
options.filters = {};
}
options.filters.max_file_size = value;
break;
case 'multipart':
if (!value) {
options.send_file_name = true;
}
break;
case 'multipart_params':
options.params = options.multipart_params = value;
break;
case 'resize':
if (value) {
return plupload.extend({
preserve_headers: true,
crop: false
}, value);
}
return false;
case 'prevent_duplicates':
if (options && !options.filters) {
options.filters = {};
}
options.filters.prevent_duplicates = !!value;
break;
case 'unique_names':
if (value) {
options.send_file_name = true;
}
break;
case 'required_features':
// Normalize the list of required capabilities
return normalizeCaps(plupload.extend({}, options));
case 'preferred_caps':
// Come up with the list of capabilities that can affect default mode in a multi-mode runtimes
return normalizeCaps(plupload.extend({}, options, {
required_features: true
}));
// options that require reinitialisation
case 'container':
case 'browse_button':
case 'drop_element':
return 'container' === option ? plupload.get(value) : plupload.getAll(value);
}
return value;
}
/**
* Registers a filter that will be executed for each file added to the queue.
* If callback returns false, file will not be added.
*
* Callback receives two arguments: a value for the filter as it was specified in settings.filters
* and a file to be filtered. Callback is executed in the context of uploader instance.
*
* @method addFileFilter
* @static
* @param {String} name Name of the filter by which it can be referenced in settings.filters
* @param {String} cb Callback - the actual routine that every added file must pass
*/
function addFileFilter(name, cb) {
fileFilters[name] = cb;
}
/**
* A way to predict what runtime will be choosen in the current environment with the
* specified settings.
*
* @method predictRuntime
* @static
* @param {Object|String} config Plupload settings to check
* @param {String} [runtimes] Comma-separated list of runtimes to check against
* @return {String} Type of compatible runtime
*/
function predictRuntime(config, runtimes) {
var up, runtime;
up = new Uploader(config);
runtime = plupload.Runtime.thatCan(up.getOption('required_features'), runtimes || config.runtimes);
up.destroy();
return runtime;
}
addFileFilter('mime_types', function(filters, file, cb) {
if (filters.length && !this.getOption('re_ext_filter').test(file.name)) {
this.trigger('Error', {
code: plupload.FILE_EXTENSION_ERROR,
message: plupload.translate('File extension error.'),
file: file
});
cb(false);
} else {
cb(true);
}
});
addFileFilter('max_file_size', function(maxSize, file, cb) {
var undef;
maxSize = plupload.parseSize(maxSize);
// Invalid file size
if (file.size !== undef && maxSize && file.size > maxSize) {
this.trigger('Error', {
code: plupload.FILE_SIZE_ERROR,
message: plupload.translate('File size error.'),
file: file
});
cb(false);
} else {
cb(true);
}
});
addFileFilter('prevent_duplicates', function(value, file, cb) {
var self = this;
if (value) {
this.forEachItem(function(item) {
// Compare by name and size (size might be 0 or undefined, but still equivalent for both)
if (file.name === item.name && file.size === item.size) {
self.trigger('Error', {
code: plupload.FILE_DUPLICATE_ERROR,
message: plupload.translate('Duplicate file error.'),
file: file
});
cb(false);
return;
}
});
}
cb(true);
});
addFileFilter('prevent_empty', function(value, file, cb) {
if (value && !file.size && file.size !== undef) {
this.trigger('Error', {
code : plupload.FILE_SIZE_ERROR,
message : plupload.translate('File size error.'),
file : file
});
cb(false);
} else {
cb(true);
}
});
Uploader.addFileFilter = addFileFilter;
plupload.inherit(Uploader, Queue);
// for backward compatibility
plupload.addFileFilter = addFileFilter;
plupload.predictRuntime = predictRuntime;
return Uploader;
});
expose(["plupload","plupload/core/Collection","plupload/core/ArrCollection","plupload/core/Optionable","plupload/core/Queueable","plupload/core/Stats","plupload/core/Queue","plupload/QueueUpload","plupload/QueueResize","plupload/ChunkUploader","plupload/FileUploader","plupload/ImageResizer","plupload/File","plupload/Uploader"]);
})(this);
}));