[wp-trac] [WordPress Trac] #18590: Swap out "return false" JS calls for preventDefault
WordPress Trac
wp-trac at lists.automattic.com
Mon Sep 5 19:08:41 UTC 2011
#18590: Swap out "return false" JS calls for preventDefault
----------------------------+------------------------------
Reporter: Viper007Bond | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Administration | Version: 3.3
Severity: normal | Resolution:
Keywords: needs-patch |
----------------------------+------------------------------
Comment (by Viper007Bond):
Here's my code incase things are unclear:
{{{
jQuery(document).ready(function($) {
// ID tracker field
var IDtracker = $('<input>').attr({
type: 'hidden',
id: ADASIParams.idtracker,
name: ADASIParams.idtracker,
value: ''
}).prependTo('#update-nav-menu');
function adasi_add_checkbox( item ) {
// Skip items that are known not to be hierarchical post
types or that we already modified
if ( $(item).is('.adasi-checked, .menu-item-custom, .menu-
item-category, .menu-item-post_tag') ) {
return;
}
// Don't check this item again
$(item).addClass('adasi-checked');
var itemID = parseInt( $(item).attr('id').replace('menu-
item-', ''), 10 );
// Gotta figure it out in PHP, so use an AJAX call
jQuery.post(
ajaxurl,
{
action: ADASIParams.ajaxaction,
id: itemID
},
function( response ){
if ( response && response.add ) {
// Track IDs to check the POST for
IDtracker.val( IDtracker.val() +
',' + itemID );
// Add the checkbox
var checkboxid =
ADASIParams.checkboxprefix + itemID;
$(item).find('.menu-item-actions
.link-to-original').after('<p><label><input type="checkbox" id="' +
checkboxid + '" name="' + checkboxid + '" value="1" /> ' +
ADASIParams.checkboxdesc + '</label></p>');
if ( response.checked ) {
$('#' +
checkboxid).prop('checked', true);
}
}
},
'json'
);
}
// Try adding checkboxes to all existing menu items
$('.menu-item').each(function(){
adasi_add_checkbox( this );
});
// When hovering over a menu item added using Javascript, try
adding a checkbox to it.
// Props DD32 for mouseover hack to get around return false;
inside other click bound event.
$('.menu-item.pending').live('mouseover', function(){
adasi_add_checkbox( this );
});
});
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/18590#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list