Ver código fonte

No semi colons

Kevin van Zonneveld 9 anos atrás
pai
commit
bd85a07cd6

+ 1 - 1
.eslintrc

@@ -170,7 +170,7 @@
     "id-match": 0,
     "require-jsdoc": 0,
     "require-yield": 0,
-    "semi": [2, "always"],
+    "semi": [2, "never"],
     "semi-spacing": [0, {"before": false, "after": true}],
     "sort-vars": 0,
     "space-after-keywords": [2, "always"],

+ 19 - 19
src/core/Core.js

@@ -1,5 +1,5 @@
-import Utils from '../core/Utils';
-import Translator from '../core/Translator';
+import Utils from '../core/Utils'
+import Translator from '../core/Translator'
 
 /**
 * Main Uppy core
@@ -13,18 +13,18 @@ export default class Core {
     const defaultOptions = {
       // load English as the default locale
       locale: require('../locale/en_US.js')
-    };
+    }
 
     // Merge default options with the ones set by user
-    this.opts = Object.assign({}, defaultOptions, opts);
+    this.opts = Object.assign({}, defaultOptions, opts)
 
     // Dictates in what order different plugin types are ran:
-    this.types = [ 'presetter', 'selecter', 'uploader' ];
+    this.types = [ 'presetter', 'selecter', 'uploader' ]
 
-    this.type = 'core';
+    this.type = 'core'
 
     // Container for different types of plugins
-    this.plugins = {};
+    this.plugins = {}
 
     // this.translator = new Translator({locale: this.opts.locale});
     // console.log(this.translator.t('files_chosen', {smart_count: 3}));
@@ -39,11 +39,11 @@ export default class Core {
  */
   use(Plugin, opts) {
     // Instantiate
-    const plugin = new Plugin(this, opts);
-    this.plugins[plugin.type] = this.plugins[plugin.type] || [];
-    this.plugins[plugin.type].push(plugin);
+    const plugin = new Plugin(this, opts)
+    this.plugins[plugin.type] = this.plugins[plugin.type] || []
+    this.plugins[plugin.type].push(plugin)
 
-    return this;
+    return this
   }
 
   /**
@@ -55,8 +55,8 @@ export default class Core {
  */
   setProgress(plugin, percentage) {
     // Any plugin can call this via `this.core.setProgress(this, precentage)`
-    console.log(plugin.type + ' plugin ' + plugin.name + ' set the progress to ' + percentage);
-    return this;
+    console.log(plugin.type + ' plugin ' + plugin.name + ' set the progress to ' + percentage)
+    return this
   }
 
   /**
@@ -69,9 +69,9 @@ export default class Core {
   runType(type, files) {
     const methods = this.plugins[type].map(
       plugin => plugin.run.call(plugin, files)
-    );
+    )
 
-    return Promise.all(methods);
+    return Promise.all(methods)
   }
 
   /**
@@ -82,16 +82,16 @@ export default class Core {
     console.log({
       class  : 'Core',
       method : 'run'
-    });
+    })
 
     // First we select only plugins of current type,
     // then create an array of runType methods of this plugins
     let typeMethods = this.types.filter(type => {
-      return this.plugins[type];
-    }).map(type => this.runType.bind(this, type));
+      return this.plugins[type]
+    }).map(type => this.runType.bind(this, type))
 
     Utils.promiseWaterfall(typeMethods)
       .then((result) => console.log(result))
-      .catch((error) => console.error(error));
+      .catch((error) => console.error(error))
   }
 }

+ 12 - 12
src/core/Translator.js

@@ -14,8 +14,8 @@
 export default class Translator {
   constructor(opts) {
 
-    const defaultOptions = {};
-    this.opts = Object.assign({}, defaultOptions, opts);
+    const defaultOptions = {}
+    this.opts = Object.assign({}, defaultOptions, opts)
   }
 
   /**
@@ -30,26 +30,26 @@ export default class Translator {
   * @return {string} interpolated
   */
   interpolate(phrase, options) {
-    const replace = String.prototype.replace;
-    const dollarRegex = /\$/g;
-    const dollarBillsYall = '$$$$';
+    const replace = String.prototype.replace
+    const dollarRegex = /\$/g
+    const dollarBillsYall = '$$$$'
 
     for (let arg in options) {
       if (arg !== '_' && options.hasOwnProperty(arg)) {
         // Ensure replacement value is escaped to prevent special $-prefixed
         // regex replace tokens. the "$$$$" is needed because each "$" needs to
         // be escaped with "$" itself, and we need two in the resulting output.
-        var replacement = options[arg];
+        var replacement = options[arg]
         if (typeof replacement === 'string') {
-          replacement = replace.call(options[arg], dollarRegex, dollarBillsYall);
+          replacement = replace.call(options[arg], dollarRegex, dollarBillsYall)
         }
         // We create a new `RegExp` each time instead of using a more-efficient
         // string replace so that the same argument can be replaced multiple times
         // in the same phrase.
-        phrase = replace.call(phrase, new RegExp('%\\{'+arg+'\\}', 'g'), replacement);
+        phrase = replace.call(phrase, new RegExp('%\\{'+arg+'\\}', 'g'), replacement)
       }
     }
-    return phrase;
+    return phrase
   }
 
   /**
@@ -61,11 +61,11 @@ export default class Translator {
   */
   t(key, options) {
     if (options && options.smart_count) {
-      var plural = this.opts.locale.pluralize(options.smart_count);
-      return this.interpolate(this.opts.locale.strings[key][plural], options);
+      var plural = this.opts.locale.pluralize(options.smart_count)
+      return this.interpolate(this.opts.locale.strings[key][plural], options)
     }
 
-    return this.interpolate(this.opts.locale.strings[key], options);
+    return this.interpolate(this.opts.locale.strings[key], options)
   }
 
 }

+ 19 - 19
src/core/Utils.js

@@ -6,12 +6,12 @@
  * @return {Promise} of the final task
  */
 function promiseWaterfall(methods) {
-  const [resolvedPromise, ...tasks] = methods;
+  const [resolvedPromise, ...tasks] = methods
   const finalTaskPromise = tasks.reduce(function (prevTaskPromise, task) {
-    return prevTaskPromise.then(task);
-  }, resolvedPromise([]));  // initial value
+    return prevTaskPromise.then(task)
+  }, resolvedPromise([]))  // initial value
 
-  return finalTaskPromise;
+  return finalTaskPromise
 }
 
 /**
@@ -24,16 +24,16 @@ function promiseWaterfall(methods) {
  */
 function toggleClass(el, className) {
   if (el.classList) {
-    el.classList.toggle(className);
+    el.classList.toggle(className)
   } else {
-    const classes = el.className.split(' ');
-    const existingIndex = classes.indexOf(className);
+    const classes = el.className.split(' ')
+    const existingIndex = classes.indexOf(className)
 
     if (existingIndex >= 0) {
-      classes.splice(existingIndex, 1);
+      classes.splice(existingIndex, 1)
     } else {
-      classes.push(className);
-      el.className = classes.join(' ');
+      classes.push(className)
+      el.className = classes.join(' ')
     }
   }
 }
@@ -47,9 +47,9 @@ function toggleClass(el, className) {
  */
 function addClass(el, className) {
   if (el.classList) {
-    el.classList.add(className);
+    el.classList.add(className)
   } else {
-    el.className += ' ' + className;
+    el.className += ' ' + className
   }
 }
 
@@ -62,11 +62,11 @@ function addClass(el, className) {
  */
 function removeClass(el, className) {
   if (el.classList) {
-    el.classList.remove(className);
+    el.classList.remove(className)
   } else {
-    const patClasses = className.split(' ').join('|');
-    const pattern    = new RegExp('(^|\\b)' + patClasses + '(\\b|$)', 'gi');
-    el.className     = el.className.replace(pat, ' ');
+    const patClasses = className.split(' ').join('|')
+    const pattern    = new RegExp('(^|\\b)' + patClasses + '(\\b|$)', 'gi')
+    el.className     = el.className.replace(pat, ' ')
   }
 }
 
@@ -80,9 +80,9 @@ function removeClass(el, className) {
  * @return {String}
  */
 function addListenerMulti(el, events, cb) {
-  const eventsArray = events.split(' ');
+  const eventsArray = events.split(' ')
   for (let event in eventsArray) {
-    el.addEventListener(eventsArray[event], cb, false);
+    el.addEventListener(eventsArray[event], cb, false)
   }
 }
 
@@ -92,4 +92,4 @@ export default {
   addClass,
   removeClass,
   addListenerMulti
-};
+}

+ 1 - 1
src/core/index.js

@@ -1 +1 @@
-export default from './Core';
+export default from './Core'

+ 4 - 4
src/index.js

@@ -1,10 +1,10 @@
-import Core from './core';
-import plugins from './plugins';
+import Core from './core'
+import plugins from './plugins'
 
-const locale = {};
+const locale = {}
 
 export default {
   Core,
   plugins,
   locale
-};
+}

+ 7 - 7
src/locale/en_US.js

@@ -1,4 +1,4 @@
-const en_US = {};
+const en_US = {}
 
 en_US.strings = {
   'choose_file': 'Choose a file',
@@ -8,17 +8,17 @@ en_US.strings = {
     0: '%{smart_count} file selected',
     1: '%{smart_count} files selected'
   }
-};
+}
 
 en_US.pluralize = function (n) {
   if (n === 1) {
-    return 0;
+    return 0
   }
-  return 1;
-};
+  return 1
+}
 
 if (typeof Uppy !== 'undefined') {
-  Uppy.locale.en_US = en_US;
+  Uppy.locale.en_US = en_US
 }
 
-export default en_US;
+export default en_US

+ 8 - 8
src/locale/ru.js

@@ -1,4 +1,4 @@
-const ru = {};
+const ru = {}
 
 ru.strings = {
   'choose_file': 'Выберите файл',
@@ -10,22 +10,22 @@ ru.strings = {
     1: 'Выбрано %{smart_count} файла',
     2: 'Выбрано %{smart_count} файлов'
   }
-};
+}
 
 ru.pluralize = function (n) {
   if (n % 10 === 1 && n % 100 !== 11) {
-    return 0;
+    return 0
   }
 
   if (n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20)) {
-    return 1;
+    return 1
   }
 
-  return 2;
-};
+  return 2
+}
 
 if (typeof Uppy !== 'undefined') {
-  Uppy.locale.ru = ru;
+  Uppy.locale.ru = ru
 }
 
-export default ru;
+export default ru

+ 46 - 46
src/plugins/DragDrop.js

@@ -1,5 +1,5 @@
-import Utils from '../core/Utils';
-import Plugin from './Plugin';
+import Utils from '../core/Utils'
+import Plugin from './Plugin'
 
 /**
 * Drag & Drop plugin
@@ -7,33 +7,33 @@ import Plugin from './Plugin';
 */
 export default class DragDrop extends Plugin {
   constructor(core, opts) {
-    super(core, opts);
-    this.type = 'selecter';
+    super(core, opts)
+    this.type = 'selecter'
 
     // set default options
     const defaultOptions = {
       bla       : 'blabla',
       autoSubmit: true,
       modal     : true
-    };
+    }
 
     // merge default options with the ones set by user
-    this.opts = defaultOptions;
-    Object.assign(this.opts, opts);
+    this.opts = defaultOptions
+    Object.assign(this.opts, opts)
 
     // get the element where the Drag & Drop event will occur
-    this.dropzone      = document.querySelectorAll(this.opts.selector)[0];
-    this.dropzoneInput = document.querySelectorAll('.UppyDragDrop-input')[0];
+    this.dropzone      = document.querySelectorAll(this.opts.selector)[0]
+    this.dropzoneInput = document.querySelectorAll('.UppyDragDrop-input')[0]
 
-    this.status = document.querySelectorAll('.UppyDragDrop-status')[0];
+    this.status = document.querySelectorAll('.UppyDragDrop-status')[0]
 
-    this.isDragDropSupported = this.checkDragDropSupport();
+    this.isDragDropSupported = this.checkDragDropSupport()
 
     // crazy stuff so that ‘this’ will behave in class
-    this.listenForEvents      = this.listenForEvents.bind(this);
-    this.handleDrop           = this.handleDrop.bind(this);
-    this.checkDragDropSupport = this.checkDragDropSupport.bind(this);
-    this.handleInputChange    = this.handleInputChange.bind(this);
+    this.listenForEvents      = this.listenForEvents.bind(this)
+    this.handleDrop           = this.handleDrop.bind(this)
+    this.checkDragDropSupport = this.checkDragDropSupport.bind(this)
+    this.handleInputChange    = this.handleInputChange.bind(this)
   }
 
    /**
@@ -41,70 +41,70 @@ export default class DragDrop extends Plugin {
   * @return {object} true if supported, false otherwise
   */
   checkDragDropSupport() {
-    const div = document.createElement('div');
+    const div = document.createElement('div')
 
     if (!('draggable' in div) || !('ondragstart' in div && 'ondrop' in div)) {
-      return false;
+      return false
     }
 
     if (!('FormData' in window)) {
-      return false;
+      return false
     }
 
     if (!('FileReader' in window)) {
-      return false;
+      return false
     }
 
-    return true;
+    return true
   }
 
   listenForEvents() {
-    console.log(`waiting for some files to be dropped on ${this.opts.selector}`);
+    console.log(`waiting for some files to be dropped on ${this.opts.selector}`)
 
     if (this.isDragDropSupported) {
-      Utils.addClass(this.dropzone, 'is-dragdrop-supported');
+      Utils.addClass(this.dropzone, 'is-dragdrop-supported')
     }
 
     // prevent default actions for all drag & drop events
     Utils.addListenerMulti(this.dropzone, 'drag dragstart dragend dragover dragenter dragleave drop', (e) => {
-      e.preventDefault();
-      e.stopPropagation();
-    });
+      e.preventDefault()
+      e.stopPropagation()
+    })
 
     // Toggle is-dragover state when files are dragged over or dropped
     Utils.addListenerMulti(this.dropzone, 'dragover dragenter', (e) => {
-      Utils.addClass(this.dropzone, 'is-dragover');
-    });
+      Utils.addClass(this.dropzone, 'is-dragover')
+    })
 
     Utils.addListenerMulti(this.dropzone, 'dragleave dragend drop', (e) => {
-      Utils.removeClass(this.dropzone, 'is-dragover');
-    });
+      Utils.removeClass(this.dropzone, 'is-dragover')
+    })
 
     const onDrop = new Promise((resolve, reject) => {
       this.dropzone.addEventListener('drop', (e) => {
-        resolve(this.handleDrop.bind(null, e));
-      });
-    });
+        resolve(this.handleDrop.bind(null, e))
+      })
+    })
 
     const onInput = new Promise((resolve, reject) => {
       this.dropzoneInput.addEventListener('change', (e) => {
-        resolve(this.handleInputChange.bind(null, e));
-      });
-    });
+        resolve(this.handleInputChange.bind(null, e))
+      })
+    })
 
-    return Promise.race([onDrop, onInput]).then(handler => handler());
+    return Promise.race([onDrop, onInput]).then(handler => handler())
 
     // this.dropzone.addEventListener('drop', this.handleDrop);
     // this.dropzoneInput.addEventListener('change', this.handleInputChange);
   }
 
   displayStatus(status) {
-    this.status.innerHTML = status;
+    this.status.innerHTML = status
   }
 
   handleDrop(e) {
-    console.log('all right, someone dropped something here...');
-    const files = e.dataTransfer.files;
+    console.log('all right, someone dropped something here...')
+    const files = e.dataTransfer.files
     // files = Array.from(files);
 
     // const formData = new FormData(this.dropzone);
@@ -115,17 +115,17 @@ export default class DragDrop extends Plugin {
     //   console.log('pizza', files[i]);
     // }
 
-    return Promise.resolve({from: 'DragDrop', files: files});
+    return Promise.resolve({from: 'DragDrop', files: files})
   }
 
   handleInputChange() {
     // const fileInput = document.querySelectorAll('.UppyDragDrop-input')[0];
-    const formData = new FormData(this.dropzone);
+    const formData = new FormData(this.dropzone)
 
-    console.log('@todo: No support for formData yet', formData);
-    const files = [];
+    console.log('@todo: No support for formData yet', formData)
+    const files = []
 
-    return Promise.resolve({from: 'DragDrop', files: files});
+    return Promise.resolve({from: 'DragDrop', files: files})
   }
 
   run(results) {
@@ -133,8 +133,8 @@ export default class DragDrop extends Plugin {
       class  : 'DragDrop',
       method : 'run',
       results: results
-    });
+    })
 
-    return this.listenForEvents();
+    return this.listenForEvents()
   }
 }

+ 41 - 41
src/plugins/Dropbox.js

@@ -1,32 +1,32 @@
-import Utils from '../core/Utils';
-import Plugin from './Plugin';
-import request from 'superagent';
+import Utils from '../core/Utils'
+import Plugin from './Plugin'
+import request from 'superagent'
 
 export default class Dropbox extends Plugin {
   constructor(core, opts) {
-    super(core, opts);
-    this.type = 'selecter';
-    this.authenticate = this.authenticate.bind(this);
-    this.connect = this.connect.bind(this);
-    this.render = this.render.bind(this);
-    this.files = [];
-    this.currentDir = '/';
+    super(core, opts)
+    this.type = 'selecter'
+    this.authenticate = this.authenticate.bind(this)
+    this.connect = this.connect.bind(this)
+    this.render = this.render.bind(this)
+    this.files = []
+    this.currentDir = '/'
   }
 
   connect(target) {
-    this._target = document.getElementById(target);
+    this._target = document.getElementById(target)
 
-    this.client = new Dropbox.Client({ key: 'b7dzc9ei5dv5hcv', token: '' });
-    this.client.authDriver(new Dropbox.AuthDriver.Redirect());
-    this.authenticate();
+    this.client = new Dropbox.Client({ key: 'b7dzc9ei5dv5hcv', token: '' })
+    this.client.authDriver(new Dropbox.AuthDriver.Redirect())
+    this.authenticate()
 
     if (this.client.credentials().token) {
-      this.getDirectory();
+      this.getDirectory()
     }
   }
 
   authenticate() {
-    this.client.authenticate();
+    this.client.authenticate()
   }
 
   addFile() {
@@ -41,15 +41,15 @@ export default class Dropbox extends Plugin {
       })
       .set('Content-Type', 'application/json')
       .end((err, res) => {
-        console.log(res);
-      });
+        console.log(res)
+      })
 
     return this.client.readdir(this.currentDir, (error, entries, stat, statFiles) => {
       if (error) {
-        return showError(error);  // Something went wrong.
+        return showError(error)  // Something went wrong.
       }
-      return this.render(statFiles);
-    });
+      return this.render(statFiles)
+    })
   }
 
   run(results) {
@@ -59,44 +59,44 @@ export default class Dropbox extends Plugin {
   render(files) {
     // for each file in the directory, create a list item element
     const elems = files.map((file, i) => {
-      const icon = (file.isFolder) ? 'folder' : 'file';
-      return `<li data-type="${icon}" data-name="${file.name}"><span>${icon} : </span><span> ${file.name}</span></li>`;
-    });
+      const icon = (file.isFolder) ? 'folder' : 'file'
+      return `<li data-type="${icon}" data-name="${file.name}"><span>${icon} : </span><span> ${file.name}</span></li>`
+    })
 
     // appends the list items to the target
-    this._target.innerHTML = elems.sort().join('');
+    this._target.innerHTML = elems.sort().join('')
 
     if (this.currentDir.length > 1) {
-      const parent = document.createElement('LI');
-      parent.setAttribute('data-type', 'parent');
-      parent.innerHTML = '<span>...</span>';
-      this._target.appendChild(parent);
+      const parent = document.createElement('LI')
+      parent.setAttribute('data-type', 'parent')
+      parent.innerHTML = '<span>...</span>'
+      this._target.appendChild(parent)
     }
 
     // add an onClick to each list item
-    const fileElems = this._target.querySelectorAll('li');
+    const fileElems = this._target.querySelectorAll('li')
 
     Array.prototype.forEach.call(fileElems, element => {
-      const type = element.getAttribute('data-type');
+      const type = element.getAttribute('data-type')
 
       if (type === 'file') {
         element.addEventListener('click', () => {
-          this.files.push(element.getAttribute('data-name'));
-          console.log(`files: ${this.files}`);
-        });
+          this.files.push(element.getAttribute('data-name'))
+          console.log(`files: ${this.files}`)
+        })
       } else {
         element.addEventListener('dblclick', () => {
-          const length = this.currentDir.split('/').length;
+          const length = this.currentDir.split('/').length
 
           if (type === 'folder') {
-            this.currentDir = `${this.currentDir}${element.getAttribute('data-name')}/`;
+            this.currentDir = `${this.currentDir}${element.getAttribute('data-name')}/`
           } else if (type === 'parent') {
-            this.currentDir = `${this.currentDir.split('/').slice(0, length - 2).join('/')}/`;
+            this.currentDir = `${this.currentDir.split('/').slice(0, length - 2).join('/')}/`
           }
-          console.log(this.currentDir);
-          this.getDirectory();
-        });
+          console.log(this.currentDir)
+          this.getDirectory()
+        })
       }
-    });
+    })
   }
 }

+ 14 - 14
src/plugins/Formtag.js

@@ -1,9 +1,9 @@
-import Plugin from './Plugin';
+import Plugin from './Plugin'
 
 export default class Formtag extends Plugin {
   constructor(core, opts) {
-    super(core, opts);
-    this.type = 'selecter';
+    super(core, opts)
+    this.type = 'selecter'
   }
 
   run(results) {
@@ -11,17 +11,17 @@ export default class Formtag extends Plugin {
       class  : 'Formtag',
       method : 'run',
       results: results
-    });
+    })
 
-    this.setProgress(0);
+    this.setProgress(0)
 
-    const button = document.querySelector(this.opts.doneButtonSelector);
-    var self     = this;
+    const button = document.querySelector(this.opts.doneButtonSelector)
+    var self     = this
 
     return new Promise((resolve, reject) => {
       button.addEventListener('click', (e) => {
-        var fields   = document.querySelectorAll(self.opts.selector);
-        var files    = [];
+        var fields   = document.querySelectorAll(self.opts.selector)
+        var files    = []
         var selected = [];
 
         [].forEach.call(fields, (field, i) => {
@@ -31,7 +31,7 @@ export default class Formtag extends Plugin {
               file: file
             })
           })
-        });
+        })
 
         // console.log(fields.length);
         // for (var i in fields) {
@@ -50,13 +50,13 @@ export default class Formtag extends Plugin {
         //     }
         //   }
         // }
-        self.setProgress(100);
+        self.setProgress(100)
         console.log({
           selected:selected,
           fields  :fields
         })
-        resolve(selected);
-      });
-    });
+        resolve(selected)
+      })
+    })
   }
 }

+ 28 - 28
src/plugins/Multipart.js

@@ -1,14 +1,14 @@
-import Plugin from './Plugin';
+import Plugin from './Plugin'
 
 export default class Multipart extends Plugin {
   constructor(core, opts) {
-    super(core, opts);
-    this.type = 'uploader';
+    super(core, opts)
+    this.type = 'uploader'
     if (!this.opts.fieldName === undefined) {
-      this.opts.fieldName = 'files[]';
+      this.opts.fieldName = 'files[]'
     }
     if (this.opts.bundle === undefined) {
-      this.opts.bundle = true;
+      this.opts.bundle = true
     }
   }
 
@@ -17,58 +17,58 @@ export default class Multipart extends Plugin {
       class  : 'Multipart',
       method : 'run',
       results: results
-    });
+    })
 
-    const files = this.extractFiles(results);
+    const files = this.extractFiles(results)
 
-    this.setProgress(0);
-    var uploaders = [];
+    this.setProgress(0)
+    var uploaders = []
 
     if (this.opts.bundle) {
-      uploaders.push(this.upload(files, 0, files.length));
+      uploaders.push(this.upload(files, 0, files.length))
     } else {
       for (let i in files) {
-        uploaders.push(this.upload(files, i, files.length));
+        uploaders.push(this.upload(files, i, files.length))
       }
     }
 
-    return Promise.all(uploaders);
+    return Promise.all(uploaders)
   }
 
   upload(files, current, total) {
-    var formPost = new FormData();
+    var formPost = new FormData()
 
     // turn file into an array so we can use bundle
     if (!this.opts.bundle) {
-      files = [files[current]];
+      files = [files[current]]
     }
 
     for (let i in files) {
-      formPost.append(this.opts.fieldName, files[i]);
+      formPost.append(this.opts.fieldName, files[i])
     }
 
-    var xhr = new XMLHttpRequest();
-    xhr.open('POST', this.opts.endpoint, true);
+    var xhr = new XMLHttpRequest()
+    xhr.open('POST', this.opts.endpoint, true)
 
     xhr.addEventListener('progress', (e) => {
-      var percentage = (e.loaded / e.total * 100).toFixed(2);
-      this.setProgress(percentage, current, total);
-    });
+      var percentage = (e.loaded / e.total * 100).toFixed(2)
+      this.setProgress(percentage, current, total)
+    })
 
     xhr.addEventListener('load', () => {
-      var upload = {};
+      var upload = {}
       if (this.opts.bundle) {
-        upload = {files: files};
+        upload = {files: files}
       } else {
-        upload = {file: files[current]};
+        upload = {file: files[current]}
       }
-      return Promise.resolve(upload);
-    });
+      return Promise.resolve(upload)
+    })
 
     xhr.addEventListener('error', () => {
-      return Promise.reject('fucking error!');
-    });
+      return Promise.reject('fucking error!')
+    })
 
-    xhr.send(formPost);
+    xhr.send(formPost)
   }
 }

+ 12 - 12
src/plugins/Plugin.js

@@ -10,14 +10,14 @@
 export default class Plugin {
 
   constructor(core, opts) {
-    this.core = core;
-    this.opts = opts;
-    this.type = 'none';
-    this.name = this.constructor.name;
+    this.core = core
+    this.opts = opts
+    this.type = 'none'
+    this.name = this.constructor.name
   }
 
   setProgress(percentage, current, total) {
-    var finalPercentage = percentage;
+    var finalPercentage = percentage
 
     // if (current !== undefined && total !== undefined) {
     //   var percentageOfTotal = (percentage / total);
@@ -29,7 +29,7 @@ export default class Plugin {
     //   }
     // }
 
-    this.core.setProgress(this, finalPercentage);
+    this.core.setProgress(this, finalPercentage)
   }
 
   extractFiles(results) {
@@ -37,12 +37,12 @@ export default class Plugin {
       class  : 'Plugin',
       method : 'extractFiles',
       results: results
-    });
+    })
 
-    const files = [];
+    const files = []
     results.forEach(result => {
-      Array.from(result.files).forEach(file => files.push(file));
-    });
+      Array.from(result.files).forEach(file => files.push(file))
+    })
 
     // const files = [];
     // for (let i in results) {
@@ -55,10 +55,10 @@ export default class Plugin {
     // }
 
     // return Array.from(fileList);
-    return files;
+    return files
   }
 
   run(results) {
-    return results;
+    return results
   }
 }

+ 3 - 3
src/plugins/TransloaditBasic.js

@@ -1,9 +1,9 @@
-import Plugin from './Plugin';
+import Plugin from './Plugin'
 
 class TransloaditBasic extends Plugin {
   constructor(core, opts) {
-    super(core, opts);
-    this.type = 'presetter';
+    super(core, opts)
+    this.type = 'presetter'
     this.core
       .use(DragDrop, {modal: true, wait: true})
       .use(Tus10, {endpoint: 'http://master.tus.io:8080'})

+ 23 - 23
src/plugins/Tus10.js

@@ -1,5 +1,5 @@
-import Plugin from './Plugin';
-import tus from 'tus-js-client';
+import Plugin from './Plugin'
+import tus from 'tus-js-client'
 
 /**
 * Tus resumable file uploader
@@ -7,8 +7,8 @@ import tus from 'tus-js-client';
 */
 export default class Tus10 extends Plugin {
   constructor(core, opts) {
-    super(core, opts);
-    this.type = 'uploader';
+    super(core, opts)
+    this.type = 'uploader'
   }
 
   /**
@@ -22,23 +22,23 @@ export default class Tus10 extends Plugin {
       class  : 'Tus10',
       method : 'run',
       results: results
-    });
+    })
 
-    const files = this.extractFiles(results);
+    const files = this.extractFiles(results)
 
     // console.log(files);
 
-    this.setProgress(0);
+    this.setProgress(0)
     // var uploaded  = [];
-    const uploaders = [];
+    const uploaders = []
     for (let i in files) {
-      const file = files[i];
-      const current = parseInt(i) + 1;
-      const total = files.length;
-      uploaders.push(this.upload(file, current, total));
+      const file = files[i]
+      const current = parseInt(i) + 1
+      const total = files.length
+      uploaders.push(this.upload(file, current, total))
     }
 
-    return Promise.all(uploaders);
+    return Promise.all(uploaders)
   }
 
   /**
@@ -50,25 +50,25 @@ export default class Tus10 extends Plugin {
  * @returns {Promise}
  */
   upload(file, current, total) {
-    console.log(`uploading ${current} of ${total}`);
+    console.log(`uploading ${current} of ${total}`)
     // Create a new tus upload
-    const self = this;
+    const self = this
     const upload = new tus.Upload(file, {
       endpoint: this.opts.endpoint,
       onError: function (error) {
-        return Promise.reject('Failed because: ' + error);
+        return Promise.reject('Failed because: ' + error)
       },
       onProgress: function (bytesUploaded, bytesTotal) {
-        let percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
-        percentage = Math.round(percentage);
-        self.setProgress(percentage, current, total);
+        let percentage = (bytesUploaded / bytesTotal * 100).toFixed(2)
+        percentage = Math.round(percentage)
+        self.setProgress(percentage, current, total)
       },
       onSuccess: function () {
-        console.log(`Download ${upload.file.name} from ${upload.url}`);
-        return Promise.resolve(upload);
+        console.log(`Download ${upload.file.name} from ${upload.url}`)
+        return Promise.resolve(upload)
       }
-    });
+    })
     // Start the upload
-    upload.start();
+    upload.start()
   }
 }

+ 8 - 8
src/plugins/index.js

@@ -1,17 +1,17 @@
 // Parent
-import Plugin from './Plugin';
+import Plugin from './Plugin'
 
 // Selecters
-import DragDrop from './DragDrop';
-import Dropbox from './Dropbox';
-import Formtag from './Formtag';
+import DragDrop from './DragDrop'
+import Dropbox from './Dropbox'
+import Formtag from './Formtag'
 
 // Uploaders
-import Tus10 from './Tus10';
-import Multipart from './Multipart';
+import Tus10 from './Tus10'
+import Multipart from './Multipart'
 
 // Presetters
-import TransloaditBasic from './TransloaditBasic';
+import TransloaditBasic from './TransloaditBasic'
 
 export default {
   Plugin,
@@ -21,4 +21,4 @@ export default {
   Tus10,
   Multipart,
   TransloaditBasic
-};
+}