From ab196b35a65697ac5be162bd99ed82a231f179c7 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 21 Feb 2017 16:53:02 +0200 Subject: [PATCH] refactor(markdown) es2015-ify --- client/markdown.js | 98 +++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/client/markdown.js b/client/markdown.js index 5d8fbd7c..0b700266 100644 --- a/client/markdown.js +++ b/client/markdown.js @@ -1,56 +1,58 @@ 'use strict'; -/*global CloudCmd, Util, DOM */ +/*global CloudCmd */ -window.CloudCmd.Markdown = MarkdownProto; +CloudCmd.Markdown = MarkdownProto; -function MarkdownProto(nameParam, optionsParam) { - var Images = DOM.Images, - RESTful = DOM.RESTful, - Markdown = RESTful.Markdown, - MD = this; - - function init() { - Images.show.load('top'); - - Util.exec.series([ - CloudCmd.View, - Util.exec.with(MD.show, null, null), - ]); - } +const exec = require('execon'); + +const Images = require('./images'); +const load = require('./load'); +const {Markdown} = require('./rest'); + +function MarkdownProto(name, options) { + Images.show.load('top'); - this.show = function(name, options) { - var o = options || optionsParam || {}, - relativeQuery = '?relative'; - - if (!name) - name = nameParam; - - Images.show.load(o.positionLoad); - - if (o.relative) - name += relativeQuery; - - Markdown.read(name, function(error, result) { - var div = DOM.load({ - name : 'div', - className : 'help', - inner : result - }); - - Images.hide(); - - CloudCmd.View.show(div); - - nameParam = - optionsParam = null; - }); - }; + exec.series([ + CloudCmd.View, + exec.with(show, name, options), + ]); - this.hide = function() { - CloudCmd.View.hide(); - }; - - init(); + return module.exports; +} + +module.exports.show = show; + +module.exports.hide = () => { + CloudCmd.View.hide(); +}; + + +function show(name, options = {}) { + const relativeQuery = '?relative'; + const { + positionLoad, + relative, + } = options; + + Images.show.load(positionLoad); + + if (relative) + name += relativeQuery; + + Markdown.read(name, (error, inner) => { + const name = 'div'; + const className = 'help'; + + const div = load({ + name, + className, + inner, + }); + + Images.hide(); + + CloudCmd.View.show(div); + }); }