From b17124f5dfe6df2470aad72a6a0ca3bda4ed6f12 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 22 Feb 2026 14:38:35 +0000 Subject: [PATCH] =?UTF-8?q?Dateien=20nach=20=E2=80=9Ebavarian-rank-engine/?= =?UTF-8?q?assets=E2=80=9C=20hochladen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bavarian-rank-engine/assets/geo-editor.js | 84 +++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 bavarian-rank-engine/assets/geo-editor.js diff --git a/bavarian-rank-engine/assets/geo-editor.js b/bavarian-rank-engine/assets/geo-editor.js new file mode 100644 index 0000000..7697f2c --- /dev/null +++ b/bavarian-rank-engine/assets/geo-editor.js @@ -0,0 +1,84 @@ +/* global jQuery, ajaxurl */ +jQuery( function ( $ ) { + var $box = $( '#bre-geo-box' ); + if ( ! $box.length ) return; + + var postId = $box.data( 'post-id' ); + var nonce = $box.data( 'nonce' ); + var $generate = $( '#bre-geo-generate' ); + var $clear = $( '#bre-geo-clear' ); + var $status = $( '#bre-geo-status' ); + var $summary = $( '#bre-geo-summary' ); + var $bullets = $( '#bre-geo-bullets' ); + var $faq = $( '#bre-geo-faq' ); + var $lock = $( '#bre-geo-lock' ); + + function setStatus( msg, isError ) { + $status.text( msg ).css( 'color', isError ? '#dc3232' : '#46b450' ); + if ( msg ) { + setTimeout( function () { $status.text( '' ); }, 4000 ); + } + } + + function populateFields( data ) { + $summary.val( data.summary || '' ); + $bullets.val( ( data.bullets || [] ).join( '\n' ) ); + var faqLines = ( data.faq || [] ).map( function ( item ) { + return item.q + ' | ' + item.a; + } ); + $faq.val( faqLines.join( '\n' ) ); + // AI-generated content resets the lock + $lock.prop( 'checked', false ); + } + + // Track manual edits → auto-set lock to protect from overwrite + $summary.add( $bullets ).add( $faq ).on( 'input', function () { + $lock.prop( 'checked', true ); + } ); + + if ( $generate.length ) { + $generate.on( 'click', function () { + $generate.prop( 'disabled', true ).text( '…' ); + setStatus( '' ); + $.post( ajaxurl, { + action: 'bre_geo_generate', + nonce: nonce, + post_id: postId, + } ).done( function ( res ) { + if ( res.success ) { + populateFields( res.data ); + setStatus( 'Generated ✓', false ); + $generate.text( 'Regenerate' ); + } else { + setStatus( res.data || 'Error', true ); + } + } ).fail( function () { + setStatus( 'Connection error', true ); + } ).always( function () { + $generate.prop( 'disabled', false ); + } ); + } ); + } + + if ( $clear.length ) { + $clear.on( 'click', function () { + if ( ! window.confirm( 'Really clear GEO fields?' ) ) return; + $clear.prop( 'disabled', true ); + $.post( ajaxurl, { + action: 'bre_geo_clear', + nonce: nonce, + post_id: postId, + } ).done( function ( res ) { + if ( res.success ) { + $summary.val( '' ); + $bullets.val( '' ); + $faq.val( '' ); + $lock.prop( 'checked', false ); + setStatus( 'Cleared', false ); + } + } ).always( function () { + $clear.prop( 'disabled', false ); + } ); + } ); + } +} );