diff --git a/ChangeLog b/ChangeLog index f22d3a8d..2d7d867c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -90,6 +90,8 @@ getJSONfromFileTable. * feature(socket) if id in use - reconnect +* chore(console) remove jquery-terminal + 2012.04.22, v0.2.0 diff --git a/lib/client/console.js b/lib/client/console.js index 7d01071d..25595226 100644 --- a/lib/client/console.js +++ b/lib/client/console.js @@ -120,12 +120,12 @@ var CloudCmd, Util, DOM, $, jqconsole; function load(pCallBack){ Util.time(Name + ' load'); - var lDir = CloudCmd.LIBDIRCLIENT + 'terminal/jq-console/', + var lDir = CloudCmd.LIBDIRCLIENT + 'console/', lFiles = [ lDir + 'jqconsole.js', lDir + 'jqconsole.css', lDir + 'ansi.css', - CloudCmd.LIBDIRCLIENT + 'terminal/jquery-terminal/jquery-migrate-1.0.0.js' + lDir + 'jquery-migrate-1.0.0.js' ]; DOM.anyLoadInParallel(lFiles, function(){ diff --git a/lib/client/terminal/jq-console/ansi.css b/lib/client/console/ansi.css similarity index 100% rename from lib/client/terminal/jq-console/ansi.css rename to lib/client/console/ansi.css diff --git a/lib/client/terminal/jq-console/jqconsole.css b/lib/client/console/jqconsole.css similarity index 100% rename from lib/client/terminal/jq-console/jqconsole.css rename to lib/client/console/jqconsole.css diff --git a/lib/client/terminal/jq-console/jqconsole.js b/lib/client/console/jqconsole.js similarity index 100% rename from lib/client/terminal/jq-console/jqconsole.js rename to lib/client/console/jqconsole.js diff --git a/lib/client/terminal/jquery-terminal/jquery-migrate-1.0.0.js b/lib/client/console/jquery-migrate-1.0.0.js similarity index 100% rename from lib/client/terminal/jquery-terminal/jquery-migrate-1.0.0.js rename to lib/client/console/jquery-migrate-1.0.0.js diff --git a/lib/client/jquery-console.js b/lib/client/jquery-console.js deleted file mode 100644 index 9ba73d4e..00000000 --- a/lib/client/jquery-console.js +++ /dev/null @@ -1,93 +0,0 @@ -var CloudCmd, Util, DOM, $; -(function(CloudCmd, Util, DOM){ - 'use strict'; - - CloudCmd.Console = new ConsoleProto(CloudCmd, Util, DOM); - - function ConsoleProto(CloudCmd, Util, DOM){ - var Name = 'Console', - Key = CloudCmd.Key, - Images = DOM.Images, - Console = this; - - this.init = function(pCallBack){ - Util.loadOnLoad([ - Console.show, - load, - CloudCmd.View, - DOM.jqueryLoad, - ]); - - DOM.Events.addKey(listener); - - delete Console.init; - }; - - this.show = function(){ - var lElement; - - Images.showLoad({top:true}); - - lElement = DOM.anyload({ - name : 'div', - className : 'console' - }); - - $(lElement).console({ - promptLabel: '# ', - commandValidate : function(line){ - var lRet = line !== ""; - - return lRet; - }, - commandHandle : function(line){ - return line; - }, - autofocus : true, - animateScroll : false, - promptHistory : true, - }); - - CloudCmd.View.show(lElement); - }; - - - this.hide = function(){ - CloudCmd.View.hide(); - }; - - function load(pCallBack){ - Util.time(Name + ' load'); - - var lDir = CloudCmd.LIBDIRCLIENT + 'terminal/jquery-console/', - lFiles = [ - lDir + 'jquery.console.js', - lDir + 'jquery.console.css' - ]; - - DOM.anyLoadInParallel(lFiles, function(){ - console.timeEnd(Name + ' load'); - - Util.exec(pCallBack); - }); - } - - function listener(pEvent){ - var lF10 = Key.F10, - lESC = Key.ESC, - lIsBind = Key.isBind(), - lKey = pEvent.keyCode; - - switch(lKey){ - case lF10: - Console.show(); - break; - case lESC: - Console.hide(); - break; - } - - } - } - -})(CloudCmd, Util, DOM); \ No newline at end of file diff --git a/lib/client/terminal.js b/lib/client/terminal.js deleted file mode 100644 index c311d20e..00000000 --- a/lib/client/terminal.js +++ /dev/null @@ -1,135 +0,0 @@ -var CloudCmd, Util, DOM, $; -/* object contains terminal jqconsole */ - -(function(CloudCmd, Util, DOM){ - 'use strict'; - - var Key = CloudCmd.Key, - TerminalId, - Term, - Hidden = false, - JqueryTerminal = {}; - - CloudCmd.Terminal = {}; - - /** - * function loads jquery-terminal - */ - function load(pCallBack){ - Util.time('terminal load'); - - var lDir = '/lib/client/terminal/jquery-terminal/jquery.', - lFiles = [ - lDir + 'terminal.js', - lDir + 'mousewheel.js', - lDir + 'terminal.css' - ], - lJqueryMigrate = '//code.jquery.com/jquery-migrate-1.0.0.js'; - /* //github.com/jquery/jquery-migrate/ */ - - DOM.anyLoadOnLoad([lFiles, lJqueryMigrate], function(){ - Util.timeEnd('terminal load'); - init(); - $(function($) { - Term = JqueryTerminal.Term = $('#terminal').terminal(function(command, term){ - term.echo(''); - CloudCmd.Socket.send(command); - }, { - greetings : '[[;#729FCF;]CloudCmd Terminal]', - prompt : '[[;#729FCF;]cloudcmd> ]', - color : '#729FCF;' - }); - }); - /* removing resize function, no need for us */ - $(window).unbind('resize'); - - Util.exec(pCallBack); - }).cssSet({id:'terminal-css', - inner: '.terminal{' + - 'height: 720px;' + - '};' - }); - } - - /** - * function do basic initialization - */ - function init(){ - if(!TerminalId) - TerminalId = DOM.anyload({ - name : 'div', - id : 'terminal', - className : 'panel terminal', - parent : DOM.getFM() - }); - } - - /** - * functin show jquery-terminal - */ - JqueryTerminal.show = function(){ - DOM.Images.hideLoad(); - /* only if panel was hided */ - if( DOM.hidePanel() ){ - Hidden = false; - DOM.show(TerminalId); - Key.unsetBind(); - Term.resume(); - } - }; - - /** - * function hide jquery-terminal - */ - JqueryTerminal.hide = function(){ - Hidden = true; - - DOM.hide(TerminalId); - DOM.showPanel(); - Key.setBind(); - - Term.pause(); - }; - - /** - * function bind keys - */ - CloudCmd.Terminal.init = function(){ - Util.loadOnLoad([ - JqueryTerminal.show, - load, - DOM.socketLoad, - DOM.jqueryLoad, - ]); - - DOM.Events.addKey(lListener); - - function lListener(pEvent){ - var lRet = true, - lESC = Key.ESC, - lTRA = Key.TRA, - lKey = pEvent.keyCode, - lIsBind = Key.isBind(); - - switch(lKey){ - case lTRA: - if(Hidden && lIsBind){ - JqueryTerminal.show(); - DOM.preventDefault(pEvent); - lRet = false; - } - break; - - case lESC: - if(!Hidden) - JqueryTerminal.hide(); - break; - } - - return lRet; - } - }; - - CloudCmd.Terminal.JqueryTerminal = JqueryTerminal; - -})(CloudCmd, Util, DOM); diff --git a/lib/client/terminal/jquery-console/.gitignore b/lib/client/terminal/jquery-console/.gitignore deleted file mode 100644 index ac8f9688..00000000 --- a/lib/client/terminal/jquery-console/.gitignore +++ /dev/null @@ -1,20 +0,0 @@ -# Compiled source # -################### -*.com -*.class -*.dll -*.exe -*.o -*.so -*.pyc - -# Logs and databases # -###################### -*.log - -# OS generated files # -###################### -.DS_Store* -ehthumbs.db -Icon? -Thumbs.db diff --git a/lib/client/terminal/jquery-console/README b/lib/client/terminal/jquery-console/README deleted file mode 100644 index ac29694c..00000000 --- a/lib/client/terminal/jquery-console/README +++ /dev/null @@ -1,78 +0,0 @@ -INTRODUCTION - -See demo.html. Or here: http://chrisdone.com/jquery-console/ - -Options available: - - autofocus bool Autofocus the terminal, rather than - having to click on it. - - promptHistory bool Provide history support (kind of crappy, - needs doing properly.) - - historyPreserveColumn bool Preserve the column you were one when - switching between history. - - welcomeMessage string Just a first message to display on the - terminal. - - promptLabel string Prompt string like 'JavaScript> '. - - cols integer the number of cols, this value is only - used by the command completion to format - the list of results. - - commandValidate function When user hits return, validate - whether to trigger commandHandle and - re-prompt. - - commandHandle function Handle the command line, return a - string, boolean, or list - of {msg:"foo",className:"my-css-class"}. - commandHandle(line,report) is - called. Report function is for you - to report a result of the command - asynchronously. - - commandComplete function Handle the command completion when the - tab key is pressed. It returns a list - of string completion suffixes. - - animateScroll bool Whether to animate the scroll to - top. Currently disabled. - - charInsertTrigger function Predicate for whether to allow - character insertion. - charInsertTrigger(char,line) is called. - - cancelHandle function Handle a user-signaled interrupt. - -LICENSE - -Copyright 2010 Chris Done, Simon David Pratt. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - 1. Redistributions of source code must retain the above - copyright notice, this list of conditions and the following - disclaimer. - - 2. Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials - provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/client/terminal/jquery-console/jquery.console.css b/lib/client/terminal/jquery-console/jquery.console.css deleted file mode 100644 index 0bc50483..00000000 --- a/lib/client/terminal/jquery-console/jquery.console.css +++ /dev/null @@ -1,34 +0,0 @@ -.console { - word-wrap: break-word; -} - -.jquery-console-inner { - padding:0.5em; -} -.jquery-console-prompt-box { - color:black; - font-family:monospace; -} -.jquery-console-cursor { - color:#333; - font-weight:bold; -} -.jquery-console-message-error { - color:#ef0505; - font-family:sans-serif; - font-weight:bold; - padding:0.1em; -} -.jquery-console-message-value { - color:#1ad027; - font-family:monospace; - padding:0.1em; -} -.jquery-console-message-type { - color:#52666f; - font-family:monospace; - padding:0.1em; -} -.jquery-console-prompt-label { - font-weight:bold; -} \ No newline at end of file diff --git a/lib/client/terminal/jquery-console/jquery.console.js b/lib/client/terminal/jquery-console/jquery.console.js deleted file mode 100644 index 4c20925d..00000000 --- a/lib/client/terminal/jquery-console/jquery.console.js +++ /dev/null @@ -1,716 +0,0 @@ -// JQuery Console 1.0 -// Sun Feb 21 20:28:47 GMT 2010 -// -// Copyright 2010 Chris Done, Simon David Pratt. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above -// copyright notice, this list of conditions and the following -// disclaimer. -// -// 2. Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials -// provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -// TESTED ON -// Internet Explorer 6 -// Opera 10.01 -// Chromium 4.0.237.0 (Ubuntu build 31094) -// Firefox 3.5.8, 3.6.2 (Mac) -// Safari 4.0.5 (6531.22.7) (Mac) -// Google Chrome 5.0.375.55 (Mac) - -(function($){ - var isWebkit = !!~navigator.userAgent.indexOf(' AppleWebKit/'); - - $.fn.console = function(config){ - //////////////////////////////////////////////////////////////////////// - // Constants - // Some are enums, data types, others just for optimisation - var keyCodes = { - // left - 37: moveBackward, - // right - 39: moveForward, - // up - 38: previousHistory, - // down - 40: nextHistory, - // backspace - 8: backDelete, - // delete - 46: forwardDelete, - // end - 35: moveToEnd, - // start - 36: moveToStart, - // return - 13: commandTrigger, - // tab - 18: doNothing, - // tab - 9: doComplete - }; - var ctrlCodes = { - // C-a - 65: moveToStart, - // C-e - 69: moveToEnd, - // C-d - 68: forwardDelete, - // C-n - 78: nextHistory, - // C-p - 80: previousHistory, - // C-b - 66: moveBackward, - // C-f - 70: moveForward, - // C-k - 75: deleteUntilEnd - }; - if(config.ctrlCodes) { - $.extend(ctrlCodes, config.ctrlCodes); - } - var altCodes = { - // M-f - 70: moveToNextWord, - // M-b - 66: moveToPreviousWord, - // M-d - 68: deleteNextWord - }; - var cursor = ' '; - - //////////////////////////////////////////////////////////////////////// - // Globals - var container = $(this); - var inner = $('
'); - // erjiang: changed this from a text input to a textarea so we - // can get pasted newlines - var typer = $(''); - // Prompt - var promptBox; - var prompt; - var promptLabel = config && config.promptLabel? config.promptLabel : "> "; - var continuedPromptLabel = config && config.continuedPromptLabel? - config.continuedPromptLabel : "> "; - var column = 0; - var promptText = ''; - var restoreText = ''; - var continuedText = ''; - // Prompt history stack - var history = []; - var ringn = 0; - // For reasons unknown to The Sword of Michael himself, Opera - // triggers and sends a key character when you hit various - // keys like PgUp, End, etc. So there is no way of knowing - // when a user has typed '#' or End. My solution is in the - // typer.keydown and typer.keypress functions; I use the - // variable below to ignore the keypress event if the keydown - // event succeeds. - var cancelKeyPress = 0; - // When this value is false, the prompt will not respond to input - var acceptInput = true; - // When this value is true, the command has been canceled - var cancelCommand = false; - - // External exports object - var extern = {}; - - //////////////////////////////////////////////////////////////////////// - // Main entry point - (function(){ - container.append(inner); - inner.append(typer); - typer.css({position:'absolute',top:0,left:'-9999px'}); - if (config.welcomeMessage) - message(config.welcomeMessage,'jquery-console-welcome'); - newPromptBox(); - if (config.autofocus) { - inner.addClass('jquery-console-focus'); - typer.focus(); - setTimeout(function(){ - inner.addClass('jquery-console-focus'); - typer.focus(); - },100); - } - extern.inner = inner; - extern.typer = typer; - extern.scrollToBottom = scrollToBottom; - })(); - - //////////////////////////////////////////////////////////////////////// - // Reset terminal - extern.reset = function(){ - var welcome = (typeof config.welcomeMessage != 'undefined'); - inner.parent().fadeOut(function(){ - inner.find('div').each(function(){ - if (!welcome) { - $(this).remove(); - } else { - welcome = false; - } - }); - newPromptBox(); - inner.parent().fadeIn(function(){ - inner.addClass('jquery-console-focus'); - typer.focus(); - }); - }); - }; - - //////////////////////////////////////////////////////////////////////// - // Reset terminal - extern.notice = function(msg,style){ - var n = $('
').append($('
').text(msg)) - .css({visibility:'hidden'}); - container.append(n); - var focused = true; - if (style=='fadeout') - setTimeout(function(){ - n.fadeOut(function(){ - n.remove(); - }); - },4000); - else if (style=='prompt') { - var a = $('
OK
'); - n.append(a); - focused = false; - a.click(function(){ n.fadeOut(function(){ n.remove();inner.css({opacity:1}) }); }); - } - var h = n.height(); - n.css({height:'0px',visibility:'visible'}) - .animate({height:h+'px'},function(){ - if (!focused) inner.css({opacity:0.5}); - }); - n.css('cursor','default'); - return n; - }; - - //////////////////////////////////////////////////////////////////////// - // Make a new prompt box - function newPromptBox() { - column = 0; - promptText = ''; - ringn = 0; // Reset the position of the history ring - enableInput(); - promptBox = $('
'); - var label = $(''); - var labelText = extern.continuedPrompt? continuedPromptLabel : promptLabel; - promptBox.append(label.text(labelText).show()); - label.html(label.html().replace(' ',' ')); - prompt = $(''); - promptBox.append(prompt); - inner.append(promptBox); - updatePromptDisplay(); - }; - - //////////////////////////////////////////////////////////////////////// - // Handle setting focus - container.click(function(){ - inner.addClass('jquery-console-focus'); - inner.removeClass('jquery-console-nofocus'); - if (isWebkit) { - typer.focusWithoutScrolling(); - } else { - typer.css('position', 'fixed').focus(); - } - scrollToBottom(); - return false; - }); - - //////////////////////////////////////////////////////////////////////// - // Handle losing focus - typer.blur(function(){ - inner.removeClass('jquery-console-focus'); - inner.addClass('jquery-console-nofocus'); - }); - - //////////////////////////////////////////////////////////////////////// - // Bind to the paste event of the input box so we know when we - // get pasted data - typer.bind('paste', function(e) { - // wipe typer input clean just in case - typer.val(""); - // this timeout is required because the onpaste event is - // fired *before* the text is actually pasted - setTimeout(function() { - typer.consoleInsert(typer.val()); - typer.val(""); - }, 0); - }); - - //////////////////////////////////////////////////////////////////////// - // Handle key hit before translation - // For picking up control characters like up/left/down/right - - typer.keydown(function(e){ - cancelKeyPress = 0; - var keyCode = e.keyCode; - // C-c: cancel the execution - if(e.ctrlKey && keyCode == 67) { - cancelKeyPress = keyCode; - cancelExecution(); - return false; - } - if (acceptInput) { - if (keyCode in keyCodes) { - cancelKeyPress = keyCode; - (keyCodes[keyCode])(); - return false; - } else if (e.ctrlKey && keyCode in ctrlCodes) { - cancelKeyPress = keyCode; - (ctrlCodes[keyCode])(); - return false; - } else if (e.altKey && keyCode in altCodes) { - cancelKeyPress = keyCode; - (altCodes[keyCode])(); - return false; - } - } - }); - - //////////////////////////////////////////////////////////////////////// - // Handle key press - typer.keypress(function(e){ - var keyCode = e.keyCode || e.which; - if (isIgnorableKey(e)) { - return false; - } - // C-v: don't insert on paste event - if ((e.ctrlKey || e.metaKey) && String.fromCharCode(keyCode).toLowerCase() == 'v') { - return true; - } - if (acceptInput && cancelKeyPress != keyCode && keyCode >= 32){ - if (cancelKeyPress) return false; - if ( - typeof config.charInsertTrigger == 'undefined' || ( - typeof config.charInsertTrigger == 'function' && - config.charInsertTrigger(keyCode,promptText) - ) - ){ - typer.consoleInsert(keyCode); - } - } - if (isWebkit) return false; - }); - - function isIgnorableKey(e) { - // for now just filter alt+tab that we receive on some platforms when - // user switches windows (goes away from the browser) - return ((e.keyCode == keyCodes.tab || e.keyCode == 192) && e.altKey); - }; - - //////////////////////////////////////////////////////////////////////// - // Rotate through the command history - function rotateHistory(n){ - if (history.length == 0) return; - ringn += n; - if (ringn < 0) ringn = history.length; - else if (ringn > history.length) ringn = 0; - var prevText = promptText; - if (ringn == 0) { - promptText = restoreText; - } else { - promptText = history[ringn - 1]; - } - if (config.historyPreserveColumn) { - if (promptText.length < column + 1) { - column = promptText.length; - } else if (column == 0) { - column = promptText.length; - } - } else { - column = promptText.length; - } - updatePromptDisplay(); - }; - - function previousHistory() { - rotateHistory(-1); - }; - - function nextHistory() { - rotateHistory(1); - }; - - // Add something to the history ring - function addToHistory(line){ - history.push(line); - restoreText = ''; - }; - - // Delete the character at the current position - function deleteCharAtPos(){ - if (column < promptText.length){ - promptText = - promptText.substring(0,column) + - promptText.substring(column+1); - restoreText = promptText; - return true; - } else return false; - }; - - function backDelete() { - if (moveColumn(-1)){ - deleteCharAtPos(); - updatePromptDisplay(); - } - }; - - function forwardDelete() { - if (deleteCharAtPos()){ - updatePromptDisplay(); - } - }; - - function deleteUntilEnd() { - while(deleteCharAtPos()) { - updatePromptDisplay(); - } - }; - - function deleteNextWord() { - // A word is defined within this context as a series of alphanumeric - // characters. - // Delete up to the next alphanumeric character - while( - column < promptText.length && - !isCharAlphanumeric(promptText[column]) - ) { - deleteCharAtPos(); - updatePromptDisplay(); - } - // Then, delete until the next non-alphanumeric character - while( - column < promptText.length && - isCharAlphanumeric(promptText[column]) - ) { - deleteCharAtPos(); - updatePromptDisplay(); - } - }; - - //////////////////////////////////////////////////////////////////////// - // Validate command and trigger it if valid, or show a validation error - function commandTrigger() { - var line = promptText; - if (typeof config.commandValidate == 'function') { - var ret = config.commandValidate(line); - if (ret == true || ret == false) { - if (ret) { - handleCommand(); - } - } else { - commandResult(ret,"jquery-console-message-error"); - } - } else { - handleCommand(); - } - }; - - // Scroll to the bottom of the view - function scrollToBottom() { - if (jQuery.fn.jquery > "1.6") { - inner.prop({ scrollTop: inner.prop("scrollHeight") }); - } - else { - inner.attr({ scrollTop: inner.attr("scrollHeight") }); - } - }; - - function cancelExecution() { - if(typeof config.cancelHandle == 'function') { - config.cancelHandle(); - } - } - - //////////////////////////////////////////////////////////////////////// - // Handle a command - function handleCommand() { - if (typeof config.commandHandle == 'function') { - disableInput(); - addToHistory(promptText); - var text = promptText; - if (extern.continuedPrompt) { - if (continuedText) - continuedText += '\n' + promptText; - else continuedText = promptText; - } else continuedText = undefined; - if (continuedText) text = continuedText; - var ret = config.commandHandle(text,function(msgs){ - commandResult(msgs); - }); - if (extern.continuedPrompt && !continuedText) - continuedText = promptText; - if (typeof ret == 'boolean') { - if (ret) { - // Command succeeded without a result. - commandResult(); - } else { - commandResult( - 'Command failed.', - "jquery-console-message-error" - ); - } - } else if (typeof ret == "string") { - commandResult(ret,"jquery-console-message-success"); - } else if (typeof ret == 'object' && ret.length) { - commandResult(ret); - } else if (extern.continuedPrompt) { - commandResult(); - } - } - }; - - //////////////////////////////////////////////////////////////////////// - // Disable input - function disableInput() { - acceptInput = false; - }; - - // Enable input - function enableInput() { - acceptInput = true; - } - - //////////////////////////////////////////////////////////////////////// - // Reset the prompt in invalid command - function commandResult(msg,className) { - column = -1; - updatePromptDisplay(); - if (typeof msg == 'string') { - message(msg,className); - } else if ($.isArray(msg)) { - for (var x in msg) { - var ret = msg[x]; - message(ret.msg,ret.className); - } - } else { // Assume it's a DOM node or jQuery object. - inner.append(msg); - } - newPromptBox(); - }; - - //////////////////////////////////////////////////////////////////////// - // Display a message - function message(msg,className) { - var mesg = $('
'); - if (className) mesg.addClass(className); - mesg.filledText(msg).hide(); - inner.append(mesg); - mesg.show(); - }; - - //////////////////////////////////////////////////////////////////////// - // Handle normal character insertion - // data can either be a number, which will be interpreted as the - // numeric value of a single character, or a string - typer.consoleInsert = function(data){ - // TODO: remove redundant indirection - var text = isNaN(data) ? data : String.fromCharCode(data); - var before = promptText.substring(0,column); - var after = promptText.substring(column); - promptText = before + text + after; - moveColumn(text.length); - restoreText = promptText; - updatePromptDisplay(); - }; - - //////////////////////////////////////////////////////////////////////// - // Move to another column relative to this one - // Negative means go back, positive means go forward. - function moveColumn(n){ - if (column + n >= 0 && column + n <= promptText.length){ - column += n; - return true; - } else return false; - }; - - function moveForward() { - if(moveColumn(1)) { - updatePromptDisplay(); - return true; - } - return false; - }; - - function moveBackward() { - if(moveColumn(-1)) { - updatePromptDisplay(); - return true; - } - return false; - }; - - function moveToStart() { - if (moveColumn(-column)) - updatePromptDisplay(); - }; - - function moveToEnd() { - if (moveColumn(promptText.length-column)) - updatePromptDisplay(); - }; - - function moveToNextWord() { - while( - column < promptText.length && - !isCharAlphanumeric(promptText[column]) && - moveForward() - ) {} - while( - column < promptText.length && - isCharAlphanumeric(promptText[column]) && - moveForward() - ) {} - }; - - function moveToPreviousWord() { - // Move backward until we find the first alphanumeric - while( - column -1 >= 0 && - !isCharAlphanumeric(promptText[column-1]) && - moveBackward() - ) {} - // Move until we find the first non-alphanumeric - while( - column -1 >= 0 && - isCharAlphanumeric(promptText[column-1]) && - moveBackward() - ) {} - }; - - function isCharAlphanumeric(charToTest) { - if(typeof charToTest == 'string') { - var code = charToTest.charCodeAt(); - return (code >= 'A'.charCodeAt() && code <= 'Z'.charCodeAt()) || - (code >= 'a'.charCodeAt() && code <= 'z'.charCodeAt()) || - (code >= '0'.charCodeAt() && code <= '9'.charCodeAt()); - } - return false; - }; - - function doComplete() { - if(typeof config.completeHandle == 'function') { - var completions = config.completeHandle(promptText); - var len = completions.length; - if (len === 1) { - extern.promptText(promptText + completions[0]); - } else if (len > 1 && config.cols) { - var prompt = promptText; - // Compute the number of rows that will fit in the width - var max = 0; - for (var i = 0;i < len;i++) { - max = Math.max(max, completions[i].length); - } - max += 2; - var n = Math.floor(config.cols / max); - var buffer = ""; - var col = 0; - for (i = 0;i < len;i++) { - var completion = completions[i]; - buffer += completions[i]; - for (var j = completion.length;j < max;j++) { - buffer += " "; - } - if (++col >= n) { - buffer += "\n"; - col = 0; - } - } - commandResult(buffer,"jquery-console-message-value"); - extern.promptText(prompt); - } - } - }; - - function doNothing() {}; - - extern.promptText = function(text){ - if (typeof text === 'string') { - promptText = text; - column = promptText.length; - updatePromptDisplay(); - } - return promptText; - }; - - //////////////////////////////////////////////////////////////////////// - // Update the prompt display - function updatePromptDisplay(){ - var line = promptText; - var html = ''; - if (column > 0 && line == ''){ - // When we have an empty line just display a cursor. - html = cursor; - } else if (column == promptText.length){ - // We're at the end of the line, so we need to display - // the text *and* cursor. - html = htmlEncode(line) + cursor; - } else { - // Grab the current character, if there is one, and - // make it the current cursor. - var before = line.substring(0, column); - var current = line.substring(column,column+1); - if (current){ - current = - '' + - htmlEncode(current) + - ''; - } - var after = line.substring(column+1); - html = htmlEncode(before) + current + htmlEncode(after); - } - prompt.html(html); - scrollToBottom(); - }; - - // Simple HTML encoding - // Simply replace '<', '>' and '&' - // TODO: Use jQuery's .html() trick, or grab a proper, fast - // HTML encoder. - function htmlEncode(text){ - return ( - text.replace(/&/g,'&') - .replace(/') - ); - }; - - return extern; - }; - // Simple utility for printing messages - $.fn.filledText = function(txt){ - $(this).text(txt); - $(this).html($(this).html().replace(/\n/g,'
')); - return this; - }; - - // Alternative method for focus without scrolling - $.fn.focusWithoutScrolling = function(){ - var x = window.scrollX, y = window.scrollY; - $(this).focus(); - window.scrollTo(x, y); - }; -})(jQuery); diff --git a/lib/client/terminal/jquery-terminal/CHANGELOG b/lib/client/terminal/jquery-terminal/CHANGELOG deleted file mode 100644 index 305b1b9c..00000000 --- a/lib/client/terminal/jquery-terminal/CHANGELOG +++ /dev/null @@ -1,88 +0,0 @@ -0.4.20 Add exec, greetings, onClear, onBlur, onFocus, onTerminalChange -0.4.19 add support for ANSI terminal formatting, fix cancelable ajax on - CTRL+D, replace emails with link mailto, remove formatting processing - from command line, add text glow option to formatting -0.4.18 fix scrollbar, better exceptions in chrome, replace urls with links - one style for font and color in root .terminal class -0.4.17 fix IE formatting issue by adding cross-browser split -0.4.16 add reverse history search on CTRL+R - - fix cancel ajax call on CTRL+D -0.4.15 only one command from multiply commands is added to history - CTRL+D is handled even if exit is false -0.4.14 terminal don't add space after prompt (prompt need to add this space) - fix historyFilter - remove livequery -0.4.12 history return history object - add historyFilter - new event onCommandChange that execute scroll_to_bottom - add event onBeforeLogin -0.4.11 fix blank lines when echo longer strings -0.4.10 fix long line formatting and linebreak in the middle of formatting -0.4.9 fix wrap first line when prompt contain formatting -0.4.8 fix alt+d and ctrl+u -0.4.7 fix inserting special characters in Webkit on Windows -0.4.6 remove undocumented pipe operator - refreash prompt on resume -0.4.5 fix line wrapping when text contains tabulations -0.4.4 fix line wrapping with scrollbars -0.4.3 fix JSON-RPC when use without login -0.4.2 fix formatting when text contain empty lines -0.4.1 fix formatting when text contains newline characters -0.4 fix text formating when text splited into more then one line - you can pass nested objects as first argument - add tab completion with object passed as first argument -0.3.8 fix cursor manipulation when command contain new line characters -0.3.7 fix function terminal.login_name -0.3.6 fix switch between terminals - when terminal is not visible scroll to current terminal -0.3.5 fix scrolling in jQuery 1.6 -0.3.3 fixing PAGE UP/DOWN -0.3.2 fixing cursor in long lines -0.3.1 fixing small bugs, speed up resizing -0.3 fix resizing on start and issue with greetings - add formating strings to set style of text. - add to echo a function which will be called when terminal - is resized -0.3-RC2 fix manipulation of long line commands -0.3-RC1 add callbacks and new functions - you can now overwrite keyboard shortcuts - resizing recalculates lines lenght and redraw content - if you create plugin for elements that are not in the DOM - and then append it to DOM it's display corectly - put all dependencies in one file - Default greetings show terminal signature depending on - width of terminal - use Local Sorage for command line history if posible - remove access to command line (cmd plugin) and add interface - to allow interact with it - -0.2.3.9 fix append enter character (0x0D) to the command (thanks to marat - for reporting the bug) - -0.2.3.8 update mousewheel plugin which fix scrolling in Opera (Thanks for - Alexey Dubovtsev for reporting the bug) - -0.2.3.7 fix cursor in IE in tilda example - -0.2.3.6 fix json serialization in IE - -0.2.3.5 fix demos and clipboard textarea transparency in IE - -0.2.3.4 fix long lines in command line issue - -0.2.3.3 fix Terminal in Internet Exporer - -0.2.3.2 fix blank line issue (thanks to Chris Janicki for finding the - bug) and fix CTRL + Arrows scroll on CTRL+V - -0.2.3.1 allow CTRL+W CTRL+T - -0.2.3 fix for "(#$%.{" characters on Opera/Chrome, add cursor move - with CTRL+P, CTRL+N, CTRL+F, CTRL+B which also work in Chrome. - Fix Arrow Keys on Chrome (for cursor move and command line - history). Change License to LGPL3. - -0.2.2 fix down-arrow/open parentises issue in Opera and Chrome - -0.2.1 add support for paste from clipboard with CTRL+V (Copy to - clipboard is alway enabled on websites) \ No newline at end of file diff --git a/lib/client/terminal/jquery-terminal/README b/lib/client/terminal/jquery-terminal/README deleted file mode 100644 index 16957789..00000000 --- a/lib/client/terminal/jquery-terminal/README +++ /dev/null @@ -1,69 +0,0 @@ - __ _____ ________ __ - / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / / - __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ / - / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__ - \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/ - \/ /____/ version 0.4.22 - - -http://terminal.jcubic.pl - -Licensed under GNU LGPL Version 3 license http://www.gnu.org/licenses/lgpl.html -Copyright (c) 2011-2012 Jakub Jankiewicz - -JQuery Terminal Emulator is a plugin for creating command line interpreters in -your applications. It can automatically call JSON-RPC service when user type -commands or you can provide you own function in which you can parse user -command. It's ideal if you want to provide additional functionality for power -users. It can also be used to debug your aplication. - -Features: - - * You can create interpreter for your JSON-RPC service with one line - of code. - - * Support for authentication (you can provide function when user enter - login and password or if you use JSON-RPC it can automatically call - login function on the server and pass token to all functions) - - * Stack of interpreters - you can create commands that trigger additional - interpreters (eg. you can use couple of JSON-RPC service and run them - when user type command) - - * Command Tree - you can use nested objects. Each command will invoke a - function, if the value is an object it will create new interpreter and - use function from that object as commands. You can use as much nested - object/commands as you like. If the value is a string it will create - JSON-RPC service. - - * Support for command line history it use Local Storage if posible - - * Support for tab completion if you create terminal from an object - - * Include keyboard shortcut from bash like CTRL+A, CTRL+D, CTRL+E etc. - - * Multiply terminals on one page (every terminal can have different - command, it's own authentication function and it's own command history) - - * It catch all exceptions and display error messages in terminal - (you can see errors in your javascript and php code in terminal if they - are in interpreter function) - - -Example of usage (javascript interpreter) - -jQuery(function($, undefined) { - $('#term_demo').terminal(function(command, term) { - if (command !== '') { - var result = window.eval(command); - if (result != undefined) { - term.echo(String(result)); - } - } - }, { - greetings: 'Javascript Interpreter', - name: 'js_demo', - height: 200, - width: 450, - prompt: 'js> '}); -}); \ No newline at end of file diff --git a/lib/client/terminal/jquery-terminal/dterm.js b/lib/client/terminal/jquery-terminal/dterm.js deleted file mode 100644 index 7506d2fc..00000000 --- a/lib/client/terminal/jquery-terminal/dterm.js +++ /dev/null @@ -1,63 +0,0 @@ -/*! - * Example plugin using JQuery Terminal Emulator - * Copyright (C) 2010 Jakub Jankiewicz - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ -(function($) { - $.extend_if_has = function(desc, source, array) { - for (var i=array.length;i--;) { - if (typeof source[array[i]] != 'undefined') { - desc[array[i]] = source[array[i]]; - } - } - return desc; - }; - $.fn.dterm = function(eval, options) { - var op = $.extend_if_has({}, options, - ['greetings', 'prompt', 'onInit', - 'onExit', 'clear', - 'login', 'name', 'exit']); - op.enabled = false; - var terminal = this.terminal(eval, op).css('overflow', 'hidden'); - if (!options.title) { - options.title = 'JQuery Terminal Emulator'; - } - if (options.logoutOnClose) { - options.close = function(e, ui) { - terminal.logout(); - terminal.clear(); - }; - } else { - options.close = function(e, ui) { - terminal.disable(); - }; - } - var self = this; - var dialog = this.dialog($.extend(options, { - resizeStop: function(e, ui) { - var content = self.find('.ui-dialog-content'); - terminal.resize(content.width(), content.height()); - }, - open: function(e, ui) { - terminal.focus(); - terminal.resize(); - }, - show: 'fade', - closeOnEscape: false - })); - self.terminal = terminal; - return self; - }; -})(jQuery); diff --git a/lib/client/terminal/jquery-terminal/index.html b/lib/client/terminal/jquery-terminal/index.html deleted file mode 100644 index 37496a42..00000000 --- a/lib/client/terminal/jquery-terminal/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - -
- \ No newline at end of file diff --git a/lib/client/terminal/jquery-terminal/jquery.mousewheel.js b/lib/client/terminal/jquery-terminal/jquery.mousewheel.js deleted file mode 100644 index c7b28217..00000000 --- a/lib/client/terminal/jquery-terminal/jquery.mousewheel.js +++ /dev/null @@ -1,84 +0,0 @@ -/*! Copyright (c) 2011 Brandon Aaron (http://brandonaaron.net) - * Licensed under the MIT License (LICENSE.txt). - * - * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers. - * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix. - * Thanks to: Seamus Leahy for adding deltaX and deltaY - * - * Version: 3.0.6 - * - * Requires: 1.2.2+ - */ - -(function($) { - -var types = ['DOMMouseScroll', 'mousewheel']; - -if ($.event.fixHooks) { - for ( var i=types.length; i; ) { - $.event.fixHooks[ types[--i] ] = $.event.mouseHooks; - } -} - -$.event.special.mousewheel = { - setup: function() { - if ( this.addEventListener ) { - for ( var i=types.length; i; ) { - this.addEventListener( types[--i], handler, false ); - } - } else { - this.onmousewheel = handler; - } - }, - - teardown: function() { - if ( this.removeEventListener ) { - for ( var i=types.length; i; ) { - this.removeEventListener( types[--i], handler, false ); - } - } else { - this.onmousewheel = null; - } - } -}; - -$.fn.extend({ - mousewheel: function(fn) { - return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel"); - }, - - unmousewheel: function(fn) { - return this.unbind("mousewheel", fn); - } -}); - - -function handler(event) { - var orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true, deltaX = 0, deltaY = 0; - event = $.event.fix(orgEvent); - event.type = "mousewheel"; - - // Old school scrollwheel delta - if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta/120; } - if ( orgEvent.detail ) { delta = -orgEvent.detail/3; } - - // New school multidimensional scroll (touchpads) deltas - deltaY = delta; - - // Gecko - if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) { - deltaY = 0; - deltaX = -1*delta; - } - - // Webkit - if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY/120; } - if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = -1*orgEvent.wheelDeltaX/120; } - - // Add event and delta to the front of the arguments - args.unshift(event, delta, deltaX, deltaY); - - return ($.event.dispatch || $.event.handle).apply(this, args); -} - -})(jQuery); \ No newline at end of file diff --git a/lib/client/terminal/jquery-terminal/jquery.terminal.css b/lib/client/terminal/jquery-terminal/jquery.terminal.css deleted file mode 100644 index 8eb2cee7..00000000 --- a/lib/client/terminal/jquery-terminal/jquery.terminal.css +++ /dev/null @@ -1,74 +0,0 @@ -.terminal .clipboard { - position: absolute; - bottom: 0; - left: 0; - opacity: 0.01; - filter: alpha(opacity = 0.01); - filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0.01); - width: 2px; -} -.cmd > .clipboard { - position: fixed; -} -.terminal { - padding: 10px; - position: relative; - overflow: hidden; -} -.cmd { - padding: 0; - margin: 0; - height: 1.3em; -} -.terminal .terminal-output div div, .terminal .prompt { - display: block; - /* line-height: 9px; */ - height: 14px; -} -.terminal { - font-family: FreeMono, monospace; - color: #aaa; - background-color: #000; - /* font-size: 12px; */ - /* line-height: 14px; */ - line-height: 16px; - /* removing breaking the lines */ -} -.terminal .terminal-output div span { - display: inline-block; -} -.terminal .cmd span { - display: inline-block; -} -.terminal .cmd span.inverted { - background-color: #aaa; - color: #000; -} -.terminal .terminal-output div div::-moz-selection, .terminal .terminal-output div span::-moz-selection { - background-color: #aaa; - color: #000; -} -.terminal .terminal-output div div::selection, .terminal .terminal-output div span::selection, -.terminal .cmd > span::selection, .terminal .prompt span::selection { - background-color: #aaa; - color: #000; -} -.terminal .terminal-output div.error, .terminal .terminal-output div.error div { - color: red; -} -.tilda { - position: fixed; - top: 0; - left: 0; - width: 100%; - z-index: 1100; -} -.clear { - clear: both; -} -.terminal a { - color: #0F60FF; -} -.terminal a:hover { - color: red; -} \ No newline at end of file diff --git a/lib/client/terminal/jquery-terminal/jquery.terminal.js b/lib/client/terminal/jquery-terminal/jquery.terminal.js deleted file mode 100644 index b8af09fe..00000000 --- a/lib/client/terminal/jquery-terminal/jquery.terminal.js +++ /dev/null @@ -1,2712 +0,0 @@ -/**@license - *| __ _____ ________ __ - *| / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / / - *| __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ / - *| / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__ - *| \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/ - *| \/ /____/ version 0.4.22 - * http://terminal.jcubic.pl - * - * Licensed under GNU LGPL Version 3 license - * Copyright (c) 2011-2012 Jakub Jankiewicz - * - * Includes: - * - * Storage plugin Distributed under the MIT License - * Copyright (c) 2010 Dave Schindler - * - * jQuery Timers licenced with the WTFPL - * - * - * Cross-Browser Split 1.1.1 - * Copyright 2007-2012 Steven Levithan - * Available under the MIT License - * - * Date: Thu, 15 Nov 2012 07:12:21 +0000 - */ - -/* - - TODO: - add destroy method to terminal (cmd alrady have it) - - add support for - $(...).each(function() { ... }); - - $.fn.pluginname = function(options) { - var settings = $.extend({}, $.fn.pluginname.defaultOptions, options); - - return this.each(function() { - var $this = $(this); - }); - $.fn.pluginname.defaultOptions = { - }; - }; - - distinguish between paused and disabled - paused should block keydown in terminal it should disable command line - disable - -*/ - - - -(function($, undefined) { - "use strict"; - - // map object to object - $.omap = function(o, fn) { - var result = {}; - $.each(o, function(k, v) { - result[k] = fn.call(o, k, v); - }); - return result; - }; - // debug function - function get_stack(caller) { - "use strict"; - if (caller) { - return [caller.toString().match(/.*\n.*\n/)]. - concat(get_stack(caller.caller)); - } else { - return []; - } - } - // ---------------------------------------- - // START Storage plugin - // ---------------------------------------- - // Private data - var isLS = typeof window.localStorage !== 'undefined'; - // Private functions - function wls(n, v) { - var c; - if (typeof n === 'string' && typeof v === 'string') { - localStorage[n] = v; - return true; - } else if (typeof n === 'object' && typeof v === 'undefined') { - for (c in n) { - if (n.hasOwnProperty(c)) { - localStorage[c] = n[c]; - } - } - return true; - } - return false; - } - function wc(n, v) { - var dt, e, c; - dt = new Date(); - dt.setTime(dt.getTime() + 31536000000); - e = '; expires=' + dt.toGMTString(); - if (typeof n === 'string' && typeof v === 'string') { - document.cookie = n + '=' + v + e + '; path=/'; - return true; - } else if (typeof n === 'object' && typeof v === 'undefined') { - for (c in n) { - if (n.hasOwnProperty(c)) { - document.cookie = c + '=' + n[c] + e + '; path=/'; - } - } - return true; - } - return false; - } - function rls(n) { - return localStorage[n]; - } - function rc(n) { - var nn, ca, i, c; - nn = n + '='; - ca = document.cookie.split(';'); - for (i = 0; i < ca.length; i++) { - c = ca[i]; - while (c.charAt(0) === ' ') { - c = c.substring(1, c.length); - } - if (c.indexOf(nn) === 0) { - return c.substring(nn.length, c.length); - } - } - return null; - } - function dls(n) { - return delete localStorage[n]; - } - function dc(n) { - return wc(n, '', -1); - } - /** - * Public API - * $.Storage.set("name", "value") - * $.Storage.set({"name1":"value1", "name2":"value2", etc}) - * $.Storage.get("name") - * $.Storage.remove("name") - */ - $.extend({ - Storage: { - set: isLS ? wls : wc, - get: isLS ? rls : rc, - remove: isLS ? dls : dc - } - }); - // ---------------------------------------- - // END Storage plugin - // ---------------------------------------- - // START jQuery Timers - // ---------------------------------------- - jQuery.fn.extend({ - everyTime: function(interval, label, fn, times, belay) { - return this.each(function() { - jQuery.timer.add(this, interval, label, fn, times, belay); - }); - }, - oneTime: function(interval, label, fn) { - return this.each(function() { - jQuery.timer.add(this, interval, label, fn, 1); - }); - }, - stopTime: function(label, fn) { - return this.each(function() { - jQuery.timer.remove(this, label, fn); - }); - } - }); - - jQuery.extend({ - timer: { - guid: 1, - global: {}, - regex: /^([0-9]+)\s*(.*s)?$/, - powers: { - // Yeah this is major overkill... - 'ms': 1, - 'cs': 10, - 'ds': 100, - 's': 1000, - 'das': 10000, - 'hs': 100000, - 'ks': 1000000 - }, - timeParse: function(value) { - if (value === undefined || value === null) { - return null; - } - var result = this.regex.exec(jQuery.trim(value.toString())); - if (result[2]) { - var num = parseInt(result[1], 10); - var mult = this.powers[result[2]] || 1; - return num * mult; - } else { - return value; - } - }, - add: function(element, interval, label, fn, times, belay) { - var counter = 0; - - if (jQuery.isFunction(label)) { - if (!times) { - times = fn; - } - fn = label; - label = interval; - } - - interval = jQuery.timer.timeParse(interval); - - if (typeof interval !== 'number' || - isNaN(interval) || - interval <= 0) { - return; - } - if (times && times.constructor !== Number) { - belay = !!times; - times = 0; - } - - times = times || 0; - belay = belay || false; - - if (!element.$timers) { - element.$timers = {}; - } - if (!element.$timers[label]) { - element.$timers[label] = {}; - } - fn.$timerID = fn.$timerID || this.guid++; - - var handler = function() { - if (belay && handler.inProgress) { - return; - } - handler.inProgress = true; - if ((++counter > times && times !== 0) || - fn.call(element, counter) === false) { - jQuery.timer.remove(element, label, fn); - } - handler.inProgress = false; - }; - - handler.$timerID = fn.$timerID; - - if (!element.$timers[label][fn.$timerID]) { - element.$timers[label][fn.$timerID] = window.setInterval(handler, interval); - } - - if (!this.global[label]) { - this.global[label] = []; - } - this.global[label].push(element); - - }, - remove: function(element, label, fn) { - var timers = element.$timers, ret; - - if (timers) { - - if (!label) { - for (var lab in timers) { - if (timers.hasOwnProperty(lab)) { - this.remove(element, lab, fn); - } - } - } else if (timers[label]) { - if (fn) { - if (fn.$timerID) { - window.clearInterval(timers[label][fn.$timerID]); - delete timers[label][fn.$timerID]; - } - } else { - for (var _fn in timers[label]) { - if (timers[label].hasOwnProperty(_fn)) { - window.clearInterval(timers[label][_fn]); - delete timers[label][_fn]; - } - } - } - - for (ret in timers[label]) { - if (timers[label].hasOwnProperty(ret)) { - break; - } - } - if (!ret) { - ret = null; - delete timers[label]; - } - } - - for (ret in timers) { - if (timers.hasOwnProperty(ret)) { - break; - } - } - if (!ret) { - element.$timers = null; - } - } - } - } - }); - - if (jQuery.browser.msie) { - jQuery(window).one('unload', function() { - var global = jQuery.timer.global; - for (var label in global) { - if (global.hasOwnProperty(label)) { - var els = global[label], i = els.length; - while (--i) { - jQuery.timer.remove(els[i], label); - } - } - } - }); - } - // ---------------------------------------- - // START CROSS BROWSER SPLIT - // ---------------------------------------- - - (function(undef) { - - // prevent double include - - if (!String.prototype.split.toString().match(/\[native/)) { - return; - } - - var nativeSplit = String.prototype.split, - compliantExecNpcg = /()??/.exec("")[1] === undef, // NPCG: nonparticipating capturing group - self; - - self = function (str, separator, limit) { - // If `separator` is not a regex, use `nativeSplit` - if (Object.prototype.toString.call(separator) !== "[object RegExp]") { - return nativeSplit.call(str, separator, limit); - } - var output = [], - flags = (separator.ignoreCase ? "i" : "") + - (separator.multiline ? "m" : "") + - (separator.extended ? "x" : "") + // Proposed for ES6 - (separator.sticky ? "y" : ""), // Firefox 3+ - lastLastIndex = 0, - // Make `global` and avoid `lastIndex` issues by working with a copy - separator2, match, lastIndex, lastLength; - separator = new RegExp(separator.source, flags + "g"); - str += ""; // Type-convert - if (!compliantExecNpcg) { - // Doesn't need flags gy, but they don't hurt - separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags); - } - /* Values for `limit`, per the spec: - * If undefined: 4294967295 // Math.pow(2, 32) - 1 - * If 0, Infinity, or NaN: 0 - * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296; - * If negative number: 4294967296 - Math.floor(Math.abs(limit)) - * If other: Type-convert, then use the above rules - */ - // ? Math.pow(2, 32) - 1 : ToUint32(limit) - limit = limit === undef ? -1 >>> 0 : limit >>> 0; - while (match = separator.exec(str)) { - // `separator.lastIndex` is not reliable cross-browser - lastIndex = match.index + match[0].length; - if (lastIndex > lastLastIndex) { - output.push(str.slice(lastLastIndex, match.index)); - // Fix browsers whose `exec` methods don't consistently return `undefined` for - // nonparticipating capturing groups - if (!compliantExecNpcg && match.length > 1) { - match[0].replace(separator2, function () { - for (var i = 1; i < arguments.length - 2; i++) { - if (arguments[i] === undef) { - match[i] = undef; - } - } - }); - } - if (match.length > 1 && match.index < str.length) { - Array.prototype.push.apply(output, match.slice(1)); - } - lastLength = match[0].length; - lastLastIndex = lastIndex; - if (output.length >= limit) { - break; - } - } - if (separator.lastIndex === match.index) { - separator.lastIndex++; // Avoid an infinite loop - } - } - if (lastLastIndex === str.length) { - if (lastLength || !separator.test("")) { - output.push(""); - } - } else { - output.push(str.slice(lastLastIndex)); - } - return output.length > limit ? output.slice(0, limit) : output; - }; - - // For convenience - String.prototype.split = function (separator, limit) { - return self(this, separator, limit); - }; - - return self; - - })(); - - // ----------------------------------------------------------------------- - /* - function decodeHTML(str) { - if (typeof str === 'string') { - str = str.replace(/&/g, '&'); - str = str.replace(/</g, '<').replace(/>/g, '>'); - str = str.replace(/ /g, '\t'); - str = str.replace(//g, '\n').replace(/ /g, ' '); - return str; - } else { - return ''; - } - } - */ - //split string to array of strings with the same length - function str_parts(str, length) { - var result = []; - var len = str.length; - if (len < length) { - return [str]; - } - for (var i = 0; i < len; i += length) { - result.push(str.substring(i, i + length)); - } - return result; - } - - - // ----------------------------------------------------------------------- - - function skipFormattingCount(string) { - return $('
' + $.terminal.strip(string) + '
').text().length; - } - - // ----------------------------------------------------------------------- - function formattingCount(string) { - return string.length - skipFormattingCount(string); - } - - // ----------------------------------------------------------------------- - // CYCLE DATA STRUCTURE - // ----------------------------------------------------------------------- - function Cycle(init) { - var data = init ? [init] : []; - var pos = 0; - $.extend(this, { - rotate: function() { - if (data.length === 1) { - return data[0]; - } else { - if (pos === data.length - 1) { - pos = 0; - } else { - ++pos; - } - return data[pos]; - } - }, - length: function() { - return data.length; - }, - set: function(item) { - for (var i = data.length; i--;) { - if (data[i] === item) { - pos = i; - return; - } - } - this.append(item); - }, - front: function() { - return data[pos]; - }, - append: function(item) { - data.push(item); - } - }); - } - // ----------------------------------------------------------------------- - // :: BCYCLE DATA STRUCTURE // Two way cycle - // ----------------------------------------------------------------------- - function BCycle(init) { - var data = init instanceof Array ? init : init ? [init] : []; - var pos = 0; - $.extend(this, { - left: function() { - if (pos === 0) { - pos = data.length - 1; - } else { - --pos; - } - return data[pos]; - }, - right: function() { - if (pos === data.length - 1) { - pos = 0; - } else { - ++pos; - } - return data[pos]; - }, - current: function() { - return data[pos]; - }, - data: function() { - return data; - }, - length: function() { - return data.length; - }, - reset: function() { - pos = 0; - }, - append: function(item) { - data.push(item); - this.reset(); - } - }); - } - // ----------------------------------------------------------------------- - // :: STACK DATA STRUCTURE - // ----------------------------------------------------------------------- - function Stack(init) { - var data = init ? [init] : []; - $.extend(this, { - size: function() { - return data.length; - }, - pop: function() { - if (data.length === 0) { - return null; - } else { - var value = data[data.length - 1]; - data = data.slice(0, data.length - 1); - return value; - } - }, - push: function(value) { - data = data.concat([value]); - return value; - }, - top: function() { - return data.length > 0 ? data[data.length - 1] : null; - } - }); - } - // serialize object myself (biwascheme or prototype library do something - // wiked with JSON serialization for Arrays) - $.json_stringify = function(object, level) { - var result = '', i; - level = level === undefined ? 1 : level; - var type = typeof object; - switch (type) { - case 'function': - result += object; - break; - case 'boolean': - result += object ? 'true' : 'false'; - break; - case 'object': - if (object === null) { - result += 'null'; - } else if (object instanceof Array) { - result += '['; - var len = object.length; - for (i = 0; i < len - 1; ++i) { - result += $.json_stringify(object[i], level + 1); - } - result += $.json_stringify(object[len - 1], level + 1) + ']'; - } else { - result += '{'; - for (var property in object) { - if (object.hasOwnProperty(property)) { - result += '"' + property + '":' + - $.json_stringify(object[property], level + 1); - } - } - result += '}'; - } - break; - case 'string': - var str = object; - var repl = { - '\\\\': '\\\\', - '"': '\\"', - '/': '\\/', - '\\n': '\\n', - '\\r': '\\r', - '\\t': '\\t'}; - for (i in repl) { - if (repl.hasOwnProperty(i)) { - str = str.replace(new RegExp(i, 'g'), repl[i]); - } - } - result += '"' + str + '"'; - break; - case 'number': - result += String(object); - break; - } - result += (level > 1 ? ',' : ''); - // quick hacks below - if (level === 1) { - // fix last comma - result = result.replace(/,([\]}])/g, '$1'); - } - // fix comma before array or object - return result.replace(/([\[{]),/g, '$1'); - }; - // ----------------------------------------------------------------------- - // :: HISTORY CLASS - // ----------------------------------------------------------------------- - function History(name) { - var enabled = true; - if (typeof name === 'string' && name !== '') { - name += '_'; - } - var data = $.Storage.get(name + 'commands'); - var bc = new BCycle(data ? eval('(' + data + ')') : ['']); - - $.extend(this, { - append: function(item) { - if (enabled) { - bc.append(item); - $.Storage.set(name + 'commands', $.json_stringify(bc.data())); - } - }, - data: function() { - return bc.data(); - }, - next: function() { - return bc.right(); - }, - last: function() { - bc.reset(); - }, - previous: function() { - return bc.left(); - }, - clear: function() { - bc = new BCycle(); - $.Storage.remove(name + 'commands'); - }, - enable: function() { - enabled = true; - }, - disable: function() { - enabled = false; - } - }); - } - // ----------------------------------------------------------------------- - // :: COMMAND LINE PLUGIN - // ----------------------------------------------------------------------- - $.fn.cmd = function(options) { - var self = this; - self.addClass('cmd'); - self.append('' + - ' '); - var clip = $('