sproutcore 0.9.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/History.txt +4 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +269 -0
  4. data/README.txt +67 -0
  5. data/Rakefile +4 -0
  6. data/app_generators/sproutcore/USAGE +5 -0
  7. data/app_generators/sproutcore/sproutcore_generator.rb +66 -0
  8. data/app_generators/sproutcore/templates/README +77 -0
  9. data/app_generators/sproutcore/templates/environment.yml +4 -0
  10. data/bin/sc-build +145 -0
  11. data/bin/sc-gen +24 -0
  12. data/bin/sc-server +63 -0
  13. data/bin/sproutcore +21 -0
  14. data/clients/sc_docs/controllers/docs.js +118 -0
  15. data/clients/sc_docs/core.js +19 -0
  16. data/clients/sc_docs/english.lproj/body.css +159 -0
  17. data/clients/sc_docs/english.lproj/body.rhtml +33 -0
  18. data/clients/sc_docs/english.lproj/controls.css +0 -0
  19. data/clients/sc_docs/english.lproj/icons/small/next.png +0 -0
  20. data/clients/sc_docs/english.lproj/icons/small/reset.png +0 -0
  21. data/clients/sc_docs/english.lproj/images/gradients.png +0 -0
  22. data/clients/sc_docs/english.lproj/images/indicator.gif +0 -0
  23. data/clients/sc_docs/english.lproj/images/toolbar.png +0 -0
  24. data/clients/sc_docs/english.lproj/no_docs.rhtml +7 -0
  25. data/clients/sc_docs/english.lproj/strings.js +14 -0
  26. data/clients/sc_docs/english.lproj/warning.rhtml +6 -0
  27. data/clients/sc_docs/fixtures/doc.js +11 -0
  28. data/clients/sc_docs/main.js +21 -0
  29. data/clients/sc_docs/models/doc.js +9 -0
  30. data/clients/sc_docs/tests/controllers/docs.rhtml +21 -0
  31. data/clients/sc_docs/tests/models/doc.rhtml +21 -0
  32. data/clients/sc_docs/tests/views/doc_frame.rhtml +21 -0
  33. data/clients/sc_docs/tests/views/doc_label_view.rhtml +21 -0
  34. data/clients/sc_docs/views/doc_frame.js +33 -0
  35. data/clients/sc_docs/views/doc_label.js +20 -0
  36. data/clients/sc_test_runner/controllers/runner.js +175 -0
  37. data/clients/sc_test_runner/core.js +19 -0
  38. data/clients/sc_test_runner/english.lproj/body.css +151 -0
  39. data/clients/sc_test_runner/english.lproj/body.rhtml +35 -0
  40. data/clients/sc_test_runner/english.lproj/controls.css +0 -0
  41. data/clients/sc_test_runner/english.lproj/icons/small/next.png +0 -0
  42. data/clients/sc_test_runner/english.lproj/icons/small/reset.png +0 -0
  43. data/clients/sc_test_runner/english.lproj/images/gradients.png +0 -0
  44. data/clients/sc_test_runner/english.lproj/images/indicator.gif +0 -0
  45. data/clients/sc_test_runner/english.lproj/images/toolbar.png +0 -0
  46. data/clients/sc_test_runner/english.lproj/no_tests.rhtml +6 -0
  47. data/clients/sc_test_runner/english.lproj/strings.js +14 -0
  48. data/clients/sc_test_runner/english.lproj/warning.rhtml +6 -0
  49. data/clients/sc_test_runner/fixtures/test.js +12 -0
  50. data/clients/sc_test_runner/main.js +26 -0
  51. data/clients/sc_test_runner/models/test.js +11 -0
  52. data/clients/sc_test_runner/views/runner_frame.js +72 -0
  53. data/clients/sc_test_runner/views/test_label.js +20 -0
  54. data/config/hoe.rb +70 -0
  55. data/config/requirements.rb +17 -0
  56. data/environment.yml +9 -0
  57. data/frameworks/prototype/prototype.js +4186 -0
  58. data/frameworks/sproutcore/Core.js +378 -0
  59. data/frameworks/sproutcore/README +3 -0
  60. data/frameworks/sproutcore/controllers/array.js +236 -0
  61. data/frameworks/sproutcore/controllers/collection.js +305 -0
  62. data/frameworks/sproutcore/controllers/controller.js +323 -0
  63. data/frameworks/sproutcore/controllers/object.js +372 -0
  64. data/frameworks/sproutcore/drag/drag.js +549 -0
  65. data/frameworks/sproutcore/drag/drag_data_source.js +32 -0
  66. data/frameworks/sproutcore/drag/drag_source.js +64 -0
  67. data/frameworks/sproutcore/drag/drop_target.js +153 -0
  68. data/frameworks/sproutcore/english.lproj/blank.gif +0 -0
  69. data/frameworks/sproutcore/english.lproj/buttons.css +589 -0
  70. data/frameworks/sproutcore/english.lproj/buttons.png +0 -0
  71. data/frameworks/sproutcore/english.lproj/inline_text_editor.css +21 -0
  72. data/frameworks/sproutcore/english.lproj/menu.css +121 -0
  73. data/frameworks/sproutcore/english.lproj/panels/background-fat.jpg +0 -0
  74. data/frameworks/sproutcore/english.lproj/panels/background-thin.jpg +0 -0
  75. data/frameworks/sproutcore/english.lproj/panels/bottom-edge.png +0 -0
  76. data/frameworks/sproutcore/english.lproj/panels/bottom-left-corner.png +0 -0
  77. data/frameworks/sproutcore/english.lproj/panels/bottom-right-corner.png +0 -0
  78. data/frameworks/sproutcore/english.lproj/panels/left-edge.png +0 -0
  79. data/frameworks/sproutcore/english.lproj/panels/overlay.png +0 -0
  80. data/frameworks/sproutcore/english.lproj/panels/right-edge.png +0 -0
  81. data/frameworks/sproutcore/english.lproj/panels/top-edge.png +0 -0
  82. data/frameworks/sproutcore/english.lproj/panels/top-left-corner.png +0 -0
  83. data/frameworks/sproutcore/english.lproj/panels/top-right-corner.png +0 -0
  84. data/frameworks/sproutcore/english.lproj/panes.css +155 -0
  85. data/frameworks/sproutcore/english.lproj/picker.css +22 -0
  86. data/frameworks/sproutcore/english.lproj/strings.js +15 -0
  87. data/frameworks/sproutcore/english.lproj/tab.css +23 -0
  88. data/frameworks/sproutcore/english.lproj/tests.css +67 -0
  89. data/frameworks/sproutcore/english.lproj/theme.css +77 -0
  90. data/frameworks/sproutcore/foundation/animator.js +670 -0
  91. data/frameworks/sproutcore/foundation/application.js +199 -0
  92. data/frameworks/sproutcore/foundation/array.js +348 -0
  93. data/frameworks/sproutcore/foundation/benchmark.js +211 -0
  94. data/frameworks/sproutcore/foundation/binding.js +384 -0
  95. data/frameworks/sproutcore/foundation/date.js +357 -0
  96. data/frameworks/sproutcore/foundation/error.js +39 -0
  97. data/frameworks/sproutcore/foundation/input_manager.js +153 -0
  98. data/frameworks/sproutcore/foundation/json.js +296 -0
  99. data/frameworks/sproutcore/foundation/mock.js +42 -0
  100. data/frameworks/sproutcore/foundation/node_descriptor.js +56 -0
  101. data/frameworks/sproutcore/foundation/object.js +777 -0
  102. data/frameworks/sproutcore/foundation/observable.js +451 -0
  103. data/frameworks/sproutcore/foundation/page.js +63 -0
  104. data/frameworks/sproutcore/foundation/path_module.js +413 -0
  105. data/frameworks/sproutcore/foundation/responder.js +310 -0
  106. data/frameworks/sproutcore/foundation/routes.js +371 -0
  107. data/frameworks/sproutcore/foundation/run_loop.js +21 -0
  108. data/frameworks/sproutcore/foundation/server.js +491 -0
  109. data/frameworks/sproutcore/foundation/set.js +96 -0
  110. data/frameworks/sproutcore/foundation/string.js +149 -0
  111. data/frameworks/sproutcore/foundation/undo_manager.js +186 -0
  112. data/frameworks/sproutcore/foundation/unittest.js +622 -0
  113. data/frameworks/sproutcore/foundation/utils.js +61 -0
  114. data/frameworks/sproutcore/globals/panels.js +182 -0
  115. data/frameworks/sproutcore/globals/popups.js +60 -0
  116. data/frameworks/sproutcore/globals/window.js +381 -0
  117. data/frameworks/sproutcore/lib/index.rhtml +66 -0
  118. data/frameworks/sproutcore/models/collection.js +395 -0
  119. data/frameworks/sproutcore/models/record.js +622 -0
  120. data/frameworks/sproutcore/models/store.js +295 -0
  121. data/frameworks/sproutcore/panes/dialog.js +16 -0
  122. data/frameworks/sproutcore/panes/manager.js +164 -0
  123. data/frameworks/sproutcore/panes/menu.js +45 -0
  124. data/frameworks/sproutcore/panes/overlay.js +231 -0
  125. data/frameworks/sproutcore/panes/pane.js +90 -0
  126. data/frameworks/sproutcore/panes/panel.js +19 -0
  127. data/frameworks/sproutcore/panes/picker.js +45 -0
  128. data/frameworks/sproutcore/tests/controllers/array.rhtml +86 -0
  129. data/frameworks/sproutcore/tests/controllers/controller.rhtml +273 -0
  130. data/frameworks/sproutcore/tests/controllers/object.rhtml +327 -0
  131. data/frameworks/sproutcore/tests/foundation/application.rhtml +125 -0
  132. data/frameworks/sproutcore/tests/foundation/array.rhtml +221 -0
  133. data/frameworks/sproutcore/tests/foundation/object.rhtml +69 -0
  134. data/frameworks/sproutcore/tests/globals/window.rhtml +45 -0
  135. data/frameworks/sproutcore/tests/panes/pane.rhtml +88 -0
  136. data/frameworks/sproutcore/tests/views/collection.rhtml +137 -0
  137. data/frameworks/sproutcore/tests/views/popup_button.rhtml +115 -0
  138. data/frameworks/sproutcore/tests/views/text_field.rhtml +37 -0
  139. data/frameworks/sproutcore/validators/credit_card.js +92 -0
  140. data/frameworks/sproutcore/validators/date.js +36 -0
  141. data/frameworks/sproutcore/validators/email.js +29 -0
  142. data/frameworks/sproutcore/validators/not_empty.js +24 -0
  143. data/frameworks/sproutcore/validators/number.js +55 -0
  144. data/frameworks/sproutcore/validators/password.js +78 -0
  145. data/frameworks/sproutcore/validators/validator.js +304 -0
  146. data/frameworks/sproutcore/views/button.js +425 -0
  147. data/frameworks/sproutcore/views/checkbox_field.js +30 -0
  148. data/frameworks/sproutcore/views/collection.js +1521 -0
  149. data/frameworks/sproutcore/views/container.js +62 -0
  150. data/frameworks/sproutcore/views/error_explanation.js +45 -0
  151. data/frameworks/sproutcore/views/field.js +214 -0
  152. data/frameworks/sproutcore/views/filter_button.js +29 -0
  153. data/frameworks/sproutcore/views/form.js +591 -0
  154. data/frameworks/sproutcore/views/image.js +141 -0
  155. data/frameworks/sproutcore/views/inline_text_editor.js +96 -0
  156. data/frameworks/sproutcore/views/label.js +176 -0
  157. data/frameworks/sproutcore/views/menu_item.js +90 -0
  158. data/frameworks/sproutcore/views/pagination.js +54 -0
  159. data/frameworks/sproutcore/views/popup_button.js +86 -0
  160. data/frameworks/sproutcore/views/popup_menu.js +137 -0
  161. data/frameworks/sproutcore/views/progress.js +100 -0
  162. data/frameworks/sproutcore/views/radio_field.js +107 -0
  163. data/frameworks/sproutcore/views/radio_group.js +48 -0
  164. data/frameworks/sproutcore/views/segmented.js +80 -0
  165. data/frameworks/sproutcore/views/select_field.js +272 -0
  166. data/frameworks/sproutcore/views/spinner.js +11 -0
  167. data/frameworks/sproutcore/views/tab.js +126 -0
  168. data/frameworks/sproutcore/views/text_field.js +179 -0
  169. data/frameworks/sproutcore/views/textarea_field.js +14 -0
  170. data/frameworks/sproutcore/views/toolbar.js +29 -0
  171. data/frameworks/sproutcore/views/view.js +1389 -0
  172. data/frameworks/sproutcore/views/workspace.js +170 -0
  173. data/generators/client/README +3 -0
  174. data/generators/client/USAGE +12 -0
  175. data/generators/client/client_generator.rb +53 -0
  176. data/generators/client/templates/core.js +19 -0
  177. data/generators/client/templates/english.lproj/body.css +0 -0
  178. data/generators/client/templates/english.lproj/body.rhtml +3 -0
  179. data/generators/client/templates/english.lproj/controls.css +0 -0
  180. data/generators/client/templates/english.lproj/strings.js +14 -0
  181. data/generators/client/templates/main.js +37 -0
  182. data/generators/controller/USAGE +16 -0
  183. data/generators/controller/controller_generator.rb +51 -0
  184. data/generators/controller/templates/controller.js +21 -0
  185. data/generators/controller/templates/test.rhtml +21 -0
  186. data/generators/framework/README +7 -0
  187. data/generators/framework/USAGE +12 -0
  188. data/generators/framework/framework_generator.rb +53 -0
  189. data/generators/framework/templates/core.js +20 -0
  190. data/generators/framework/templates/english.lproj/body.css +0 -0
  191. data/generators/framework/templates/english.lproj/body.rhtml +3 -0
  192. data/generators/framework/templates/english.lproj/controls.css +0 -0
  193. data/generators/framework/templates/english.lproj/strings.js +14 -0
  194. data/generators/language/USAGE +16 -0
  195. data/generators/language/language_generator.rb +47 -0
  196. data/generators/language/templates/strings.js +10 -0
  197. data/generators/model/USAGE +24 -0
  198. data/generators/model/model_generator.rb +55 -0
  199. data/generators/model/templates/fixture.js +11 -0
  200. data/generators/model/templates/model.js +20 -0
  201. data/generators/model/templates/test.rhtml +21 -0
  202. data/generators/test/USAGE +16 -0
  203. data/generators/test/templates/test.rhtml +21 -0
  204. data/generators/test/test_generator.rb +47 -0
  205. data/generators/view/USAGE +16 -0
  206. data/generators/view/templates/test.rhtml +21 -0
  207. data/generators/view/templates/view.js +20 -0
  208. data/generators/view/view_generator.rb +51 -0
  209. data/jsdoc/README.txt +119 -0
  210. data/jsdoc/app/DocFile.js +137 -0
  211. data/jsdoc/app/DocTag.js +110 -0
  212. data/jsdoc/app/Doclet.js +63 -0
  213. data/jsdoc/app/Dumper.js +143 -0
  214. data/jsdoc/app/JsDoc.js +103 -0
  215. data/jsdoc/app/JsHilite.js +45 -0
  216. data/jsdoc/app/JsIO.js +163 -0
  217. data/jsdoc/app/JsParse.js +385 -0
  218. data/jsdoc/app/JsPlate.js +130 -0
  219. data/jsdoc/app/JsTestrun.js +129 -0
  220. data/jsdoc/app/JsToke.js +564 -0
  221. data/jsdoc/app/Symbol.js +298 -0
  222. data/jsdoc/app/Transformer.js +14 -0
  223. data/jsdoc/app/Util.js +97 -0
  224. data/jsdoc/app/js.jar +0 -0
  225. data/jsdoc/app/run.js +144 -0
  226. data/jsdoc/plugins/min.js +316 -0
  227. data/jsdoc/plugins/strip.js +20 -0
  228. data/jsdoc/templates/sproutcore/class.tmpl +438 -0
  229. data/jsdoc/templates/sproutcore/default.css +241 -0
  230. data/jsdoc/templates/sproutcore/index.html +13 -0
  231. data/jsdoc/templates/sproutcore/index.tmpl +21 -0
  232. data/jsdoc/templates/sproutcore/prototype.js +4186 -0
  233. data/jsdoc/templates/sproutcore/publish.js +236 -0
  234. data/jsdoc/templates/sproutcore/splash.html +7 -0
  235. data/lib/sproutcore/build_tools/html_builder.rb +88 -0
  236. data/lib/sproutcore/build_tools/resource_builder.rb +194 -0
  237. data/lib/sproutcore/build_tools.rb +44 -0
  238. data/lib/sproutcore/bundle.rb +517 -0
  239. data/lib/sproutcore/bundle_manifest.rb +397 -0
  240. data/lib/sproutcore/generator_helper.rb +170 -0
  241. data/lib/sproutcore/helpers/capture_helper.rb +42 -0
  242. data/lib/sproutcore/helpers/static_helper.rb +80 -0
  243. data/lib/sproutcore/helpers/tag_helper.rb +110 -0
  244. data/lib/sproutcore/helpers/text_helper.rb +336 -0
  245. data/lib/sproutcore/helpers.rb +3 -0
  246. data/lib/sproutcore/jsdoc.rb +40 -0
  247. data/lib/sproutcore/jsmin.rb +247 -0
  248. data/lib/sproutcore/library.rb +258 -0
  249. data/lib/sproutcore/merb/bundle_controller.rb +179 -0
  250. data/lib/sproutcore/merb/router.rb +43 -0
  251. data/lib/sproutcore/merb.rb +27 -0
  252. data/lib/sproutcore/version.rb +9 -0
  253. data/lib/sproutcore/view_helpers/button_views.rb +302 -0
  254. data/lib/sproutcore/view_helpers/core_views.rb +284 -0
  255. data/lib/sproutcore/view_helpers/form_views.rb +258 -0
  256. data/lib/sproutcore/view_helpers/menu_views.rb +94 -0
  257. data/lib/sproutcore/view_helpers.rb +628 -0
  258. data/lib/sproutcore.rb +30 -0
  259. data/script/destroy +14 -0
  260. data/script/generate +14 -0
  261. data/script/txt2html +74 -0
  262. data/setup.rb +1585 -0
  263. data/spec/spec.opts +1 -0
  264. data/spec/spec_helper.rb +7 -0
  265. data/spec/sproutcore_spec.rb +11 -0
  266. data/tasks/deployment.rake +34 -0
  267. data/tasks/environment.rake +7 -0
  268. data/tasks/rspec.rake +21 -0
  269. data/tasks/website.rake +17 -0
  270. metadata +365 -0
@@ -0,0 +1,199 @@
1
+ require('Core');
2
+ require('foundation/responder');
3
+
4
+ /**
5
+ * The SC.Application object manages a SproutCore application.
6
+ * A single instance is created and placed in a global variable named SC.app.
7
+ * All events and actions are routed through this object.
8
+ * @class
9
+ * @constructor
10
+ * @extends SC.Responder
11
+ * @author Skip Baney
12
+ * @copyright 2006-2007, Sprout Systems, Inc. and contributors.
13
+ * @version 0.1
14
+ */
15
+ SC.Application = SC.Responder.extend( /** @scope SC.Application.prototype */ {
16
+
17
+ /**
18
+ * The pane that is currently receiving key events.
19
+ * @return {SC.PaneView}
20
+ */
21
+ keyPane: function( key, value )
22
+ {
23
+ if ( value != undefined )
24
+ {
25
+ if (this._keyPane) this._keyPane.willResignKeyPane();
26
+ if (this._keyPane) this._keyPane.set('isKeyPane', false);
27
+ this._keyPane = value;
28
+ if (this._keyPane) this._keyPane.set('isKeyPane', true);
29
+ if (this._keyPane) this._keyPane.didBecomeKeyPane();
30
+ }
31
+ return this._keyPane || null;
32
+ }.property(),
33
+
34
+ /**
35
+ * The primary pane for the application.
36
+ * @return {SC.PaneView}
37
+ */
38
+ mainPane: function( key, value )
39
+ {
40
+ if ( value != undefined )
41
+ {
42
+ if (this._mainPane) this._mainPane.willResignMainPane();
43
+ if (this._mainPane) this._mainPane.set('isMainPane', false);
44
+ this._mainPane = value;
45
+ if (this._mainPane) this._mainPane.set('isMainPane', true);
46
+ if (this._mainPane) this._mainPane.didBecomeMainPane();
47
+ }
48
+ return this._mainPane || null;
49
+ }.property(),
50
+
51
+ /**
52
+ * Starts the application
53
+ * @return {void}
54
+ */
55
+ run: function()
56
+ {
57
+ // primary application pane.
58
+ SC.window.setup();
59
+ SC.window.makeMainPane();
60
+ SC.window.makeKeyPane();
61
+ },
62
+
63
+ /**
64
+ * Route an action message to the appropriate responder
65
+ * @param {String} action The action to perform
66
+ * @param {SC.Responder} target The object to perform the action upon. Set to null to search the Responder chain for a receiver.
67
+ * @param {Object} sender The sender of the action
68
+ * @returns return value info
69
+ * @type Array
70
+ */
71
+ sendAction: function( action, target, sender )
72
+ {
73
+ var target = this.targetForAction(action, target, sender);
74
+ return (!!target && (target.tryToPerform(action, sender) != false));
75
+ },
76
+
77
+ targetForAction: function( action, target, sender )
78
+ {
79
+ // no action, no target...
80
+ if (!action || ($type(action) != T_STRING)) return null;
81
+
82
+ // an explicit target was passed... but make sure that it does indeed respond to the action...
83
+ if (target) return target.respondsTo(action) ? target : null;
84
+
85
+ // ok, no target was passed... try to find one in the responder chain
86
+ var keyPane = this.get('keyPane');
87
+ var mainPane = this.get('mainPane');
88
+
89
+ // TODO: add in a check for Pane and App delegates once we add support for them...
90
+ if (keyPane)
91
+ {
92
+ target = keyPane.get('firstResponder') || keyPane.get('defaultResponder') || keyPane;
93
+ do {
94
+ if (target.respondsTo(action)) return target;
95
+ } while (target = target.get('nextResponder'));
96
+ }
97
+ if (mainPane && (mainPane != keyPane))
98
+ {
99
+ target = mainPane.get('firstResponder') || mainPane.get('defaultResponder') || mainPane;
100
+ do {
101
+ if (target.respondsTo(action)) return target;
102
+ } while (target = target.get('nextResponder'));
103
+ }
104
+ // last stop, SC.app
105
+ target = this;
106
+ if (target.respondsTo(action)) return target;
107
+
108
+ return null;
109
+ },
110
+
111
+
112
+ sendEvent: function( evt, target )
113
+ {
114
+ var target = target || null;
115
+ var handler = null;
116
+
117
+ //console.log( '[SC.Application#sendEvent] type: %s, evt: %o, target: %o', evt._type, evt, target );
118
+
119
+ if (target && target.respondsTo(evt._type))
120
+ {
121
+ // explicit target was passed... we send the event to that target only...
122
+ return (target.tryToPerform(evt._type, evt)) ? target : false;
123
+ }
124
+
125
+ // ok... then we need to resolve the target based on event type...
126
+ switch ( evt._type )
127
+ {
128
+ case 'keyDown':
129
+ case 'keyUp':
130
+ case 'flagsChanged':
131
+ var pane = this.get('keyPane');
132
+ if (!pane) return null;
133
+ target = pane.get('firstResponder') || pane.get('defaultResponder') || pane;
134
+ break;
135
+ case 'mouseOver':
136
+ case 'mouseOut':
137
+ case 'mouseMoved':
138
+ case 'mouseDown':
139
+ case 'mouseUp':
140
+ case 'click':
141
+ case 'doubleClick':
142
+ target = SC.window.firstViewForEvent(evt);
143
+ break;
144
+ default:
145
+ // unrecognized event type.. bail...
146
+ return null;
147
+ }
148
+
149
+ // unable to resolve a target... mouseDown on an element not in the view chain, key responder is null, etc...
150
+ if (!target) return null;
151
+
152
+ // calling doCommand will crawl up the responder chain until someone handles it or it hits the end of the chain (SC.PaneView).
153
+ handler = target.doCommand( evt._type, evt );
154
+
155
+ // unhandled keyDown event...
156
+ if ((evt._type == 'keyDown') && !handler)
157
+ {
158
+ // lonely keyDown... the responder chain doesn't want you...
159
+ // perhaps someone else has defined you as a shortcut?
160
+ if (this._attemptKeyEquivalent(evt)) return true;
161
+ // no?... how about keyView navigation?
162
+ if (this._attemptKeyInterfaceControl(evt)) return true;
163
+ }
164
+
165
+ //console.log( '[SC.Application#sendEvent] ----- handler: %o', handler );
166
+ return handler;
167
+ },
168
+
169
+ _attemptKeyEquivalent: function( evt )
170
+ {
171
+ // keystring is a method name representing the keys pressed (i.e 'alt_shift_escape')
172
+ var keystring = SC.Responder.inputManager.codesForEvent(evt).first();
173
+
174
+ //console.log( '[SC.Application#_attemptKeyEquivalent] keystring: %s, evt: %o', keystring, evt );
175
+
176
+ // inputManager couldn't build a keystring for this key event... nothing to do...
177
+ if (!keystring) return false;
178
+
179
+ var keyPane = this.get('keyPane');
180
+ var mainPane = this.get('mainPane');
181
+
182
+ if (keyPane && keyPane.performKeyEquivalent(keystring, evt)) return true;
183
+ if (mainPane && (mainPane != keyPane) && mainPane.performKeyEquivalent(keystring, evt)) return true;
184
+ return this.performKeyEquivalent(keystring, evt);
185
+ },
186
+ _attemptKeyInterfaceControl: function( evt )
187
+ {
188
+ // keystring is a method name representing the keys pressed (i.e 'alt_shift_escape')
189
+ var keystring = SC.Responder.inputManager.codesForEvent(evt).first();
190
+
191
+ //console.log( '[SC.Application#_attemptKeyInterfaceControl] keystring: %s, evt: %o', keystring, evt );
192
+
193
+ var pane = this.get('keyPane');
194
+ if ( !pane ) return false;
195
+
196
+ return pane.performKeyInterfaceControl(keystring, evt);
197
+ }
198
+
199
+ });
@@ -0,0 +1,348 @@
1
+ // ==========================================================================
2
+ // SproutCore -- JavaScript Application Framework
3
+ // copyright 2006-2007, Sprout Systems, Inc. and contributors.
4
+ // ==========================================================================
5
+
6
+ require('foundation/observable');
7
+
8
+ // Make Arrays observable
9
+ Object.extend(Array.prototype, SC.Observable) ;
10
+
11
+ SC.OUT_OF_RANGE_EXCEPTION = "Index out of range" ;
12
+
13
+ /**
14
+ @namespace SC.Array
15
+
16
+ This module implements Observer-friendly Array-like behavior. This mixin is
17
+ picked up by the Array class as well as other controllers, etc. that want to
18
+ appear to be arrays.
19
+
20
+ You can use the methods defined in this module to access and modify array
21
+ contents in a KVO-friendly way. You can also be notified whenever the
22
+ membership if an array changes by observing the "[]" property.
23
+
24
+ To support SC.Array in your own class, you must override two
25
+ primitives to use it: replace() and objectAt().
26
+
27
+ */
28
+ SC.Array = {
29
+
30
+ /**
31
+ @property {Number} length
32
+
33
+ Your array must support the length property. your replace methods should
34
+ set this property whenever it changes.
35
+ */
36
+ // length: 0,
37
+
38
+ /**
39
+ This is one of the primitves you must implement to support SC.Array. You
40
+ should replace amt objects started at idx with the objects in the passed
41
+ array. You should also call this.arrayContentDidChange() ;
42
+
43
+ @param {Number} idx
44
+ Starting index in the array to replace. If idx >= length, then append to
45
+ the end of the array.
46
+
47
+ @param {Number} amt
48
+ Number of elements that should be removed from the array, starting at
49
+ *idx*.
50
+
51
+ @param {Array} objects
52
+ An array of zero or more objects that should be inserted into the array at
53
+ *idx*
54
+ */
55
+ replace: function(idx, amt, objects) {
56
+ throw "replace() must be implemented to support SC.Array" ;
57
+ },
58
+
59
+ /**
60
+ This is one of the primitives you must implement to support SC.Array.
61
+ Returns the object at the named index. If your object supports retrieving
62
+ the value of an array item using get() (i.e. myArray.get(0)), then you do
63
+ not need to implement this method yourself.
64
+
65
+ @param {Number} idx
66
+ The index of the item to return. If idx exceeds the current length,
67
+ return null.
68
+ */
69
+ objectAt: function(idx)
70
+ {
71
+ if (idx >= this.get('length')) return undefined;
72
+ return this.get(idx);
73
+ },
74
+
75
+ // this is required to support the enumerable options. Override with your
76
+ // own method if you prefer.
77
+ _each: function(iterator) {
78
+ var len ;
79
+ for (var i = 0, len = this.get('length'); i < len; i++)
80
+ iterator(this.objectAt(i));
81
+ },
82
+
83
+ /**
84
+ When you implement replace(), be sure to call this method whenever the
85
+ membership of your array changes. This will make sure users are properly
86
+ notified.
87
+ */
88
+ arrayContentDidChange: function() {
89
+ this.propertyDidChange('[]') ;
90
+ },
91
+
92
+ /**
93
+ @property []
94
+
95
+ This is the handler for the special array content property. If you get
96
+ this property, it will return this. If you set this property it a new
97
+ array, it will replace the current content.
98
+ */
99
+ '[]': function(key, value) {
100
+ if (value !== undefined) {
101
+ this.replace(0, this.get('length'), value) ;
102
+ }
103
+ return this ;
104
+ }.property(),
105
+
106
+ /**
107
+ This will use the primitive replace() method to insert an object at the
108
+ specified index.
109
+
110
+ @param {Number} idx index of insert the object at.
111
+ @param {Object} object object to insert
112
+ */
113
+ insertAt: function(idx, object) {
114
+ if (idx > this.get('length')) throw SC.OUT_OF_RANGE_EXCEPTION ;
115
+ this.replace(idx,0,[object]) ;
116
+ return this ;
117
+ },
118
+
119
+ /**
120
+ Remove an object at the specified index using the replace() primitive method.
121
+
122
+ @param {Number} idx index of object to remove
123
+ */
124
+ removeAt: function(idx) {
125
+ if ((idx < 0) || (idx >= this.get('length'))) throw SC.OUT_OF_RANGE_EXCEPTION;
126
+ this.replace(idx,1,[]);
127
+ return this ;
128
+ },
129
+
130
+ /**
131
+ Search the array of this object, removing any occurrences of it.
132
+ @param {object} obj object to remove
133
+ */
134
+ removeObject: function(obj) {
135
+ var loc = this.get('length') || 0;
136
+ while(--loc >= 0) {
137
+ var curObject = this.objectAt(loc) ;
138
+ if (curObject == obj) this.removeAt(loc) ;
139
+ }
140
+ return this ;
141
+ },
142
+
143
+ /**
144
+ Push the object onto the end of the array. Works just like push() but it
145
+ is KVO-compliant.
146
+ */
147
+ pushObject: function(obj) {
148
+ this.insertAt(this.get('length'), obj) ;
149
+ return obj ;
150
+ },
151
+
152
+ /**
153
+ Pop object from array or nil if none are left. Works just like pop() but
154
+ it is KVO-compliant.
155
+ */
156
+ popObject: function() {
157
+ var len = this.get('length') ;
158
+ if (len == 0) return null ;
159
+
160
+ var ret = this.objectAt(len-1) ;
161
+ this.removeAt(len-1) ;
162
+ return ret ;
163
+ },
164
+
165
+ /**
166
+ Shift an object from start of array or nil if none are left. Works just
167
+ like shift() but it is KVO-compliant.
168
+ */
169
+ shiftObject: function() {
170
+ if (this.get('length') == 0) return null ;
171
+ var ret = this.objectAt(0) ;
172
+ this.removeAt(0) ;
173
+ return ret ;
174
+ },
175
+
176
+ /**
177
+ Unshift an object to start of array. Works just like unshift() but it is
178
+ KVO-compliant.
179
+ */
180
+ unshiftObject: function(obj) {
181
+ this.insertAt(0, obj) ;
182
+ return obj ;
183
+ },
184
+
185
+ /**
186
+ Compares each item in the array. Returns true if they are equal.
187
+ */
188
+ isEqual: function(ary) {
189
+ if (!ary) return false ;
190
+ if (ary == this) return true;
191
+
192
+ var loc = ary.get('length') ;
193
+ if (loc != this.get('length')) return false ;
194
+
195
+ while(--loc >= 0) {
196
+ if (ary.objectAt(loc) != this.objectAt(loc)) return false ;
197
+ }
198
+ return true ;
199
+ }
200
+
201
+ } ;
202
+
203
+ // All arrays have the SC.Array mixin. Do this before we add the
204
+ // enumerable methods since Arrays are already enumerable.
205
+ Object.extend(Array.prototype, SC.Array) ;
206
+
207
+ // Now make SC.Array enumerable.
208
+ Object.extend(SC.Array, Enumerable) ;
209
+
210
+ // ........................................................
211
+ // A few basic enhancements to the Array class.
212
+ // These methods add support for the SproutCore replace() method as well as
213
+ // optimizing certain enumerable methods.
214
+ //
215
+ Object.extend(Array.prototype, {
216
+
217
+ // primitive for array support.
218
+ replace: function(idx, amt, objects) {
219
+ if (!objects || objects.length == 0) {
220
+ this.splice(idx, amt) ;
221
+ } else {
222
+ var args = [idx, amt].concat(objects) ;
223
+ this.splice.apply(this,args) ;
224
+ }
225
+ this.arrayContentDidChange() ;
226
+ return this ;
227
+ },
228
+
229
+ // These are faster implementations of the iterations defined by prototype.
230
+ // The iterators there are cool but they consume large numbers of stack
231
+ // frames. These are API compatible, but much faster because they duplicate
232
+ // code instead of calling a bunch of common methods.
233
+
234
+ each: function(iterator) {
235
+ try {
236
+ for(var index=0;index<this.length;index++) {
237
+ var item = this[index] ;
238
+ iterator.call(item,item,index) ;
239
+ }
240
+ } catch (e) {
241
+ if (e != $break) throw e ;
242
+ }
243
+ return this ;
244
+ },
245
+
246
+ invoke: function(iterator) {
247
+ var args = $A(arguments) ;
248
+ var methodName = args.shift() ;
249
+ var ret = [] ;
250
+ try {
251
+ for(var index=0;index<this.length;index++) {
252
+ var item = this[index] ;
253
+ ret.push(item[methodName].apply(item,args)) ;
254
+ } ;
255
+ } catch (e) {
256
+ if (e != $break) throw e ;
257
+ }
258
+ return ret ;
259
+ },
260
+
261
+ map: function(iterator) {
262
+ var ret = [] ;
263
+ try {
264
+ for(var index=0;index<this.length;index++) {
265
+ var item = this[index] ;
266
+ ret.push((iterator || Prototype.K).call(item,item,index)) ;
267
+ } ;
268
+ } catch (e) {
269
+ if (e != $break) throw e ;
270
+ }
271
+ return ret ;
272
+ },
273
+
274
+ // This will invoke the passed method and arguments on the member elements
275
+ // as long as the value returned is the first argument.
276
+ invokeWhile: function(retValue, methodName) {
277
+ var ret ;
278
+ var args = $A(arguments) ;
279
+ retValue = args.shift() ;
280
+ methodName = args.shift() ;
281
+
282
+ try {
283
+ for(var index=0; index < this.length; index++) {
284
+ var item = this[index] ;
285
+ var func = (item) ? item[methodName] : null ;
286
+ ret = func.apply(item, args) ;
287
+ if (ret != retValue) return retValue ;
288
+ }
289
+ } catch (e) {
290
+ if (e != $break) throw e ;
291
+ }
292
+ return ret ;
293
+ },
294
+
295
+ // If you ask for an unknown property, then try to collect the value
296
+ // from member items.
297
+ unknownProperty: function(key, value) {
298
+ if (value !== undefined) return null ;
299
+ return this.invoke('get', key) ;
300
+ }
301
+ }) ;
302
+
303
+ Array.prototype.collect = Array.prototype.map ;
304
+
305
+
306
+ // Returns the passed item as an array. If the item is already an array,
307
+ // it is returned as is. If it is not an array, it is placed into one. If
308
+ // it is null, an empty array is returned.
309
+ Array.asArray = function (array)
310
+ {
311
+ if(array && !(array instanceof Array))
312
+ {
313
+ return [array];
314
+ }
315
+ if(array)
316
+ {
317
+ return array;
318
+ }
319
+ return [];
320
+ };
321
+
322
+ // Alias for asArray
323
+ Array.from = Array.asArray ;
324
+
325
+ // Map added array methods to other enumerables
326
+ Object.extend(Enumerable, {
327
+
328
+ invokeWhile: function(retValue, methodName) {
329
+ var ret ;
330
+ var args = $A(arguments) ;
331
+ retValue = args.shift() ;
332
+ methodName = args.shift() ;
333
+
334
+ try {
335
+ var obj = this ;
336
+ this._each(function(item) {
337
+ var func = (item) ? item[methodName] : null ;
338
+ ret = func.apply(item, args) ;
339
+ if (ret != retValue) $break ;
340
+ }) ;
341
+ } catch (e) {
342
+ if (e != $break) throw e ;
343
+ }
344
+ return ret ;
345
+ }
346
+
347
+ }) ;
348
+