index.js 3.01 KB
/**
 * index
 * 默认依赖
 */
'use strict';
var $ = require('jquery');

var isMenuShow = false;
var localStorage = window.localStorage;

/*左侧导航*/
$('.leftpanel .nav .parent>a').click(function() {
  var parent = $(this).parent(),
      child = parent.find('.children');

  parent.siblings('.active').find('.children').removeClass("active").slideUp('fast');
  parent.siblings('.active').removeClass("active");

  if(parent.hasClass('active')){
    $(".parent ").removeClass("active");
    $('.children').removeClass("active").slideUp('fast');
    isMenuShow = false;
  }else{
    $(this).parent(".parent ").addClass("active");
    child.slideDown('fast').addClass("active");
    isMenuShow = true;
  }
  return false;
});

/*菜单*/
$(".leftpanel .nav .children a").each(function() {
  var attr = $(this).attr('href');

  if (!isMenuShow && attr == window.location.pathname + window.location.search) {
    $(this).parents(".children").show();
    $(this).parent("li").addClass("active");
    $(this).parents(".parent").addClass("active");
    localStorage.setItem("router", attr);
    localStorage.getItem("router");
    isMenuShow = true;
  }
});

if (!isMenuShow && localStorage.getItem("router")) {
  $(".leftpanel .nav .children a").each(function() {
    var attr = $(this).attr('href');

    if (localStorage.getItem("router") == attr) {
      $(this).parents(".children").show();
      $(this).parent("li").addClass("active");
      $(this).parents(".parent").addClass("active");
      isMenuShow = true;
    }
  });
}

// LocalStorage.setItem("router",);
$('.panel-heading').hover(function() {
  $(this).find('.panel-btns').fadeIn('fast');
}, function() {
  $(this).find('.panel-btns').fadeOut('fast');
});

$('.panel .panel-close').click(function() {
  $(this).closest('.panel').fadeOut(200);
  return false;
});

// Minimize Panel
$('.panel .panel-minimize').click(function() {
  var t = $(this);
  var p = t.closest('.panel');
  if (!$(this).hasClass('maximize')) {
    p.find('.panel-body, .panel-footer').slideUp(200);
    t.addClass('maximize');
    t.find('i').removeClass('fa-minus').addClass('fa-plus');
  } else {
    p.find('.panel-body, .panel-footer').slideDown(200);
    t.removeClass('maximize');
    t.find('i').removeClass('fa-plus').addClass('fa-minus');
  }
  return false;
});

var timer = null;
$('.dropdown-toggle').on('mouseenter', function() {
  $('.dropdown-menu').hide();
  $(this).siblings('.dropdown-menu').show();
}).on('mouseleave', function() {
  var that = this;
  clearTimeout(timer);
  timer = setTimeout(function() {
    $(that).siblings('.dropdown-menu').hide();
  }, 1000);

});

$('.dropdown-menu').on('mouseenter', function() {
  clearTimeout(timer);
  $(this).show();
}).on('mouseleave', function() {
  $(this).hide();
});

$(document).on("click",".delay-btn",function(){
  var $this=$(this);
  $this.prop("disabled",true);
  setTimeout(function(){
    $this.prop("disabled",false)
  },2000);
});

$(document).on("keyup change","input[type='number']",function(){
  $(this).val($(this).val().replace(/[^0-9]/g, ''));
});