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.

69 lines
1.5 KiB

  1. enyo.kind({
  2. name: "enyo.AlphaJumper",
  3. classes: "enyo-alpha-jumper enyo-border-box",
  4. published: {
  5. marker: null
  6. },
  7. events: {
  8. onAlphaJump: ""
  9. },
  10. handlers: {
  11. ondown: "down",
  12. onmove: "move",
  13. onup: "up"
  14. },
  15. initComponents: function() {
  16. for (var s="A".charCodeAt(0), i=s; i<s+26; i++) {
  17. this.createComponent({content: String.fromCharCode(i)});
  18. }
  19. this.inherited(arguments);
  20. },
  21. down: function(inSender, inEvent) {
  22. if (this.tracking) {
  23. enyo.dispatcher.release();
  24. }
  25. this.tracking = true;
  26. if (this.hasNode()) {
  27. var b = this.node.getBoundingClientRect();
  28. // IE8 does not return width
  29. var w = (b.width === undefined) ? (b.right - b.left) : b.width;
  30. this.x = b.left + w/2;
  31. }
  32. enyo.dispatcher.capture(this);
  33. this.track(inEvent);
  34. },
  35. move: function(inSender, inEvent) {
  36. if (this.tracking) {
  37. this.track(inEvent);
  38. }
  39. },
  40. up: function() {
  41. if (this.tracking) {
  42. enyo.dispatcher.release();
  43. this.setMarker(null);
  44. this.tracking = false;
  45. }
  46. },
  47. track: function(inEvent) {
  48. var n = document.elementFromPoint(this.x, inEvent.pageY);
  49. var c = this.nodeToControl(n);
  50. if (c) {
  51. this.setMarker(c);
  52. }
  53. },
  54. nodeToControl: function(inNode) {
  55. for (var i=0, c$=this.controls, c; c=c$[i]; i++) {
  56. if (inNode == c.hasNode()) {
  57. return c;
  58. }
  59. }
  60. },
  61. markerChanged: function(inLast) {
  62. if (inLast) {
  63. inLast.removeClass("active");
  64. }
  65. if (this.marker) {
  66. this.marker.addClass("active");
  67. this.doAlphaJump({letter: this.marker.getContent(), index: this.marker.indexInContainer()});
  68. }
  69. }
  70. });