ぱどタウンでprototype.js
少し前に、ぱどタウンの部屋ページにJSONで部屋の情報をいくつか埋め込んでみたに書いた通り部屋の情報をJavaScriptで参照できるようにしたのですが、追加でタウンのリスト(33タウン)も入れた。
prototype.jsも読み込んでいるので、ぱど厨なHackもエレガントに行えます。たぶん。
ためしにprototype.jsの勉強もかねて、自分でぱどタウンの中でよく見かけるショートカット集をつくってみた。
<div id="townselecter"></div>
<script>
var TownPageArray=[
{'page':'townoffice/','name':'住民センター'},
{'page':'helicopter/','name':'へリポート'},
{'page':'shop/','name':'ショップ街'},
{'page':'hiroba/','name':'コンテンツ広場'},
{'page':'map.cgi','name':'MAP'}
];
var TownSelecter = Class.create();
TownSelecter.prototype={
initialize: function(divid){
this.divele=$(divid);
this.t_select = document.createElement('select');
for(var i=0;i<PadoTownArray.length;i++){
var isselected=(RoomJObj.town == PadoTownArray[i].town) ? true : false;
this.t_select.options[this.t_select.options.length]
= new Option(PadoTownArray[i].town_name,PadoTownArray[i].town,false,isselected);
}
this.divele.appendChild(this.t_select);
this.p_select = document.createElement('select');
for(var i=0;i<TownPageArray.length;i++){
this.p_select.options[this.p_select.options.length]
= new Option(TownPageArray[i].name,TownPageArray[i].page,false,false);
}
this.divele.appendChild(this.p_select);
this.g_button = document.createElement('input');
this.g_button.type="button";
this.g_button.value="GO!";
this.divele.appendChild(this.g_button);
Event.observe(this.g_button,'click',this.t_onclick.bindAsEventListener(this), false);
},
t_onclick:function () {
var selected_town=$F(this.t_select);
var selected_page=$F(this.p_select);
top.document.location.href="http://"+ selected_town+".padotown.net/"+selected_page;
}
};
new TownSelecter('townselecter');
</script>
PadoTownArrayはタウンのリスト、RoomJObjは部屋の情報
ずいぶんわかりやすくなっていいですね、prototype.js。
いままでのJavaScriptを全部書き直してみたくなる罠にはまりそうです。
コメント
友達に進められたので
投稿者: 高田浩司 | 2005年10月17日 14:51
五年生です友達がやってるのを見たらすっげーおもしろかった
投稿者: 健成 | 2005年10月17日 15:00
友達がおしえてくれたけど、どうログインするのかがわからない
投稿者: 遼太郎 | 2006年01月08日 02:40