'+
'
';
YourbrainYesnoBP.tpls.explain=
'
'+
'
'+
'
';
YourbrainYesnoBP.tpls.qanda=
'
'+
'
'+
'
';
YourbrainYesnoBP.tpls.result= '
'+
'
'+
'

';
YourbrainYesnoBP.tm=0;
YourbrainYesnoBP.divs={};
YourbrainYesnoBP.divs.container=null;
YourbrainYesnoBP.divs.content=null;
YourbrainYesnoBP.divs.explain=null;
YourbrainYesnoBP.js=null;
YourbrainYesnoBP.explainInterval=4000; // 説明の表示切り替えのインターバル
YourbrainYesnoBP.explains=new Array(); // 説明一覧
YourbrainYesnoBP.explainId=0; // 表示中の説明番号
YourbrainYesnoBP.quizs=[]; // 取得済みクイズ キャッシュファイル
YourbrainYesnoBP.quizId=0; // 表示中クイズ番号
YourbrainYesnoBP.quizAnswers=new Array(); //回答番号一覧
/****
開始
****/
YourbrainYesnoBP.Init=function(){
this.U.SetXmlns();
var id='';
while(1){
id=this.U.R(6,'');
if(window[id]===undefined && !document.getElementById(id))
break;
}
this.tpls.container=this.tpls.container.replace(/%baseurl%/g, this.urls.baseurl).replace(/%id%/g, id);
this.tpls.explain=this.tpls.explain.replace(/%baseurl%/g, this.urls.baseurl);
this.tpls.qanda=this.tpls.qanda.replace(/%baseurl%/g, this.urls.baseurl);
this.tpls.result=this.tpls.result.replace(/%baseurl%/g, this.urls.baseurl);
if(this.U.isXml){
var div=this.U.CreateElement('div');
div.innerHTML=this.tpls.container;
this.divs.container=div.firstChild;
div=null;
// IEはXMLでの表示ができないため、ここを通過しない
if(window.addEventListener){
window.addEventListener('load',function(){
var scrs=document.getElementsByTagName('script');
for(var i=0;i
");
}
delete id;
return true;
};//Init
/****
イニシャライズ続き
****/
YourbrainYesnoBP.Init2=function(){
this.divs.container.id='';
this.divs.content=this.U.GetInnerElement(this.divs.container, 'content');
/* starting */
this.divs.content.innerHTML=this.tpls.explain;
this.divs.explain=this.U.GetInnerElement(this.divs.container, 'explain');
this.U.SetDefaultStyles(this.divs.container);
this.SetDefaultStyles();
//explain.jsからthis.Loadedを実行する
this.js=this.U.CreateScript(this.urls.baseurl+'explain.js');
};//Init2
/****
Restart
Explainを表示するだけ
****/
YourbrainYesnoBP.Restart=function(){
this.divs.content.innerHTML=this.tpls.explain;
this.divs.explain=this.U.GetInnerElement(this.divs.container, 'explain');
this.SetDefaultStyles();
this.explainId=0;
this.Explain();
return true;
};//Restart
/****
JSONPで読み込んだ説明書きの表示
タイマーにより1セットずつ表示する。
****/
YourbrainYesnoBP.Explain=function(){
this.divs.explain.innerHTML=this.explains[this.explainId];
this.SetDefaultStyles();
this.explainId++;
if(this.explainId>=this.explains.length)
this.explainId=0;
this.tm=setTimeout(function(){YourbrainYesnoBP.Explain();}, this.explainInterval);
return true;
};//Explain
/****
開始ボタン、リスタートボタン押下
****/
YourbrainYesnoBP.Start=function(){
if(this.tm)
this.tm=clearTimeout(this.tm);
this.explainId=0
this.quizId=0;
this.quizAnswers=new Array();
this.quizs=new Array();
this.divs.content.innerHTML=this.tpls.qanda.replace(/%question%/, this.tpls.loading).replace(/%answeryes%/,'').replace(/%answerno%/,'');
this.SetDefaultStyles();
this.RemoveOldQuiz();
//quiz.jsからthis.Quizを実行する。
this.GetNextquiz();
return this;
};//Start
/****
JSONP call
クイズと選択肢を表示
****/
YourbrainYesnoBP.Quiz=function(qs){
if(this.tm)
this.tm=clearTimeout(this.tm);
this.quizId++;
this.quizs.push(qs);
switch(qs[0]){
case 'x': // 説明
for(var i=1;i
ancher内のimgをswap-image
flg=1: img.src に'_'を追加 ex) image.gif -> image_.gif
flg=0: restore
****/
YourbrainYesnoBP.Swap=function(elm, flg){
var img=elm.firstChild;
while(img && img.nodeType!=1)
img=img.nextSibling;
if(!img)
return false;
var src=img.src;
src=(flg)?src.replace(/(\.\w+)$/, "_$1"):src.replace(/_(\.\w+)$/, "$1");
img.src=src;
return true;
};//Swap
/****
flg=1: background-positionを移動
flg=0: restore
****/
YourbrainYesnoBP.SwapBG=function(elm, flg){
if(!elm.style)
return false;
var height=parseInt(this.U.GetStyle(elm, 'height'));
if(height==NaN)
height=0;
height=-(+flg) * height;
elm.style.backgroundPosition='0px '+height+'px';
return true;
};//SwapBG
/*****/
YourbrainYesnoBP.U={
xmlns:''
,isXml:false
};//U
/****
ランダムな文字列を生成
****/
YourbrainYesnoBP.U.R=function(cnt, s){
for(var i=cnt,s='',r;i;i--){
s+=String.fromCharCode('a'.charCodeAt(0)+Math.random()*26);
}
return s;
};//R
/****
スクリプト要素を作成、ドキュメントに追加
****/
YourbrainYesnoBP.U.CreateScript=function(src){
if(!src||src=='')
return false;
var sc=this.CreateElement('script');
if(!sc)
return false;
if(this.isXml)
this.SetAttribute(sc, 'type', 'application/x-javascript');
else
this.SetAttribute(sc, 'type', 'text/javascript');
this.SetAttribute(sc, 'charset', 'utf-8');
this.SetAttribute(sc, 'src', src);
var hd=document.getElementsByTagName('head');
if(hd)
hd=hd.item?hd.item(0)||hd[0]:hd[0];
else
hd=document.body||document.documentElement;
if(hd)
hd.insertBefore(sc, null);
else if(document.insertBefore)
document.insertBefore(sc, null);
return sc;
};//CreateScript
/*****/
/****
Firefox