cleanup before testing.
This commit is contained in:
parent
893b5cf1de
commit
4f48d4d45f
1 changed files with 225 additions and 206 deletions
163
sahli.js
163
sahli.js
|
|
@ -1,7 +1,7 @@
|
|||
// .___________________________________. ._____.
|
||||
// | / | | . | |_____|
|
||||
// | ____ | : | | |
|
||||
//: |___/ / | | l_____| |
|
||||
// .___________________________________, ___
|
||||
// | / | | . \ .(___):
|
||||
// | _______ | : \ : |
|
||||
//: |___/ / | | \__| |
|
||||
//| / | | | |
|
||||
//l__________/__________|___|______l__________j_____j
|
||||
//
|
||||
|
|
@ -10,12 +10,12 @@
|
|||
// Uses fonts by DMG, http://trueschool.se
|
||||
// Uses SixteenColors textmode js library for rendering
|
||||
|
||||
var Sahli = function(){
|
||||
var Sahli = function() {
|
||||
this.outbox = $('div#outbox');
|
||||
this.dbox = $('div#drawbox');
|
||||
this.image;
|
||||
this.image = 0;
|
||||
|
||||
// scroll speed of 5 looks ... "ok" on macbook pro. 4 was original.
|
||||
// scroll speed of 5 looks ... "ok" on macbook pro. 4 was original.
|
||||
this.scroll_speed = 5;
|
||||
this.scroll_direction = 1;
|
||||
this.zoomspeed = 200;
|
||||
|
|
@ -26,11 +26,14 @@ var Sahli = function(){
|
|||
this.dbox.height(document.height - 24);
|
||||
this.dbox.width(document.width - 2);
|
||||
this.sizemult = 16; // 32 is larger than screen, and somewhat silly
|
||||
this.origheight, this.origwidth, this.filedata, this.slides;
|
||||
this.origheight = 0;
|
||||
this.origwidth = 0;
|
||||
this.filedata = '';
|
||||
this.slides = 0;
|
||||
this.currentpic = 0;
|
||||
this.nonfsheight = document.height - 40;
|
||||
|
||||
this.loadpic = function(picdata,inserthere){
|
||||
this.loadpic = function(picdata, inserthere) {
|
||||
var infob = $('div.infobox');
|
||||
var pdiv = $('<div>');
|
||||
var canv = document.createElement('canvas');
|
||||
|
|
@ -42,13 +45,17 @@ var Sahli = function(){
|
|||
var color = this.calccolor(picdata.color);
|
||||
var bgcolor = this.calccolor(picdata.bg);
|
||||
ptxt.addClass(picdata.font.toLowerCase());
|
||||
ptxt.css({'color':color,'background-color':bgcolor,'margin':'auto'});
|
||||
ptxt.width(picdata.width*8);
|
||||
ptxt.css({
|
||||
'color': color,
|
||||
'background-color': bgcolor,
|
||||
'margin': 'auto'
|
||||
});
|
||||
ptxt.width(picdata.width * 8);
|
||||
pdiv.width('100%');
|
||||
pdiv.append(ptxt);
|
||||
// x-user-defined
|
||||
// x-user-defined
|
||||
req.overrideMimeType('text/plain; charset=ISO-8859-1');
|
||||
req.onreadystatechange = function () {
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState === req.DONE) {
|
||||
if (req.status === 200 || req.status === 0) {
|
||||
ptxt.text(this.responseText);
|
||||
|
|
@ -56,7 +63,7 @@ var Sahli = function(){
|
|||
} else {
|
||||
// I really should make a real error handler.
|
||||
alert(req);
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
req.open('GET', picdata.file, true);
|
||||
|
|
@ -66,11 +73,11 @@ var Sahli = function(){
|
|||
this.image = new ImageTextModeANSI();
|
||||
this.image.parseUrl(picdata.file);
|
||||
this.image.renderCanvas(canv);
|
||||
pdiv.append(canv)
|
||||
pdiv.append(canv);
|
||||
inserthere.after(pdiv);
|
||||
this.origwidth=canv.width;
|
||||
this.origheight=canv.height;
|
||||
};
|
||||
this.origwidth = canv.width;
|
||||
this.origheight = canv.height;
|
||||
}
|
||||
infob.find('h1').text(picdata.name);
|
||||
infob.find('h2').text(picdata.author);
|
||||
infob.find('h3#text').text(picdata.line1);
|
||||
|
|
@ -82,48 +89,60 @@ var Sahli = function(){
|
|||
};
|
||||
|
||||
this.calccolor = function(colorset) {
|
||||
return 'rgba('+colorset.toString()+')';
|
||||
return 'rgba(' + colorset.toString() + ')';
|
||||
};
|
||||
|
||||
this.resize = function(amt){
|
||||
this.resize = function(amt) {
|
||||
var canv = $('canvas');
|
||||
var w = canv.width() * amt;
|
||||
var h = canv.height() * amt;
|
||||
canv.animate({width:w,height:h},this.zoomspeed);
|
||||
canv.animate({
|
||||
width: w,
|
||||
height: h
|
||||
}, this.zoomspeed);
|
||||
};
|
||||
|
||||
this.fullwidth = function(){
|
||||
this.fullwidth = function() {
|
||||
this.stopscroll();
|
||||
if($('canvas').width() == this.dbox.width() ) {
|
||||
if ($('canvas').width() == this.dbox.width()) {
|
||||
this.originalsize(this.zoomspeed);
|
||||
} else {
|
||||
var ratio = this.origwidth / this.dbox.width();
|
||||
$('canvas').animate({width:this.dbox.width(),height:this.origheight / ratio},this.zoomspeed);
|
||||
$('canvas').animate({
|
||||
width: this.dbox.width(),
|
||||
height: this.origheight / ratio
|
||||
}, this.zoomspeed);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
this.fullheight = function(){
|
||||
this.fullheight = function() {
|
||||
var canv = $('canvas');
|
||||
if(canv.height() == this.dbox.height() ) {
|
||||
if (canv.height() == this.dbox.height()) {
|
||||
this.originalsize(this.zoomspeed);
|
||||
} else {
|
||||
var ratio = this.origheight / this.dbox.height() ;
|
||||
canv.animate({height: this.dbox.height(), width:this.origwidth / ratio},this.zoomspeed);
|
||||
var ratio = this.origheight / this.dbox.height();
|
||||
canv.animate({
|
||||
height: this.dbox.height(),
|
||||
width: this.origwidth / ratio
|
||||
}, this.zoomspeed);
|
||||
}
|
||||
};
|
||||
|
||||
this.originalsize = function(zoomspeed) {
|
||||
// why do we not have origwidth now? hmm.
|
||||
// why do we not have origwidth now? hmm.
|
||||
var canv = $('canvas');
|
||||
canv.animate({width: this.origwidth, height:this.origheight},this.zoomspeed);
|
||||
canv.animate({
|
||||
width: this.origwidth,
|
||||
height: this.origheight
|
||||
}, this.zoomspeed);
|
||||
};
|
||||
|
||||
|
||||
this.toptext = function(text) {
|
||||
if (this.DEBUG) {
|
||||
$('h1#top').text(text);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
this.setscroll = function() {
|
||||
|
|
@ -140,14 +159,16 @@ var Sahli = function(){
|
|||
scrollto = 0;
|
||||
steps = this.dbox.scrollTop();
|
||||
}
|
||||
this.toptext(this.scroll_speed +' | '+ steps);
|
||||
this.toptext(this.scroll_speed + ' | ' + steps);
|
||||
|
||||
this.dbox.animate({scrollTop : scrollto}, this.scroll_speed*steps ,'linear');
|
||||
this.dbox.animate({
|
||||
scrollTop: scrollto
|
||||
}, this.scroll_speed * steps, 'linear');
|
||||
};
|
||||
|
||||
this.resizedrawbox = function(height) {
|
||||
var dbox1 = $('div#drawbox');
|
||||
if( 'undefined' === typeof height ) {
|
||||
if ('undefined' === typeof height) {
|
||||
dbox1.height(window.innerHeight - 2);
|
||||
} else {
|
||||
dbox1.height(height);
|
||||
|
|
@ -155,14 +176,14 @@ var Sahli = function(){
|
|||
dbox1.width(window.innerWidth - 2);
|
||||
};
|
||||
|
||||
this.stopscroll = function () {
|
||||
this.stopscroll = function() {
|
||||
this.dbox.stop(true);
|
||||
};
|
||||
|
||||
this.moveabout = function(lines) {
|
||||
var line = this.dbox.scrollTop();
|
||||
this.dbox.stop(true);
|
||||
switch(lines) {
|
||||
switch (lines) {
|
||||
case 0:
|
||||
this.dbox.scrollTop(0);
|
||||
break;
|
||||
|
|
@ -177,11 +198,11 @@ var Sahli = function(){
|
|||
|
||||
this.requestsahlifile = function(url) {
|
||||
var ref = this;
|
||||
$.getJSON(url,function(json) {
|
||||
$.getJSON(url, function(json) {
|
||||
ref.filedata = json.filedata;
|
||||
ref.slides = json.slides;
|
||||
ref.buildcompo();
|
||||
} );
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -192,62 +213,61 @@ var Sahli = function(){
|
|||
|
||||
this.nextpic = function() {
|
||||
this.dbox.children().remove();
|
||||
// reset scrolling;
|
||||
// reset scrolling;
|
||||
this.stopscroll();
|
||||
this.scroll_direction = 1;
|
||||
var i = this.currentpic;
|
||||
var filedata = this.filedata;
|
||||
filedata[i].pic = $("<h6>"+filedata[i].file+"</h6>");
|
||||
filedata[i].pic = $("<h6>" + filedata[i].file + "</h6>");
|
||||
this.dbox.append(filedata[i].pic);
|
||||
this.loadpic(filedata[i],filedata[i].pic);
|
||||
this.loadpic(filedata[i], filedata[i].pic);
|
||||
this.currentpic += 1;
|
||||
if (this.currentpic > filedata.length -1 ) {
|
||||
if (this.currentpic > filedata.length - 1) {
|
||||
this.currentpic = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.gofullscreen = function(){
|
||||
var docElm= document.documentElement;
|
||||
var toid = window.setTimeout( sahli.resizedrawbox, 100);
|
||||
this.gofullscreen = function() {
|
||||
var docElm = document.documentElement;
|
||||
var toid = window.setTimeout(sahli.resizedrawbox, 100);
|
||||
if (docElm.requestFullscreen) {
|
||||
docElm.requestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
|
||||
}
|
||||
else if (docElm.mozRequestFullScreen) {
|
||||
} else if (docElm.mozRequestFullScreen) {
|
||||
docElm.mozRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
|
||||
}
|
||||
else if (docElm.webkitRequestFullScreen) {
|
||||
} else if (docElm.webkitRequestFullScreen) {
|
||||
docElm.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.cancelfullscreen = function(){
|
||||
var toid = window.setTimeout( sahli.resizedrawbox, 100, this.nonfsheight );
|
||||
this.cancelfullscreen = function() {
|
||||
var toid = window.setTimeout(sahli.resizedrawbox, 100, this.nonfsheight);
|
||||
if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
}
|
||||
else if (document.mozCancelFullScreen) {
|
||||
} else if (document.mozCancelFullScreen) {
|
||||
document.mozCancelFullScreen();
|
||||
}
|
||||
else if (document.webkitCancelFullScreen) {
|
||||
} else if (document.webkitCancelFullScreen) {
|
||||
document.webkitCancelFullScreen();
|
||||
}
|
||||
};
|
||||
|
||||
this.fixhelpbox = function() {
|
||||
var h = $('.help');
|
||||
// var xy = {'top': document.height/2 - h.height()/2, 'left': document.width/2 - h.width()/2};
|
||||
var xy = {'top': 0, 'left': document.width/2 - h.width()/2};
|
||||
// var xy = {'top': document.height/2 - h.height()/2, 'left': document.width/2 - h.width()/2};
|
||||
var xy = {
|
||||
'top': 0,
|
||||
'left': document.width / 2 - h.width() / 2
|
||||
};
|
||||
h.css(xy);
|
||||
};
|
||||
|
||||
this.toggledebug = function(){
|
||||
this.toggledebug = function() {
|
||||
$('h1#top').fadeToggle();
|
||||
this.DEBUG = (!this.DEBUG);
|
||||
};
|
||||
|
||||
this.loadkeys = function(){
|
||||
this.loadkeys = function() {
|
||||
var ref = this;
|
||||
$(document).bind('click', function(ev) {
|
||||
if (ev.clientY < 100) {
|
||||
|
|
@ -258,13 +278,13 @@ var Sahli = function(){
|
|||
}
|
||||
} else {
|
||||
ref.setscroll();
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
$(document).bind('keydown', function(ev){
|
||||
switch(ev.which) {
|
||||
$(document).bind('keydown', function(ev) {
|
||||
switch (ev.which) {
|
||||
case 84: // t
|
||||
ref.asciiasgfx = (! ref.asciiasgfx);
|
||||
ref.asciiasgfx = (!ref.asciiasgfx);
|
||||
ref.toptext(ref.asciiasgfx);
|
||||
break;
|
||||
case 85: // u
|
||||
|
|
@ -282,7 +302,7 @@ var Sahli = function(){
|
|||
ref.resize(2);
|
||||
break;
|
||||
case 75: // k
|
||||
ref.resize(.5);
|
||||
ref.resize(0.5);
|
||||
break;
|
||||
case 79: // o
|
||||
ref.fullwidth();
|
||||
|
|
@ -304,7 +324,7 @@ var Sahli = function(){
|
|||
case 107: // +
|
||||
case 190: // .
|
||||
ref.scroll_speed = ref.scroll_speed * 2;
|
||||
ref.toptext("speed doubled:" + ref.scroll_speed );
|
||||
ref.toptext("speed doubled:" + ref.scroll_speed);
|
||||
break;
|
||||
case 109: // -
|
||||
case 188: // ,
|
||||
|
|
@ -366,23 +386,22 @@ var Sahli = function(){
|
|||
default:
|
||||
if (ref.DEBUG) {
|
||||
alert(ev.which);
|
||||
};
|
||||
}
|
||||
break;
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.loadkeys();
|
||||
// this.loadpic('h7-r2012.ans',this.dbox);
|
||||
// this.loadpic('h7-r2012.ans',this.dbox);
|
||||
this.fixhelpbox();
|
||||
var ref = this;
|
||||
$(window).resize(function () {
|
||||
$(window).resize(function() {
|
||||
ref.resizedrawbox();
|
||||
});
|
||||
this.requestsahlifile('list.sahli');
|
||||
|
||||
};
|
||||
|
||||
// Dammit I hate how conttrol-R in textmate is "some shell shit"
|
||||
// I also hate how scrolling is incredibly stupid on osX
|
||||
// Mind you, it's better than touching anything in Windows.
|
||||
// I switched to Sublime text + sublemacs pro.
|
||||
// Yes, the author of Sublime Text's emacs hatred is annoying.
|
||||
Loading…
Add table
Add a link
Reference in a new issue