PageRenderTime 21ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/snapshots/session_04/scripts/libs/jquerymobile/plugins/jquery.swipeButton-1.2.js

https://github.com/jakubc/webworks-jquery-mobile-notes
JavaScript | 73 lines | 44 code | 16 blank | 13 comment | 2 complexity | 021b12d29f6e22b8bec171b70bc9e9bf MD5 | raw file
  1. /*
  2. Name: jquery.swipeButton.js
  3. Author: Andy andyMatthews
  4. Website: http://andyMatthews.net
  5. Packed With: http://jsutility.pjoneil.net/
  6. Version: 1.2
  7. */
  8. (function($){
  9. $.fn.swipeDelete = function(o){
  10. o = $.extend( {}, $.fn.swipeDelete.defaults, o );
  11. return this.filter('[data-swipeurl]').each(function(i, el){
  12. var $e = $(el);
  13. var $parent = $(el).parent('ul');
  14. $e.bind(o.direction, function ( e ) {
  15. // reference the current item
  16. var $li = $(this);
  17. var cnt = $('.ui-btn', $li).length;
  18. // remove all currently displayed buttons
  19. $('div.ui-btn, .' + o.btnClass, $parent).animate({ width: 'toggle' }, 200, function(e) {
  20. $(this).remove();
  21. });
  22. // if there's an existing button we simply delete it, then stop
  23. if (!cnt) {
  24. // create button
  25. var $swipeBtn = $('<a>' + o.btnLabel + '</a>').attr({
  26. 'data-role': 'button',
  27. 'data-inline': 'true',
  28. 'class': (o.btnClass == 'aSwipeBtn') ? o.btnClass : o.btnClass + ' aSwipeBtn',
  29. 'data-theme': o.btnTheme,
  30. 'href': $li.data('swipeurl')
  31. })
  32. .bind('click tap', o.click);
  33. // slide insert button into list item
  34. $swipeBtn.prependTo($li).button();
  35. $li.find('.ui-btn').hide().animate({ width: 'toggle' }, 200);
  36. // override row click
  37. $('div a:not(' + o.btnClass + ')', $li).bind('click.swipe', function(e){
  38. e.stopPropagation();
  39. e.preventDefault();
  40. $(this).unbind('click.swipe');
  41. $li.removeClass('ui-btn-active').find('div.ui-btn').remove();
  42. });
  43. }
  44. });
  45. });
  46. }
  47. $.fn.swipeDelete.defaults = {
  48. direction: 'swiperight',
  49. btnLabel: 'Delete',
  50. btnTheme: 'e',
  51. btnClass: 'aSwipeBtn',
  52. click: function(e){
  53. e.preventDefault();
  54. $(this).parents('li').slideUp();
  55. }
  56. };
  57. })(jQuery);