$ua = navigator.userAgent; $.extend($.support, { touch: "ontouchend" in document }); if($.support.touch) { mouseenterEvent = clickEvent = "touchstart"; } else { clickEvent = "click"; mouseenterEvent = "mouseenter"; } // Focus first element !function ($) { $.fn.focusFirstField = function(){ $this = this; $this.find(":text:visible:enabled").filter(function(){ return $(this).parents(":hidden").size() == 0; }).slice(0,1).focus(); return this; } }(window.jQuery); // Search Clear !function ($) { $.fn.searchClear = function (param){ _defaultSettings = { inputName: ':input', inputIcon: 'inputIcon', clearBtnIcon: 'clearBtnIcon', }; _set = $.extend(_defaultSettings, param); $this = this; $input = this.find(_set.inputName); $tmp = ''; $input.wrap('
'); $this.find('.sc-field').prepend($tmp); $searchClear = $this.find(".search-clear"); function run(e) { $searchClear.hide(); if($input.val().length > 0) { $searchClear.show(); }else { $searchClear.hide(); } $input.on("blur keyup", function(){ if($(this).val().length > 0) { $searchClear.show(); }else { $searchClear.hide(); } }); $searchClear.on({ click: function(){ $(this).hide(); $input.val("") }, }); } // Checking IE10 // if Windows 8 and IE is ture. remove search clear buttom and fix text input padding-right if(/Windows NT 6.2/g.test(navigator.userAgent)){ if(/MSIE/g.test(navigator.userAgent)){ $searchClear.remove(); $input.css({ 'padding-right': '5px', }); }else{run()} }else{run()} } }(window.jQuery); // Fixed Nav !function ($) { fixedNav = function () { if($('.fixed-nav').length){ var $fixedNav = $('.fixed-nav'); if($sidebarState){ $fixedNav.addClass('open'); } $fixedNav.on(clickEvent, function() { if($sidebarState) { window.localStorage.removeItem('sidebarState'); $fixedNav.removeClass('open'); }else{ window.localStorage.setItem('sidebarState', 1); $fixedNav.addClass('open'); } $sidebarState = window.localStorage.getItem('sidebarState') }); } }; }(window.jQuery); // Sidebar !function ($) { sidebarNav = function () { var $sidebar = $('#sidebar'), $sidebarMenu = $('#sidebar-menu'), $scroller = $('.scroller'), $sidebarNav = $('.sidebar-nav'), $el = $('.sidebar-nav').children('li'), $elIndex = null, $blockList = $('.sub-nav-block-list'), $block = $('.sub-nav-block'), $blockIndex = 0, $arrow = $('.sub-nav-arrow'), $wrap = $('#main-wrap'), $wrapLeft = $wrap.css('margin-left'), $position = 0, $arrowHeightFormat = $('.position').height()-8; if($('#sidebar').length>0) { $wrap.css({'margin-left': 61}); $wrapLeft = 61; } if($el.hasClass('active')) { // Menu defaults active $elIndex = $el.filter('.active').index(); if($sidebarState) { $block.eq($elIndex).addClass('show'); $blockList.css({'width': 180}); $wrap.css({ 'margin-left': 241, }); } // Arrow defaults position $position = $el.eq($elIndex).offset().top-$el.eq($elIndex).height()/2+$arrowHeightFormat-$(document).scrollTop(); $arrow.css({ 'top': $position, }); } if($.support.touch) { $el.find('a').removeAttr('href'); }; $el.on(mouseenterEvent, function(e) { $block.siblings().removeClass('show').eq($(this).index()).addClass('show'); $arrow.stop(true, false).animate({ top: ($(this).offset().top-$(this).height()/2)+$arrowHeightFormat-$(document).scrollTop(), },{ duration: 500, easing: 'easeInOutBack', }); if(!$sidebarState || !$el.hasClass('active')) { $blockList.css({'width': 180}); if($('#pageslide').length) { if($('#pageslide').is(":hidden")) { $wrap.css({ 'margin-left': $blockList.width()+$sidebarNav.width(), }); } }else{ $wrap.css({ 'margin-left': $blockList.width()+$sidebarNav.width(), }); } // if($('.topnav').length) { // $('.topnav').css({ // 'left': $blockList.width()+$sidebarNav.width()+20, // }); // } if($('.bottomnav').length) { $('.bottomnav').css({ 'left': $blockList.width()+$sidebarNav.width()+20, }); } $sidebar.css({ 'width': $blockList.width()+$sidebarNav.width(), }); } }); // $el.on('mouseleave', function() { // $el.hasClass('active') ? $position = $el.eq($elIndex).offset().top-$el.eq($elIndex).height()/2+$arrowHeightFormat-$(document).scrollTop() : 0; // $(this).hasClass('active') ? '':$(this).children('span').removeClass('hover'); // }); $block.on({ mouseenter: function() { $blockIndex = $block.filter('.sub-nav-block show').index(); $el.eq($blockIndex).hasClass('active') ? '':$el.eq($blockIndex).children('span').addClass('hover'); }, mouseleave: function() { $block.removeClass('show'); if(!$sidebarState || !$el.hasClass('active')) { $blockList.css({'width': 0}); if($('#pageslide').length) { if($('#pageslide').is(":hidden")) { $wrap.css({ 'margin-left': $wrapLeft, }); // if($('.topnav').length) { // if($sidebarState) { // $('.topnav').css({ // 'left': 261, // }); // } // } } } else { $wrap.css({ 'margin-left': $blockList.width()+$sidebarNav.width(), }); } // if($('.topnav').length) { // $('.topnav').css({ // 'left': $blockList.width()+$sidebarNav.width()+20, // }); // } if($('.bottomnav').length) { $('.bottomnav').css({ 'left': $blockList.width()+$sidebarNav.width()+20, }); } $sidebar.css({'width': 61}); }else{ $block.eq($elIndex).addClass('show'); }; if($elIndex === null) { $position = 0; } else { $position = $el.eq($elIndex).offset().top-$el.eq($elIndex).height()/2+$arrowHeightFormat-$(document).scrollTop(); } $arrow.stop(true, false).animate({ top: $position, },{ duration: 500, easing: 'easeInOutBack', }); } }); // Touch Start $wrap.on({ touchstart: function() { if(!$sidebarState || !$el.hasClass('active')) { if($block.hasClass('show')) { $blockIndex = $block.filter('.sub-nav-block show').index(); $block.removeClass('show'); $blockList.css({'width': 0}); $wrap.css({ 'margin-left': $wrapLeft, }); $sidebar.css({'width': 61}); $arrow.stop().animate({ top: $position, },{ duration: 500, easing: 'easeInOutBack', }); $el.eq($blockIndex).hasClass('active') ? '':$el.eq($blockIndex).children('span').removeClass('hover'); } } } }); // Sidebar Nav Drag if(/MSIE 8.0/g.test($ua)){ $sidebarMenu.addClass('nano') .css({'position': 'relative', 'top': '0px'}) .children('.scroller') .addClass('content') .removeClass('scroller'); $sidebarMenu.nanoScroller({ scrollTop: 0 }); } else { var sidebarMenu = new iScroll('sidebar-menu', { vScrollbar: true, scrollbarClass: 'myScrollbar', onBeforeScrollStart: function (e) { var target = e.target; clearTimeout(this.hoverTimeout); while (target.nodeName != "SPAN") target = target.parentNode; $target = $(target.parentNode).index(); }, touch: function () { if (this.hoverTarget) { clearTimeout(this.hoverTimeout); $('.sub-nav-block').removeClass('show') $('.sub-nav-block').eq($target).addClass('show') } }, }); }; }; }(window.jQuery); // Initial State !function ($) { initialState = function () { if($('.bottomnav').length) { var $bottomnavHeight = $('.bottomnav').outerHeight(); $('.wrap-inner').css({ 'padding-bottom': $bottomnavHeight, }) if($sidebarState) { $('.bottomnav').css({ 'left': 261, }); } } // if($('.topnav').length) { // if($sidebarState) { // $('.topnav').css({ // 'left': 261, // }); // } // } }; }(window.jQuery); // Open Slide function openSlide() { var $openSlide = $('.open-slide'), $pageslideW; $(window).width() > 1440 ? $pageslideW = 1024 : $pageslideW = 954; $(window).resize(function() { $(this).width() > 1440 ? $pageslideW = 1024 : $pageslideW = 954; }) $openSlide.each(function() { if($(this).hasClass('view-page')) { $(this).pageslide({ W: $pageslideW, iframe: true}); } else if($('#items').length) { $(this).pageslide({ W: 600}); } else { $(this).pageslide(); }; }); } //Global Variables var $sidebarState = window.localStorage.getItem('sidebarState'); // Document Ready $(function() { initialState(); $('#login').on('shown', function () { $(document.body).addClass('modalBlur'); $('#login').focusFirstField(); }).on("hide", function() { $(document.body).removeClass('modalBlur'); }); $('#search').searchClear({ inputName: '.search-query', inputIcon: 'icon-search', clearBtnIcon: 'icons-cross-3', }); $('#member-filter').on('shown', function() { $(this).find('.nano').nanoScroller({ scrollTop: 0, iOSNativeScrolling: true }); }); if($('#sidebar').length) { if(!/MSIE 8.0/g.test(navigator.userAgent)){ document.getElementById('sidebar').addEventListener('touchmove', function (e) { e.preventDefault(); }, false); } } if($('#pageslide').length) { openSlide(); } if($('.tags').length) { $('#filter-input').fastLiveFilter('#tags-list', '.filter-item', '.tag'); } if($('#card-list').length) { $('#filter-input').fastLiveFilter('#card-list', '.filter-item', '.user-name'); } sidebarNav(); });