🏠 Home 

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)


Install this script?
  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. (function() {
  12. 'use strict';
  13. AJS.toInit(function(){
  14. var $ = AJS.$;
  15. //AJS.whenIType("c").execute(function(e) { // Don't know how to stop further execution/propagation with that
  16. $(document).bind('keydown', 'c', function(e) {
  17. var quickLink = $('#quick-create-page-button');
  18. if (quickLink.is(':visible')) {
  19. quickLink.click();
  20. e.preventDefault();
  21. e.stopImmediatePropagation();
  22. return false;
  23. }
  24. });
  25. var origConfluenceDialogWizard = Confluence.DialogWizard;
  26. Confluence.DialogWizard = function(dialog, finalAction) {
  27. var res = origConfluenceDialogWizard(dialog, finalAction);
  28. // Unfortunately we can not override the doFinalAction via prototype - so, the res.newPage-Action will still use the old one :(
  29. var doFinalAction = res.doFinalAction;
  30. res.doFinalAction = function(ev, state, wizardData, finalAction, wizard) {
  31. if (state.finalUrl && state.spaceKey == AJS.Meta.get('space-key')) {
  32. runInMain(state.finalUrl);
  33. AJS.$(".button-panel-cancel-link").click();
  34. } else {
  35. doFinalAction(ev, state, wizardData, finalAction, wizard);
  36. }
  37. };
  38. return res;
  39. };
  40. function runInMain(src) {
  41. var $main = $('#main'), headerHeight = $('#header').height();
  42. $main.children().detach();
  43. $('body').css('overflow', 'hidden');
  44. $main.parent().css('height', 'calc(100% - ' + headerHeight + 'px)');
  45. $main.parents().css('overflow', 'hidden');
  46. $main.css({
  47. height: '100%',
  48. padding: 0,
  49. borderBottom: 'none',
  50. minHeight: 0
  51. });
  52. $('#footer').hide();
  53. var iframe = $('<iframe>', {
  54. src: src,
  55. frameborder: 0,
  56. scrolling: 'no',
  57. }).css({
  58. marginTop: -1 * headerHeight,
  59. marginBottom: -1,
  60. height: 'calc(100% + ' + (headerHeight + 1) + 'px)',
  61. width: '100%'
  62. }).appendTo($main).one('load', function(e) {
  63. iframe.contents().find('head').append('<base target="_parent">');
  64. $(iframe.prop('contentWindow')).bind('unload', function() {
  65. window.setInterval(function() {
  66. var doc = iframe.prop('contentWindow').document;
  67. if (doc.readyState === 'loading') {
  68. document.location.href = doc.location.href;
  69. iframe.css('visibility', 'hidden');
  70. }
  71. }, 10);
  72. });
  73. $(this).one('load', function(e) {
  74. //document.location.href = $(this).prop('contentWindow').document.location.href;
  75. });
  76. });
  77. }
  78. $('#editPageLink, #quick-create-page-button').off('click').click(function(e) {
  79. e.preventDefault();
  80. e.stopImmediatePropagation();
  81. runInMain($(this).attr('href'));
  82. });
  83. });
  84. })();