riojs 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +24 -0
  3. data/VERSION +1 -0
  4. data/bin/rio +5 -0
  5. data/generators/rio_app/USAGE +19 -0
  6. data/generators/rio_app/rio_app_generator.rb +40 -0
  7. data/generators/rio_app/templates/app.build +10 -0
  8. data/generators/rio_app/templates/app.css +0 -0
  9. data/generators/rio_app/templates/app.js +20 -0
  10. data/generators/rio_app/templates/app_view.html.erb +19 -0
  11. data/generators/rio_app/templates/fixture.js +4 -0
  12. data/generators/rio_app/templates/rio.html.erb +18 -0
  13. data/generators/rio_app/templates/rio_controller.rb +2 -0
  14. data/generators/rio_app/templates/spec.js +7 -0
  15. data/generators/rio_component/USAGE +13 -0
  16. data/generators/rio_component/rio_component_generator.rb +16 -0
  17. data/generators/rio_component/templates/component.css +0 -0
  18. data/generators/rio_component/templates/component.js +11 -0
  19. data/generators/rio_component/templates/fixture.js +3 -0
  20. data/generators/rio_component/templates/spec.js +6 -0
  21. data/generators/rio_model/USAGE +12 -0
  22. data/generators/rio_model/rio_model_generator.rb +21 -0
  23. data/generators/rio_model/templates/fixture.js +3 -0
  24. data/generators/rio_model/templates/model.js +9 -0
  25. data/generators/rio_model/templates/spec.js +6 -0
  26. data/generators/rio_page/USAGE +14 -0
  27. data/generators/rio_page/rio_page_generator.rb +16 -0
  28. data/generators/rio_page/templates/fixture.js +3 -0
  29. data/generators/rio_page/templates/page.css +12 -0
  30. data/generators/rio_page/templates/page.js +12 -0
  31. data/generators/rio_page/templates/page.jst +64 -0
  32. data/generators/rio_page/templates/spec.js +6 -0
  33. data/generators/rio_resource/USAGE +20 -0
  34. data/generators/rio_resource/rio_resource_generator.rb +10 -0
  35. data/generators/rio_resource/templates/controller.rb +3 -0
  36. data/init.rb +4 -0
  37. data/install/config/juggernaut_hosts.yml +18 -0
  38. data/install/lib/tasks/rio.rake +1 -0
  39. data/install/script/rio_server +37 -0
  40. data/lib/rio/autospec.rb +86 -0
  41. data/lib/rio/install.rb +90 -0
  42. data/lib/rio/juggernaut.rb +212 -0
  43. data/lib/rio/path.rb +3 -0
  44. data/lib/rio/rio_compressor.rb +219 -0
  45. data/lib/rio/rio_file_controller.rb +16 -0
  46. data/lib/rio/rio_on_rails.rb +586 -0
  47. data/lib/rio/rio_proxy_controller.rb +60 -0
  48. data/lib/rio/rio_push_controller.rb +48 -0
  49. data/lib/rio/rio_routes.rb +24 -0
  50. data/lib/rio/rio_spec_controller.rb +70 -0
  51. data/lib/riojs.rb +14 -0
  52. data/lib/tasks/rio.rb +63 -0
  53. data/public/images/background-chiffon.png +0 -0
  54. data/public/images/button-gradient-overlay-down.png +0 -0
  55. data/public/images/button-gradient-overlay.png +0 -0
  56. data/public/images/icons/add.png +0 -0
  57. data/public/images/icons/error-big.png +0 -0
  58. data/public/images/icons/warning-big.png +0 -0
  59. data/public/images/rio-logo-big.png +0 -0
  60. data/public/images/rio-logo.png +0 -0
  61. data/public/images/splitter-handle-horizontal.png +0 -0
  62. data/public/images/splitter-handle-vertical.png +0 -0
  63. data/public/images/tab-bar-gradient-overlay.png +0 -0
  64. data/public/images/title-gradient-overlay.png +0 -0
  65. data/public/images/trash.gif +0 -0
  66. data/public/javascripts/components/accordion.js +144 -0
  67. data/public/javascripts/components/alert_box.js +59 -0
  68. data/public/javascripts/components/base.js +47 -0
  69. data/public/javascripts/components/box.js +63 -0
  70. data/public/javascripts/components/button.js +98 -0
  71. data/public/javascripts/components/checkbox.js +44 -0
  72. data/public/javascripts/components/container.js +265 -0
  73. data/public/javascripts/components/grid_view.js +107 -0
  74. data/public/javascripts/components/image.js +19 -0
  75. data/public/javascripts/components/input.js +171 -0
  76. data/public/javascripts/components/label.js +15 -0
  77. data/public/javascripts/components/lightbox.js +160 -0
  78. data/public/javascripts/components/link.js +43 -0
  79. data/public/javascripts/components/list_item.js +44 -0
  80. data/public/javascripts/components/list_view.js +192 -0
  81. data/public/javascripts/components/marquee.js +131 -0
  82. data/public/javascripts/components/menu.js +89 -0
  83. data/public/javascripts/components/notification.js +75 -0
  84. data/public/javascripts/components/overlay.js +134 -0
  85. data/public/javascripts/components/panel.js +146 -0
  86. data/public/javascripts/components/radio.js +46 -0
  87. data/public/javascripts/components/splitter.js +65 -0
  88. data/public/javascripts/components/tab_bar.js +64 -0
  89. data/public/javascripts/components/tab_panel.js +57 -0
  90. data/public/javascripts/components/textarea.js +223 -0
  91. data/public/javascripts/components/toggle_button.js +22 -0
  92. data/public/javascripts/components/tooltip.js +80 -0
  93. data/public/javascripts/lib/application.js +482 -0
  94. data/public/javascripts/lib/attr.js +760 -0
  95. data/public/javascripts/lib/benchmark.js +235 -0
  96. data/public/javascripts/lib/blank.html +39 -0
  97. data/public/javascripts/lib/boot.js +300 -0
  98. data/public/javascripts/lib/clipboard.js +96 -0
  99. data/public/javascripts/lib/collection_entity.js +46 -0
  100. data/public/javascripts/lib/component.js +129 -0
  101. data/public/javascripts/lib/console.js +75 -0
  102. data/public/javascripts/lib/console/apps/console.build +43 -0
  103. data/public/javascripts/lib/console/apps/console.js +28 -0
  104. data/public/javascripts/lib/console/blank.html +39 -0
  105. data/public/javascripts/lib/console/components/benchmark.js +196 -0
  106. data/public/javascripts/lib/console/components/console.js +352 -0
  107. data/public/javascripts/lib/console/components/dependencies_list.js +17 -0
  108. data/public/javascripts/lib/console/components/docs.js +66 -0
  109. data/public/javascripts/lib/console/components/playground.js +30 -0
  110. data/public/javascripts/lib/console/console.html +27 -0
  111. data/public/javascripts/lib/console/console_commands.js +287 -0
  112. data/public/javascripts/lib/console/console_commands.js.rej +21 -0
  113. data/public/javascripts/lib/console/console_mixin.js +22 -0
  114. data/public/javascripts/lib/console/docs/files.html +579 -0
  115. data/public/javascripts/lib/console/docs/index.html +323 -0
  116. data/public/javascripts/lib/console/docs/symbols/Object.html +291 -0
  117. data/public/javascripts/lib/console/docs/symbols/_global_.html +413 -0
  118. data/public/javascripts/lib/console/docs/symbols/rio.AIM.html +490 -0
  119. data/public/javascripts/lib/console/docs/symbols/rio.Application.html +841 -0
  120. data/public/javascripts/lib/console/docs/symbols/rio.Attr.html +1075 -0
  121. data/public/javascripts/lib/console/docs/symbols/rio.Binding.html +272 -0
  122. data/public/javascripts/lib/console/docs/symbols/rio.Component.html +419 -0
  123. data/public/javascripts/lib/console/docs/symbols/rio.Cookie.html +543 -0
  124. data/public/javascripts/lib/console/docs/symbols/rio.DelayedTask#initialize.html +270 -0
  125. data/public/javascripts/lib/console/docs/symbols/rio.DelayedTask.html +391 -0
  126. data/public/javascripts/lib/console/docs/symbols/rio.JsTemplate.html +271 -0
  127. data/public/javascripts/lib/console/docs/symbols/rio.Juggernaut.html +329 -0
  128. data/public/javascripts/lib/console/docs/symbols/rio.Model.html +822 -0
  129. data/public/javascripts/lib/console/docs/symbols/rio.Page.html +383 -0
  130. data/public/javascripts/lib/console/docs/symbols/rio.Template.html +328 -0
  131. data/public/javascripts/lib/console/docs/symbols/rio.Utils.html +617 -0
  132. data/public/javascripts/lib/console/docs/symbols/rio.html +506 -0
  133. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_components_base.js.html +54 -0
  134. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_application.js.html +490 -0
  135. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_attr.js.html +768 -0
  136. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_boot.js.html +308 -0
  137. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_clipboard.js.html +103 -0
  138. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_collection_entity.js.html +53 -0
  139. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_component.js.html +137 -0
  140. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_cookie.js.html +81 -0
  141. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_delayed_task.js.html +68 -0
  142. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_file.js.html +80 -0
  143. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_flash_detect.js.html +129 -0
  144. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_form.js.html +95 -0
  145. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_id.js.html +50 -0
  146. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_inflector.js.html +167 -0
  147. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_js_template.js.html +283 -0
  148. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_juggernaut.js.html +303 -0
  149. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_key_map.js.html +68 -0
  150. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_layout_manager.js.html +175 -0
  151. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_log.js.html +17 -0
  152. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_model.js.html +1074 -0
  153. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_page.js.html +246 -0
  154. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_parameters.js.html +66 -0
  155. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_protohack.js.html +305 -0
  156. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_push.js.html +12 -0
  157. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_rsh.js.html +659 -0
  158. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_swfobject.js.html +12 -0
  159. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_tag.js.html +60 -0
  160. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_template.js.html +64 -0
  161. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_theme.js.html +105 -0
  162. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_undo.js.html +142 -0
  163. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_utils.js.html +87 -0
  164. data/public/javascripts/lib/console/docs/symbols/src/public_javascripts_lib_yaml.js.html +88 -0
  165. data/public/javascripts/lib/console/file-small.png +0 -0
  166. data/public/javascripts/lib/console/green-circle.png +0 -0
  167. data/public/javascripts/lib/console/loading.gif +0 -0
  168. data/public/javascripts/lib/console/pages/console_page.js +149 -0
  169. data/public/javascripts/lib/console/pages/console_page.jst +27 -0
  170. data/public/javascripts/lib/console/red-circle.png +0 -0
  171. data/public/javascripts/lib/cookie.js +74 -0
  172. data/public/javascripts/lib/delayed_task.js +61 -0
  173. data/public/javascripts/lib/dependencies.js +76 -0
  174. data/public/javascripts/lib/environment.js +30 -0
  175. data/public/javascripts/lib/event.simulate.js +137 -0
  176. data/public/javascripts/lib/expressinstall.swf +0 -0
  177. data/public/javascripts/lib/file.js +72 -0
  178. data/public/javascripts/lib/flash_detect.js +122 -0
  179. data/public/javascripts/lib/flashembed.min.js +16 -0
  180. data/public/javascripts/lib/form.js +88 -0
  181. data/public/javascripts/lib/id.js +43 -0
  182. data/public/javascripts/lib/inflector.js +160 -0
  183. data/public/javascripts/lib/instrumenter.js +106 -0
  184. data/public/javascripts/lib/js_template.js +275 -0
  185. data/public/javascripts/lib/jslint.js +4950 -0
  186. data/public/javascripts/lib/juggernaut.js +295 -0
  187. data/public/javascripts/lib/juggernaut.swf +0 -0
  188. data/public/javascripts/lib/key_map.js +60 -0
  189. data/public/javascripts/lib/layout_manager.js +167 -0
  190. data/public/javascripts/lib/model.js +1067 -0
  191. data/public/javascripts/lib/page.js +238 -0
  192. data/public/javascripts/lib/parameters.js +59 -0
  193. data/public/javascripts/lib/png_fix.js +75 -0
  194. data/public/javascripts/lib/protohack.js +297 -0
  195. data/public/javascripts/lib/push.js +5 -0
  196. data/public/javascripts/lib/rio.build +28 -0
  197. data/public/javascripts/lib/rio_development.build +5 -0
  198. data/public/javascripts/lib/rio_lint.js +66 -0
  199. data/public/javascripts/lib/rsh.js +651 -0
  200. data/public/javascripts/lib/spec.js +545 -0
  201. data/public/javascripts/lib/spec_runner.js +242 -0
  202. data/public/javascripts/lib/swfobject.js +5 -0
  203. data/public/javascripts/lib/tag.js +52 -0
  204. data/public/javascripts/lib/undo.js +134 -0
  205. data/public/javascripts/lib/utils.js +80 -0
  206. data/public/javascripts/lib/yaml.js +80 -0
  207. data/public/javascripts/pages/playground_page.js +15 -0
  208. data/public/javascripts/prototype/builder.js +146 -0
  209. data/public/javascripts/prototype/controls.js +1004 -0
  210. data/public/javascripts/prototype/dragdrop.js +1030 -0
  211. data/public/javascripts/prototype/effects.js +1137 -0
  212. data/public/javascripts/prototype/prototype.js +4320 -0
  213. data/public/javascripts/prototype/slider.js +283 -0
  214. data/public/javascripts/prototype/sound.js +67 -0
  215. data/public/javascripts/specs/components/box_spec.js +6 -0
  216. data/public/javascripts/specs/components/checkbox_spec.js +26 -0
  217. data/public/javascripts/specs/components/container_spec.js +6 -0
  218. data/public/javascripts/specs/components/input_spec.js +71 -0
  219. data/public/javascripts/specs/components/panel_spec.js +6 -0
  220. data/public/javascripts/specs/components/radio_spec.js +40 -0
  221. data/public/javascripts/specs/fixtures/components/box.js +3 -0
  222. data/public/javascripts/specs/fixtures/components/checkbox.js +9 -0
  223. data/public/javascripts/specs/fixtures/components/container.js +3 -0
  224. data/public/javascripts/specs/fixtures/components/input.js +12 -0
  225. data/public/javascripts/specs/fixtures/components/menu.js +19 -0
  226. data/public/javascripts/specs/fixtures/components/menu_item.js +18 -0
  227. data/public/javascripts/specs/fixtures/components/radio.js +11 -0
  228. data/public/javascripts/specs/lib/application_spec.js +281 -0
  229. data/public/javascripts/specs/lib/attr_spec.js +1514 -0
  230. data/public/javascripts/specs/lib/benchmark_spec.js +361 -0
  231. data/public/javascripts/specs/lib/collection_entity_spec.js +131 -0
  232. data/public/javascripts/specs/lib/component_spec.js +86 -0
  233. data/public/javascripts/specs/lib/form_spec.js +171 -0
  234. data/public/javascripts/specs/lib/id_spec.js +21 -0
  235. data/public/javascripts/specs/lib/instrumenter_spec.js +5 -0
  236. data/public/javascripts/specs/lib/js_template_spec.js +131 -0
  237. data/public/javascripts/specs/lib/key_map_spec.js +227 -0
  238. data/public/javascripts/specs/lib/model_spec.js +2268 -0
  239. data/public/javascripts/specs/lib/parameters_spec.js +94 -0
  240. data/public/javascripts/specs/lib/spec_spec.js +943 -0
  241. data/public/javascripts/specs/lib/undo_spec.js +105 -0
  242. data/public/javascripts/specs/lib/yaml_spec.js +127 -0
  243. data/public/sounds/basso.wav +0 -0
  244. data/public/sounds/purr.wav +0 -0
  245. data/public/stylesheets/components/accordion.css +24 -0
  246. data/public/stylesheets/components/alert_box.css +35 -0
  247. data/public/stylesheets/components/box.css +0 -0
  248. data/public/stylesheets/components/button.css +39 -0
  249. data/public/stylesheets/components/checkbox.css +9 -0
  250. data/public/stylesheets/components/container.css +3 -0
  251. data/public/stylesheets/components/grid_view.css +52 -0
  252. data/public/stylesheets/components/input.css +10 -0
  253. data/public/stylesheets/components/label.css +3 -0
  254. data/public/stylesheets/components/lightbox.css +31 -0
  255. data/public/stylesheets/components/link.css +4 -0
  256. data/public/stylesheets/components/list_view.css +23 -0
  257. data/public/stylesheets/components/marquee.css +29 -0
  258. data/public/stylesheets/components/menu.css +34 -0
  259. data/public/stylesheets/components/notification.css +52 -0
  260. data/public/stylesheets/components/overlay.css +8 -0
  261. data/public/stylesheets/components/panel.css +36 -0
  262. data/public/stylesheets/components/radio.css +9 -0
  263. data/public/stylesheets/components/splitter.css +35 -0
  264. data/public/stylesheets/components/tab_bar.css +59 -0
  265. data/public/stylesheets/components/tab_panel.css +15 -0
  266. data/public/stylesheets/components/textarea.css +11 -0
  267. data/public/stylesheets/components/tooltip.css +10 -0
  268. data/public/stylesheets/console.css +151 -0
  269. data/public/stylesheets/css_reset.css +55 -0
  270. metadata +343 -0
@@ -0,0 +1,80 @@
1
+ // Based on the work of Tj Holowaychuk
2
+ // http://refactormycode.com/codes/1045-js-yaml-parser
3
+ //
4
+ // This implementation is not complete
5
+
6
+ rio.Yaml = {
7
+ dump: function(obj, indent) {
8
+ indent = indent || 0;
9
+ var indentText = " ".times(indent);
10
+
11
+ if (Object.isArray(obj)) {
12
+ return obj.map(function(item) {
13
+ return indentText + "- " + item;
14
+ }.bind(this)).join("\n");
15
+ } else {
16
+ return Object.keys(obj).map(function(k) {
17
+ var val = obj[k];
18
+ if (this._isPrimitive(val)) {
19
+ return indentText + k + ": " + val;
20
+ } else {
21
+ return indentText + k + ":\n" + this.dump(obj[k], indent + 1);
22
+ }
23
+ }.bind(this)).join("\n");
24
+ }
25
+ },
26
+
27
+ parse: function(str) {
28
+ return this._parse(this._tokenize(str));
29
+ },
30
+
31
+ _isPrimitive: function(val) {
32
+ return Object.isNumber(val) || Object.isString(val);
33
+ },
34
+
35
+ _valueOf: function(token) {
36
+ try {
37
+ return eval('(' + token + ')');
38
+ } catch(e) {
39
+ return token;
40
+ }
41
+ },
42
+
43
+ _tokenize: function(str) {
44
+ return str.match(/(---|true|false|null|#(.*)|\[(.*?)\]|\{(.*?)\}|[^\w\n]*[\/\.\w\-]+:|[^\w\n]*-(.+)|\d+\.\d+|\d+|\n+|\w.+)/g);
45
+ },
46
+
47
+ _indentLevel: function(token) {
48
+ return token ? Math.max(token.match(/^(\t*).*/)[1].length, token.match(/^([\s]*).*/)[1].length / 2) : 0;
49
+ },
50
+
51
+ _parse: function(tokens) {
52
+ while(tokens[0] == "\n") { tokens.shift(); }
53
+
54
+ var token, list = /-(.*)/, key = /([\/\.\w\-]+):/, stack = {};
55
+
56
+ var indentLevel = this._indentLevel(tokens[0]);
57
+
58
+ while (tokens[0] && (this._indentLevel(tokens[0]) >= indentLevel || tokens[0] == "\n")) {
59
+ token = tokens.shift();
60
+ if (token[0] == '#' || token == '---' || token == "\n") {
61
+ continue;
62
+ } else if (key.exec(token)) {
63
+ var keyName = RegExp.$1.strip();
64
+ if (tokens[0] == "\n") {
65
+ tokens.shift();
66
+ stack[keyName] = this._parse(tokens);
67
+ } else {
68
+ stack[keyName] = this._valueOf(tokens.shift());
69
+ }
70
+ } else if (list.exec(token)) {
71
+ (Object.isArray(stack) ? stack : (stack = [])).push(RegExp.$1.strip());
72
+ }
73
+ }
74
+ return stack;
75
+ },
76
+
77
+ toString: function() {
78
+ return "Yaml";
79
+ }
80
+ };
@@ -0,0 +1,15 @@
1
+ rio.pages.PlaygroundPage = rio.Page.create("Playground", {
2
+ methods: {
3
+ buildHtml: function() {
4
+ return rio.Tag.div("", { style: "height: 100%" });
5
+ },
6
+
7
+ render: function() {
8
+ try {
9
+ eval(rio.Cookie.get("playgroundContent") || "");
10
+ } catch(e) {
11
+ this.html().update(e);
12
+ }
13
+ }
14
+ }
15
+ });
@@ -0,0 +1,146 @@
1
+ // script.aculo.us builder.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008
2
+
3
+ // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
4
+ //
5
+ // script.aculo.us is freely distributable under the terms of an MIT-style license.
6
+ // For details, see the script.aculo.us web site: http://script.aculo.us/
7
+
8
+ Builder = {
9
+ NODEMAP: {
10
+ AREA: 'map',
11
+ CAPTION: 'table',
12
+ COL: 'table',
13
+ COLGROUP: 'table',
14
+ LEGEND: 'fieldset',
15
+ OPTGROUP: 'select',
16
+ OPTION: 'select',
17
+ PARAM: 'object',
18
+ TBODY: 'table',
19
+ TD: 'table',
20
+ TFOOT: 'table',
21
+ TH: 'table',
22
+ THEAD: 'table',
23
+ TR: 'table'
24
+ },
25
+ // note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken,
26
+ // due to a Firefox bug
27
+ node: function(elementName) {
28
+ elementName = elementName.toUpperCase();
29
+
30
+ // try innerHTML approach
31
+ var parentTag = this.NODEMAP[elementName] || 'div';
32
+ var parentElement = document.createElement(parentTag);
33
+ try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
34
+ parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
35
+ } catch(e) {}
36
+ var element = parentElement.firstChild || null;
37
+
38
+ // see if browser added wrapping tags
39
+ if(element && (element.tagName.toUpperCase() != elementName)) {
40
+ element = element.getElementsByTagName(elementName)[0];
41
+ }
42
+
43
+ // fallback to createElement approach
44
+ if(!element) { element = document.createElement(elementName); }
45
+
46
+ // abort if nothing could be created
47
+ if(!element) { return; }
48
+
49
+ // attributes (or text)
50
+ if(arguments[1]) {
51
+ if(this._isStringOrNumber(arguments[1]) ||
52
+ (arguments[1] instanceof Array) ||
53
+ arguments[1].tagName) {
54
+ this._children(element, arguments[1]);
55
+ } else {
56
+ var attrs = this._attributes(arguments[1]);
57
+ if(attrs.length) {
58
+ try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
59
+ parentElement.innerHTML = "<" +elementName + " " +
60
+ attrs + "></" + elementName + ">";
61
+ } catch(e2) {}
62
+ element = parentElement.firstChild || null;
63
+ // workaround firefox 1.0.X bug
64
+ if(!element) {
65
+ element = document.createElement(elementName);
66
+ for(attr in arguments[1]) {
67
+ element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
68
+ }
69
+ }
70
+ if(element.tagName.toUpperCase() != elementName) {
71
+ element = parentElement.getElementsByTagName(elementName)[0];
72
+ }
73
+ }
74
+ }
75
+ }
76
+
77
+ // text, or array of children
78
+ if(arguments[2]) {
79
+ this._children(element, arguments[2]);
80
+ }
81
+
82
+ return element;
83
+ },
84
+ _text: function(text, parentTagName) {
85
+ return document.createTextNode(Prototype.Browser.IE && !["textarea", "pre"].include(parentTagName.toLowerCase()) ? text.gsub(/\s+/, " ") : text);
86
+ },
87
+
88
+ ATTR_MAP: {
89
+ 'className': 'class',
90
+ 'htmlFor': 'for'
91
+ },
92
+
93
+ _attributes: function(attributes) {
94
+ var attrs = [];
95
+ for(attribute in attributes) {
96
+ attrs.push((attribute in this.ATTR_MAP ? this.ATTR_MAP[attribute] : attribute) +
97
+ '="' + attributes[attribute].toString().escapeHTML().gsub(/"/,'&quot;') + '"');
98
+ }
99
+ return attrs.join(" ");
100
+ },
101
+ _children: function(element, children) {
102
+ if(children.tagName) {
103
+ element.appendChild(children);
104
+ return;
105
+ }
106
+ if(typeof children=='object') { // array can hold nodes and text
107
+ children.flatten().each( function(e) {
108
+ if(typeof e=='object') {
109
+ element.appendChild(e);
110
+ } else {
111
+ if(Builder._isStringOrNumber(e)) {
112
+ element.appendChild(Builder._text(e, element.tagName));
113
+ }
114
+ }
115
+ });
116
+ } else {
117
+ if(Builder._isStringOrNumber(children)) {
118
+ element.appendChild(Builder._text(children, element.tagName));
119
+ }
120
+ }
121
+ },
122
+ _isStringOrNumber: function(param) {
123
+ return(typeof param=='string' || typeof param=='number');
124
+ },
125
+ build: function(html) {
126
+ var element = this.node('div');
127
+ $(element).update(html.strip());
128
+ return element.down();
129
+ },
130
+ dump: function(scope) {
131
+ if(typeof scope != 'object' && typeof scope != 'function') { scope = window; } //global scope
132
+
133
+ var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
134
+ "BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
135
+ "FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
136
+ "KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
137
+ "PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
138
+ "TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);
139
+
140
+ tags.each( function(tag){
141
+ scope[tag] = function() {
142
+ return Builder.node.apply(Builder, [tag].concat($A(arguments)));
143
+ };
144
+ });
145
+ }
146
+ };
@@ -0,0 +1,1004 @@
1
+ // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
2
+ // (c) 2005-2007 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
3
+ // (c) 2005-2007 Jon Tirsen (http://www.tirsen.com)
4
+ // Contributors:
5
+ // Richard Livsey
6
+ // Rahul Bhargava
7
+ // Rob Wills
8
+ //
9
+ // script.aculo.us is freely distributable under the terms of an MIT-style license.
10
+ // For details, see the script.aculo.us web site: http://script.aculo.us/
11
+
12
+ // Autocompleter.Base handles all the autocompletion functionality
13
+ // that's independent of the data source for autocompletion. This
14
+ // includes drawing the autocompletion menu, observing keyboard
15
+ // and mouse events, and similar.
16
+ //
17
+ // Specific autocompleters need to provide, at the very least,
18
+ // a getUpdatedChoices function that will be invoked every time
19
+ // the text inside the monitored textbox changes. This method
20
+ // should get the text for which to provide autocompletion by
21
+ // invoking this.getToken(), NOT by directly accessing
22
+ // this.element.value. This is to allow incremental tokenized
23
+ // autocompletion. Specific auto-completion logic (AJAX, etc)
24
+ // belongs in getUpdatedChoices.
25
+ //
26
+ // Tokenized incremental autocompletion is enabled automatically
27
+ // when an autocompleter is instantiated with the 'tokens' option
28
+ // in the options parameter, e.g.:
29
+ // new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' });
30
+ // will incrementally autocomplete with a comma as the token.
31
+ // Additionally, ',' in the above example can be replaced with
32
+ // a token array, e.g. { tokens: [',', '\n'] } which
33
+ // enables autocompletion on multiple tokens. This is most
34
+ // useful when one of the tokens is \n (a newline), as it
35
+ // allows smart autocompletion after linebreaks.
36
+
37
+ if(typeof Effect == 'undefined') {
38
+ throw("controls.js requires including script.aculo.us' effects.js library");
39
+ }
40
+
41
+ Autocompleter = { };
42
+ Autocompleter.Base = Class.create({
43
+ baseInitialize: function(element, update, options) {
44
+ element = $(element);
45
+ this.element = element;
46
+ this.update = $(update);
47
+ this.hasFocus = false;
48
+ this.changed = false;
49
+ this.active = false;
50
+ this.index = 0;
51
+ this.entryCount = 0;
52
+ this.oldElementValue = this.element.value;
53
+
54
+ if(this.setOptions) {
55
+ this.setOptions(options);
56
+ } else {
57
+ this.options = options || { };
58
+ }
59
+
60
+ this.options.paramName = this.options.paramName || this.element.name;
61
+ this.options.tokens = this.options.tokens || [];
62
+ this.options.frequency = this.options.frequency || 0.4;
63
+ this.options.minChars = this.options.minChars || 1;
64
+ this.options.onShow = this.options.onShow ||
65
+ function(element, update){
66
+ if(!update.style.position || update.style.position=='absolute') {
67
+ update.style.position = 'absolute';
68
+ Position.clone(element, update, {
69
+ setHeight: false,
70
+ offsetTop: element.offsetHeight
71
+ });
72
+ }
73
+ Effect.Appear(update,{duration:0.15});
74
+ };
75
+ this.options.onHide = this.options.onHide ||
76
+ function(element, update){ new Effect.Fade(update,{duration:0.15}); };
77
+
78
+ if(typeof(this.options.tokens) == 'string') {
79
+ this.options.tokens = new Array(this.options.tokens);
80
+ }
81
+ // Force carriage returns as token delimiters anyway
82
+ if (!this.options.tokens.include('\n')) {
83
+ this.options.tokens.push('\n');
84
+ }
85
+
86
+ this.observer = null;
87
+
88
+ this.element.setAttribute('autocomplete','off');
89
+
90
+ Element.hide(this.update);
91
+
92
+ Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this));
93
+ Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this));
94
+ },
95
+
96
+ show: function() {
97
+ if(Element.getStyle(this.update, 'display')=='none') { this.options.onShow(this.element, this.update); }
98
+ if(!this.iefix &&
99
+ (Prototype.Browser.IE) &&
100
+ (Element.getStyle(this.update, 'position')=='absolute')) {
101
+ new Insertion.After(this.update,
102
+ '<iframe id="' + this.update.id + '_iefix" '+
103
+ 'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
104
+ 'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
105
+ this.iefix = $(this.update.id+'_iefix');
106
+ }
107
+ if(this.iefix) { setTimeout(this.fixIEOverlapping.bind(this), 50); }
108
+ },
109
+
110
+ fixIEOverlapping: function() {
111
+ Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
112
+ this.iefix.style.zIndex = 1;
113
+ this.update.style.zIndex = 2;
114
+ Element.show(this.iefix);
115
+ },
116
+
117
+ hide: function() {
118
+ this.stopIndicator();
119
+ if(Element.getStyle(this.update, 'display')!='none') { this.options.onHide(this.element, this.update); }
120
+ if(this.iefix) { Element.hide(this.iefix); }
121
+ },
122
+
123
+ startIndicator: function() {
124
+ if(this.options.indicator) { Element.show(this.options.indicator); }
125
+ },
126
+
127
+ stopIndicator: function() {
128
+ if(this.options.indicator) { Element.hide(this.options.indicator); }
129
+ },
130
+
131
+ onKeyPress: function(event) {
132
+ if(this.active) {
133
+ switch(event.keyCode) {
134
+ case Event.KEY_TAB:
135
+ case Event.KEY_RETURN:
136
+ this.selectEntry();
137
+ Event.stop(event);
138
+ case Event.KEY_ESC:
139
+ this.hide();
140
+ this.active = false;
141
+ Event.stop(event);
142
+ return;
143
+ case Event.KEY_LEFT:
144
+ case Event.KEY_RIGHT:
145
+ return;
146
+ case Event.KEY_UP:
147
+ this.markPrevious();
148
+ this.render();
149
+ Event.stop(event);
150
+ return;
151
+ case Event.KEY_DOWN:
152
+ this.markNext();
153
+ this.render();
154
+ Event.stop(event);
155
+ return;
156
+ }
157
+ } else {
158
+ if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
159
+ (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) { return; }
160
+ }
161
+
162
+ this.changed = true;
163
+ this.hasFocus = true;
164
+
165
+ if(this.observer) { clearTimeout(this.observer); }
166
+ this.observer =
167
+ setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
168
+ },
169
+
170
+ activate: function() {
171
+ this.changed = false;
172
+ this.hasFocus = true;
173
+ this.getUpdatedChoices();
174
+ },
175
+
176
+ onHover: function(event) {
177
+ var element = Event.findElement(event, 'LI');
178
+ if(this.index != element.autocompleteIndex)
179
+ {
180
+ this.index = element.autocompleteIndex;
181
+ this.render();
182
+ }
183
+ Event.stop(event);
184
+ },
185
+
186
+ onClick: function(event) {
187
+ var element = Event.findElement(event, 'LI');
188
+ this.index = element.autocompleteIndex;
189
+ this.selectEntry();
190
+ this.hide();
191
+ },
192
+
193
+ onBlur: function(event) {
194
+ // needed to make click events working
195
+ setTimeout(this.hide.bind(this), 250);
196
+ this.hasFocus = false;
197
+ this.active = false;
198
+ },
199
+
200
+ render: function() {
201
+ if(this.entryCount > 0) {
202
+ for (var i = 0; i < this.entryCount; i++) {
203
+ this.index==i ?
204
+ Element.addClassName(this.getEntry(i),"selected") :
205
+ Element.removeClassName(this.getEntry(i),"selected");
206
+ }
207
+ if(this.hasFocus) {
208
+ this.show();
209
+ this.active = true;
210
+ }
211
+ } else {
212
+ this.active = false;
213
+ this.hide();
214
+ }
215
+ },
216
+
217
+ markPrevious: function() {
218
+ if(this.index > 0) { this.index--;
219
+ } else { this.index = this.entryCount-1; }
220
+ this.getEntry(this.index).scrollIntoView(true);
221
+ },
222
+
223
+ markNext: function() {
224
+ if(this.index < this.entryCount-1) { this.index++;
225
+ } else { this.index = 0; }
226
+ this.getEntry(this.index).scrollIntoView(false);
227
+ },
228
+
229
+ getEntry: function(index) {
230
+ return this.update.firstChild.childNodes[index];
231
+ },
232
+
233
+ getCurrentEntry: function() {
234
+ return this.getEntry(this.index);
235
+ },
236
+
237
+ selectEntry: function() {
238
+ this.active = false;
239
+ this.updateElement(this.getCurrentEntry());
240
+ },
241
+
242
+ updateElement: function(selectedElement) {
243
+ if (this.options.updateElement) {
244
+ this.options.updateElement(selectedElement);
245
+ return;
246
+ }
247
+ var value = '';
248
+ if (this.options.select) {
249
+ var nodes = $(selectedElement).select('.' + this.options.select) || [];
250
+ if(nodes.length>0) { value = Element.collectTextNodes(nodes[0], this.options.select); }
251
+ } else {
252
+ value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
253
+ }
254
+
255
+ var bounds = this.getTokenBounds();
256
+ if (bounds[0] != -1) {
257
+ var newValue = this.element.value.substr(0, bounds[0]);
258
+ var whitespace = this.element.value.substr(bounds[0]).match(/^\s+/);
259
+ if (whitespace) {
260
+ newValue += whitespace[0];
261
+ }
262
+ this.element.value = newValue + value + this.element.value.substr(bounds[1]);
263
+ } else {
264
+ this.element.value = value;
265
+ }
266
+ this.oldElementValue = this.element.value;
267
+ this.element.focus();
268
+
269
+ if (this.options.afterUpdateElement) {
270
+ this.options.afterUpdateElement(this.element, selectedElement);
271
+ }
272
+ },
273
+
274
+ updateChoices: function(choices) {
275
+ if(!this.changed && this.hasFocus) {
276
+ this.update.innerHTML = choices;
277
+ Element.cleanWhitespace(this.update);
278
+ Element.cleanWhitespace(this.update.down());
279
+
280
+ if(this.update.firstChild && this.update.down().childNodes) {
281
+ this.entryCount =
282
+ this.update.down().childNodes.length;
283
+ for (var i = 0; i < this.entryCount; i++) {
284
+ var entry = this.getEntry(i);
285
+ entry.autocompleteIndex = i;
286
+ this.addObservers(entry);
287
+ }
288
+ } else {
289
+ this.entryCount = 0;
290
+ }
291
+
292
+ this.stopIndicator();
293
+ this.index = 0;
294
+
295
+ if(this.entryCount==1 && this.options.autoSelect) {
296
+ this.selectEntry();
297
+ this.hide();
298
+ } else {
299
+ this.render();
300
+ }
301
+ }
302
+ },
303
+
304
+ addObservers: function(element) {
305
+ Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
306
+ Event.observe(element, "click", this.onClick.bindAsEventListener(this));
307
+ },
308
+
309
+ onObserverEvent: function() {
310
+ this.changed = false;
311
+ this.tokenBounds = null;
312
+ if(this.getToken().length>=this.options.minChars) {
313
+ this.getUpdatedChoices();
314
+ } else {
315
+ this.active = false;
316
+ this.hide();
317
+ }
318
+ this.oldElementValue = this.element.value;
319
+ },
320
+
321
+ getToken: function() {
322
+ var bounds = this.getTokenBounds();
323
+ return this.element.value.substring(bounds[0], bounds[1]).strip();
324
+ },
325
+
326
+ getTokenBounds: function() {
327
+ if (null != this.tokenBounds) { return this.tokenBounds; }
328
+ var value = this.element.value;
329
+ if (value.strip().empty()) { return [-1, 0]; }
330
+ var diff = arguments.callee.getFirstDifferencePos(value, this.oldElementValue);
331
+ var offset = (diff == this.oldElementValue.length ? 1 : 0);
332
+ var prevTokenPos = -1, nextTokenPos = value.length;
333
+ var tp;
334
+ for (var index = 0, l = this.options.tokens.length; index < l; ++index) {
335
+ tp = value.lastIndexOf(this.options.tokens[index], diff + offset - 1);
336
+ if (tp > prevTokenPos) { prevTokenPos = tp; }
337
+ tp = value.indexOf(this.options.tokens[index], diff + offset);
338
+ if (-1 != tp && tp < nextTokenPos) { nextTokenPos = tp; }
339
+ }
340
+ return (this.tokenBounds = [prevTokenPos + 1, nextTokenPos]);
341
+ }
342
+ });
343
+
344
+ Autocompleter.Base.prototype.getTokenBounds.getFirstDifferencePos = function(newS, oldS) {
345
+ var boundary = Math.min(newS.length, oldS.length);
346
+ for (var index = 0; index < boundary; ++index) {
347
+ if (newS[index] != oldS[index]) {
348
+ return index;
349
+ }
350
+ }
351
+ return boundary;
352
+ };
353
+
354
+ Ajax.Autocompleter = Class.create(Autocompleter.Base, {
355
+ initialize: function(element, update, url, options) {
356
+ this.baseInitialize(element, update, options);
357
+ this.options.asynchronous = true;
358
+ this.options.onComplete = this.onComplete.bind(this);
359
+ this.options.defaultParams = this.options.parameters || null;
360
+ this.url = url;
361
+ },
362
+
363
+ getUpdatedChoices: function() {
364
+ this.startIndicator();
365
+
366
+ var entry = encodeURIComponent(this.options.paramName) + '=' +
367
+ encodeURIComponent(this.getToken());
368
+
369
+ this.options.parameters = this.options.callback ?
370
+ this.options.callback(this.element, entry) : entry;
371
+
372
+ if(this.options.defaultParams) {
373
+ this.options.parameters += '&' + this.options.defaultParams;
374
+ }
375
+
376
+ new Ajax.Request(this.url, this.options);
377
+ },
378
+
379
+ onComplete: function(request) {
380
+ this.updateChoices(request.responseText);
381
+ }
382
+ });
383
+
384
+ // The local array autocompleter. Used when you'd prefer to
385
+ // inject an array of autocompletion options into the page, rather
386
+ // than sending out Ajax queries, which can be quite slow sometimes.
387
+ //
388
+ // The constructor takes four parameters. The first two are, as usual,
389
+ // the id of the monitored textbox, and id of the autocompletion menu.
390
+ // The third is the array you want to autocomplete from, and the fourth
391
+ // is the options block.
392
+ //
393
+ // Extra local autocompletion options:
394
+ // - choices - How many autocompletion choices to offer
395
+ //
396
+ // - partialSearch - If false, the autocompleter will match entered
397
+ // text only at the beginning of strings in the
398
+ // autocomplete array. Defaults to true, which will
399
+ // match text at the beginning of any *word* in the
400
+ // strings in the autocomplete array. If you want to
401
+ // search anywhere in the string, additionally set
402
+ // the option fullSearch to true (default: off).
403
+ //
404
+ // - fullSsearch - Search anywhere in autocomplete array strings.
405
+ //
406
+ // - partialChars - How many characters to enter before triggering
407
+ // a partial match (unlike minChars, which defines
408
+ // how many characters are required to do any match
409
+ // at all). Defaults to 2.
410
+ //
411
+ // - ignoreCase - Whether to ignore case when autocompleting.
412
+ // Defaults to true.
413
+ //
414
+ // It's possible to pass in a custom function as the 'selector'
415
+ // option, if you prefer to write your own autocompletion logic.
416
+ // In that case, the other options above will not apply unless
417
+ // you support them.
418
+
419
+ Autocompleter.Local = Class.create(Autocompleter.Base, {
420
+ initialize: function(element, update, array, options) {
421
+ this.baseInitialize(element, update, options);
422
+ this.options.array = array;
423
+ },
424
+
425
+ getUpdatedChoices: function() {
426
+ this.updateChoices(this.options.selector(this));
427
+ },
428
+
429
+ setOptions: function(options) {
430
+ this.options = Object.extend({
431
+ choices: 10,
432
+ partialSearch: true,
433
+ partialChars: 2,
434
+ ignoreCase: true,
435
+ fullSearch: false,
436
+ selector: function(instance) {
437
+ var ret = []; // Beginning matches
438
+ var partial = []; // Inside matches
439
+ var entry = instance.getToken();
440
+ var count = 0;
441
+
442
+ for (var i = 0; i < instance.options.array.length &&
443
+ ret.length < instance.options.choices ; i++) {
444
+
445
+ var elem = instance.options.array[i];
446
+ var foundPos = instance.options.ignoreCase ?
447
+ elem.toLowerCase().indexOf(entry.toLowerCase()) :
448
+ elem.indexOf(entry);
449
+
450
+ while (foundPos != -1) {
451
+ if (foundPos == 0 && elem.length != entry.length) {
452
+ ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
453
+ elem.substr(entry.length) + "</li>");
454
+ break;
455
+ } else if (entry.length >= instance.options.partialChars &&
456
+ instance.options.partialSearch && foundPos != -1) {
457
+ if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
458
+ partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
459
+ elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
460
+ foundPos + entry.length) + "</li>");
461
+ break;
462
+ }
463
+ }
464
+
465
+ foundPos = instance.options.ignoreCase ?
466
+ elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
467
+ elem.indexOf(entry, foundPos + 1);
468
+
469
+ }
470
+ }
471
+ if (partial.length) {
472
+ ret = ret.concat(partial.slice(0, instance.options.choices - ret.length));
473
+ }
474
+ return "<ul>" + ret.join('') + "</ul>";
475
+ }
476
+ }, options || { });
477
+ }
478
+ });
479
+
480
+ // AJAX in-place editor and collection editor
481
+ // Full rewrite by Christophe Porteneuve <tdd@tddsworld.com> (April 2007).
482
+
483
+ // Use this if you notice weird scrolling problems on some browsers,
484
+ // the DOM might be a bit confused when this gets called so do this
485
+ // waits 1 ms (with setTimeout) until it does the activation
486
+ Field.scrollFreeActivate = function(field) {
487
+ setTimeout(function() {
488
+ Field.activate(field);
489
+ }, 1);
490
+ };
491
+
492
+ Ajax.InPlaceEditor = Class.create({
493
+ initialize: function(element, url, options) {
494
+ this.url = url;
495
+ this.element = element = $(element);
496
+ this.prepareOptions();
497
+ this._controls = { };
498
+ arguments.callee.dealWithDeprecatedOptions(options); // DEPRECATION LAYER!!!
499
+ Object.extend(this.options, options || { });
500
+ if (!this.options.formId && this.element.id) {
501
+ this.options.formId = this.element.id + '-inplaceeditor';
502
+ if ($(this.options.formId)) {
503
+ this.options.formId = '';
504
+ }
505
+ }
506
+ if (this.options.externalControl) {
507
+ this.options.externalControl = $(this.options.externalControl);
508
+ }
509
+ if (!this.options.externalControl) {
510
+ this.options.externalControlOnly = false;
511
+ }
512
+ this._originalBackground = this.element.getStyle('background-color') || 'transparent';
513
+ this.element.title = this.options.clickToEditText;
514
+ this._boundCancelHandler = this.handleFormCancellation.bind(this);
515
+ this._boundComplete = (this.options.onComplete || Prototype.emptyFunction).bind(this);
516
+ this._boundFailureHandler = this.handleAJAXFailure.bind(this);
517
+ this._boundSubmitHandler = this.handleFormSubmission.bind(this);
518
+ this._boundWrapperHandler = this.wrapUp.bind(this);
519
+ this.registerListeners();
520
+ },
521
+ checkForEscapeOrReturn: function(e) {
522
+ if (!this._editing || e.ctrlKey || e.altKey || e.shiftKey) { return; }
523
+ if (Event.KEY_ESC == e.keyCode) {
524
+ this.handleFormCancellation(e);
525
+ } else if (Event.KEY_RETURN == e.keyCode) {
526
+ this.handleFormSubmission(e);
527
+ }
528
+ },
529
+ createControl: function(mode, handler, extraClasses) {
530
+ var control = this.options[mode + 'Control'];
531
+ var text = this.options[mode + 'Text'];
532
+ if ('button' == control) {
533
+ var btn = document.createElement('input');
534
+ btn.type = 'submit';
535
+ btn.value = text;
536
+ btn.className = 'editor_' + mode + '_button';
537
+ if ('cancel' == mode) {
538
+ btn.onclick = this._boundCancelHandler;
539
+ }
540
+ this._form.appendChild(btn);
541
+ this._controls[mode] = btn;
542
+ } else if ('link' == control) {
543
+ var link = document.createElement('a');
544
+ link.href = '#';
545
+ link.appendChild(document.createTextNode(text));
546
+ link.onclick = 'cancel' == mode ? this._boundCancelHandler : this._boundSubmitHandler;
547
+ link.className = 'editor_' + mode + '_link';
548
+ if (extraClasses) {
549
+ link.className += ' ' + extraClasses;
550
+ }
551
+ this._form.appendChild(link);
552
+ this._controls[mode] = link;
553
+ }
554
+ },
555
+ createEditField: function() {
556
+ var text = (this.options.loadTextURL ? this.options.loadingText : this.getText());
557
+ var fld;
558
+ if (1 >= this.options.rows && !/\r|\n/.test(this.getText())) {
559
+ fld = document.createElement('input');
560
+ fld.type = 'text';
561
+ var size = this.options.size || this.options.cols || 0;
562
+ if (0 < size) { fld.size = size; }
563
+ } else {
564
+ fld = document.createElement('textarea');
565
+ fld.rows = (1 >= this.options.rows ? this.options.autoRows : this.options.rows);
566
+ fld.cols = this.options.cols || 40;
567
+ }
568
+ fld.name = this.options.paramName;
569
+ fld.value = text; // No HTML breaks conversion anymore
570
+ fld.className = 'editor_field';
571
+ if (this.options.submitOnBlur) {
572
+ fld.onblur = this._boundSubmitHandler;
573
+ }
574
+ this._controls.editor = fld;
575
+ if (this.options.loadTextURL) {
576
+ this.loadExternalText();
577
+ }
578
+ this._form.appendChild(this._controls.editor);
579
+ },
580
+ createForm: function() {
581
+ var ipe = this;
582
+ function addText(mode, condition) {
583
+ var text = ipe.options['text' + mode + 'Controls'];
584
+ if (!text || condition === false) { return; }
585
+ ipe._form.appendChild(document.createTextNode(text));
586
+ }
587
+ this._form = $(document.createElement('form'));
588
+ this._form.id = this.options.formId;
589
+ this._form.addClassName(this.options.formClassName);
590
+ this._form.onsubmit = this._boundSubmitHandler;
591
+ this.createEditField();
592
+ if ('textarea' == this._controls.editor.tagName.toLowerCase()) {
593
+ this._form.appendChild(document.createElement('br'));
594
+ }
595
+ if (this.options.onFormCustomization) {
596
+ this.options.onFormCustomization(this, this._form);
597
+ }
598
+ addText('Before', this.options.okControl || this.options.cancelControl);
599
+ this.createControl('ok', this._boundSubmitHandler);
600
+ addText('Between', this.options.okControl && this.options.cancelControl);
601
+ this.createControl('cancel', this._boundCancelHandler, 'editor_cancel');
602
+ addText('After', this.options.okControl || this.options.cancelControl);
603
+ },
604
+ destroy: function() {
605
+ if (this._oldInnerHTML) {
606
+ this.element.innerHTML = this._oldInnerHTML;
607
+ }
608
+ this.leaveEditMode();
609
+ this.unregisterListeners();
610
+ },
611
+ enterEditMode: function(e) {
612
+ if (this._saving || this._editing) { return; }
613
+ this._editing = true;
614
+ this.triggerCallback('onEnterEditMode');
615
+ if (this.options.externalControl) {
616
+ this.options.externalControl.hide();
617
+ }
618
+ this.element.hide();
619
+ this.createForm();
620
+ this.element.parentNode.insertBefore(this._form, this.element);
621
+ if (!this.options.loadTextURL) {
622
+ this.postProcessEditField();
623
+ }
624
+ if (e) { Event.stop(e); }
625
+ },
626
+ enterHover: function(e) {
627
+ if (this.options.hoverClassName) {
628
+ this.element.addClassName(this.options.hoverClassName);
629
+ }
630
+ if (this._saving) { return; }
631
+ this.triggerCallback('onEnterHover');
632
+ },
633
+ getText: function() {
634
+ return this.element.innerHTML;
635
+ },
636
+ handleAJAXFailure: function(transport) {
637
+ this.triggerCallback('onFailure', transport);
638
+ if (this._oldInnerHTML) {
639
+ this.element.innerHTML = this._oldInnerHTML;
640
+ this._oldInnerHTML = null;
641
+ }
642
+ },
643
+ handleFormCancellation: function(e) {
644
+ this.wrapUp();
645
+ if (e) { Event.stop(e); }
646
+ },
647
+ handleFormSubmission: function(e) {
648
+ var form = this._form;
649
+ var value = $F(this._controls.editor);
650
+ this.prepareSubmission();
651
+ var params = this.options.callback(form, value) || '';
652
+ var options;
653
+ if (Object.isString(params)) {
654
+ params = params.toQueryParams();
655
+ }
656
+ params.editorId = this.element.id;
657
+ if (this.options.htmlResponse) {
658
+ options = Object.extend({ evalScripts: true }, this.options.ajaxOptions);
659
+ Object.extend(options, {
660
+ parameters: params,
661
+ onComplete: this._boundWrapperHandler,
662
+ onFailure: this._boundFailureHandler
663
+ });
664
+ new Ajax.Updater({ success: this.element }, this.url, options);
665
+ } else {
666
+ options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
667
+ Object.extend(options, {
668
+ parameters: params,
669
+ onComplete: this._boundWrapperHandler,
670
+ onFailure: this._boundFailureHandler
671
+ });
672
+ new Ajax.Request(this.url, options);
673
+ }
674
+ if (e) { Event.stop(e); }
675
+ },
676
+ leaveEditMode: function() {
677
+ this.element.removeClassName(this.options.savingClassName);
678
+ this.removeForm();
679
+ this.leaveHover();
680
+ this.element.style.backgroundColor = this._originalBackground;
681
+ this.element.show();
682
+ if (this.options.externalControl) {
683
+ this.options.externalControl.show();
684
+ }
685
+ this._saving = false;
686
+ this._editing = false;
687
+ this._oldInnerHTML = null;
688
+ this.triggerCallback('onLeaveEditMode');
689
+ },
690
+ leaveHover: function(e) {
691
+ if (this.options.hoverClassName) {
692
+ this.element.removeClassName(this.options.hoverClassName);
693
+ }
694
+ if (this._saving) { return; }
695
+ this.triggerCallback('onLeaveHover');
696
+ },
697
+ loadExternalText: function() {
698
+ this._form.addClassName(this.options.loadingClassName);
699
+ this._controls.editor.disabled = true;
700
+ var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
701
+ Object.extend(options, {
702
+ parameters: 'editorId=' + encodeURIComponent(this.element.id),
703
+ onComplete: Prototype.emptyFunction,
704
+ onSuccess: function(transport) {
705
+ this._form.removeClassName(this.options.loadingClassName);
706
+ var text = transport.responseText;
707
+ if (this.options.stripLoadedTextTags) {
708
+ text = text.stripTags();
709
+ }
710
+ this._controls.editor.value = text;
711
+ this._controls.editor.disabled = false;
712
+ this.postProcessEditField();
713
+ }.bind(this),
714
+ onFailure: this._boundFailureHandler
715
+ });
716
+ new Ajax.Request(this.options.loadTextURL, options);
717
+ },
718
+ postProcessEditField: function() {
719
+ var fpc = this.options.fieldPostCreation;
720
+ if (fpc) {
721
+ $(this._controls.editor)['focus' == fpc ? 'focus' : 'activate']();
722
+ }
723
+ },
724
+ prepareOptions: function() {
725
+ this.options = Object.clone(Ajax.InPlaceEditor.DefaultOptions);
726
+ Object.extend(this.options, Ajax.InPlaceEditor.DefaultCallbacks);
727
+ [this._extraDefaultOptions].flatten().compact().each(function(defs) {
728
+ Object.extend(this.options, defs);
729
+ }.bind(this));
730
+ },
731
+ prepareSubmission: function() {
732
+ this._saving = true;
733
+ this.removeForm();
734
+ this.leaveHover();
735
+ this.showSaving();
736
+ },
737
+ registerListeners: function() {
738
+ this._listeners = { };
739
+ var listener;
740
+ $H(Ajax.InPlaceEditor.Listeners).each(function(pair) {
741
+ listener = this[pair.value].bind(this);
742
+ this._listeners[pair.key] = listener;
743
+ if (!this.options.externalControlOnly) {
744
+ this.element.observe(pair.key, listener);
745
+ }
746
+ if (this.options.externalControl) {
747
+ this.options.externalControl.observe(pair.key, listener);
748
+ }
749
+ }.bind(this));
750
+ },
751
+ removeForm: function() {
752
+ if (!this._form) { return; }
753
+ this._form.remove();
754
+ this._form = null;
755
+ this._controls = { };
756
+ },
757
+ showSaving: function() {
758
+ this._oldInnerHTML = this.element.innerHTML;
759
+ this.element.innerHTML = this.options.savingText;
760
+ this.element.addClassName(this.options.savingClassName);
761
+ this.element.style.backgroundColor = this._originalBackground;
762
+ this.element.show();
763
+ },
764
+ triggerCallback: function(cbName, arg) {
765
+ if ('function' == typeof this.options[cbName]) {
766
+ this.options[cbName](this, arg);
767
+ }
768
+ },
769
+ unregisterListeners: function() {
770
+ $H(this._listeners).each(function(pair) {
771
+ if (!this.options.externalControlOnly) {
772
+ this.element.stopObserving(pair.key, pair.value);
773
+ }
774
+ if (this.options.externalControl) {
775
+ this.options.externalControl.stopObserving(pair.key, pair.value);
776
+ }
777
+ }.bind(this));
778
+ },
779
+ wrapUp: function(transport) {
780
+ this.leaveEditMode();
781
+ // Can't use triggerCallback due to backward compatibility: requires
782
+ // binding + direct element
783
+ this._boundComplete(transport, this.element);
784
+ }
785
+ });
786
+
787
+ Object.extend(Ajax.InPlaceEditor.prototype, {
788
+ dispose: Ajax.InPlaceEditor.prototype.destroy
789
+ });
790
+
791
+ Ajax.InPlaceCollectionEditor = Class.create(Ajax.InPlaceEditor, {
792
+ initialize: function($super, element, url, options) {
793
+ this._extraDefaultOptions = Ajax.InPlaceCollectionEditor.DefaultOptions;
794
+ $super(element, url, options);
795
+ },
796
+
797
+ createEditField: function() {
798
+ var list = document.createElement('select');
799
+ list.name = this.options.paramName;
800
+ list.size = 1;
801
+ this._controls.editor = list;
802
+ this._collection = this.options.collection || [];
803
+ if (this.options.loadCollectionURL) {
804
+ this.loadCollection();
805
+ } else {
806
+ this.checkForExternalText();
807
+ }
808
+ this._form.appendChild(this._controls.editor);
809
+ },
810
+
811
+ loadCollection: function() {
812
+ this._form.addClassName(this.options.loadingClassName);
813
+ this.showLoadingText(this.options.loadingCollectionText);
814
+ var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
815
+ Object.extend(options, {
816
+ parameters: 'editorId=' + encodeURIComponent(this.element.id),
817
+ onComplete: Prototype.emptyFunction,
818
+ onSuccess: function(transport) {
819
+ var js = transport.responseText.strip();
820
+ if (!/^\[.*\]$/.test(js)) { // TODO: improve sanity check
821
+ throw 'Server returned an invalid collection representation.';
822
+ }
823
+ this._collection = eval(js);
824
+ this.checkForExternalText();
825
+ }.bind(this),
826
+ onFailure: this.onFailure
827
+ });
828
+ new Ajax.Request(this.options.loadCollectionURL, options);
829
+ },
830
+
831
+ showLoadingText: function(text) {
832
+ this._controls.editor.disabled = true;
833
+ var tempOption = this._controls.editor.firstChild;
834
+ if (!tempOption) {
835
+ tempOption = document.createElement('option');
836
+ tempOption.value = '';
837
+ this._controls.editor.appendChild(tempOption);
838
+ tempOption.selected = true;
839
+ }
840
+ tempOption.update((text || '').stripScripts().stripTags());
841
+ },
842
+
843
+ checkForExternalText: function() {
844
+ this._text = this.getText();
845
+ if (this.options.loadTextURL) {
846
+ this.loadExternalText();
847
+ } else {
848
+ this.buildOptionList();
849
+ }
850
+ },
851
+
852
+ loadExternalText: function() {
853
+ this.showLoadingText(this.options.loadingText);
854
+ var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
855
+ Object.extend(options, {
856
+ parameters: 'editorId=' + encodeURIComponent(this.element.id),
857
+ onComplete: Prototype.emptyFunction,
858
+ onSuccess: function(transport) {
859
+ this._text = transport.responseText.strip();
860
+ this.buildOptionList();
861
+ }.bind(this),
862
+ onFailure: this.onFailure
863
+ });
864
+ new Ajax.Request(this.options.loadTextURL, options);
865
+ },
866
+
867
+ buildOptionList: function() {
868
+ this._form.removeClassName(this.options.loadingClassName);
869
+ this._collection = this._collection.map(function(entry) {
870
+ return 2 === entry.length ? entry : [entry, entry].flatten();
871
+ });
872
+ var marker = ('value' in this.options) ? this.options.value : this._text;
873
+ var textFound = this._collection.any(function(entry) {
874
+ return entry[0] == marker;
875
+ }.bind(this));
876
+ this._controls.editor.update('');
877
+ var option;
878
+ this._collection.each(function(entry, index) {
879
+ option = document.createElement('option');
880
+ option.value = entry[0];
881
+ option.selected = textFound ? entry[0] == marker : 0 == index;
882
+ option.appendChild(document.createTextNode(entry[1]));
883
+ this._controls.editor.appendChild(option);
884
+ }.bind(this));
885
+ this._controls.editor.disabled = false;
886
+ Field.scrollFreeActivate(this._controls.editor);
887
+ }
888
+ });
889
+
890
+ //**** DEPRECATION LAYER FOR InPlace[Collection]Editor! ****
891
+ //**** This only exists for a while, in order to let ****
892
+ //**** users adapt to the new API. Read up on the new ****
893
+ //**** API and convert your code to it ASAP! ****
894
+
895
+ Ajax.InPlaceEditor.prototype.initialize.dealWithDeprecatedOptions = function(options) {
896
+ if (!options) { return; }
897
+ function fallback(name, expr) {
898
+ if (name in options || expr === undefined) { return; }
899
+ options[name] = expr;
900
+ }
901
+ fallback('cancelControl', (options.cancelLink ? 'link' : (options.cancelButton ? 'button' :
902
+ options.cancelLink == options.cancelButton == false ? false : undefined)));
903
+ fallback('okControl', (options.okLink ? 'link' : (options.okButton ? 'button' :
904
+ options.okLink == options.okButton == false ? false : undefined)));
905
+ fallback('highlightColor', options.highlightcolor);
906
+ fallback('highlightEndColor', options.highlightendcolor);
907
+ };
908
+
909
+ Object.extend(Ajax.InPlaceEditor, {
910
+ DefaultOptions: {
911
+ ajaxOptions: { },
912
+ autoRows: 3, // Use when multi-line w/ rows == 1
913
+ cancelControl: 'link', // 'link'|'button'|false
914
+ cancelText: 'cancel',
915
+ clickToEditText: 'Click to edit',
916
+ externalControl: null, // id|elt
917
+ externalControlOnly: false,
918
+ fieldPostCreation: 'activate', // 'activate'|'focus'|false
919
+ formClassName: 'inplaceeditor-form',
920
+ formId: null, // id|elt
921
+ highlightColor: '#ffff99',
922
+ highlightEndColor: '#ffffff',
923
+ hoverClassName: '',
924
+ htmlResponse: true,
925
+ loadingClassName: 'inplaceeditor-loading',
926
+ loadingText: 'Loading...',
927
+ okControl: 'button', // 'link'|'button'|false
928
+ okText: 'ok',
929
+ paramName: 'value',
930
+ rows: 1, // If 1 and multi-line, uses autoRows
931
+ savingClassName: 'inplaceeditor-saving',
932
+ savingText: 'Saving...',
933
+ size: 0,
934
+ stripLoadedTextTags: false,
935
+ submitOnBlur: false,
936
+ textAfterControls: '',
937
+ textBeforeControls: '',
938
+ textBetweenControls: ''
939
+ },
940
+ DefaultCallbacks: {
941
+ callback: function(form) {
942
+ return Form.serialize(form);
943
+ },
944
+ onComplete: function(transport, element) {
945
+ // For backward compatibility, this one is bound to the IPE, and passes
946
+ // the element directly. It was too often customized, so we don't break it.
947
+ new Effect.Highlight(element, {
948
+ startcolor: this.options.highlightColor, keepBackgroundImage: true });
949
+ },
950
+ onEnterEditMode: null,
951
+ onEnterHover: function(ipe) {
952
+ ipe.element.style.backgroundColor = ipe.options.highlightColor;
953
+ if (ipe._effect) {
954
+ ipe._effect.cancel();
955
+ }
956
+ },
957
+ onFailure: function(transport, ipe) {
958
+ alert('Error communication with the server: ' + transport.responseText.stripTags());
959
+ },
960
+ onFormCustomization: null, // Takes the IPE and its generated form, after editor, before controls.
961
+ onLeaveEditMode: null,
962
+ onLeaveHover: function(ipe) {
963
+ ipe._effect = new Effect.Highlight(ipe.element, {
964
+ startcolor: ipe.options.highlightColor, endcolor: ipe.options.highlightEndColor,
965
+ restorecolor: ipe._originalBackground, keepBackgroundImage: true
966
+ });
967
+ }
968
+ },
969
+ Listeners: {
970
+ click: 'enterEditMode',
971
+ keydown: 'checkForEscapeOrReturn',
972
+ mouseover: 'enterHover',
973
+ mouseout: 'leaveHover'
974
+ }
975
+ });
976
+
977
+ Ajax.InPlaceCollectionEditor.DefaultOptions = {
978
+ loadingCollectionText: 'Loading options...'
979
+ };
980
+
981
+ // Delayed observer, like Form.Element.Observer,
982
+ // but waits for delay after last key input
983
+ // Ideal for live-search fields
984
+
985
+ Form.Element.DelayedObserver = Class.create({
986
+ initialize: function(element, delay, callback) {
987
+ this.delay = delay || 0.5;
988
+ this.element = $(element);
989
+ this.callback = callback;
990
+ this.timer = null;
991
+ this.lastValue = $F(this.element);
992
+ Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this));
993
+ },
994
+ delayedListener: function(event) {
995
+ if(this.lastValue == $F(this.element)) { return; }
996
+ if(this.timer) { clearTimeout(this.timer); }
997
+ this.timer = setTimeout(this.onTimerEvent.bind(this), this.delay * 1000);
998
+ this.lastValue = $F(this.element);
999
+ },
1000
+ onTimerEvent: function() {
1001
+ this.timer = null;
1002
+ this.callback(this.element, $F(this.element));
1003
+ }
1004
+ });