@@ -51,7 +51,7 @@ <h1 class="h3">PicoCode — Local Codebase Assistant</h1>
5151 < div class ="col-lg-4 ">
5252 < div class ="card ">
5353 < div class ="card-body ">
54- < h5 class ="card-title " style ="cursor: pointer; " onclick =" toggleSection(' configSection') ">
54+ < h5 class ="card-title toggle-section " style ="cursor: pointer; " data-section =" configSection ">
5555 Configuration < span id ="configToggle "> ▼</ span >
5656 </ h5 >
5757 < div id ="configSection ">
@@ -67,7 +67,7 @@ <h5 class="card-title" style="cursor: pointer;" onclick="toggleSection('configSe
6767
6868 < div class ="card mt-3 ">
6969 < div class ="card-body ">
70- < h5 class ="card-title " style ="cursor: pointer; " onclick =" toggleSection(' addProjectSection') ">
70+ < h5 class ="card-title toggle-section " style ="cursor: pointer; " data-section =" addProjectSection ">
7171 Add New Project < span id ="addProjectToggle "> ▼</ span >
7272 </ h5 >
7373 < div id ="addProjectSection ">
@@ -162,20 +162,6 @@ <h5 class="card-title">Chat</h5>
162162
163163 < script >
164164 $ ( document ) . ready ( function ( ) {
165- // Toggle section visibility
166- window . toggleSection = function ( sectionId ) {
167- const $section = $ ( '#' + sectionId ) ;
168- const $toggle = $ ( '#' + sectionId . replace ( 'Section' , 'Toggle' ) ) ;
169-
170- if ( $section . css ( 'display' ) === 'none' ) {
171- $section . show ( ) ;
172- $toggle . text ( '▼' ) ;
173- } else {
174- $section . hide ( ) ;
175- $toggle . text ( '▶' ) ;
176- }
177- } ;
178-
179165 // Configure marked for markdown rendering
180166 marked . setOptions ( {
181167 highlight : function ( code , lang ) {
@@ -204,13 +190,30 @@ <h5 class="card-title">Chat</h5>
204190 return DOMPurify . sanitize ( rawHtml ) ;
205191 }
206192
207- window . deleteMessage = function ( idx ) {
193+ // Toggle section visibility using event delegation
194+ $ ( document ) . on ( 'click' , '.toggle-section' , function ( ) {
195+ const sectionId = $ ( this ) . data ( 'section' ) ;
196+ const $section = $ ( '#' + sectionId ) ;
197+ const $toggle = $ ( '#' + sectionId . replace ( 'Section' , 'Toggle' ) ) ;
198+
199+ if ( $section . css ( 'display' ) === 'none' ) {
200+ $section . show ( ) ;
201+ $toggle . text ( '▼' ) ;
202+ } else {
203+ $section . hide ( ) ;
204+ $toggle . text ( '▶' ) ;
205+ }
206+ } ) ;
207+
208+ // Delete message using event delegation
209+ $ ( document ) . on ( 'click' , '.delete-message-btn' , function ( ) {
210+ const idx = $ ( this ) . data ( 'index' ) ;
208211 if ( confirm ( 'Delete this message?' ) ) {
209212 chatHistory . splice ( idx , 1 ) ;
210213 localStorage . setItem ( "picocode_chat_history" , JSON . stringify ( chatHistory ) ) ;
211214 renderChat ( ) ;
212215 }
213- } ;
216+ } ) ;
214217
215218 function renderChat ( ) {
216219 if ( chatHistory . length === 0 ) {
@@ -227,7 +230,7 @@ <h5 class="card-title">Chat</h5>
227230 <div class="card-body">
228231 <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
229232 <strong>${ msg . role === 'user' ? 'You' : 'PicoCode' } </strong>
230- <button onclick="deleteMessage( ${ idx } )" class="btn btn-sm btn-outline-danger" style="padding: 2px 8px; font-size: 12px;">×</button>
233+ <button class="btn btn-sm btn-outline-danger delete-message-btn" data-index=" ${ idx } " style="padding: 2px 8px; font-size: 12px;">×</button>
231234 </div>
232235 ` ;
233236
0 commit comments