Login   Register  
PHP Classes
elePHPant
Icontem

File: templates/terminal/phpquery.min.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Andoitz Jordan Marmolejo  >  PHP Query Terminal  >  templates/terminal/phpquery.min.js  >  Download  
File: templates/terminal/phpquery.min.js
Role: Auxiliary data
Content type: text/plain
Description: javascript for phpquery terminal
Class: PHP Query Terminal
Run command classes from an interactive console
Author: By
Last change:
Date: 4 months ago
Size: 48,981 bytes
 

Contents

Class file image Download
(function(e){function r(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function i(e,t){for(var n=[];t>0;n[--t]=e){}return n.join("")}var t=function(){if(!t.cache.hasOwnProperty(arguments[0])){t.cache[arguments[0]]=t.parse(arguments[0])}return t.format.call(null,t.cache[arguments[0]],arguments)};t.format=function(e,n){var s=1,o=e.length,u="",a,f=[],l,c,h,p,d,v;for(l=0;l<o;l++){u=r(e[l]);if(u==="string"){f.push(e[l])}else if(u==="array"){h=e[l];if(h[2]){a=n[s];for(c=0;c<h[2].length;c++){if(!a.hasOwnProperty(h[2][c])){throw t('[sprintf] property "%s" does not exist',h[2][c])}a=a[h[2][c]]}}else if(h[1]){a=n[h[1]]}else{a=n[s++]}if(/[^s]/.test(h[8])&&r(a)!="number"){throw t("[sprintf] expecting number but found %s",r(a))}switch(h[8]){case"b":a=a.toString(2);break;case"c":a=String.fromCharCode(a);break;case"d":a=parseInt(a,10);break;case"e":a=h[7]?a.toExponential(h[7]):a.toExponential();break;case"f":a=h[7]?parseFloat(a).toFixed(h[7]):parseFloat(a);break;case"o":a=a.toString(8);break;case"s":a=(a=String(a))&&h[7]?a.substring(0,h[7]):a;break;case"u":a=a>>>0;break;case"x":a=a.toString(16);break;case"X":a=a.toString(16).toUpperCase();break}a=/[def]/.test(h[8])&&h[3]&&a>=0?"+"+a:a;d=h[4]?h[4]=="0"?"0":h[4].charAt(1):" ";v=h[6]-String(a).length;p=h[6]?i(d,v):"";f.push(h[5]?a+p:p+a)}}return f.join("")};t.cache={};t.parse=function(e){var t=e,n=[],r=[],i=0;while(t){if((n=/^[^\x25]+/.exec(t))!==null){r.push(n[0])}else if((n=/^\x25{2}/.exec(t))!==null){r.push("%")}else if((n=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(t))!==null){if(n[2]){i|=1;var s=[],o=n[2],u=[];if((u=/^([a-z_][a-z_\d]*)/i.exec(o))!==null){s.push(u[1]);while((o=o.substring(u[0].length))!==""){if((u=/^\.([a-z_][a-z_\d]*)/i.exec(o))!==null){s.push(u[1])}else if((u=/^\[(\d+)\]/.exec(o))!==null){s.push(u[1])}else{throw"[sprintf] huh?"}}}else{throw"[sprintf] huh?"}n[2]=s}else{i|=2}if(i===3){throw"[sprintf] mixing positional and named placeholders is not (yet) supported"}r.push(n)}else{throw"[sprintf] huh?"}t=t.substring(n[0].length)}return r};var n=function(e,n,r){r=n.slice(0);r.splice(0,0,e);return t.apply(null,r)};e.sprintf=t;e.vsprintf=n})(typeof exports!="undefined"?exports:window);(function(e,t){"use strict";function r(e,t){var n;if(typeof e==="string"&&typeof t==="string"){localStorage[e]=t;return true}else if(typeof e==="object"&&typeof t==="undefined"){for(n in e){if(e.hasOwnProperty(n)){localStorage[n]=e[n]}}return true}return false}function i(e,t){var n,r,i;n=new Date;n.setTime(n.getTime()+31536e6);r="; expires="+n.toGMTString();if(typeof e==="string"&&typeof t==="string"){document.cookie=e+"="+t+r+"; path=/";return true}else if(typeof e==="object"&&typeof t==="undefined"){for(i in e){if(e.hasOwnProperty(i)){document.cookie=i+"="+e[i]+r+"; path=/"}}return true}return false}function s(e){return localStorage[e]}function o(e){var t,n,r,i;t=e+"=";n=document.cookie.split(";");for(r=0;r<n.length;r++){i=n[r];while(i.charAt(0)===" "){i=i.substring(1,i.length)}if(i.indexOf(t)===0){return i.substring(t.length,i.length)}}return null}function u(e){return delete localStorage[e]}function a(e){return i(e,"",-1)}function f(e,t){var n=[];var r=e.length;if(r<t){return[e]}for(var i=0;i<r;i+=t){n.push(e.substring(i,i+t))}return n}function l(t){var n=t?[t]:[];var r=0;e.extend(this,{get:function(){return n},rotate:function(){if(n.length===1){return n[0]}else{if(r===n.length-1){r=0}else{++r}return n[r]}},length:function(){return n.length},set:function(e){for(var t=n.length;t--;){if(n[t]===e){r=t;return}}this.append(e)},front:function(){return n[r]},append:function(e){n.push(e)}})}function c(t){var n=t?[t]:[];e.extend(this,{map:function(t){return e.map(n,t)},size:function(){return n.length},pop:function(){if(n.length===0){return null}else{var e=n[n.length-1];n=n.slice(0,n.length-1);return e}},push:function(e){n=n.concat([e]);return e},top:function(){return n.length>0?n[n.length-1]:null}})}function h(t,n){var r=true;var i="";if(typeof t==="string"&&t!==""){i=t+"_"}i+="commands";var s=e.Storage.get(i);s=s?e.parseJSON(s):[];var o=s.length-1;e.extend(this,{append:function(t){if(r){if(s[s.length-1]!==t){s.push(t);if(n&&s.length>n){s=s.slice(-n)}o=s.length-1;e.Storage.set(i,e.json_stringify(s))}}},data:function(){return s},reset:function(){o=s.length-1},last:function(){return s[length-1]},end:function(){return o===s.length-1},position:function(){return o},current:function(){return s[o]},next:function(){if(o<s.length-1){++o}if(o!==-1){return s[o]}},previous:function(){var e=o;if(o>0){--o}if(e!==-1){return s[o]}},clear:function(){s=[];this.purge()},enabled:function(){return r},enable:function(){r=true},purge:function(){e.Storage.remove(i)},disable:function(){r=false}})}function p(t){return e("<div>"+e.terminal.strip(t)+"</div>").text().length}function d(e){return e.length-p(e)}function v(){var e=false,n="animation",r="",i="Webkit Moz O ms Khtml".split(" "),s="",o=document.createElement("div");if(o.style.animationName){e=true}if(e===false){for(var u=0;u<i.length;u++){if(o.style[i[u]+"AnimationName"]!==t){s=i[u];n=s+"Animation";r="-"+s.toLowerCase()+"-";e=true;break}}}return e}function m(e,t){var n=e.replace(/^\s+|\s+$/g,"").split(/(\s+)/);var r=e.replace(/^[^\s]+\s*/,"");return{name:n[0],args:t(r),rest:r}}function A(t){var n=e(window).scrollTop();var r=n+e(window).height();var i=e(t).offset().top;var s=i+e(t).height();return s>=n&&i<=r}function O(){var t=e('<div class="terminal"><div class="cmd"><span>&nbsp;'+"</span></div></div>").appendTo("body");var n=t.find("span");var r={width:n.width(),height:n.outerHeight()};t.remove();return r}function M(e){var t=O().width;var n=Math.floor(e.width()/t);if(P(e)){var r=20;var i=e.innerWidth()-e.width();n-=Math.ceil((r-i/2)/(t-1))}return n}function _(e){return Math.floor(e.height()/O().height)}function D(){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 P(e){return e.get(0).scrollHeight>e.innerHeight()}e.omap=function(t,n){var r={};e.each(t,function(e,i){r[e]=n.call(t,e,i)});return r};var n=typeof window.localStorage!=="undefined";e.extend({Storage:{set:n?r:i,get:n?s:o,remove:n?u:a}});jQuery.fn.extend({everyTime:function(e,t,n,r,i){return this.each(function(){jQuery.timer.add(this,e,t,n,r,i)})},oneTime:function(e,t,n){return this.each(function(){jQuery.timer.add(this,e,t,n,1)})},stopTime:function(e,t){return this.each(function(){jQuery.timer.remove(this,e,t)})}});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(e){if(e===t||e===null){return null}var n=this.regex.exec(jQuery.trim(e.toString()));if(n[2]){var r=parseInt(n[1],10);var i=this.powers[n[2]]||1;return r*i}else{return e}},add:function(e,t,n,r,i,s){var o=0;if(jQuery.isFunction(n)){if(!i){i=r}r=n;n=t}t=jQuery.timer.timeParse(t);if(typeof t!=="number"||isNaN(t)||t<=0){return}if(i&&i.constructor!==Number){s=!!i;i=0}i=i||0;s=s||false;if(!e.$timers){e.$timers={}}if(!e.$timers[n]){e.$timers[n]={}}r.$timerID=r.$timerID||this.guid++;var u=function(){if(s&&u.inProgress){return}u.inProgress=true;if(++o>i&&i!==0||r.call(e,o)===false){jQuery.timer.remove(e,n,r)}u.inProgress=false};u.$timerID=r.$timerID;if(!e.$timers[n][r.$timerID]){e.$timers[n][r.$timerID]=window.setInterval(u,t)}if(!this.global[n]){this.global[n]=[]}this.global[n].push(e)},remove:function(e,t,n){var r=e.$timers,i;if(r){if(!t){for(var s in r){if(r.hasOwnProperty(s)){this.remove(e,s,n)}}}else if(r[t]){if(n){if(n.$timerID){window.clearInterval(r[t][n.$timerID]);delete r[t][n.$timerID]}}else{for(var o in r[t]){if(r[t].hasOwnProperty(o)){window.clearInterval(r[t][o]);delete r[t][o]}}}for(i in r[t]){if(r[t].hasOwnProperty(i)){break}}if(!i){i=null;delete r[t]}}for(i in r){if(r.hasOwnProperty(i)){break}}if(!i){e.$timers=null}}}}});if(/(msie) ([\w.]+)/.exec(navigator.userAgent.toLowerCase())){jQuery(window).one("unload",function(){var e=jQuery.timer.global;for(var t in e){if(e.hasOwnProperty(t)){var n=e[t],r=n.length;while(--r){jQuery.timer.remove(n[r],t)}}}})}(function(e){if(!String.prototype.split.toString().match(/\[native/)){return}var t=String.prototype.split,n=/()??/.exec("")[1]===e,r;r=function(r,i,s){if(Object.prototype.toString.call(i)!=="[object RegExp]"){return t.call(r,i,s)}var o=[],u=(i.ignoreCase?"i":"")+(i.multiline?"m":"")+(i.extended?"x":"")+(i.sticky?"y":""),a=0,f,l,c,h;i=new RegExp(i.source,u+"g");r+="";if(!n){f=new RegExp("^"+i.source+"$(?!\\s)",u)}s=s===e?-1>>>0:s>>>0;while(l=i.exec(r)){c=l.index+l[0].length;if(c>a){o.push(r.slice(a,l.index));if(!n&&l.length>1){l[0].replace(f,function(){for(var t=1;t<arguments.length-2;t++){if(arguments[t]===e){l[t]=e}}})}if(l.length>1&&l.index<r.length){Array.prototype.push.apply(o,l.slice(1))}h=l[0].length;a=c;if(o.length>=s){break}}if(i.lastIndex===l.index){i.lastIndex++}}if(a===r.length){if(h||!i.test("")){o.push("")}}else{o.push(r.slice(a))}return o.length>s?o.slice(0,s):o};String.prototype.split=function(e,t){return r(this,e,t)};return r})();e.json_stringify=function(n,r){var i="",s;r=r===t?1:r;var o=typeof n;switch(o){case"function":i+=n;break;case"boolean":i+=n?"true":"false";break;case"object":if(n===null){i+="null"}else if(n instanceof Array){i+="[";var u=n.length;for(s=0;s<u-1;++s){i+=e.json_stringify(n[s],r+1)}i+=e.json_stringify(n[u-1],r+1)+"]"}else{i+="{";for(var a in n){if(n.hasOwnProperty(a)){i+='"'+a+'":'+e.json_stringify(n[a],r+1)}}i+="}"}break;case"string":var f=n;var l={"\\\\":"\\\\",'"':'\\"',"/":"\\/","\\n":"\\n","\\r":"\\r","\\t":"\\t"};for(s in l){if(l.hasOwnProperty(s)){f=f.replace(new RegExp(s,"g"),l[s])}}i+='"'+f+'"';break;case"number":i+=String(n);break}i+=r>1?",":"";if(r===1){i=i.replace(/,([\]}])/g,"$1")}return i.replace(/([\[{]),/g,"$1")};e.fn.cmd=function(n){function L(e){C.toggleClass("inverted")}function A(){E="(reverse-i-search)`"+l+"': ";F()}function O(){E=d;a=false;c=null;l=""}function M(e){var t=N.data();var n,i;var s=t.length;if(e&&c>0){s-=c}if(l.length>0){for(var o=l.length;o>0;o--){i=l.substring(0,o).replace(/([.*+{}\[\]?])/g,"\\$1");n=new RegExp(i);for(var u=s;u--;){if(n.test(t[u])){c=t.length-u;w=0;r.set(t[u],true);B();if(l.length!==o){l=l.substring(0,o);A()}return}}}}l=""}function _(){var e=r.width();var t=C.innerWidth();o=Math.floor(e/t)}function P(e,t){var n="";for(var r=t;r--;){n+=e}return n}function H(e){var t=e.substring(0,o-u);var n=e.substring(o-u);return[t].concat(f(n,o))}function I(){s.focus();r.oneTime(1,function(){r.insert(s.val());s.blur().val("")})}function R(e){var i,s,o;if(typeof n.keydown=="function"){i=n.keydown(e);if(i!==t){return i}}if(S){if(e.which!==38&&!(e.which===80&&e.ctrlKey)){q=true}if(a&&(e.which===35||e.which===36||e.which===37||e.which===38||e.which===39||e.which===40||e.which===13||e.which===27)){O();F();if(e.which===27){g=""}B();R.call(this,e)}else if(e.altKey){if(e.which===68){r.set(g.slice(0,w)+g.slice(w).replace(/[^ ]+ |[^ ]+$/,""),true);return false}return true}else if(e.keyCode===13){if(e.shiftKey){r.insert("\n")}else{if(N&&g&&!m&&(typeof n.historyFilter=="function"&&n.historyFilter(g)||!n.historyFilter)){N.append(g)}var u=g;N.reset();r.set("");if(n.commands){n.commands(u)}if(typeof E==="function"){F()}}}else if(e.which===8){if(a){l=l.slice(0,-1);A()}else{if(g!==""&&w>0){g=g.slice(0,w-1)+g.slice(w,g.length);--w;B()}}}else if(e.which===67&&e.ctrlKey&&e.shiftKey){y=D()}else if(e.which===86&&e.ctrlKey&&e.shiftKey){if(y!==""){r.insert(y)}}else if(e.which===9&&!(e.ctrlKey||e.altKey)){r.insert("	")}else if(e.which===46){if(g!==""&&w<g.length){g=g.slice(0,w)+g.slice(w+1,g.length);B()}return true}else if(N&&e.which===38||e.which===80&&e.ctrlKey){if(q){j=g;r.set(N.current())}else{r.set(N.previous())}q=false}else if(N&&e.which===40||e.which===78&&e.ctrlKey){r.set(N.end()?j:N.next())}else if(e.which===37||e.which===66&&e.ctrlKey){if(e.ctrlKey&&e.which!==66){o=w-1;s=0;if(g[o]===" "){--o}for(var f=o;f>0;--f){if(g[f]===" "&&g[f+1]!==" "){s=f+1;break}else if(g[f]==="\n"&&g[f+1]!=="\n"){s=f;break}}r.position(s)}else{if(w>0){--w;B()}}}else if(e.which===82&&e.ctrlKey){if(a){M(true)}else{d=E;A();j=g;g="";B();a=true}}else if(e.which==71&&e.ctrlKey){if(a){E=d;F();g=j;B();a=false;l=""}}else if(e.which===39||e.which===70&&e.ctrlKey){if(e.ctrlKey&&e.which!==70){if(g[w]===" "){++w}var c=/\S[\n\s]{2,}|[\n\s]+\S?/;var h=g.slice(w).match(c);if(!h||h[0].match(/^\s+$/)){w=g.length}else{if(h[0][0]!==" "){w+=h.index+1}else{w+=h.index+h[0].length-1;if(h[0][h[0].length-1]!==" "){--w}}}B()}else{if(w<g.length){++w;B()}}}else if(e.which===123){return true}else if(e.which===36){r.position(0)}else if(e.which===35){r.position(g.length)}else if(e.shiftKey&&e.which==45){I();return true}else if(e.ctrlKey||e.metaKey){if(e.which===192){return true}if(e.metaKey){if(e.which===82){return true}else if(e.which===76){return true}}if(e.shiftKey){if(e.which===84){return true}}else{if(e.which===81){if(g!==""&&w!==0){var p=g.slice(0,w);var v=g.slice(w+1);var x=p.match(/([^ ]+ *$)/);w=p.length-x[0].length;b=p.slice(w);g=p.slice(0,w)+v;B()}return false}else if(e.which===72){if(g!==""&&w>0){g=g.slice(0,--w);if(w<g.length-1){g+=g.slice(w)}B()}return false}else if(e.which===65){r.position(0)}else if(e.which===69){r.position(g.length)}else if(e.which===88||e.which===67||e.which===84){return true}else if(e.which===89){if(b!==""){r.insert(b)}}else if(e.which===86){I();return true}else if(e.which===75){if(w===0){b=g;r.set("")}else if(w!==g.length){b=g.slice(w);r.set(g.slice(0,w))}}else if(e.which===85){if(g!==""&&w!==0){b=g.slice(0,w);r.set(g.slice(w,g.length));r.position(0)}}else if(e.which===17){return false}}}else{return true}return false}}var r=this;var i=r.data("cmd");if(i){return i}r.addClass("cmd");r.append('<span class="prompt" id="prompt"></span><span></span>'+'<span class="cursor">&nbsp;</span><span></span>');var s=e("<textarea/>").addClass("clipboard").appendTo(r).attr("id","clipboard");if(n.width){r.width(n.width)}var o;var u;var a=false;var l="";var c=null;var d;var m=n.mask||false;var g="";var y="";var b="";var w=0;var E;var S=n.enabled;var x=n.historySize||60;var T,N;var C=r.find(".cursor");var k;if(v()){k=function(e){if(e){C.addClass("blink")}else{C.removeClass("blink")}}}else{k=function(e){if(e&&!S){C.addClass("inverted");r.everyTime(500,"blink",L)}else if(S){r.stopTime("blink",L);C.removeClass("inverted")}}}var B=function(t){function i(t,i){var s=t.length;if(i===s){n.html(e.terminal.encode(t,true));C.html("&nbsp;");r.html("")}else if(i===0){n.html("");C.html(e.terminal.encode(t.slice(0,1),true));r.html(e.terminal.encode(t.slice(1),true))}else{var o=e.terminal.encode(t.slice(0,i),true);n.html(o);var u=t.slice(i,i+1);C.html(u===" "?"&nbsp;":e.terminal.encode(u,true));if(i===t.length-1){r.html("")}else{r.html(e.terminal.encode(t.slice(i+1),true))}}}function s(t){return"<div>"+e.terminal.encode(t,true)+"</div>"}function a(t){var n=r;e.each(t,function(t,r){n=e(s(r)).insertAfter(n).addClass("clear")})}function l(t){e.each(t,function(e,t){n.before(s(t))})}var n=C.prev();var r=C.next();var c=0;return function(){var c=m?g.replace(/./g,"*"):g;var h,p;t.find("div").remove();n.html("");if(c.length>o-u-1||c.match(/\n/)){var d;var v=c.match(/\t/g);var y=v?v.length*3:0;if(v){c=c.replace(/\t/g,"\0\0\0\0")}if(c.match(/\n/)){var b=c.split("\n");p=o-u-1;for(h=0;h<b.length-1;++h){b[h]+=" "}if(b[0].length>p){d=[b[0].substring(0,p)];d=d.concat(f(b[0].substring(p),o))}else{d=[b[0]]}for(h=1;h<b.length;++h){if(b[h].length>o){d=d.concat(f(b[h],o))}else{d.push(b[h])}}}else{d=H(c)}if(v){d=e.map(d,function(e){return e.replace(/\x00\x00\x00\x00/g,"	")})}p=d[0].length;if(p===0&&d.length===1){}else if(w<p){i(d[0],w);a(d.slice(1))}else if(w===p){n.before(s(d[0]));i(d[1],0);a(d.slice(2))}else{var E=d.length;var S=0;if(w<p){i(d[0],w);a(d.slice(1))}else if(w===p){n.before(s(d[0]));i(d[1],0);a(d.slice(2))}else{var x=d.slice(-1)[0];var T=c.length-w;var N=x.length;var k=0;if(T<=N){l(d.slice(0,-1));k=N===T?0:N-T;i(x,k+y)}else{if(E===3){n.before("<div>"+e.terminal.encode(d[0],true)+"</div>");i(d[1],w-p-1);r.after('<div class="clear">'+e.terminal.encode(d[2],true)+"</div>")}else{var L;var A;k=w;for(h=0;h<d.length;++h){var O=d[h].length;if(k>O){k-=O}else{break}}A=d[h];L=h;if(k===A.length){k=0;A=d[++L]}i(A,k);l(d.slice(0,L));a(d.slice(L+1))}}}}}else{if(c===""){n.html("");C.html("&nbsp;");r.html("")}else{i(c,w)}}}}(r);var j;var F=function(){function n(n){u=p(n);t.html(e.terminal.format(e.terminal.encode(n)))}var t=r.find(".prompt");return function(){switch(typeof E){case"string":n(E);break;case"function":E(n);break}}}();var q=true;var U=[];e.extend(r,{name:function(e){if(e!==t){T=e;var n=N&&N.enabled()||!N;N=new h(e,x);if(!n){N.disable()}return r}else{return T}},purge:function(){N.clear();return r},history:function(){return N},set:function(e,i){if(e!==t){g=e;if(!i){w=g.length}B();if(typeof n.onCommandChange==="function"){n.onCommandChange(g)}}return r},insert:function(e,t){if(w===g.length){g+=e}else if(w===0){g=e+g}else{g=g.slice(0,w)+e+g.slice(w)}if(!t){w+=e.length}B();if(typeof n.onCommandChange==="function"){n.onCommandChange(g)}return r},get:function(){return g},commands:function(e){if(e){n.commands=e;return r}else{return e}},destroy:function(){e(document.documentElement||window).unbind(".cmd");r.stopTime("blink",L);r.find(".cursor").next().remove().end().prev().remove().end().remove();r.find(".prompt, .clipboard").remove();r.removeClass("cmd").removeData("cmd");return r},prompt:function(e){if(e===t){return E}else{if(typeof e==="string"||typeof e==="function"){E=e}else{throw"prompt must be a function or string"}F();B();return r}},kill_text:function(){return b},position:function(e){if(typeof e==="number"){w=e<0?0:e>g.length?g.length:e;B();return r}else{return w}},visible:function(){var e=r.visible;return function(){e.apply(r,[]);B();F()}}(),show:function(){var e=r.show;return function(){e.apply(r,[]);B();F()}}(),resize:function(e){if(e){o=e}else{_()}B();return r},enable:function(){S=true;k(true);return r},isenabled:function(){return S},disable:function(){S=false;k(false);return r},mask:function(e){if(typeof e==="boolean"){m=e;B();return r}else{return m}}});r.name(n.name||n.prompt||"");E=n.prompt||"> ";F();if(n.enabled===t||n.enabled===true){r.enable()}var z;e(document.documentElement||window).bind("keypress.cmd",function(i){var s;if(i.ctrlKey&&i.which===99){return true}if(!a&&typeof n.keypress==="function"){s=n.keypress(i)}if(s===t||s){if(S){if(e.inArray(i.which,[38,13,0,8])>-1&&i.keyCode!==123&&!(i.which===38&&i.shiftKey)){return false}else if(!i.ctrlKey&&!(i.altKey&&i.which===100)||i.altKey){if(a){l+=String.fromCharCode(i.which);M();A()}else{r.insert(String.fromCharCode(i.which))}return false}}}else{return s}}).bind("keydown.cmd",R);r.data("cmd",r);return r};var g=["black","silver","gray","white","maroon","red","purple","fuchsia","green","lime","olive","yellow","navy","blue","teal","aqua","aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"];var y=/(\[\[[gbiuso]*;[^;]*;[^\]]*\](?:[^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?)/i;var b=/\[\[([gbiuso]*);([^;]*);([^;\]]*);?([^;\]]*);?([^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?/gi;var w=/\[\[([gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]?/gi;var E=/^\[\[([gbiuso]*;[^;\]]*;[^;\]]*(?:;|[^\]()]*);?[^\]]*)\]([^\]]*\\\][^\]]*|[^\]]*|[^\[]*\[[^\]]*)\]$/gi;var S=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i;var x=/\bhttps?:\/\/(?:(?!&[^;]+;)[^\s"'<>)])+\b/g;var T=/((([^<>('")[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,})))/g;var N=/('[^']*'|"(\\"|[^"])*"|\/(\\\/|[^\/])+\/[gimy]*|(\\ |[^ ])+|[\w-]+)/g;var C=/(\[\[[gbiuso]*;[^;]*;[^\]]*\])/i;var k=/\[\[[gbiuso]*;[^;]*;[^\]]*\]?$/i;e.terminal={valid_color:function(t){return t.match(S)||e.inArray(t.toLowerCase(),g)!==-1},escape_regex:function(e){var t=/([\^\$\[\]\(\)\+\*\.\|])/g;return e.replace(t,"\\$1")},have_formatting:function(e){return e.match(w)},is_formatting:function(e){return e.match(E)},format_split:function(e){return e.split(y)},split_equal:function(e,t){var n=false;var r=false;var i=0;var s="";var o=[];var u=e.replace(w,function(e,t,n){var r=t.match(/;/g).length;if(r==2){r=";;"}else if(r==3){r=";"}else{r=""}return"[["+t+r+n.replace(/\\\]/g,"&#93;").replace(/\n/g,"\\n")+"]"+n+"]"}).split(/\n/g);for(var a=0,f=u.length;a<f;++a){if(u[a]===""){o.push("");continue}var l=u[a];var c=0;var h=0;for(var p=0,d=l.length;p<d;++p){if(l[p]==="["&&l[p+1]==="["){n=true}else if(n&&l[p]==="]"){if(r){n=false;r=false}else{r=true}}else if(n&&r||!n){if(l[p]==="&"){var v=l.substring(p).match(/^(&[^;]+;)/);if(!v){throw"Unclosed html entity in line "+(a+1)+" at char "+(p+1)}p+=v[1].length-2;if(p===d-1){o.push(m+v[1])}continue}else if(l[p]==="]"&&l[p-1]==="\\"){--h}else{++h}}if(h===t||p===d-1){var m=l.substring(c,p+1);if(s){m=s+m;if(m.match("]")){s=""}}c=p+1;h=0;var g=m.match(w);if(g){var y=g[g.length-1];if(y[y.length-1]!=="]"){s=y.match(C)[1];m+="]"}else if(m.match(k)){var b=m.length;var E=b-y[y.length-1].length;m=m.replace(k,"");s=y.match(C)[1]}}o.push(m)}}}return o},encode:function(e,t){if(t){e=e.replace(/&(?![^=]+=)/g,"&")}else{e=e.replace(/&(?!#[0-9]+;|[a-zA-Z]+;|[^= "]+=[^=])/g,"&")}return e.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/ /g,"&nbsp;").replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;")},format:function(t,n){var r=e.extend({},{linksNoReferrer:false},n||{});if(typeof t==="string"){var i=e.terminal.format_split(t);if(i&&i.length>1){t=e.map(i,function(t){if(t===""){return t}else if(t.substring(0,1)==="["){return t.replace(b,function(t,n,r,i,s,o,u){if(u===""){return""}u=u.replace(/\\]/g,"]");var a="";if(n.indexOf("b")!==-1){a+="font-weight:bold;"}var f=[];if(n.indexOf("u")!==-1){f.push("underline")}if(n.indexOf("s")!==-1){f.push("line-through")}if(n.indexOf("o")!==-1){f.push("overline")}if(f.length){a+="text-decoration:"+f.join(" ")+";"}if(n.indexOf("i")!==-1){a+="font-style:italic;"}if(e.terminal.valid_color(r)){a+="color:"+r+";";if(n.indexOf("g")!==-1){a+="text-shadow:0 0 5px "+r+";"}}if(e.terminal.valid_color(i)){a+="background-color:"+i}var l;if(o===""){l=u}else{l=o.replace(/&#93;/g,"]")}var c='<span style="'+a+'"'+(s!==""?' class="'+s+'"':"")+' data-text="'+l.replace('"',"&quote;")+'">'+u+"</span>";return c})}else{return"<span>"+t+"</span>"}}).join("")}return e.map(t.split(/(<\/?span[^>]*>)/g),function(e){if(!e.match(/span/)){return e.replace(x,function(e){var t=e.match(/\.$/);e=e.replace(/\.$/,"");return'<a target="_blank" '+(r.linksNoReferer?' rel="noreferrer" ':"")+'href="'+e+'">'+e+"</a>"+(t?".":"")}).replace(T,'<a href="mailto:$1">$1</a>')}else{return e}}).join("").replace(/<span><br\/?><\/span>/g,"<br/>")}else{return""}},escape_brackets:function(e){return e.replace(/\[/g,"&#91;").replace(/\]/g,"&#93;")},strip:function(e){return e.replace(b,"$6")},active:function(){return U.front()},overtyping:function(e){return e.replace(/((?:_\x08.|.\x08_)+)/g,function(e,t){return"[[u;;]"+e.replace(/_x08|\x08_|_\u0008|\u0008_/g,"")+"]"}).replace(/((?:.\x08.)+)/g,function(e,t){return"[[b;#fff;]"+e.replace(/(.)(?:\x08|\u0008)(.)/g,function(e,t,n){return n})+"]"})},ansi_colors:{normal:{black:"#000",red:"#A00",green:"#008400",yellow:"#A50",blue:"#00A",magenta:"#A0A",cyan:"#0AA",white:"#AAA"},faited:{black:"#000",red:"#640000",green:"#006100",yellow:"#737300",blue:"#000087",magenta:"#650065",cyan:"#008787",white:"#818181"},bold:{black:"#000",red:"#F55",green:"#44D544",yellow:"#FF5",blue:"#55F",magenta:"#F5F",cyan:"#5FF",white:"#FFF"},palette:["#000000","#AA0000","#00AA00","#AA5500","#0000AA","#AA00AA","#00AAAA","#AAAAAA","#555555","#FF5555","#55FF55","#FFFF55","#5555FF","#FF55FF","#55FFFF","#FFFFFF","#000000","#00005F","#000087","#0000AF","#0000D7","#0000FF","#005F00","#005F5F","#005F87","#005FAF","#005FD7","#005FFF","#008700","#00875F","#008787","#0087AF","#0087D7","#00AF00","#00AF5F","#00AF87","#00AFAF","#00AFD7","#00AFFF","#00D700","#00D75F","#00D787","#00D7AF","#00D7D7","#00D7FF","#00FF00","#00FF5F","#00FF87","#00FFAF","#00FFD7","#00FFFF","#5F0000","#5F005F","#5F0087","#5F00AF","#5F00D7","#5F00FF","#5F5F00","#5F5F5F","#5F5F87","#5F5FAF","#5F5FD7","#5F5FFF","#5F8700","#5F875F","#5F8787","#5F87AF","#5F87D7","#5F87FF","#5FAF00","#5FAF5F","#5FAF87","#5FAFAF","#5FAFD7","#5FAFFF","#5FD700","#5FD75F","#5FD787","#5FD7AF","#5FD7D7","#5FD7FF","#5FFF00","#5FFF5F","#5FFF87","#5FFFAF","#5FFFD7","#5FFFFF","#870000","#87005F","#870087","#8700AF","#8700D7","#8700FF","#875F00","#875F5F","#875F87","#875FAF","#875FD7","#875FFF","#878700","#87875F","#878787","#8787AF","#8787D7","#8787FF","#87AF00","#87AF5F","#87AF87","#87AFAF","#87AFD7","#87AFFF","#87D700","#87D75F","#87D787","#87D7AF","#87D7D7","#87D7FF","#87FF00","#87FF5F","#87FF87","#87FFAF","#87FFD7","#87FFFF","#AF0000","#AF005F","#AF0087","#AF00AF","#AF00D7","#AF00FF","#AF5F00","#AF5F5F","#AF5F87","#AF5FAF","#AF5FD7","#AF5FFF","#AF8700","#AF875F","#AF8787","#AF87AF","#AF87D7","#AF87FF","#AFAF00","#AFAF5F","#AFAF87","#AFAFAF","#AFAFD7","#AFAFFF","#AFD700","#AFD75F","#AFD787","#AFD7AF","#AFD7D7","#AFD7FF","#AFFF00","#AFFF5F","#AFFF87","#AFFFAF","#AFFFD7","#AFFFFF","#D70000","#D7005F","#D70087","#D700AF","#D700D7","#D700FF","#D75F00","#D75F5F","#D75F87","#D75FAF","#D75FD7","#D75FFF","#D78700","#D7875F","#D78787","#D787AF","#D787D7","#D787FF","#D7AF00","#D7AF5F","#D7AF87","#D7AFAF","#D7AFD7","#D7AFFF","#D7D700","#D7D75F","#D7D787","#D7D7AF","#D7D7D7","#D7D7FF","#D7FF00","#D7FF5F","#D7FF87","#D7FFAF","#D7FFD7","#D7FFFF","#FF0000","#FF005F","#FF0087","#FF00AF","#FF00D7","#FF00FF","#FF5F00","#FF5F5F","#FF5F87","#FF5FAF","#FF5FD7","#FF5FFF","#FF8700","#FF875F","#FF8787","#FF87AF","#FF87D7","#FF87FF","#FFAF00","#FFAF5F","#FFAF87","#FFAFAF","#FFAFD7","#FFAFFF","#FFD700","#FFD75F","#FFD787","#FFD7AF","#FFD7D7","#FFD7FF","#FFFF00","#FFFF5F","#FFFF87","#FFFFAF","#FFFFD7","#FFFFFF","#080808","#121212","#1C1C1C","#262626","#303030","#3A3A3A","#444444","#4E4E4E","#585858","#626262","#6C6C6C","#767676","#808080","#8A8A8A","#949494","#9E9E9E","#A8A8A8","#B2B2B2","#BCBCBC","#C6C6C6","#D0D0D0","#DADADA","#E4E4E4","#EEEEEE"]},from_ansi:function(){function r(r){var i=r.split(";");var s;var o=false;var u=false;var a=false;var f=[];var l="";var c="";var h=false;var p=false;var d=false;var v=e.terminal.ansi_colors.palette;for(var m in i){s=parseInt(i[m],10);switch(s){case 1:f.push("b");a=true;o=false;break;case 4:f.push("u");break;case 3:f.push("i");break;case 5:d=true;break;case 38:h=true;break;case 48:p=true;break;case 2:o=true;a=false;break;case 7:u=true;break;default:if(h&&d&&v[s-1]){l=v[s-1]}else if(t[s]){l=t[s]}if(p&&d&&v[s-1]){c=v[s-1]}else if(n[s]){c=n[s]}}if(s!==5){d=false}}if(u){if(l&&c){var g=c;c=l;l=g}else{l="black";c="white"}}var y,b;if(a){y=b=e.terminal.ansi_colors.bold}else if(o){y=b=e.terminal.ansi_colors.faited}else{y=b=e.terminal.ansi_colors.normal}return[f.join(""),h?l:y[l],p?c:b[c]]}var t={30:"black",31:"red",32:"green",33:"yellow",34:"blue",35:"magenta",36:"cyan",37:"white",39:"white"};var n={40:"black",41:"red",42:"green",43:"yellow",44:"blue",45:"magenta",46:"cyan",47:"white",49:"black"};return function(e){var t=e.split(/(\x1B\[[0-9;]*[A-Za-z])/g);if(t.length==1){return e}var n=[];if(t.length>3&&t.slice(0,3).join("")=="[0m"){t=t.slice(3)}var i=false,s,o,u,a,f;for(var l=0;l<t.length;++l){f=t[l].match(/^\x1B\[([0-9;]*)([A-Za-z])$/);if(f){switch(f[2]){case"m":if(f[1]===""){continue}if(f[1]!=="0"){a=r(f[1])}if(i){n.push("]");if(f[1]=="0"){i=false;o=u=""}else{a[1]=a[1]||o;a[2]=a[2]||u;n.push("[["+a.join(";")+"]");if(a[1]){o=a[1]}if(a[2]){u=a[2]}}}else{if(f[1]!="0"){i=true;n.push("[["+a.join(";")+"]");if(a[1]){o=a[1]}if(a[2]){u=a[2]}}}break}}else{n.push(t[l])}}if(i){n.push("]")}return n.join("")}}(),parseArguments:function(t){return e.map(t.match(N)||[],function(e){if(e[0]==="'"&&e[e.length-1]==="'"){return e.replace(/^'|'$/g,"")}else if(e[0]==='"'&&e[e.length-1]==='"'){e=e.replace(/^"|"$/g,"").replace(/\\([" ])/g,"$1");return e.replace(/\\\\|\\t|\\n/g,function(e){if(e[1]==="t"){return"	"}else if(e[1]==="n"){return"\n"}else{return"\\"}}).replace(/\\x([0-9a-f]+)/gi,function(e,t){return String.fromCharCode(parseInt(t,16))}).replace(/\\0([0-7]+)/g,function(e,t){return String.fromCharCode(parseInt(t,8))})}else if(e.match(/^\/(\\\/|[^\/])+\/[gimy]*$/)){var t=e.match(/^\/([^\/]+)\/([^\/]*)$/);return new RegExp(t[1],t[2])}else if(e.match(/^-?[0-9]+$/)){return parseInt(e,10)}else if(e.match(/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/)){return parseFloat(e)}else{return e.replace(/\\ /g," ")}})},splitArguments:function(t){return e.map(t.match(N)||[],function(e){if(e[0]==="'"&&e[e.length-1]==="'"){return e.replace(/^'|'$/g,"")}else if(e[0]==='"'&&e[e.length-1]==='"'){return e.replace(/^"|"$/g,"").replace(/\\([" ])/g,"$1")}else if(e[0]==="/"&&e[e.length-1]=="/"){return e}else{return e.replace(/\\ /g," ")}})},parseCommand:function(t){return m(t,e.terminal.parseArguments)},splitCommand:function(t){return m(t,e.terminal.splitArguments)},ajax:function(e){return e}};e.fn.visible=function(){return this.css("visibility","visible")};e.fn.hidden=function(){return this.css("visibility","hidden")};var L={};e.jrpc=function(t,n,r,i,s){L[t]=L[t]||0;var o=e.json_stringify({jsonrpc:"2.0",method:n,params:r,id:++L[t]});return e.ajax({url:t,data:o,success:function(t,n,r){var o=r.getResponseHeader("Content-Type");if(!o.match(/application\/json/)){if(console&&console.warn){console.warn("Response Content-Type is not application/json")}else{throw new Error("WARN: Response Content-Type is not application/json")}}var u;try{u=e.parseJSON(t)}catch(a){if(s){s(r,"Invalid JSON",a)}else{throw new Error("Invalid JSON")}return}i(u,n,r)},error:s,contentType:"application/json",dataType:"text",async:true,cache:false,type:"POST"})};var H="0.1";var B=!H.match(/^\{\{/);var j="Copyright (c) 2014 Andoitz <http://www.andoitz.com>";var F=B?" version "+H:" ";var I=new RegExp(" {"+F.length+"}$");var q=[["PHPQuery","(c) 2014 andoitz"],["PHPQuery Emulator"+(B?" v. "+H:""),j.replace(/ *<.*>/,"")],["PHPQuery Emulator"+(B?F:""),j.replace(/^Copyright /,"")],[F,j],[F,j]];e.terminal.defaults={prompt:"> ",history:true,exit:true,clear:true,enabled:true,historySize:60,checkArity:true,exceptionHandler:null,cancelableAjax:true,processArguments:true,linksNoReferrer:false,outputLimit:-1,onAjaxError:null,onRPCError:null,completion:false,historyFilter:null,onInit:e.noop,onClear:e.noop,onBlur:e.noop,onFocus:e.noop,onTerminalChange:e.noop,onExit:e.noop,keypress:e.noop,keydown:e.noop,strings:{ajaxAbortError:"Error while aborting ajax call!",wrongArity:"Wrong number of arguments. Function '%s' expect %s got %s!",commandNotFound:"Command '%s' Not Found!",oneRPCWithIgnore:"You can use only one rpc with ignoreSystemDescribe",oneInterpreterFunction:"You can't use more then one function (rpc with "+"ignoreSystemDescribe is count as one)",serverResponse:"Server reponse is",wrongGreetings:"Wrong value of greetings parameter",canExitError:"You can't exit from main interpeter",invalidCompletion:"Invalid completion"}};var R=[];var U=new l;e.fn.terminal=function(n,r){function i(t){if(typeof rt.processArguments==="function"){return m(t,rt.processArguments)}else if(rt.processArguments){return e.terminal.parseCommand(t)}else{return e.terminal.splitCommand(t)}}function s(t){if(typeof t==="string"){j.echo(t)}else if(t instanceof Array){j.echo(e.map(t,function(t){return e.json_stringify(t)}).join(" "))}else if(typeof t==="object"){j.echo(e.json_stringify(t))}else{j.echo(t)}}function o(e){if(typeof rt.onRPCError==="function"){rt.onRPCError.call(j,e)}else{j.error("&#91;RPC&#93; "+e.message)}}function u(t){var n=function(n,r){j.pause();e.jrpc(t,n,r,function(e){if(!e.error){if(typeof rt.processRPCResponse==="function"){rt.processRPCResponse.call(j,e.result)}else{s(e.result)}}else{o(e.error)}j.resume()},f)};return function(e,t){if(e===""){return}e=i(e);n(e.name,e.args)}}function a(n,r,s){return function(o,u){if(o===""){return}var f=i(o);var l=n[f.name];var c=e.type(l);if(c==="function"){if(r&&l.length!==f.args.length){j.error("&#91;Arity&#93; "+sprintf(it.wrongArity,f.name,l.length,f.args.length))}else{return l.apply(j,f.args)}}else if(c==="object"||c==="string"){var h=[];if(c==="object"){h=Object.keys(l);l=a(l,r)}u.push(l,{prompt:f.name+"> ",name:f.name,completion:c==="object"?function(e,t,n){n(h)}:t})}else{if(e.type(s)==="function"){s(o,j)}else if(e.type(rt.onCommandNotFound)==="function"){rt.onCommandNotFound(o,j)}else{u.error(sprintf(it.commandNotFound,f.name))}}}}function f(e,t,n){j.resume();if(typeof rt.onAjaxError=="function"){rt.onAjaxError.call(j,e,t,n)}else if(t!=="abort"){j.error("&#91;AJAX&#93; "+t+" - "+it.serverResponse+": \n"+e.responseText)}}function l(t,n){e.jrpc(t,"system.describe",[],function(r){var i=[];if(r.procs){var u={};e.each(r.procs,function(n,r){u[r.name]=function(){var n=Array.prototype.slice.call(arguments);if(rt.checkArity&&r.params&&r.params.length!==n.length){j.error("&#91;Arity&#93; "+sprintf(it.wrongArity,r.name,r.params.length,n.length))}else{j.pause();e.jrpc(t,r.name,n,function(e){if(e.error){o(e.error)}else{s(e.result)}j.resume()},f)}}});n(u)}else{n(null)}},function(){n(null)})}function h(t,n){n=n||e.noop;var r=e.type(t);var i={};var s;var o=0;var f;if(r==="array"){var c={};(function h(t,n){if(t.length){var r=t[0];var i=t.slice(1);var s=e.type(r);if(s==="string"){o++;j.pause();if(rt.ignoreSystemDescribe){if(o===1){f=u(r)}else{j.error(it.oneRPCWithIgnore)}h(i,n)}else{l(r,function(t){if(t){e.extend(c,t)}j.resume();h(i,n)})}}else if(s==="function"){if(f){j.error(it.oneInterpreterFunction)}else{f=r}}else if(s==="object"){e.extend(c,r);h(i,n)}}else{n()}})(t,function(){s=Object.keys(c);i.interpreter=a(c,false,f);i.completion=function(e,t,n){n(s)};n(i)})}else if(r==="string"){if(rt.ignoreSystemDescribe){n({interpreter:u(t),completion:rt.completion})}else{j.pause();l(t,function(e){if(e){i.interpreter=a(e,false);i.completion=function(e,t,n){n(s)}}else{i.interpreter=u(t);i.completion=rt.completion}j.resume();n(i)})}}else if(r==="object"){s=Object.keys(t);i.interpreter=a(t,rt.checkArity);i.completion=function(e,t,n){n(s)};n(i)}else{if(r==="undefined"){t=e.noop}else if(r!=="function"){throw r+" is invalid interpreter value"}n({interpreter:t,completion:rt.completion})}}function p(e){if(typeof e==="string"){return e}else if(typeof e.fileName==="string"){return e.fileName+": "+e.message}else{return e.message}}function d(e,t){if(typeof rt.exceptionHandler=="function"){rt.exceptionHandler.call(j,e)}else{j.exception(e,t)}}function v(){var e=F.prop?F.prop("scrollHeight"):F.attr("scrollHeight");F.scrollTop(e)}function g(e,t){try{if(typeof t==="function"){t(function(){})}else if(typeof t!=="string"){var n=e+" must be string or function";throw n}}catch(r){d(r,e.toUpperCase());return false}return true}function w(t,n){try{var r=e.extend({raw:false,finalize:e.noop},n||{});t=e.type(t)==="function"?t():t;t=e.type(t)==="string"?t:String(t);var i,s;if(!r.raw){t=e.terminal.encode(t)}t=e.terminal.overtyping(t);t=e.terminal.from_ansi(t);y.push(b);if(!r.raw&&(t.length>K||t.match(/\n/))){var o=e.terminal.split_equal(t,K);for(i=0,s=o.length;i<s;++i){if(o[i]===""||o[i]==="\r"){y.push("&nbsp;")}else{if(r.raw){y.push(o[i])}else{y.push(e.terminal.format(o[i],{linksNoReferer:rt.linksNoReferer}))}}}}else{if(!r.raw){t=e.terminal.format(t,{linksNoReferer:rt.linksNoReferer})}y.push(t)}y.push(r.finalize)}catch(u){y=[];alert("[Internal Exception(draw_line)]:"+p(u)+"\n"+u.stack)}}function E(){ft.resize(K);var t=V.empty().detach();var n;if(rt.outputLimit>=0){var r=rt.outputLimit===0?j.rows():rt.outputLimit;n=X.slice(X.length-r-1)}else{n=X}e.each(n,function(e,t){w.apply(null,t)});ft.before(t);j.flush()}function S(){if(rt.greetings===t){j.echo(j.signature)}else if(rt.greetings){var e=typeof rt.greetings;if(e==="string"){j.echo(rt.greetings)}else if(e==="function"){rt.greetings.call(j,j.echo)}else{j.error(it.wrongGreetings)}}}function x(t){t=e.terminal.escape_brackets(e.terminal.encode(t,true));var n=ft.prompt();if(ft.mask()){t=t.replace(/./g,"*")}if(typeof n==="function"){n(function(e){j.echo(e+t)})}else{j.echo(n+t)}}function T(n,r,i){try{if(!O()){I=e.terminal.splitCommand(n).name;if(i&&typeof rt.historyFilter=="function"&&rt.historyFilter(n)||!rt.historyFilter){ft.history().append(n)}}var s=at.top();if(n==="exit"&&rt.exit){var o=at.size();if(o==1||o>1){if(!r){x(n)}j.pop()}}else{if(!r){x(n)}var u=X.length-1;if(n==="clear"&&rt.clear){j.clear()}else{var a=s.interpreter(n,j);if(a!==t){if(u===X.length-1){X.pop();if(a!==false){j.echo(a)}}else{if(a===false){X=X.slice(0,u).concat(X.slice(u+1))}else{X=X.slice(0,u).concat([a]).concat(X.slice(u+1))}}j.resize()}}}}catch(f){d(f,"USER");j.resume();throw f}}function N(t){var n=j.prefix_name()+"_interpreters";var r=e.Storage.get(n);if(r){r=e.parseJSON(r)}else{r=[]}if(e.inArray(t,r)==-1){r.push(t);e.Storage.set(n,e.json_stringify(r))}}function C(e){var t=at.top();var n=j.prefix_name(true);if(!O()){N(n)}ft.name(n);if(typeof t.prompt=="function"){ft.prompt(function(e){t.prompt(e,j)})}else{ft.prompt(t.prompt)}ft.set("");if(!e&&typeof t.onStart==="function"){t.onStart(j)}}function k(){C();S();var t=false;if(typeof rt.onInit==="function"){Z=function(){t=true};try{rt.onInit(j)}catch(n){d(n,"OnInit");throw n}finally{Z=e.noop;if(!t){j.resume()}}}}function L(t,n,r){var i=ft.get().substring(0,ft.position());if(i!==t){return}var s=new RegExp("^"+e.terminal.escape_regex(n));var o=[];for(var u=r.length;u--;){if(s.test(r[u])){o.push(r[u])}}if(o.length===1){j.insert(o[0].replace(s,"")+" ")}else if(o.length>1){if(W>=2){x(t);j.echo(o.join("	"));W=0}else{var a=false;var f;var l;e:for(l=n.length;l<o[0].length;++l){for(u=1;u<o.length;++u){if(o[0].charAt(l)!==o[u].charAt(l)){break e}}a=true}if(a){j.insert(o[0].slice(0,l).replace(s,""))}}}}function O(){return ft.mask()}function B(n){var r,i,s=at.top();if(e.type(s.keydown)==="function"){r=s.keydown(n,j);if(r!==t){return r}}var o;if(rt.completion&&e.type(rt.completion)!="boolean"&&!s.completion){o=rt.completion}else{o=s.completion}j.oneTime(10,function(){ut()});if(e.type(rt.keydown)==="function"){r=rt.keydown(n,j);if(r!==t){return r}}if(!j.paused()){if(n.which!==9){W=0}if(n.which===68&&n.ctrlKey){if(ft.get()===""){j.resume();j.echo("")}else{j.set_command("")}return false}else if(n.which===76&&n.ctrlKey){j.clear()}else if(o&&n.which===9){++W;var u=ft.get().substring(0,ft.position());var a=u.split(" ");var f;if(a.length==1){f=a[0]}else{f=a[a.length-1];for(i=a.length-1;i>0;i--){if(a[i-1][a[i-1].length-1]=="\\"){f=a[i-1]+" "+f}else{break}}}switch(e.type(o)){case"function":o(j,f,function(e){L(u,f,e)});break;case"array":L(u,f,o);break;default:throw new Error(e.terminal.defaults.strings.invalidCompletion)}return false}else if(n.which===86&&n.ctrlKey){j.oneTime(1,function(){v()});return}else if(n.which===9&&n.ctrlKey){if(U.length()>1){j.focus(false);return false}}else if(n.which===34){j.scroll(j.height())}else if(n.which===33){j.scroll(-j.height())}else{j.attr({scrollTop:j.attr("scrollHeight")})}}else if(n.which===68&&n.ctrlKey){if(R.length){for(i=R.length;i--;){var l=R[i];if(4!==l.readyState){try{l.abort()}catch(c){j.error(a.ajaxAbortError)}}}R=[];j.resume()}return false}}var y=[];var b=1;var j=this;if(this.length>1){return this.each(function(){e.fn.terminal.call(e(this),n,e.extend({name:j.selector},r))})}else{if(j.data("terminal")){return j.data("terminal")}if(j.length===0){throw'Sorry, but terminal said that "'+j.selector+'" is not valid selector!'}var F;var I;var z=false;var W=0;var X=[];var V;var J=U.length();var K;var Q;var G=[];var Y;var Z=e.noop;var et,tt;var nt=[];var rt=e.extend({},e.terminal.defaults,{name:j.selector},r||{});var it=e.terminal.defaults.strings;var st=rt.enabled;var ot=false;e.extend(j,e.omap({clear:function(){V.html("");ft.set("");X=[];try{rt.onClear(j)}catch(e){d(e,"onClear");throw e}j.attr({scrollTop:0});return j},exec:function(e,t){if(ot){nt.push([e,t])}else{T(e,t,true)}return j},settings:rt,commands:function(){return at.top().interpreter},greetings:function(){S();return j},paused:function(){return ot},pause:function(){Z();if(!ot&&ft){ot=true;j.disable();ft.hidden()}return j},resume:function(){if(ot&&ft){ot=false;j.enable();ft.visible();var e=nt;nt=[];while(e.length){j.exec.apply(j,e.shift())}v()}return j},cols:function(){return K},rows:function(){return Q},history:function(){return ft.history()},next:function(){if(U.length()===1){return j}else{var t=j.offset().top;var n=j.height();var r=j.scrollTop();if(!A(j)){j.enable();e("html,body").animate({scrollTop:t-50},500);return j}else{U.front().disable();var i=U.rotate().enable();var s=i.offset().top-50;e("html,body").animate({scrollTop:s},500);try{rt.onTerminalChange(i)}catch(o){d(o,"onTerminalChange");throw o}return i}}},focus:function(e,t){j.oneTime(1,function(){if(U.length()===1){if(e===false){try{if(!t&&rt.onBlur(j)!==false){j.disable()}}catch(n){d(n,"onBlur");throw n}}else{try{if(!t&&rt.onFocus(j)!==false){j.enable()}}catch(n){d(n,"onFocus");throw n}}}else{if(e===false){j.next()}else{var r=U.front();if(r!=j){r.disable();if(!t){try{rt.onTerminalChange(j)}catch(n){d(n,"onTerminalChange");throw n}}}U.set(j);j.enable()}}});return j},enable:function(){if(K===t){j.resize()}if(ft){ft.enable();st=true}return j},disable:function(){if(ft){st=false;ft.disable()}return j},enabled:function(){return st},signature:function(){var e=j.cols();var t=e<15?null:e<35?0:e<55?1:e<64?2:e<75?3:4;if(t!==null){return q[t].join("\n")+"\n"}else{return""}},version:function(){return H},cmd:function(){return ft},get_command:function(){return ft.get()},set_command:function(e){ft.set(e);return j},insert:function(e){if(typeof e==="string"){ft.insert(e);return j}else{throw"insert function argument is not a string"}},set_prompt:function(e){if(g("prompt",e)){if(typeof e=="function"){ft.prompt(function(t){e(t,j)})}else{ft.prompt(e)}at.top().prompt=e}return j},get_prompt:function(){return at.top().prompt},set_mask:function(e){ft.mask(e);return j},get_output:function(t){if(t){return X}else{return e.map(X,function(e){return typeof e[0]=="function"?e[0]():e[0]}).join("\n")}},resize:function(e,t){if(e&&t){j.width(e);j.height(t)}e=j.width();t=j.height();var n=M(j);var r=_(j);if(n!==K||r!==Q){K=n;Q=r;E();if(typeof rt.onResize==="function"&&(tt!==t||et!==e)){rt.onResize(j)}if(tt!==t||et!==e){tt=t;et=e}}return j},flush:function(){try{var t;e.each(y,function(n,r){if(r===b){t=e("<div></div>")}else if(typeof r==="function"){t.appendTo(V);try{r(t)}catch(i){d(i,"USER:echo(finalize)")}}else{e("<div/>").html(r).appendTo(t).width("100%")}});if(rt.outputLimit>=0){var n=rt.outputLimit===0?j.rows():rt.outputLimit;var r=V.find("div div");if(r.length>n){var i=r.slice(0,X.length-n+1);var s=i.parent();i.remove();s.each(function(){var t=e(this);if(t.is(":empty")){t.remove()}})}}v();y=[]}catch(o){alert("[Flush] "+p(o)+"\n"+o.stack)}return j},echo:function(t,n){try{t=t||"";var r=e.extend({flush:true,raw:false,finalize:e.noop},n||{});y=[];w(t,r);X.push([t,r]);if(r.flush){j.flush()}ut()}catch(i){alert("[Terminal.echo] "+p(i)+"\n"+i.stack)}return j},error:function(t,n){return j.echo("[[;#f00;]"+e.terminal.escape_brackets(t).replace(/\\$/,"&#92;")+"]",n)},exception:function(t,n){var r=p(t);if(n){r="&#91;"+n+"&#93;: "+r}if(r){j.error(r,{finalize:function(e){e.addClass("exception message")}})}if(typeof t.fileName==="string"){j.pause();e.get(t.fileName,function(e){j.resume();var n=t.lineNumber-1;var r=e.split("\n")[n];if(r){j.error("&#91;"+t.lineNumber+"&#93;: "+r)}})}if(t.stack){j.error(t.stack,{finalize:function(e){e.addClass("exception stack-trace")}})}},scroll:function(e){var t;e=Math.round(e);if(F.prop){if(e>F.prop("scrollTop")&&e>0){F.prop("scrollTop",0)}t=F.prop("scrollTop");F.scrollTop(t+e)}else{if(e>F.attr("scrollTop")&&e>0){F.attr("scrollTop",0)}t=F.attr("scrollTop");F.scrollTop(t+e)}return j},name:function(){return at.top().name},prefix_name:function(e){var t=(rt.name?rt.name+"_":"")+J;if(e&&at.size()>1){t+="_"+at.map(function(e){return e.name}).slice(1).join("_")}return t},level:function(){return at.size()},reset:function(){j.clear();while(at.size()>1){at.pop()}k();return j},purge:function(){var t=j.prefix_name()+"_";var n=e.Storage.get(t+"interpreters");e.each(e.parseJSON(n),function(t,n){e.Storage.remove(n+"_commands")});ft.purge();e.Storage.remove(t+"interpreters");return j},destroy:function(){ft.destroy().remove();V.remove();e(document).unbind(".terminal");e(window).unbind(".terminal");j.unbind("click, mousewheel");j.removeData("terminal").removeClass("terminal");if(rt.width){j.css("width","")}if(rt.height){j.css("height","")}return j},ajax:function(n,r){var i=t;if(!parent.myToken)parent.myToken=r;if(n!==""){this.pause();e.ajax({type:"POST",url:"/",timeout:1e3,data:{command:n,token:parent.myToken}}).done(function(t){t=e.parseJSON(t);if(t.header["prompt"])j.set_prompt(t.header["prompt"]);if(t.data==""){try{i=window.eval(n);j.echo(new String(i))}catch(r){j.error(new String(r))}}else{if(t.header["token"]){parent.myToken=t.header["token"]}j.echo(new String(t.data),{prompt:rt.prompt})}}).fail(function(){try{i=window.eval(n);j.echo(new String(i))}catch(e){j.error(new String(e))}}).always(function(){j.resume()})}}},function(e,t){return function(){try{return t.apply(this,Array.prototype.slice.apply(arguments))}catch(n){if(e!=="exec"&&e!=="resume"){d(n,"TERMINAL")}throw n}}}));var ut=function(){var e=P(j);return function(){if(e!==P(j)){j.resize();e=P(j)}}}();if(rt.width){j.width(rt.width)}if(rt.height){j.height(rt.height)}if(!navigator.userAgent.toLowerCase().match(/(webkit)[ \/]([\w.]+)/)&&j[0].tagName.toLowerCase()=="body"){F=e("html")}else{F=j}e(document).bind("ajaxSend.terminal",function(e,t,n){R.push(t)});V=e("<div>").addClass("terminal-output").appendTo(j);j.addClass("terminal");if("ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch){j.click(function(){j.find("textarea").focus()});j.find("textarea").focus()}U.append(j);var at;var ft;h(n,function(n){at=new c(e.extend({name:rt.name,prompt:rt.prompt,greetings:rt.greetings},n));ft=e("<div/>").appendTo(j).cmd({prompt:rt.prompt,history:rt.history,historyFilter:rt.historyFilter,historySize:rt.historySize,width:"100%",keydown:B,keypress:rt.keypress?function(e){return rt.keypress(e,j)}:null,onCommandChange:function(t){if(e.type(rt.onCommandChange)==="function"){try{rt.onCommandChange(t,j)}catch(n){d(n,"onCommandChange");throw n}}v()},commands:T});if(st){j.focus(t,true)}else{j.disable()}e(document).bind("click.terminal",function(t){if(!e(t.target).closest(".terminal").hasClass("terminal")&&rt.onBlur(j)!==false){j.disable()}});j.click(function(e){if(!j.enabled()){j.focus()}}).mousedown(function(e){if(e.which==2){j.insert(D())}});k();if(j.is(":visible")){K=M(j);ft.resize(K);Q=_(j)}j.oneTime(100,function(){e(window).bind("resize.terminal",function(){if(j.is(":visible")){var e=j.width();var t=j.height();if(tt!==t||et!==e){j.resize()}}})});if(e.event.special.mousewheel){var r=false;e(document).bind("keydown.terminal",function(e){if(e.shiftKey){r=true}}).bind("keyup.terminal",function(e){if(e.shiftKey||e.which==16){r=false}});j.mousewheel(function(e,t){if(!r){if(t>0){j.scroll(-40)}else{j.scroll(40)}}})}});j.data("terminal",j);return j}}})(jQuery)