日期:2014-05-16  浏览次数:20465 次

网页看板娘 js版(论坛娘、博客娘。总之就是梦娘 V (-1) 代码
/**
 * ukagaka.js
 * @author Star
 */
 if(typeof(Kangbang) == 'undefined')
     var Kangbang = {};
     var Ukagaka = null;
	 Kangbang.ukagaka = function(){
	 	this.msgList = []; //可用的消息列表
		this.shellList = [];//可用的shell列表
		this.msgIndex = 0; //当前消息索引
		this.shellIndex = 0;//当前shell索引
		this.ghostName = "";//当前人格名称
		this.msgBox = ""; // 语言输出位置,默认为div
		this.shell = "";  // 默认的ukagaka图像显示位置,默认为img元素
		this.config = ""; // ukagaka的配置信息,使用 HashTable初始化
		this.somagicShell = "";
		this.somagicMsg = "";
		this.somagicMsgBox = "";
		this.timer = null;
		this.timerFlag = false;
	 };
	 
	 Kangbang.ukagaka.prototype = {
	 	
		setGhostName : function( name){this.ghostName = name; },
		getGhostName : function(){ return this.ghostName; },
		setMsgList : function(msgs){ this.msgList = msgs; },
		setShellList : function(shells){ this.shellList = shells; },
        setShell : function(img){this.shell = img; },
		setMsgBox : function(div){this.msgBox = div; },
		setSomagicShell : function(div){ this.somagicShell = div; },
		setSomagicMsgBox : function(div){ this.somagicMsgBox = div;	}, // 整个对话框
		setSomagicMsg : function(div){ this.somagicMsg = div; },    //显示对话的部分
		getConfig : function(){	return this.config;	},
		
		hiddenSomagicMsgBox : function(){ Kit.hidden(this.somagicMsgBox);},
		showSomagicMsgBox : function(){Kit.show(this.somagicMsgBox); this.showSomagic();},
		hiddenSomagic : function(){ Kit.hidden(this.somagicShell);  /*this.hiddenSomagicMsgBox()*/},
		showSomagic  : function(){Kit.show(this.somagicShell);},
		stopTimer : function(){ if(this.timer ==null) return ;this.timerFlag = false;clearTimeout(this.timer)},
		
		setConfig : function(cfg){  // 后台取得服务器配置文件之后调用
			this.config = cfg;	
			this.shellList = cfg.get("#shell").split(",");
			this.msgList = cfg.get("#msg").split("\\w");
			this.ghostName = cfg.get("#ghost");
			this.createCode();
		},
		createCode : function(){  // 动态创建js属性或方法
			var codes = this.config.get("#jsCode").split("\[code\]");
			for (var i = 0; i < codes.length; i++) {
				//alert(codes[i]);
				eval(codes[i]);
			}
			
		},
		init : function(){    //前台页面加载完成后调用,sonotori,前台个很据自己情况手动控制
			//this.showMenu();
//			this.hello = function(){
//		 	alert("Hello!");
//		 };
		},
		showMenu : function(){  // 显示系统菜单,显示位置为对话框
		    //alert(this.config.get("#menu"));
			this.stopTimer();
			this.msgBox.innerHTML = this.config.get("#menu");
		},
		sayNext  : function(){ //简单的按照顺序显示下一列对话。 用于自我吐槽
			if(this.msgIndex >= this.msgList.length) this.msgIndex = 0;
			this.msgBox.innerHTML = this.msgList[this.msgIndex ++].split("\\c")[0];
			Kit.element("outPutDialog").innerHTML = this.msgBox.innerHTML + "<br/>";
		},
		sayToIndex : function(index){ // 控制吐槽顺序
			if(index > this.msgList.length) index = this.msgList.length;
			if(index < 0) index = 0;
			this.msgBox.innerHTML = this.msgList[index].split("\\s")[0];
		},
		
		shellNext : function(){ // 按照外壳顺序切换外形
			if(this.shellIndex >= this.shellList.length) this.shellIndex = 0;
			this.shell.src = this.shellList[this.shellIndex ++];
		},
		shellToIndex : function(index){ //控制外壳显示顺序
			if(index > this.shellList.length) index = this.shellList.length;
			if(index < 0) index = 0;
			this.shell.src = this.shellList[index];
		},
		shellOnce : function(index /* */ , time /* */){ //控制显示顺序并在time之后恢复默认
			this.shellToIndex(index);
			setTimeout(function(){Ukagaka.shellToIndex(0);} , time);
		},
		tsukkomi : function(){    //自己吐
			if(this.msgList.length <= 0) return;
			this.sayNext();
			this.timer = setTimeout(function(){Ukagaka.tsukkomi();} , 10 * 1000);
		},
		tsukkomiSomagic : function(){   // 一起吐
			if(this.msgList.length <= 0) return;
			if(this.msgIndex >= this.msgList.length) this.msgIndex = 0;
			this.timer = setTimeout(function(){Ukagaka.tsukkomiSomagic();} , 10 * 1000);
			var arr = this.msgList[this.msgIndex ++ ].split("\\c");
			this.msgBox.innerHTML = arr[0];
			this