pupu 0.0.1 → 0.0.2.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. data/CHANGELOG +12 -1
  2. data/README.textile +38 -104
  3. data/Rakefile +17 -54
  4. data/TODO.txt +11 -6
  5. data/examples/merb/README.textile +7 -0
  6. data/examples/merb/Rakefile +30 -0
  7. data/examples/merb/application.rb +13 -0
  8. data/examples/merb/config/framework.rb +7 -0
  9. data/examples/merb/config/init.rb +48 -0
  10. data/examples/{blog/media/pupu/autocompleter → merb/public}/javascripts/initializers/autocompleter.js +0 -0
  11. data/examples/{blog/media/pupu/flash → merb/public}/javascripts/initializers/flash.js +0 -0
  12. data/examples/{blog/media/pupu/lighter → merb/public/javascripts}/initializers/lighter.js +0 -0
  13. data/examples/{blog/media → merb/public}/pupu/autocompleter/CHANGELOG +0 -0
  14. data/examples/{blog/media → merb/public}/pupu/autocompleter/LICENSE +0 -0
  15. data/examples/{blog/media → merb/public}/pupu/autocompleter/README.textile +0 -0
  16. data/examples/{blog/media → merb/public}/pupu/autocompleter/Rakefile +0 -0
  17. data/examples/{blog/media → merb/public}/pupu/autocompleter/TODO +0 -0
  18. data/examples/{blog/media → merb/public}/pupu/autocompleter/config.rb +0 -0
  19. data/examples/{blog/media → merb/public}/pupu/autocompleter/images/spinner.gif +0 -0
  20. data/examples/{blog/media → merb/public}/pupu/autocompleter/javascripts/autocompleter.js +0 -0
  21. data/examples/{blog/media → merb/public}/pupu/autocompleter/javascripts/autocompleter.local.js +0 -0
  22. data/examples/{blog/media → merb/public}/pupu/autocompleter/javascripts/autocompleter.request.js +0 -0
  23. data/examples/{blog/media → merb/public}/pupu/autocompleter/javascripts/observer.js +0 -0
  24. data/examples/{blog/media → merb/public}/pupu/autocompleter/metadata.yml +0 -0
  25. data/examples/{blog/media → merb/public}/pupu/autocompleter/stylesheets/autocompleter.css +0 -0
  26. data/examples/{blog/media → merb/public}/pupu/blueprint/CHANGELOG +0 -0
  27. data/examples/{blog/media → merb/public}/pupu/blueprint/LICENSE +0 -0
  28. data/examples/{blog/media → merb/public}/pupu/blueprint/README.textile +0 -0
  29. data/examples/{blog/media → merb/public}/pupu/blueprint/Rakefile +0 -0
  30. data/examples/{blog/media → merb/public}/pupu/blueprint/TODO +0 -0
  31. data/examples/{blog/media → merb/public}/pupu/blueprint/config.rb +0 -0
  32. data/examples/{blog/media → merb/public}/pupu/blueprint/metadata.yml +0 -0
  33. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/ie.css +0 -0
  34. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/buttons/icons/cross.png +0 -0
  35. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/buttons/icons/key.png +0 -0
  36. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/buttons/icons/tick.png +0 -0
  37. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/buttons/readme.txt +0 -0
  38. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/buttons/screen.css +0 -0
  39. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/fancy-type/readme.txt +0 -0
  40. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/fancy-type/screen.css +0 -0
  41. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/link-icons/icons/doc.png +0 -0
  42. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/link-icons/icons/email.png +0 -0
  43. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/link-icons/icons/external.png +0 -0
  44. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/link-icons/icons/feed.png +0 -0
  45. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/link-icons/icons/im.png +0 -0
  46. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/link-icons/icons/pdf.png +0 -0
  47. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/link-icons/icons/visited.png +0 -0
  48. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/link-icons/icons/xls.png +0 -0
  49. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/link-icons/readme.txt +0 -0
  50. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/link-icons/screen.css +0 -0
  51. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/rtl/readme.txt +0 -0
  52. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/plugins/rtl/screen.css +0 -0
  53. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/print.css +0 -0
  54. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/screen.css +0 -0
  55. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/src/forms.css +0 -0
  56. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/src/grid.css +0 -0
  57. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/src/grid.png +0 -0
  58. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/src/ie.css +0 -0
  59. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/src/print.css +0 -0
  60. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/src/reset.css +0 -0
  61. data/examples/{blog/media → merb/public}/pupu/blueprint/stylesheets/src/typography.css +0 -0
  62. data/examples/{blog/media → merb/public}/pupu/flash/CHANGELOG +0 -0
  63. data/examples/{blog/media → merb/public}/pupu/flash/LICENSE +0 -0
  64. data/examples/{blog/media → merb/public}/pupu/flash/README.textile +0 -0
  65. data/examples/{blog/media → merb/public}/pupu/flash/Rakefile +0 -0
  66. data/examples/{blog/media → merb/public}/pupu/flash/TODO +0 -0
  67. data/examples/{blog/media → merb/public}/pupu/flash/config.rb +0 -0
  68. data/examples/{blog/media → merb/public}/pupu/flash/javascripts/flash.js +0 -0
  69. data/examples/{blog/media → merb/public}/pupu/flash/metadata.yml +0 -0
  70. data/examples/{blog/media → merb/public}/pupu/lighter/CHANGELOG +0 -0
  71. data/examples/{blog/media → merb/public}/pupu/lighter/LICENSE +0 -0
  72. data/examples/{blog/media → merb/public}/pupu/lighter/README.textile +0 -0
  73. data/examples/{blog/media → merb/public}/pupu/lighter/TODO.txt +0 -0
  74. data/examples/{blog/media → merb/public}/pupu/lighter/config.rb +0 -0
  75. data/examples/{blog/media → merb/public}/pupu/lighter/javascripts/Fuel.css.js +0 -0
  76. data/examples/{blog/media → merb/public}/pupu/lighter/javascripts/Fuel.html.js +0 -0
  77. data/examples/{blog/media → merb/public}/pupu/lighter/javascripts/Fuel.js.js +0 -0
  78. data/examples/{blog/media → merb/public}/pupu/lighter/javascripts/Fuel.md.js +0 -0
  79. data/examples/{blog/media → merb/public}/pupu/lighter/javascripts/Fuel.php.js +0 -0
  80. data/examples/{blog/media → merb/public}/pupu/lighter/javascripts/Fuel.ruby.js +0 -0
  81. data/examples/{blog/media → merb/public}/pupu/lighter/javascripts/Fuel.shell.js +0 -0
  82. data/examples/{blog/media → merb/public}/pupu/lighter/javascripts/Fuel.sql.js +0 -0
  83. data/examples/{blog/media → merb/public}/pupu/lighter/javascripts/Fuel.template.js +0 -0
  84. data/examples/{blog/media → merb/public}/pupu/lighter/javascripts/ZeroClipboard.js +0 -0
  85. data/examples/{blog/media → merb/public}/pupu/lighter/javascripts/lighter.js +0 -0
  86. data/examples/{blog/media → merb/public}/pupu/lighter/media/ZeroClipboard.swf +0 -0
  87. data/examples/{blog/media → merb/public}/pupu/lighter/metadata.yml +0 -0
  88. data/examples/{blog/media → merb/public}/pupu/lighter/stylesheets/Flame.git.css +0 -0
  89. data/examples/{blog/media → merb/public}/pupu/lighter/stylesheets/Flame.mocha.css +0 -0
  90. data/examples/{blog/media → merb/public}/pupu/lighter/stylesheets/Flame.panic.css +0 -0
  91. data/examples/{blog/media → merb/public}/pupu/lighter/stylesheets/Flame.standard.css +0 -0
  92. data/examples/{blog/media → merb/public}/pupu/lighter/stylesheets/Flame.template.css +0 -0
  93. data/examples/{blog/media → merb/public}/pupu/lighter/stylesheets/Flame.tutti.css +0 -0
  94. data/examples/{blog/media → merb/public}/pupu/lighter/stylesheets/Flame.twilight.css +0 -0
  95. data/examples/{blog/media → merb/public}/pupu/mootools/CHANGELOG +0 -0
  96. data/examples/{blog/media → merb/public}/pupu/mootools/LICENSE +0 -0
  97. data/examples/{blog/media → merb/public}/pupu/mootools/README.textile +0 -0
  98. data/examples/{blog/media → merb/public}/pupu/mootools/Rakefile +0 -0
  99. data/examples/{blog/media → merb/public}/pupu/mootools/TODO +0 -0
  100. data/examples/{blog/media → merb/public}/pupu/mootools/config.rb +0 -0
  101. data/examples/{blog/media → merb/public}/pupu/mootools/javascripts/mootools-1.2-core.js +0 -0
  102. data/examples/{blog/media → merb/public}/pupu/mootools/javascripts/mootools-1.2-more.js +0 -0
  103. data/examples/{blog/media → merb/public}/pupu/mootools/metadata.yml +0 -0
  104. data/examples/{blog/media/pupu/flash → merb/public}/stylesheets/initializers/flash.css +0 -0
  105. data/examples/merb/spec/application_spec.rb +37 -0
  106. data/examples/merb/spec/spec_helper.rb +16 -0
  107. data/examples/merb/views/examples/arguments.html.erb +0 -0
  108. data/examples/merb/views/examples/dependencies.html.erb +0 -0
  109. data/examples/merb/views/examples/simple.html.erb +4 -0
  110. data/examples/merb/views/index.html.erb +7 -0
  111. data/examples/merb/views/layout.html.erb +12 -0
  112. data/examples/rango/README.textile +7 -0
  113. data/examples/{blog → rango}/Rakefile +0 -0
  114. data/examples/{blog → rango}/config.ru +2 -3
  115. data/examples/{blog → rango}/init.rb +6 -5
  116. data/examples/{blog → rango}/media/javascripts/initializers/lighter.js +0 -0
  117. data/examples/rango/media/pupu/autocompleter/CHANGELOG +1 -0
  118. data/examples/rango/media/pupu/autocompleter/LICENSE +20 -0
  119. data/examples/rango/media/pupu/autocompleter/README.textile +26 -0
  120. data/examples/rango/media/pupu/autocompleter/Rakefile +29 -0
  121. data/examples/rango/media/pupu/autocompleter/TODO +1 -0
  122. data/examples/rango/media/pupu/autocompleter/config.rb +12 -0
  123. data/examples/rango/media/pupu/autocompleter/images/spinner.gif +0 -0
  124. data/examples/rango/media/pupu/autocompleter/javascripts/autocompleter.js +442 -0
  125. data/examples/rango/media/pupu/autocompleter/javascripts/autocompleter.local.js +31 -0
  126. data/examples/rango/media/pupu/autocompleter/javascripts/autocompleter.request.js +109 -0
  127. data/examples/rango/media/pupu/autocompleter/javascripts/initializers/autocompleter.js +26 -0
  128. data/examples/rango/media/pupu/autocompleter/javascripts/observer.js +69 -0
  129. data/examples/rango/media/pupu/autocompleter/metadata.yml +5 -0
  130. data/examples/rango/media/pupu/autocompleter/stylesheets/autocompleter.css +68 -0
  131. data/examples/rango/media/pupu/blueprint/CHANGELOG +1 -0
  132. data/examples/rango/media/pupu/blueprint/LICENSE +20 -0
  133. data/examples/rango/media/pupu/blueprint/README.textile +22 -0
  134. data/examples/rango/media/pupu/blueprint/Rakefile +29 -0
  135. data/examples/rango/media/pupu/blueprint/TODO +3 -0
  136. data/examples/rango/media/pupu/blueprint/config.rb +18 -0
  137. data/examples/rango/media/pupu/blueprint/metadata.yml +5 -0
  138. data/examples/rango/media/pupu/blueprint/stylesheets/ie.css +26 -0
  139. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/buttons/icons/cross.png +0 -0
  140. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/buttons/icons/key.png +0 -0
  141. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/buttons/icons/tick.png +0 -0
  142. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/buttons/readme.txt +32 -0
  143. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/buttons/screen.css +97 -0
  144. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/fancy-type/readme.txt +14 -0
  145. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/fancy-type/screen.css +71 -0
  146. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/link-icons/icons/doc.png +0 -0
  147. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/link-icons/icons/email.png +0 -0
  148. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/link-icons/icons/external.png +0 -0
  149. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/link-icons/icons/feed.png +0 -0
  150. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/link-icons/icons/im.png +0 -0
  151. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/link-icons/icons/pdf.png +0 -0
  152. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/link-icons/icons/visited.png +0 -0
  153. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/link-icons/icons/xls.png +0 -0
  154. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/link-icons/readme.txt +18 -0
  155. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/link-icons/screen.css +40 -0
  156. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/rtl/readme.txt +10 -0
  157. data/examples/rango/media/pupu/blueprint/stylesheets/plugins/rtl/screen.css +109 -0
  158. data/examples/rango/media/pupu/blueprint/stylesheets/print.css +30 -0
  159. data/examples/rango/media/pupu/blueprint/stylesheets/screen.css +251 -0
  160. data/examples/rango/media/pupu/blueprint/stylesheets/src/forms.css +49 -0
  161. data/examples/rango/media/pupu/blueprint/stylesheets/src/grid.css +212 -0
  162. data/examples/rango/media/pupu/blueprint/stylesheets/src/grid.png +0 -0
  163. data/examples/rango/media/pupu/blueprint/stylesheets/src/ie.css +59 -0
  164. data/examples/rango/media/pupu/blueprint/stylesheets/src/print.css +85 -0
  165. data/examples/rango/media/pupu/blueprint/stylesheets/src/reset.css +38 -0
  166. data/examples/rango/media/pupu/blueprint/stylesheets/src/typography.css +105 -0
  167. data/examples/rango/media/pupu/flash/CHANGELOG +1 -0
  168. data/examples/rango/media/pupu/flash/LICENSE +20 -0
  169. data/examples/rango/media/pupu/flash/README.textile +22 -0
  170. data/examples/rango/media/pupu/flash/Rakefile +37 -0
  171. data/examples/rango/media/pupu/flash/TODO +1 -0
  172. data/examples/rango/media/pupu/flash/config.rb +11 -0
  173. data/examples/rango/media/pupu/flash/javascripts/flash.js +63 -0
  174. data/examples/rango/media/pupu/flash/javascripts/initializers/flash.js +12 -0
  175. data/examples/rango/media/pupu/flash/metadata.yml +5 -0
  176. data/examples/rango/media/pupu/flash/stylesheets/initializers/flash.css +21 -0
  177. data/examples/rango/media/pupu/lighter/CHANGELOG +2 -0
  178. data/examples/rango/media/pupu/lighter/LICENSE +20 -0
  179. data/examples/rango/media/pupu/lighter/README.textile +19 -0
  180. data/examples/rango/media/pupu/lighter/TODO.txt +4 -0
  181. data/examples/rango/media/pupu/lighter/config.rb +20 -0
  182. data/examples/rango/media/pupu/lighter/initializers/lighter.js +11 -0
  183. data/examples/rango/media/pupu/lighter/javascripts/Fuel.css.js +1 -0
  184. data/examples/rango/media/pupu/lighter/javascripts/Fuel.html.js +1 -0
  185. data/examples/rango/media/pupu/lighter/javascripts/Fuel.js.js +1 -0
  186. data/examples/rango/media/pupu/lighter/javascripts/Fuel.md.js +1 -0
  187. data/examples/rango/media/pupu/lighter/javascripts/Fuel.php.js +1 -0
  188. data/examples/rango/media/pupu/lighter/javascripts/Fuel.ruby.js +1 -0
  189. data/examples/rango/media/pupu/lighter/javascripts/Fuel.shell.js +1 -0
  190. data/examples/rango/media/pupu/lighter/javascripts/Fuel.sql.js +1 -0
  191. data/examples/rango/media/pupu/lighter/javascripts/Fuel.template.js +45 -0
  192. data/examples/rango/media/pupu/lighter/javascripts/ZeroClipboard.js +1 -0
  193. data/examples/rango/media/pupu/lighter/javascripts/lighter.js +1 -0
  194. data/examples/rango/media/pupu/lighter/media/ZeroClipboard.swf +0 -0
  195. data/examples/rango/media/pupu/lighter/metadata.yml +5 -0
  196. data/examples/rango/media/pupu/lighter/stylesheets/Flame.git.css +1 -0
  197. data/examples/rango/media/pupu/lighter/stylesheets/Flame.mocha.css +1 -0
  198. data/examples/rango/media/pupu/lighter/stylesheets/Flame.panic.css +1 -0
  199. data/examples/rango/media/pupu/lighter/stylesheets/Flame.standard.css +1 -0
  200. data/examples/rango/media/pupu/lighter/stylesheets/Flame.template.css +101 -0
  201. data/examples/rango/media/pupu/lighter/stylesheets/Flame.tutti.css +1 -0
  202. data/examples/rango/media/pupu/lighter/stylesheets/Flame.twilight.css +1 -0
  203. data/examples/rango/media/pupu/mootools/CHANGELOG +2 -0
  204. data/examples/rango/media/pupu/mootools/LICENSE +20 -0
  205. data/examples/rango/media/pupu/mootools/README.textile +19 -0
  206. data/examples/rango/media/pupu/mootools/Rakefile +29 -0
  207. data/examples/rango/media/pupu/mootools/TODO +1 -0
  208. data/examples/rango/media/pupu/mootools/config.rb +8 -0
  209. data/examples/rango/media/pupu/mootools/javascripts/mootools-1.2-core.js +350 -0
  210. data/examples/rango/media/pupu/mootools/javascripts/mootools-1.2-more.js +154 -0
  211. data/examples/rango/media/pupu/mootools/metadata.yml +5 -0
  212. data/examples/rango/spec/pupu_spec.rb +37 -0
  213. data/examples/rango/spec/spec_helper.rb +15 -0
  214. data/examples/{blog → rango}/templates/base.html.haml +2 -3
  215. data/examples/rango/templates/examples/arguments.html.haml +7 -0
  216. data/examples/{blog → rango}/templates/examples/base.html.haml +3 -3
  217. data/examples/{blog → rango}/templates/examples/dependencies.html.haml +1 -1
  218. data/examples/{blog → rango}/templates/examples/simple.html.haml +1 -1
  219. data/examples/{blog → rango}/templates/index.html.haml +0 -0
  220. data/lib/pupu.rb +1 -1
  221. data/lib/pupu/adapters/merb.rb +4 -10
  222. data/lib/pupu/adapters/rails.rb +6 -0
  223. data/lib/pupu/adapters/rango.rb +0 -1
  224. data/lib/pupu/cli.rb +7 -3
  225. data/lib/pupu/github.rb +1 -1
  226. data/pupu.pre.gemspec +44 -0
  227. data/script/spec +2 -0
  228. data/tasks/benchmark.rake +11 -0
  229. data/tasks/gem.rake +23 -0
  230. data/tasks/hooks.rake +12 -0
  231. data/tasks/release.rake +68 -0
  232. data/tasks/spec.rake +27 -0
  233. data/tasks/submodules.rake +33 -0
  234. data/tasks/yardoc.rake +9 -0
  235. metadata +227 -115
  236. data/examples/blog/Thorfile +0 -9
  237. data/examples/blog/bin/pupu +0 -4
  238. data/examples/blog/config/pupu.rb +0 -4
  239. data/examples/blog/templates/examples/arguments.html.haml +0 -7
  240. data/url.rb +0 -20
  241. data/url_spec.rb +0 -35
@@ -0,0 +1,12 @@
1
+ # autocompleter depends on mootools
2
+ dependencies :mootools
3
+
4
+ # javascripts for loading
5
+ javascripts "observer", "autocompleter"
6
+
7
+ # stylesheet
8
+ stylesheet "autocompleter"
9
+
10
+ parameter :type, :optional => ["local", "request"] do |type|
11
+ javascript "autocompleter.#{type}"
12
+ end
@@ -0,0 +1,442 @@
1
+ /**
2
+ * Autocompleter
3
+ *
4
+ * http://digitarald.de/project/autocompleter/
5
+ *
6
+ * @version 1.1.2
7
+ *
8
+ * @license MIT-style license
9
+ * @author Harald Kirschner <mail [at] digitarald.de>
10
+ * @copyright Author
11
+ */
12
+
13
+ var Autocompleter = new Class({
14
+
15
+ Implements: [Options, Events],
16
+
17
+ options: {/*
18
+ onOver: $empty,
19
+ onSelect: $empty,
20
+ onSelection: $empty,
21
+ onShow: $empty,
22
+ onHide: $empty,
23
+ onBlur: $empty,
24
+ onFocus: $empty,*/
25
+ minLength: 1,
26
+ markQuery: true,
27
+ width: 'inherit',
28
+ maxChoices: 10,
29
+ injectChoice: null,
30
+ customChoices: null,
31
+ emptyChoices: null,
32
+ visibleChoices: true,
33
+ className: 'autocompleter-choices',
34
+ zIndex: 42,
35
+ delay: 400,
36
+ observerOptions: {},
37
+ fxOptions: {},
38
+
39
+ autoSubmit: false,
40
+ overflow: false,
41
+ overflowMargin: 25,
42
+ selectFirst: false,
43
+ filter: null,
44
+ filterCase: false,
45
+ filterSubset: false,
46
+ forceSelect: false,
47
+ selectMode: true,
48
+ choicesMatch: null,
49
+
50
+ multiple: false,
51
+ separator: ', ',
52
+ separatorSplit: /\s*[,;]\s*/,
53
+ autoTrim: false,
54
+ allowDupes: false,
55
+
56
+ cache: true,
57
+ relative: false
58
+ },
59
+
60
+ initialize: function(element, options) {
61
+ this.element = $(element);
62
+ this.setOptions(options);
63
+ this.build();
64
+ this.observer = new Observer(this.element, this.prefetch.bind(this), $merge({
65
+ 'delay': this.options.delay
66
+ }, this.options.observerOptions));
67
+ this.queryValue = null;
68
+ if (this.options.filter) this.filter = this.options.filter.bind(this);
69
+ var mode = this.options.selectMode;
70
+ this.typeAhead = (mode == 'type-ahead');
71
+ this.selectMode = (mode === true) ? 'selection' : mode;
72
+ this.cached = [];
73
+ },
74
+
75
+ /**
76
+ * build - Initialize DOM
77
+ *
78
+ * Builds the html structure for choices and appends the events to the element.
79
+ * Override this function to modify the html generation.
80
+ */
81
+ build: function() {
82
+ if ($(this.options.customChoices)) {
83
+ this.choices = this.options.customChoices;
84
+ } else {
85
+ this.choices = new Element('ul', {
86
+ 'class': this.options.className,
87
+ 'styles': {
88
+ 'zIndex': this.options.zIndex
89
+ }
90
+ }).inject(document.body);
91
+ this.relative = false;
92
+ if (this.options.relative) {
93
+ this.choices.inject(this.element, 'after');
94
+ this.relative = this.element.getOffsetParent();
95
+ }
96
+ this.fix = new OverlayFix(this.choices);
97
+ }
98
+ if (!this.options.separator.test(this.options.separatorSplit)) {
99
+ this.options.separatorSplit = this.options.separator;
100
+ }
101
+ this.fx = (!this.options.fxOptions) ? null : new Fx.Tween(this.choices, $merge({
102
+ 'property': 'opacity',
103
+ 'link': 'cancel',
104
+ 'duration': 200
105
+ }, this.options.fxOptions)).addEvent('onStart', Chain.prototype.clearChain).set(0);
106
+ this.element.setProperty('autocomplete', 'off')
107
+ .addEvent((Browser.Engine.trident || Browser.Engine.webkit) ? 'keydown' : 'keypress', this.onCommand.bind(this))
108
+ .addEvent('click', this.onCommand.bind(this, [false]))
109
+ .addEvent('focus', this.toggleFocus.create({bind: this, arguments: true, delay: 100}))
110
+ .addEvent('blur', this.toggleFocus.create({bind: this, arguments: false, delay: 100}));
111
+ },
112
+
113
+ destroy: function() {
114
+ if (this.fix) this.fix.destroy();
115
+ this.choices = this.selected = this.choices.destroy();
116
+ },
117
+
118
+ toggleFocus: function(state) {
119
+ this.focussed = state;
120
+ if (!state) this.hideChoices(true);
121
+ this.fireEvent((state) ? 'onFocus' : 'onBlur', [this.element]);
122
+ },
123
+
124
+ onCommand: function(e) {
125
+ if (!e && this.focussed) return this.prefetch();
126
+ if (e && e.key && !e.shift) {
127
+ switch (e.key) {
128
+ case 'enter':
129
+ if (this.element.value != this.opted) return true;
130
+ if (this.selected && this.visible) {
131
+ this.choiceSelect(this.selected);
132
+ return !!(this.options.autoSubmit);
133
+ }
134
+ break;
135
+ case 'up': case 'down':
136
+ if (!this.prefetch() && this.queryValue !== null) {
137
+ var up = (e.key == 'up');
138
+ this.choiceOver((this.selected || this.choices)[
139
+ (this.selected) ? ((up) ? 'getPrevious' : 'getNext') : ((up) ? 'getLast' : 'getFirst')
140
+ ](this.options.choicesMatch), true);
141
+ }
142
+ return false;
143
+ case 'esc': case 'tab':
144
+ this.hideChoices(true);
145
+ break;
146
+ }
147
+ }
148
+ return true;
149
+ },
150
+
151
+ setSelection: function(finish) {
152
+ var input = this.selected.inputValue, value = input;
153
+ var start = this.queryValue.length, end = input.length;
154
+ if (input.substr(0, start).toLowerCase() != this.queryValue.toLowerCase()) start = 0;
155
+ if (this.options.multiple) {
156
+ var split = this.options.separatorSplit;
157
+ value = this.element.value;
158
+ start += this.queryIndex;
159
+ end += this.queryIndex;
160
+ var old = value.substr(this.queryIndex).split(split, 1)[0];
161
+ value = value.substr(0, this.queryIndex) + input + value.substr(this.queryIndex + old.length);
162
+ if (finish) {
163
+ var tokens = value.split(this.options.separatorSplit).filter(function(entry) {
164
+ return this.test(entry);
165
+ }, /[^\s,]+/);
166
+ if (!this.options.allowDupes) tokens = [].combine(tokens);
167
+ var sep = this.options.separator;
168
+ value = tokens.join(sep) + sep;
169
+ end = value.length;
170
+ }
171
+ }
172
+ this.observer.setValue(value);
173
+ this.opted = value;
174
+ if (finish || this.selectMode == 'pick') start = end;
175
+ this.element.selectRange(start, end);
176
+ this.fireEvent('onSelection', [this.element, this.selected, value, input]);
177
+ },
178
+
179
+ showChoices: function() {
180
+ var match = this.options.choicesMatch, first = this.choices.getFirst(match);
181
+ this.selected = this.selectedValue = null;
182
+ if (this.fix) {
183
+ var pos = this.element.getCoordinates(this.relative), width = this.options.width || 'auto';
184
+ this.choices.setStyles({
185
+ 'left': pos.left,
186
+ 'top': pos.bottom,
187
+ 'width': (width === true || width == 'inherit') ? pos.width : width
188
+ });
189
+ }
190
+ if (!first) return;
191
+ if (!this.visible) {
192
+ this.visible = true;
193
+ this.choices.setStyle('display', '');
194
+ if (this.fx) this.fx.start(1);
195
+ this.fireEvent('onShow', [this.element, this.choices]);
196
+ }
197
+ if (this.options.selectFirst || this.typeAhead || first.inputValue == this.queryValue) this.choiceOver(first, this.typeAhead);
198
+ var items = this.choices.getChildren(match), max = this.options.maxChoices;
199
+ var styles = {'overflowY': 'hidden', 'height': ''};
200
+ this.overflown = false;
201
+ if (items.length > max) {
202
+ var item = items[max - 1];
203
+ styles.overflowY = 'scroll';
204
+ styles.height = item.getCoordinates(this.choices).bottom;
205
+ this.overflown = true;
206
+ };
207
+ this.choices.setStyles(styles);
208
+ this.fix.show();
209
+ if (this.options.visibleChoices) {
210
+ var scroll = document.getScroll(),
211
+ size = document.getSize(),
212
+ coords = this.choices.getCoordinates();
213
+ if (coords.right > scroll.x + size.x) scroll.x = coords.right - size.x;
214
+ if (coords.bottom > scroll.y + size.y) scroll.y = coords.bottom - size.y;
215
+ window.scrollTo(Math.min(scroll.x, coords.left), Math.min(scroll.y, coords.top));
216
+ }
217
+ },
218
+
219
+ hideChoices: function(clear) {
220
+ if (clear) {
221
+ var value = this.element.value;
222
+ if (this.options.forceSelect) value = this.opted;
223
+ if (this.options.autoTrim) {
224
+ value = value.split(this.options.separatorSplit).filter($arguments(0)).join(this.options.separator);
225
+ }
226
+ this.observer.setValue(value);
227
+ }
228
+ if (!this.visible) return;
229
+ this.visible = false;
230
+ if (this.selected) this.selected.removeClass('autocompleter-selected');
231
+ this.observer.clear();
232
+ var hide = function(){
233
+ this.choices.setStyle('display', 'none');
234
+ this.fix.hide();
235
+ }.bind(this);
236
+ if (this.fx) this.fx.start(0).chain(hide);
237
+ else hide();
238
+ this.fireEvent('onHide', [this.element, this.choices]);
239
+ },
240
+
241
+ prefetch: function() {
242
+ var value = this.element.value, query = value;
243
+ if (this.options.multiple) {
244
+ var split = this.options.separatorSplit;
245
+ var values = value.split(split);
246
+ var index = this.element.getSelectedRange().start;
247
+ var toIndex = value.substr(0, index).split(split);
248
+ var last = toIndex.length - 1;
249
+ index -= toIndex[last].length;
250
+ query = values[last];
251
+ }
252
+ if (query.length < this.options.minLength) {
253
+ this.hideChoices();
254
+ } else {
255
+ if (query === this.queryValue || (this.visible && query == this.selectedValue)) {
256
+ if (this.visible) return false;
257
+ this.showChoices();
258
+ } else {
259
+ this.queryValue = query;
260
+ this.queryIndex = index;
261
+ if (!this.fetchCached()) this.query();
262
+ }
263
+ }
264
+ return true;
265
+ },
266
+
267
+ fetchCached: function() {
268
+ return false;
269
+ if (!this.options.cache
270
+ || !this.cached
271
+ || !this.cached.length
272
+ || this.cached.length >= this.options.maxChoices
273
+ || this.queryValue) return false;
274
+ this.update(this.filter(this.cached));
275
+ return true;
276
+ },
277
+
278
+ update: function(tokens) {
279
+ this.choices.empty();
280
+ this.cached = tokens;
281
+ var type = tokens && $type(tokens);
282
+ if (!type || (type == 'array' && !tokens.length) || (type == 'hash' && !tokens.getLength())) {
283
+ (this.options.emptyChoices || this.hideChoices).call(this);
284
+ } else {
285
+ if (this.options.maxChoices < tokens.length && !this.options.overflow) tokens.length = this.options.maxChoices;
286
+ tokens.each(this.options.injectChoice || function(token){
287
+ var choice = new Element('li', {'html': this.markQueryValue(token)});
288
+ choice.inputValue = token;
289
+ this.addChoiceEvents(choice).inject(this.choices);
290
+ }, this);
291
+ this.showChoices();
292
+ }
293
+ },
294
+
295
+ choiceOver: function(choice, selection) {
296
+ if (!choice || choice == this.selected) return;
297
+ if (this.selected) this.selected.removeClass('autocompleter-selected');
298
+ this.selected = choice.addClass('autocompleter-selected');
299
+ this.fireEvent('onSelect', [this.element, this.selected, selection]);
300
+ if (!this.selectMode) this.opted = this.element.value;
301
+ if (!selection) return;
302
+ this.selectedValue = this.selected.inputValue;
303
+ if (this.overflown) {
304
+ var coords = this.selected.getCoordinates(this.choices), margin = this.options.overflowMargin,
305
+ top = this.choices.scrollTop, height = this.choices.offsetHeight, bottom = top + height;
306
+ if (coords.top - margin < top && top) this.choices.scrollTop = Math.max(coords.top - margin, 0);
307
+ else if (coords.bottom + margin > bottom) this.choices.scrollTop = Math.min(coords.bottom - height + margin, bottom);
308
+ }
309
+ if (this.selectMode) this.setSelection();
310
+ },
311
+
312
+ choiceSelect: function(choice) {
313
+ if (choice) this.choiceOver(choice);
314
+ this.setSelection(true);
315
+ this.queryValue = false;
316
+ this.hideChoices();
317
+ },
318
+
319
+ filter: function(tokens) {
320
+ return (tokens || this.tokens).filter(function(token) {
321
+ return this.test(token);
322
+ }, new RegExp(((this.options.filterSubset) ? '' : '^') + this.queryValue.escapeRegExp(), (this.options.filterCase) ? '' : 'i'));
323
+ },
324
+
325
+ /**
326
+ * markQueryValue
327
+ *
328
+ * Marks the queried word in the given string with <span class="autocompleter-queried">*</span>
329
+ * Call this i.e. from your custom parseChoices, same for addChoiceEvents
330
+ *
331
+ * @param {String} Text
332
+ * @return {String} Text
333
+ */
334
+ markQueryValue: function(str) {
335
+ return (!this.options.markQuery || !this.queryValue) ? str
336
+ : str.replace(new RegExp('(' + ((this.options.filterSubset) ? '' : '^') + this.queryValue.escapeRegExp() + ')', (this.options.filterCase) ? '' : 'i'), '<span class="autocompleter-queried">$1</span>');
337
+ },
338
+
339
+ /**
340
+ * addChoiceEvents
341
+ *
342
+ * Appends the needed event handlers for a choice-entry to the given element.
343
+ *
344
+ * @param {Element} Choice entry
345
+ * @return {Element} Choice entry
346
+ */
347
+ addChoiceEvents: function(el) {
348
+ return el.addEvents({
349
+ 'mouseover': this.choiceOver.bind(this, [el]),
350
+ 'click': this.choiceSelect.bind(this, [el])
351
+ });
352
+ }
353
+ });
354
+
355
+ var OverlayFix = new Class({
356
+
357
+ initialize: function(el) {
358
+ if (Browser.Engine.trident) {
359
+ this.element = $(el);
360
+ this.relative = this.element.getOffsetParent();
361
+ this.fix = new Element('iframe', {
362
+ 'frameborder': '0',
363
+ 'scrolling': 'no',
364
+ 'src': 'javascript:false;',
365
+ 'styles': {
366
+ 'position': 'absolute',
367
+ 'border': 'none',
368
+ 'display': 'none',
369
+ 'filter': 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'
370
+ }
371
+ }).inject(this.element, 'after');
372
+ }
373
+ },
374
+
375
+ show: function() {
376
+ if (this.fix) {
377
+ var coords = this.element.getCoordinates(this.relative);
378
+ delete coords.right;
379
+ delete coords.bottom;
380
+ this.fix.setStyles($extend(coords, {
381
+ 'display': '',
382
+ 'zIndex': (this.element.getStyle('zIndex') || 1) - 1
383
+ }));
384
+ }
385
+ return this;
386
+ },
387
+
388
+ hide: function() {
389
+ if (this.fix) this.fix.setStyle('display', 'none');
390
+ return this;
391
+ },
392
+
393
+ destroy: function() {
394
+ if (this.fix) this.fix = this.fix.destroy();
395
+ }
396
+
397
+ });
398
+
399
+ Element.implement({
400
+
401
+ getSelectedRange: function() {
402
+ if (!Browser.Engine.trident) return {start: this.selectionStart, end: this.selectionEnd};
403
+ var pos = {start: 0, end: 0};
404
+ var range = this.getDocument().selection.createRange();
405
+ if (!range || range.parentElement() != this) return pos;
406
+ var dup = range.duplicate();
407
+ if (this.type == 'text') {
408
+ pos.start = 0 - dup.moveStart('character', -100000);
409
+ pos.end = pos.start + range.text.length;
410
+ } else {
411
+ var value = this.value;
412
+ var offset = value.length - value.match(/[\n\r]*$/)[0].length;
413
+ dup.moveToElementText(this);
414
+ dup.setEndPoint('StartToEnd', range);
415
+ pos.end = offset - dup.text.length;
416
+ dup.setEndPoint('StartToStart', range);
417
+ pos.start = offset - dup.text.length;
418
+ }
419
+ return pos;
420
+ },
421
+
422
+ selectRange: function(start, end) {
423
+ if (Browser.Engine.trident) {
424
+ var diff = this.value.substr(start, end - start).replace(/\r/g, '').length;
425
+ start = this.value.substr(0, start).replace(/\r/g, '').length;
426
+ var range = this.createTextRange();
427
+ range.collapse(true);
428
+ range.moveEnd('character', start + diff);
429
+ range.moveStart('character', start);
430
+ range.select();
431
+ } else {
432
+ this.focus();
433
+ this.setSelectionRange(start, end);
434
+ }
435
+ return this;
436
+ }
437
+
438
+ });
439
+
440
+ /* compatibility */
441
+
442
+ Autocompleter.Base = Autocompleter;