Add draft-preview plugin v1.0.5

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-18 23:45:01 +02:00
parent 582b8629c4
commit e8c04adbcb
26 changed files with 1396 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
(function(win, doc) {
'use strict';
if ( location.pathname.includes( 'pages' ) && document.querySelector( '#titlebar-save' ) )
{
// define preview URL and neighbour
let route = ( typeof draft_preview_route == 'string' ) ? draft_preview_route : '/preview';
let lang = ( typeof draft_preview_language == 'string' ) ? draft_preview_language : '';
const previewPath = lang + route + '?slug=/' + GravAdmin.config.route;
const ancestor = document.querySelector( '#titlebar-button-delete' );
// create button (clone of the original preview btn)
let button = doc.createElement( 'a' );
button.href = previewPath;
button.id = 'titlebar-button-preview';
button.target = "_blank";
button.classList.add( 'button' );
button.innerHTML = '<i class="fa fa-eye"></i>';
// insert button
ancestor.insertAdjacentElement( 'beforebegin', button );
// no CSS flex, so we need a space for spacing…
doc.querySelector( '.button-bar' ).insertBefore( doc.createTextNode( ' ' ), ancestor );
}
})(window, document);