From f4ffdffa824148608c6d84d5c209b7239e12dc13 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 13 May 2014 02:25:50 -0400 Subject: [PATCH] feature(view) show: data, callback, newConfig -> data, options --- lib/client/config.js | 5 ++-- lib/client/console.js | 60 ++++++++++++++++++++++-------------------- lib/client/edit.js | 5 ++-- lib/client/terminal.js | 21 ++++++++------- lib/client/view.js | 17 +++++------- 5 files changed, 55 insertions(+), 53 deletions(-) diff --git a/lib/client/config.js b/lib/client/config.js index 97dd1805..ccaed44d 100644 --- a/lib/client/config.js +++ b/lib/client/config.js @@ -83,8 +83,9 @@ var CloudCmd, Util, DOM; Events.addKey(key, input); } - CloudCmd.View.show(div, focus, { - autoSize: true + CloudCmd.View.show(div, { + autoSize: true, + afterShow: focus }); }); } diff --git a/lib/client/console.js b/lib/client/console.js index 22cc9dbe..3a530039 100644 --- a/lib/client/console.js +++ b/lib/client/console.js @@ -74,38 +74,40 @@ var CloudCmd, Util, DOM, CloudFunc, $; handler(); } - CloudCmd.View.show(Element, function() { - var console = jqconsole.$console, - input = jqconsole.$input_source, - - focus = function() { - var x = window.scrollX, - y = window.scrollY; + CloudCmd.View.show(Element, { + afterShow: function() { + var console = jqconsole.$console, + input = jqconsole.$input_source, - input.focus(); - window.scrollTo(x,y); - }; - - focus(); - - if (!MouseBinded) { - MouseBinded = true; - - console.unbind('mouseup'); - console.mouseup(function() { - var top, - isSelection = '' + window.getSelection(); - - if (!isSelection) { - top = console.scrollTop(); + focus = function() { + var x = window.scrollX, + y = window.scrollY; - focus(); - console.scrollTop(top); - } - }); + input.focus(); + window.scrollTo(x,y); + }; + + focus(); + + if (!MouseBinded) { + MouseBinded = true; + + console.unbind('mouseup'); + console.mouseup(function() { + var top, + isSelection = '' + window.getSelection(); + + if (!isSelection) { + top = console.scrollTop(); + + focus(); + console.scrollTop(top); + } + }); + } + + Util.exec(callback); } - - Util.exec(callback); }); } } diff --git a/lib/client/edit.js b/lib/client/edit.js index 7f611505..01da3f8f 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -89,8 +89,9 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip; var UndoManager = ace.require('ace/undomanager').UndoManager; Ace.setValue(Value); - CloudCmd.View.show(Element, focus, { - beforeClose: isChanged + CloudCmd.View.show(Element, { + beforeClose: isChanged, + afterShow: focus }); Session.setUndoManager(new UndoManager()); diff --git a/lib/client/terminal.js b/lib/client/terminal.js index 409de59e..0336d4d7 100644 --- a/lib/client/terminal.js +++ b/lib/client/terminal.js @@ -45,10 +45,6 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal; CloudTerm.write = write; function show(callback) { - var options = { - onUpdate: onResize, - }; - if (!Loading) { Images.showLoad({top:true}); @@ -90,12 +86,10 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal; Term.open(Element); } - CloudCmd.View.show(Element, function() { - Element.focus(); - Terminal.brokenBold = true; - - Util.exec(callback); - }, options); + CloudCmd.View.show(Element, { + onUpdate : onResize, + afterShow : afterShow.bind(null, callback) + }); } } @@ -165,6 +159,13 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal; } } + function afterShow(callback) { + Element.focus(); + Terminal.brokenBold = true; + + Util.exec(callback); + } + function load(callback) { var dir = CloudCmd.LIBDIRCLIENT + 'terminal/', path = dir + 'term.js'; diff --git a/lib/client/view.js b/lib/client/view.js index 0a2e3130..fbe9f553 100644 --- a/lib/client/view.js +++ b/lib/client/view.js @@ -71,8 +71,8 @@ var CloudCmd, Util, DOM, CloudFunc, $; /** * function shows FancyBox */ - function show(data, callback, newConfig) { - var path, element, func, + function show(data, options) { + var path, element, config = {}; if (!Loading) { @@ -80,24 +80,21 @@ var CloudCmd, Util, DOM, CloudFunc, $; if (data) { element = $(Element).append(data); - func = Util.retExec(callback); - - Config.afterShow = func; - + Util.copyObj(config, Config); - if (newConfig) - Object.keys(newConfig).forEach(function(name) { + if (options) + Object.keys(options).forEach(function(name) { var func, asyncCall = Util.asyncCall, - item = newConfig[name], + item = options[name], isFunc = Util.isFunction(item); if (isFunc) { func = config[name]; config[name] = Util.bind(asyncCall, [item, func]); } else { - config[name] = newConfig[name]; + config[name] = options[name]; } });