Kiln » Kiln Storage Service Read More
Clone URL:  
jquery.terminal-0.3.3.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* | __ _____ ________ __ | / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / / | __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ / | / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__ | \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/ | \/ /____/ version 0.3.3 http://terminal.jcubic.pl Licensed under GNU LGPL Version 3 license Copyright (c) 2011 Jakub Jankiewicz <http://jcubic.pl> Includes: Storage plugin Distributed under the MIT License Copyright (c) 2010 Dave Schindler LiveQuery plugin Dual MIT and GPL Copyright (c) 2008 Brandon Aaron (http://brandonaaron.net) jQuery Timers licenced with the WTFPL <http://jquery.offput.ca/every/> Date: Mon, 07 Mar 2011 11:57:17 +0000 */ Array.prototype.has=function(g){for(var v=this.length;v--;)if(this[v]==g)return true;return false};function get_stack(g){return g?[g.toString().match(/.*\n.*\n/)].concat(get_stack(g.caller)):[]} (function(g,v){function S(a,d){var c;if(typeof a==="string"&&typeof d==="string"){localStorage[a]=d;return true}else if(typeof a==="object"&&typeof d==="undefined"){for(c in a)if(a.hasOwnProperty(c))localStorage[c]=a[c];return true}return false}function O(a,d){var c,i;c=new Date;c.setTime(c.getTime()+31536E6);c="; expires="+c.toGMTString();if(typeof a==="string"&&typeof d==="string"){document.cookie=a+"="+d+c+"; path=/";return true}else if(typeof a==="object"&&typeof d==="undefined"){for(i in a)if(a.hasOwnProperty(i))document.cookie= i+"="+a[i]+c+"; path=/";return true}return false}function T(a){return localStorage[a]}function U(a){var d,c,i;a+="=";d=document.cookie.split(";");for(c=0;c<d.length;c++){for(i=d[c];i.charAt(0)===" ";)i=i.substring(1,i.length);if(i.indexOf(a)===0)return i.substring(a.length,i.length)}return null}function V(a){return delete localStorage[a]}function W(a){return O(a,"",-1)}function P(a,d){var c=[],i=a.length;if(i<d)return[a];for(var j=0;j<i;j+=d)c.push(a.substring(j,j+d));return c}function x(a){if(typeof a== "string"){a=a.replace(/&(?!#[0-9]*;)/g,"&amp;");a=a.replace(/</g,"&lt;").replace(/>/g,"&gt;");a=a.replace(/\n/g,"<br/>");a=a.replace(/ /g,"&nbsp;");a=a.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");var d=a.split(X);if(d.length>1)a=g.map(d,function(c){return c[0]=="["?c.replace(Y,function(i,j,p,u,k){i="";if(j.indexOf("b")!=-1)i+="font-weight:bold;";if(j.indexOf("u")!=-1)i+="text-decoration:underline;";if(j.indexOf("i")!=-1)i+="font-style:italic; ";if(p.match(Q))i+="color:"+p+";";if(u.match(Q))i+="background-color:"+ u;return a='<span style="'+i+'">'+k+"</span>"}):"<span>"+c+"</span>"}).join("");return a}else return""}function R(a){var d=a instanceof Array?a:a?[a]:[],c=0;g.extend(this,{left:function(){if(c===0)c=d.length-1;else--c;return d[c]},right:function(){if(c==d.length-1)c=0;else++c;return d[c]},current:function(){return d[c]},data:function(){return d},reset:function(){c=0},append:function(i){d.push(i);this.reset()}})}function Z(a){var d=a?[a]:[];g.extend(this,{size:function(){return d.length},pop:function(){if(d.length=== 0)return null;else{var c=d[d.length-1];d=d.slice(0,d.length-1);return c}},push:function(c){d=d.concat([c]);return c},top:function(){return d.length>0?d[d.length-1]:null}})}function $(a){var d=true;if(typeof a==="string"&&a!=="")a+="_";var c=g.Storage.get(a+"commands"),i=new R(c?eval("("+c+")"):[""]);g.extend(this,{append:function(j){if(d&&i.current()!=j){i.append(j);g.Storage.set(a+"commands",g.json_stringify(i.data()))}},data:function(){return i.data()},next:function(){return i.right()},last:function(){i.reset()}, previous:function(){return i.left()},clear:function(){i=new R;g.Storage.remove(a+"commands")},enable:function(){d=true},disable:function(){d=false}})}g.extend(g.fn,{livequery:function(a,d,c){var i=this,j;if(g.isFunction(a)){c=d;d=a;a=v}g.each(g.livequery.queries,function(p,u){if(i.selector==u.selector&&i.context==u.context&&a==u.type&&(!d||d.$lqguid==u.fn.$lqguid)&&(!c||c.$lqguid==u.fn2.$lqguid))return(j=u)&&false});j=j||new g.livequery(this.selector,this.context,a,d,c);j.stopped=false;j.run();return this}, expire:function(a,d,c){var i=this;if(g.isFunction(a)){c=d;d=a;a=v}g.each(g.livequery.queries,function(j,p){if(i.selector==p.selector&&i.context==p.context&&(!a||a==p.type)&&(!d||d.$lqguid==p.fn.$lqguid)&&(!c||c.$lqguid==p.fn2.$lqguid)&&!this.stopped)g.livequery.stop(p.id)});return this}});g.livequery=function(a,d,c,i,j){this.selector=a;this.context=d||document;this.type=c;this.fn=i;this.fn2=j;this.elements=[];this.stopped=false;this.id=g.livequery.queries.push(this)-1;i.$lqguid=i.$lqguid||g.livequery.guid++; if(j)j.$lqguid=j.$lqguid||g.livequery.guid++;return this};g.livequery.prototype={stop:function(){var a=this;if(this.type)this.elements.unbind(this.type,this.fn);else this.fn2&&this.elements.each(function(d,c){a.fn2.apply(c)});this.elements=[];this.stopped=true},run:function(){if(!this.stopped){var a=this,d=this.elements,c=g(this.selector,this.context),i=c.not(d);this.elements=c;if(this.type){i.bind(this.type,this.fn);d.length>0&&g.each(d,function(j,p){g.inArray(p,c)<0&&g.event.remove(p,a.type,a.fn)})}else{i.each(function(){a.fn.apply(this)}); this.fn2&&d.length>0&&g.each(d,function(j,p){g.inArray(p,c)<0&&a.fn2.apply(p)})}}}};g.extend(g.livequery,{guid:0,queries:[],queue:[],running:false,timeout:null,checkQueue:function(){if(g.livequery.running&&g.livequery.queue.length)for(var a=g.livequery.queue.length;a--;)g.livequery.queries[g.livequery.queue.shift()].run()},pause:function(){g.livequery.running=false},play:function(){g.livequery.running=true;g.livequery.run()},registerPlugin:function(){g.each(arguments,function(a,d){if(g.fn[d]){var c= g.fn[d];g.fn[d]=function(){var i=c.apply(this,arguments);g.livequery.run();return i}}})},run:function(a){if(a!=v)g.inArray(a,g.livequery.queue)<0&&g.livequery.queue.push(a);else g.each(g.livequery.queries,function(d){g.inArray(d,g.livequery.queue)<0&&g.livequery.queue.push(d)});g.livequery.timeout&&clearTimeout(g.livequery.timeout);g.livequery.timeout=setTimeout(g.livequery.checkQueue,20)},stop:function(a){a!=v?g.livequery.queries[a].stop():g.each(g.livequery.queries,function(d){g.livequery.queries[d].stop()})}}); g.livequery.registerPlugin("append","prepend","after","before","wrap","attr","removeAttr","addClass","removeClass","toggleClass","empty","remove");g(function(){g.livequery.play()});var aa=g.prototype.init;g.prototype.init=function(a,d){var c=aa.apply(this,arguments);if(a&&a.selector){c.context=a.context;c.selector=a.selector}if(typeof a=="string"){c.context=d||document;c.selector=a}return c};g.prototype.init.prototype=g.prototype;var J=typeof window.localStorage!=="undefined";g.extend({Storage:{set:J? S:O,get:J?T:U,remove:J?V:W}});jQuery.fn.extend({everyTime:function(a,d,c,i,j){return this.each(function(){jQuery.timer.add(this,a,d,c,i,j)})},oneTime:function(a,d,c){return this.each(function(){jQuery.timer.add(this,a,d,c,1)})},stopTime:function(a,d){return this.each(function(){jQuery.timer.remove(this,a,d)})}});jQuery.extend({timer:{guid:1,global:{},regex:/^([0-9]+)\s*(.*s)?$/,powers:{ms:1,cs:10,ds:100,s:1E3,das:1E4,hs:1E5,ks:1E6},timeParse:function(a){if(a==v||a==null)return null;var d=this.regex.exec(jQuery.trim(a.toString())); return d[2]?parseInt(d[1],10)*(this.powers[d[2]]||1):a},add:function(a,d,c,i,j,p){var u=0;if(jQuery.isFunction(c)){j||(j=i);i=c;c=d}d=jQuery.timer.timeParse(d);if(!(typeof d!="number"||isNaN(d)||d<=0)){if(j&&j.constructor!=Number){p=!!j;j=0}j=j||0;p=p||false;if(!a.$timers)a.$timers={};a.$timers[c]||(a.$timers[c]={});i.$timerID=i.$timerID||this.guid++;var k=function(){if(!(p&&this.inProgress)){this.inProgress=true;if(++u>j&&j!==0||i.call(a,u)===false)jQuery.timer.remove(a,c,i);this.inProgress=false}}; k.$timerID=i.$timerID;a.$timers[c][i.$timerID]||(a.$timers[c][i.$timerID]=window.setInterval(k,d));this.global[c]||(this.global[c]=[]);this.global[c].push(a)}},remove:function(a,d,c){var i=a.$timers,j;if(i){if(d){if(i[d]){if(c){if(c.$timerID){window.clearInterval(i[d][c.$timerID]);delete i[d][c.$timerID]}}else for(c in i[d]){window.clearInterval(i[d][c]);delete i[d][c]}for(j in i[d])break;if(!j){j=null;delete i[d]}}}else for(d in i)this.remove(a,d,c);for(j in i)break;if(!j)a.$timers=null}}}});if(jQuery.browser.msie)jQuery(window).one("unload", function(){var a=jQuery.timer.global,d;for(d in a)for(var c=a[d],i=c.length;--i;)jQuery.timer.remove(c[i],d)});var X=/(\[\[[biu]*;[^;]*;[^\]]*\][^\]]*\])/g,Y=/\[\[([biu]*);([^;]*);([^\]]*)\]([^\]]*)\]/g,Q=/#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})/;g.json_stringify=function(a,d){var c="";d=d===v?1:d;switch(typeof a){case "function":c+=a;break;case "boolean":c+=a?"true":"false";break;case "object":if(a===null)c+="null";else if(a instanceof Array){c+="[";for(var i=a.length,j=0;j<i-1;++j)c+=g.json_stringify(a[j], d+1);c+=g.json_stringify(a[i-1],d+1)+"]"}else{c+="{";for(i in a)if(a.hasOwnProperty(i))c+='"'+i+'":'+g.json_stringify(a[i],d+1);c+="}"}break;case "string":i=a;var p={"\\\\":"\\\\",'"':'\\"',"/":"\\/","\\n":"\\n","\\r":"\\r","\\t":"\\t"};for(j in p)if(p.hasOwnProperty(j))i=i.replace(RegExp(j,"g"),p[j]);c+='"'+i+'"';break;case "number":c+=String(a)}c+=d>1?",":"";if(d==1)c=c.replace(/,([\]}])/g,"$1");return c.replace(/([\[{]),/g,"$1")};g.fn.cmd=function(a){function d(e){var q=e.substring(0,j-p-1);e= e.substring(j-p-1);return[q].concat(P(e,j))}var c=this;c.addClass("cmd");c.append('<span class="prompt"></span><span></span><span class="cursor">&nbsp;</span><span></span>');var i=g("<textarea/>").addClass("clipboard").appendTo(c);a.width&&c.width(a.width);var j,p,u=a.mask||false,k="",m=0,C,F=a.enabled,K,z,L=function(){var e=c.find(".cursor");return function(){e.toggleClass("inverted")}}(),N=c.find(".cursor"),f=function(e){function q(b,h){if(h==b.length){w.html(x(b));D.html("&nbsp;");o.html("")}else if(h=== 0){w.html("");D.html(x(b.slice(0,1)));o.html(x(b.slice(1)))}else{var n=x(b.slice(0,h));w.html(n);n=b.slice(h,h+1);D.html(n==" "?"&nbsp;":x(n));h==b.lenght-1?o.html(""):o.html(x(b.slice(h+1)))}}function A(b){return"<div>"+x(b)+"</div>"}function l(b){var h=o;g.each(b,function(n,s){h=g(A(s)).insertAfter(h)})}function G(b){g.each(b,function(h,n){w.before(A(n))})}var D=e.find(".cursor"),w=D.prev(),o=D.next();return function(){var b=u?k.replace(/./g,"*"):k;e.find("div").remove();w.html("");if(b.length> j-p-1){var h=d(b),n=h[0].length;if(m<n){q(h[0],m);l(h.slice(1))}else if(m==n){w.before(A(h[0]));q(h[1],0);l(h.slice(2))}else{var s=h.length;if(m<n){q(h[0],m);l(h.slice(1))}else if(m==n){w.before(A(h[0]));q(h[1],0);l(h.slice(2))}else{var r=h.slice(-1)[0];b=b.length-m;if(b<=r.length){G(h.slice(0,-1));n=r.length==b?0:r.length-b;q(r,n)}else if(s==3){w.before("<div>"+x(h[0])+"</div>");q(h[1],m-n-1);o.after("<div>"+x(h[2])+"</div>")}else{r=Math.floor((m+p)/j);s=h[r];n=function(y){for(var t=0,B=y.length;B--;)t+= y[B].length;return t}(h.slice(0,r));n=m-n;if(n==j){n=0;s=h[++r]}x(s.slice(0,n));q(s,n);G(h.slice(0,r));l(h.slice(r+1))}}}}else if(b===""){w.html("");D.html("&nbsp;");o.html("")}else q(b,m)}}(c),E=function(){var e=c.find(".prompt");return function(){if(typeof C=="string"){p=C.length;e.html(x(C)+"&nbsp;")}else C(function(q){p=q.length;e.html(x(q)+"&nbsp;")})}}();g.extend(c,{name:function(e){if(e!==v){K=e;z=new $(e)}else return K},history:function(){return z},set:function(e,q){if(e!==v){k=e;if(!q)m= k.length;f()}},insert:function(e,q){if(m==k.length)k+=e;else k=m===0?e+k:k.slice(0,m)+e+k.slice(m);q||(m+=e.length);f()},get:function(){return k},commands:function(e){if(e)a.commands=e;else return e},destroy:function(){g(document.documentElement).unbind(".commandline");c.find(".prompt").remove()},prompt:function(e){if(e===v)return C;else{if(typeof e=="string"||typeof e=="function")C=e;else throw"prompt must be a function or string";E()}},position:function(e){if(typeof e=="number"){m=e<0?0:e>k.length? k.length:e;f()}else return m},resize:function(e){if(e)j=e;else{e=c.width();var q=N.innerWidth();j=Math.floor(e/q)}f()},enable:function(){if(!this.isenabled()){c.everyTime(500,"blink",L);F=true}},isenabled:function(){return F},disable:function(){if(this.isenabled()){c.stopTime("blink",L);c.find(".cursor").removeClass("inverted");F=false}},mask:function(e){if(typeof e=="boolean"){u=e;f()}else return u}});c.name(a.name||"");C=a.prompt||">";E();if(a.enabled===v||a.enabled===true)c.enable();g(document.documentElement).keypress(function(e){var q; if(e.ctrlKey&&e.which==99)return true;if(a.keypress)q=a.keypress(e);if(q===v||q){if(F)if([38,32,13,40,0,8].has(e.which)&&e.keyCode!=123&&!(e.which==40&&e.shiftKey||e.which==38&&e.shiftKey))return false;else if(!e.ctrlKey&&!(e.altKey&&e.which==100)){c.insert(String.fromCharCode(e.which));return false}}else return q;if(e.which==100&&e.ctrlKey)return false}).keydown(function(e){if(a.keydown&&a.keydown(e)===false)return false;if(F){var q;if(e.keyCode==13){z&&k&&z.append(k);z.last();e=k;c.set("");typeof C== "function"&&E();a.commands&&a.commands(e)}else if(e.which==32)c.insert(" ");else if(e.which==8){if(k!==""&&m>0){k=k.slice(0,m-1)+k.slice(m,k.length);--m;f()}}else if(e.which==9&&!(e.ctrlKey||e.altKey))c.insert("\t");else if(e.which==46||e.which==68&&e.ctrlKey){if(k!==""&&m<k.length){k=k.slice(0,m)+k.slice(m+1,k.length);f()}return true}else if(z&&e.which==38||e.which==80&&e.ctrlKey)c.set(z.previous());else if(z&&e.which==40||e.which==78&&e.ctrlKey)c.set(z.next());else if(e.which==27)c.set("");else if(e.which== 37||e.which==66&&e.ctrlKey)if(e.ctrlKey&&e.which!=66){q=m-1;e=0;for(k[q]==" "&&--q;q>0;--q)if(k[q]==" "&&k[q+1]!=" "){e=q+1;break}c.position(e)}else{if(m>0){--m;f()}}else if(e.which==39||e.which==70&&e.ctrlKey)if(e.ctrlKey&&e.which!=70){k[m]==" "&&++m;e=k.slice(m).match(/[^ ] {2,}| +[^ ]?/);if(!e||e[0].match(/^ +$/))m=k.length;else if(e[0][0]!=" ")m+=e.index+1;else{m+=e.index+e[0].length-1;e[0][e[0].length-1]!=" "&&--m}f()}else{if(m<k.length){++m;f()}}else if(e.which==123)return true;else if(e.which== 36)c.position(0);else if(e.which==35)c.position(k.length);else if(e.ctrlKey)if(e.shiftKey){if(e.which==84)return true}else{if(!e.altKey)if(e.which==65)c.position(0);else if(e.which==69)c.position(k.length);else if(e.which==88||e.which==67||e.which==87||e.which==84)return true;else if(e.which==86){i.focus();c.oneTime(1,function(){c.insert(i.val());i.blur();i.val("")});return true}else if(e.which==75)if(m===0)c.set("");else m!=k.length&&c.set(k.slice(0,m));else if(e.which==17)return true}else if(e.altKey)e.which== 68&&c.set(k.slice(0,m)+k.slice(m).replace(/[^ ]+ |[^ ]+$/,""),true);else return true;return false}else if(e.altKey&&e.which==68||e.ctrlKey&&[65,66,68,69,80,78,70].has(e.which)||[35,36,37,38,39,40].has(e.which))return false});return c};var M=[];g.jrpc=function(a,d,c,i,j,p){d=g.json_stringify({jsonrpc:"2.0",method:c,params:i,id:d});return g.ajax({url:a,data:d,success:j,error:p,contentType:"application/json",dataType:"json",beforeSend:function(u){M.push(u)},async:true,cache:false,type:"POST"})};J=/ {13}$/; var ba=[["jQuery Terminal","(c) 2011 jcubic"],["JQuery Terminal Emulator v. 0.3.3","Copyright (c) 2011 Jakub Jankiewicz <http://jcubic.pl>".replace(/ *<.*>/,"")],["JQuery Terminal Emulator version version 0.3.3","Copyright (c) 2011 Jakub Jankiewicz <http://jcubic.pl>"],[" _______ ________ __"," / / _ /_ ____________ _/__ ___/______________ _____ / /"," __ / / // / // / _ / _/ // / / / _ / _/ / / \\/ / _ \\/ /","/ / / // / // / ___/ // // / / / ___/ // / / / / /\\ / // / /__", "\\___/____ \\\\__/____/_/ \\__ / /_/____/_//_/ /_/ /_/ \\/\\__\\_\\___/"," \\/ /____/ ".replace(J,"")+"version 0.3.3","Copyright (c) 2011 Jakub Jankiewicz <http://jcubic.pl>"],[" __ _____ ________ __"," / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / /"," __ / // // // // // _ // _// // / / // _ // _// // // \\/ // _ \\/ /","/ / // // // // // ___// / / // / / // ___// / / / / // // /\\ // // / /__", "\\___//____ \\\\___//____//_/ _\\_ / /_//____//_/ /_/ /_//_//_/ /_/ \\__\\_\\___/"," \\/ /____/ ".replace(J,"")+"version 0.3.3","Copyright (c) 2011 Jakub Jankiewicz <http://jcubic.pl>"]],H=new function(a){var d=a?[a]:[],c=0;g.extend(this,{rotate:function(){if(d.length==1)return d[0];else{if(c==d.length-1)c=0;else++c;return d[c]}},length:function(){return d.length},set:function(i){for(var j=d.length;j--;)if(d[j]===i){c=j;return}this.append(i)}, front:function(){return d[c]},append:function(i){d.push(i)}})};M=[];g.fn.terminal=function(a,d){function c(){var b=g("<span>x</span>").appendTo(f),h=Math.floor(f.width()/b.width());b.remove();return h}function i(b,h){if(typeof b=="string")f.error("&#91;"+h+"&#93;: "+b);else{f.error("&#91;"+h+"&#93;: "+b.fileName+": "+b.message);f.pause();g.get(b.fileName,function(n){f.resume();var s=b.lineNumber-1;f.error("&#91;"+b.lineNumber+"&#93;: "+n.split("\n")[s])})}}function j(b,h){try{if(typeof h=="function")h(function(){}); else if(typeof h!="string")throw b+" must be string or function";}catch(n){i(n,b.toUpperCase());return false}return true}function p(b){b.scrollTop(f.attr("scrollHeight"))}function u(b){b=typeof b=="string"?b:String(b);var h;if(b.length>A){b=b.split("\n");h=g("<div></div>");for(var n=b.length,s=0;s<n;++s)if(b[s]===""||b[s]=="\r")h.append("<div>&nbsp;</div>");else if(b[s].length>A){var r=P(b[s],A);g.each(r,function(y,t){g("<div/>").html(x(t)).appendTo(h)})}else g("<div/>").html(x(b[s])).appendTo(h)}else h= g("<div/>").html(x(b));e.append(h);h.width("100%");p(f);return h}function k(b,h){var n=1,s=function(r,y){h.pause();g.jrpc(b,n++,r,y,function(t){if(t.error)h.error("&#91;RPC&#93; "+t.error.message);else if(typeof t.result=="string")h.echo(t.result);else if(t.result instanceof Array)h.echo(t.result.join(" "));else if(typeof t.result=="object"){var B="",I;for(I in t.result)if(t.result.hasOwnProperty(I))B+=I+": "+t.result[I]+"\n";h.echo(B)}h.resume()},function(t,B){h.error("&#91;AJAX&#93; "+B+" - Server reponse is: \n"+ t.responseText);h.resume()})};return function(r,y){if(r!==""){var t,B;if(r.match(/[^ ]* /)){r=r.split(/ */);t=r[0];B=r.slice(1)}else{t=r;B=[]}if(!l.login||t=="help")s(t,B);else{var I=y.token();I?s(t,[I].concat(B)):y.error("&#91;AUTH&#93; Access denied (no token)")}}}}function m(b){var h=o.prompt();if(o.mask())b=b.replace(/./g,"*");typeof h=="function"?h(function(n){f.echo(n+" "+b)}):f.echo(h+" "+b)}function C(b){try{var h=w.top();if(b=="exit"&&l.exit)if(w.size()==1)l.login?K():f.echo("You can exit from main interpeter"); else f.pop("exit");else{m(b);b=="clear"&&l.clear?f.clear():h.eval(b,f)}}catch(n){i(n,"USER");throw n;}}function F(){var b=null;o.prompt("login:");l.history&&o.history().disable();o.commands(function(h){try{m(h);if(b){o.mask(false);f.pause();l.login(b,h,function(s){if(s){var r=l.name;r=r?"_"+r:"";g.Storage.set("token"+r,s);g.Storage.set("login"+r,b);o.commands(C);L()}else{f.error("Wrong password try again");o.prompt("login:");b=null}f.resume();l.history&&o.history().enable()})}else{b=h;o.prompt("password:"); o.mask(true)}}catch(n){i(n,"LOGIN",f);throw n;}})}function K(){var b=l.name;b=b?"_"+b:"";g.Storage.remove("token"+b,null);g.Storage.remove("login"+b,null);l.history&&o.history().disable();F()}function z(){var b=w.top(),h="";if(b.name!==v&&b.name!=="")h+=b.name+"_";h+=q;o.name(h);o.prompt(b.prompt);l.history&&o.history().enable();o.set("");if(typeof b.onStart=="function")b.onStart(f)}function L(){z();if(d.greetings===v)f.echo(f.signature);else d.greetings&&f.echo(d.greetings);if(typeof l.onInit=="function")l.onInit(f)} function N(b){if(l.keypress&&l.keypress(b,f)===false)return false;if(f.paused()){if(b.which==100&&b.ctrlKey){for(b=M.length;b--;){var h=M[b];if(4!=h.readyState)try{h.abort()}catch(n){f.error("error in aborting ajax")}}f.resume();return false}}else if(b.which==100&&b.ctrlKey){if(l.exit&&o.get()==="")if(w.size()>1||l.login!==v)f.pop("");else{f.resume();f.echo("")}return false}else if(b.which==118&&b.ctrlKey){f.oneTime(1,function(){f.attr({scrollTop:f.attr("scrollHeight")})});return true}else if(b.keyCode== 9&&b.ctrlKey)f.focus(false);else if(b.keyCode==34)f.scroll(f.height());else b.keyCode==33?f.scroll(-f.height()):f.attr({scrollTop:f.attr("scrollHeight")})}var f=this,E=[],e,q=H.length(),A,l={name:null,prompt:">",history:true,exit:true,clear:true,enabled:true,login:null,onInit:null,onExit:null,keypress:null,keydown:null};if(d){d.width&&f.width(d.width);d.height&&f.height(d.height);g.extend(l,d)}var G=!l.enabled;if(f.length===0)throw'Sorry, but terminal said that "'+f.selector+'" is not valid selector'; if(f.data("terminal")){f.ajaxSend(function(b,h){M.push(h)});return f.data("terminal")}e=g("<div>").addClass("terminal-output").appendTo(f);f.addClass("terminal").append("<div/>");g.extend(f,{clear:function(){e.html("");o.set("");E=[];f.attr({scrollTop:0});return f},paused:function(){return G},pause:function(){if(o){f.disable();o.hide()}return f},resume:function(){if(o){f.enable();o.show();p(f)}return f},cols:function(){return A},rows:function(){return E.length},history:function(){return o.history().data()}, next:function(){if(H.length()==1)return f;else{H.front().disable();var b=H.rotate().enable(),h=b.offset().top-50;g("html,body").animate({scrollTop:h},500);return b}},focus:function(b){f.oneTime(1,function(){if(H.length()==1)b===false?f.disable():f.enable();else if(b===false)f.next();else{H.front().disable();H.set(f);f.enable()}});return f},enable:function(){A===v&&f.resize();if(G)if(o){o.enable();G=false}return f},disable:function(){if(o){G=true;o.disable()}return f},enabled:function(){return G}, signature:function(){var b=f.cols();b=b<15?null:b<35?0:b<55?1:b<64?2:b<75?3:4;return b!==null?ba[b].join("\n")+"\n":""},get_command:function(){return o.get()},insert:function(b){o.insert(b);return f},set_prompt:function(b){j("prompt",b)&&o.prompt(b);return f},set_command:function(b){o.set(b);return f},set_mask:function(b){o.mask(b);return f},get_output:function(){return g.map(E,function(b,h){return typeof h=="function"?h():h}).get().join("\n")},resize:function(b,h){if(b&&h){f.width(b);f.height(h)}A= c();o.resize(A);var n=e.detach();e.html("");g.each(E,function(s,r){u(typeof r=="function"?r():r)});f.prepend(n);p(f);return f},echo:function(b){E.push(b);return u(typeof b=="function"?b():b)},error:function(b){f.echo(b).addClass("error")},scroll:function(b){b>f.attr("scrollTop")&&b>0&&f.attr("scrollTop",0);var h=f.attr("scrollTop");f.attr("scrollTop",h+b);return f},logout:l.login?function(){for(;w.size()>1;)w.pop();K();return f}:function(){throw"You don't have login function";},token:l.login?function(){var b= l.name;return g.Storage.get("token"+(b?"_"+b:""))}:null,login_name:l.login?function(){var b=l.name;return g.Storage.get("login_"+(b?"_"+b:""))}:null,name:function(){return l.name},push:function(b,h){if(!h.prompt||j("prompt",h.prompt)){if(typeof b=="string")b=k(h.eval,f);w.push(g.extend({eval:b},h));z()}return f},pop:function(b){b!==v&&m(b);if(w.top().name===l.name){if(l.login){K();if(typeof l.onExit=="function")l.onExit(f)}}else{b=w.pop();z();if(typeof b.onExit=="function")b.onExit(f)}return f}}); var D;switch(typeof a){case "string":D=a;a=k(a,f);break;case "object":a=function(b){return function(h){if(h!=""){h=h.split(/ */);var n=h[0];h=h.slice(1);var s=b[n];typeof s=="function"?s.apply(f,h):f.echo("Command '"+n+"' Not Found")}}}(a)}if(D&&typeof l.login=="string"||D)l.login=function(b){var h=1;return function(n,s,r){f.pause();g.jrpc(D,h++,b,[n,s],function(y){f.resume();!y.error&&y.result?r(y.result):r(null)},function(y,t){f.resume();f.error("&#91;AJAX&#92; Response: "+t+"\n"+y.responseText)})}}(typeof l.login== "boolean"?"login":l.login);if(j("prompt",l.prompt)){var w=new Z({name:l.name,eval:a,prompt:l.prompt,greetings:l.greetings}),o=f.find(".terminal-output").next().cmd({prompt:l.prompt,history:l.history,width:"100%",keydown:l.keydown?function(b){return l.keydown(b,f)}:null,keypress:N,commands:C});f.livequery(function(){f.resize()});H.append(f);l.enabled===true?f.focus():f.disable();g(window).resize(f.resize);f.click(function(){f.focus()});f.token&&!f.token()&&f.login_name&&!f.login_name()?F():L();typeof g.fn.init.prototype.mousewheel=== "function"&&f.mousewheel(function(b,h){h>0?f.scroll(-40):f.scroll(40);return false},true)}f.data("terminal",f);return f}})(jQuery);