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.

179 lines
4.6 KiB

  1. /**
  2. A list that provides a pull-to-refresh feature, which allows new data to be
  3. retrieved and updated in the list.
  4. PulldownList provides the onPullRelease event to allow an application to start
  5. retrieving new data. The onPullComplete event indicates that the pull is
  6. complete and it's time to update the list with the new data.
  7. {name: "list", kind: "PulldownList", onSetupItem: "setupItem",
  8. onPullRelease: "pullRelease", onPullComplete: "pullComplete",
  9. components: [
  10. {name: "item"}
  11. ]}
  12. pullRelease: function() {
  13. this.search();
  14. },
  15. processSearchResults: function(inRequest, inResponse) {
  16. this.results = inResponse.results;
  17. this.$.list.setCount(this.results.length);
  18. this.$.list.completePull();
  19. },
  20. pullComplete: function() {
  21. this.$.list.reset();
  22. }
  23. */
  24. enyo.kind({
  25. name: "enyo.PulldownList",
  26. kind: "List",
  27. touch: true,
  28. pully: null,
  29. pulldownTools: [
  30. {name: "pulldown", classes: "enyo-list-pulldown", components: [
  31. {name: "puller", kind: "Puller"}
  32. ]}
  33. ],
  34. events: {
  35. onPullStart: "",
  36. onPullCancel: "",
  37. onPull: "",
  38. onPullRelease: "",
  39. onPullComplete: ""
  40. },
  41. handlers: {
  42. onScrollStart: "scrollStartHandler",
  43. onScroll: "scrollHandler",
  44. onScrollStop: "scrollStopHandler",
  45. ondragfinish: "dragfinish"
  46. },
  47. //
  48. pullingMessage: "Pull down to refresh...",
  49. pulledMessage: "Release to refresh...",
  50. loadingMessage: "Loading...",
  51. //
  52. pullingIconClass: "enyo-puller-arrow enyo-puller-arrow-down",
  53. pulledIconClass: "enyo-puller-arrow enyo-puller-arrow-up",
  54. loadingIconClass: "",
  55. //* @protected
  56. create: function() {
  57. var p = {kind: "Puller", showing: false, text: this.loadingMessage, iconClass: this.loadingIconClass, onCreate: "setPully"};
  58. this.listTools.splice(0, 0, p);
  59. this.inherited(arguments);
  60. this.setPulling();
  61. },
  62. initComponents: function() {
  63. this.createChrome(this.pulldownTools);
  64. this.accel = enyo.dom.canAccelerate();
  65. this.translation = this.accel ? "translate3d" : "translate";
  66. this.inherited(arguments);
  67. },
  68. setPully: function(inSender, inEvent) {
  69. this.pully = inEvent.originator;
  70. },
  71. scrollStartHandler: function() {
  72. this.firedPullStart = false;
  73. this.firedPull = false;
  74. this.firedPullCancel = false;
  75. },
  76. scrollHandler: function(inSender) {
  77. if (this.completingPull) {
  78. this.pully.setShowing(false);
  79. }
  80. var s = this.getStrategy().$.scrollMath;
  81. var over = s.y;
  82. if (s.isInOverScroll() && over > 0) {
  83. enyo.dom.transformValue(this.$.pulldown, this.translation, "0," + over + "px" + (this.accel ? ",0" : ""));
  84. if (!this.firedPullStart) {
  85. this.firedPullStart = true;
  86. this.pullStart();
  87. this.pullHeight = this.$.pulldown.getBounds().height;
  88. }
  89. if (over > this.pullHeight && !this.firedPull) {
  90. this.firedPull = true;
  91. this.firedPullCancel = false;
  92. this.pull();
  93. }
  94. if (this.firedPull && !this.firedPullCancel && over < this.pullHeight) {
  95. this.firedPullCancel = true;
  96. this.firedPull = false;
  97. this.pullCancel();
  98. }
  99. }
  100. },
  101. scrollStopHandler: function() {
  102. if (this.completingPull) {
  103. this.completingPull = false;
  104. this.doPullComplete();
  105. }
  106. },
  107. dragfinish: function() {
  108. if (this.firedPull) {
  109. var s = this.getStrategy().$.scrollMath;
  110. s.setScrollY(s.y - this.pullHeight);
  111. this.pullRelease();
  112. }
  113. },
  114. //* @public
  115. //* To signal that the list should execute pull completion. This usually be called after the application has received the new data.
  116. completePull: function() {
  117. this.completingPull = true;
  118. this.$.strategy.$.scrollMath.setScrollY(this.pullHeight);
  119. this.$.strategy.$.scrollMath.start();
  120. },
  121. //* @protected
  122. pullStart: function() {
  123. this.setPulling();
  124. this.pully.setShowing(false);
  125. this.$.puller.setShowing(true);
  126. this.doPullStart();
  127. },
  128. pull: function() {
  129. this.setPulled();
  130. this.doPull();
  131. },
  132. pullCancel: function() {
  133. this.setPulling();
  134. this.doPullCancel();
  135. },
  136. pullRelease: function() {
  137. this.$.puller.setShowing(false);
  138. this.pully.setShowing(true);
  139. this.doPullRelease();
  140. },
  141. setPulling: function() {
  142. this.$.puller.setText(this.pullingMessage);
  143. this.$.puller.setIconClass(this.pullingIconClass);
  144. },
  145. setPulled: function() {
  146. this.$.puller.setText(this.pulledMessage);
  147. this.$.puller.setIconClass(this.pulledIconClass);
  148. }
  149. });
  150. enyo.kind({
  151. name: "enyo.Puller",
  152. classes: "enyo-puller",
  153. published: {
  154. text: "",
  155. iconClass: ""
  156. },
  157. events: {
  158. onCreate: ""
  159. },
  160. components: [
  161. {name: "icon"},
  162. {name: "text", tag: "span", classes: "enyo-puller-text"}
  163. ],
  164. create: function() {
  165. this.inherited(arguments);
  166. this.doCreate();
  167. this.textChanged();
  168. this.iconClassChanged();
  169. },
  170. textChanged: function() {
  171. this.$.text.setContent(this.text);
  172. },
  173. iconClassChanged: function() {
  174. this.$.icon.setClasses(this.iconClass);
  175. }
  176. });