diff --git a/lib/client/jq_console.js b/lib/client/jq_console.js index b1afb060..02724742 100644 --- a/lib/client/jq_console.js +++ b/lib/client/jq_console.js @@ -6,15 +6,18 @@ var CloudCmd, Util, DOM, $; function ConsoleProto(CloudCmd, Util, DOM){ var Name = 'Console', + Element, Key = CloudCmd.Key, Images = DOM.Images, Console = this; this.init = function(pCallBack){ + var lViewFunc = CloudCmd.View.show || CloudCmd.View; + Util.loadOnLoad([ Console.show, load, - CloudCmd.View, + lViewFunc, DOM.jqueryLoad, ]); @@ -24,67 +27,69 @@ var CloudCmd, Util, DOM, $; }; this.show = function(){ - var lElement, jqconsole; + var jqconsole; Images.showLoad({top:true}); - lElement = DOM.anyload({ - name : 'div', - className : 'console' - }); - - jqconsole = $(lElement).jqconsole('header', 'JS> '); - - // Abort prompt on Ctrl+Z. - jqconsole.RegisterShortcut('Z', function() { - jqconsole.AbortPrompt(); - handler(); - }); + if (!Element) { + Element = DOM.anyload({ + name : 'div', + className : 'console' + }); - // Move to line start Ctrl+A. - jqconsole.RegisterShortcut('A', function() { - jqconsole.MoveToStart(); - handler(); - }); - - // Move to line end Ctrl+E. - jqconsole.RegisterShortcut('E', function() { - jqconsole.MoveToEnd(); - handler(); - }); - - jqconsole.RegisterMatching('{', '}', 'brace'); - jqconsole.RegisterMatching('(', ')', 'paran'); - jqconsole.RegisterMatching('[', ']', 'bracket'); - // Handle a command. - var handler = function(command) { - if (command) { - try { - jqconsole.Write('==> ' + window.eval(command) + '\n'); - } catch (e) { - jqconsole.Write('ERROR: ' + e.message + '\n'); + jqconsole = $(Element).jqconsole('header', 'JS> '); + // Abort prompt on Ctrl+Z. + jqconsole.RegisterShortcut('Z', function() { + jqconsole.AbortPrompt(); + handler(); + }); + + // Move to line start Ctrl+A. + jqconsole.RegisterShortcut('A', function() { + jqconsole.MoveToStart(); + handler(); + }); + + // Move to line end Ctrl+E. + jqconsole.RegisterShortcut('E', function() { + jqconsole.MoveToEnd(); + handler(); + }); + + jqconsole.RegisterMatching('{', '}', 'brace'); + jqconsole.RegisterMatching('(', ')', 'paran'); + jqconsole.RegisterMatching('[', ']', 'bracket'); + // Handle a command. + var handler = function(command) { + if (command) { + try { + jqconsole.Write('==> ' + window.eval(command) + '\n'); + } catch (e) { + jqconsole.Write('ERROR: ' + e.message + '\n'); + } } - } - jqconsole.Prompt(true, handler, function(command) { - // Continue line if can't compile the command. - try { - Function(command); - } catch (e) { - if (/[\[\{\(]$/.test(command)) { - return 1; - } else { - return 0; - } - } - return false; - }); - }; - - // Initiate the first prompt. - handler(); - + jqconsole.Prompt(true, handler, function(command) { + // Continue line if can't compile the command. + try { + Function(command); + } catch (e) { + if (/[\[\{\(]$/.test(command)) { + return 1; + } else { + return 0; + } + } + return false; + }); + }; + + // Initiate the first prompt. + handler(); + } - CloudCmd.View.show(lElement); + CloudCmd.View.show(Element, function(){ + $('.jqconsole-prompt')[0].focus(); + }); };