/* FWDMComplexButton */ (function (){ var FWDMComplexButton = function( n1Img, s1Img, n2Img, s2Img, disptachMainEvent_bl, vector1, vector2, vectorClass1N, vectorCalss1S, vectorClass2N, vectorClass2S ){ var _s = this; var prototype = FWDMComplexButton.prototype; _s.n1Img = n1Img; _s.s1Img = s1Img; _s.n2Img = n2Img; _s.s2Img = s2Img; _s.firstButton_do; _s.n1_do; _s.s1_do; _s.secondButton_do; _s.n2_do; _s.s2_do; if(n1Img){ _s.buttonWidth = _s.n1Img.width; _s.buttonHeight = _s.n1Img.height; } _s.currentState = 1; _s.isDisabled_bl = false; _s.isMaximized_bl = false; _s.disptachMainEvent_bl = disptachMainEvent_bl; _s.isMobile_bl = FWDMUtils.isMobile; _s.hasPointerEvent_bl = FWDMUtils.hasPointerEvent; //##########################################// /* initialize _s */ //##########################################// _s.init = function(){ _s.setButtonMode(true); _s.setWidth(_s.buttonWidth); _s.setHeight(_s.buttonHeight); _s.setupMainContainers(); _s.secondButton_do.setVisible(false); }; //##########################################// /* setup main containers */ //##########################################// _s.setupMainContainers = function(){ _s.firstButton_do = new FWDMDisplayObject("div"); _s.addChild(_s.firstButton_do); _s.secondButton_do = new FWDMDisplayObject("div"); _s.addChild(_s.secondButton_do); if(vector1){ _s.dumy_do = new FWDMDisplayObject('div'); _s.dumy_do.getStyle().width = '100%'; _s.dumy_do.getStyle().height = '100%'; _s.addChild(_s.dumy_do); _s.isSkin1 = vectorClass1N.indexOf('skin1'); // First button. _s.setOverflow('visible'); _s.firstButton_do.setOverflow('visible'); _s.n1_do = new FWDMDisplayObject("div"); _s.n1_do.getStyle().lineHeight = 0; _s.m_cnt = new FWDMDisplayObject("div",'relative'); _s.m_cnt.setOverflow('visible'); _s.m_cnt.getStyle().boxSizing = 'border-box'; _s.m_cnt.getStyle().lineHeight = 0; _s.vectCnt_do = new FWDMDisplayObject('div', 'relative'); _s.vectCnt_do.getStyle().lineHeight = 0; _s.vectCnt_do.getStyle().display = 'flex'; _s.vectCnt_do.getStyle().alignItems = 'center'; _s.vectCnt_do.getStyle().justifyContent = 'center'; _s.vctIcn_do = new FWDMDisplayObject('div', 'relative'); _s.vctIcn_do.getStyle().lineHeight = 0; _s.vctIcn_do.setInnerHTML(vector1); _s.n1_do.addChild(_s.m_cnt); _s.m_cnt.addChild(_s.vectCnt_do); _s.vectCnt_do.addChild(_s.vctIcn_do); _s.firstButton_do.addChild(_s.n1_do); // Second button. _s.secondButton_do.setOverflow('visible'); _s.n2_do = new FWDMDisplayObject("div"); _s.n2_do.getStyle().lineHeight = 0; _s.m_cnt2 = new FWDMDisplayObject("div",'relative'); _s.m_cnt2.setOverflow('visible'); _s.m_cnt2.getStyle().boxSizing = 'border-box'; _s.m_cnt2.getStyle().lineHeight = 0; _s.vectCnt2_do = new FWDMDisplayObject('div', 'relative'); _s.vectCnt2_do.getStyle().lineHeight = 0; _s.vectCnt2_do.getStyle().display = 'flex'; _s.vectCnt2_do.getStyle().alignItems = 'center'; _s.vectCnt2_do.getStyle().justifyContent = 'center'; _s.vctIcn2_do = new FWDMDisplayObject('div', 'relative'); _s.vctIcn2_do.getStyle().lineHeight = 0; _s.vctIcn2_do.setInnerHTML(vector2); _s.n2_do.addChild(_s.m_cnt2); _s.m_cnt2.addChild(_s.vectCnt2_do); _s.vectCnt2_do.addChild(_s.vctIcn2_do); _s.secondButton_do.addChild(_s.n2_do); _s.setNormalState(); _s.setFinalSize(); }else{ _s.n1_do = new FWDMSimpleDisplayObject("img"); _s.n1_do.setScreen(_s.n1Img); _s.s1_do = new FWDMSimpleDisplayObject("img"); _s.s1_do.setScreen(_s.s1Img); _s.s1_do.setAlpha(0); _s.firstButton_do.addChild(_s.n1_do); _s.firstButton_do.addChild(_s.s1_do); _s.firstButton_do.setWidth(_s.n1Img.width); _s.firstButton_do.setHeight(_s.n1Img.height); _s.n2_do = new FWDMSimpleDisplayObject("img"); _s.n2_do.setScreen(_s.n2Img); _s.s2_do = new FWDMSimpleDisplayObject("img"); _s.s2_do.setScreen(_s.s2Img); _s.s2_do.setAlpha(0); _s.secondButton_do.addChild(_s.n2_do); _s.secondButton_do.addChild(_s.s2_do); _s.secondButton_do.setWidth(_s.n2Img.width); _s.secondButton_do.setHeight(_s.n2Img.height); } if(_s.isMobile_bl){ if(_s.hasPointerEvent_bl){ _s.screen.addEventListener("MSPointerDown", _s.onMouseDown); _s.screen.addEventListener("MSPointerUp", _s.onClick); _s.screen.addEventListener("MSPointerOver", _s.onMouseOver); _s.screen.addEventListener("MSPointerOut", _s.onMouseOut); }else{ _s.screen.addEventListener("touchstart", _s.onMouseDown); } }else if(_s.screen.addEventListener){ _s.screen.addEventListener("mouseover", _s.onMouseOver); _s.screen.addEventListener("mouseout", _s.onMouseOut); _s.screen.addEventListener("mousedown", _s.onMouseDown); _s.screen.addEventListener("click", _s.onClick); }else if(_s.screen.attachEvent){ _s.screen.attachEvent("onmouseover", _s.onMouseOver); _s.screen.attachEvent("onmouseout", _s.onMouseOut); _s.screen.attachEvent("onmousedown", _s.onMouseDown); _s.screen.attachEvent("onclick", _s.onClick); } }; _s.checkCount = 0; _s.setFinalSize = function(reset){ if(!_s) return; if(reset){ _s.checkCount = 0; } clearInterval(_s.checkId_int); if(_s.checkCount > 6) return; _s.lastWidth = _s.vectCnt_do.screen.offsetWidth; _s.checkCount +=1; _s.checkId_int = setInterval(function(){ if(!_s) return; _s.setFinalSize(); },100); if(_s.prevWidth == _s.lastWidth || _s.lastWidth == 0) return; _s.setWidth(_s.vectCnt_do.screen.offsetWidth); _s.setHeight(_s.vectCnt_do.screen.offsetHeight); _s.firstButton_do.setWidth(_s.w); _s.firstButton_do.setHeight(_s.h); _s.secondButton_do.setWidth(_s.w); _s.secondButton_do.setHeight(_s.h); _s.n1_do.setWidth(_s.w); _s.n1_do.setHeight(_s.h); _s.n2_do.setWidth(_s.w); _s.n2_do.setHeight(_s.h); _s.buttonWidth = _s.w; _s.buttonHeight = _s.h; _s.totalWidth = _s.w; _s.totalHeight = _s.h; _s.prevWidth = _s.lastWidth; } _s.onMouseOver = function(e, animate){ if(!e.pointerType || e.pointerType == e.MSPOINTER_TYPE_MOUSE){ _s.setSelectedState(true); _s.dispatchEvent(FWDMComplexButton.MOUSE_OVER, {e:e}); } }; _s.onMouseOut = function(e){ if(!e.pointerType || e.pointerType == e.MSPOINTER_TYPE_MOUSE){ _s.setNormalState(true); _s.dispatchEvent(FWDMComplexButton.MOUSE_OUT); } }; _s.onClick = function(e){ if(_s.isDisabled_bl) return; if(e.preventDefault) e.preventDefault(); if(_s.disptachMainEvent_bl) _s.dispatchEvent(FWDMComplexButton.CLICK); }; _s.onMouseDown = function(e){ if(_s.isDisabled_bl) return; if(e.preventDefault) e.preventDefault(); if(!_s.isMobile_bl) _s.onMouseOver(e, false); if(_s.disptachMainEvent_bl) _s.dispatchEvent(FWDMComplexButton.MOUSE_DOWN, {e:e}); }; //##############################// // set select / deselect final. //##############################// _s.setNormalState = function(anim){ if(vector1){ FWDAnimation.killTweensOf(_s.vctIcn_do.screen); FWDAnimation.killTweensOf(_s.vctIcn2_do.screen); if(vectorClass2N){ FWDAnimation.killTweensOf(_s.vectCnt_do.screen); FWDAnimation.killTweensOf(_s.vectCnt2_do.screen); } if(anim){ if(vectorClass2N){ FWDAnimation.to(_s.vectCnt_do.screen, .6, {className:vectorClass2N, ease:Expo.easeOut}); FWDAnimation.to(_s.vectCnt2_do.screen, .6, {className:vectorClass2N, ease:Expo.easeOut}); } FWDAnimation.to(_s.vctIcn_do.screen, .6, {className:vectorClass1N, ease:Expo.easeOut}); FWDAnimation.to(_s.vctIcn2_do.screen, .6, {className:vectorClass1N, ease:Expo.easeOut}); }else{ if(vectorClass2N){ _s.vectCnt_do.screen.className = vectorClass2N; _s.vectCnt2_do.screen.className = vectorClass2N; } _s.vctIcn_do.screen.className = vectorClass1N; _s.vctIcn2_do.screen.className = vectorClass1N; } }else{ FWDAnimation.killTweensOf(_s.s1_do); FWDAnimation.killTweensOf(_s.s2_do); FWDAnimation.to(_s.s1_do, .5, {alpha:0, ease:Expo.easeOut}); FWDAnimation.to(_s.s2_do, .5, {alpha:0, ease:Expo.easeOut}); } } _s.setSelectedState = function(anim){ if(vector1){ FWDAnimation.killTweensOf(_s.vctIcn_do.screen); FWDAnimation.killTweensOf(_s.vctIcn2_do.screen); if(vectorClass2N){ FWDAnimation.killTweensOf(_s.vectCnt_do.screen); FWDAnimation.killTweensOf(_s.vectCnt2_do.screen); } if(anim){ if(vectorClass2S){ FWDAnimation.to(_s.vectCnt_do.screen, .8, {className:vectorClass2S, ease:Expo.easeOut}); FWDAnimation.to(_s.vectCnt2_do.screen, .8, {className:vectorClass2S, ease:Expo.easeOut}); } FWDAnimation.to(_s.vctIcn_do.screen, .8, {className:vectorCalss1S, ease:Expo.easeOut}); FWDAnimation.to(_s.vctIcn2_do.screen, .8, {className:vectorCalss1S, ease:Expo.easeOut}); }else{ if(vectorClass2S){ _s.vectCnt_do.screen.className = vectorClass2S; _s.vectCnt2_do.screen.className = vectorClass2S; } _s.vctIcn_do.screen.className = vectorCalss1S; _s.vctIcn2_do.screen.className = vectorCalss1S; } }else{ FWDAnimation.killTweensOf(_s.s1_do); FWDAnimation.killTweensOf(_s.s2_do); FWDAnimation.to(_s.s1_do, .5, {alpha:1, delay:.1, ease:Expo.easeOut}); FWDAnimation.to(_s.s2_do, .5, {alpha:1, delay:.1, ease:Expo.easeOut}); } } //##############################// /* toggle button */ //#############################// _s.toggleButton = function(){ if(_s.currentState == 1){ _s.firstButton_do.setVisible(false); _s.secondButton_do.setVisible(true); _s.currentState = 0; _s.dispatchEvent(FWDMComplexButton.FIRST_BUTTON_CLICK); }else{ _s.firstButton_do.setVisible(true); _s.secondButton_do.setVisible(false); _s.currentState = 1; _s.dispatchEvent(FWDMComplexButton.SECOND_BUTTON_CLICK); } }; //##############################// /* set second buttons state */ //##############################// _s.setButtonState = function(state){ if(state == 1){ _s.firstButton_do.setVisible(true); _s.secondButton_do.setVisible(false); _s.currentState = 1; }else{ _s.firstButton_do.setVisible(false); _s.secondButton_do.setVisible(true); _s.currentState = 0; } }; //##############################// /* destroy */ //##############################// _s.destroy = function(){ if(_s.isMobile_bl){ if(_s.hasPointerEvent_bl){ _s.screen.removeEventListener("MSPointerDown", _s.onMouseDown); _s.screen.removeEventListener("MSPointerUp", _s.onClick); _s.screen.removeEventListener("MSPointerOver", _s.onMouseOver); _s.screen.removeEventListener("MSPointerOut", _s.onMouseOut); }else{ _s.screen.removeEventListener("touchstart", _s.onMouseDown); } }else if(_s.screen.removeEventListener){ _s.screen.removeEventListener("mouseover", _s.onMouseOver); _s.screen.removeEventListener("mouseout", _s.onMouseOut); _s.screen.removeEventListener("mousedown", _s.onMouseDown); _s.screen.removeEventListener("click", _s.onClick); }else if(_s.screen.detachEvent){ _s.screen.detachEvent("onmouseover", _s.onMouseOver); _s.screen.detachEvent("onmouseout", _s.onMouseOut); _s.screen.detachEvent("onmousedown", _s.onMouseDown); _s.screen.detachEvent("onclick", _s.onClick); } _s.firstButton_do.destroy(); _s.n1_do.destroy(); _s.secondButton_do.destroy(); _s.n2_do.destroy(); if(_s.s1_do){ FWDAnimation.killTweensOf(_s.s1_do); FWDAnimation.killTweensOf(_s.s2_do); _s.s1_do.destroy(); _s.s2_do.destroy(); } _s.firstButton_do = null; _s.n1_do = null; _s.s1_do = null; _s.secondButton_do = null; _s.n2_do = null; _s.s2_do = null; _s.n1Img = null; _s.s1Img = null; _s.n2Img = null; _s.s2Img = null; n1Img = null; s1Img = null; n2Img = null; s2Img = null; _s.init = null; _s.setupMainContainers = null; _s.onMouseOver = null; _s.onMouseOut = null; _s.onClick = null; _s.onMouseDown = null; _s.toggleButton = null; _s.setButtonState = null; _s.destroy = null; _s.setInnerHTML(""); prototype.destroy(); _s = null; prototype = null; FWDMComplexButton.prototype = null; }; _s.init(); }; /* set prototype */ FWDMComplexButton.setPrototype = function(){ FWDMComplexButton.prototype = new FWDMDisplayObject("div"); }; FWDMComplexButton.FIRST_BUTTON_CLICK = "onFirstClick"; FWDMComplexButton.SECOND_BUTTON_CLICK = "secondButtonOnClick"; FWDMComplexButton.MOUSE_OVER = "onMouseOver"; FWDMComplexButton.MOUSE_OUT = "onMouseOut"; FWDMComplexButton.MOUSE_DOWN = "onMouseDown"; FWDMComplexButton.CLICK = "onClick"; FWDMComplexButton.prototype = null; window.FWDMComplexButton = FWDMComplexButton; }(window));