sproutcore 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,357 @@
|
|
1
|
+
// ========================================================================
|
2
|
+
// SproutCore
|
3
|
+
// copyright 2006-2007 Sprout Systems, Inc.
|
4
|
+
// ========================================================================
|
5
|
+
|
6
|
+
// Extensions to the Date object. Comes from JavaScript Toolbox at:
|
7
|
+
// http://www.mattkruse.com/javascript/date/source.html
|
8
|
+
|
9
|
+
// ------------------------------------------------------------------
|
10
|
+
// These functions use the same 'format' strings as the
|
11
|
+
// java.text.SimpleDateFormat class, with minor exceptions.
|
12
|
+
// The format string consists of the following abbreviations:
|
13
|
+
//
|
14
|
+
// Field | Full Form | Short Form
|
15
|
+
// -------------+--------------------+-----------------------
|
16
|
+
// Year | yyyy (4 digits) | yy (2 digits), y (2 or 4 digits)
|
17
|
+
// Month | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
|
18
|
+
// | NNN (abbr.) |
|
19
|
+
// Day of Month | dd (2 digits) | d (1 or 2 digits)
|
20
|
+
// Day of Week | EE (name) | E (abbr)
|
21
|
+
// Hour (1-12) | hh (2 digits) | h (1 or 2 digits)
|
22
|
+
// Hour (0-23) | HH (2 digits) | H (1 or 2 digits)
|
23
|
+
// Hour (0-11) | KK (2 digits) | K (1 or 2 digits)
|
24
|
+
// Hour (1-24) | kk (2 digits) | k (1 or 2 digits)
|
25
|
+
// Minute | mm (2 digits) | m (1 or 2 digits)
|
26
|
+
// Second | ss (2 digits) | s (1 or 2 digits)
|
27
|
+
// AM/PM | a |
|
28
|
+
//
|
29
|
+
// NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!
|
30
|
+
// Examples:
|
31
|
+
// "MMM d, y" matches: January 01, 2000
|
32
|
+
// Dec 1, 1900
|
33
|
+
// Nov 20, 00
|
34
|
+
// "M/d/yy" matches: 01/20/00
|
35
|
+
// 9/2/00
|
36
|
+
// "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
|
37
|
+
// ------------------------------------------------------------------
|
38
|
+
|
39
|
+
var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
|
40
|
+
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
|
41
|
+
function LZ(x) {return(x<0||x>9?"":"0")+x;}
|
42
|
+
|
43
|
+
Object.extend(Date,{
|
44
|
+
|
45
|
+
// returns the current time as an offset
|
46
|
+
now: function() {
|
47
|
+
return new Date().getTime() ;
|
48
|
+
},
|
49
|
+
|
50
|
+
// ------------------------------------------------------------------
|
51
|
+
// isDate ( date_string, format_string )
|
52
|
+
// Returns true if date string matches format of format string and
|
53
|
+
// is a valid date. Else returns false.
|
54
|
+
// It is recommended that you trim whitespace around the value before
|
55
|
+
// passing it to this function, as whitespace is NOT ignored!
|
56
|
+
// ------------------------------------------------------------------
|
57
|
+
isDate: function(val,format) {
|
58
|
+
var date = Date.getDateFromFormat(val,format);
|
59
|
+
if (date==0) { return false; }
|
60
|
+
return true;
|
61
|
+
},
|
62
|
+
|
63
|
+
// -------------------------------------------------------------------
|
64
|
+
// compareDates(date1,date1format,date2,date2format)
|
65
|
+
// Compare two date strings to see which is greater.
|
66
|
+
// Returns:
|
67
|
+
// 1 if date1 is greater than date2
|
68
|
+
// 0 if date2 is greater than date1 of if they are the same
|
69
|
+
// -1 if either of the dates is in an invalid format
|
70
|
+
// -------------------------------------------------------------------
|
71
|
+
compareDates: function(date1,dateformat1,date2,dateformat2) {
|
72
|
+
var d1= Date.getDateFromFormat(date1,dateformat1);
|
73
|
+
var d2= Date.getDateFromFormat(date2,dateformat2);
|
74
|
+
if (d1==0 || d2==0) {
|
75
|
+
return -1;
|
76
|
+
}
|
77
|
+
else if (d1 > d2) {
|
78
|
+
return 1;
|
79
|
+
}
|
80
|
+
return 0;
|
81
|
+
},
|
82
|
+
|
83
|
+
// ------------------------------------------------------------------
|
84
|
+
// getDateFromFormat( date_string , format_string )
|
85
|
+
//
|
86
|
+
// This function takes a date string and a format string. It matches
|
87
|
+
// If the date string matches the format string, it returns the
|
88
|
+
// getTime() of the date. If it does not match, it returns 0.
|
89
|
+
// ------------------------------------------------------------------
|
90
|
+
getDateFromFormat: function(val,format) {
|
91
|
+
val=val+"";
|
92
|
+
format=format+"";
|
93
|
+
var i_val=0;
|
94
|
+
var i_format=0;
|
95
|
+
var c="";
|
96
|
+
var token="";
|
97
|
+
var token2="";
|
98
|
+
var x,y;
|
99
|
+
var now=new Date();
|
100
|
+
var year=now.getYear();
|
101
|
+
var month=now.getMonth()+1;
|
102
|
+
var date=1;
|
103
|
+
var hh=now.getHours();
|
104
|
+
var mm=now.getMinutes();
|
105
|
+
var ss=now.getSeconds();
|
106
|
+
var ampm="";
|
107
|
+
|
108
|
+
while (i_format < format.length) {
|
109
|
+
// Get next token from format string
|
110
|
+
c=format.charAt(i_format);
|
111
|
+
token="";
|
112
|
+
while ((format.charAt(i_format)==c) && (i_format < format.length)) {
|
113
|
+
token += format.charAt(i_format++);
|
114
|
+
}
|
115
|
+
// Extract contents of value based on format token
|
116
|
+
if (token=="yyyy" || token=="yy" || token=="y") {
|
117
|
+
if (token=="yyyy") { x=4;y=4; }
|
118
|
+
if (token=="yy") { x=2;y=2; }
|
119
|
+
if (token=="y") { x=2;y=4; }
|
120
|
+
year=Date._getInt(val,i_val,x,y);
|
121
|
+
if (year==null) { return 0; }
|
122
|
+
i_val += year.length;
|
123
|
+
if (year.length==2) {
|
124
|
+
if (year > 70) { year=1900+(year-0); }
|
125
|
+
else { year=2000+(year-0); }
|
126
|
+
}
|
127
|
+
}
|
128
|
+
else if (token=="MMM"||token=="NNN"){
|
129
|
+
month=0;
|
130
|
+
for (var i=0; i<MONTH_NAMES.length; i++) {
|
131
|
+
var month_name=MONTH_NAMES[i];
|
132
|
+
if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
|
133
|
+
if (token=="MMM"||(token=="NNN"&&i>11)) {
|
134
|
+
month=i+1;
|
135
|
+
if (month>12) { month -= 12; }
|
136
|
+
i_val += month_name.length;
|
137
|
+
break;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
}
|
141
|
+
if ((month < 1)||(month>12)){return 0;}
|
142
|
+
}
|
143
|
+
else if (token=="EE"||token=="E"){
|
144
|
+
for (var i=0; i<DAY_NAMES.length; i++) {
|
145
|
+
var day_name=DAY_NAMES[i];
|
146
|
+
if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
|
147
|
+
i_val += day_name.length;
|
148
|
+
break;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
else if (token=="MM"||token=="M") {
|
153
|
+
month=Date._getInt(val,i_val,token.length,2);
|
154
|
+
if(month==null||(month<1)||(month>12)){return 0;}
|
155
|
+
i_val+=month.length;}
|
156
|
+
else if (token=="dd"||token=="d") {
|
157
|
+
date=Date._getInt(val,i_val,token.length,2);
|
158
|
+
if(date==null||(date<1)||(date>31)){return 0;}
|
159
|
+
i_val+=date.length;}
|
160
|
+
else if (token=="hh"||token=="h") {
|
161
|
+
hh=Date._getInt(val,i_val,token.length,2);
|
162
|
+
if(hh==null||(hh<1)||(hh>12)){return 0;}
|
163
|
+
i_val+=hh.length;}
|
164
|
+
else if (token=="HH"||token=="H") {
|
165
|
+
hh=Date._getInt(val,i_val,token.length,2);
|
166
|
+
if(hh==null||(hh<0)||(hh>23)){return 0;}
|
167
|
+
i_val+=hh.length;}
|
168
|
+
else if (token=="KK"||token=="K") {
|
169
|
+
hh=Date._getInt(val,i_val,token.length,2);
|
170
|
+
if(hh==null||(hh<0)||(hh>11)){return 0;}
|
171
|
+
i_val+=hh.length;}
|
172
|
+
else if (token=="kk"||token=="k") {
|
173
|
+
hh=Date._getInt(val,i_val,token.length,2);
|
174
|
+
if(hh==null||(hh<1)||(hh>24)){return 0;}
|
175
|
+
i_val+=hh.length;hh--;}
|
176
|
+
else if (token=="mm"||token=="m") {
|
177
|
+
mm=Date._getInt(val,i_val,token.length,2);
|
178
|
+
if(mm==null||(mm<0)||(mm>59)){return 0;}
|
179
|
+
i_val+=mm.length;}
|
180
|
+
else if (token=="ss"||token=="s") {
|
181
|
+
ss=Date._getInt(val,i_val,token.length,2);
|
182
|
+
if(ss==null||(ss<0)||(ss>59)){return 0;}
|
183
|
+
i_val+=ss.length;}
|
184
|
+
else if (token=="a") {
|
185
|
+
if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
|
186
|
+
else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
|
187
|
+
else {return 0;}
|
188
|
+
i_val+=2;}
|
189
|
+
else {
|
190
|
+
if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
|
191
|
+
else {i_val+=token.length;}
|
192
|
+
}
|
193
|
+
}
|
194
|
+
// If there are any trailing characters left in the value, it doesn't match
|
195
|
+
if (i_val != val.length) { return 0; }
|
196
|
+
// Is date valid for month?
|
197
|
+
if (month==2) {
|
198
|
+
// Check for leap year
|
199
|
+
if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
|
200
|
+
if (date > 29){ return 0; }
|
201
|
+
}
|
202
|
+
else { if (date > 28) { return 0; } }
|
203
|
+
}
|
204
|
+
if ((month==4)||(month==6)||(month==9)||(month==11)) {
|
205
|
+
if (date > 30) { return 0; }
|
206
|
+
}
|
207
|
+
// Correct hours value
|
208
|
+
if (hh<12 && ampm=="PM") { hh=hh-0+12; }
|
209
|
+
else if (hh>11 && ampm=="AM") { hh-=12; }
|
210
|
+
var newdate=new Date(year,month-1,date,hh,mm,ss);
|
211
|
+
return newdate.getTime();
|
212
|
+
},
|
213
|
+
|
214
|
+
// ------------------------------------------------------------------
|
215
|
+
// parseDate( date_string [, prefer_euro_format] )
|
216
|
+
//
|
217
|
+
// This function takes a date string and tries to match it to a
|
218
|
+
// number of possible date formats to get the value. It will try to
|
219
|
+
// match against the following international formats, in this order:
|
220
|
+
// y-M-d MMM d, y MMM d,y y-MMM-d d-MMM-y MMM d
|
221
|
+
// M/d/y M-d-y M.d.y MMM-d M/d M-d
|
222
|
+
// d/M/y d-M-y d.M.y d-MMM d/M d-M
|
223
|
+
//
|
224
|
+
// Also understands:
|
225
|
+
//
|
226
|
+
// yesterday, today, tomorrow, now
|
227
|
+
//
|
228
|
+
// A second argument may be passed to instruct the method to search
|
229
|
+
// for formats like d/M/y (european format) before M/d/y (American).
|
230
|
+
// Returns a Date object or null if no patterns match.
|
231
|
+
// ------------------------------------------------------------------
|
232
|
+
parseDate: function(val) {
|
233
|
+
var preferEuro=(arguments.length==2)?arguments[1]:false;
|
234
|
+
generalFormats=new Array('E NNN dd HH:mm:ss UTC yyyy','y-M-d','y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d','d MMM y','d.MMM.y','y MMM d','y.MMM.d');
|
235
|
+
monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
|
236
|
+
dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
|
237
|
+
var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
|
238
|
+
var d=null;
|
239
|
+
|
240
|
+
// first look for natural language
|
241
|
+
d = 0 ; var now = new Date().getTime() ;
|
242
|
+
switch(val.toLowerCase()) {
|
243
|
+
case 'yesterday'.loc():
|
244
|
+
d = now - (24*60*60*1000) ;
|
245
|
+
break ;
|
246
|
+
case 'today'.loc():
|
247
|
+
case 'now'.loc():
|
248
|
+
d = now ;
|
249
|
+
break ;
|
250
|
+
case 'tomorrow'.loc():
|
251
|
+
d = now + (24*60*60*1000) ;
|
252
|
+
break;
|
253
|
+
}
|
254
|
+
if (d>0) return new Date(d) ;
|
255
|
+
|
256
|
+
for (var i=0; i<checkList.length; i++) {
|
257
|
+
var l=window[checkList[i]];
|
258
|
+
for (var j=0; j<l.length; j++) {
|
259
|
+
d=Date.getDateFromFormat(val,l[j]);
|
260
|
+
if (d==0) d = Date.getDateFromFormat(val,l[j] + ' H:m:s') ;
|
261
|
+
if (d==0) d = Date.getDateFromFormat(val,l[j] + ' h:m:s a') ;
|
262
|
+
if (d!=0) return new Date(d);
|
263
|
+
}
|
264
|
+
}
|
265
|
+
return null;
|
266
|
+
},
|
267
|
+
|
268
|
+
// ------------------------------------------------------------------
|
269
|
+
// Utility functions for parsing in getDateFromFormat()
|
270
|
+
// ------------------------------------------------------------------
|
271
|
+
_isInteger: function(val) {
|
272
|
+
var digits="1234567890";
|
273
|
+
for (var i=0; i < val.length; i++) {
|
274
|
+
if (digits.indexOf(val.charAt(i))==-1) { return false; }
|
275
|
+
}
|
276
|
+
return true;
|
277
|
+
},
|
278
|
+
|
279
|
+
_getInt: function(str,i,minlength,maxlength) {
|
280
|
+
for (var x=maxlength; x>=minlength; x--) {
|
281
|
+
var token=str.substring(i,i+x);
|
282
|
+
if (token.length < minlength) { return null; }
|
283
|
+
if (Date._isInteger(token)) { return token; }
|
284
|
+
}
|
285
|
+
return null;
|
286
|
+
}
|
287
|
+
|
288
|
+
}) ;
|
289
|
+
|
290
|
+
Object.extend(Date.prototype, {
|
291
|
+
|
292
|
+
// ------------------------------------------------------------------
|
293
|
+
// formatDate (date_object, format, naturalLanguage)
|
294
|
+
// Returns a date in the output format specified.
|
295
|
+
// The format string uses the same abbreviations as in getDateFromFormat()
|
296
|
+
//
|
297
|
+
// ------------------------------------------------------------------
|
298
|
+
format: function(format) {
|
299
|
+
format=format+"";
|
300
|
+
var date = this ;
|
301
|
+
var result="";
|
302
|
+
var i_format=0;
|
303
|
+
var c="";
|
304
|
+
var token="";
|
305
|
+
var y=date.getYear()+"";
|
306
|
+
var M=date.getMonth()+1;
|
307
|
+
var d=date.getDate();
|
308
|
+
var E=date.getDay();
|
309
|
+
var H=date.getHours();
|
310
|
+
var m=date.getMinutes();
|
311
|
+
var s=date.getSeconds();
|
312
|
+
var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
|
313
|
+
// Convert real date parts into formatted versions
|
314
|
+
var value=new Object();
|
315
|
+
if (y.length < 4) {y=""+(y-0+1900);}
|
316
|
+
value["y"]=""+y;
|
317
|
+
value["yyyy"]=y;
|
318
|
+
value["yy"]=y.substring(2,4);
|
319
|
+
value["M"]=M;
|
320
|
+
value["MM"]=LZ(M);
|
321
|
+
value["MMM"]=MONTH_NAMES[M-1];
|
322
|
+
value["NNN"]=MONTH_NAMES[M+11];
|
323
|
+
value["d"]=d;
|
324
|
+
value["dd"]=LZ(d);
|
325
|
+
value["E"]=DAY_NAMES[E+7];
|
326
|
+
value["EE"]=DAY_NAMES[E];
|
327
|
+
value["H"]=H;
|
328
|
+
value["HH"]=LZ(H);
|
329
|
+
if (H==0){value["h"]=12;}
|
330
|
+
else if (H>12){value["h"]=H-12;}
|
331
|
+
else {value["h"]=H;}
|
332
|
+
value["hh"]=LZ(value["h"]);
|
333
|
+
if (H>11){value["K"]=H-12;} else {value["K"]=H;}
|
334
|
+
value["k"]=H+1;
|
335
|
+
value["KK"]=LZ(value["K"]);
|
336
|
+
value["kk"]=LZ(value["k"]);
|
337
|
+
if (H > 11) { value["a"]="PM"; }
|
338
|
+
else { value["a"]="AM"; }
|
339
|
+
value["m"]=m;
|
340
|
+
value["mm"]=LZ(m);
|
341
|
+
value["s"]=s;
|
342
|
+
value["ss"]=LZ(s);
|
343
|
+
while (i_format < format.length) {
|
344
|
+
c=format.charAt(i_format);
|
345
|
+
token="";
|
346
|
+
while ((format.charAt(i_format)==c) && (i_format < format.length)) {
|
347
|
+
token += format.charAt(i_format++);
|
348
|
+
}
|
349
|
+
if (value[token] != null) { result=result + value[token]; }
|
350
|
+
else { result=result + token; }
|
351
|
+
}
|
352
|
+
return result;
|
353
|
+
},
|
354
|
+
|
355
|
+
utcFormat: function() { return (new Date(this.getTime() + (this.getTimezoneOffset() * 60 * 1000))).format('E NNN dd HH:mm:ss UTC yyyy'); }
|
356
|
+
|
357
|
+
}) ;
|
@@ -0,0 +1,39 @@
|
|
1
|
+
// ========================================================================
|
2
|
+
// SproutCore
|
3
|
+
// copyright 2006-2007 Sprout Systems, Inc.
|
4
|
+
// ========================================================================
|
5
|
+
|
6
|
+
require('foundation/object');
|
7
|
+
|
8
|
+
// Error is used to communicate errors throughout the app.
|
9
|
+
SC.Error = SC.Object.extend({
|
10
|
+
code: -1, // error code. Used to designate type.
|
11
|
+
description: '', // human readable dscriptions.
|
12
|
+
label: null // optionally set to human readable the name of the item with the error.
|
13
|
+
}) ;
|
14
|
+
|
15
|
+
// this will create a new instance of the receiver with the passed
|
16
|
+
// description, etc.
|
17
|
+
SC.Error.desc = function(description, label, code) {
|
18
|
+
var opts = { description: description } ;
|
19
|
+
if (label !== undefined) opts.label = label ;
|
20
|
+
if (code !== undefined) opts.code = code ;
|
21
|
+
return this.create(opts) ;
|
22
|
+
} ;
|
23
|
+
|
24
|
+
// returns an error object.
|
25
|
+
function $error(description, label, c) {
|
26
|
+
return SC.Error.desc(description,label, c);
|
27
|
+
} ;
|
28
|
+
|
29
|
+
|
30
|
+
// returns true if the return value is not false or an error.
|
31
|
+
function $ok(ret) {
|
32
|
+
return (ret !== false) && ($type(ret) != T_ERROR) ;
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
// STANDARD ERROR OBJECTS
|
37
|
+
|
38
|
+
// Used by objects that do not support multiple values.
|
39
|
+
SC.Error.HAS_MULTIPLE_VALUES = -100 ;
|
@@ -0,0 +1,153 @@
|
|
1
|
+
// ========================================================================
|
2
|
+
// SproutCore
|
3
|
+
// copyright 2006-2007 Sprout Systems, Inc.
|
4
|
+
// ========================================================================
|
5
|
+
|
6
|
+
require('Core') ;
|
7
|
+
require('foundation/object') ;
|
8
|
+
|
9
|
+
// An InputManager knows how to convert incoming keyboard events and convert
|
10
|
+
// them into actions on a responder. The default version should provide the
|
11
|
+
// correct behavior for most people. However, if you want some special
|
12
|
+
// behavior, you can always write your own.
|
13
|
+
//
|
14
|
+
// An instance of this input manager is created as a property of
|
15
|
+
// SC.Responder. To overide the inputManager used for all responders, replace
|
16
|
+
// this property with your own instance. To override the inputManager used
|
17
|
+
// only for one responder, set the inputManager property on your specific
|
18
|
+
// instance.
|
19
|
+
//
|
20
|
+
// Note that generally you do not want to write your own inputManager. They
|
21
|
+
// are tricky to get right. Instead, you should implement the various handler
|
22
|
+
// methods on the responder.
|
23
|
+
SC.InputManager = SC.Object.extend({
|
24
|
+
|
25
|
+
// The is the primary entry point for the inputManager. If you override
|
26
|
+
// the input manager, have this method process the key event and invoke
|
27
|
+
// methods on the responder.
|
28
|
+
interpretKeyEvents: function(event, responder)
|
29
|
+
{
|
30
|
+
var codes = this.codesForEvent(event) ;
|
31
|
+
var cmd = codes[0]; var chr = codes[1];
|
32
|
+
if (!cmd && !chr) return false ; //nothing to do.
|
33
|
+
|
34
|
+
// if this is a command key, try to do something about it.
|
35
|
+
if (cmd)
|
36
|
+
{
|
37
|
+
var methodName = SC.MODIFIED_COMMAND_MAP[cmd] || SC.BASE_COMMAND_MAP[cmd.split('_').last()];
|
38
|
+
if (methodName && responder.respondsTo(methodName))
|
39
|
+
{
|
40
|
+
// the responder has a method matching the keybinding... call it.
|
41
|
+
return responder[methodName]( event );
|
42
|
+
}
|
43
|
+
}
|
44
|
+
if (chr && responder.respondsTo('insertText'))
|
45
|
+
{
|
46
|
+
// if we haven't returned yet and there is plain text, then do an insert of the text.
|
47
|
+
return responder.insertText(chr);
|
48
|
+
}
|
49
|
+
|
50
|
+
return false ; //nothing to do.
|
51
|
+
},
|
52
|
+
|
53
|
+
// this will get a standardized command code for the event. It returns
|
54
|
+
// null if the event is plain text, not a command code.
|
55
|
+
codesForEvent: function(e) {
|
56
|
+
var code = e.keyCode ;
|
57
|
+
var ret = null ; var key = null ;
|
58
|
+
var modifiers = '' ;
|
59
|
+
|
60
|
+
// handle function keys.
|
61
|
+
if (code) {
|
62
|
+
ret = SC.FUNCTION_KEYS[code] ;
|
63
|
+
if (!ret && (e.altKey || e.ctrlKey)) ret = SC.PRINTABLE_KEYS[code] ;
|
64
|
+
if (ret) {
|
65
|
+
if (e.altKey) modifiers += 'alt_' ;
|
66
|
+
if (e.ctrlKey) modifiers += 'ctrl_' ;
|
67
|
+
if (e.shiftKey) modifiers += 'shift_' ;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
// otherwise just go get the right key.
|
72
|
+
if (!ret) {
|
73
|
+
var code = e.charCode || e.keyCode ;
|
74
|
+
key = ret = String.fromCharCode(code) ;
|
75
|
+
var lowercase = ret.toLowerCase() ;
|
76
|
+
if (ret != lowercase) {
|
77
|
+
modifiers = 'shift_' ;
|
78
|
+
ret = lowercase ;
|
79
|
+
} else ret = null ;
|
80
|
+
}
|
81
|
+
|
82
|
+
if (ret) ret = modifiers + ret ;
|
83
|
+
return [ret, key] ;
|
84
|
+
}
|
85
|
+
|
86
|
+
});
|
87
|
+
|
88
|
+
SC.MODIFIED_COMMAND_MAP = {
|
89
|
+
'ctrl_.': 'cancel',
|
90
|
+
'shift_tab': 'insertBacktab',
|
91
|
+
'shift_left': 'moveLeftAndModifySelection',
|
92
|
+
'shift_right': 'moveRightAndModifySelection',
|
93
|
+
'shift_up': 'moveUpAndModifySelection',
|
94
|
+
'shift_down': 'moveDownAndModifySelection',
|
95
|
+
'alt_left': 'moveLeftAndModifySelection',
|
96
|
+
'alt_right': 'moveRightAndModifySelection',
|
97
|
+
'alt_up': 'moveUpAndModifySelection',
|
98
|
+
'alt_down': 'moveDownAndModifySelection',
|
99
|
+
'ctrl_a': 'selectAll'
|
100
|
+
} ;
|
101
|
+
|
102
|
+
SC.BASE_COMMAND_MAP = {
|
103
|
+
'escape': 'cancel',
|
104
|
+
'backspace': 'deleteBackward',
|
105
|
+
'delete': 'deleteForward',
|
106
|
+
'return': 'insertNewline',
|
107
|
+
'tab': 'insertTab',
|
108
|
+
'left': 'moveLeft',
|
109
|
+
'right': 'moveRight',
|
110
|
+
'up': 'moveUp',
|
111
|
+
'down': 'moveDown',
|
112
|
+
'home': 'moveToBeginningOfDocument',
|
113
|
+
'end': 'moveToEndOfDocument',
|
114
|
+
'pagedown': 'pageDown',
|
115
|
+
'pageup': 'pageUp'
|
116
|
+
} ;
|
117
|
+
|
118
|
+
SC.MODIFIER_KEYS = {
|
119
|
+
16:'shift', 17:'ctrl', 18: 'alt'
|
120
|
+
};
|
121
|
+
|
122
|
+
SC.FUNCTION_KEYS = {
|
123
|
+
8: 'backspace', 9: 'tab', 13: 'return', 19: 'pause', 27: 'escape',
|
124
|
+
32: 'space', 33: 'pageup', 34: 'pagedown', 35: 'end', 36: 'home',
|
125
|
+
37: 'left', 38: 'up', 39: 'right', 40: 'down', 44: 'printscreen',
|
126
|
+
45: 'insert', 46: 'delete', 112: 'f1', 113: 'f2', 114: 'f3', 115: 'f4',
|
127
|
+
116: 'f5', 117: 'f7', 119: 'f8', 120: 'f9', 121: 'f10', 122: 'f11',
|
128
|
+
123: 'f12', 144: 'numlock', 145: 'scrolllock'
|
129
|
+
} ;
|
130
|
+
|
131
|
+
SC.PRINTABLE_KEYS = {
|
132
|
+
48:"0", 49:"1", 50:"2", 51:"3", 52:"4", 53:"5", 54:"6", 55:"7", 56:"8",
|
133
|
+
57:"9", 59:";", 61:"=", 65:"a", 66:"b", 67:"c", 68:"d", 69:"e", 70:"f",
|
134
|
+
71:"g", 72:"h", 73:"i", 74:"j", 75:"k", 76:"l", 77:"m", 78:"n", 79:"o",
|
135
|
+
80:"p", 81:"q", 82:"r", 83:"s", 84:"t", 85:"u", 86:"v", 87:"w", 88:"x",
|
136
|
+
89:"y", 90:"z", 107:"+", 109:"-", 110:".", 188:",", 190:".", 191:"/",
|
137
|
+
192:"`", 219:"[", 220:"\\", 221:"]", 222:"\""
|
138
|
+
} ;
|
139
|
+
|
140
|
+
// make reverse keycode lookup for using in unit tests...
|
141
|
+
SC.KEY_CODES = {};
|
142
|
+
for (var i=0, n=256; i < n; i++)
|
143
|
+
{
|
144
|
+
if (SC.MODIFIER_KEYS[i] !== undefined) {
|
145
|
+
SC.KEY_CODES[ SC.MODIFIER_KEYS[i] ] = i;
|
146
|
+
} else if (SC.FUNCTION_KEYS[i] !== undefined) {
|
147
|
+
SC.KEY_CODES[ SC.FUNCTION_KEYS[i] ] = i;
|
148
|
+
} else if (SC.PRINTABLE_KEYS[i] !== undefined) {
|
149
|
+
SC.KEY_CODES[ SC.PRINTABLE_KEYS[i] ] = i;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
|