[wp-trac] [WordPress Trac] #32711: Customizer Menus: link items should have view links also
WordPress Trac
noreply at wordpress.org
Fri Jun 19 07:17:26 UTC 2015
#32711: Customizer Menus: link items should have view links also
--------------------------+-----------------------------
Reporter: designsimply | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 4.3
Component: Customize | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch | Focuses: ui, javascript
--------------------------+-----------------------------
Comment (by westonruter):
Here's the logic for how the Customizer determines whether or not a URL
can be previewed: https://github.com/xwp/wordpress-
develop/blob/322b6cc54fcdcd078fe8fefd6e66ebe67dc7de16/src/wp-admin/js
/customize-controls.js#L2507-L2543
So what you could do is something like this:
{{{#!js
var originalLink = navMenuItemControl.container.find( '.original-link' );
originalLink.attr( 'target', '_blank' );
originalLink.on( 'click', function( e ) {
var previousPreviewedUrl =
wp.customize.previewer.previewUrl.get();
if ( previousPreviewedUrl === this.href ) {
// URL is already being previewed, so do nothing.
e.preventDefault();
return;
}
wp.customize.previewer.previewUrl.set( this.href );
if ( previousPreviewedUrl !==
wp.customize.previewer.previewUrl.get() ) {
/*
* URL can successfully be previewed (and will now be),
* so don't let URL open in new window.
*/
e.preventDefault();
return;
}
/*
* At this point, since the URL in the link is not the same as the
currently-previewed
* URL, and since the setter for wp.customize.previewer.previewUrl
rejected the link
* URL as not being previewable, we let the browser do the default
action and open
* the URL in a new window.
*/
} );
// Update the link whenever the menu item's URL changes.
navMenuItemControl.setting.bind( function ( newNavMenuItem, oldNavMenuItem
) {
var previousPreviewUrl;
if ( navMenuItem && newNavMenuItem.url !== oldNavMenuItem.url ) {
originalLink.attr( 'href', navMenuItem.url );
}
} );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32711#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list