@@ -275,6 +275,7 @@ var BLOECKS = (function($) {
275
275
initDragDrop ( ) ;
276
276
checkForMessages ( ) ;
277
277
initCopyPasteHandlers ( ) ;
278
+ // Button states will be updated after loadMultiClipboardFromServer() completes
278
279
} ) ;
279
280
280
281
// Check for BLOECKS messages and show as toasts
@@ -489,6 +490,7 @@ var BLOECKS = (function($) {
489
490
checkForMessages ( ) ;
490
491
initCopyPasteHandlers ( ) ;
491
492
checkForScrollTarget ( ) ; // Add this call!
493
+ // Button states will be updated via loadMultiClipboardFromServer()
492
494
} , 100 ) ;
493
495
}
494
496
} ) ;
@@ -502,6 +504,7 @@ var BLOECKS = (function($) {
502
504
checkForMessages ( ) ;
503
505
initCopyPasteHandlers ( ) ;
504
506
checkForScrollTarget ( ) ; // Add this call!
507
+ // Button states will be updated via loadMultiClipboardFromServer()
505
508
} , 150 ) ;
506
509
}
507
510
} ) ;
@@ -524,6 +527,7 @@ var BLOECKS = (function($) {
524
527
checkForMessages ( ) ;
525
528
initCopyPasteHandlers ( ) ;
526
529
checkForScrollTarget ( ) ;
530
+ // Button states will be updated via loadMultiClipboardFromServer()
527
531
} , 100 ) ;
528
532
}
529
533
} ) ;
@@ -651,6 +655,11 @@ var BLOECKS = (function($) {
651
655
container : '#rex-js-page-main-content' ,
652
656
fragment : '#rex-js-page-main-content' ,
653
657
push : false // Important: don't push to history
658
+ } ) . done ( function ( ) {
659
+ // After PJAX reload, restore button states based on clipboard
660
+ setTimeout ( function ( ) {
661
+ updateAllButtonStates ( ) ;
662
+ } , 100 ) ;
654
663
} ) ;
655
664
} , 800 ) ; // Shorter wait time
656
665
} else {
@@ -706,13 +715,42 @@ var BLOECKS = (function($) {
706
715
}
707
716
708
717
updatePasteButtons ( ) ;
718
+ // Update button states after adding
719
+ updateAllButtonStates ( ) ;
709
720
}
710
721
711
722
function removeFromMultiClipboard ( sliceId ) {
712
723
multiClipboard = multiClipboard . filter ( function ( item ) {
713
724
return item . source_slice_id !== sliceId ;
714
725
} ) ;
715
726
updatePasteButtons ( ) ;
727
+ // Update button states after removal
728
+ updateAllButtonStates ( ) ;
729
+ }
730
+
731
+ // Update all copy/cut button states based on current clipboard
732
+ function updateAllButtonStates ( ) {
733
+ // Reset all buttons first
734
+ $ ( '.bloecks-copy, .bloecks-cut' ) . each ( function ( ) {
735
+ var $btn = $ ( this ) ;
736
+ $btn . removeClass ( 'btn-success' )
737
+ . removeClass ( 'active' )
738
+ . removeAttr ( 'data-bloecks-cutncopy-iscopied' ) ;
739
+ } ) ;
740
+
741
+ // Mark buttons for items in clipboard
742
+ multiClipboard . forEach ( function ( item ) {
743
+ var sliceId = item . source_slice_id ;
744
+ var action = item . action ;
745
+ var selector = '.bloecks-' + action + '[data-slice-id="' + sliceId + '"]' ;
746
+
747
+ $ ( selector ) . each ( function ( ) {
748
+ var $btn = $ ( this ) ;
749
+ $btn . addClass ( 'btn-success' )
750
+ . addClass ( 'active' )
751
+ . attr ( 'data-bloecks-cutncopy-iscopied' , 'true' ) ;
752
+ } ) ;
753
+ } ) ;
716
754
}
717
755
718
756
function clearMultiClipboard ( ) {
@@ -1051,6 +1089,8 @@ var BLOECKS = (function($) {
1051
1089
// Re-check multi-clipboard config after navigation
1052
1090
if ( typeof BLOECKS_MULTI_CLIPBOARD !== 'undefined' && BLOECKS_MULTI_CLIPBOARD ) {
1053
1091
setMultiClipboardEnabled ( true ) ;
1092
+ // Update button states after PJAX reload
1093
+ updateAllButtonStates ( ) ;
1054
1094
loadMultiClipboardFromServer ( ) ;
1055
1095
}
1056
1096
} , 100 ) ;
@@ -1083,6 +1123,8 @@ var BLOECKS = (function($) {
1083
1123
}
1084
1124
1085
1125
updatePasteButtons ( ) ;
1126
+ // Update button states after loading from server
1127
+ updateAllButtonStates ( ) ;
1086
1128
}
1087
1129
} ,
1088
1130
error : function ( ) {
@@ -1112,6 +1154,7 @@ var BLOECKS = (function($) {
1112
1154
removeFromMultiClipboard : removeFromMultiClipboard ,
1113
1155
clearMultiClipboard : clearMultiClipboard ,
1114
1156
loadMultiClipboardFromServer : loadMultiClipboardFromServer ,
1157
+ updateAllButtonStates : updateAllButtonStates ,
1115
1158
version : '2.5.0'
1116
1159
} ;
1117
1160
@@ -1126,6 +1169,9 @@ $(document).ready(function() {
1126
1169
if ( typeof BLOECKS_MULTI_CLIPBOARD !== 'undefined' && BLOECKS_MULTI_CLIPBOARD ) {
1127
1170
BLOECKS . setMultiClipboardEnabled ( true ) ;
1128
1171
}
1172
+
1173
+ // Load clipboard status from server (which will call updateAllButtonStates)
1174
+ BLOECKS . loadMultiClipboardFromServer ( ) ;
1129
1175
} ) ;
1130
1176
1131
1177
// Re-initialize after PJAX navigation
@@ -1140,6 +1186,7 @@ $(document).on('pjax:complete pjax:end rex:ready', function() {
1140
1186
}
1141
1187
1142
1188
// Load current clipboard status to sync frontend with backend
1189
+ // This will also call updateAllButtonStates() in its success callback
1143
1190
BLOECKS . loadMultiClipboardFromServer ( ) ;
1144
1191
1145
1192
// Check for scroll target after PJAX navigation (important for paste operations)
@@ -1165,6 +1212,10 @@ if (typeof MutationObserver !== 'undefined') {
1165
1212
if ( shouldReinit ) {
1166
1213
setTimeout ( function ( ) {
1167
1214
BLOECKS . initCopyPasteHandlers ( ) ;
1215
+ // Update button states when new buttons are added
1216
+ if ( typeof BLOECKS . updateAllButtonStates === 'function' ) {
1217
+ BLOECKS . updateAllButtonStates ( ) ;
1218
+ }
1168
1219
} , 50 ) ;
1169
1220
}
1170
1221
} ) ;
0 commit comments