gettext 1.0.0-mswin32 → 1.1.0-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (301) hide show
  1. data/ChangeLog +193 -0
  2. data/NEWS +51 -1
  3. data/README +29 -11
  4. data/Rakefile +70 -56
  5. data/bin/rgettext +2 -0
  6. data/bin/rmsgfmt +2 -0
  7. data/bin/rmsgmerge +24 -0
  8. data/data/locale/cs/LC_MESSAGES/rails.mo +0 -0
  9. data/data/locale/cs/LC_MESSAGES/rgettext.mo +0 -0
  10. data/data/locale/de/LC_MESSAGES/rails.mo +0 -0
  11. data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
  12. data/data/locale/es/LC_MESSAGES/rails.mo +0 -0
  13. data/data/locale/es/LC_MESSAGES/rgettext.mo +0 -0
  14. data/data/locale/fr/LC_MESSAGES/rails.mo +0 -0
  15. data/data/locale/fr/LC_MESSAGES/rgettext.mo +0 -0
  16. data/data/locale/it/LC_MESSAGES/rgettext.mo +0 -0
  17. data/data/locale/ja/LC_MESSAGES/rails.mo +0 -0
  18. data/data/locale/ja/LC_MESSAGES/rgettext.mo +0 -0
  19. data/data/locale/ko/LC_MESSAGES/rails.mo +0 -0
  20. data/data/locale/ko/LC_MESSAGES/rgettext.mo +0 -0
  21. data/data/locale/nl/LC_MESSAGES/rails.mo +0 -0
  22. data/data/locale/nl/LC_MESSAGES/rgettext.mo +0 -0
  23. data/data/locale/pt_BR/LC_MESSAGES/rails.mo +0 -0
  24. data/data/locale/pt_BR/LC_MESSAGES/rgettext.mo +0 -0
  25. data/data/locale/sv/LC_MESSAGES/rgettext.mo +0 -0
  26. data/ext/gettext/gettext/_locale.BAK +86 -0
  27. data/ext/gettext/gettext/_locale.c +1 -1
  28. data/ext/gettext/gettext/_locale.exp +0 -0
  29. data/ext/gettext/gettext/_locale.lib +0 -0
  30. data/ext/gettext/gettext/_locale.obj +0 -0
  31. data/ext/gettext/gettext/_locale.pdb +0 -0
  32. data/ext/gettext/gettext/_locale.so +0 -0
  33. data/ext/gettext/gettext/mkmf.log +4 -4
  34. data/ext/gettext/gettext/vc70.pdb +0 -0
  35. data/lib/_locale.so +0 -0
  36. data/lib/gettext.rb +17 -4
  37. data/lib/gettext/cgi.rb +34 -19
  38. data/lib/gettext/locale.rb +3 -13
  39. data/lib/gettext/locale_default.rb +2 -2
  40. data/lib/gettext/locale_win32.rb +27 -7
  41. data/lib/gettext/mo.rb +6 -1
  42. data/lib/gettext/parser/activerecord.rb +115 -0
  43. data/lib/gettext/parser/glade.rb +3 -1
  44. data/lib/gettext/parser/ruby.rb +56 -57
  45. data/lib/gettext/poparser.rb +297 -0
  46. data/lib/gettext/rails.rb +161 -3
  47. data/lib/gettext/rgettext.rb +19 -9
  48. data/lib/gettext/rmsgfmt.rb +95 -363
  49. data/lib/gettext/rmsgmerge.rb +381 -0
  50. data/lib/gettext/string.rb +26 -0
  51. data/lib/gettext/textdomain.rb +21 -18
  52. data/lib/gettext/utils.rb +55 -0
  53. data/lib/gettext/version.rb +1 -1
  54. data/po/cs/rails.po +83 -0
  55. data/po/cs/rgettext.po +104 -0
  56. data/po/de/rails.po +79 -0
  57. data/po/de/rgettext.po +72 -21
  58. data/po/es/rails.po +80 -0
  59. data/po/es/rgettext.po +75 -19
  60. data/po/fr/rails.po +81 -0
  61. data/po/fr/rgettext.po +75 -19
  62. data/po/it/rgettext.po +68 -17
  63. data/po/ja/rails.po +78 -0
  64. data/po/ja/rgettext.po +71 -20
  65. data/po/ko/rails.po +77 -0
  66. data/po/ko/rgettext.po +74 -22
  67. data/po/nl/rails.po +80 -0
  68. data/po/nl/rgettext.po +102 -0
  69. data/po/pt_BR/rails.po +79 -0
  70. data/po/pt_BR/rgettext.po +77 -24
  71. data/po/rails.pot +80 -0
  72. data/po/rgettext.pot +63 -13
  73. data/po/sv/rgettext.po +63 -15
  74. data/samples/cgi/cookie.cgi +5 -0
  75. data/samples/cgi/helloerb1.cgi +4 -0
  76. data/samples/cgi/helloerb2.cgi +5 -0
  77. data/samples/cgi/index.cgi +5 -0
  78. data/samples/cgi/locale/cs/LC_MESSAGES/helloerb1.mo +0 -0
  79. data/samples/cgi/locale/cs/LC_MESSAGES/helloerb2.mo +0 -0
  80. data/samples/cgi/locale/cs/LC_MESSAGES/hellolib.mo +0 -0
  81. data/samples/cgi/locale/cs/LC_MESSAGES/main.mo +0 -0
  82. data/samples/cgi/locale/fr/LC_MESSAGES/main.mo +0 -0
  83. data/samples/cgi/locale/ko/LC_MESSAGES/helloerb1.mo +0 -0
  84. data/samples/cgi/locale/ko/LC_MESSAGES/helloerb2.mo +0 -0
  85. data/samples/cgi/locale/ko/LC_MESSAGES/hellolib.mo +0 -0
  86. data/samples/cgi/locale/ko/LC_MESSAGES/main.mo +0 -0
  87. data/samples/cgi/locale/nl/LC_MESSAGES/helloerb1.mo +0 -0
  88. data/samples/cgi/locale/nl/LC_MESSAGES/helloerb2.mo +0 -0
  89. data/samples/cgi/locale/nl/LC_MESSAGES/hellolib.mo +0 -0
  90. data/samples/cgi/locale/nl/LC_MESSAGES/main.mo +0 -0
  91. data/samples/cgi/locale/pt_BR/LC_MESSAGES/helloerb1.mo +0 -0
  92. data/samples/cgi/locale/pt_BR/LC_MESSAGES/helloerb2.mo +0 -0
  93. data/samples/cgi/locale/pt_BR/LC_MESSAGES/hellolib.mo +0 -0
  94. data/samples/cgi/locale/pt_BR/LC_MESSAGES/main.mo +0 -0
  95. data/samples/cgi/po/cs/helloerb1.po +66 -0
  96. data/samples/cgi/po/cs/helloerb2.po +52 -0
  97. data/samples/cgi/po/cs/hellolib.po +25 -0
  98. data/samples/cgi/po/cs/main.po +78 -0
  99. data/samples/cgi/po/fr/main.po +8 -8
  100. data/samples/cgi/po/ko/helloerb1.po +2 -3
  101. data/samples/cgi/po/ko/helloerb2.po +1 -2
  102. data/samples/cgi/po/ko/hellolib.po +1 -2
  103. data/samples/cgi/po/ko/main.po +2 -3
  104. data/samples/cgi/po/nl/helloerb1.po +60 -0
  105. data/samples/cgi/po/nl/helloerb2.po +52 -0
  106. data/samples/cgi/po/nl/hellolib.po +24 -0
  107. data/samples/cgi/po/nl/main.po +76 -0
  108. data/samples/cgi/po/pt_BR/helloerb1.po +59 -0
  109. data/samples/cgi/po/pt_BR/helloerb2.po +51 -0
  110. data/samples/cgi/po/pt_BR/hellolib.po +22 -0
  111. data/samples/cgi/po/pt_BR/main.po +75 -0
  112. data/samples/locale/cs/LC_MESSAGES/hello.mo +0 -0
  113. data/samples/locale/cs/LC_MESSAGES/hello2.mo +0 -0
  114. data/samples/locale/cs/LC_MESSAGES/hello_noop.mo +0 -0
  115. data/samples/locale/cs/LC_MESSAGES/hello_plural.mo +0 -0
  116. data/samples/locale/cs/LC_MESSAGES/helloglade2.mo +0 -0
  117. data/samples/locale/cs/LC_MESSAGES/hellogtk.mo +0 -0
  118. data/samples/locale/cs/LC_MESSAGES/hellotk.mo +0 -0
  119. data/samples/locale/fr/LC_MESSAGES/helloglade2.mo +0 -0
  120. data/samples/locale/ko/LC_MESSAGES/hello.mo +0 -0
  121. data/samples/locale/ko/LC_MESSAGES/hello2.mo +0 -0
  122. data/samples/locale/ko/LC_MESSAGES/hello_noop.mo +0 -0
  123. data/samples/locale/ko/LC_MESSAGES/hello_plural.mo +0 -0
  124. data/samples/locale/ko/LC_MESSAGES/helloglade2.mo +0 -0
  125. data/samples/locale/ko/LC_MESSAGES/hellogtk.mo +0 -0
  126. data/samples/locale/ko/LC_MESSAGES/hellotk.mo +0 -0
  127. data/samples/locale/nl/LC_MESSAGES/hello.mo +0 -0
  128. data/samples/locale/nl/LC_MESSAGES/hello2.mo +0 -0
  129. data/samples/locale/nl/LC_MESSAGES/hello_noop.mo +0 -0
  130. data/samples/locale/nl/LC_MESSAGES/hello_plural.mo +0 -0
  131. data/samples/locale/nl/LC_MESSAGES/helloglade2.mo +0 -0
  132. data/samples/locale/nl/LC_MESSAGES/hellogtk.mo +0 -0
  133. data/samples/locale/nl/LC_MESSAGES/hellotk.mo +0 -0
  134. data/samples/locale/pt_BR/LC_MESSAGES/hello.mo +0 -0
  135. data/samples/locale/pt_BR/LC_MESSAGES/hello2.mo +0 -0
  136. data/samples/locale/pt_BR/LC_MESSAGES/hello_noop.mo +0 -0
  137. data/samples/locale/pt_BR/LC_MESSAGES/hello_plural.mo +0 -0
  138. data/samples/locale/pt_BR/LC_MESSAGES/helloglade2.mo +0 -0
  139. data/samples/locale/pt_BR/LC_MESSAGES/hellogtk.mo +0 -0
  140. data/samples/locale/pt_BR/LC_MESSAGES/hellotk.mo +0 -0
  141. data/samples/po/cs/hello.po +23 -0
  142. data/samples/po/cs/hello2.po +31 -0
  143. data/samples/po/cs/hello_noop.po +27 -0
  144. data/samples/po/cs/hello_plural.po +26 -0
  145. data/samples/po/cs/helloglade2.po +37 -0
  146. data/samples/po/cs/hellogtk.po +23 -0
  147. data/samples/po/cs/hellotk.po +23 -0
  148. data/samples/po/fr/helloglade2.po +2 -2
  149. data/samples/po/hello.pot +1 -0
  150. data/samples/po/hello2.pot +1 -0
  151. data/samples/po/hello_noop.pot +2 -1
  152. data/samples/po/hello_plural.pot +6 -2
  153. data/samples/po/helloglade2.pot +8 -3
  154. data/samples/po/hellotk.pot +4 -0
  155. data/samples/po/ko/hello.po +1 -2
  156. data/samples/po/ko/hello2.po +1 -2
  157. data/samples/po/ko/hello_noop.po +1 -2
  158. data/samples/po/ko/hello_plural.po +1 -2
  159. data/samples/po/ko/helloglade2.po +2 -2
  160. data/samples/po/ko/hellogtk.po +1 -2
  161. data/samples/po/ko/hellotk.po +1 -2
  162. data/samples/po/nl/hello.po +24 -0
  163. data/samples/po/nl/hello2.po +32 -0
  164. data/samples/po/nl/hello_noop.po +28 -0
  165. data/samples/po/nl/hello_plural.po +26 -0
  166. data/samples/po/nl/helloglade2.po +31 -0
  167. data/samples/po/nl/hellogtk.po +24 -0
  168. data/samples/po/nl/hellotk.po +24 -0
  169. data/samples/po/pt_BR/hello.po +6 -5
  170. data/samples/po/pt_BR/hello2.po +6 -5
  171. data/samples/po/pt_BR/hello_noop.po +6 -5
  172. data/samples/po/pt_BR/hello_plural.po +6 -6
  173. data/samples/po/pt_BR/helloglade2.po +6 -5
  174. data/samples/po/pt_BR/hellogtk.po +6 -5
  175. data/samples/po/pt_BR/hellotk.po +6 -5
  176. data/samples/rails/README +21 -15
  177. data/samples/rails/Rakefile +10 -1
  178. data/samples/rails/app/controllers/application.rb +10 -18
  179. data/samples/rails/app/controllers/blog_controller.rb +1 -5
  180. data/samples/rails/app/helpers/blog_helper.rb +1 -1
  181. data/samples/rails/app/models/article.rb +15 -0
  182. data/samples/rails/app/views/blog/_form.rhtml +2 -2
  183. data/samples/rails/config/boot.rb +17 -0
  184. data/samples/rails/config/database.yml +6 -4
  185. data/samples/rails/config/environment.rb +40 -75
  186. data/samples/rails/config/environments/development.rb +12 -7
  187. data/samples/rails/config/environments/production.rb +17 -6
  188. data/samples/rails/config/environments/test.rb +8 -6
  189. data/samples/rails/locale/cs/LC_MESSAGES/blog.mo +0 -0
  190. data/samples/rails/locale/cs/LC_MESSAGES/gettext_plugin.mo +0 -0
  191. data/samples/rails/locale/de/LC_MESSAGES/blog.mo +0 -0
  192. data/samples/rails/locale/de/LC_MESSAGES/gettext_plugin.mo +0 -0
  193. data/samples/rails/locale/en/LC_MESSAGES/blog.mo +0 -0
  194. data/samples/rails/locale/es/LC_MESSAGES/blog.mo +0 -0
  195. data/samples/rails/locale/es/LC_MESSAGES/gettext_plugin.mo +0 -0
  196. data/samples/rails/locale/fr/LC_MESSAGES/blog.mo +0 -0
  197. data/samples/rails/locale/fr/LC_MESSAGES/{lang_helper.mo → gettext_plugin.mo} +0 -0
  198. data/samples/rails/locale/ja/LC_MESSAGES/blog.mo +0 -0
  199. data/samples/rails/locale/ja/LC_MESSAGES/{lang_helper.mo → gettext_plugin.mo} +0 -0
  200. data/samples/rails/locale/ko/LC_MESSAGES/blog.mo +0 -0
  201. data/samples/rails/locale/ko/LC_MESSAGES/gettext_plugin.mo +0 -0
  202. data/samples/rails/locale/nl/LC_MESSAGES/blog.mo +0 -0
  203. data/samples/rails/locale/nl/LC_MESSAGES/gettext_plugin.mo +0 -0
  204. data/samples/rails/locale/pt_BR/LC_MESSAGES/blog.mo +0 -0
  205. data/samples/rails/locale/pt_BR/LC_MESSAGES/gettext_plugin.mo +0 -0
  206. data/samples/rails/po/blog.pot +57 -37
  207. data/samples/rails/po/cs/blog.po +116 -0
  208. data/samples/rails/po/cs/gettext_plugin.po +29 -0
  209. data/samples/rails/po/de/blog.po +70 -51
  210. data/samples/rails/po/de/{lang_helper.po → gettext_plugin.po} +4 -5
  211. data/samples/rails/po/en/blog.po +111 -0
  212. data/samples/rails/po/es/blog.po +67 -47
  213. data/samples/rails/po/es/{lang_helper.po → gettext_plugin.po} +5 -5
  214. data/samples/rails/po/fr/blog.po +65 -45
  215. data/samples/rails/po/fr/{lang_helper.po → gettext_plugin.po} +4 -4
  216. data/samples/rails/po/{lang_helper.pot → gettext_plugin.pot} +4 -4
  217. data/samples/rails/po/ja/blog.po +64 -44
  218. data/samples/rails/po/ja/{lang_helper.po → gettext_plugin.po} +4 -4
  219. data/samples/rails/po/ko/blog.po +65 -46
  220. data/samples/rails/po/ko/{lang_helper.po → gettext_plugin.po} +5 -6
  221. data/samples/rails/po/nl/blog.po +115 -0
  222. data/samples/rails/po/nl/gettext_plugin.po +28 -0
  223. data/samples/rails/po/pt_BR/blog.po +109 -0
  224. data/samples/rails/po/pt_BR/gettext_plugin.po +27 -0
  225. data/samples/rails/public/images/rails.png +0 -0
  226. data/samples/rails/public/index.html +272 -71
  227. data/samples/rails/public/javascripts/controls.js +441 -166
  228. data/samples/rails/public/javascripts/dragdrop.js +261 -279
  229. data/samples/rails/public/javascripts/effects.js +657 -277
  230. data/samples/rails/public/javascripts/prototype.js +911 -223
  231. data/samples/rails/public/robots.txt +1 -0
  232. data/samples/rails/public/stylesheets/scaffold.css +1 -1
  233. data/samples/rails/script/about +3 -0
  234. data/samples/rails/script/breakpointer +3 -4
  235. data/samples/rails/script/console +3 -23
  236. data/samples/rails/script/destroy +3 -7
  237. data/samples/rails/script/generate +3 -7
  238. data/samples/rails/script/performance/benchmarker +3 -0
  239. data/samples/rails/script/performance/profiler +3 -0
  240. data/samples/rails/script/plugin +3 -0
  241. data/samples/rails/script/process/reaper +3 -0
  242. data/samples/rails/script/process/spawner +3 -0
  243. data/samples/rails/script/process/spinner +3 -0
  244. data/samples/rails/script/runner +3 -29
  245. data/samples/rails/script/server +3 -49
  246. data/samples/rails/vendor/plugins/gettext/init.rb +19 -0
  247. data/samples/rails/vendor/{lang_helper.rb → plugins/gettext/lib/gettext_plugin.rb} +15 -11
  248. data/src/poparser.ry +171 -0
  249. data/test/gettext_runner.rb +3 -1
  250. data/test/gettext_test.rb +56 -31
  251. data/test/gettext_test_cgi.rb +12 -0
  252. data/test/gettext_test_parser.rb +3 -0
  253. data/test/gettext_test_string.rb +14 -0
  254. data/test/locale/cr/LC_MESSAGES/plural.mo +0 -0
  255. data/test/locale/da/LC_MESSAGES/plural.mo +0 -0
  256. data/test/locale/da/LC_MESSAGES/plural_error.mo +0 -0
  257. data/test/locale/fr/LC_MESSAGES/plural.mo +0 -0
  258. data/test/locale/fr/LC_MESSAGES/plural_error.mo +0 -0
  259. data/test/locale/ir/LC_MESSAGES/plural.mo +0 -0
  260. data/test/locale/la/LC_MESSAGES/plural.mo +0 -0
  261. data/test/locale/li/LC_MESSAGES/plural.mo +0 -0
  262. data/test/locale/po/LC_MESSAGES/plural.mo +0 -0
  263. data/test/locale/sl/LC_MESSAGES/plural.mo +0 -0
  264. data/test/po/cr/plural.po +3 -3
  265. data/test/po/da/plural.po +2 -2
  266. data/test/po/da/plural_error.po +2 -1
  267. data/test/po/fr/plural.po +2 -2
  268. data/test/po/fr/plural_error.po +2 -1
  269. data/test/po/ir/plural.po +3 -3
  270. data/test/po/la/plural.po +3 -3
  271. data/test/po/li/plural.po +3 -3
  272. data/test/po/po/plural.po +3 -3
  273. data/test/po/sl/plural.po +4 -4
  274. data/test/test.sh +1 -0
  275. data/test/test_rubyparser.rb +20 -0
  276. data/test/{test_rubyparser_n.rb → test_rubyparser_N.rb} +0 -0
  277. metadata +163 -43
  278. data/README.ja +0 -115
  279. data/data/locale/de/LC_MESSAGES/rmsgfmt.mo +0 -0
  280. data/data/locale/es/LC_MESSAGES/rmsgfmt.mo +0 -0
  281. data/data/locale/fr/LC_MESSAGES/rmsgfmt.mo +0 -0
  282. data/data/locale/it/LC_MESSAGES/rmsgfmt.mo +0 -0
  283. data/data/locale/ja/LC_MESSAGES/rmsgfmt.mo +0 -0
  284. data/data/locale/ko/LC_MESSAGES/rmsgfmt.mo +0 -0
  285. data/data/locale/pt_BR/LC_MESSAGES/rmsgfmt.mo +0 -0
  286. data/data/locale/sv/LC_MESSAGES/rmsgfmt.mo +0 -0
  287. data/gettext-1.0.0-mswin32.gem +0 -0
  288. data/po/de/rmsgfmt.po +0 -45
  289. data/po/es/rmsgfmt.po +0 -43
  290. data/po/fr/rmsgfmt.po +0 -43
  291. data/po/it/rmsgfmt.po +0 -44
  292. data/po/ja/rmsgfmt.po +0 -43
  293. data/po/ko/rmsgfmt.po +0 -40
  294. data/po/pt_BR/rmsgfmt.po +0 -42
  295. data/po/rmsgfmt.pot +0 -40
  296. data/po/sv/rmsgfmt.po +0 -43
  297. data/samples/rails/locale/de/LC_MESSAGES/lang_helper.mo +0 -0
  298. data/samples/rails/locale/es/LC_MESSAGES/lang_helper.mo +0 -0
  299. data/samples/rails/locale/ko/LC_MESSAGES/lang_helper.mo +0 -0
  300. data/samples/rails/log/development.log +0 -378
  301. data/src/rmsgfmt.ry +0 -233
@@ -1,41 +1,12 @@
1
1
  // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
2
2
  // (c) 2005 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
3
+ // (c) 2005 Jon Tirsen (http://www.tirsen.com)
4
+ // Contributors:
5
+ // Richard Livsey
6
+ // Rahul Bhargava
7
+ // Rob Wills
3
8
  //
4
- // Permission is hereby granted, free of charge, to any person obtaining
5
- // a copy of this software and associated documentation files (the
6
- // "Software"), to deal in the Software without restriction, including
7
- // without limitation the rights to use, copy, modify, merge, publish,
8
- // distribute, sublicense, and/or sell copies of the Software, and to
9
- // permit persons to whom the Software is furnished to do so, subject to
10
- // the following conditions:
11
- //
12
- // The above copyright notice and this permission notice shall be
13
- // included in all copies or substantial portions of the Software.
14
- //
15
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
-
23
- Element.collectTextNodesIgnoreClass = function(element, ignoreclass) {
24
- var children = $(element).childNodes;
25
- var text = "";
26
- var classtest = new RegExp("^([^ ]+ )*" + ignoreclass+ "( [^ ]+)*$","i");
27
-
28
- for (var i = 0; i < children.length; i++) {
29
- if(children[i].nodeType==3) {
30
- text+=children[i].nodeValue;
31
- } else {
32
- if((!children[i].className.match(classtest)) && children[i].hasChildNodes())
33
- text += Element.collectTextNodesIgnoreClass(children[i], ignoreclass);
34
- }
35
- }
36
-
37
- return text;
38
- }
9
+ // See scriptaculous.js for full license.
39
10
 
40
11
  // Autocompleter.Base handles all the autocompletion functionality
41
12
  // that's independent of the data source for autocompletion. This
@@ -46,7 +17,7 @@ Element.collectTextNodesIgnoreClass = function(element, ignoreclass) {
46
17
  // a getUpdatedChoices function that will be invoked every time
47
18
  // the text inside the monitored textbox changes. This method
48
19
  // should get the text for which to provide autocompletion by
49
- // invoking this.getEntry(), NOT by directly accessing
20
+ // invoking this.getToken(), NOT by directly accessing
50
21
  // this.element.value. This is to allow incremental tokenized
51
22
  // autocompletion. Specific auto-completion logic (AJAX, etc)
52
23
  // belongs in getUpdatedChoices.
@@ -57,7 +28,7 @@ Element.collectTextNodesIgnoreClass = function(element, ignoreclass) {
57
28
  // new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' });
58
29
  // will incrementally autocomplete with a comma as the token.
59
30
  // Additionally, ',' in the above example can be replaced with
60
- // a token array, e.g. { tokens: new Array (',', '\n') } which
31
+ // a token array, e.g. { tokens: [',', '\n'] } which
61
32
  // enables autocompletion on multiple tokens. This is most
62
33
  // useful when one of the tokens is \n (a newline), as it
63
34
  // allows smart autocompletion after linebreaks.
@@ -65,79 +36,79 @@ Element.collectTextNodesIgnoreClass = function(element, ignoreclass) {
65
36
  var Autocompleter = {}
66
37
  Autocompleter.Base = function() {};
67
38
  Autocompleter.Base.prototype = {
68
- base_initialize: function(element, update, options) {
39
+ baseInitialize: function(element, update, options) {
69
40
  this.element = $(element);
70
41
  this.update = $(update);
71
- this.has_focus = false;
42
+ this.hasFocus = false;
72
43
  this.changed = false;
73
44
  this.active = false;
74
45
  this.index = 0;
75
- this.entry_count = 0;
46
+ this.entryCount = 0;
76
47
 
77
48
  if (this.setOptions)
78
49
  this.setOptions(options);
79
50
  else
80
- this.options = {}
81
-
82
- this.options.tokens = this.options.tokens || new Array();
51
+ this.options = options || {};
52
+
53
+ this.options.paramName = this.options.paramName || this.element.name;
54
+ this.options.tokens = this.options.tokens || [];
83
55
  this.options.frequency = this.options.frequency || 0.4;
84
- this.options.min_chars = this.options.min_chars || 1;
56
+ this.options.minChars = this.options.minChars || 1;
85
57
  this.options.onShow = this.options.onShow ||
86
58
  function(element, update){
87
59
  if(!update.style.position || update.style.position=='absolute') {
88
60
  update.style.position = 'absolute';
89
- var offsets = Position.cumulativeOffset(element);
90
- update.style.left = offsets[0] + 'px';
91
- update.style.top = (offsets[1] + element.offsetHeight) + 'px';
92
- update.style.width = element.offsetWidth + 'px';
61
+ Position.clone(element, update, {setHeight: false, offsetTop: element.offsetHeight});
93
62
  }
94
- new Effect.Appear(update,{duration:0.15});
63
+ Effect.Appear(update,{duration:0.15});
95
64
  };
96
65
  this.options.onHide = this.options.onHide ||
97
66
  function(element, update){ new Effect.Fade(update,{duration:0.15}) };
98
-
99
- if(this.options.indicator)
100
- this.indicator = $(this.options.indicator);
101
67
 
102
68
  if (typeof(this.options.tokens) == 'string')
103
69
  this.options.tokens = new Array(this.options.tokens);
104
-
70
+
105
71
  this.observer = null;
106
72
 
73
+ this.element.setAttribute('autocomplete','off');
74
+
107
75
  Element.hide(this.update);
108
-
76
+
109
77
  Event.observe(this.element, "blur", this.onBlur.bindAsEventListener(this));
110
78
  Event.observe(this.element, "keypress", this.onKeyPress.bindAsEventListener(this));
111
79
  },
112
80
 
113
81
  show: function() {
114
- if(this.update.style.display=='none') this.options.onShow(this.element, this.update);
115
- if(!this.iefix && (navigator.appVersion.indexOf('MSIE')>0) && this.update.style.position=='absolute') {
82
+ if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
83
+ if(!this.iefix && (navigator.appVersion.indexOf('MSIE')>0) && (Element.getStyle(this.update, 'position')=='absolute')) {
116
84
  new Insertion.After(this.update,
117
85
  '<iframe id="' + this.update.id + '_iefix" '+
118
- 'style="display:none;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
86
+ 'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
119
87
  'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
120
88
  this.iefix = $(this.update.id+'_iefix');
121
89
  }
122
- if(this.iefix) {
123
- Position.clone(this.update, this.iefix);
124
- this.iefix.style.zIndex = 1;
125
- this.update.style.zIndex = 2;
126
- Element.show(this.iefix);
127
- }
90
+ if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
128
91
  },
129
92
 
93
+ fixIEOverlapping: function() {
94
+ Position.clone(this.update, this.iefix);
95
+ this.iefix.style.zIndex = 1;
96
+ this.update.style.zIndex = 2;
97
+ Element.show(this.iefix);
98
+ },
99
+
130
100
  hide: function() {
131
- if(this.update.style.display=='') this.options.onHide(this.element, this.update);
101
+ this.stopIndicator();
102
+ if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update);
132
103
  if(this.iefix) Element.hide(this.iefix);
133
104
  },
134
-
105
+
135
106
  startIndicator: function() {
136
- if(this.indicator) Element.show(this.indicator);
107
+ if(this.options.indicator) Element.show(this.options.indicator);
137
108
  },
138
-
109
+
139
110
  stopIndicator: function() {
140
- if(this.indicator) Element.hide(this.indicator);
111
+ if(this.options.indicator) Element.hide(this.options.indicator);
141
112
  },
142
113
 
143
114
  onKeyPress: function(event) {
@@ -145,22 +116,23 @@ Autocompleter.Base.prototype = {
145
116
  switch(event.keyCode) {
146
117
  case Event.KEY_TAB:
147
118
  case Event.KEY_RETURN:
148
- this.select_entry();
119
+ this.selectEntry();
149
120
  Event.stop(event);
150
121
  case Event.KEY_ESC:
151
122
  this.hide();
152
123
  this.active = false;
124
+ Event.stop(event);
153
125
  return;
154
126
  case Event.KEY_LEFT:
155
127
  case Event.KEY_RIGHT:
156
128
  return;
157
129
  case Event.KEY_UP:
158
- this.mark_previous();
130
+ this.markPrevious();
159
131
  this.render();
160
132
  if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event);
161
133
  return;
162
134
  case Event.KEY_DOWN:
163
- this.mark_next();
135
+ this.markNext();
164
136
  this.render();
165
137
  if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event);
166
138
  return;
@@ -168,15 +140,15 @@ Autocompleter.Base.prototype = {
168
140
  else
169
141
  if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN)
170
142
  return;
171
-
143
+
172
144
  this.changed = true;
173
- this.has_focus = true;
174
-
145
+ this.hasFocus = true;
146
+
175
147
  if(this.observer) clearTimeout(this.observer);
176
148
  this.observer =
177
149
  setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
178
150
  },
179
-
151
+
180
152
  onHover: function(event) {
181
153
  var element = Event.findElement(event, 'LI');
182
154
  if(this.index != element.autocompleteIndex)
@@ -190,92 +162,100 @@ Autocompleter.Base.prototype = {
190
162
  onClick: function(event) {
191
163
  var element = Event.findElement(event, 'LI');
192
164
  this.index = element.autocompleteIndex;
193
- this.select_entry();
194
- Event.stop(event);
165
+ this.selectEntry();
166
+ this.hide();
195
167
  },
196
168
 
197
169
  onBlur: function(event) {
198
170
  // needed to make click events working
199
171
  setTimeout(this.hide.bind(this), 250);
200
- this.has_focus = false;
172
+ this.hasFocus = false;
201
173
  this.active = false;
202
174
  },
203
175
 
204
176
  render: function() {
205
- if(this.entry_count > 0) {
206
- for (var i = 0; i < this.entry_count; i++)
177
+ if(this.entryCount > 0) {
178
+ for (var i = 0; i < this.entryCount; i++)
207
179
  this.index==i ?
208
- Element.addClassName(this.get_entry(i),"selected") :
209
- Element.removeClassName(this.get_entry(i),"selected");
210
-
211
- if(this.has_focus) {
212
- if(this.get_current_entry().scrollIntoView)
213
- this.get_current_entry().scrollIntoView(false);
180
+ Element.addClassName(this.getEntry(i),"selected") :
181
+ Element.removeClassName(this.getEntry(i),"selected");
214
182
 
183
+ if(this.hasFocus) {
215
184
  this.show();
216
185
  this.active = true;
217
186
  }
218
- } else this.hide();
187
+ } else {
188
+ this.active = false;
189
+ this.hide();
190
+ }
219
191
  },
220
192
 
221
- mark_previous: function() {
193
+ markPrevious: function() {
222
194
  if(this.index > 0) this.index--
223
- else this.index = this.entry_count-1;
195
+ else this.index = this.entryCount-1;
224
196
  },
225
197
 
226
- mark_next: function() {
227
- if(this.index < this.entry_count-1) this.index++
198
+ markNext: function() {
199
+ if(this.index < this.entryCount-1) this.index++
228
200
  else this.index = 0;
229
201
  },
230
202
 
231
- get_entry: function(index) {
203
+ getEntry: function(index) {
232
204
  return this.update.firstChild.childNodes[index];
233
205
  },
234
206
 
235
- get_current_entry: function() {
236
- return this.get_entry(this.index);
207
+ getCurrentEntry: function() {
208
+ return this.getEntry(this.index);
237
209
  },
238
210
 
239
- select_entry: function() {
211
+ selectEntry: function() {
240
212
  this.active = false;
241
- value = Element.collectTextNodesIgnoreClass(this.get_current_entry(), 'informal').unescapeHTML();
242
- this.updateElement(value);
243
- this.element.focus();
213
+ this.updateElement(this.getCurrentEntry());
244
214
  },
245
215
 
246
- updateElement: function(value) {
247
- var last_token_pos = this.findLastToken();
248
- if (last_token_pos != -1) {
249
- var new_value = this.element.value.substr(0, last_token_pos + 1);
250
- var whitespace = this.element.value.substr(last_token_pos + 1).match(/^\s+/);
216
+ updateElement: function(selectedElement) {
217
+ if (this.options.updateElement) {
218
+ this.options.updateElement(selectedElement);
219
+ return;
220
+ }
221
+
222
+ var value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
223
+ var lastTokenPos = this.findLastToken();
224
+ if (lastTokenPos != -1) {
225
+ var newValue = this.element.value.substr(0, lastTokenPos + 1);
226
+ var whitespace = this.element.value.substr(lastTokenPos + 1).match(/^\s+/);
251
227
  if (whitespace)
252
- new_value += whitespace[0];
253
- this.element.value = new_value + value;
228
+ newValue += whitespace[0];
229
+ this.element.value = newValue + value;
254
230
  } else {
255
231
  this.element.value = value;
256
- }
232
+ }
233
+ this.element.focus();
234
+
235
+ if (this.options.afterUpdateElement)
236
+ this.options.afterUpdateElement(this.element, selectedElement);
257
237
  },
258
-
238
+
259
239
  updateChoices: function(choices) {
260
- if(!this.changed && this.has_focus) {
240
+ if(!this.changed && this.hasFocus) {
261
241
  this.update.innerHTML = choices;
262
242
  Element.cleanWhitespace(this.update);
263
243
  Element.cleanWhitespace(this.update.firstChild);
264
244
 
265
245
  if(this.update.firstChild && this.update.firstChild.childNodes) {
266
- this.entry_count =
246
+ this.entryCount =
267
247
  this.update.firstChild.childNodes.length;
268
- for (var i = 0; i < this.entry_count; i++) {
269
- entry = this.get_entry(i);
248
+ for (var i = 0; i < this.entryCount; i++) {
249
+ var entry = this.getEntry(i);
270
250
  entry.autocompleteIndex = i;
271
251
  this.addObservers(entry);
272
252
  }
273
253
  } else {
274
- this.entry_count = 0;
254
+ this.entryCount = 0;
275
255
  }
276
-
256
+
277
257
  this.stopIndicator();
278
-
258
+
279
259
  this.index = 0;
280
260
  this.render();
281
261
  }
@@ -288,7 +268,7 @@ Autocompleter.Base.prototype = {
288
268
 
289
269
  onObserverEvent: function() {
290
270
  this.changed = false;
291
- if(this.getEntry().length>=this.options.min_chars) {
271
+ if(this.getToken().length>=this.options.minChars) {
292
272
  this.startIndicator();
293
273
  this.getUpdatedChoices();
294
274
  } else {
@@ -297,58 +277,56 @@ Autocompleter.Base.prototype = {
297
277
  }
298
278
  },
299
279
 
300
- getEntry: function() {
301
- var token_pos = this.findLastToken();
302
- if (token_pos != -1)
303
- var ret = this.element.value.substr(token_pos + 1).replace(/^\s+/,'').replace(/\s+$/,'');
280
+ getToken: function() {
281
+ var tokenPos = this.findLastToken();
282
+ if (tokenPos != -1)
283
+ var ret = this.element.value.substr(tokenPos + 1).replace(/^\s+/,'').replace(/\s+$/,'');
304
284
  else
305
285
  var ret = this.element.value;
306
-
286
+
307
287
  return /\n/.test(ret) ? '' : ret;
308
288
  },
309
289
 
310
290
  findLastToken: function() {
311
- var last_token_pos = -1;
291
+ var lastTokenPos = -1;
312
292
 
313
293
  for (var i=0; i<this.options.tokens.length; i++) {
314
- var this_token_pos = this.element.value.lastIndexOf(this.options.tokens[i]);
315
- if (this_token_pos > last_token_pos)
316
- last_token_pos = this_token_pos;
294
+ var thisTokenPos = this.element.value.lastIndexOf(this.options.tokens[i]);
295
+ if (thisTokenPos > lastTokenPos)
296
+ lastTokenPos = thisTokenPos;
317
297
  }
318
- return last_token_pos;
298
+ return lastTokenPos;
319
299
  }
320
300
  }
321
301
 
322
302
  Ajax.Autocompleter = Class.create();
323
- Ajax.Autocompleter.prototype = Object.extend(new Autocompleter.Base(),
324
- Object.extend(new Ajax.Base(), {
303
+ Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.prototype), {
325
304
  initialize: function(element, update, url, options) {
326
- this.base_initialize(element, update, options);
305
+ this.baseInitialize(element, update, options);
327
306
  this.options.asynchronous = true;
328
- this.options.onComplete = this.onComplete.bind(this)
329
- this.options.method = 'post';
307
+ this.options.onComplete = this.onComplete.bind(this);
330
308
  this.options.defaultParams = this.options.parameters || null;
331
309
  this.url = url;
332
310
  },
333
-
311
+
334
312
  getUpdatedChoices: function() {
335
- entry = encodeURIComponent(this.element.name) + '=' +
336
- encodeURIComponent(this.getEntry());
337
-
313
+ entry = encodeURIComponent(this.options.paramName) + '=' +
314
+ encodeURIComponent(this.getToken());
315
+
338
316
  this.options.parameters = this.options.callback ?
339
317
  this.options.callback(this.element, entry) : entry;
340
-
318
+
341
319
  if(this.options.defaultParams)
342
320
  this.options.parameters += '&' + this.options.defaultParams;
343
-
321
+
344
322
  new Ajax.Request(this.url, this.options);
345
323
  },
346
-
324
+
347
325
  onComplete: function(request) {
348
326
  this.updateChoices(request.responseText);
349
327
  }
350
328
 
351
- }));
329
+ });
352
330
 
353
331
  // The local array autocompleter. Used when you'd prefer to
354
332
  // inject an array of autocompletion options into the page, rather
@@ -362,22 +340,22 @@ Object.extend(new Ajax.Base(), {
362
340
  // Extra local autocompletion options:
363
341
  // - choices - How many autocompletion choices to offer
364
342
  //
365
- // - partial_search - If false, the autocompleter will match entered
343
+ // - partialSearch - If false, the autocompleter will match entered
366
344
  // text only at the beginning of strings in the
367
345
  // autocomplete array. Defaults to true, which will
368
346
  // match text at the beginning of any *word* in the
369
347
  // strings in the autocomplete array. If you want to
370
348
  // search anywhere in the string, additionally set
371
- // the option full_search to true (default: off).
349
+ // the option fullSearch to true (default: off).
372
350
  //
373
- // - full_search - Search anywhere in autocomplete array strings.
351
+ // - fullSsearch - Search anywhere in autocomplete array strings.
374
352
  //
375
- // - partial_chars - How many characters to enter before triggering
376
- // a partial match (unlike min_chars, which defines
353
+ // - partialChars - How many characters to enter before triggering
354
+ // a partial match (unlike minChars, which defines
377
355
  // how many characters are required to do any match
378
356
  // at all). Defaults to 2.
379
357
  //
380
- // - ignore_case - Whether to ignore case when autocompleting.
358
+ // - ignoreCase - Whether to ignore case when autocompleting.
381
359
  // Defaults to true.
382
360
  //
383
361
  // It's possible to pass in a custom function as the 'selector'
@@ -388,7 +366,7 @@ Object.extend(new Ajax.Base(), {
388
366
  Autocompleter.Local = Class.create();
389
367
  Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), {
390
368
  initialize: function(element, update, array, options) {
391
- this.base_initialize(element, update, options);
369
+ this.baseInitialize(element, update, options);
392
370
  this.options.array = array;
393
371
  },
394
372
 
@@ -399,41 +377,42 @@ Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), {
399
377
  setOptions: function(options) {
400
378
  this.options = Object.extend({
401
379
  choices: 10,
402
- partial_search: true,
403
- partial_chars: 2,
404
- ignore_case: true,
405
- full_search: false,
380
+ partialSearch: true,
381
+ partialChars: 2,
382
+ ignoreCase: true,
383
+ fullSearch: false,
406
384
  selector: function(instance) {
407
- var ret = new Array(); // Beginning matches
408
- var partial = new Array(); // Inside matches
409
- var entry = instance.getEntry();
385
+ var ret = []; // Beginning matches
386
+ var partial = []; // Inside matches
387
+ var entry = instance.getToken();
410
388
  var count = 0;
411
-
389
+
412
390
  for (var i = 0; i < instance.options.array.length &&
413
- ret.length < instance.options.choices ; i++) {
391
+ ret.length < instance.options.choices ; i++) {
392
+
414
393
  var elem = instance.options.array[i];
415
- var found_pos = instance.options.ignore_case ?
394
+ var foundPos = instance.options.ignoreCase ?
416
395
  elem.toLowerCase().indexOf(entry.toLowerCase()) :
417
396
  elem.indexOf(entry);
418
397
 
419
- while (found_pos != -1) {
420
- if (found_pos == 0 && elem.length != entry.length) {
398
+ while (foundPos != -1) {
399
+ if (foundPos == 0 && elem.length != entry.length) {
421
400
  ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
422
401
  elem.substr(entry.length) + "</li>");
423
402
  break;
424
- } else if (entry.length >= instance.options.partial_chars &&
425
- instance.options.partial_search && found_pos != -1) {
426
- if (instance.options.full_search || /\s/.test(elem.substr(found_pos-1,1))) {
427
- partial.push("<li>" + elem.substr(0, found_pos) + "<strong>" +
428
- elem.substr(found_pos, entry.length) + "</strong>" + elem.substr(
429
- found_pos + entry.length) + "</li>");
403
+ } else if (entry.length >= instance.options.partialChars &&
404
+ instance.options.partialSearch && foundPos != -1) {
405
+ if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
406
+ partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
407
+ elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
408
+ foundPos + entry.length) + "</li>");
430
409
  break;
431
410
  }
432
411
  }
433
412
 
434
- found_pos = instance.options.ignore_case ?
435
- elem.toLowerCase().indexOf(entry.toLowerCase(), found_pos + 1) :
436
- elem.indexOf(entry, found_pos + 1);
413
+ foundPos = instance.options.ignoreCase ?
414
+ elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
415
+ elem.indexOf(entry, foundPos + 1);
437
416
 
438
417
  }
439
418
  }
@@ -444,3 +423,299 @@ Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), {
444
423
  }, options || {});
445
424
  }
446
425
  });
426
+
427
+ // AJAX in-place editor
428
+ //
429
+ // see documentation on http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor
430
+
431
+ // Use this if you notice weird scrolling problems on some browsers,
432
+ // the DOM might be a bit confused when this gets called so do this
433
+ // waits 1 ms (with setTimeout) until it does the activation
434
+ Field.scrollFreeActivate = function(field) {
435
+ setTimeout(function() {
436
+ Field.activate(field);
437
+ }, 1);
438
+ }
439
+
440
+ Ajax.InPlaceEditor = Class.create();
441
+ Ajax.InPlaceEditor.defaultHighlightColor = "#FFFF99";
442
+ Ajax.InPlaceEditor.prototype = {
443
+ initialize: function(element, url, options) {
444
+ this.url = url;
445
+ this.element = $(element);
446
+
447
+ this.options = Object.extend({
448
+ okText: "ok",
449
+ cancelText: "cancel",
450
+ savingText: "Saving...",
451
+ clickToEditText: "Click to edit",
452
+ okText: "ok",
453
+ rows: 1,
454
+ onComplete: function(transport, element) {
455
+ new Effect.Highlight(element, {startcolor: this.options.highlightcolor});
456
+ },
457
+ onFailure: function(transport) {
458
+ alert("Error communicating with the server: " + transport.responseText.stripTags());
459
+ },
460
+ callback: function(form) {
461
+ return Form.serialize(form);
462
+ },
463
+ handleLineBreaks: true,
464
+ loadingText: 'Loading...',
465
+ savingClassName: 'inplaceeditor-saving',
466
+ loadingClassName: 'inplaceeditor-loading',
467
+ formClassName: 'inplaceeditor-form',
468
+ highlightcolor: Ajax.InPlaceEditor.defaultHighlightColor,
469
+ highlightendcolor: "#FFFFFF",
470
+ externalControl: null,
471
+ ajaxOptions: {}
472
+ }, options || {});
473
+
474
+ if(!this.options.formId && this.element.id) {
475
+ this.options.formId = this.element.id + "-inplaceeditor";
476
+ if ($(this.options.formId)) {
477
+ // there's already a form with that name, don't specify an id
478
+ this.options.formId = null;
479
+ }
480
+ }
481
+
482
+ if (this.options.externalControl) {
483
+ this.options.externalControl = $(this.options.externalControl);
484
+ }
485
+
486
+ this.originalBackground = Element.getStyle(this.element, 'background-color');
487
+ if (!this.originalBackground) {
488
+ this.originalBackground = "transparent";
489
+ }
490
+
491
+ this.element.title = this.options.clickToEditText;
492
+
493
+ this.onclickListener = this.enterEditMode.bindAsEventListener(this);
494
+ this.mouseoverListener = this.enterHover.bindAsEventListener(this);
495
+ this.mouseoutListener = this.leaveHover.bindAsEventListener(this);
496
+ Event.observe(this.element, 'click', this.onclickListener);
497
+ Event.observe(this.element, 'mouseover', this.mouseoverListener);
498
+ Event.observe(this.element, 'mouseout', this.mouseoutListener);
499
+ if (this.options.externalControl) {
500
+ Event.observe(this.options.externalControl, 'click', this.onclickListener);
501
+ Event.observe(this.options.externalControl, 'mouseover', this.mouseoverListener);
502
+ Event.observe(this.options.externalControl, 'mouseout', this.mouseoutListener);
503
+ }
504
+ },
505
+ enterEditMode: function(evt) {
506
+ if (this.saving) return;
507
+ if (this.editing) return;
508
+ this.editing = true;
509
+ this.onEnterEditMode();
510
+ if (this.options.externalControl) {
511
+ Element.hide(this.options.externalControl);
512
+ }
513
+ Element.hide(this.element);
514
+ this.createForm();
515
+ this.element.parentNode.insertBefore(this.form, this.element);
516
+ Field.scrollFreeActivate(this.editField);
517
+ // stop the event to avoid a page refresh in Safari
518
+ if (evt) {
519
+ Event.stop(evt);
520
+ }
521
+ return false;
522
+ },
523
+ createForm: function() {
524
+ this.form = document.createElement("form");
525
+ this.form.id = this.options.formId;
526
+ Element.addClassName(this.form, this.options.formClassName)
527
+ this.form.onsubmit = this.onSubmit.bind(this);
528
+
529
+ this.createEditField();
530
+
531
+ if (this.options.textarea) {
532
+ var br = document.createElement("br");
533
+ this.form.appendChild(br);
534
+ }
535
+
536
+ okButton = document.createElement("input");
537
+ okButton.type = "submit";
538
+ okButton.value = this.options.okText;
539
+ this.form.appendChild(okButton);
540
+
541
+ cancelLink = document.createElement("a");
542
+ cancelLink.href = "#";
543
+ cancelLink.appendChild(document.createTextNode(this.options.cancelText));
544
+ cancelLink.onclick = this.onclickCancel.bind(this);
545
+ this.form.appendChild(cancelLink);
546
+ },
547
+ hasHTMLLineBreaks: function(string) {
548
+ if (!this.options.handleLineBreaks) return false;
549
+ return string.match(/<br/i) || string.match(/<p>/i);
550
+ },
551
+ convertHTMLLineBreaks: function(string) {
552
+ return string.replace(/<br>/gi, "\n").replace(/<br\/>/gi, "\n").replace(/<\/p>/gi, "\n").replace(/<p>/gi, "");
553
+ },
554
+ createEditField: function() {
555
+ var text;
556
+ if(this.options.loadTextURL) {
557
+ text = this.options.loadingText;
558
+ } else {
559
+ text = this.getText();
560
+ }
561
+
562
+ if (this.options.rows == 1 && !this.hasHTMLLineBreaks(text)) {
563
+ this.options.textarea = false;
564
+ var textField = document.createElement("input");
565
+ textField.type = "text";
566
+ textField.name = "value";
567
+ textField.value = text;
568
+ textField.style.backgroundColor = this.options.highlightcolor;
569
+ var size = this.options.size || this.options.cols || 0;
570
+ if (size != 0) textField.size = size;
571
+ this.editField = textField;
572
+ } else {
573
+ this.options.textarea = true;
574
+ var textArea = document.createElement("textarea");
575
+ textArea.name = "value";
576
+ textArea.value = this.convertHTMLLineBreaks(text);
577
+ textArea.rows = this.options.rows;
578
+ textArea.cols = this.options.cols || 40;
579
+ this.editField = textArea;
580
+ }
581
+
582
+ if(this.options.loadTextURL) {
583
+ this.loadExternalText();
584
+ }
585
+ this.form.appendChild(this.editField);
586
+ },
587
+ getText: function() {
588
+ return this.element.innerHTML;
589
+ },
590
+ loadExternalText: function() {
591
+ Element.addClassName(this.form, this.options.loadingClassName);
592
+ this.editField.disabled = true;
593
+ new Ajax.Request(
594
+ this.options.loadTextURL,
595
+ Object.extend({
596
+ asynchronous: true,
597
+ onComplete: this.onLoadedExternalText.bind(this)
598
+ }, this.options.ajaxOptions)
599
+ );
600
+ },
601
+ onLoadedExternalText: function(transport) {
602
+ Element.removeClassName(this.form, this.options.loadingClassName);
603
+ this.editField.disabled = false;
604
+ this.editField.value = transport.responseText.stripTags();
605
+ },
606
+ onclickCancel: function() {
607
+ this.onComplete();
608
+ this.leaveEditMode();
609
+ return false;
610
+ },
611
+ onFailure: function(transport) {
612
+ this.options.onFailure(transport);
613
+ if (this.oldInnerHTML) {
614
+ this.element.innerHTML = this.oldInnerHTML;
615
+ this.oldInnerHTML = null;
616
+ }
617
+ return false;
618
+ },
619
+ onSubmit: function() {
620
+ // onLoading resets these so we need to save them away for the Ajax call
621
+ var form = this.form;
622
+ var value = this.editField.value;
623
+
624
+ // do this first, sometimes the ajax call returns before we get a chance to switch on Saving...
625
+ // which means this will actually switch on Saving... *after* we've left edit mode causing Saving...
626
+ // to be displayed indefinitely
627
+ this.onLoading();
628
+
629
+ new Ajax.Updater(
630
+ {
631
+ success: this.element,
632
+ // don't update on failure (this could be an option)
633
+ failure: null
634
+ },
635
+ this.url,
636
+ Object.extend({
637
+ parameters: this.options.callback(form, value),
638
+ onComplete: this.onComplete.bind(this),
639
+ onFailure: this.onFailure.bind(this)
640
+ }, this.options.ajaxOptions)
641
+ );
642
+ // stop the event to avoid a page refresh in Safari
643
+ if (arguments.length > 1) {
644
+ Event.stop(arguments[0]);
645
+ }
646
+ return false;
647
+ },
648
+ onLoading: function() {
649
+ this.saving = true;
650
+ this.removeForm();
651
+ this.leaveHover();
652
+ this.showSaving();
653
+ },
654
+ showSaving: function() {
655
+ this.oldInnerHTML = this.element.innerHTML;
656
+ this.element.innerHTML = this.options.savingText;
657
+ Element.addClassName(this.element, this.options.savingClassName);
658
+ this.element.style.backgroundColor = this.originalBackground;
659
+ Element.show(this.element);
660
+ },
661
+ removeForm: function() {
662
+ if(this.form) {
663
+ if (this.form.parentNode) Element.remove(this.form);
664
+ this.form = null;
665
+ }
666
+ },
667
+ enterHover: function() {
668
+ if (this.saving) return;
669
+ this.element.style.backgroundColor = this.options.highlightcolor;
670
+ if (this.effect) {
671
+ this.effect.cancel();
672
+ }
673
+ Element.addClassName(this.element, this.options.hoverClassName)
674
+ },
675
+ leaveHover: function() {
676
+ if (this.options.backgroundColor) {
677
+ this.element.style.backgroundColor = this.oldBackground;
678
+ }
679
+ Element.removeClassName(this.element, this.options.hoverClassName)
680
+ if (this.saving) return;
681
+ this.effect = new Effect.Highlight(this.element, {
682
+ startcolor: this.options.highlightcolor,
683
+ endcolor: this.options.highlightendcolor,
684
+ restorecolor: this.originalBackground
685
+ });
686
+ },
687
+ leaveEditMode: function() {
688
+ Element.removeClassName(this.element, this.options.savingClassName);
689
+ this.removeForm();
690
+ this.leaveHover();
691
+ this.element.style.backgroundColor = this.originalBackground;
692
+ Element.show(this.element);
693
+ if (this.options.externalControl) {
694
+ Element.show(this.options.externalControl);
695
+ }
696
+ this.editing = false;
697
+ this.saving = false;
698
+ this.oldInnerHTML = null;
699
+ this.onLeaveEditMode();
700
+ },
701
+ onComplete: function(transport) {
702
+ this.leaveEditMode();
703
+ this.options.onComplete.bind(this)(transport, this.element);
704
+ },
705
+ onEnterEditMode: function() {},
706
+ onLeaveEditMode: function() {},
707
+ dispose: function() {
708
+ if (this.oldInnerHTML) {
709
+ this.element.innerHTML = this.oldInnerHTML;
710
+ }
711
+ this.leaveEditMode();
712
+ Event.stopObserving(this.element, 'click', this.onclickListener);
713
+ Event.stopObserving(this.element, 'mouseover', this.mouseoverListener);
714
+ Event.stopObserving(this.element, 'mouseout', this.mouseoutListener);
715
+ if (this.options.externalControl) {
716
+ Event.stopObserving(this.options.externalControl, 'click', this.onclickListener);
717
+ Event.stopObserving(this.options.externalControl, 'mouseover', this.mouseoverListener);
718
+ Event.stopObserving(this.options.externalControl, 'mouseout', this.mouseoutListener);
719
+ }
720
+ }
721
+ };