Requires

Provides

Search.js

Search field with a dropdown

License:
Public domain (http://unlicense.org).
Authors:
Yaroslaff Fedin
  1. 30
  2. 31
  3. 32
  4. 33
  5. 34
  6. 35
  7. 36
  8. 37
  9. 38
  10. 39
  11. 40
  12. 41
  13. 42
  14. 43
  15. 44
  16. 45
  17. 46
  18. 47
  19. 48
  20. 49
  21. 50
  22. 51
  23. 52
  24. 53
  25. 54
  26. 55
  27. 56
  28. 57
  29. 58
  30. 59
  31. 60
  32. 61
  33. 62
  34. 63
  35. 64
  36. 65
  37. 66
  38. 67
  39. 68
  40. 69
  41. 70
  42. 71
  43. 72
  44. 73
  45. 74
  46. 75
  47. 76
  48. 77
  49. 78
  50. 79
  51. 80
  52. 81
  53. 82
  54. 83
  55. 84
  56. 85
  57. 86
  58. 87
  59. 88
  60. 89
  61. 90
  62. 91
  63. 92
  64. 93
  65. 94
  66. 95
  67. 96
  68. 97
  69. 98
  70. 99
  71. 100
  72. 101
  73. 102
  74. 103
  75. 104
  76. 105
  77. 106
  78. 107
  79. 108
  80. 109
  81. 110
  82. 111
  83. 112
  84. 113
  85. 114
  86. 115
  87. 116
  88. 117
  89. 118
  90. 119
  91. 120
  92. 121
  93. 122
  94. 123
  95. 124
  96. 125
  97. 126
  98. 127
  99. 128
  100. 129
  101. 130
  102. 131
  103. 132
  104. 133
  105. 134
  106. 135
  107. 136
  108. 137
  109. 138
  110. 139
  111. 140
  112. 141
  113. 142
  114. 143
  115. 144
  116. 145
  117. 146
  118. 147
  119. 148
  120. 149
  121. 150
  122. 151
  123. 152
  124. 153
  125. 154
  126. 155
  127. 156
  128. 157
  129. 158
  130. 159
  131. 160
  132. 161
  133. 162
  134. 163
LSD.Widget.Input.Search = new Class({ Includes: [ LSD.Widget.Input, LSD.Trait.Expectations, LSD.Trait.Proxies, LSD.Trait.Menu.Stateful, LSD.Trait.List, LSD.Trait.Choice, LSD.Trait.Value, LSD.Trait.Observer.Stateful ], States: { 'detailed': ['enrich', 'clean'], 'uniconed': ['uniconize', 'iconize'] }, options: { tag: 'input', layout: { item: 'input-option', children: { '>icon': {}, '>button': {} } }, events: { icon: { click: 'expand' }, button: { click: 'clear' }, self: { set: 'setIcon', focus: 'expand' } }, menu: { position: 'bottom' } }, attach: Macro.onion(function() { if (this.hasItems()) { this.enrich(); } else { this.clean(); } }), setInputSize: Macro.onion(function() { if (!this.resorted && this.icon.element.parentNode) { this.resorted = true; $(this.input).inject(this.icon, 'after') } if (this.button) this.button.refresh(); this.input.setStyle('width', this.size.width - this.button.getLayoutWidth(this.button.size.width) - this.icon.getLayoutWidth() - 1) }), processValue: function(item) { return item.value.title; }, clear: function() { this.empty(); this.focus(); }, applyValue: $lambda(true), setIcon: function(item) { if (item && item.value) item = item.value.icon; this.collapse(); if (!item) { this.iconize(); this.icon.element.setStyle('background-image', ''); } else { this.uniconize(); this.icon.element.setStyle('background', 'url(' + item + ') no-repeat ' + (this.icon.offset.outside.left + 4) + 'px ' + this.icon.offset.outside.left + 'px'); } } }); LSD.Widget.Input.Option = LSD.Widget.Input.Search.Option = new Class({ Extends: LSD.Widget.Container, States: { chosen: ['choose', 'forget'] }, options: { tag: 'option', events: { element: { click: 'select', mousemove: 'chooseOnHover' } } }, render: Macro.onion(function() { var icon = this.value ? this.value.icon : false; if ((this.icon == icon) || !icon) return; this.icon = icon; this.element.setStyle('background-image', 'url(' + icon + ')'); this.element.setStyle('background-repeat', 'no-repeat'); this.element.setStyle('background-position', ((this.offset.outside.left || 0) + 4) + 'px center'); this.element.setStyle('padding-left', 15) }), select: function() { this.listWidget.selectItem.delay(50, this.listWidget, [this]); }, chooseOnHover: function() { this.listWidget.selectItem(this, true) } }); LSD.Widget.Input.Icon = LSD.Widget.Input.Search.Icon = new Class({ Includes: [ LSD.Widget.Button ], options: { tag: 'icon' } }); LSD.Widget.Input.Search.Button = LSD.Widget.Button;