From 750ab79d4c976d847debf8db8c835861bb4b0326 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 16 Feb 2017 11:57:13 +0200 Subject: [PATCH] chore(upload) es2015-ify --- client/upload.js | 117 ++++++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 53 deletions(-) diff --git a/client/upload.js b/client/upload.js index 2a32e411..6884da02 100644 --- a/client/upload.js +++ b/client/upload.js @@ -1,63 +1,74 @@ -/* global CloudCmd, Util, DOM */ +/* global CloudCmd, DOM */ 'use strict'; +const exec = require('execon'); + +const load = require('./load'); +const Files = require('./files'); + CloudCmd.Upload = UploadProto; function UploadProto() { - var Images = DOM.Images, - Files = DOM.Files, - - Upload = this; + Images.show.load('top'); - function init() { - Images.show.load('top'); - - Util.exec.series([ - CloudCmd.View, - Upload.show - ]); - } + exec.series([ + CloudCmd.View, + show + ]); - this.show = function() { - Images.show.load('top'); - - Files.get('upload', function(error, data) { - CloudCmd.View.show(data, { - autoSize : true, - afterShow : afterShow - }); - }); - - DOM.load.style({ - id : 'upload-css', - inner : '[data-name=js-upload-file-button] {' + - 'font-family: "Droid Sans Mono", "Ubuntu Mono", "Consolas", monospace;' + - 'font-size: 20px;' + - 'width: 97%' + - '}' - }); - - }; - - this.hide = function() { - CloudCmd.View.hide(); - }; - - function afterShow() { - var button = DOM.getByDataName('js-upload-file-button'); - - Images.hide(); - - DOM.Events.add('change', button, (event) => { - const files = event.target.files; - - Upload.hide(); - - DOM.uploadFiles(files); - }); - } - - init(); + return exports; +} + +const {Images} = DOM; + +module.exports.show = show; +module.exports.hide = hide; + +function show() { + Images.show.load('top'); + + Files.get('upload', (error, data) => { + const autoSize = true; + + CloudCmd.View.show(data, { + autoSize, + afterShow, + }); + }); + + const fontFamily = [ + '"Droid Sans Mono"', + '"Ubuntu Mono"', + '"Consolas"', + 'monospace' + ].join(', '); + + load.style({ + id : 'upload-css', + inner : '[data-name=js-upload-file-button] {' + + `font-family: ${fontFamily};` + + 'font-size: 20px;' + + 'width: 97%' + + '}' + }); +} + +function hide() { + CloudCmd.View.hide(); +} + +function afterShow() { + const button = DOM.getByDataName('js-upload-file-button'); + + Images.hide(); + + DOM.Events.add('change', button, ({target}) => { + const {files} = target; + + hide(); + + DOM.uploadFiles(files); + }); }