not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.7 KiB

  1. /**
  2. An item that slides to the left to reveal Delete and Cancel buttons. Pressing the Cancel button will slide the item back into place and generate
  3. an onCancel event. Pressing the Delete button will immediately position the content back in place and generate an onDelete event.
  4. A SwipeableItem contains methods for styling its content and these should be used to effect styling on the row content. Add css classes via
  5. the contentClasses property and the methods add|remove|has|addRemove<ContentClass>. Alter css styles via the applyContentStyle method.
  6. {kind: "onyx.SwipeableItem", onCancel: "canceled", onDelete: "deleted"}
  7. */
  8. enyo.kind({
  9. name: "onyx.SwipeableItem",
  10. kind: "onyx.Item",
  11. classes: "onyx-swipeable-item",
  12. published: {
  13. //* Add custom CSS classes via the contentClasses property to style the SwipeableItem's content
  14. contentClasses: "",
  15. //* Set to true to prevent a drag from bubbling beyond the SwipeableItem.
  16. preventDragPropagation: false
  17. },
  18. defaultContentClasses: "onyx-swipeable-item-content",
  19. handlers: {
  20. ondown: "down"
  21. },
  22. events: {
  23. /**
  24. Fires when a SwipeableItem's delete button has been triggered
  25. This event does not fire when programatically deleting a SwipeableItem instance
  26. */
  27. onDelete: "",
  28. /**
  29. Fires when a SwipeableItem's cancel button has been triggered
  30. This event does not fire when selecting a second SwipeableItem, causing the first to cancel itself programatically
  31. */
  32. onCancel: ""
  33. },
  34. components: [
  35. {name: "client", kind: "Slideable", min: -100, unit: "%", ondragstart: "clientDragStart"},
  36. {name: "confirm", kind: "onyx.Toolbar", canGenerate: false, classes: "onyx-swipeable-item-confirm enyo-fit", style: "text-align: center;", ontap: "confirmTap", components: [
  37. {kind: "onyx.Button", content: "Delete", ontap: "deleteTap"},
  38. {kind: "onyx.Button", content: "Cancel", ontap: "cancelTap"}
  39. ]}
  40. ],
  41. //* @protected
  42. swiping: -1,
  43. create: function() {
  44. this.inherited(arguments);
  45. this.contentClassesChanged();
  46. },
  47. //* @public
  48. //* Resets the sliding position of the SwipeableItem currently displaying confirmation options
  49. reset: function() {
  50. this.applyStyle("position", null);
  51. this.$.confirm.setShowing(false);
  52. // stop animating if we reset.
  53. this.$.client.getAnimator().stop();
  54. this.$.client.setValue(0);
  55. },
  56. //* @protected
  57. contentClassesChanged: function() {
  58. this.$.client.setClasses(this.defaultContentClasses + " " + this.contentClasses);
  59. },
  60. //* @public
  61. //* Applies a single style value to the SwipeableItem
  62. applyContentStyle: function(inStyle, inValue) {
  63. this.$.client.applyStyle(inStyle, inValue);
  64. },
  65. //* Applies a CSS class to the SwipeableItem's contentClasses
  66. addContentClass: function(inClass) {
  67. this.$.client.addClass(inClass);
  68. },
  69. //* Removes a CSS class to the SwipeableItem's contentClasses
  70. removeContentClass: function(inClass) {
  71. this.$.client.removeClass(inClass);
  72. },
  73. //* Returns true if the _class_ attribute contains a substring matching _inClass_
  74. hasContentClass: function(inClass) {
  75. return this.$.client.hasClass(inClass);
  76. },
  77. /**
  78. Adds or removes substring _inClass_ from the _class_ attribute of this object based
  79. on the value of _inTrueToAdd_.
  80. If _inTrueToAdd_ is truthy, then _inClass_ is added; otherwise, _inClass_ is removed.
  81. */
  82. addRemoveContentClass: function(inClass, inAdd) {
  83. this.$.client.addRemoveClass(inClass, inAdd);
  84. },
  85. //* @protected
  86. generateHtml: function() {
  87. this.reset();
  88. return this.inherited(arguments);
  89. },
  90. contentChanged: function() {
  91. this.$.client.setContent(this.content);
  92. },
  93. confirmTap: function() {
  94. return true;
  95. },
  96. deleteTap: function(inSender, inEvent) {
  97. this.reset();
  98. this.doDelete();
  99. return true;
  100. },
  101. cancelTap: function(inSender, inEvent) {
  102. this.$.client.animateToMax();
  103. this.doCancel();
  104. return true;
  105. },
  106. down: function(inSender, inEvent) {
  107. // on down, remove swiping state
  108. var last = this.swiping;
  109. this.swiping = inEvent.index;
  110. var flyweight = inEvent.flyweight;
  111. if (this.swiping != last && last >= 0 && flyweight) {
  112. flyweight.performOnRow(last, enyo.bind(this, function() {
  113. this.reset();
  114. }));
  115. }
  116. },
  117. clientDragStart: function(inSender, inEvent) {
  118. if (inSender.dragging) {
  119. var flyweight = inEvent.flyweight;
  120. if (flyweight) {
  121. flyweight.prepareRow(inEvent.index);
  122. // if needed, render confirm.
  123. // NOTE: position relative so can enyo-fit confirm; apply only when confirm needed
  124. // because it's a known rendering slowdown.
  125. this.applyStyle("position", "relative");
  126. this.$.confirm.setShowing(true);
  127. if (!this.$.confirm.hasNode()) {
  128. // NOTE: prepend so Slideable will be on top.
  129. this.$.confirm.prepend = true;
  130. this.$.confirm.render();
  131. this.$.confirm.prepend = false;
  132. }
  133. // note: can't teardown.
  134. }
  135. }
  136. return this.preventDragPropagation;
  137. }
  138. });