@@ -638,11 +638,6 @@ async function openLinksInParentFrame( calypsoPort ) {
638
638
const popoverContainer = getPopoverFallbackContainer ( ) ;
639
639
popoverContainer && popoverSlotObserver . observe ( popoverContainer , { childList : true } ) ;
640
640
641
- const { createNewPostUrl } = calypsoifyGutenberg ;
642
- if ( ! createNewPostUrl ) {
643
- return ;
644
- }
645
-
646
641
// Handle the view post link in the snackbar, which unfortunately has a click
647
642
// handler which stops propagation, so we can't override it with the global handler.
648
643
const updateViewPostLinkNotice = ( ) => {
@@ -671,90 +666,6 @@ async function openLinksInParentFrame( calypsoPort ) {
671
666
'Could not find the snackbar list element so, the "View post" link may open inside the iframe.'
672
667
) ;
673
668
}
674
-
675
- // Create a new post link in block settings sidebar for Query block
676
- const tryToReplaceCreateNewPostLink = ( ) => {
677
- // We need to wait for the rendering to be finished.
678
- // This is mostly for Safari, but it doesn't hurt for other browsers.
679
- setTimeout ( ( ) => {
680
- const hyperlink = document . querySelector ( '.wp-block-query__create-new-link a' ) ;
681
- if ( hyperlink ) {
682
- hyperlink . href = createNewPostUrl ;
683
- hyperlink . target = '_top' ;
684
- }
685
- } ) ;
686
- } ;
687
- const createNewPostLinkObserver = new window . MutationObserver ( tryToReplaceCreateNewPostLink ) ;
688
-
689
- const shouldReplaceCreateNewPostLinksFor = ( node ) =>
690
- createNewPostUrl && node . classList . contains ( 'interface-interface-skeleton__sidebar' ) ;
691
-
692
- const observeSidebarMutations = ( node ) => {
693
- if (
694
- // Block settings sidebar for Query block.
695
- shouldReplaceCreateNewPostLinksFor ( node )
696
- ) {
697
- createNewPostLinkObserver . observe ( node , { childList : true , subtree : true } ) ;
698
- // If a Query block is selected, then the sidebar will
699
- // directly open on the block settings tab
700
- tryToReplaceCreateNewPostLink ( ) ;
701
- }
702
- } ;
703
-
704
- const unobserveSidebarMutations = ( node ) => {
705
- if (
706
- // Block settings sidebar for Query block.
707
- shouldReplaceCreateNewPostLinksFor ( node )
708
- ) {
709
- createNewPostLinkObserver . disconnect ( ) ;
710
- }
711
- } ;
712
-
713
- // This observer functions as a "parent" observer, which connects and disconnects
714
- // "child" observers as the relevant sidebar settings appear and disappear in the DOM.
715
- const sidebarsObserver = new window . MutationObserver ( ( mutations ) => {
716
- for ( const record of mutations ) {
717
- // We are checking for added nodes here to start observing for more specific changes.
718
- for ( const node of record . addedNodes ) {
719
- observeSidebarMutations ( node ) ;
720
- }
721
-
722
- // We are checking the removed nodes here to disconect
723
- // the correct observer when a node is removed.
724
- for ( const node of record . removedNodes ) {
725
- unobserveSidebarMutations ( node ) ;
726
- }
727
- }
728
- } ) ;
729
-
730
- // If one of the sidebar elements we're interested in is already present, start observing
731
- // them for changes immediately.
732
- const sidebars = document . querySelectorAll (
733
- '.interface-interface-skeleton__sidebar, .interface-interface-skeleton__secondary-sidebar'
734
- ) ;
735
- for ( const sidebar of sidebars ) {
736
- observeSidebarMutations ( sidebar ) ;
737
- }
738
-
739
- // Add and remove the sidebar observers as the sidebar elements appear and disappear.
740
- // They are always direct children of the body element.
741
- const body = document . querySelector ( '.interface-interface-skeleton__body' ) ;
742
- sidebarsObserver . observe ( body , { childList : true } ) ;
743
-
744
- // Sidebar might already be open before this script is executed.
745
- // post and site editors
746
- if ( createNewPostUrl ) {
747
- const sidebarComponentsPanel = document . querySelector (
748
- '.interface-interface-skeleton__sidebar .components-panel'
749
- ) ;
750
- if ( sidebarComponentsPanel ) {
751
- createNewPostLinkObserver . observe ( sidebarComponentsPanel , {
752
- childList : true ,
753
- subtree : true ,
754
- } ) ;
755
- tryToReplaceCreateNewPostLink ( ) ;
756
- }
757
- }
758
669
}
759
670
760
671
/**
0 commit comments