From e1e89b40fb947f6b85cda799a12f4e4102033d99 Mon Sep 17 00:00:00 2001 From: luxick Date: Tue, 17 Mar 2026 10:51:30 +0100 Subject: [PATCH] Update section edit buttons --- css/_edit.css | 66 +++++++++++++++++++++++++++++++++++++++++++++++---- main.php | 31 ++++++++++++++++++++++++ script.js | 21 ++++++++++++++++ 3 files changed, 113 insertions(+), 5 deletions(-) diff --git a/css/_edit.css b/css/_edit.css index de55ba7..51461ab 100755 --- a/css/_edit.css +++ b/css/_edit.css @@ -105,8 +105,6 @@ div.picker button.toolbutton { margin-right: 0; margin-left: 1em; } -.dokuwiki .editBar .editButtons button { -} /* summary input and minor changes checkbox */ .dokuwiki .editBar .summary { @@ -140,9 +138,67 @@ div.picker button.toolbutton { /* section edit buttons ********************************************************************/ -/* Hidden for now - positioning was problematic */ -.dokuwiki .secedit { - display: none; +.dokuwiki .section-heading-row { + position: relative; +} + +.dokuwiki .section-heading-row > h1, +.dokuwiki .section-heading-row > h2, +.dokuwiki .section-heading-row > h3, +.dokuwiki .section-heading-row > h4, +.dokuwiki .section-heading-row > h5, +.dokuwiki .section-heading-row > h6 { + padding-right: 1.75em; +} + +[dir=rtl] .dokuwiki .section-heading-row > h1, +[dir=rtl] .dokuwiki .section-heading-row > h2, +[dir=rtl] .dokuwiki .section-heading-row > h3, +[dir=rtl] .dokuwiki .section-heading-row > h4, +[dir=rtl] .dokuwiki .section-heading-row > h5, +[dir=rtl] .dokuwiki .section-heading-row > h6 { + padding-right: 0; + padding-left: 1.75em; +} + +.dokuwiki .section-heading-row > .secedit { + display: block; + position: absolute; + top: 50%; + right: 0; + transform: translateY(-50%); +} + +[dir=rtl] .dokuwiki .section-heading-row > .secedit { + right: auto; + left: 0; +} + +.dokuwiki .section-heading-row > .secedit form { + margin: 0; +} + +.dokuwiki .section-heading-row > .secedit button { + border: 0; + padding: .15em; + min-width: 1.25em; + background: transparent; + color: @ini_icons; + font-size: 0; + line-height: 1; + cursor: pointer; +} + +.dokuwiki .section-heading-row > .secedit button::before { + content: '\270E edit'; + opacity: 0.75; + font-style: italic; + font-size: .95rem; +} + +.dokuwiki .section-heading-row > .secedit button:hover, +.dokuwiki .section-heading-row > .secedit button:focus { + color: @ini_link; } /* Sidebar should never show section edit buttons */ diff --git a/main.php b/main.php index 8cfcbb5..83a8962 100755 --- a/main.php +++ b/main.php @@ -10,6 +10,37 @@ if (!defined('DOKU_INC')) die(); /* must be run from within DokuWiki */ +// Replace default section edit buttons with a compact pencil icon +global $EVENT_HANDLER; +$EVENT_HANDLER->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', null, '_luxtools_secedit_button'); + +function _luxtools_secedit_button(\dokuwiki\Extension\Event $event, $param) { + global $ID, $INFO; + $data = $event->data; + + if (!isset($data['name']) || $data['name'] === '') { + $event->preventDefault(); + $event->result = ''; + return; + } + + $name = $data['name']; + $secid = $data['secid']; + unset($data['name'], $data['secid']); + + $params = array_merge( + ['do' => 'edit', 'rev' => $INFO['lastmod'], 'summary' => '[' . $name . '] '], + $data + ); + + $html = '
'; + $html .= html_btn('secedit', $ID, '', $params, 'post', $name); + $html .= '
'; + + $event->preventDefault(); + $event->result = $html; +} + $hasSidebar = page_findnearest($conf['sidebar']); $showSidebar = $hasSidebar && ($ACT == 'show'); ?> diff --git a/script.js b/script.js index 9917eac..f93685c 100755 --- a/script.js +++ b/script.js @@ -139,6 +139,27 @@ jQuery(function(){ } }()); + // Relocate section edit buttons next to their headings. + // DokuWiki renders the edit marker after the section content div, + // so we match by secid: .editbutton_N belongs to h*.sectioneditN. + (function enhanceSectionEditButtons() { + jQuery('#dokuwiki__content .secedit[class*="editbutton_"]').each(function () { + var $btn = jQuery(this); + var match = $btn.attr('class').match(/editbutton_(\d+)/); + if (!match) return; + + var $heading = jQuery('#dokuwiki__content .sectionedit' + match[1]); + if (!$heading.length || !$heading.is('h1,h2,h3,h4,h5,h6')) return; + + // Skip if already relocated + if ($heading.parent().hasClass('section-heading-row')) return; + + var $wrapper = jQuery('
', {'class': 'section-heading-row'}); + $heading.before($wrapper); + $wrapper.append($heading, $btn); + }); + }()); + // enhance header search with suggestions and keyboard navigation (function enhanceSearch(){ var $input = jQuery('#qsearch__in');