/*************************************** * クラスライブラリ[classlib.txt] * (C) Copyright 2002 by A.I.Soft Incorporation. * * 概要 * * 作成 2006-04-07 by yoshida ***************************************/ // -*- Mode: Javascript -*- Function.prototype.bind = function(object) { var __method = this; return function() { return __method.apply(object, arguments); } } // 引数束縛 // http://nanto.asablo.jp/blog/2005/12/13/176033 Function.prototype.curry = function () { var args = arguments; var self = this; return function () { Array.prototype.unshift.apply(arguments, args); return self.apply(this, arguments); }; } // 関数の非同期実行を行う function AnSync() { this.method = null; this.doneCB = null; this.threadID = 0; this.bStop = false; this.Start = function(method_, doneCB_, interval_){ this.method = method_; this.doneCB = doneCB_; this.bStop = false; this.threadID = setInterval(this.Task.bind(this), interval_); } this.Stop = function(){ this.bStop = true; } this.Task = function(){ if(this.bStop){ clearInterval(this.threadID); this.doneCB(false); return; } if(this.method()){ ; } else { clearInterval(this.threadID); this.doneCB(true); } } return this; } // 関数の非同期実行を行う function AnSync2() { this.method = null; this.doneCB = null; this.threadID = 0; this.bStop = false; this.counter = 0; this.Start = function(method_, doneCB_, interval_){ this.method = method_; this.doneCB = doneCB_; this.bStop = false; this.counter = 0; this.threadID = setInterval(this.Task.bind(this), interval_); } this.Stop = function(){ this.bStop = true; } this.Task = function(){ if(this.method(this.counter, this.bStop)){ this.counter++; } else { clearInterval(this.threadID); this.doneCB(); } } return this; } // 非同期関数を逐次実行する function Sequent(doneCB_) { this.coms = new Array; this.doneCB = doneCB_; this.start = function(){ this.coms[0](this.done.bind(this)); } this.done = function(){ this.coms.shift(); if(this.coms.length == 0){ this.doneCB(); return; } this.coms[0](this.done.bind(this)); } } // 非同期関数を並列実行する function Parallel(doneCB_) { this.coms = new Array; this.doneCB = doneCB_; this.endFuncNum = 0; this.start = function(){ this.endFuncNum = 0; for (var i = 0; i < this.coms.length; i++) { this.coms[i](this.done.bind(this)); } } this.done = function(){ this.endFuncNum++; if(this.endFuncNum == this.coms.length){ this.doneCB(); } } } function counter(min, max, full, count) { return min + (max - min) * count / full; } /// メッセージレイヤー function MsgLayer(textDivID_, backDivID_, textSpanID_, waitSpanID_) { this.ansync = new AnSync2; this.textDivID = textDivID_; this.backDivID = backDivID_; this.textSpanID = textSpanID_; this.waitSpanID = waitSpanID_; this.msg = ""; this.state = "ready"; this.bNewLine = false; this.addText = function(text_, interval_, doneCB_){ if("ready" != this.state){ return; } this.state = "busy" this.msg = text_; this.stop = function(){this.ansync.Stop();} divClearImage(this.waitSpanID); // WaitCursorの削除 this.ansync.Start(this.$text.bind(this), doneCB_, interval_); } this.show = function(interval_, doneCB_){ this.msg = ""; this.stop = function(){}; this.ansync.Start(this.$show.bind(this), doneCB_, interval_); } this.hide = function(interval_, doneCB_){ this.msg = ""; this.stop = function(){}; this.ansync.Start(this.$hide.bind(this), doneCB_, interval_); } this.clear = function(){ divClearImage(this.waitSpanID); // WaitCursorの削除 divClear(this.textSpanID); this.bNewLine = false; // setTimeout(doneCB_, 0); } this.newLine = function(){ divInsertNewLine(this.textSpanID); } this.stop = function(){ this.ansync.Stop(); } this.showLineCursor = function(doneCB_){ divInsertImage(this.waitSpanID, "", "", "cursor/click.gif"); setTimeout(doneCB_, 0); } this.showPageCursor = function(doneCB_){ divInsertImage(this.waitSpanID, "", "", "cursor/page.gif"); setTimeout(doneCB_, 0); } this.$text = function(counter_, bStop_){ if(bStop_){ divInsertChar(this.textDivID, this.msg.substr(counter_)); this.state = "ready"; return false; } if(counter_ > this.msg.length){ this.state = "ready"; // divInsertImage(this.waitSpanID, "", "", "cursor/click.gif"); return false; } divInsertChar(this.textSpanID, this.msg.charAt(counter_)); return true; } this.$show = function(counter_, bStop_){ if(bStop_){return ture;} if(counter_ > 5){return false;} divSetAlpha(this.backDivID, counter(0, 30, 5, counter_)); divSetAlpha(this.textDivID, counter(0, 100, 5, counter_)); return true; } this.$hide = function(counter_, bStop_){ if(bStop_){return ture;} if(counter_ > 5){return false;} divSetAlpha(this.backDivID, counter(30, 0, 5, counter_)); divSetAlpha(this.textDivID, counter(100, 0, 5, counter_)); return true; } } /// クロスフェードレイヤー function XfadeLayer(priDivID_, secDivID_) { this.ansync = new AnSync2; this.priDivID = priDivID_; this.secDivID = secDivID_; this.imgID = "img" + priDivID_; this.imgpath = ""; this.quake = function(interval_, doneCB_){ this.stop = function(){this.ansync.Stop();} this.ansync.Start(this.$quake.bind(this), doneCB_, interval_); } this.fade = function(imgpath_, interval_, doneCB_){ this.imgpath = imgpath_; this.stop = function(){this.ansync.Stop();} divInsertImage(this.secDivID, "", "", imgpath_); this.ansync.Start(this.$fade.bind(this), doneCB_, interval_); } this.hide = function(interval_, doneCB_){ this.stop = function(){}; this.ansync.Start(this.$hide.bind(this), doneCB_, interval_); } this.show = function(interval_, doneCB_){ this.stop = function(){}; this.ansync.Start(this.$show.bind(this), doneCB_, interval_); } this.zoom = function(interval_, doneCB_){ this.stop = function(){}; this.ansync.Start(this.$zoom.bind(this), doneCB_, interval_); } this.$fade = function(counter_, bStop_){ if(counter_ > 3){ divClearImage(this.priDivID); divClearImage(this.secDivID); divInsertImage(this.priDivID, "", this.imgID, this.imgpath); divSetAlpha(this.priDivID, 100); divSetAlpha(this.secDivID, 0); return false; } divSetAlpha(this.secDivID, counter(0, 100, 3, counter_)); divSetAlpha(this.priDivID, counter(100, 0, 3, counter_)); return true; } this.$hide = function(counter_, bStop_){ if(counter_ > 5){return false;} divSetAlpha(this.priDivID, counter(100, 0, 3, counter_)); return true; } this.$show = function(counter_, bStop_){ if(counter_ > 5){return false;} divSetAlpha(this.priDivID, counter(0, 100, 3, counter_)); return true; } this.$quake = function(counter_, bStop_){ if(counter_ > 10){ divSetpos(this.priDivID,0,0); return false; } divSetpos(this.priDivID, (0 == counter_%2)? -10: 10, 0); return true; } this.$zoom = function(counter_, bStop_){ if(counter_ > 8){ divImageZoom(this.imgID, 0); return false; } divImageZoom(this.imgID, counter(0, 20, 8, counter_)); return true; } } /// 単色のフェードを行うレイヤー function SimplefadeLayer(divID_) { this.ansync = new AnSync2; this.divID = divID_; this.hide = function(interval_, doneCB_){ this.stop = function(){}; this.ansync.Start(this.$hide.bind(this), doneCB_, interval_); } this.show = function(color, interval_, doneCB_){ divSetBkColor(this.divID, color); this.stop = function(){}; this.ansync.Start(this.$show.bind(this), doneCB_, interval_); } this.$hide = function(counter_, bStop_){ if(counter_ > 5){return false;} divSetAlpha(this.divID, counter(100, 0, 5, counter_)); return true; } this.$show = function(counter_, bStop_){ if(counter_ > 5){return false;} divSetAlpha(this.divID, counter(0, 100, 5, counter_)); return true; } } function ImgLayer(priImgID_, secImgID_) { this.ansync = new AnSync2; this.priImgID = priImgID_; this.secImgID = secImgID_; this.x = 0; this.y = 0; this.imgpath = ""; this.init = function(src_, x_, y_, opacity_){ this.x = x_; this.y = y_; imageSet(this.priImgID, src_, this.x, this.y); divSetAlpha(this.priImgID, opacity_); } this.fade = function(imgpath_, x_, y_, interval_, doneCB_){ this.imgpath = imgpath_; this.x = x_; this.y = y_; this.stop = function(){this.ansync.Stop();} imageSet(this.secImgID, imgpath_, x_, y_); this.ansync.Start(this.$fade.bind(this), doneCB_, interval_); } this.hide = function(interval_, doneCB_){ this.stop = function(){}; this.ansync.Start(this.$hide.bind(this), doneCB_, interval_); } this.show = function(interval_, doneCB_){ this.stop = function(){}; this.ansync.Start(this.$show.bind(this), doneCB_, interval_); } this.zoom = function(interval_, doneCB_){ this.stop = function(){}; this.ansync.Start(this.$zoom.bind(this), doneCB_, interval_); } this.quake = function(interval_, doneCB_){ this.stop = function(){this.ansync.Stop();} this.ansync.Start(this.$quake.bind(this), doneCB_, interval_); } this.raster = function(interval_, doneCB_){ } this.$fade = function(counter_, bStop_){ if(counter_ > 3){ imageSet(this.priImgID, this.imgpath, this.x, this.y); divSetAlpha(this.priImgID, 100); divSetAlpha(this.secImgID, 0); return false; } divSetAlpha(this.secImgID, counter(0, 100, 3, counter_)); var Obj = document.getElementById( this.priImgID ); divSetAlpha(this.priImgID, counter(100, 0, 3, counter_)); return true; } this.$hide = function(counter_, bStop_){ if(counter_ > 3){return false;} divSetAlpha(this.priImgID, counter(100, 0, 3, counter_)); return true; } this.$show = function(counter_, bStop_){ if(counter_ > 3){return false;} divSetAlpha(this.priDImgID, counter(0, 100, 3, counter_)); return true; } this.$quake = function(counter_, bStop_){ if(counter_ > 10){ imagePos(this.priImgID,0,0); return false; } imagePos(this.priImgID, (0 == counter_%2)? -10: 10, 0); return true; } this.$zoom = function(counter_, bStop_){ if(counter_ > 8){ imageZoom(this.priImgID, this.x, this.y, 0); return false; } imageZoom(this.priImgID, this.x, this.y, counter(0, 20, 8, counter_)); return true; } }