transloadit-core.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // The plugin
  2. let dragndrop = function(options) {
  3. console.log(options.selector);
  4. console.log('dragging and dropping here');
  5. // return function (options) {
  6. // console.log('dragging and dropping here');
  7. // };
  8. };
  9. // Using classes internally
  10. class Transloadit {
  11. constructor(opts = {}, plugins = []) {
  12. this.opts = opts;
  13. this.plugins = plugins;
  14. }
  15. plugin(name, initializer) {
  16. return initializer();
  17. }
  18. use (iterator, opts) {
  19. iterator(opts);
  20. return this;
  21. }
  22. prepare() {
  23. // ...
  24. }
  25. upload(files) {
  26. return new Promise(function (resolve, reject) {
  27. // ...
  28. resolve('upload successful');
  29. });
  30. }
  31. }
  32. let transloadit = new Transloadit();
  33. transloadit.use(dragndrop, {
  34. selector: '.drop'
  35. });
  36. // Then the function is exposed to the user
  37. // it accepts an array of plugins and their options
  38. // transloadit(['dragndrop', 'dropbox', 'instagram']);
  39. // let transloadit = function (plugins) {
  40. // // if ( plugins.length === 1 && Array.isArray(plugins[0]) ) {
  41. // // plugins = plugins[0];
  42. // // }
  43. // return new Transloadit(plugins);
  44. // };
  45. // Then we invoke it
  46. // transloadit([
  47. // dragndrop(),
  48. // dropbox({
  49. // folder: '/media',
  50. // allowSmth: true
  51. // })
  52. // ]);
  53. // transloadit([
  54. // {dragndrop, {selector: '.dragndrop-zone'}},
  55. // {dropbox, {
  56. // folder: '/media',
  57. // allowSmth: true
  58. // }})
  59. // ]);
  60. // transloadit('dragndrop', 'dropbox', 'instagram')
  61. // .then(function (result) {
  62. // console.log(`Done processing: ${result}`)
  63. // });