Maybe I am doing it wrong. What I want to do is change the input of a field when its entered or pasted. The input field changes but is not reflected on the shortcode insertion.
function arve_extract_url( changed, collection, shortcode ) {
function attr_by_name( name ) {
return _.find(
collection,
function( viewModel ) {
return name === viewModel.model.get( 'attr' );
}
);
}
var val = changed.value,
short_val = changed.value,
input = attr_by_name( 'url' ).$el.find( 'input' );
if( typeof val === 'undefined' ) {
return;
}
short_val = val.replace( 'https://www.youtube.com/watch?v=', 'https://youtu.be/' );
short_val = short_val.replace( 'http://ift.tt/1nL2Nvk', 'http://dai.ly/' );
if( short_val !== val ) {
input.val( short_val );
}
if( val.match(/src="([^"]+)/) ) {
var test_url = val.match(/src="([^"]+)/),
only_url = test_url && test_url[1];
input.val( only_url );
}
}
wp.shortcake.hooks.addAction( 'arve.url', arve_extract_url );
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire