admin.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. $(function(){
  2. // 一次性初始化所有弹出框
  3. $('[data-toggle="popover"]').popover();
  4. // 图片lazyload
  5. $('img.lazy').lazyload({
  6. effect : 'fadeIn',
  7. data_attribute : 'src',
  8. placeholder : $('#corethink_home_img').val()+'/default/default.gif'
  9. });
  10. // 刷新验证码
  11. $(document).on('click', '.reload-verify', function() {
  12. var verifyimg = $(this).attr("src");
  13. if (verifyimg.indexOf('?') > 0) {
  14. $(this).attr("src", verifyimg + '&random=' + Math.random());
  15. } else {
  16. $(this).attr("src", verifyimg.replace(/\?.*$/, '') + '?' + Math.random());
  17. }
  18. });
  19. //全选/反选/单选的实现
  20. $(document).on('click', '.check-all', function() {
  21. $(".ids").prop("checked", this.checked);
  22. });
  23. $(document).on('click', '.ids', function() {
  24. var option = $(".ids");
  25. option.each(function() {
  26. if (!this.checked) {
  27. $(".check-all").prop("checked", false);
  28. return false;
  29. } else {
  30. $(".check-all").prop("checked", true);
  31. }
  32. });
  33. });
  34. //搜索功能
  35. $(document).on('click', '.search-btn', function() {
  36. var url = $(this).closest('form').attr('action');
  37. var query = $(this).closest('form').serialize();
  38. query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
  39. query = query.replace(/(^&)|(\+)/g, '');
  40. if (url.indexOf('?') > 0) {
  41. url += '&' + query;
  42. } else {
  43. url += '?' + query;
  44. }
  45. window.location.href = url;
  46. return false;
  47. });
  48. //回车搜索
  49. $(document).on('keydown', '.search-input', function(e) {
  50. if (e.keyCode === 13) {
  51. $(this).closest('form').find('.search-btn').click();
  52. return false;
  53. }
  54. });
  55. // 设置ct-tab的宽度
  56. $('.ct-tab').width($(window).width()-373);
  57. // 打开新Tab
  58. $(document).on('click', '#sidebar .open-tab', function() {
  59. var tab_url = $(this).attr('href');
  60. var tab_name = $(this).attr('tab-name');
  61. var is_open = $('.ct-tab-content #' + tab_name).length;
  62. if(is_open !== 0){
  63. $('.ct-tab a[href=#' + tab_name + ']').tab('show');
  64. } else {
  65. var tab = '<li class="new-add" style="position: relative;float:left;display: inline-block;"><a href="#'
  66. + tab_name
  67. + '" role="tab" data-toggle="tab">'
  68. + $(this).html()
  69. + '<button type="button" class="close" aria-label="Close">'
  70. + '<span aria-hidden="true">&times;</span></button></a></li>';
  71. var tab_content = '<div role="tabpanel" class="new-add tab-pane fade" id="'
  72. + tab_name
  73. + '"><iframe name="#'
  74. + tab_name
  75. + '" class="iframe" src="'
  76. + tab_url
  77. +'"></iframe></div>';
  78. $('.ct-tab').width($('.ct-tab').width() + 60);
  79. $('.ct-tab').append(tab);
  80. $('.ct-tab-content').append(tab_content);
  81. $('.ct-tab a:last').tab('show');
  82. }
  83. return false;
  84. });
  85. // 关闭标签时自动取消左侧导航的active状态
  86. $(document).on('click', '.nav-close .close', function() {
  87. var id = $(this).closest('a[data-toggle="tab"]').attr('href');
  88. var tab = id.split('#');
  89. $('a[tab-name=' + tab[1] + ']').closest('li').removeClass('active');
  90. });
  91. // 关闭所有标签
  92. $(document).on('click', '.close-all', function() {
  93. $('.new-add').remove();
  94. $('.ct-tab a:first').tab('show');
  95. });
  96. // 双击刷新标签
  97. $(document).on('dblclick', '.ct-tab a', function() {
  98. var id = $(this).attr('href');
  99. $(id+' .iframe').attr('src', $(id+' .iframe').attr('src'));
  100. });
  101. // TAB向左滚动
  102. $(document).on('click', '#tab-left', function() {
  103. var left = $('.ct-tab').position().left;
  104. if (left < 0) {
  105. $('.ct-tab').animate({left:(left+480+'px')});
  106. }
  107. });
  108. // TAB向右滚动
  109. $(document).on('click', '#tab-right', function() {
  110. var left = $('.ct-tab').position().left;
  111. if(($(window).width()-373)-(left+$('.ct-tab').width()) < 0){
  112. $('.ct-tab').animate({left:(left-480+'px')});
  113. }
  114. });
  115. });