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.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +269 -0
- data/README.txt +67 -0
- data/Rakefile +4 -0
- data/app_generators/sproutcore/USAGE +5 -0
- data/app_generators/sproutcore/sproutcore_generator.rb +66 -0
- data/app_generators/sproutcore/templates/README +77 -0
- data/app_generators/sproutcore/templates/environment.yml +4 -0
- data/bin/sc-build +145 -0
- data/bin/sc-gen +24 -0
- data/bin/sc-server +63 -0
- data/bin/sproutcore +21 -0
- data/clients/sc_docs/controllers/docs.js +118 -0
- data/clients/sc_docs/core.js +19 -0
- data/clients/sc_docs/english.lproj/body.css +159 -0
- data/clients/sc_docs/english.lproj/body.rhtml +33 -0
- data/clients/sc_docs/english.lproj/controls.css +0 -0
- data/clients/sc_docs/english.lproj/icons/small/next.png +0 -0
- data/clients/sc_docs/english.lproj/icons/small/reset.png +0 -0
- data/clients/sc_docs/english.lproj/images/gradients.png +0 -0
- data/clients/sc_docs/english.lproj/images/indicator.gif +0 -0
- data/clients/sc_docs/english.lproj/images/toolbar.png +0 -0
- data/clients/sc_docs/english.lproj/no_docs.rhtml +7 -0
- data/clients/sc_docs/english.lproj/strings.js +14 -0
- data/clients/sc_docs/english.lproj/warning.rhtml +6 -0
- data/clients/sc_docs/fixtures/doc.js +11 -0
- data/clients/sc_docs/main.js +21 -0
- data/clients/sc_docs/models/doc.js +9 -0
- data/clients/sc_docs/tests/controllers/docs.rhtml +21 -0
- data/clients/sc_docs/tests/models/doc.rhtml +21 -0
- data/clients/sc_docs/tests/views/doc_frame.rhtml +21 -0
- data/clients/sc_docs/tests/views/doc_label_view.rhtml +21 -0
- data/clients/sc_docs/views/doc_frame.js +33 -0
- data/clients/sc_docs/views/doc_label.js +20 -0
- data/clients/sc_test_runner/controllers/runner.js +175 -0
- data/clients/sc_test_runner/core.js +19 -0
- data/clients/sc_test_runner/english.lproj/body.css +151 -0
- data/clients/sc_test_runner/english.lproj/body.rhtml +35 -0
- data/clients/sc_test_runner/english.lproj/controls.css +0 -0
- data/clients/sc_test_runner/english.lproj/icons/small/next.png +0 -0
- data/clients/sc_test_runner/english.lproj/icons/small/reset.png +0 -0
- data/clients/sc_test_runner/english.lproj/images/gradients.png +0 -0
- data/clients/sc_test_runner/english.lproj/images/indicator.gif +0 -0
- data/clients/sc_test_runner/english.lproj/images/toolbar.png +0 -0
- data/clients/sc_test_runner/english.lproj/no_tests.rhtml +6 -0
- data/clients/sc_test_runner/english.lproj/strings.js +14 -0
- data/clients/sc_test_runner/english.lproj/warning.rhtml +6 -0
- data/clients/sc_test_runner/fixtures/test.js +12 -0
- data/clients/sc_test_runner/main.js +26 -0
- data/clients/sc_test_runner/models/test.js +11 -0
- data/clients/sc_test_runner/views/runner_frame.js +72 -0
- data/clients/sc_test_runner/views/test_label.js +20 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +17 -0
- data/environment.yml +9 -0
- data/frameworks/prototype/prototype.js +4186 -0
- data/frameworks/sproutcore/Core.js +378 -0
- data/frameworks/sproutcore/README +3 -0
- data/frameworks/sproutcore/controllers/array.js +236 -0
- data/frameworks/sproutcore/controllers/collection.js +305 -0
- data/frameworks/sproutcore/controllers/controller.js +323 -0
- data/frameworks/sproutcore/controllers/object.js +372 -0
- data/frameworks/sproutcore/drag/drag.js +549 -0
- data/frameworks/sproutcore/drag/drag_data_source.js +32 -0
- data/frameworks/sproutcore/drag/drag_source.js +64 -0
- data/frameworks/sproutcore/drag/drop_target.js +153 -0
- data/frameworks/sproutcore/english.lproj/blank.gif +0 -0
- data/frameworks/sproutcore/english.lproj/buttons.css +589 -0
- data/frameworks/sproutcore/english.lproj/buttons.png +0 -0
- data/frameworks/sproutcore/english.lproj/inline_text_editor.css +21 -0
- data/frameworks/sproutcore/english.lproj/menu.css +121 -0
- data/frameworks/sproutcore/english.lproj/panels/background-fat.jpg +0 -0
- data/frameworks/sproutcore/english.lproj/panels/background-thin.jpg +0 -0
- data/frameworks/sproutcore/english.lproj/panels/bottom-edge.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/bottom-left-corner.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/bottom-right-corner.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/left-edge.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/overlay.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/right-edge.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/top-edge.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/top-left-corner.png +0 -0
- data/frameworks/sproutcore/english.lproj/panels/top-right-corner.png +0 -0
- data/frameworks/sproutcore/english.lproj/panes.css +155 -0
- data/frameworks/sproutcore/english.lproj/picker.css +22 -0
- data/frameworks/sproutcore/english.lproj/strings.js +15 -0
- data/frameworks/sproutcore/english.lproj/tab.css +23 -0
- data/frameworks/sproutcore/english.lproj/tests.css +67 -0
- data/frameworks/sproutcore/english.lproj/theme.css +77 -0
- data/frameworks/sproutcore/foundation/animator.js +670 -0
- data/frameworks/sproutcore/foundation/application.js +199 -0
- data/frameworks/sproutcore/foundation/array.js +348 -0
- data/frameworks/sproutcore/foundation/benchmark.js +211 -0
- data/frameworks/sproutcore/foundation/binding.js +384 -0
- data/frameworks/sproutcore/foundation/date.js +357 -0
- data/frameworks/sproutcore/foundation/error.js +39 -0
- data/frameworks/sproutcore/foundation/input_manager.js +153 -0
- data/frameworks/sproutcore/foundation/json.js +296 -0
- data/frameworks/sproutcore/foundation/mock.js +42 -0
- data/frameworks/sproutcore/foundation/node_descriptor.js +56 -0
- data/frameworks/sproutcore/foundation/object.js +777 -0
- data/frameworks/sproutcore/foundation/observable.js +451 -0
- data/frameworks/sproutcore/foundation/page.js +63 -0
- data/frameworks/sproutcore/foundation/path_module.js +413 -0
- data/frameworks/sproutcore/foundation/responder.js +310 -0
- data/frameworks/sproutcore/foundation/routes.js +371 -0
- data/frameworks/sproutcore/foundation/run_loop.js +21 -0
- data/frameworks/sproutcore/foundation/server.js +491 -0
- data/frameworks/sproutcore/foundation/set.js +96 -0
- data/frameworks/sproutcore/foundation/string.js +149 -0
- data/frameworks/sproutcore/foundation/undo_manager.js +186 -0
- data/frameworks/sproutcore/foundation/unittest.js +622 -0
- data/frameworks/sproutcore/foundation/utils.js +61 -0
- data/frameworks/sproutcore/globals/panels.js +182 -0
- data/frameworks/sproutcore/globals/popups.js +60 -0
- data/frameworks/sproutcore/globals/window.js +381 -0
- data/frameworks/sproutcore/lib/index.rhtml +66 -0
- data/frameworks/sproutcore/models/collection.js +395 -0
- data/frameworks/sproutcore/models/record.js +622 -0
- data/frameworks/sproutcore/models/store.js +295 -0
- data/frameworks/sproutcore/panes/dialog.js +16 -0
- data/frameworks/sproutcore/panes/manager.js +164 -0
- data/frameworks/sproutcore/panes/menu.js +45 -0
- data/frameworks/sproutcore/panes/overlay.js +231 -0
- data/frameworks/sproutcore/panes/pane.js +90 -0
- data/frameworks/sproutcore/panes/panel.js +19 -0
- data/frameworks/sproutcore/panes/picker.js +45 -0
- data/frameworks/sproutcore/tests/controllers/array.rhtml +86 -0
- data/frameworks/sproutcore/tests/controllers/controller.rhtml +273 -0
- data/frameworks/sproutcore/tests/controllers/object.rhtml +327 -0
- data/frameworks/sproutcore/tests/foundation/application.rhtml +125 -0
- data/frameworks/sproutcore/tests/foundation/array.rhtml +221 -0
- data/frameworks/sproutcore/tests/foundation/object.rhtml +69 -0
- data/frameworks/sproutcore/tests/globals/window.rhtml +45 -0
- data/frameworks/sproutcore/tests/panes/pane.rhtml +88 -0
- data/frameworks/sproutcore/tests/views/collection.rhtml +137 -0
- data/frameworks/sproutcore/tests/views/popup_button.rhtml +115 -0
- data/frameworks/sproutcore/tests/views/text_field.rhtml +37 -0
- data/frameworks/sproutcore/validators/credit_card.js +92 -0
- data/frameworks/sproutcore/validators/date.js +36 -0
- data/frameworks/sproutcore/validators/email.js +29 -0
- data/frameworks/sproutcore/validators/not_empty.js +24 -0
- data/frameworks/sproutcore/validators/number.js +55 -0
- data/frameworks/sproutcore/validators/password.js +78 -0
- data/frameworks/sproutcore/validators/validator.js +304 -0
- data/frameworks/sproutcore/views/button.js +425 -0
- data/frameworks/sproutcore/views/checkbox_field.js +30 -0
- data/frameworks/sproutcore/views/collection.js +1521 -0
- data/frameworks/sproutcore/views/container.js +62 -0
- data/frameworks/sproutcore/views/error_explanation.js +45 -0
- data/frameworks/sproutcore/views/field.js +214 -0
- data/frameworks/sproutcore/views/filter_button.js +29 -0
- data/frameworks/sproutcore/views/form.js +591 -0
- data/frameworks/sproutcore/views/image.js +141 -0
- data/frameworks/sproutcore/views/inline_text_editor.js +96 -0
- data/frameworks/sproutcore/views/label.js +176 -0
- data/frameworks/sproutcore/views/menu_item.js +90 -0
- data/frameworks/sproutcore/views/pagination.js +54 -0
- data/frameworks/sproutcore/views/popup_button.js +86 -0
- data/frameworks/sproutcore/views/popup_menu.js +137 -0
- data/frameworks/sproutcore/views/progress.js +100 -0
- data/frameworks/sproutcore/views/radio_field.js +107 -0
- data/frameworks/sproutcore/views/radio_group.js +48 -0
- data/frameworks/sproutcore/views/segmented.js +80 -0
- data/frameworks/sproutcore/views/select_field.js +272 -0
- data/frameworks/sproutcore/views/spinner.js +11 -0
- data/frameworks/sproutcore/views/tab.js +126 -0
- data/frameworks/sproutcore/views/text_field.js +179 -0
- data/frameworks/sproutcore/views/textarea_field.js +14 -0
- data/frameworks/sproutcore/views/toolbar.js +29 -0
- data/frameworks/sproutcore/views/view.js +1389 -0
- data/frameworks/sproutcore/views/workspace.js +170 -0
- data/generators/client/README +3 -0
- data/generators/client/USAGE +12 -0
- data/generators/client/client_generator.rb +53 -0
- data/generators/client/templates/core.js +19 -0
- data/generators/client/templates/english.lproj/body.css +0 -0
- data/generators/client/templates/english.lproj/body.rhtml +3 -0
- data/generators/client/templates/english.lproj/controls.css +0 -0
- data/generators/client/templates/english.lproj/strings.js +14 -0
- data/generators/client/templates/main.js +37 -0
- data/generators/controller/USAGE +16 -0
- data/generators/controller/controller_generator.rb +51 -0
- data/generators/controller/templates/controller.js +21 -0
- data/generators/controller/templates/test.rhtml +21 -0
- data/generators/framework/README +7 -0
- data/generators/framework/USAGE +12 -0
- data/generators/framework/framework_generator.rb +53 -0
- data/generators/framework/templates/core.js +20 -0
- data/generators/framework/templates/english.lproj/body.css +0 -0
- data/generators/framework/templates/english.lproj/body.rhtml +3 -0
- data/generators/framework/templates/english.lproj/controls.css +0 -0
- data/generators/framework/templates/english.lproj/strings.js +14 -0
- data/generators/language/USAGE +16 -0
- data/generators/language/language_generator.rb +47 -0
- data/generators/language/templates/strings.js +10 -0
- data/generators/model/USAGE +24 -0
- data/generators/model/model_generator.rb +55 -0
- data/generators/model/templates/fixture.js +11 -0
- data/generators/model/templates/model.js +20 -0
- data/generators/model/templates/test.rhtml +21 -0
- data/generators/test/USAGE +16 -0
- data/generators/test/templates/test.rhtml +21 -0
- data/generators/test/test_generator.rb +47 -0
- data/generators/view/USAGE +16 -0
- data/generators/view/templates/test.rhtml +21 -0
- data/generators/view/templates/view.js +20 -0
- data/generators/view/view_generator.rb +51 -0
- data/jsdoc/README.txt +119 -0
- data/jsdoc/app/DocFile.js +137 -0
- data/jsdoc/app/DocTag.js +110 -0
- data/jsdoc/app/Doclet.js +63 -0
- data/jsdoc/app/Dumper.js +143 -0
- data/jsdoc/app/JsDoc.js +103 -0
- data/jsdoc/app/JsHilite.js +45 -0
- data/jsdoc/app/JsIO.js +163 -0
- data/jsdoc/app/JsParse.js +385 -0
- data/jsdoc/app/JsPlate.js +130 -0
- data/jsdoc/app/JsTestrun.js +129 -0
- data/jsdoc/app/JsToke.js +564 -0
- data/jsdoc/app/Symbol.js +298 -0
- data/jsdoc/app/Transformer.js +14 -0
- data/jsdoc/app/Util.js +97 -0
- data/jsdoc/app/js.jar +0 -0
- data/jsdoc/app/run.js +144 -0
- data/jsdoc/plugins/min.js +316 -0
- data/jsdoc/plugins/strip.js +20 -0
- data/jsdoc/templates/sproutcore/class.tmpl +438 -0
- data/jsdoc/templates/sproutcore/default.css +241 -0
- data/jsdoc/templates/sproutcore/index.html +13 -0
- data/jsdoc/templates/sproutcore/index.tmpl +21 -0
- data/jsdoc/templates/sproutcore/prototype.js +4186 -0
- data/jsdoc/templates/sproutcore/publish.js +236 -0
- data/jsdoc/templates/sproutcore/splash.html +7 -0
- data/lib/sproutcore/build_tools/html_builder.rb +88 -0
- data/lib/sproutcore/build_tools/resource_builder.rb +194 -0
- data/lib/sproutcore/build_tools.rb +44 -0
- data/lib/sproutcore/bundle.rb +517 -0
- data/lib/sproutcore/bundle_manifest.rb +397 -0
- data/lib/sproutcore/generator_helper.rb +170 -0
- data/lib/sproutcore/helpers/capture_helper.rb +42 -0
- data/lib/sproutcore/helpers/static_helper.rb +80 -0
- data/lib/sproutcore/helpers/tag_helper.rb +110 -0
- data/lib/sproutcore/helpers/text_helper.rb +336 -0
- data/lib/sproutcore/helpers.rb +3 -0
- data/lib/sproutcore/jsdoc.rb +40 -0
- data/lib/sproutcore/jsmin.rb +247 -0
- data/lib/sproutcore/library.rb +258 -0
- data/lib/sproutcore/merb/bundle_controller.rb +179 -0
- data/lib/sproutcore/merb/router.rb +43 -0
- data/lib/sproutcore/merb.rb +27 -0
- data/lib/sproutcore/version.rb +9 -0
- data/lib/sproutcore/view_helpers/button_views.rb +302 -0
- data/lib/sproutcore/view_helpers/core_views.rb +284 -0
- data/lib/sproutcore/view_helpers/form_views.rb +258 -0
- data/lib/sproutcore/view_helpers/menu_views.rb +94 -0
- data/lib/sproutcore/view_helpers.rb +628 -0
- data/lib/sproutcore.rb +30 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/sproutcore_spec.rb +11 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/website.rake +17 -0
- metadata +365 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/*
|
|
2
|
+
json.js
|
|
3
|
+
2007-03-20
|
|
4
|
+
|
|
5
|
+
Public Domain
|
|
6
|
+
|
|
7
|
+
This file adds these methods to JavaScript:
|
|
8
|
+
|
|
9
|
+
array.toJSONString()
|
|
10
|
+
boolean.toJSONString()
|
|
11
|
+
date.toJSONString()
|
|
12
|
+
number.toJSONString()
|
|
13
|
+
object.toJSONString()
|
|
14
|
+
string.toJSONString()
|
|
15
|
+
These methods produce a JSON text from a JavaScript value.
|
|
16
|
+
It must not contain any cyclical references. Illegal values
|
|
17
|
+
will be excluded.
|
|
18
|
+
|
|
19
|
+
The default conversion for dates is to an ISO string. You can
|
|
20
|
+
add a toJSONString method to any date object to get a different
|
|
21
|
+
representation.
|
|
22
|
+
|
|
23
|
+
string.parseJSON(filter)
|
|
24
|
+
This method parses a JSON text to produce an object or
|
|
25
|
+
array. It can throw a SyntaxError exception.
|
|
26
|
+
|
|
27
|
+
The optional filter parameter is a function which can filter and
|
|
28
|
+
transform the results. It receives each of the keys and values, and
|
|
29
|
+
its return value is used instead of the original value. If it
|
|
30
|
+
returns what it received, then structure is not modified. If it
|
|
31
|
+
returns undefined then the member is deleted.
|
|
32
|
+
|
|
33
|
+
Example:
|
|
34
|
+
|
|
35
|
+
// Parse the text. If a key contains the string 'date' then
|
|
36
|
+
// convert the value to a date.
|
|
37
|
+
|
|
38
|
+
myData = text.parseJSON(function (key, value) {
|
|
39
|
+
return key.indexOf('date') >= 0 ? new Date(value) : value;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
It is expected that these methods will formally become part of the
|
|
43
|
+
JavaScript Programming Language in the Fourth Edition of the
|
|
44
|
+
ECMAScript standard in 2008.
|
|
45
|
+
|
|
46
|
+
This file will break programs with improper for..in loops. See
|
|
47
|
+
http://yuiblog.com/blog/2006/09/26/for-in-intrigue/
|
|
48
|
+
|
|
49
|
+
This is a reference implementation. You are free to copy, modify, or
|
|
50
|
+
redistribute.
|
|
51
|
+
|
|
52
|
+
Use your own copy. It is extremely unwise to load untrusted third party
|
|
53
|
+
code into your pages.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
// Augment the basic prototypes if they have not already been augmented.
|
|
57
|
+
|
|
58
|
+
if (!Object.toJSONString) {
|
|
59
|
+
|
|
60
|
+
Array.prototype.toJSONString = function () {
|
|
61
|
+
var a = ['['], // The array holding the text fragments.
|
|
62
|
+
b, // A boolean indicating that a comma is required.
|
|
63
|
+
i, // Loop counter.
|
|
64
|
+
l = this.length,
|
|
65
|
+
v; // The value to be stringified.
|
|
66
|
+
|
|
67
|
+
function p(s) {
|
|
68
|
+
|
|
69
|
+
// p accumulates text fragments in an array. It inserts a comma before all
|
|
70
|
+
// except the first fragment.
|
|
71
|
+
|
|
72
|
+
if (b) {
|
|
73
|
+
a.push(',');
|
|
74
|
+
}
|
|
75
|
+
a.push(s);
|
|
76
|
+
b = true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// For each value in this array...
|
|
80
|
+
|
|
81
|
+
for (i = 0; i < l; i += 1) {
|
|
82
|
+
v = this[i];
|
|
83
|
+
switch (typeof v) {
|
|
84
|
+
|
|
85
|
+
// Serialize a JavaScript object value. Ignore objects thats lack the
|
|
86
|
+
// toJSONString method. Due to a specification error in ECMAScript,
|
|
87
|
+
// typeof null is 'object', so watch out for that case.
|
|
88
|
+
|
|
89
|
+
case 'object':
|
|
90
|
+
if (v) {
|
|
91
|
+
if (typeof v.toJSONString === 'function') {
|
|
92
|
+
p(v.toJSONString());
|
|
93
|
+
} else p(Object.toJSONString(v)) ;
|
|
94
|
+
} else {
|
|
95
|
+
p("null");
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
|
|
99
|
+
// Otherwise, serialize the value.
|
|
100
|
+
|
|
101
|
+
case 'string':
|
|
102
|
+
case 'number':
|
|
103
|
+
case 'boolean':
|
|
104
|
+
p(v.toJSONString());
|
|
105
|
+
|
|
106
|
+
// Values without a JSON representation are ignored.
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Join all of the fragments together and return.
|
|
112
|
+
|
|
113
|
+
a.push(']');
|
|
114
|
+
return a.join('');
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
Boolean.prototype.toJSONString = function () {
|
|
119
|
+
return String(this);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
Date.prototype.toJSONString = function () {
|
|
124
|
+
|
|
125
|
+
// Ultimately, this method will be equivalent to the date.toISOString method.
|
|
126
|
+
|
|
127
|
+
function f(n) {
|
|
128
|
+
|
|
129
|
+
// Format integers to have at least two digits.
|
|
130
|
+
|
|
131
|
+
return n < 10 ? '0' + n : n;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return '"' + this.getFullYear() + '-' +
|
|
135
|
+
f(this.getMonth() + 1) + '-' +
|
|
136
|
+
f(this.getDate()) + 'T' +
|
|
137
|
+
f(this.getHours()) + ':' +
|
|
138
|
+
f(this.getMinutes()) + ':' +
|
|
139
|
+
f(this.getSeconds()) + '"';
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
Number.prototype.toJSONString = function () {
|
|
144
|
+
|
|
145
|
+
// JSON numbers must be finite. Encode non-finite numbers as null.
|
|
146
|
+
|
|
147
|
+
return isFinite(this) ? String(this) : "null";
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
Object.toJSONString = function (object) {
|
|
152
|
+
var a = ['{'], // The array holding the text fragments.
|
|
153
|
+
b, // A boolean indicating that a comma is required.
|
|
154
|
+
k, // The current key.
|
|
155
|
+
v; // The current value.
|
|
156
|
+
|
|
157
|
+
function p(s) {
|
|
158
|
+
|
|
159
|
+
// p accumulates text fragment pairs in an array. It inserts a comma before all
|
|
160
|
+
// except the first fragment pair.
|
|
161
|
+
|
|
162
|
+
if (b) {
|
|
163
|
+
a.push(',');
|
|
164
|
+
}
|
|
165
|
+
a.push(k.toJSONString(), ':', s);
|
|
166
|
+
b = true;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Iterate through all of the keys in the object, ignoring the proto chain.
|
|
170
|
+
|
|
171
|
+
for (k in object) {
|
|
172
|
+
if (object.hasOwnProperty(k)) {
|
|
173
|
+
v = object[k];
|
|
174
|
+
switch (typeof v) {
|
|
175
|
+
|
|
176
|
+
// Serialize a JavaScript object value. Ignore objects that lack the
|
|
177
|
+
// toJSONString method. Due to a specification error in ECMAScript,
|
|
178
|
+
// typeof null is 'object', so watch out for that case.
|
|
179
|
+
|
|
180
|
+
case 'object':
|
|
181
|
+
if (v) {
|
|
182
|
+
if (typeof v.toJSONString === 'function') {
|
|
183
|
+
p(v.toJSONString());
|
|
184
|
+
} else p(Object.toJSONString(v)) ;
|
|
185
|
+
} else {
|
|
186
|
+
p("null");
|
|
187
|
+
}
|
|
188
|
+
break;
|
|
189
|
+
|
|
190
|
+
case 'string':
|
|
191
|
+
case 'number':
|
|
192
|
+
case 'boolean':
|
|
193
|
+
p(v.toJSONString());
|
|
194
|
+
|
|
195
|
+
// Values without a JSON representation are ignored.
|
|
196
|
+
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Join all of the fragments together and return.
|
|
202
|
+
|
|
203
|
+
a.push('}');
|
|
204
|
+
return a.join('');
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
(function (s) {
|
|
209
|
+
|
|
210
|
+
// Augment String.prototype. We do this in an immediate anonymous function to
|
|
211
|
+
// avoid defining global variables.
|
|
212
|
+
|
|
213
|
+
// m is a table of character substitutions.
|
|
214
|
+
|
|
215
|
+
var m = {
|
|
216
|
+
'\b': '\\b',
|
|
217
|
+
'\t': '\\t',
|
|
218
|
+
'\n': '\\n',
|
|
219
|
+
'\f': '\\f',
|
|
220
|
+
'\r': '\\r',
|
|
221
|
+
'"' : '\\"',
|
|
222
|
+
'\\': '\\\\'
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
s.parseJSON = function (filter) {
|
|
227
|
+
|
|
228
|
+
// Parsing happens in three stages. In the first stage, we run the text against
|
|
229
|
+
// a regular expression which looks for non-JSON characters. We are especially
|
|
230
|
+
// concerned with '()' and 'new' because they can cause invocation, and '='
|
|
231
|
+
// because it can cause mutation. But just to be safe, we will reject all
|
|
232
|
+
// unexpected characters.
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.
|
|
236
|
+
test(this)) {
|
|
237
|
+
|
|
238
|
+
// In the second stage we use the eval function to compile the text into a
|
|
239
|
+
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
|
240
|
+
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
|
241
|
+
// in parens to eliminate the ambiguity.
|
|
242
|
+
|
|
243
|
+
var j = eval('(' + this + ')');
|
|
244
|
+
|
|
245
|
+
// In the optional third stage, we recursively walk the new structure, passing
|
|
246
|
+
// each name/value pair to a filter function for possible transformation.
|
|
247
|
+
|
|
248
|
+
if (typeof filter === 'function') {
|
|
249
|
+
|
|
250
|
+
function walk(k, v) {
|
|
251
|
+
if (v && typeof v === 'object') {
|
|
252
|
+
for (var i in v) {
|
|
253
|
+
if (v.hasOwnProperty(i)) {
|
|
254
|
+
v[i] = walk(i, v[i]);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return filter(k, v);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
j = walk('', j);
|
|
262
|
+
}
|
|
263
|
+
return j;
|
|
264
|
+
}
|
|
265
|
+
} catch (e) {
|
|
266
|
+
|
|
267
|
+
// Fall through if the regexp test fails.
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
throw new SyntaxError("parseJSON");
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
s.toJSONString = function () {
|
|
275
|
+
|
|
276
|
+
// If the string contains no control characters, no quote characters, and no
|
|
277
|
+
// backslash characters, then we can simply slap some quotes around it.
|
|
278
|
+
// Otherwise we must also replace the offending characters with safe
|
|
279
|
+
// sequences.
|
|
280
|
+
|
|
281
|
+
if (/["\\\x00-\x1f]/.test(this)) {
|
|
282
|
+
return '"' + this.replace(/([\x00-\x1f\\"])/g, function(a, b) {
|
|
283
|
+
var c = m[b];
|
|
284
|
+
if (c) {
|
|
285
|
+
return c;
|
|
286
|
+
}
|
|
287
|
+
c = b.charCodeAt();
|
|
288
|
+
return '\\u00' +
|
|
289
|
+
Math.floor(c / 16).toString(16) +
|
|
290
|
+
(c % 16).toString(16);
|
|
291
|
+
}) + '"';
|
|
292
|
+
}
|
|
293
|
+
return '"' + this + '"';
|
|
294
|
+
};
|
|
295
|
+
})(String.prototype);
|
|
296
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require('Core');
|
|
2
|
+
require('foundation/object');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
@namespace Mocks for unit testing
|
|
6
|
+
@author Skip Baney
|
|
7
|
+
@copyright 2006-2007, Sprout Systems, Inc. and contributors.
|
|
8
|
+
@version 0.1
|
|
9
|
+
|
|
10
|
+
Mock objects provide basic support for unit testing. Look for subclasses.
|
|
11
|
+
|
|
12
|
+
*/
|
|
13
|
+
SC.Mock = {};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Base DOM event mock
|
|
17
|
+
* @extends SC.Object
|
|
18
|
+
*/
|
|
19
|
+
SC.Mock.DOMEvent = SC.Object.extend(
|
|
20
|
+
/** @scope SC.Mock.DOMEvent.prototype */
|
|
21
|
+
{
|
|
22
|
+
type: null,
|
|
23
|
+
target: null,
|
|
24
|
+
stopped: false,
|
|
25
|
+
preventDefault: function() {},
|
|
26
|
+
stopPropagation: function() {}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Mock for key events
|
|
31
|
+
* @extends SC.Mock.DOMEvent
|
|
32
|
+
*/
|
|
33
|
+
SC.Mock.KeyEvent = SC.Mock.DOMEvent.extend(
|
|
34
|
+
/** @scope SC.Mock.KeyEvent.prototype */
|
|
35
|
+
{
|
|
36
|
+
keyCode: 0,
|
|
37
|
+
altKey: false,
|
|
38
|
+
ctrlKey: false,
|
|
39
|
+
shiftKey: false,
|
|
40
|
+
metaKey: false
|
|
41
|
+
});
|
|
42
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// ========================================================================
|
|
2
|
+
// SproutCore
|
|
3
|
+
// copyright 2006-2007 Sprout Systems, Inc.
|
|
4
|
+
// ========================================================================
|
|
5
|
+
|
|
6
|
+
require('Core') ;
|
|
7
|
+
|
|
8
|
+
// This object can generate HTML DOM elements from a hash-based description of
|
|
9
|
+
// the nodes. See the NodeDescriptor wiki page for complete docs.
|
|
10
|
+
//
|
|
11
|
+
// See https://wiki.sproutit.com/engineering/show/NodeDescriptor
|
|
12
|
+
//
|
|
13
|
+
SC.NodeDescriptor = {
|
|
14
|
+
create: function(descriptor, opts) {
|
|
15
|
+
if (!opts) opts = {} ;
|
|
16
|
+
// collect info from descriptor
|
|
17
|
+
var tag = opts.tag || descriptor.tag || 'div' ;
|
|
18
|
+
var className = opts.cssClass || descriptor.cssClass ;
|
|
19
|
+
var elementId = opts.id || descriptor.id ;
|
|
20
|
+
var style = opts.style || descriptor.style ;
|
|
21
|
+
var innerHTML = opts.innerHTML || descriptor.innerHTML ;
|
|
22
|
+
if (!innerHTML) {
|
|
23
|
+
var childNodes = opts.childNodes || descriptor.childNodes ;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// create element
|
|
27
|
+
var ret = $(document.createElement(tag)) ;
|
|
28
|
+
if (className) ret.className = className ;
|
|
29
|
+
if (elementId) ret.id = elementId ;
|
|
30
|
+
if (style) {
|
|
31
|
+
for (var name in style) element.style[name.camelize()] = style[name];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// apply extra attributes
|
|
35
|
+
for(var attr in descriptor) {
|
|
36
|
+
if (this.ignoredProperties.indexOf(attr) == -1) {
|
|
37
|
+
ret.setAttribute(attr,descriptor[attr]) ;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// build child nodes, if they exist.
|
|
42
|
+
if (innerHTML) {
|
|
43
|
+
ret.innerHTML = innerHTML ;
|
|
44
|
+
} else if (childNodes) {
|
|
45
|
+
var that = this ;
|
|
46
|
+
childNodes.each(function(desc) {
|
|
47
|
+
ret.appendChild(that.create(desc)) ;
|
|
48
|
+
}) ;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return ret ;
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
ignoredProperties: ['tag','cssClass','id','style','childNodes','innerHTML']
|
|
55
|
+
}
|
|
56
|
+
|