bootstrap.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. require(['../addons/bootstrapcontextmenu/js/bootstrap-contextmenu'], function (undefined) {
  2. if (Config.controllername == 'index' && Config.actionname == 'index') {
  3. $("body").append(
  4. '<div id="context-menu">' +
  5. '<ul class="dropdown-menu" role="menu">' +
  6. '<li><a tabindex="-1" data-operate="refresh"><i class="fa fa-refresh fa-fw"></i>刷新</a></li>' +
  7. '<li><a tabindex="-1" data-operate="refreshTable"><i class="fa fa-table fa-fw"></i>刷新表格</a></li>' +
  8. '<li><a tabindex="-1" data-operate="close"><i class="fa fa-close fa-fw"></i>关闭</a></li>' +
  9. '<li><a tabindex="-1" data-operate="closeOther"><i class="fa fa-window-close-o fa-fw"></i>关闭其他</a></li>' +
  10. '<li class="divider"></li>' +
  11. '<li><a tabindex="-1" data-operate="closeAll"><i class="fa fa-power-off fa-fw"></i>关闭全部</a></li>' +
  12. '</ul>' +
  13. '</div>');
  14. $(".nav-addtabs").contextmenu({
  15. target: "#context-menu",
  16. scopes: 'li[role=presentation]',
  17. onItem: function (e, event) {
  18. var $element = $(event.target);
  19. var tab_id = e.attr('id');
  20. var id = tab_id.substr('tab_'.length);
  21. var con_id = 'con_' + id;
  22. switch ($element.data('operate')) {
  23. case 'refresh':
  24. $("#" + con_id + " iframe").attr('src', function (i, val) {
  25. return val;
  26. });
  27. break;
  28. case 'refreshTable':
  29. try {
  30. if ($("#" + con_id + " iframe").contents().find(".btn-refresh").size() > 0) {
  31. $("#" + con_id + " iframe")[0].contentWindow.$(".btn-refresh").trigger("click");
  32. }
  33. } catch (e) {
  34. }
  35. break;
  36. case 'close':
  37. if (e.find(".close-tab").length > 0) {
  38. e.find(".close-tab").click();
  39. }
  40. break;
  41. case 'closeOther':
  42. e.parent().find("li[role='presentation']").each(function () {
  43. if ($(this).attr('id') == tab_id) {
  44. return;
  45. }
  46. if ($(this).find(".close-tab").length > 0) {
  47. $(this).find(".close-tab").click();
  48. }
  49. });
  50. break;
  51. case 'closeAll':
  52. e.parent().find("li[role='presentation']").each(function () {
  53. if ($(this).find(".close-tab").length > 0) {
  54. $(this).find(".close-tab").click();
  55. }
  56. });
  57. break;
  58. default:
  59. break;
  60. }
  61. }
  62. });
  63. }
  64. $(document).on('click', function () { // iframe内点击 隐藏菜单
  65. try {
  66. top.window.$(".nav-addtabs").contextmenu("closemenu");
  67. } catch (e) {
  68. }
  69. });
  70. });