Skip to content

Instantly share code, notes, and snippets.

@commadelimited
Created January 19, 2012 19:52
Show Gist options
  • Save commadelimited/1642163 to your computer and use it in GitHub Desktop.
Save commadelimited/1642163 to your computer and use it in GitHub Desktop.
Add swipe to delete
$(function(){
$('div').live('pageshow',function(event,ui){
if ( event.target.id.indexOf('swipedelete') >= 0) {
// remove any existing swipe areas
$('.aDeleteBtn').remove();
// add swipe event to the list item
$('ul li').bind('swiperight', function(e){
// reference the just swiped list item
var $li = $(this);
// remove all buttons first
$('.aDeleteBtn').remove();
// create buttons and div container
var $deleteBtn = $('<a>Delete</a>').attr({
'class': 'aDeleteBtn ui-btn-up-r',
'href': 'some/link/page.html?nID=' + $li.data('nid')
});
// insert swipe div into list item
$li.prepend($deleteBtn);
});
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment