(function($,sr){ // debouncing function from John Hann // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/ var debounce = function (func, threshold, execAsap) { var timeout; return function debounced () { var obj = this, args = arguments; function delayed () { if (!execAsap) func.apply(obj, args); timeout = null; } if (timeout) clearTimeout(timeout); else if (execAsap) func.apply(obj, args); timeout = setTimeout(delayed, threshold || 100); }; }; // smartresize jQuery.fn[sr] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); }; })(jQuery,'smartresize'); var CURRENT_URL = window.location.href.split('#')[0].split('?')[0], $BODY = $('body'), $MENU_TOGGLE = $('#menu_toggle'), $SIDEBAR_MENU = $('#sidebar-menu'), $SIDEBAR_FOOTER = $('.sidebar-footer'), $LEFT_COL = $('.left_col'), $RIGHT_COL = $('.right_col'), $NAV_MENU = $('.nav_menu'), $FOOTER = $('footer'); // Sidebar function init_sidebar() { // TODO: This is some kind of easy fix, maybe we can improve this var setContentHeight = function () { // reset height $RIGHT_COL.css('height', $(window).height()); var windowHeight = $(window).height(), bodyHeight = $BODY.outerHeight(), bodyHeight = windowHeight > bodyHeight ? bodyHeight : windowHeight, footerHeight = $BODY.hasClass('footer_fixed') ? -10 : $FOOTER.outerHeight(), leftColHeight = $LEFT_COL.eq(1).height() + $SIDEBAR_FOOTER.height(), contentHeight = bodyHeight < leftColHeight ? leftColHeight : bodyHeight; // normalize content contentHeight -= $NAV_MENU.height() + footerHeight; $RIGHT_COL.css('height', contentHeight); }; $SIDEBAR_MENU.find('a').on('click', function(ev) { console.log('clicked - sidebar_menu'); var $li = $(this).parent(); if ($li.is('.active')) { return; $li.removeClass('active active-sm'); $('ul:first', $li).slideUp(function() { setContentHeight(); }); } else { $li.siblings().removeClass('active active-sm'); // prevent closing menu if we are on child menu if (!$li.parent().is('.child_menu')) { $SIDEBAR_MENU.find('li').removeClass('active active-sm'); $SIDEBAR_MENU.find('li ul').slideUp(); } else { if ( $BODY.is( ".nav-sm" ) ) { $SIDEBAR_MENU.find( "li" ).removeClass( "active active-sm" ); $SIDEBAR_MENU.find( "li ul" ).slideUp(); } } $li.addClass('active'); $('ul:first', $li).slideDown(function() { setContentHeight(); }); } var href = $(this).attr('data-href') || $(this).attr('href'); $('.iframe_container').attr('src', href); $('#iframge_container').on('load', iframeLoaded()); return; }); // toggle small or large menu $MENU_TOGGLE.on('click', function() { console.log('clicked - menu toggle'); if ($BODY.hasClass('nav-md')) { $SIDEBAR_MENU.find('li.active ul').hide(); $SIDEBAR_MENU.find('li.active').addClass('active-sm').removeClass('active'); } else { $SIDEBAR_MENU.find('li.active-sm ul').show(); $SIDEBAR_MENU.find('li.active-sm').addClass('active').removeClass('active-sm'); } $BODY.toggleClass('nav-md nav-sm'); setContentHeight(); $('.dataTable').each ( function () { $(this).dataTable().fnDraw(); }); }); // check active menu $SIDEBAR_MENU.find('a[href="' + CURRENT_URL + '"]').parent('li').addClass('current-page'); $SIDEBAR_MENU.find('a').filter(function () { return this.href == CURRENT_URL; }).parent('li').addClass('current-page').parents('ul').slideDown(function() { setContentHeight(); }).parent().addClass('active'); // recompute content when resizing $(window).smartresize(function(){ setContentHeight(); }); setContentHeight(); // fixed sidebar if ($.fn.mCustomScrollbar) { $('.menu_fixed').mCustomScrollbar({ autoHideScrollbar: true, theme: 'minimal', mouseWheel:{ preventDefault: true } }); } }; // /Sidebar // NProgress if (typeof NProgress != 'undefined') { $(document).ready(function () { NProgress.start(); }); $(window).load(function () { NProgress.done(); }); } // iframe加载后点击事件,隐藏dropdown var IframeOnClick = { resolution: 200, iframes: [], interval: null, Iframe: function() { this.element = arguments[0]; this.cb = arguments[1]; this.hasTracked = false; }, track: function(element, cb) { this.iframes.push(new this.Iframe(element, cb)); if (!this.interval) { var _this = this; this.interval = setInterval(function() { _this.checkClick(); }, this.resolution); } }, checkClick: function() { if (document.activeElement) { var activeElement = document.activeElement; for (var i in this.iframes) { if (activeElement === this.iframes[i].element) { // user is in this Iframe if (this.iframes[i].hasTracked == false) { this.iframes[i].cb.apply(window, []); this.iframes[i].hasTracked = true; } } else { this.iframes[i].hasTracked = false; } } } } }; IframeOnClick.track(document.getElementById("iframe_container"), function() { iframeLoaded() }); function iframeLoaded() { // console.log('iframe_container click') var $dropdown = $('.dropdown-toggle'); if ($dropdown.attr('aria-expanded')) { $dropdown.parent().removeClass('open'); } } // $('#iframe_container').on('load', iframeLoaded()); $(document).ready(function() { init_sidebar(); });