/* ユーザーJS ---------------------------------------------*/ function focusColor(i){ i.style.backgroundColor='#fffcdb'; } function blurColor(i){ i.style.backgroundColor='#ffffff'; } /** * 指定したタグ内のaタグのhrefが動作する際、指定したタグをアニメーションさせ、終了後hrefに遷移する。 * ※onclickには適用しません。 */ function SlideMenu() { this.initialize.apply(this, arguments); } SlideMenu.durationTime = 1000;//スライドアニメーション継続時間(ms)※WebKit系のみ SlideMenu.prototype = { /** * コンストラクタ * @param moveId [in] 移動アニメーション付加対象タグID * @param menuId [in] アニメーション起動用Aタグを含むタグID * @param direction [in] 移動方向(1:右/-1左) */ initialize:function(moveId, menuId, direction) { var obj = document.getElementById(moveId); var menuObj = document.getElementById(menuId); if(obj == undefined || menuObj == undefined || (direction!=1&&direction!=-1) || !this.isCanTrans(moveId) ) { return; } var myObj = this; this.moveId = moveId; this.direction = direction; this.baseObj = document.createElement('div'); this.baseObj.style.margin = '0'; this.baseObj.style.padding = '0'; this.baseObj.style.border = ''; this.baseObj.style.position='relative'; this.baseObj.style.width='100%'; this.baseObj.style.height='100%'; this.scrollObj = document.createElement('div'); this.scrollObj.style.margin = '0'; this.scrollObj.style.padding = '0'; this.scrollObj.style.border = ''; this.scrollObj.style.position='relative'; this.scrollObj.style.width='100%'; this.scrollObj.style.height='100%'; while(obj.firstChild) { this.scrollObj.appendChild(obj.removeChild(obj.firstChild)); } obj.appendChild(this.baseObj); this.baseObj.appendChild(this.scrollObj); this.baseObj.style.overflow = 'hidden'; this.setTransform(this.scrollObj, "translate3d(0px, 0px, 0px)"); if(menuObj.tagName == 'A') { this._set(menuObj); } else { var menuList = menuObj.getElementsByTagName('a'); for(i = 0; i < menuList.length; i++) { this._set(menuList[i]); } } } ,_set:function(obj) { var myObj = this; if(obj.onclick=='' || obj.onclick==undefined) { if(obj.getAttribute('href').indexOf("#")!=0) { obj.setAttribute('SlideMenuId', this.moveId); obj.setAttribute('SlideMenuHref', obj.href); obj.onclick=function() { myObj.moveStart(this.getAttribute('SlideMenuHref')); this.href = 'javascript:void(0);'; return false; }; } } } , moveStart:function(url) { this.setTransition(this.scrollObj, "all "+(SlideMenu.durationTime/1000)+"s cubic-bezier(0.8, 0, 1.0, 1.0)"); this.setTransform(this.scrollObj, "translate3d("+(this.baseObj.offsetWidth*this.direction)+"px, 0px, 0px)"); setTimeout( function() { window.location.href = url; } ,SlideMenu.durationTime); } , resetLeft:function() { if(this.isCanTrans(this.moveId)) { this.setTransform(this.scrollObj, "translate3d(0px, 0px, 0px)"); } } , setTransition:function(obj, value) { if(obj.style.transition != undefined) { obj.style.transition = value; } if(obj.style.webkitTransition != undefined) { obj.style.webkitTransition = value; } if(obj.style.MozTransition != undefined) { obj.style.MozTransition = value; } if(obj.style.OTransition != undefined) { obj.style.OTransition = value; } if(obj.style.msTransition != undefined) { obj.style.msTransition = value; } } , setTransform:function(obj, value) { if(obj.style.transform != undefined) { obj.style.transform = value; } if(obj.style.webkitTransform != undefined) { obj.style.webkitTransform = value; } if(obj.style.MozTransform != undefined) { obj.style.MozTransform = value; } if(obj.style.OTransform != undefined) { obj.style.OTransform = value; } if(obj.style.msTransform != undefined) { obj.style.msTransform = value; } } , getTransform:function(obj) { if(obj.style.transform != undefined) { return obj.style.transform; } if(obj.style.webkitTransform != undefined) { return obj.style.webkitTransform; } if(obj.style.MozTransform != undefined) { return obj.style.MozTransform; } if(obj.style.OTransform != undefined) { return obj.style.OTransform; } if(obj.style.msTransform != undefined) { return obj.style.msTransform; } return null; } , isCanTrans:function(target) { var obj = document.getElementById(target); if( (obj.style.transition != undefined && obj.style.transform != undefined) || (obj.style.webkitTransition != undefined && obj.style.webkitTransform != undefined) || (obj.style.MozTransition != undefined && obj.style.MozTransform != undefined) || (obj.style.OTransition != undefined && obj.style.OTransform != undefined) || (obj.style.msTransition != undefined && obj.style.msTransform != undefined) ) { this.setTransform(obj, "translate3d(0px, 0px, 0px)"); var tmp = this.getTransform(obj); return(tmp && tmp.length > 0); } else { return false; } } } /** * 指定したタグを縦スクロールメニューにする。 */ function ScrollMenu() { this.initialize.apply(this, arguments); } ScrollMenu.durationTime = 750;//スクロールアニメーション継続時間(ms) ScrollMenu.keyActionTime = 100;//リンク選択時入力判定時間(ms) ScrollMenu.posMargin = 10;//位置変更なしと判断する遊びサイズ(px) ScrollMenu.objList = new Array(); ScrollMenu.lastEventList = new Array(); ScrollMenu.prototype = { /** * コンストラクタ * @param target [in] 対象ID * @param height [in] スクロールエリアの高さ(px)(0で画面の高さに合わせる) * @param revise [in] 高さの補正(px)(height=0時に指定サイズを加える) */ initialize:function(target, height, revise) { var obj = document.getElementById(target); if(obj == undefined) { return; } this.target = target; this.isDrag = false; this.basePos = 0; this.startPos = 0; this.baseTime = (new Date()).getTime(); this.startTime = this.baseTime; this.nowPos = 0; this.tagLinkList = new Array(); this.revise = revise; this.isDefaultHeight = (height==0); this.selectMenuId = 0; if(height==0) { height = this.getHeight() + this.revise; } this.baseHeight = obj.clientHeight; this.dispHeight = height; obj.style.height = this.dispHeight+'px'; this.baseObj = document.createElement('div'); this.baseObj.style.margin = '0'; this.baseObj.style.padding = '0'; this.baseObj.style.border = ''; this.baseObj.style.position='relative'; this.baseObj.style.width='100%'; this.baseObj.style.height='100%'; this.baseObj.style.top = '0px'; this.scrollObj = document.createElement('div'); this.scrollObj.style.margin = '0'; this.scrollObj.style.padding = '0'; this.scrollObj.style.border = ''; this.scrollObj.style.position='relative'; this.scrollObj.style.width='100%'; this.scrollObj.style.height=Math.max(this.baseHeight, height)+'px'; this.scrollObj.style.top = '0px'; this.dummyObj = document.createElement('input'); this.dummyObj.type='button'; this.dummyObj.style.display='none'; this.scrollObj.appendChild(this.dummyObj); while(obj.firstChild) { this.scrollObj.appendChild(obj.removeChild(obj.firstChild)); } obj.appendChild(this.baseObj); this.baseObj.appendChild(this.scrollObj); if(this.isCanTrans(this.baseObj)) { obj.style.overflow = 'hidden'; this.setTransition(this.scrollObj, ""); this.setTransform(this.scrollObj, "translate3d(0px, 0px, 0px)"); var myObj = this; obj.onmousedown=function(e) { return myObj.start(e); }; obj.ontouchstart=function(e) { if(e.touches.length==1) { ScrollMenu.lastEventList[myObj.target] = e; return myObj.start(e); } return true; }; ScrollMenu.objList[this.target] = myObj; var scrollMenuId = 1; var elements = this.baseObj.getElementsByTagName('A'); for(var cnt = 0; cnt < elements.length; cnt++) { var obj = elements[cnt]; this.tagLinkList[scrollMenuId] = {'href': elements[cnt].getAttribute('href'), 'click':elements[cnt].onclick, 'obj':elements[cnt]}; elements[cnt].onclick = function() {return false}; elements[cnt].setAttribute('ScrollMenuId',scrollMenuId); scrollMenuId++; } var elements = this.baseObj.getElementsByTagName('SELECT'); for(var cnt = 0; cnt < elements.length; cnt++) { if(elements[cnt].onchange) { elements[cnt].orgOnChange = elements[cnt].onchange; } elements[cnt].onchange=function(e) { setTimeout( function() { myObj.dummyObj.style.display=''; myObj.dummyObj.focus(); myObj.dummyObj.style.display='none'; } , 0 ); if(this.orgOnChange) { this.orgOnChange(e); } } } } else { obj.style.overflow = 'scroll'; } } , getHeight:function() { var height = 0; if(document.documentElement.clientWidth) { height = document.documentElement.clientHeight; } else if(document.body.clientWidth){ height = document.body.clientHeight; } else { height = window.innerHeight; } return height; } , start:function(eObj) { var e = (eObj.touches?eObj.touches[0]:eObj); this.isDrag = true; this.baseTime = (new Date()).getTime(); this.startTime = this.baseTime; this.basePos = e.pageY; this.startPos = e.pageY; if(typeof(this.scrollObj.getBoundingClientRect) === 'function') { this.nowPos = this.scrollObj.getBoundingClientRect().top - this.baseObj.getBoundingClientRect().top; } this.setTransition(this.scrollObj, ""); this.setTransform(this.scrollObj, "translate3d(0px, "+this.nowPos+"px, 0px)"); if(eObj.target.tagName == 'A') { this.selectMenuId = eObj.target.getAttribute('ScrollMenuId'); return false; } else { var tmpNode = eObj.target; while(tmpNode = tmpNode.parentNode) { if(tmpNode.tagName == 'A') { this.selectMenuId = tmpNode.getAttribute('ScrollMenuId'); return false; } } } if(eObj.target.tagName == 'INPUT' || eObj.target.tagName == 'TEXTAREA') { this.isDrag = false; return true; } if(eObj.target.tagName == 'SELECT') { this.isDrag = false; this.selectTmp = eObj.target; return true; } if(this.selectTmp) { this.dummyObj.style.display=''; this.dummyObj.focus(); this.dummyObj.style.display='none'; } return false; } , end:function(eObj) { var e = (eObj.touches?eObj.touches[0]:eObj); if(this.isDrag) { this.isDrag = false; var nowTime = (new Date()).getTime(); var diffTime = nowTime - this.baseTime; var diffPos = (e.pageY-this.basePos); if(diffTime > 0) { this.nowPos += Math.round(diffPos*750/diffTime); } this.baseTime = nowTime; var isRevise = false; var preNowPos = this.nowPos; if(this.nowPos > 0) { this.nowPos = 0; isRevise = true; } else if(this.nowPos != 0 && this.nowPos+this.baseHeight < this.dispHeight) { if(this.baseHeight < this.dispHeight) { this.nowPos = 0; } else { this.nowPos = this.dispHeight-this.baseHeight; } isRevise = true; } if(isRevise && Math.abs(this.nowPos - preNowPos < ScrollMenu.posMargin) && preNowPos < ScrollMenu.posMargin) { isRevise = false; } this.basePos = e.pageY; if(Math.abs(this.startPos - this.basePos) < ScrollMenu.posMargin && !isRevise) { if((nowTime-this.startTime) > ScrollMenu.keyActionTime) { if(this.selectMenuId > 0) { if(this.tagLinkList[this.selectMenuId]) { if(this.tagLinkList[this.selectMenuId]['click'] && this.tagLinkList[this.selectMenuId]['click'] != '') { this.tagLinkList[this.selectMenuId]['obj'].onclick = this.tagLinkList[this.selectMenuId]['click']; this.tagLinkList[this.selectMenuId]['obj'].onclick(); this.tagLinkList[this.selectMenuId]['obj'].onclick = function(){return false;}; } else if(this.tagLinkList[this.selectMenuId]['href'] && this.tagLinkList[this.selectMenuId]['href'] != '') { if(String(this.tagLinkList[this.selectMenuId]['href']).indexOf("#")==0) { this.nowPos = 0; this.setTransition(this.scrollObj, "all "+(ScrollMenu.durationTime/1000)+"s ease-out"); this.setTransform(this.scrollObj, "translate3d(0px, 0px, 0px)"); } else { window.location = this.tagLinkList[this.selectMenuId]['href']; } } } this.selectMenuId = 0; } } } else { this.setTransition(this.scrollObj, "all "+(ScrollMenu.durationTime/1000)+"s ease-out"); this.setTransform(this.scrollObj, "translate3d(0px, "+this.nowPos+"px, 0px)"); } return false; } return true; } , move:function(eObj) { var e = (eObj.touches?eObj.touches[0]:eObj); if(this.isDrag) { var timeTmp = (new Date()).getTime(); var newPos = this.nowPos + (e.pageY-this.basePos); if((timeTmp - this.baseTime) > 200) { this.baseTime = timeTmp; this.nowPos = newPos; this.basePos = e.pageY; } this.setTransition(this.scrollObj, ""); this.setTransform(this.scrollObj, "translate3d(0px, "+newPos+"px, 0px)"); return false; } return true; } , rotate:function() { if(this.isDefaultHeight) { var obj = document.getElementById(this.target); this.dispHeight = this.getHeight()+this.revise; obj.style.height = this.dispHeight+'px'; var isRevise = false; if(this.nowPos > 0) { this.nowPos = 0; isRevise = true; } else if(this.nowPos+this.baseHeight < this.dispHeight) { if(this.baseHeight < this.dispHeight) { this.nowPos = 0; } else { this.nowPos = this.dispHeight-this.baseHeight; } isRevise = true; } this.setTransition(this.scrollObj, "all "+(ScrollMenu.durationTime/1000)+"s ease-out"); this.setTransform(this.scrollObj, "translate3d(0px, "+this.nowPos+"px, 0px)"); } return false; } , setTransition:function(obj, value) { if(obj.style.transition != undefined) { obj.style.transition = value; } if(obj.style.webkitTransition != undefined) { obj.style.webkitTransition = value; } if(obj.style.MozTransition != undefined) { obj.style.MozTransition = value; } if(obj.style.OTransition != undefined) { obj.style.OTransition = value; } if(obj.style.msTransition != undefined) { obj.style.msTransition = value; } } , setTransform:function(obj, value) { if(obj.style.transform != undefined) { obj.style.transform = value; } if(obj.style.webkitTransform != undefined) { obj.style.webkitTransform = value; } if(obj.style.MozTransform != undefined) { obj.style.MozTransform = value; } if(obj.style.OTransform != undefined) { obj.style.OTransform = value; } if(obj.style.msTransform != undefined) { obj.style.msTransform = value; } } , getTransform:function(obj) { if(obj.style.transform != undefined) { return obj.style.transform; } if(obj.style.webkitTransform != undefined) { return obj.style.webkitTransform; } if(obj.style.MozTransform != undefined) { return obj.style.MozTransform; } if(obj.style.OTransform != undefined) { return obj.style.OTransform; } if(obj.style.msTransform != undefined) { return obj.style.msTransform; } return null; } , isCanTrans:function(obj) { if( (obj.style.transition != undefined && obj.style.transform != undefined) || (obj.style.webkitTransition != undefined && obj.style.webkitTransform != undefined) || (obj.style.MozTransition != undefined && obj.style.MozTransform != undefined) || (obj.style.OTransition != undefined && obj.style.OTransform != undefined) || (obj.style.msTransition != undefined && obj.style.msTransform != undefined) ) { this.setTransform(obj, "translate3d(0px, 0px, 0px)"); var tmp = this.getTransform(obj); return(tmp && tmp.length > 0); } else { return false; } } } window.document.onmousemove=function(e){ var ret = true; for(var key in ScrollMenu.objList) { ret &= ScrollMenu.objList[key].move(e); } return ret; } window.document.onmouseup=function(e){ var ret = true; for(var key in ScrollMenu.objList) { ret &= ScrollMenu.objList[key].end(e); } return ret; } window.document.ontouchmove=function(e){ var ret = true; if(e.touches.length==1) { for(var key in ScrollMenu.objList) { ScrollMenu.lastEventList[key] = e; ret &= ScrollMenu.objList[key].move(e); } } return ret; } window.document.ontouchend=function(e){ var ret = true; for(var key in ScrollMenu.objList) { if(ScrollMenu.lastEventList[key]) { ret &= ScrollMenu.objList[key].end(ScrollMenu.lastEventList[key]); } } return ret; } window.onresize=function() { for(var key in ScrollMenu.objList) { ScrollMenu.objList[key].rotate(); } } window.onorientationchange=function() { for(var key in ScrollMenu.objList) { ScrollMenu.objList[key].rotate(); } }