From 01a25dab39a6f1e129773e9ad8bb9521eb1df5a0 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 15 Apr 2014 09:32:11 -0400 Subject: [PATCH] feature(key) f3: add parse markdown on shift --- json/modules.json | 1 + lib/client.js | 7 +++-- lib/client/help.js | 33 +++++---------------- lib/client/key.js | 5 +++- lib/client/markdown.js | 67 ++++++++++++++++++++++++++++++++++++++++++ lib/util.js | 15 ++++++++++ 6 files changed, 99 insertions(+), 29 deletions(-) create mode 100644 lib/client/markdown.js diff --git a/json/modules.json b/json/modules.json index c3f86976..c4faf05b 100644 --- a/json/modules.json +++ b/json/modules.json @@ -3,6 +3,7 @@ "menu", "view", "help", + "markdown", "config", "contact", "socket", diff --git a/lib/client.js b/lib/client.js index 08cdd41a..ed3104e6 100644 --- a/lib/client.js +++ b/lib/client.js @@ -113,8 +113,9 @@ var Util, DOM, CloudFunc; path += '.js'; if (!CloudCmd[name]) { - CloudCmd[name] = function(arg) { - var pathFull = CloudCmd.LIBDIRCLIENT + path; + CloudCmd[name] = function() { + var pathFull = CloudCmd.LIBDIRCLIENT + path, + args = arguments; Util.exec(doBefore); @@ -123,7 +124,7 @@ var Util, DOM, CloudFunc; var Proto = CloudCmd[name]; if (Util.isFunction(Proto)) - CloudCmd[name] = new Proto(arg); + CloudCmd[name] = Util.applyConstructor(Proto, args); }); }; diff --git a/lib/client/help.js b/lib/client/help.js index 3a26bb7f..06fe4436 100644 --- a/lib/client/help.js +++ b/lib/client/help.js @@ -6,39 +6,22 @@ var CloudCmd, Util, DOM; function HelpProto() { var Images = DOM.Images, - RESTful = DOM.RESTful, - Markdown = RESTful.Markdown, Help = this; function init() { Images.showLoad({ - top:true + top: true }); - - Util.loadOnLoad([ - CloudCmd.View, - Help.show, - ]); + Help.show(); } this.show = function() { - var name = '/HELP.md?relative'; - - Images.showLoad({ - top:true - }); - - Markdown.read(name, function(result) { - var div = DOM.anyload({ - name : 'div', - className : 'help', - inner : result - }); - - Images.hideLoad(); - - CloudCmd.View.show(div); - }); + CloudCmd + .Markdown + .show('/HELP.md', { + topLoad : true, + relative: true + }); }; this.hide = function() { diff --git a/lib/client/key.js b/lib/client/key.js index 18b1f10f..c51588ae 100644 --- a/lib/client/key.js +++ b/lib/client/key.js @@ -234,7 +234,10 @@ var CloudCmd, Util, DOM; break; case Key.F3: - Util.exec(CloudCmd.View.show); + if (shift) + Util.exec(CloudCmd.Markdown.show, path); + else + Util.exec(CloudCmd.View.show); DOM.preventDefault(event); break; diff --git a/lib/client/markdown.js b/lib/client/markdown.js new file mode 100644 index 00000000..5a6785e9 --- /dev/null +++ b/lib/client/markdown.js @@ -0,0 +1,67 @@ +var CloudCmd, Util, DOM; +(function(CloudCmd, Util, DOM){ + 'use strict'; + + CloudCmd.Markdown = MarkdownProto; + + function MarkdownProto(nameParam, optionsParam) { + var Images = DOM.Images, + RESTful = DOM.RESTful, + Markdown = RESTful.Markdown, + MD = this; + + function init() { + Images.showLoad({ + top:true + }); + + Util.loadOnLoad([ + CloudCmd.View, + Util.bind(MD.show, null, null), + ]); + } + + this.show = function(name, options) { + var o = options, + relativeQuery = '?relative'; + + if (!name) + name = nameParam; + + if (!options) + o = + options = optionsParam; + + if (options) { + Images.showLoad({ + top: o.topLoad + }); + + if (o.relative) + name += relativeQuery; + } + + Markdown.read(name, function(result) { + var div = DOM.anyload({ + name : 'div', + className : 'help', + inner : result + }); + + Images.hideLoad(); + + CloudCmd.View.show(div); + + nameParam = + optionsParam = null; + }); + }; + + this.hide = function() { + CloudCmd.View.hide(); + }; + + init(); + } + +})(CloudCmd, Util, DOM); diff --git a/lib/util.js b/lib/util.js index b3a711db..76fcd76e 100644 --- a/lib/util.js +++ b/lib/util.js @@ -67,6 +67,21 @@ return result; }; + /* + * apply arguemnts to constructor + * + * @param constructo + * @param args + */ + this.applyConstructor = function(constructor, args) { + var F = function () { + return constructor.apply(this, args); + }; + + F.prototype = constructor.prototype; + return new F(); + }; + /** * Функция ищет в имени файла расширение * и если находит возвращает true