monaco.ui.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. var iframeHeight = 0;
  2. var sidebarHeight = 0;
  3. var tabTemp;
  4. var parentTree = [];
  5. /* Close tab. */
  6. window.closeTab = function(dom)
  7. {
  8. const eleId = $(dom).parent().attr('href');
  9. const tabsEle = $(dom).parent().parent().parent();
  10. const isActive = $(dom).parent().hasClass('active');
  11. $(dom).parent().parent().remove();
  12. $(eleId).remove();
  13. $('#' + eleId.substring(5)).parent().removeClass('selected');
  14. if(isActive) tabsEle.children().last().find('a').trigger('click');
  15. if(!tabsEle.children().length) $('.monaco-dropmenu').addClass('hidden');
  16. const fileKey = eleId.substring(5).replace(/-/g, '=');
  17. $('li[z-key="' + fileKey + '"] .listitem').removeClass('selected');
  18. arrowTabs('monacoTabs', -1);
  19. }
  20. $(function()
  21. {
  22. setTimeout(function()
  23. {
  24. var fileAsId = file.replace(/=/g, '-');
  25. /* Resize moaco height. */
  26. $('#monacoTree').css('height', getSidebarHeight() - 8 + 'px');
  27. /* Init tab template. */
  28. if(!tabTemp) tabTemp = $('#monacoTabs ul li').first().clone();
  29. /* Load default tab content. */
  30. var height = getIframeHeight();
  31. $.cookie.set('repoCodePath', file, {expires:config.cookieLife, path:config.webRoot});
  32. $('#tab-' + fileAsId).html("<iframe class='repo-iframe' src='" + $.createLink('repo', 'ajaxGetEditorContent', urlParams.replace('%s', '')) + "' width='100%' height='" + height + "' scrolling='no'></iframe>")
  33. /* Select default tree item. */
  34. const currentElement = findItemInTreeItems(tree, fileAsId, 0);
  35. if(currentElement != undefined) $('#' + currentElement.id).parent().addClass('selected');
  36. if(['Git', 'Gitlab', 'Gogs', 'Gitea'].indexOf(repo.SCM) == -1)
  37. {
  38. $('#sourceSwapper').hide();
  39. }
  40. expandTree();
  41. $('.btn-left').on('click', function() {arrowTabs('monacoTabs', 1);});
  42. $('.btn-right').on('click', function() {arrowTabs('monacoTabs', -2);});
  43. }, 200);
  44. });
  45. /* Reload current page when click dropmeu. */
  46. $('body').off('click', '.dropmenu-tree .dropmenu-item').on('click', '.dropmenu-tree .dropmenu-item', function()
  47. {
  48. const branchOrTag = $(this).find('.listitem').data('value');
  49. const url = $(this).find('.listitem').data('url');
  50. if(url != 'javascript:;') return;
  51. if(branchOrTag != $.cookie.get('repoBranch')) $.cookie.set('repoBranch', branchOrTag, {expires:config.cookieLife, path:config.webRoot});
  52. openUrl(currentLink, {app: appTab});
  53. })
  54. window.dropdownClick = function(event)
  55. {
  56. const url = $(event).data('link');
  57. const file = $('#monacoTabs .nav-item .active').attr('href').substring(5).replace(/-/g, '=');
  58. if(url.indexOf('blame') >=0 && url.indexOf('download') == -1)
  59. {
  60. openUrl(url.replace('{path}', file), {app: appTab});
  61. }
  62. else
  63. {
  64. window.open(url.replace('{path}', file), '_self');
  65. }
  66. return;
  67. }
  68. /**
  69. * 打开新tab。
  70. * Open new tab.
  71. *
  72. * @access public
  73. * @return void
  74. */
  75. function openTab(entry, name)
  76. {
  77. var eleId = 'tab-' + entry.replace(/=/g, '-');
  78. var element = document.getElementById(eleId);
  79. if (element)
  80. {
  81. $("a[href='" + '#' + eleId + "']").trigger('click');
  82. return;
  83. }
  84. var newTab = tabTemp.clone();
  85. newTab.find('a').attr('href', '#' + eleId);
  86. newTab.find('span').text(name);
  87. $('#monacoTabs .nav-tabs').append(newTab);
  88. var height = getIframeHeight();
  89. $.cookie.set('repoCodePath', entry, {expires:config.cookieLife, path:config.webRoot});
  90. $('#monacoTabs .tab-content').append("<div id='" + eleId + "' class='tab-pane active in'><iframe class='repo-iframe' src='" + $.createLink('repo', 'ajaxGetEditorContent', urlParams.replace('%s', '')) + "' width='100%' height='" + height + "' scrolling='no'></iframe></div>")
  91. if($('.monaco-dropmenu').attr('class').indexOf('hidden')) $('.monaco-dropmenu').removeClass('hidden');
  92. setTimeout(() => {
  93. $("a[href='" + '#' + eleId + "']").trigger('click');
  94. }, 100);
  95. }
  96. /**
  97. * 在当前页面用modal加载链接。
  98. * Load link object page.
  99. *
  100. * @param string $link
  101. * @access public
  102. * @return void
  103. */
  104. window.loadLinkPage = function(link)
  105. {
  106. $('#linkObject').attr('href', link);
  107. $('#linkObject').trigger('click');
  108. }