Greasy Fork is available in English.

Confluence - Open editor inside main view (keep sidebar)

Open editor inside main view when creating and editing pages (known bug: when page creation requires multiple steps, the resulting page will be opened without the page tree)

  1. // ==UserScript==
  2. // @name Confluence - Open editor inside main view (keep sidebar)
  3. // @namespace http://netresearch.de/
  4. // @version 0.2
  5. // @description Open editor inside main view when creating and editing pages (known bug: when page creation requires multiple steps, the resulting page will be opened without the page tree)
  6. // @author Christian Opitz
  7. // @include *.atlassian.net/wiki/*
  8. // @grant none
  9. // @run-at document-body
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. AJS.toInit(function(){
  15. var $ = AJS.$;
  16. //AJS.whenIType("c").execute(function(e) { // Don't know how to stop further execution/propagation with that
  17. $(document).bind('keydown', 'c', function(e) {
  18. var quickLink = $('#quick-create-page-button');
  19. if (quickLink.is(':visible')) {
  20. quickLink.click();
  21. e.preventDefault();
  22. e.stopImmediatePropagation();
  23. return false;
  24. }
  25. });
  26. var origConfluenceDialogWizard = Confluence.DialogWizard;
  27. Confluence.DialogWizard = function(dialog, finalAction) {
  28. var res = origConfluenceDialogWizard(dialog, finalAction);
  29. // Unfortunately we can not override the doFinalAction via prototype - so, the res.newPage-Action will still use the old one :(
  30. var doFinalAction = res.doFinalAction;
  31. res.doFinalAction = function(ev, state, wizardData, finalAction, wizard) {
  32. if (state.finalUrl && state.spaceKey == AJS.Meta.get('space-key')) {
  33. runInMain(state.finalUrl);
  34. AJS.$(".button-panel-cancel-link").click();
  35. } else {
  36. doFinalAction(ev, state, wizardData, finalAction, wizard);
  37. }
  38. };
  39. return res;
  40. };
  41. function runInMain(src) {
  42. var $main = $('#main'), headerHeight = $('#header').height();
  43. $main.children().detach();
  44. $('body').css('overflow', 'hidden');
  45. $main.parent().css('height', 'calc(100% - ' + headerHeight + 'px)');
  46. $main.parents().css('overflow', 'hidden');
  47. $main.css({
  48. height: '100%',
  49. padding: 0,
  50. borderBottom: 'none',
  51. minHeight: 0
  52. });
  53. $('#footer').hide();
  54. var iframe = $('<iframe>', {
  55. src: src,
  56. frameborder: 0,
  57. scrolling: 'no',
  58. }).css({
  59. marginTop: -1 * headerHeight,
  60. marginBottom: -1,
  61. height: 'calc(100% + ' + (headerHeight + 1) + 'px)',
  62. width: '100%'
  63. }).appendTo($main).one('load', function(e) {
  64. iframe.contents().find('head').append('<base target="_parent">');
  65. $(iframe.prop('contentWindow')).bind('unload', function() {
  66. window.setInterval(function() {
  67. var doc = iframe.prop('contentWindow').document;
  68. if (doc.readyState === 'loading') {
  69. document.location.href = doc.location.href;
  70. iframe.css('visibility', 'hidden');
  71. }
  72. }, 10);
  73. });
  74. $(this).one('load', function(e) {
  75. //document.location.href = $(this).prop('contentWindow').document.location.href;
  76. });
  77. });
  78. }
  79. $('#editPageLink, #quick-create-page-button').off('click').click(function(e) {
  80. e.preventDefault();
  81. e.stopImmediatePropagation();
  82. runInMain($(this).attr('href'));
  83. });
  84. });
  85. })();