Customize: Split out link `click.preview` and form `submit.preview` event handlers from anonymous functions into named methods on `wp.customize.Preview` for extensibility.
See #30937. Built from https://develop.svn.wordpress.org/trunk@38811 git-svn-id: http://core.svn.wordpress.org/trunk@38754 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f1ba1918c9
commit
e8bd9645df
|
@ -105,9 +105,38 @@
|
|||
preview.add( 'scheme', urlParser.protocol.replace( /:$/, '' ) );
|
||||
|
||||
preview.body = $( document.body );
|
||||
|
||||
preview.body.on( 'click.preview', 'a', function( event ) {
|
||||
var link, isInternalJumpLink;
|
||||
link = $( this );
|
||||
preview.handleLinkClick( event );
|
||||
} );
|
||||
|
||||
preview.body.on( 'submit.preview', 'form', function( event ) {
|
||||
preview.handleFormSubmit( event );
|
||||
} );
|
||||
|
||||
preview.window = $( window );
|
||||
|
||||
if ( api.settings.channel ) {
|
||||
preview.window.on( 'scroll.preview', debounce( function() {
|
||||
preview.send( 'scroll', preview.window.scrollTop() );
|
||||
}, 200 ) );
|
||||
|
||||
preview.bind( 'scroll', function( distance ) {
|
||||
preview.window.scrollTop( distance );
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle link clicks in preview.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param {jQuery.Event} event Event.
|
||||
*/
|
||||
handleLinkClick: function( event ) {
|
||||
var preview = this, link, isInternalJumpLink;
|
||||
link = $( event.target );
|
||||
|
||||
// No-op if the anchor is not a link.
|
||||
if ( _.isUndefined( link.attr( 'href' ) ) ) {
|
||||
|
@ -147,14 +176,23 @@
|
|||
|
||||
// Note: It's not relevant to send scroll because sending url message will have the same effect.
|
||||
preview.send( 'url', link.prop( 'href' ) );
|
||||
} );
|
||||
},
|
||||
|
||||
preview.body.on( 'submit.preview', 'form', function( event ) {
|
||||
var urlParser = document.createElement( 'a' );
|
||||
urlParser.href = this.action;
|
||||
/**
|
||||
* Handle form submit.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param {jQuery.Event} event Event.
|
||||
*/
|
||||
handleFormSubmit: function( event ) {
|
||||
var preview = this, urlParser, form;
|
||||
urlParser = document.createElement( 'a' );
|
||||
form = $( event.target );
|
||||
urlParser.href = form.prop( 'action' );
|
||||
|
||||
// If the link is not previewable, prevent the browser from navigating to it.
|
||||
if ( 'GET' !== this.method.toUpperCase() || ! api.isLinkPreviewable( urlParser ) ) {
|
||||
if ( 'GET' !== form.prop( 'method' ).toUpperCase() || ! api.isLinkPreviewable( urlParser ) ) {
|
||||
wp.a11y.speak( api.settings.l10n.formUnpreviewable );
|
||||
event.preventDefault();
|
||||
return;
|
||||
|
@ -180,25 +218,12 @@
|
|||
if ( urlParser.search.length > 1 ) {
|
||||
urlParser.search += '&';
|
||||
}
|
||||
urlParser.search += $( this ).serialize();
|
||||
api.preview.send( 'url', urlParser.href );
|
||||
urlParser.search += form.serialize();
|
||||
preview.send( 'url', urlParser.href );
|
||||
}
|
||||
|
||||
// Prevent default since navigation should be done via sending url message or via JS submit handler.
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
preview.window = $( window );
|
||||
|
||||
if ( api.settings.channel ) {
|
||||
preview.window.on( 'scroll.preview', debounce( function() {
|
||||
preview.send( 'scroll', preview.window.scrollTop() );
|
||||
}, 200 ) );
|
||||
|
||||
preview.bind( 'scroll', function( distance ) {
|
||||
preview.window.scrollTop( distance );
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.7-alpha-38810';
|
||||
$wp_version = '4.7-alpha-38811';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue