/*
*
* Author Jean-Philippe SARDA https://twitter.com/jpsarda
* Code released under Common Creative license
* Framework mootools https://mootools.net/
*
*/
var _zo___initVar=0;
var _zo___cursorBlinkVar=0;
var _zo___backspaceLastTime=0;
var _zo___UDarrowLastTime=0;
var _zo___booting=1;
var _zo___currentContext=0;
var _zo___commands=[];
var _zo___history=[];
var _zo___historyIndex=0;
var _zo___historyCurrentLine='';
var _zo___saveRenew=1;
var _zo___initRestore=0;
var _zo___space='\u00A0';
window.addEvent('domready', function() {_zo___initEngineOnce(); _zo___startEngine();});
window.addEvent ('resize', function() {_zo___windowResize();});
window.addEvent ('click', function() {_zo___focusForce();});
//window.addEvent ('keypress', function() {focusForce();});
//window.addEvent ('keydown', function() {focusForce();});
//window.addEvent ('keyup', function() {focusForce();});
window.addEvent ('focus', function() {_zo___focusForce();});
// Command base class
//
var BaseCommand = new Class({
//We're using options
Implements: Options,
//Set our default options
options : {
context : 0 //object of class Context
},
//Command name
name : '',
//Command shows up on commands list
hidden : false,
//Have our initialization function
//set the options using setOptions
initialize : function(options){
this.setOptions(options);
},
//call this method to release all allocations
release : function(){
//clean timers, memory, listeners
//...
},
//call this method to end the command execution
over : function(){
this.release();
//inform the OS that the command is over.
this.options.context.over();
},
//call this method when ending the command execution
output : function(str){
this.options.context.output(str);
},
//call this method to get user input
input : function(){
this.options.context.input();
},
//to override to implement the command logic
execute : function(arg){
//output a line on the console
//this.output('Unknown command, type "help"');
this.over();
},
//Common message when a server request fails
command_ooo : function(){
this.output('Sorry this command is temporarly out of service');
},
//
// Called by the OS
//
//called by the OS, execute the command with the arguments arg (string)
start : function(ctxt,arg){
this.options.context=ctxt;
this.execute(arg);
},
//called by the OS, new user entry
user_entry : function(entry) {
//...
},
//called by the OS, returns a one line help about the command
help : function() {
return '';
},
//called by the OS, force exit (the context is inactive after this call)
force_exit : function(arg){
this.release();
}
});
// Commands
//
var AboutCommand = new Class({
Extends : BaseCommand,
name : 'about',
execute : function(arg){
//this.output('Si et JP portfolio version 0.103');
this.output("Si et JP is the name of my company (based in Paris, France). I'm JP SARDA, a senior freelance developer.
Specialized in iPhone & Android development, Digital Television Satellite DTT IPTV VOD architecture design, Flash PHP MySQL development, Game design & development.");
this.output("");
this.output("Type \"contact\" to get in touch.");
this.output("");
this.over();
},
help : function() {
return 'Display informations about Si et JP';
}
});
var ContactCommand = new Class({
Extends : BaseCommand,
name : 'contact',
execute : function(arg){
this.output("");
this.output("jpsarda@sietjp.com");
this.output("");
this.over();
},
help : function() {
return 'Display contact informations';
}
});
var PortfolioCommand = new Class({
Extends : BaseCommand,
name : 'portfolio',
execute : function(arg){
this.output("Some of my achievements...");
this.output("Game design and development : Moonlights (50,000 copies sold)");
this.output("Game design and development : Blockoban (150,000 downloads)");
this.output("Website design and development : Bonus Level (5,000 visitors/day)");
this.output("Website design and development : Cucumis (25,000 visitors/day)");
this.output("Digital TV design : Bouygues Bbox (IPTV & VOD platform architecture & design)");
this.output("iPhone + Android application : Piste et Trésor outdoor riddle game, with geoloc, compass & maps");
this.output("Suite of Android applications for Radio France : Radio France with live streaming, podcasts, news, notifications.");
this.output("");
this.over();
},
help : function() {
return 'Display some of the works of Si et JP';
}
});
var HelpCommand = new Class({
Extends : BaseCommand,
name : 'help',
execute : function(arg){
var commandList='Commands list :
';
//now you call the myArrayFunction for EACH item within the array
_zo___commands.each(function(item) {
if ((item.name!='')&&(!item.hidden)) {
commandList+=' '+item.name;
}
});
//output
this.output(commandList);
this.output('
Type a command name followed by "?" or "help" to display specific help');
//this.output('Examples :
"will ?"
"google help"');
this.over();
},
help : function() {
return 'Output the commands list';
}
});
var MenuCommand = new Class({
Extends : BaseCommand,
name : 'menu',
execute : function(arg){
this.output('
Type (or click) "portfolio" "about" "contact"
');
//this.output('Examples :
"will ?"
"google help"');
this.over();
},
help : function() {
return 'Output the menu';
}
});
var HotCommand = new Class({
Extends : BaseCommand,
name : 'hot',
execute : function(arg){
//request on the server
var myRequest = new Request({method: 'get', url: '/hot.php', onSuccess: function(responseText, responseXML){ this.response(responseText); }.bind(this), onFailure:function(xhr){ this.response(false); }.bind(this)});
myRequest.send();
},
response : function(res){
if (res!=false) {
//output the result on the console
this.output(res);
} else {
//informs that the command is out of order
this.command_ooo();
}
//command is over, OS becomes the master
this.over();
},
help : function() {
return 'Usage : "hot"
Displays the hotest and the latest commands saved on zeOracle';
}
});
var WillCommand = new Class({
Extends : BaseCommand,
name : 'will',
execute : function(arg){
//request on the server
var myRequest = new Request({method: 'get', url: '/think.php', onSuccess: function(responseText, responseXML){ this.response(responseText); }.bind(this), onFailure:function(xhr){ this.response(false); }.bind(this)});
myRequest.send('cmd='+escape(this.name)+'&ask='+escape(arg));
},
response : function(res){
if (res!=false) {
//output the result on the console
this.output(res);
} else {
//informs that the command is out of order
this.command_ooo();
}
//command is over, OS becomes the master
this.over();
},
help : function() {
return 'Usage : "will [your question about the future]"
Instrucions : zeOracle answers Yes or No
Examples :
"will I be a great man one day ?"
"will obama be the next president of the united states ?"';
}
});
var SaveCommand = new Class({
Extends : BaseCommand,
name : 'save',
execute : function(arg){
var error=0;
var option=(arg.split(' ',1))[0];
option=option.toLowerCase();
var password="";
if (option=='-p') {
arg=arg.substr(option.length).clean();
password=(arg.split(' ',1))[0];
arg=arg.substr(password.length).clean();
}
var name=arg.clean();
if (!name.match(/^[-a-zA-Z0-9_]*$/i)) {
error=1;
}
if (!password.match(/^[-a-zA-Z0-9_]*$/i)) {
error=1;
}
if (error==1) {
this.output('Invalid parameters');
this.output(this.help());
this.over();
return;
}
//request on the server
cmds='';
var i=_zo___history.length;
while(i--) {
var cmd=(_zo___history[i].split(' ',1))[0];
cmd=cmd.toLowerCase().clean();
if ((cmd=='clear')||(cmd=='reboot')) {
break;
}
if (cmd!='save') {
if (cmds=='') {
cmds=_zo___history[i];
} else {
cmds=_zo___history[i]+"\n"+cmds;
}
}
}
var myRequest = new Request({method: 'post', url: '/savecmds.php', onSuccess: function(responseText, responseXML){ this.response(responseText); }.bind(this), onFailure:function(xhr){ this.response(false); }.bind(this)});
myRequest.send('name='+escape(name)+'&pwd='+password+"&renew="+_zo___saveRenew+'&cmds='+escape(cmds));
_zo___saveRenew=0;
},
response : function(res){
if (res!=false) {
//output the result on the console
this.output(res);
} else {
//informs that the command is out of order
this.command_ooo();
}
//command is over, OS becomes the master
this.over();
},
help : function() {
return 'Usage : "save [[-p password] save_name]"
Use this to send the commands history to zeOracle servers, zeOracle will then provide a public url to restore your session. The name is optional, use it to get a fancy restore url, like zeoracle.com/myfancyname. Use a password to be able to overwrite this custom name.
Examples :
"save"
"save mysession"
save -p mypassword mysession';
}
});
var ClearCommand = new Class({
Extends : BaseCommand,
name : 'clear',
execute : function(arg){
_zo___clear();
this.over();
},
help : function() {
return 'Clear the screen';
}
});
var RebootCommand = new Class({
Extends : BaseCommand,
name : 'reboot',
execute : function(arg){
window.location.reload();
//_zo___initIndex=0;
//_zo___initIndexReady=0;
//_zo___initReadyIndex=0;
//_zo___clear();
//this.over();
//_zo___startEngine();
},
help : function() {
return 'Reboot zeOracle';
}
});
var SdkCommand = new Class({
Extends : BaseCommand,
name : 'sdk',
execute : function(arg){
var option=(arg.split(' ',1))[0];
option=option.toLowerCase();
if (option=='-test') {
arg=arg.substr(option.length).clean();
className=(arg.split(' ',1))[0];
arg=arg.substr(className.length).clean();
var scriptInject = new Element('script', {'type': 'text/javascript'});
scriptInject.set('html','var _zo___injectError=0; try { '+arg+' ; var _zo___instance=new '+className+'({}); _zo___addCommand(_zo___instance); } catch (err) { _zo___injectError=err; } _zo___currentContext.options.cmd.injectResult(_zo___injectError);');
$('inject').empty();
scriptInject.inject($('inject'));
} else {
//request the help text on the server
var myRequest = new Request({method: 'get', url: '/sdkhelp.php', onSuccess: function(responseText, responseXML){ this.response(responseText); }.bind(this), onFailure:function(xhr){ this.response(false); }.bind(this)});
myRequest.send('cmd='+escape(this.name)+'&ask='+escape(arg));
}
},
injectResult: function(res){
if (res===0) {
this.output('Code added');
} else {
$('inject').empty();
this.output('Javascript error : '+res);
}
this.over();
},
response : function(res){
if (res!=false) {
//output the result on the console
res=res.replace(//g,'>').replace(/ /gi,' ').replace(new RegExp( "\\n", "g" ),'
');
this.output(res);
} else {
//informs that the command is out of order
this.command_ooo();
}
//command is over, OS becomes the master
this.over();
},
help : function() {
var toret='Create your own commands on zeOracle.com';
toret+='
Usage :
sdk [-test MyCommandClass my javascript code]
Type "sdk" to display the documentation and more examples of commands
Type "sdk -test MyCommandClass my javascript code" to test your command on zeOracle';
toret+='
Example, type the following line to create a new command called "mycmd" :
sdk -test MyOwnCommand var MyOwnCommand = new Class({ Extends : BaseCommand, name : \'mycmd\', execute : function(arg){ this.output(\'My Own Command!!!\'); this.over(); }, help : function() { return \'MyOwnCommand\'; }, });';
toret+='
Once your command is added you can use it like all other commands and it appears in commands list (type "help")';
toret+='
Can\'t wait to contribute ? Write to contact@zeoracle.com';
return toret;
}
});
var TwitterCommand = new Class({
Extends : BaseCommand,
name : 'twitter',
timer:0,
execute : function(arg){
if (arg=='') {
this.over();
return;
}
var myRequest = new Request.JSONP({
//url: 'https://search.twitter.com/search.json',
url: 'https://bonuslevel.org/twitterpx/search/tweets.json',
retries:0,
timeout:5000,
data: {
q:arg
},
onComplete: function(res){
this.response(res);
}.bind(this)
});
this.timer=this.timeout.bind(this).periodical(5000);
myRequest.send();
},
timeout:function() {
this.response(false);
},
response : function(res) {
clearTimeout(this.timer);
if (res!=false) {
//output the result on the console
if (res.statuses) {
res.statuses.each(function(item) {
this.output('@'+item.from_user+' ('+item.created_at.substr(0,16)+') : '+_zo___replaceTweet(item.text));
}.bind(this));
} else {
this.command_ooo();
}
} else {
//informs that the command is out of order
this.command_ooo();
}
//command is over, OS becomes the master
this.over();
},
help : function() {
return 'Search the public twitter time line.
Example : "twitter iphone games"';
}
});
var GoogleCommand = new Class({
Extends : BaseCommand,
name : 'google',
timer:0,
execute : function(arg){
var option=(arg.split(' ',1))[0];
option=option.toLowerCase();
var urlAdd="web";
if ((option=='-web')||(option=='-books')||(option=='-blogs')||(option=='-news')||(option=='-video')||(option=='-images')||(option=='-patent')) {
urlAdd=option.substr(1);
arg=arg.substr(option.length).clean();
}
var myRequest = new Request.JSONP({
url: 'https://ajax.googleapis.com/ajax/services/search/'+urlAdd,
retries:0,
timeout:5000,
data: {
v:'1.0',
q:arg
},
onComplete: function(res){
this.response(res);
}.bind(this)
});
this.timer=this.timeout.bind(this).periodical(5000);
myRequest.send();
},
timeout:function() {
this.response(false);
},
response : function(res) {
clearTimeout(this.timer);
if (res!=false) {
//output the result on the console
if (res.responseData) {
res.responseData.results.each(function(item) {
var url='';
if (item.unescapedUrl) url=item.unescapedUrl;
if (item.postUrl) url=item.postUrl;
if (item.playUrl) url=item.playUrl;
var linkVisible=item.title;
if (item.visibleUrl) linkVisible+=' ('+item.visibleUrl+')';
var resume='';
if (item.content) resume=' : '+item.content;
this.output(''+linkVisible+''+resume);
}.bind(this));
} else {
if (res.responseDetails) this.output(res.responseDetails);
else this.command_ooo();
}
} else {
//informs that the command is out of order
this.command_ooo();
}
//command is over, OS becomes the master
this.over();
},
help : function() {
return 'Search with google
Usage : "google [-option] key words"
Examples :
"google iphone games"
"google -news games"
"google -video"
"google -blogs"
"google -books"
"google -images"
"google -patent microsoft"';
}
});
var TranslateCommand = new Class({
Extends : BaseCommand,
name : 'translate',
timer:0,
execute : function(arg){
arg=arg.clean();
var args=arg.split(' ');
var nooptions=0;
var oldItem='';
var source='';
var dest='en';
var error=0;
var arg='';
args.each(function(item) {
if ((error==1)) return false;
item=item.toLowerCase();
if (nooptions<2) {
if (oldItem=='-s') {
if (item.match(/^[a-z]+[-a-z]*$/i)) {
source=item;
nooptions=0;
} else {
error=1;
}
} else if (oldItem=='-d') {
if (item.match(/^[a-z]+[-a-z]*$/i)) {
dest=item;
nooptions=0;
} else {
error=1;
}
} else {
nooptions++;
}
}
if (nooptions>=2) {
arg+=' '+item;
} else {
arg=item;
}
oldItem=item;
});
arg=arg.clean();
if (arg=='') error=1;
if (error==0) {
var myRequest = new Request.JSONP({
url: 'https://ajax.googleapis.com/ajax/services/language/translate',
retries:0,
timeout:5000,
data: {
v:'1.0',
langpair:source+'|'+dest,
q:arg
},
onComplete: function(res){
this.response(res);
}.bind(this)
});
this.timer=this.timeout.bind(this).periodical(5000);
myRequest.send();
} else {
this.output('Invalid parameters');
this.output(this.help());
this.over();
}
},
timeout:function() {
this.response(false);
},
response : function(res) {
clearTimeout(this.timer);
if (res!=false) {
//output the result on the console
if (res.responseData) {
if (res.responseData.translatedText) this.output(res.responseData.translatedText);
this.output('powered by google');
} else {
//_zo___debugLog(res.responseData.results);
if (res.responseDetails) this.output(res.responseDetails);
else this.command_ooo();
}
} else {
//informs that the command is out of order
this.command_ooo();
}
//command is over, OS becomes the master
this.over();
},
help : function() {
return 'Translate a text
Usage : "translate [-s SOURCE_LANGUAGE_ISO_CODE] [-d DESTINATION_LANGUAGE_ISO_CODE] the text to be transalted"
Instructions :
The default destination language is "en" (english). If no source language is specified, it\'s auto-detected.
Examples :
"translate bonjour comment ça va ?"
"translate -d fr Hello how are you ?"
"translate -d es Bonjour comment ça va ?"
"translate -s fr -d it Bonjour comment ça va ?"';
}
});
_zo___commands.push(new BaseCommand({}));
_zo___commands.push(new MenuCommand({}));
_zo___commands.push(new AboutCommand({}));
_zo___commands.push(new PortfolioCommand({}));
_zo___commands.push(new ContactCommand({}));
//_zo___commands.push(new WillCommand({}));
//_zo___commands.push(new SaveCommand({}));
//_zo___commands.push(new HotCommand({}));
//_zo___commands.push(new TwitterCommand({}));
//_zo___commands.push(new GoogleCommand({}));
//_zo___commands.push(new TranslateCommand({}));
_zo___commands.push(new ClearCommand({}));
_zo___commands.push(new RebootCommand({}));
//_zo___commands.push(new SdkCommand({}));
_zo___commands.push(new HelpCommand({}));
var _zo___addCommand = function(cmd) {
var index=-1;
var i=0;
_zo___commands.each(function(item) {
if (item.name==cmd.name) {
index=i;
}
i++;
});
if (index>=0) {
_zo___commands[index]=cmd;
} else {
_zo___commands.push(cmd);
}
}
// Context class
//
var Context = new Class({
//We're using options
Implements: Options,
//Set our default options
options : {
active : false, //is context active or not
cmd : 0 //corresponding BaseCommand (or extended) object
},
//Have our initialization function
//set the options using setOptions
initialize : function(options){
this.setOptions(options);
},
//call this method to release the context and force_exit the command
force_exit : function(){
cmd.force_exit();
this.over();
},
//call this method to start the command execution
start : function(arg){
this.options.active=true;
this.options.cmd.start(this,arg);
},
//call this method to end the command execution
over : function(){
this.input();
this.options.active=false;
_zo___currentContext=0;
},
//call this method when ending the command execution
output : function(str){
if (!this.options.active) return;
_zo___appendLine(str,0);
},
//call this method to get user input
input : function(){
if (!this.options.active) return;
_zo___inputVisible(1);
}
});
// Starting engine
//
var _zo___startEngine = function() {
_zo___booting=1;
_zo___inputVisible(0);
_zo___appendLine('Si et JP portfolio version 0.103',0);
clearTimeout(_zo___initVar);
var timerDelay=60;
if (_zo___initCmds.length>0) timerDelay=20;
_zo___initVar = _zo___init.periodical(timerDelay);
}
var _zo___keyDownTest = function(event) {
if (event.key=='backspace') _zo___backspaceEnter();
else if (event.key=='up') _zo___UDarrowEnter(-1);
else if (event.key=='down') _zo___UDarrowEnter(1);
}
var _zo___smartPhone=false;
var _zo___initEngineOnce = function() {
zo___smartPhone=DetectSmartphone();
if(window.location.hash.length>1) {
var initCmd="";
if (window.location.hash.substr(0,1)=="#") initCmd=window.location.hash.replace('#','');
else initCmd=window.location.hash;
_zo___initCmds.splice(0,0,initCmd);
}
$('userentry').setStyle('width', 1);
_zo___windowResize();
_zo___blinkActive(1);
$('userform').addEvent('submit', function(event) {event.stopPropagation(); _zo___enter(); return false;});
$('userentry').addEvent('focus', function(event) {_zo___blinkActive(1);});
$('userentry').addEvent('blur', function(event) {_zo___blinkActive(0);});
$('userentry').addEvent('keyup', function(event) {_zo___updateNewKey(event);});
$('userentry').addEvent('keydown', function(event) {_zo___updateNewKey(event); _zo___keyDownTest(event);});
$('userentry').addEvent('keypress', function(event) {_zo___updateNewKey(event); _zo___keyDownTest(event);});
}
var _zo___clear = function() {
_zo___saveRenew=1;
$('currententry').set('html','');
$('userentry').set('value','');
$('toplines').set('html','');
_zo___inputVisible(1);
}
var _zo___blinkActive = function(b) {
if (b==1) {
if (_zo___cursorBlinkVar==0) {
$('cursor').removeClass('invisible');
_zo___cursorBlinkVar=_zo___cursorBlink.periodical(500);
}
} else {
if (_zo___cursorBlinkVar!=0) {
$('cursor').addClass('invisible');
clearTimeout(_zo___cursorBlinkVar); _zo___cursorBlinkVar=0;
}
}
}
// Keyboard
//
var _zo___cursorBlink = function() {
$('cursor').toggleClass('invisible');
}
var _zo___backspaceEnter = function() {
var timestamp=new Date().getTime();
if (timestamp-_zo___backspaceLastTime>20) {
var current=$('currententry').get('html');
//debugLog('backspaceEnter current.length='+current.length);
if (current.length>0) {
var cut=1;
var charToDelete=current.substr(current.length-1,1);
if (charToDelete==';') {
var special;
if (current.length>=6) {
special=current.substr(current.length-6,6);
if ((special==' ')) cut=6;
}
if (current.length>=5) {
special=current.substr(current.length-5,5);
if ((special=='&')) cut=5;
}
if (current.length>=4) {
special=current.substr(current.length-4,4);
if ((special=='>')||(special=='<')) cut=4;
}
//debugLog('backspaceEnter '+special+' '+cut);
}
$('currententry').set('html',current.substr(0,current.length-cut));
_zo___historyIndex=_zo___history.length;
}
_zo___backspaceLastTime=timestamp;
}
}
var _zo___UDarrowEnter = function(add) {
var timestamp=new Date().getTime();
if (timestamp-_zo___UDarrowLastTime>20) {
if (_zo___historyIndex==_zo___history.length) {
_zo___historyCurrentLine=$('currententry').get('html');
}
var newHistoryIndex=_zo___historyIndex+add;
//_zo___debugLog(newHistoryIndex+' '+_zo___history.length);
if ((newHistoryIndex>=0)&&(newHistoryIndex<_zo___history.length)) {
$('currententry').set('html',_zo___history[newHistoryIndex]);
_zo___historyIndex=newHistoryIndex;
} else if (newHistoryIndex==_zo___history.length) {
$('currententry').set('html',_zo___historyCurrentLine);
_zo___historyIndex=newHistoryIndex;
}
_zo___UDarrowLastTime=timestamp;
}
}
var _zo___updateNewKey = function(event) {
if (_zo___booting==0) {
var usercurrententry=$('currententry');
var before=usercurrententry.get('html');
var key=$('userentry').get('value');
if (key==' ') key=_zo___space;
usercurrententry.appendText(key);
if (_zo___historyIndex<_zo___history.length) {
if (before.length<(usercurrententry.get('html')).length) {
_zo___historyIndex=_zo___history.length;
}
}
}
$('userentry').set('value','')
//debugLog('updateEnter');
}
// Input
//
var _zo___nextRestoreCommandFunctionVar=0;
var _zo___nextRestoreCommand = '';
var _zo___nextRestoreCommandFunction = function() {
clearTimeout(_zo___nextRestoreCommandFunctionVar); _zo___nextRestoreCommandFunctionVar=0;
_zo___initRestore++;
_zo___enterEntry(_zo___nextRestoreCommand);
}
var _zo___inputVisible = function(b) {
if (b==1) {
$('input').setStyle('visibility','');
_zo___focusForce();
_zo___waitAnim(0);
//Command restore ?
if (_zo___initRestore>=0) {
if (_zo___initRestore>=_zo___initCmds.length) {
_zo___initRestore=-1;
} else {
if (_zo___nextRestoreCommandFunctionVar==0) {
_zo___nextRestoreCommand=_zo___initCmds[_zo___initRestore];
_zo___nextRestoreCommandFunctionVar=_zo___nextRestoreCommandFunction.bind(this).periodical(1);
}
}
}
} else {
$('input').setStyle('visibility','hidden');
_zo___waitAnim(1);
}
window.scrollBy(0,100000); // horizontal and vertical scroll increments
}
var _zo___enter = function() {
if (_zo___booting!=0) return;
//prepare
_zo___updateNewKey(null);
var entry=$('currententry').get('html')+$('userentry').get('value');
_zo___enterEntry(entry);
}
var _zo___enterEntry = function(entry) {
entry=entry.clean();
entry=entry.replace(' ',' ');
_zo___inputVisible(0);
//erase
$('currententry').set('html','');
_zo___appendLine(entry,1);
_zo___history.push(entry);
_zo___historyIndex=_zo___history.length;
if (_zo___currentContext!=0) {
_zo___currentContext.options.cmd.user_entry(entry);
} else {
//entry=(entry.toLowerCase());
var cmd=(entry.split(' ',1))[0];
cmd=cmd.toLowerCase();
var commandFound=false;
//now you call the myArrayFunction for EACH item within the array
_zo___commands.each(function(item) {
//debugLog('item.cmd='+item.cmd);
if (_zo___currentContext==0) {
if (item.name==cmd) {
commandFound=true;
var arg=entry.substr(cmd.length).clean();
if ((arg=="?")||(arg=="help")) {
_zo___result(item.help());
} else {
arg=arg.replace(/>/gi,'>').replace(/</gi,'<').replace(/&/gi,'&');
_zo___currentContext=new Context({cmd:item});
_zo___currentContext.start(arg);
}
//break;
}
}
});
if (!commandFound) {
_zo___result("Unknown command (type \"help\")");
}
}
}
var _zo___result = function(txt) {
_zo___appendLine(txt,0);
_zo___inputVisible(1);
}
// Initialization
//
var _zo___initIndex=0;
var _zo___initIndexReady=0;
var _zo___initReadyIndex=0;
var _zo___initReady = function () {
//alert('toto');
_zo___initReadyIndex++;
if (_zo___initReadyIndex==1) {
if (_zo___initIndexReady==0) {
_zo___appendInLine('iPhone, Android, Blackberry, Flash, PHP, MySQL ',0);
} else if (_zo___initIndexReady==1) {
_zo___appendInLine('Digital Television Satellite DTT IPTV VOD ',0);
} else if (_zo___initIndexReady==2) {
_zo___appendInLine('Game Design ',0);
}
} else if ((_zo___initReadyIndex>=1)&&(_zo___initReadyIndex<=Number.random(5, 10))) {
_zo___appendInLine('.',0);
} else {
_zo___appendLine(' ready',0);
_zo___initReadyIndex=0;
_zo___initIndexReady++;
_zo___initIndex++; //next init line
}
}
var _zo___initLines=[];
// https://patorjk.com/software/taag/
// Standard
_zo___initLines.push(" _____ _ _ ______ ");
_zo___initLines.push(" / ____(_) | | | | __ \\ ");
_zo___initLines.push("| (___ _ ___| |_ | | |__) |");
_zo___initLines.push(" \\___ \\| | / _ \\ __| _ | | ___/ ");
_zo___initLines.push(" ____) | | | __/ |_ | |__| | | ");
_zo___initLines.push("|_____/|_| \\___|\\__| \\____/|_| ");
_zo___initLines.push('');
_zo___initLines.push(_zo___initReady);
_zo___initLines.push(_zo___initReady);
_zo___initLines.push(_zo___initReady);
_zo___initLines.push('');
//_zo___initLines.push('Type "portfolio" "about" "contact" or "help"');
//_zo___initLines.push('zeOracle is listening to you');
var _zo___init = function() {
if (Number.random(0, 100) < 30) return;
//_zo___debugLog('init() _zo___initIndex='+_zo___initIndex+' '+_zo___initLines[_zo___initIndex]);
if (_zo___initLines[_zo___initIndex] !== undefined) {
var nextLine=_zo___initLines[_zo___initIndex];
if (typeof(nextLine)=='function') {
nextLine();
} else {
_zo___appendLine(nextLine,0,1);
_zo___initIndex++;
}
} else {
clearTimeout(_zo___initVar); _zo___initVar=0;
_zo___booting=0;
_zo___inputVisible(1);
}
}
// Utils
//
var _zo___appendInLine = function(line,prompt) {
var toplines=$('toplines');
if (prompt==1) {
toplines.appendText('> '+line);
} else {
toplines.appendText(line);
}
}
var _zo___appendLine = function(line,prompt,transform) {
//$('toplines').appendText('> '+line+'\n');
var toplines=$('toplines');
if (transform==1) {
line=line.replace(/ /gi,' ');
}
if (prompt==1) {
toplines.set('html',toplines.get('html')+'> '+line+'
');
} else {
toplines.set('html',toplines.get('html')+line+'
');
}
//debugLog(line);
window.scrollBy(0,100000); // horizontal and vertical scroll increments
}
var _zo___replaceTweet = function(str) {
var toret=str.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig,"$1");
toret=toret.replace(/@([A-Z0-9_]+)/gi,"@$1");
return toret;
}
var _zo___windowResize = function() {
//alert('Engine started!');
var size = window.getSize();
//$('userentry').setStyle('width', size.x-30);
//alert("The window is "+size.x+" pixels wide and "+size.y+"pixels high.");
}
var _zo___focusForce = function() {
if (!zo___smartPhone) $('userentry').focus();
}
var _zo___waitAnimChars=['-','\\','|','/'];
var _zo___waitAnimCharsIndex=0;
var _zo___waitAnimVar=0;
var _zo___waitAnim=function(b) {
if (_zo___waitAnimVar!=0) {
clearTimeout(_zo___waitAnimVar);
_zo___waitAnimVar=0;
$('waitanim').set('html','');
$('waitanim').addClass('invisible');
}
if (b==1) {
$('waitanim').removeClass('invisible');
_zo___waitAnimVar=_zo___waitAnimStep.periodical(50);
}
}
var _zo___waitAnimStep=function() {
_zo___waitAnimCharsIndex++;
if (_zo___waitAnimCharsIndex>=_zo___waitAnimChars.length) _zo___waitAnimCharsIndex=0;
$('waitanim').set('html',_zo___waitAnimChars[_zo___waitAnimCharsIndex]);
}
var _zo___debugLog = function(line) {
//$('toplines').appendText('> '+line+'\n');
var debug=$('debug');
debug.set('html',debug.get('html')+'> '+line+'
');
}