From 3a62894312b436b431204dee18bfd982bfa53d85 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 13 Jan 2015 04:43:14 -0500 Subject: [PATCH] feature(edward) add showMessage --- lib/client/edit.js | 35 +++++++++-------------------------- lib/client/edward.js | 44 ++++++++++++++++++++++++++++++++------------ 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/lib/client/edit.js b/lib/client/edit.js index 9d88ad9f..a1149206 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -1,4 +1,4 @@ -var CloudCmd, Util, DOM, CloudFunc, io, ace, Zip, MenuIO, Format; +var CloudCmd, Util, DOM, CloudFunc, io, ace, Zip, MenuIO, Format, edward; (function(CloudCmd, Util, DOM, CloudFunc) { 'use strict'; @@ -40,16 +40,18 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, Zip, MenuIO, Format; }; function init(callback) { + var element = createElement(); + exec.series([ CloudCmd.View, - loadFiles, + function(callback) { + loadFiles(element, callback); + }, function(callback) { DOM.loadSocket(initSocket); callback(); }, function(callback) { - var element = createElement(); - Edit.create(element) .show(callback); @@ -560,7 +562,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, Zip, MenuIO, Format; } } - function loadFiles(callback) { + function loadFiles(element, callback) { var dir = CloudCmd.LIBDIRCLIENT, name = 'edward', url = dir + name + '.js'; @@ -570,7 +572,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, Zip, MenuIO, Format; DOM.load.js(url, function() { Loading = false; - window.edward(null, function() { + edward(element, function() { Util.timeEnd(Name + ' load'); exec(callback); }); @@ -642,26 +644,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, Zip, MenuIO, Format; } this.showMessage = function(text) { - var msg, HIDE_TIME = 2000; - - /* - * Msg should be created and removed - * if it's not and just inner text - * is changing, and hide and show of DOM - * is called - bug occures: empty box - * with no text inside. - */ - msg = DOM.load({ - name : 'div', - className : 'edward-msg', - parent : Element, - inner : text, - func : alert - }); - - setTimeout(function() { - DOM.remove(msg, Element); - }, HIDE_TIME); + edward.showMessage(text); }; init(callback); diff --git a/lib/client/edward.js b/lib/client/edward.js index 8e21d97a..16238584 100644 --- a/lib/client/edward.js +++ b/lib/client/edward.js @@ -4,21 +4,39 @@ var join, Util, DOM; 'use strict'; if (typeof module !== 'undefined' && module.exports) - module.exports = edward; + module.exports = new edward(); else - global.edward = edward; + global.edward = new edward(); - function edward(el, callback) { - var Element = el || document.body; - - if (!(this instanceof edward)) - return new edward(Element, callback); - - init(callback); - - function init(callback) { + function edward() { + var Element, + ed = function(el, callback) { + Element = el || document.body; loadFiles(callback); - } + }; + + ed.showMessage = function(text) { + var msg, HIDE_TIME = 2000; + + /* + * Msg should be created and removed + * if it's not and just inner text + * is changing, and hide and show of DOM + * is called - bug occures: empty box + * with no text inside. + */ + msg = DOM.load({ + name : 'div', + className : 'edward-msg', + parent : Element, + inner : text, + func : alert + }); + + setTimeout(function() { + DOM.remove(msg, Element); + }, HIDE_TIME); + }; function loadFiles(callback) { var css = '/css/edward.css', @@ -38,6 +56,8 @@ var join, Util, DOM; }); }); } + + return ed; } })(this, join, DOM, Util.exec);