40 lines
70 KiB
JavaScript
40 lines
70 KiB
JavaScript
|
/**@license
|
||
|
* __ _____ ________ __
|
||
|
* / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / /
|
||
|
* __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ /
|
||
|
* / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__
|
||
|
* \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/
|
||
|
* \/ /____/ version 1.1.2
|
||
|
*
|
||
|
* This file is part of jQuery Terminal. http://terminal.jcubic.pl
|
||
|
*
|
||
|
* Copyright (c) 2010-2017 Jakub Jankiewicz <http://jcubic.pl/me>
|
||
|
* Released under the MIT license
|
||
|
*
|
||
|
* Contains:
|
||
|
*
|
||
|
* Storage plugin Distributed under the MIT License
|
||
|
* Copyright (c) 2010 Dave Schindler
|
||
|
*
|
||
|
* jQuery Timers licenced with the WTFPL
|
||
|
* <http://jquery.offput.ca/timers/>
|
||
|
*
|
||
|
* Cross-Browser Split 1.1.1
|
||
|
* Copyright 2007-2012 Steven Levithan <stevenlevithan.com>
|
||
|
* Available under the MIT License
|
||
|
*
|
||
|
* jQuery Caret
|
||
|
* Copyright (c) 2009, Gideon Sireling
|
||
|
* 3 clause BSD License
|
||
|
*
|
||
|
* sprintf.js
|
||
|
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
|
||
|
* licensed under 3 clause BSD license
|
||
|
*
|
||
|
* Date: Tue, 11 Apr 2017 16:39:20 +0000
|
||
|
*/
|
||
|
(function(e){var n=function(){if(!n.cache.hasOwnProperty(arguments[0])){n.cache[arguments[0]]=n.parse(arguments[0])}return n.format.call(null,n.cache[arguments[0]],arguments)};n.format=function(e,r){var o=1,a=e.length,s="",l,f=[],c,u,p,m,h,d;for(c=0;c<a;c++){s=t(e[c]);if(s==="string"){f.push(e[c])}else if(s==="array"){p=e[c];if(p[2]){l=r[o];for(u=0;u<p[2].length;u++){if(!l.hasOwnProperty(p[2][u])){throw n('[sprintf] property "%s" does not exist',p[2][u])}l=l[p[2][u]]}}else if(p[1]){l=r[p[1]]}else{l=r[o++]}if(/[^s]/.test(p[8])&&t(l)!=="number"){throw n("[sprintf] expecting number but found %s",t(l))}switch(p[8]){case"b":l=l.toString(2);break;case"c":l=String.fromCharCode(l);break;case"d":l=parseInt(l,10);break;case"e":l=p[7]?l.toExponential(p[7]):l.toExponential();break;case"f":l=p[7]?parseFloat(l).toFixed(p[7]):parseFloat(l);break;case"o":l=l.toString(8);break;case"s":l=(l=String(l))&&p[7]?l.substring(0,p[7]):l;break;case"u":l=l>>>0;break;case"x":l=l.toString(16);break;case"X":l=l.toString(16).toUpperCase();break}l=/[def]/.test(p[8])&&p[3]&&l>=0?" +"+l:l;h=p[4]?p[4]==="0"?"0":p[4].charAt(1):" ";d=p[6]-String(l).length;m=p[6]?i(h,d):"";f.push(p[5]?l+m:m+l)}}return f.join("")};n.cache={};n.parse=function(e){var n=e,r=[],t=[],i=0;while(n){if((r=/^[^\x25]+/.exec(n))!==null){t.push(r[0])}else if((r=/^\x25{2}/.exec(n))!==null){t.push("%")}else if((r=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(n))!==null){if(r[2]){i|=1;var o=[],a=r[2],s=[];if((s=/^([a-z_][a-z_\d]*)/i.exec(a))!==null){o.push(s[1]);while((a=a.substring(s[0].length))!==""){if((s=/^\.([a-z_][a-z_\d]*)/i.exec(a))!==null){o.push(s[1])}else if((s=/^\[(\d+)\]/.exec(a))!==null){o.push(s[1])}else{throw"[sprintf] huh?"}}}else{throw"[sprintf] huh?"}r[2]=o}else{i|=2}if(i===3){throw"[sprintf] mixing positional and named placeholders is not (yet) supported"}t.push(r)}else{throw"[sprintf] huh?"}n=n.substring(r[0].length)}return t};var r=function(e,r,t){t=r.slice(0);t.splice(0,0,e);return n.apply(null,t)};function t(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function i(e,n){for(var r=[];n>0;r[--n]=e){}return r.join("")}e.sprintf=n;e.vsprintf=r})(typeof global!=="undefined"?global:window);(function(e,n){"use strict";e.omap=function(n,r){var t={};e.each(n,function(e,i){t[e]=r.call(n,e,i)});return t};var r={clone_object:function(n){var r={};if(typeof n==="object"){if(e.isArray(n)){return this.clone_array(n)}else if(n===null){return n}else{for(var t in n){if(e.isArray(n[t])){r[t]=this.clone_array(n[t])}else if(typeof n[t]==="object"){r[t]=this.clone_object(n[t])}else{r[t]=n[t]}}}}return r},clone_array:function(n){if(!e.isFunction(Array.prototype.map)){throw new Error("Your browser don't support ES5 array map "+"use es5-shim")}return n.slice(0).map(function(e){if(typeof e==="object"){return this.clone_object(e)}else{return e}}.bind(this))}};var t=function(e){return r.clone_object(e)};var i=function(){var e="test",n=window.localStorage;try{n.setItem(e,"1");n.removeItem(e);return true}catch(r){return false}};var o=i();function a(e,n){var r;if(typeof e==="string"&&typeof n==="string"){localStorage[e]=n;return true}else if(typeof e==="object"&&typeof n==="undefined"){for(r in e){if(e.hasOwnProperty(r)){localStorage[r]=e[r]}}return true}return false}function s(e,n){var r,t,i;r=new Date;r.setTime(r.getTime()+31536e6);t="; expires="+r.toGMTString();if(typeof e==="string"&&typeof n==="string"){document.cookie=e+"="+n+t+"; path=/";return true}else if(typeof e==="object"&&typeof n==="undefined"){for(i in e){if(e.hasOwnProperty(i)){document.cookie=i+"="+e[i]+t+"; path=/"}}return true}return false}function l(e){return localStorage[e]}function f(e){var n,r,t,i;n=e+"=";r=document.cookie.split(";");for(t=0;t<r.length;t++){i=r[t];while(i.charAt(0)===" "){i=i.substring(1,i.length)}if(i.indexOf(n)===0){return i.substring(n.length,i.length)}}return null}function c(e){return delete localStorage[e]}function u(e){return s(e,"",-1)}e.extend({Storage:{set:o?a:s,get:o?l:f,remove:o?c:u}});var p=e;p.fn.extend({everyTime:function(e,n,r
|
||
|
|
||
|
}D[a.url]=D[a.url]||0;var l={jsonrpc:"2.0",method:a.method,params:a.params,id:++D[a.url]};return e.ajax({url:a.url,beforeSend:function(n,r){if(e.isFunction(a.request)){a.request(n,l)}r.data=JSON.stringify(l)},success:function(n,r,t){var i=t.getResponseHeader("Content-Type");if(!i.match(/(application|text)\/json/)){H("Response Content-Type is neither application/json"+" nor text/json")}var o;try{o=e.parseJSON(n)}catch(l){if(a.error){a.error(t,"Invalid JSON",l)}else{throw new Error("Invalid JSON")}return}if(e.isFunction(a.response)){a.response(t,o)}if(s(o)){a.success(o,r,t)}else if(a.error){a.error(t,"Invalid JSON-RPC")}else{throw new Error("Invalid JSON-RPC")}},error:a.error,contentType:"application/json",dataType:"text",async:true,cache:false,type:"POST"})};function B(){var n=e('<div class="terminal temp"><div class="cmd"><span cla'+'ss="cursor"> </span></div></div>').appendTo("body");var r=n.find("span");var t={width:r.width(),height:r.outerHeight()};n.remove();return t}function M(n){var r=e('<div class="terminal wrap"><span class="cursor">'+" </span></div>").appendTo("body").css("padding",0);var t=r.find("span");var i=t[0].getBoundingClientRect().width;var o=Math.floor(n.find("iframe").width()/i);r.remove();return o}function W(e){return Math.floor(e.height()/B().height)}function U(){if(window.getSelection||document.getSelection){var e=(window.getSelection||document.getSelection)();if(e.text){return e.text}else{return e.toString()}}else if(document.selection){return document.selection.createRange().text}}function K(n,r){var t=e("<div>"+r.replace(/\n/,"<br/>")+"<div>");var i;n.append(t);if(document.body.createTextRange){i=document.body.createTextRange();i.moveToElementText(t[0]);i.select()}else if(window.getSelection){var o=window.getSelection();if(o.setBaseAndExtent){o.setBaseAndExtent(t[0],0,t[0],1)}else if(document.createRange){i=document.createRange();i.selectNodeContents(t[0]);o.removeAllRanges();o.addRange(i)}}try{document.execCommand("copy")}catch(a){}t.remove()}var q=!e.terminal.version.match(/^\{\{/);var J="Copyright (c) 2011-2017 Jakub Jankiewicz <http://jcubic"+".pl/me>";var G=q?" v. "+e.terminal.version:" ";var Y=new RegExp(" {"+G.length+"}$");var X="jQuery Terminal Emulator"+(q?G:"");var V=[["jQuery Terminal","(c) 2011-2017 jcubic"],[X,J.replace(/^Copyright | *<.*>/g,"")],[X,J.replace(/^Copyright /,"")],[" _______ ________ __"," / / _ /_ ____________ _/__ ___/______________ _____ / /"," __ / / // / // / _ / _/ // / / / _ / _/ / / \\/ / _ \\/ /","/ / / // / // / ___/ // // / / / ___/ // / / / / /\\ / // / /__","\\___/____ \\\\__/____/_/ \\__ / /_/____/_//_/_/_/ /_/ \\/\\__\\_\\___/"," \\/ /____/ ".replace(Y," ")+G,J],[" __ _____ ________ "+" __"," / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ "+" / /"," __ / // // // // // _ // _// // / / // _ // _// // // \\/ // _ "+"\\/ /","/ / // // // // // ___// / / // / / // ___// / / / / // // /\\ // // "+"/ /__","\\___//____ \\\\___//____//_/ _\\_ / /_//____//_/ /_/ /_//_//_/ /_/ \\"+"__\\_\\___/",(" \\/ /____/ "+" ").replace(Y,"")+G,J]];e.terminal.defaults={prompt:"> ",history:true,exit:true,clear:true,enabled:true,historySize:60,maskChar:"*",wrap:true,checkArity:true,raw:false,exceptionHandler:null,pauseEvents:true,memory:false,cancelableAjax:true,processArguments:true,linksNoReferrer:false,processRPCResponse:null,Token:true,convertLinks:true,extra:{},historyState:false,importHistory:false,echoCommand:true,scrollOnEcho:true,login:null,outputLimit:-1,formatters:[],onAjaxError:null,scrollBottomOffset:20,wordAutocomplete:true,clickTimeout:200,request:e.noop,response:e.noop,onRPCError:null,completion:false,historyFilter:null,softPause:false,onInit:e.noop,onClear:e.noop,onBlur:e.noop,onFocus:e.noop,onTerminalChange:e.noop,onExit:e.noop,onPush:e.noop,onPop:e.noop,keypress:e.noop,keydown:e.noop,strings:{c
|
||
|
if(r!==n){O(r)}var i=se.token(true);var o;if(De.size()===1){o=De.top();if(Ee.login){H();if(e.isFunction(Ee.onExit)){try{Ee.onExit.call(se,se)}catch(a){y(a,"onExit")}}}else{se.error(Ae.canExitError)}if(!t){Ee.onPop.call(se,o,null,se)}}else{if(i){D()}var s=De.pop();o=De.top();K();if(!t){Ee.onPop.call(se,s,o)}if(ke&&se.get_prompt()!==Ae.login+": "){ke=false}if(e.isFunction(s.onExit)){try{s.onExit.call(se,se)}catch(a){y(a,"onExit")}}se.set_mask(o.mask)}return se},option:function(n,r){if(typeof r==="undefined"){if(typeof n==="string"){return Ee[n]}else if(typeof n==="object"){e.each(n,function(e,n){Ee[e]=n})}}else{Ee[n]=r}return se},level:function(){return De.size()},reset:function(){we(function e(){se.clear();while(De.size()>1){De.pop()}J()});return se},purge:function(){we(function n(){var n=se.prefix_name()+"_";var r=Se.get(n+"interpreters");if(r){e.each(e.parseJSON(r),function(e,n){Se.remove(n+"_commands");Se.remove(n+"_token");Se.remove(n+"_login")})}Be.purge();Se.remove(n+"interpreters")});return se},destroy:function(){we(function n(){Be.destroy().remove();pe.remove();je.remove();e(document).unbind(".terminal_"+se.id());e(window).unbind(".terminal_"+se.id());se.unbind("click mousewheel mousedown mouseup");se.removeData("terminal").removeClass("terminal");if(Ee.width){se.css("width","")}if(Ee.height){se.css("height","")}e(window).off("blur",Ue).off("focus",We);Ie.remove();Z.remove(me);if(!Z.length()){e(window).off("hashchange")}});return se},scroll_to_bottom:_,is_bottom:function(){if(Ee.scrollBottomOffset===-1){return false}else{var n,r,t;if(se.is("body")){n=e(document).height();r=e(window).scrollTop();t=window.innerHeight}else{n=le[0].scrollHeight;r=le.scrollTop();t=le.outerHeight()}var i=n-Ee.scrollBottomOffset;return r+t>i}}},function(e,n){return function(){try{return n.apply(se,[].slice.apply(arguments))}catch(r){if(e!=="exec"&&e!=="resume"){y(r,"TERMINAL")}throw r}}}));if(Ee.width){se.width(Ee.width)}if(Ee.height){se.height(Ee.height)}le=se.scroll_element();e(document).bind("ajaxSend.terminal_"+se.id(),function(e,n){Q.push(n)});var je=e('<div class="terminal-wrapper"/>').appendTo(se);var Ie=e("<iframe/>").appendTo(je);pe=e("<div>").addClass("terminal-output").appendTo(je);se.addClass("terminal");if(Ee.login&&e.isFunction(Ee.onBeforeLogin)){try{if(Ee.onBeforeLogin.call(se,se)===false){Pe=false}}catch(Ne){y(Ne,"onBeforeLogin");throw Ne}}var $e;if(typeof r==="string"){$e=r}else if(r instanceof Array){for(var ze=0,He=r.length;ze<He;++ze){if(typeof r[ze]==="string"){$e=r[ze];break}}}if($e&&(typeof Ee.login==="string"||Ee.login===true)){Ee.login=g($e,Ee.login)}Z.append(se);var De;var Be;var Me;function We(){if(Me){se.focus()}}function Ue(){Me=Fe;se.disable()}h(r,!!Ee.login,function(r){if(Ee.completion&&typeof Ee.completion!=="boolean"||!Ee.completion){r.completion="settings"}var t=e.extend({},X,Ee.keymap||{});De=new d(e.extend({},Ee.extra,{name:Ee.name,prompt:Ee.prompt,keypress:Ee.keypress,keydown:Ee.keydown,resize:Ee.onResize,greetings:Ee.greetings,mousewheel:Ee.mousewheel,keymap:t},r));Be=e("<div/>").appendTo(je).cmd({prompt:Ee.prompt,history:Ee.memory?"memory":Ee.history,historyFilter:Ee.historyFilter,historySize:Ee.historySize,width:"100%",enabled:Fe&&!w,keydown:oe,keymap:t,clickTimeout:Ee.clickTimeout,keypress:function(n){var r=De.top();if(e.isFunction(r.keypress)){return r.keypress.call(se,n,se)}else if(e.isFunction(Ee.keypress)){return Ee.keypress.call(se,n,se)}},onCommandChange:function(n){if(e.isFunction(Ee.onCommandChange)){try{Ee.onCommandChange.call(se,n,se)}catch(r){y(r,"onCommandChange");throw r}}_()},commands:z});if(Fe&&se.is(":visible")&&!w){se.focus(n,true)}else{se.disable()}se.oneTime(100,function(){function n(n){var r=e(n.target);if(!r.closest(".terminal").length&&se.enabled()&&Ee.onBlur.call(se,se)!==false){se.disable()}}e(document).bind("click.terminal_"+se.id(),n).bind("contextmenu.terminal_"+se.id(),n)});var i=e(window);if(!w){i.on("focus.terminal_"+se.id(),We).on("blur.terminal_"+se.id(),Ue)}else{}if(w){se.click(function(){if(!se.enabled()&&!Le){se.focus();Be.enable()}else{se.focus(false)}})}else{(
|