;(function( $ ){ 'use strict'; function Seed(){ /*레프트 메뉴 이동 오류로 인하여 주석처리*/ /*$('a[href="#"], a[href="#none"]').on('click.DefaultClick', false);*/ var $root = $(window), $document = $(document), $html = $('html'), // 반응형 모바일 사이즈 확인용 $body = $('body').append($('
', {'id':'indicator','class':'hidden'})) // overflay .append($('', {'class':'overlay'})) // progress .append(function(){ if( $.support.pjax ){ return $('', {'id':'progress','class':'progress'}); } }), $pageContent = $('.page-content'), $header = $('.header'), // 뒷 배경 overlay = $('.overlay'), // 프로그레스 바 progressEl = $('#progress'), // 모바일 확인용 indicator = $('#indicator'), // 브라우저 resize 모바일 확인용 isResponsiveMobilePoint = function(){ return !$('#indicator').is(':visible'); }, randomIntFromInterval = function (min,max) { return Math.floor(Math.random()*(max-min+1)+min); }, // 이벤트 전파 막기용 stopPropagation = function(ev){ ev.stopPropagation(); }, isGTU = false, isSiteIdx = false, siteIdx = (function(){ var currentSiteIdx = $html.data('siteidx') || '', split = currentSiteIdx.split('/'), emptySiteIdx = false; // siteIdx가 없는지 판단 $.each(split, function( i, val ){ if( !val ){ emptySiteIdx = true; isSiteIdx = true; } }); // gtu 처리 if( currentSiteIdx.indexOf('gtu') > -1 ){ currentSiteIdx = currentSiteIdx.split('/')[0] + '/' + location.hostname.split('.')[0]; isGTU = true; emptySiteIdx = false; } if( !emptySiteIdx ){ if( window.sessionStorage && split[1] === 'seed' ){ return window.sessionStorage.siteIdx; } window.sessionStorage.siteIdx = currentSiteIdx; } return emptySiteIdx ? sessionStorage.siteIdx: currentSiteIdx; }()), replaceMarkup = (function(){ // gtu - 회원관리 if( isGTU && !isSiteIdx ){ $('#memberList').attr('href', '/'+ $html.data('siteidx') +'/memberList.do#memberList'); return; } else if( isGTU ){ return; } }()), transEndEventNames = { 'WebkitTransition': 'webkitTransitionEnd', 'MozTransition': 'transitionend', 'OTransition': 'oTransitionEnd', 'msTransition': 'MSTransitionEnd', 'transition': 'transitionend' }, // transition end 이벤트 이름 확인 transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ], // 사이트 선택, 스킨, 설정 버튼 이벤트 Setting = { settings: $('.setting-list'), settingsButton: $('.toggle-setting-btn'), currentActiveSettings: null, option: { speed: 0 }, init: function(){ var self = this; Setting.settings.find('a').each(function(){ if( $(this).text() === $('.site-setting').find('button').text() ){ $(this).click(false); } }).click(function(){ $(this).parents('ul').closest('.toggle-setting-btn').text( $(this).text() ); }); if( !$('.user-info .toggle-setting-btn').text() ){ if( !window.sessionStorage.siteIdx ) return; var siteIdx = window.sessionStorage.siteIdx.split('/')[1]; $('.user-info ul.site a').each(function( i, e ){ if( siteIdx && $(e).data('siteidx') === siteIdx ){ $('.user-info .toggle-setting-btn').text( $(e).text() ); } }); } this.settingsButton .on('click', function(){ Setting.currentActiveSettings = Setting.settingsButton.index(this); Setting.settings .not(':eq('+ Setting.currentActiveSettings +')').hide( Setting.option.speed ) .end() .eq( Setting.currentActiveSettings ).toggle( Setting.option.speed ); if( $.browser.mobile ){ Layout.navContainer.toggleClass('overflowY'); } return false; }); }, close: function(){ if( this.currentActiveSettings !== null ){ if( $.browser.mobile ){ Layout.navContainer.addClass('overflowY'); } this.settings.eq( this.currentActiveSettings ).hide( this.option.speed ); this.currentActiveSettings = null; } } }, // 레이아웃 이벤트 Layout = { pageContentWrap: $('.page-content-wrap'), navContainer: $('#navContainer'), viewContainer: $('#viewContainer'), collapseButton: $('#navCollapseBtn'), direction: $('#direction'), collapseMobileButton: $('#navCollapseMobileBtn'), saveMenuState: function(){ //메뉴열기,닫기 쿠키저장 $.ajax({ type: "POST" , async: true, url:"/common/proc/seedSetUpProc.do" , timeout: 30000 , cache: false, data:{ "cookieName": "navCookie", "event": localStorage.navContainerState } }); }, init: function(){ // localStorage객체에 navContainerState프로퍼티가 없으면 'open'문자열을 초기값으로 지정합니다. if( !localStorage.navContainerState ){ localStorage.navContainerState = 'open'; } if( !localStorage.navContainerDirection ){ localStorage.navContainerDirection = 'LEFT'; } if( localStorage.navContainerState === 'close' && $.browser.desktop ){ this.deskTopClose(); } this.direction.find('a').on('click', function(){ var dir = $(this).data('direction'); var dirClass = dir === 'LEFT' ? 'DirectionLeft': 'DirectionRight'; if( !dir ) return; localStorage.navContainerDirection = dir; $html.removeClass('DirectionLeft').removeClass('DirectionRight').addClass( dirClass ); //위치 쿠키저장 $.ajax({ type: "POST" , async: true, url:"/common/proc/seedSetUpProc.do" , timeout: 30000 , cache: false, data:{ "cookieName": "directionCookie", "event": dirClass } }); }); $('#clearLocalStorage').on('click', function(){ localStorage.clear(); setTimeout(function(){ location.reload(); }, 1); }); overlay.on('click', function(){ Layout.mobileClose(); }); this.collapseButton.on('click', function(){ if( localStorage.navContainerState === 'close' || Layout.navContainer.hasClass('close') && localStorage.navContainerState === 'open' ){ Layout.deskTopOpen(); } else { if( isResponsiveMobilePoint() ){ Layout.mobileClose(); } else { Layout.deskTopClose(); } } window.tabResize(); //메뉴열기,닫기 쿠키저장 Layout.saveMenuState(); }); this.collapseMobileButton.on({ 'touchstart touchmove touchend': stopPropagation, 'click': function(){ if( self.opener ){ if( !Layout.navContainer.hasClass('open') ){ Layout.mobileOpen(); } else{ Layout.mobileClose(); } window.tabResize(); return; } if( localStorage.navContainerState === 'close' ){ Layout.mobileOpen(); } else { Layout.mobileClose(); } window.tabResize(); } }); if( $.browser.mobile && Object.bind && $.browser.platform !== 'iphone' ){ this.navContainer.add(this.pageContentWrap).on({ 'touchstart': this.navTouchStart.bind(this), 'touchmove': this.navTouchMove.bind(this), 'touchend': this.navTouchEnd.bind(this) }); } var oldWidth = $root.width(); var resizeFirstTrigger = true; $root.doneEvent('resize.layout', function( e ){ if( oldWidth !== $root.width() || resizeFirstTrigger ){ if( isResponsiveMobilePoint() ){ if( localStorage.navContainerState === 'open' ){ Layout.mobileClose(); } else { if( localStorage.navContainerState === 'close' ){ Layout.navContainer.removeClass('open'); } if( !self.opener ){ localStorage.navContainerState = 'close'; Layout.saveMenuState(); } } Layout.navContainer.removeClass('close'); Layout.viewContainer.removeClass('close'); } else { if( localStorage.navContainerState === 'close' && e.eventPhase ){ if( !self.opener ){ localStorage.navContainerState = 'open'; Layout.saveMenuState(); } } } oldWidth = $root.width(); resizeFirstTrigger = false; } }).resize(); this.navContainer.addClass('transition'); setTimeout(function(){ Layout.navContainer.removeClass('display-hide'); }, 400); }, deskTopOpen: function(){ this.navContainer.removeClass('close'); this.viewContainer.removeClass('close'); if( !self.opener ){ localStorage.navContainerState = 'open'; Layout.saveMenuState(); } var o = JSON.parse(localStorage.Gnb); $.each(o[siteIdx], function( key, val ){ Gnb.eventButton.parent().eq( key ).addClass('current-tab').find(' > ul ').show(); }); Gnb.mainManuWrap.mCustomScrollbar({scrollInertia:0}); }, deskTopClose: function(){ if( !self.opener ){ localStorage.navContainerState = 'close'; Layout.saveMenuState(); } this.navContainer.addClass('close'); this.viewContainer.addClass('close'); Gnb.mainManuWrap.mCustomScrollbar('destroy'); Gnb.eventTarget.hide(); }, mobileOpen: function(){ overlay.addClass('open'); this.navContainer.addClass('open', !transEndEventName ? 400: 0 ); this.viewContainer.addClass('scrollLock'); if( !self.opener ){ localStorage.navContainerState = 'open'; Layout.saveMenuState(); } if( $.browser.desktop ){ Gnb.mainManuWrap.mCustomScrollbar({scrollInertia:0}); } }, mobileClose: function(){ if( Setting.settings.is( ':visible' ) ){ Setting.close(); return; } overlay.removeClass('open'); this.navContainer.removeClass('open', !transEndEventName ? 400: 0).addClass('transition'); this.viewContainer.removeClass('scrollLock'); if( !self.opener ){ localStorage.navContainerState = 'close'; Layout.saveMenuState(); } this.touchPropertyReset(); if( $.browser.desktop ){ Gnb.mainManuWrap.mCustomScrollbar('destroy'); } }, touch: { firstTouchX: 0, firstTouchY: 0, translateVal: 0, friction: 2.5, distance: -40, moveType: '', moveTypeSave: false, isPageTouch: false, pageTouchLimit: false, //수평 방향을 판단하는 기준 기울기 navHorizontalSlope: (($('#navContainer').height() / 2) / $('#navContainer').width()).toFixed(2) * 1, pageHorizontalSlope: (($('.page-content-wrap').height() / 2) / $('.page-content-wrap').width()).toFixed(2) * 1, }, setGnbTransForm: function(){ this.navContainer.css('transform', 'translate3d('+ this.touch.translateVal +'px, 0, 0)'); }, touchPropertyReset: function(){ this.touch.moveType = ''; this.touch.moveTypeSave = false; this.touch.translateVal = 0; this.touch.pageTouchLimit = false; }, touchMoveType: function( horizontalSlope, space, x, y ){ var moveType = ''; var X = Math.abs(this.touch.firstTouchX - x); var Y = Math.abs(this.touch.firstTouchY - y); //현재 움직인 거리가 기준 거리보다 작을 땐 방향을 판단하지 않는다. if( (X + Y) < space ) { return moveType; } var slope = parseFloat((Y / X).toFixed(2), 10); // 수직 if( slope > horizontalSlope ){ moveType = 'verticle'; } // 수평 else { moveType = 'horizontal'; } return moveType; }, navTouchStart: function( ev ){ // touch 정보 var touchobj = ev.originalEvent.touches[0]; this.touch.firstTouchX = parseInt( touchobj.clientX ); this.touch.firstTouchY = parseInt( touchobj.clientY ); this.navContainer.removeClass('transition'); if( localStorage.navContainerDirection === 'LEFT' ){ this.touch.pageTouchLimit = Math.floor(this.touch.firstTouchX / $root.width() * 100) < 10 && ev.currentTarget.className === 'page-content-wrap'; } else if( localStorage.navContainerDirection === 'RIGHT' ){ this.touch.pageTouchLimit = Math.floor(this.touch.firstTouchX / $root.width() * 100) > 90 && ev.currentTarget.className === 'page-content-wrap'; } }, navTouchMove: function( ev ){ // 기울기, 기준거리 var slope, space; if( !this.touch.pageTouchLimit && ev.currentTarget.className === 'page-content-wrap' ){ return; } if( this.touch.pageTouchLimit ){ slope = this.touch.pageHorizontalSlope; space = 2; } else { slope = this.touch.navHorizontalSlope; space = 25; } var touchobj = ev.originalEvent.touches[0], touchX = parseInt( touchobj.clientX ), touchY = parseInt( touchobj.clientY ); // 수평인지 수직방향인지 판단한다. this.touch.moveType = this.touchMoveType( slope, space, touchX, touchY ); // 수직방향이거나 기준거리에 도달하지 못하면 함수종료 if( !this.touch.moveType || this.touch.moveType === 'verticle' ){ return; } // 움직일 translate 값 this.touch.translateVal = (touchX - this.touch.firstTouchX) / this.touch.friction; if( localStorage.navContainerDirection === 'LEFT' ){ if ( this.touch.translateVal < 0 ) { ev.preventDefault(); } if( this.touch.translateVal > 0 ) { ev.preventDefault(); this.touch.firstTouchX = touchX; return; } } else if( localStorage.navContainerDirection === 'RIGHT' ){ if ( this.touch.translateVal < 0 ) { ev.preventDefault(); this.touch.firstTouchX = touchX; return; } if( this.touch.translateVal > 0 ) { ev.preventDefault(); } } // moving this.setGnbTransForm(); }, navTouchEnd: function( ev ){ var closeNav = function(){ this.navContainer.css('transform', '').addClass('transition'); this.mobileClose(); this.touchPropertyReset(); }.bind(this); if( this.touch.pageTouchLimit ){ if( !this.touch.moveType || this.touch.moveType === 'verticle' ){ closeNav(); return; } } if( !this.touch.pageTouchLimit && ev.currentTarget.className === 'page-content-wrap' && ( this.touch.moveTypeSave || !this.touch.moveType ) ){ closeNav(); return; } this.navContainer.css('transform', '').addClass('transition'); if( localStorage.navContainerDirection === 'LEFT' ){ if( this.touch.translateVal < this.touch.distance ) { this.mobileClose(); } else { this.mobileOpen(); } } else if( localStorage.navContainerDirection === 'RIGHT' ){ if( this.touch.translateVal > Math.abs(this.touch.distance) ) { this.mobileClose(); } else { this.mobileOpen(); } } // 초기화 this.touchPropertyReset(); } }, Gnb = { mainManuWrap: $('.main-menu-wrap'), navHeader: $('.nav-header'), eventButton: $('#mainMenu > ul > li > a'), eventTarget: $('#mainMenu > ul > li > ul'), isMobile: $.browser.mobile, gnbObj: {}, init: function(){ if( siteIdx === undefined || !siteIdx ){ return; } this.gnbObj[siteIdx] = {}; if( !localStorage.Gnb ){ localStorage.Gnb = JSON.stringify(this.gnbObj); } else { this.gnbObj = $.extend( this.gnbObj, JSON.parse(localStorage.Gnb) ); } $.each(this.gnbObj[siteIdx], function( key, val ){ if( localStorage.navContainerState === 'open' ){ Gnb.eventButton.parent().eq( key ).addClass('current-tab').find(' > ul ').show(); } }); this.eventButton.on('click', function( event ){ if( localStorage.navContainerState === 'close' && !$.browser.mobile ){ return; } var $this = $(this); var index = $this.parent().index(); if( $this.next().length ){ event.preventDefault(); if( localStorage.Gnb && $.browser.desktop && !isResponsiveMobilePoint() ){ if( !!Gnb.gnbObj[siteIdx] ){ Gnb.gnbObj[siteIdx][index] = false } // 처음 열림 if( $this.parent().hasClass('current-tab') ){ if( !!Gnb.gnbObj[siteIdx] ){ delete Gnb.gnbObj[siteIdx][index]; } } localStorage.Gnb = JSON.stringify(Gnb.gnbObj); } } Gnb.toggle( $this ); }); this.eventButton.on('mouseenter', function(){ if( localStorage.navContainerState === 'close' && $.browser.desktop && !isResponsiveMobilePoint() ){ Gnb.eventTarget.hide(); $(this).next().show(); } }); Layout.navContainer.on('mouseleave', function(){ if( localStorage.navContainerState === 'close' && $.browser.desktop && !isResponsiveMobilePoint() ){ Gnb.eventTarget.hide(); } }); this.customScroll(); }, customScroll: function(){ if( $.browser.mobile ){ Layout.navContainer.addClass('overflowY'); } else { if( localStorage.navContainerState !== 'close' ){ this.mainManuWrap.mCustomScrollbar({scrollInertia:0}); } $root.on('resize.navcontainer', function(){ Gnb.mainManuWrap.height( Layout.navContainer.height() - Gnb.navHeader.outerHeight() ); }).resize(); } }, toggle: function( elem ){ if( this.isMobile ){ elem.next().toggle(); } else { elem.next().stop().slideToggle(); } elem.parent().toggleClass('current-tab'); } }; // 레이아웃 이벤트 Layout.init(); // 사이트 선택, 스킨, 설정 버튼 이벤트 Setting.init(); // gnb 이벤트 Gnb.init(); window.seedCommon = { Layout: Layout, Setting: Setting, Gnb: Gnb } // ?? 위치 옮길 것. var documentClickEvent = function(){ // 사이트 선택, 스킨, 설정 리스트 닫기 Setting.close(); // 전체메뉴 삭제 if( $('#wholeTabs').length ){ $('#wholeTabs').remove(); return; } } $document.on('click', documentClickEvent); // http://stackoverflow.com/questions/1802936/stop-all-active-ajax-requests-in-jquery $.xhrPool = []; $.xhrPool.abortAll = function() { $(this).each(function(idx, jqXHR) { jqXHR.abort(); }); $.xhrPool = []; }; } $( Seed ); }( jQuery ));