ansilove.js

A script to display ANSi and artscene related file formats on web pages
Log | Files | Refs | README | LICENSE

commit 19f2628bafe8db5f070615cefa7234f4a3ed2f1f
parent d680215148a29dac919e274905911ed285a11506
Author: Andy Herbert <andy.herbert@gmail.com>
Date:   Sat,  9 Nov 2013 08:48:26 +0000

Refactored animation calling routines.

Diffstat:
Mansilove.js | 120++++++++++++++++++++++++++++++++++++++-----------------------------------------
1 file changed, 58 insertions(+), 62 deletions(-)

diff --git a/ansilove.js b/ansilove.js @@ -1650,46 +1650,54 @@ var AnsiLove = (function () { return i; } + function play(baud, callback, clearScreen) { + var length, drawBlink; + clearScreen = (clearScreen === undefined) ? true : clearScreen; + clearTimeout(timer); + clearInterval(interval); + drawBlink = false; + interval = setInterval(function () { + ctx.drawImage(blinkCanvas[drawBlink ? 1 : 0], 0, 0); + drawBlink = !drawBlink; + }, 250); + function drawChunk() { + if (read(length)) { + timer = setTimeout(drawChunk, 10); + } else if (callback) { + callback(); + } + } + length = Math.floor((baud || 115200) / 8 / 100); + if (clearScreen) { + resetAll(); + } else { + resetAttributes(); + escapeCode = ""; + escaped = false; + file.seek(0); + } + drawChunk(); + } + + function stop() { + clearTimeout(timer); + clearInterval(interval); + } + + function load(bytes, callback) { + clearTimeout(timer); + file = new File(bytes); + callback(file.sauce); + } + return { "canvas": canvas, - "play": function (baud, callback, clearScreen) { - var length, drawBlink; - clearScreen = (clearScreen === undefined) ? true : clearScreen; - clearTimeout(timer); - clearInterval(interval); - drawBlink = false; - interval = setInterval(function () { - ctx.drawImage(blinkCanvas[drawBlink ? 1 : 0], 0, 0); - drawBlink = !drawBlink; - }, 250); - function drawChunk() { - if (read(length)) { - timer = setTimeout(drawChunk, 10); - } else if (callback) { - callback(); - } - } - length = Math.floor((baud || 115200) / 8 / 100); - if (clearScreen) { - resetAll(); - } else { - resetAttributes(); - escapeCode = ""; - escaped = false; - file.seek(0); - } - drawChunk(); - }, - "stop": function () { - clearTimeout(timer); - clearInterval(interval); - }, - "load": function (bytes, callback) { - clearTimeout(timer); - file = new File(bytes); - callback(file.sauce); - }, - "sauce": file.sauce + "sauce": file.sauce, + "controller": { + "play": play, + "stop": stop, + "load": load + } }; } @@ -1737,43 +1745,31 @@ var AnsiLove = (function () { }, callbackFail); } - function animate(url, callback, options, callbackFail) { - var ansimation; - httpGet(url, function (bytes) { - ansimation = new Ansimation(bytes, options || {}); - callback(ansimation.canvas, ansimation.sauce); - }, callbackFail); - return { - "play": function (baud, callback, clearScreen) { - ansimation.play(baud, callback, clearScreen); - }, - "stop": function () { - ansimation.stop(); - }, - "load": function (url, callback, callbackFail) { - httpGet(url, function (bytes) { - ansimation.load(bytes, callback); - }, callbackFail); - } - }; - } - function animateBytes(bytes, callback, options) { var ansimation; ansimation = new Ansimation(bytes, options || {}); setTimeout(function () { callback(ansimation.canvas, ansimation.sauce); }, 250); + return ansimation.controller; + } + + function animate(url, callback, options, callbackFail) { + var ansimation; + httpGet(url, function (bytes) { + ansimation = new Ansimation(bytes, options || {}); + callback(ansimation.canvas, ansimation.sauce); + }, callbackFail); return { "play": function (baud, callback, clearScreen) { - ansimation.play(baud, callback, clearScreen); + ansimation.controller.play(baud, callback, clearScreen); }, "stop": function () { - ansimation.stop(); + ansimation.controller.stop(); }, "load": function (url, callback, callbackFail) { httpGet(url, function (bytes) { - ansimation.load(bytes, callback); + ansimation.controller.load(bytes, callback); }, callbackFail); } };