Skip to content

Instantly share code, notes, and snippets.

@itsPG
Forked from altintx/swipe_to_delete.js
Last active August 29, 2015 14:24
Show Gist options
  • Save itsPG/6d033490a3d8b51f6021 to your computer and use it in GitHub Desktop.
Save itsPG/6d033490a3d8b51f6021 to your computer and use it in GitHub Desktop.
/* Assuming:
* dataview is a { xtype: "list" }
* dataview.itemTpl includes a <div class="deleteplaceholder"></div>
*
* Delete button will disappear as soon as something is touched
*/
dataview.on("itemswipe", function(dataview, ix, target, record, event, options) {
if (event.direction == "left") {
var del = Ext.create("Ext.Button", {
ui: "decline",
text: "Delete",
style: "position:absolute;right:0.125in;",
handler: function() {
record.stores[0].remove(record);
record.stores[0].sync();
}
});
var removeDeleteButton = function() {
Ext.Anim.run(del, 'fade', {
after: function() {
del.destroy();
},
out: true
});
};
del.renderTo(Ext.DomQuery.selectNode(".deleteplaceholder", target.dom));
dataview.on({
single: true,
buffer: 250,
itemtouchstart: removeDeleteButton
});
dataview.element.on({
single: true,
buffer: 250,
touchstart: removeDeleteButton
});
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment