ninjs 0.9.2 → 0.10.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 (159) hide show
  1. data/.bundle/config +2 -0
  2. data/Gemfile +17 -0
  3. data/Gemfile.lock +38 -0
  4. data/README.textile +1 -1
  5. data/Rakefile +60 -0
  6. data/VERSION +1 -0
  7. data/lib/ninjs.rb +0 -1
  8. data/lib/ninjs/command.rb +16 -1
  9. data/lib/ninjs/manifest.rb +1 -1
  10. data/lib/ninjs/project.rb +74 -91
  11. data/ninjs.gemspec +305 -104
  12. data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/jquery.easing-1.3.pack.js +72 -0
  13. data/repository/jquery/fancybox/assets/1.3.1/scss/fancybox.scss +69 -0
  14. data/repository/jquery/ui/1.8.7.js +783 -0
  15. data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.accordion.css +19 -0
  16. data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.all.css +11 -0
  17. data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.autocomplete.css +53 -0
  18. data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.base.css +11 -0
  19. data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.button.css +38 -0
  20. data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.core.css +41 -0
  21. data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.datepicker.css +68 -0
  22. data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.dialog.css +21 -0
  23. data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.progressbar.css +11 -0
  24. data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.resizable.css +20 -0
  25. data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.selectable.css +10 -0
  26. data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.slider.css +24 -0
  27. data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.tabs.css +18 -0
  28. data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.theme.css +252 -0
  29. data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  30. data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_flat_75_ffffff_40x100.png +0 -0
  31. data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  32. data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_glass_65_ffffff_1x400.png +0 -0
  33. data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_glass_75_dadada_1x400.png +0 -0
  34. data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  35. data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  36. data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  37. data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-icons_222222_256x240.png +0 -0
  38. data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-icons_2e83ff_256x240.png +0 -0
  39. data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-icons_454545_256x240.png +0 -0
  40. data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-icons_888888_256x240.png +0 -0
  41. data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-icons_cd0a0a_256x240.png +0 -0
  42. data/repository/jquery/ui/latest.js +1 -0
  43. data/repository/ninjs/core/.core.pdoc.yaml +0 -0
  44. data/repository/ninjs/core/.existence.pdoc.yaml +12 -0
  45. data/repository/ninjs/core/.extend.pdoc.yaml +0 -0
  46. data/repository/ninjs/core/.nin.pdoc.yaml +0 -0
  47. data/repository/ninjs/core/application.js +43 -0
  48. data/repository/ninjs/core/existence.js +221 -11
  49. data/repository/ninjs/core/extend.js +18 -0
  50. data/repository/ninjs/core/module.js +230 -0
  51. data/repository/ninjs/core/nin.js +3 -137
  52. data/repository/ninjs/docs/Data/ClassHierarchy.nd +0 -0
  53. data/repository/ninjs/docs/Data/ConfigFileInfo.nd +0 -0
  54. data/repository/ninjs/docs/Data/FileInfo.nd +16 -0
  55. data/repository/ninjs/docs/Data/ImageFileInfo.nd +0 -0
  56. data/repository/ninjs/docs/Data/ImageReferenceTable.nd +0 -0
  57. data/repository/ninjs/docs/Data/IndexInfo.nd +0 -0
  58. data/repository/ninjs/docs/Data/PreviousMenuState.nd +0 -0
  59. data/repository/ninjs/docs/Data/PreviousSettings.nd +0 -0
  60. data/repository/ninjs/docs/Data/SymbolTable.nd +0 -0
  61. data/repository/ninjs/docs/Languages.txt +113 -0
  62. data/repository/ninjs/docs/Menu.txt +63 -0
  63. data/repository/ninjs/docs/Topics.txt +81 -0
  64. data/repository/ninjs/docs/files/core/application-js.html +44 -0
  65. data/repository/ninjs/docs/files/core/existence-js.html +60 -0
  66. data/repository/ninjs/docs/files/core/extend-js.html +46 -0
  67. data/repository/ninjs/docs/files/core/module-js.html +80 -0
  68. data/repository/ninjs/docs/files/core/nin-js.html +38 -0
  69. data/repository/ninjs/docs/files/existence-js.html +54 -0
  70. data/repository/ninjs/docs/index.html +1 -0
  71. data/repository/ninjs/docs/index/Classes.html +33 -0
  72. data/repository/ninjs/docs/index/Files.html +45 -0
  73. data/repository/ninjs/docs/index/Functions.html +57 -0
  74. data/repository/ninjs/docs/index/General.html +77 -0
  75. data/repository/ninjs/docs/index/Variables.html +45 -0
  76. data/repository/ninjs/docs/javascript/main.js +841 -0
  77. data/repository/ninjs/docs/javascript/prettify.js +1526 -0
  78. data/repository/ninjs/docs/javascript/searchdata.js +152 -0
  79. data/repository/ninjs/docs/search/ClassesN.html +20 -0
  80. data/repository/ninjs/docs/search/FilesA.html +20 -0
  81. data/repository/ninjs/docs/search/FilesE.html +20 -0
  82. data/repository/ninjs/docs/search/FilesM.html +20 -0
  83. data/repository/ninjs/docs/search/FilesN.html +20 -0
  84. data/repository/ninjs/docs/search/FunctionsA.html +20 -0
  85. data/repository/ninjs/docs/search/FunctionsC.html +20 -0
  86. data/repository/ninjs/docs/search/FunctionsE.html +20 -0
  87. data/repository/ninjs/docs/search/FunctionsI.html +20 -0
  88. data/repository/ninjs/docs/search/FunctionsM.html +20 -0
  89. data/repository/ninjs/docs/search/FunctionsR.html +20 -0
  90. data/repository/ninjs/docs/search/FunctionsS.html +20 -0
  91. data/repository/ninjs/docs/search/GeneralA.html +20 -0
  92. data/repository/ninjs/docs/search/GeneralC.html +20 -0
  93. data/repository/ninjs/docs/search/GeneralD.html +20 -0
  94. data/repository/ninjs/docs/search/GeneralE.html +20 -0
  95. data/repository/ninjs/docs/search/GeneralF.html +20 -0
  96. data/repository/ninjs/docs/search/GeneralI.html +20 -0
  97. data/repository/ninjs/docs/search/GeneralM.html +20 -0
  98. data/repository/ninjs/docs/search/GeneralN.html +20 -0
  99. data/repository/ninjs/docs/search/GeneralR.html +20 -0
  100. data/repository/ninjs/docs/search/GeneralS.html +20 -0
  101. data/repository/ninjs/docs/search/GeneralT.html +20 -0
  102. data/repository/ninjs/docs/search/GeneralV.html +20 -0
  103. data/repository/ninjs/docs/search/NoResults.html +15 -0
  104. data/repository/ninjs/docs/search/VariablesD.html +20 -0
  105. data/repository/ninjs/docs/search/VariablesN.html +20 -0
  106. data/repository/ninjs/docs/search/VariablesR.html +20 -0
  107. data/repository/ninjs/docs/search/VariablesT.html +20 -0
  108. data/repository/ninjs/docs/styles/main.css +828 -0
  109. data/repository/ninjs/docs/styles/mystyles.css +828 -0
  110. data/repository/ninjs/tests/index.html +6 -6
  111. data/repository/ninjs/tests/ninjs.test.js +94 -43
  112. data/repository/ninjs/tests/ninjs.utilities.test.js +6 -18
  113. data/repository/ninjs/tests/qunit/qunit.css +197 -0
  114. data/repository/ninjs/tests/qunit/qunit.js +1415 -0
  115. data/repository/ninjs/utilities/all.js +2 -1
  116. data/repository/ninjs/utilities/array.js +3 -3
  117. data/repository/ninjs/utilities/cookie.js +0 -0
  118. data/repository/ninjs/utilities/number.js +2 -2
  119. data/repository/ninjs/utilities/string.js +3 -3
  120. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCore.css +226 -0
  121. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreDefault.css +328 -0
  122. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreDjango.css +331 -0
  123. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreEclipse.css +339 -0
  124. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreEmacs.css +324 -0
  125. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreFadeToGrey.css +328 -0
  126. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreMDUltra.css +324 -0
  127. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreMidnight.css +324 -0
  128. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreRDark.css +324 -0
  129. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeDefault.css +117 -0
  130. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeDjango.css +120 -0
  131. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeEclipse.css +128 -0
  132. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeEmacs.css +113 -0
  133. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeFadeToGrey.css +117 -0
  134. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeMDUltra.css +113 -0
  135. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeMidnight.css +113 -0
  136. data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeRDark.css +113 -0
  137. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCore.scss +216 -0
  138. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreDefault.scss +2 -0
  139. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreDjango.scss +2 -0
  140. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreEclipse.scss +2 -0
  141. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreEmacs.scss +2 -0
  142. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreFadeToGrey.scss +2 -0
  143. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreMDUltra.scss +2 -0
  144. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreMidnight.scss +2 -0
  145. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreRDark.scss +2 -0
  146. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeDefault.scss +7 -0
  147. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeDjango.scss +36 -0
  148. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeEclipse.scss +48 -0
  149. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeEmacs.scss +32 -0
  150. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeFadeToGrey.scss +36 -0
  151. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeMDUltra.scss +32 -0
  152. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeMidnight.scss +32 -0
  153. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeRDark.scss +32 -0
  154. data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_theme_template.scss +120 -0
  155. data/repository/syntaxhighlighter/default.js +2 -1
  156. data/repository/syntaxhighlighter/shBrushAppleScript.js +1 -1
  157. data/repository/syntaxhighlighter/shBrushPerl.js +1 -1
  158. data/repository/syntaxhighlighter/shBrushPhp.js +4 -4
  159. metadata +317 -33
@@ -0,0 +1 @@
1
+ //= require "1.8.7"
File without changes
@@ -0,0 +1,12 @@
1
+ ---
2
+ id: "is_defined"
3
+ type: class method
4
+ line_number: 5
5
+ description: |
6
+
7
+
8
+ signatures:
9
+ -
10
+ signature: ".is_defined(suspect)"
11
+ return_value: "Any"
12
+ file: /Volumes/Storage/Development/ninjs/repository/ninjs/core/existence.js
File without changes
File without changes
@@ -0,0 +1,43 @@
1
+ /*
2
+ File: application.js
3
+
4
+ Class: NinjsApplication
5
+ An NinjsApplication object serves as your application's namespace and includes a utility to add modules to the application object.
6
+
7
+ See Also:
8
+ <NinjsModule>
9
+ */
10
+ var NinjsApplication = function() {
11
+ if (is_undefined(window._)) {
12
+ window._ = this;
13
+ }
14
+
15
+ if (is_undefined(window.app)) {
16
+ window.app = this;
17
+ }
18
+ };
19
+
20
+ /*
21
+ Method: add_module
22
+ Adds a NinjsModule to the application.
23
+
24
+ Parameters:
25
+ name - the name of the module
26
+
27
+ > myapp.add_module('my_module');
28
+ */
29
+ NinjsApplication.method('add_module', function(name) {
30
+ try {
31
+ if (is_undefined(name)) {
32
+ throw new SyntaxError("NinjsApplication.add_module(name): name is undefined");
33
+ }
34
+
35
+ if (is_defined(this[name])) {
36
+ throw new SyntaxError("NinjsApplication.add_module(name): '" + name + "' already declared");
37
+ }
38
+ this[name] = new NinjsModule(name);
39
+ }
40
+ catch(error) {
41
+ alert(error.message);
42
+ }
43
+ });
@@ -1,26 +1,75 @@
1
+ /* File: existence.js */
1
2
  if (is_defined === undefined) {
2
- var is_defined = function(variable) {
3
- return (variable === undefined) ? false : true;
3
+ /*
4
+ Function: is_defined
5
+ Checks if a variable is undefined.
6
+
7
+ Parameters:
8
+ suspect - suspect variable to test
9
+
10
+ Returns:
11
+ bool
12
+
13
+ See Also:
14
+
15
+ <is_undefined>
16
+ */
17
+ var is_defined = function(suspect) {
18
+ return (suspect === undefined) ? false : true;
4
19
  };
5
20
  }
6
21
 
7
22
  if (!is_defined(is_undefined)) {
8
- var is_undefined = function(variable) {
9
- return (variable === undefined) ? true : false;
23
+ /*
24
+ Function: is_undefined
25
+ Checks if a variable is defined.
26
+
27
+ Parameters:
28
+ suspect - suspect variable to test
29
+
30
+ Returns:
31
+ bool
32
+
33
+ See Also:
34
+
35
+ <is_defined>
36
+ */
37
+ var is_undefined = function(suspect) {
38
+ return (suspect === undefined) ? true : false;
10
39
  };
11
40
  }
12
41
 
13
42
  if (is_undefined(is_typeof)) {
14
- var is_typeof = function(type, variable) {
43
+ /*
44
+ Function: is_typeof
45
+ Determine an object's type strictly by comparing constructors.
46
+
47
+ Parameters:
48
+ type - The type you expect (ie. String, Number, Array without quotes: is_typeof(String, 'hello'): // true)
49
+ suspect - The variable to check against type
50
+
51
+ Returns:
52
+ bool
53
+
54
+ See Also:
55
+ <is_numeric>,
56
+ <is_string>,
57
+ <is_array>,
58
+ <is_number>,
59
+ <is_date>,
60
+ <is_bool>,
61
+ <is_regex>
62
+ */
63
+ var is_typeof = function(type, suspect) {
15
64
  try {
16
65
  if (is_undefined(type)) {
17
- throw new SyntaxError("is_typeof(Type, variable): type is undefined");
66
+ throw new SyntaxError("is_typeof(Type, suspect): type is undefined");
18
67
  }
19
- if (is_undefined(variable)) {
20
- throw new SyntaxError("is_typeof(Type, variable): variable is undefined");
68
+ if (is_undefined(suspect)) {
69
+ throw new SyntaxError("is_typeof(Type, suspect): suspect is undefined");
21
70
  }
22
71
 
23
- return (variable.constructor == type) ? true : false;
72
+ return (suspect.constructor == type) ? true : false;
24
73
  }
25
74
  catch(error) {
26
75
  alert(error.message);
@@ -28,8 +77,21 @@ if (is_undefined(is_typeof)) {
28
77
  };
29
78
  }
30
79
 
31
- if (is_undefined(is_mumeric)) {
32
- var is_mumeric = function(suspect) {
80
+ if (is_undefined(is_numeric)) {
81
+ /*
82
+ Function: is_numeric
83
+ Determine if the suspect string represents a numeric value.
84
+
85
+ Parameters:
86
+ suspect - variable to check for numeric value
87
+
88
+ Returns:
89
+ bool
90
+
91
+ See Also:
92
+ <is_number>
93
+ */
94
+ var is_numeric = function(suspect) {
33
95
  if(is_typeof(Number, suspect)) {
34
96
  return true;
35
97
  }
@@ -39,3 +101,151 @@ if (is_undefined(is_mumeric)) {
39
101
  }
40
102
  };
41
103
  }
104
+
105
+ if (is_undefined(is_string)) {
106
+ /*
107
+ Function: is_string
108
+ Determine the suspect is a String. This is a proxy method for is_typeof(String, suspect).
109
+
110
+ Parameters:
111
+ suspect - supect variable to test
112
+
113
+ Returns:
114
+ bool
115
+
116
+ See Also:
117
+ <is_typeof>,
118
+ <is_numeric>,
119
+ <is_array>,
120
+ <is_number>,
121
+ <is_date>,
122
+ <is_bool>,
123
+ <is_regex>
124
+ */
125
+ var is_string = function(suspect) {
126
+ return is_typeof(String, suspect);
127
+ };
128
+ }
129
+
130
+ if (is_undefined(is_array)) {
131
+ /*
132
+ Function: is_array
133
+ Determine if the suspect is an Array. This is a proxy method for is_typeof(Array, suspect).
134
+
135
+ Parameters:
136
+ suspect - suspect variable to test
137
+
138
+ Returns:
139
+ bool
140
+
141
+ See Also:
142
+ <is_typeof>,
143
+ <is_numeric>,
144
+ <is_string>,
145
+ <is_number>,
146
+ <is_date>,
147
+ <is_bool>,
148
+ <is_regex>
149
+ */
150
+ var is_array = function(suspect) {
151
+ return is_typeof(Array, suspect);
152
+ };
153
+ }
154
+
155
+ if (is_undefined(is_number)) {
156
+ /*
157
+ Function: is_number
158
+ Determines if the suspect is a Number. This is a proxy method for is_typeof(Number, suspect).
159
+
160
+ Parameters:
161
+ suspect - suspect variable to test
162
+
163
+ Returns:
164
+ bool
165
+
166
+ See Also:
167
+ <is_typeof>,
168
+ <is_numeric>,
169
+ <is_string>,
170
+ <is_array>,
171
+ <is_date>,
172
+ <is_bool>,
173
+ <is_regex>
174
+ */
175
+ var is_number = function(suspect) {
176
+ return is_typeof(Number, suspect);
177
+ };
178
+ }
179
+
180
+ if (is_undefined(is_date)) {
181
+ /*
182
+ Function: is_date
183
+ Determines if the suspect is a Date. This is a proxy method for is_typeof(Date, suspect).
184
+
185
+ Parameters:
186
+ suspect - suspect variable to test
187
+
188
+ Returns:
189
+ bool
190
+
191
+ See Also:
192
+ <is_typeof>,
193
+ <is_numeric>,
194
+ <is_string>,
195
+ <is_array>,
196
+ <is_number>,
197
+ <is_bool>,
198
+ <is_regex>
199
+ */
200
+ var is_date = function(suspect) {
201
+ return is_typeof(Date, suspect);
202
+ };
203
+ }
204
+
205
+ if (is_undefined(is_bool)) {
206
+ /*
207
+ Function: is_bool
208
+ Determines if the suspect is a Boolean. This is a proxy method for is_typeof(Boolean, suspect).
209
+
210
+ Parameters:
211
+ suspect - suspect variable to test
212
+
213
+ Returns:
214
+ bool
215
+
216
+ See Also:
217
+ <is_typeof>,
218
+ <is_numeric>,
219
+ <is_string>,
220
+ <is_array>,
221
+ <is_number>,
222
+ <is_regex>
223
+ */
224
+ var is_bool = function(suspect) {
225
+ return is_typeof(Boolean, suspect);
226
+ };
227
+ }
228
+
229
+ if (is_undefined(is_regex)) {
230
+ /*
231
+ Function: is_regex
232
+ Determines if the suspect is a RegExp. This is a proxy method for is_typeof(RegExp, suspect).
233
+
234
+ Parameters:
235
+ suspect - suspect variable to test
236
+
237
+ Returns:
238
+ bool
239
+
240
+ See Also:
241
+ <is_typeof>,
242
+ <is_numeric>,
243
+ <is_string>,
244
+ <is_array>,
245
+ <is_number>,
246
+ <is_bool>
247
+ */
248
+ var is_regex = function(suspect) {
249
+ return is_typeof(RegExp, suspect);
250
+ };
251
+ }
@@ -1,6 +1,24 @@
1
+ /* File: extend.js */
1
2
  //= require "existence"
2
3
 
3
4
  if (is_undefined(Function.prototype['method'])) {
5
+ /*
6
+ Function: method
7
+ Method to add a method to an object (ie. String.method('my_method', my_func); //-> 'hello'.my_func())
8
+
9
+ Parameters:
10
+ name - name of the method
11
+ func - function definition
12
+
13
+ Returns:
14
+ this === Function
15
+
16
+ > String.method('custom_method', function() {
17
+ > // define custom_method
18
+ > });
19
+ >
20
+ > "hello".custom_method();
21
+ */
4
22
  Function.prototype.method = function(name, func) {
5
23
  try {
6
24
  if (is_undefined(name)) {
@@ -0,0 +1,230 @@
1
+ /*
2
+ File: module.js
3
+
4
+ Class: NinjsModule
5
+ A NinjsModule is an object which encapsulates a certain behavior or functionality.
6
+
7
+ Parameters:
8
+ name - the name of the module
9
+
10
+ See Also:
11
+ <NinjsApplication>
12
+ */
13
+ var NinjsModule = function(name) {
14
+ /*
15
+ Variable: data
16
+ The module's data object
17
+ */
18
+ this.data = {};
19
+ /*
20
+ Variable: name
21
+ The module's name (string)
22
+ */
23
+ this.name = name;
24
+ /*
25
+ Variable: run_tests (beta)
26
+ Boolean to turn tests on/off
27
+ */
28
+ this.run_tests = false;
29
+ /*
30
+ Variable: tests (beta)
31
+ Array of test files to run
32
+ */
33
+ this.tests = [];
34
+ };
35
+
36
+ /*
37
+ Method: actions
38
+ The actions method contains code to be executed when run is called. This method is a placeholder to be overwritten.
39
+
40
+ > MyModule.actions = function() {
41
+ > // define actions here
42
+ >};
43
+ */
44
+ NinjsModule.method('actions', function() {});
45
+
46
+
47
+ /*
48
+ Method: run
49
+ Waits for the DOM to load then calls execute.
50
+
51
+ > MyModule.run();
52
+ */
53
+ NinjsModule.method('run', function() {
54
+ this.call_on_ready(this.execute);
55
+ });
56
+
57
+ /*
58
+ Method: call_on_ready
59
+ Waits for the DOM to be ready and then executes a callback.
60
+
61
+ Parameters:
62
+ callback - function to be called when the DOM is ready
63
+
64
+ > MyModule.call_on_ready(function() {
65
+ > // some code to execute when the DOM is ready
66
+ > });
67
+ */
68
+ NinjsModule.method('call_on_ready', function(callback) {
69
+ var timer;
70
+ var module = this;
71
+
72
+ function check_ready() {
73
+ timer = setInterval(is_ready, 13);
74
+ }
75
+
76
+ function is_ready() {
77
+ if (document && document.getElementsByTagName && document.getElementById && document.body) {
78
+ clearInterval(timer);
79
+ timer = null;
80
+ callback.call(module);
81
+ }
82
+ }
83
+
84
+ check_ready();
85
+ });
86
+
87
+ /*
88
+ Method: execute
89
+ Wrapper method that set's up the environment and then calls actions.
90
+
91
+ > MyModule.execute();
92
+ */
93
+ NinjsModule.method('execute', function() {
94
+ // swap out the __ alias
95
+ this.old__ = is_defined(window.__) ? window.__ : undefined;
96
+ window.__ = this;
97
+
98
+ if (this.run_tests) {
99
+ this._run_tests();
100
+ }
101
+ this.actions();
102
+
103
+ // reset the __ alias
104
+ if(is_defined(this.old__)) {
105
+ window.__ = this.old__;
106
+ }
107
+ });
108
+
109
+ /*
110
+ Method: elements
111
+ Method to define module elements.
112
+
113
+ Parameters:
114
+ callback - function to define a module's elements
115
+
116
+ > MyModule.elements(function() {
117
+ > // element definitions go here
118
+ > });
119
+ */
120
+ NinjsModule.method('elements', function(callback) {
121
+ // swap out the __ alias
122
+ this.old__ = is_defined(window.__) ? window.__ : undefined;
123
+ window.__ = this;
124
+
125
+ this.call_on_ready(callback);
126
+
127
+ // reset the __ alias
128
+ if(is_defined(this.old__)) {
129
+ window.__ = this.old__;
130
+ }
131
+ });
132
+
133
+
134
+ /*
135
+ Method: set_data
136
+ Adds properties to the module's data object.
137
+
138
+ Parameters:
139
+ key - string or object (if string = key, if object sets multiple properties)
140
+ value - value of key if key is string
141
+
142
+ > MyModule.set_data('some_key', 'some_value');
143
+ > MyModule.data.some_key === 'some_value'
144
+
145
+ > MyModule.set_data({
146
+ > 'property_one': 'value_one',
147
+ > 'property_two': 'value_two'
148
+ > });
149
+ > MyModule.data.property_one === 'value_one'
150
+ > MyModule.data.property_two === 'value_two'
151
+ */
152
+ NinjsModule.method('set_data', function(key, value) {
153
+ try {
154
+ if (is_undefined(key)) {
155
+ throw new SyntaxError('NinjsModule.set_data(key, value): key is undefined');
156
+ }
157
+
158
+ if (is_typeof(String, key) && is_undefined(value)) {
159
+ throw new SyntaxError('NinjsModule.set_data(key, value): value is undefined');
160
+ }
161
+
162
+ if (is_typeof(String, key)) {
163
+ this.data[key] = value;
164
+ }
165
+ else if (is_typeof(Object, key)) {
166
+ var data = key;
167
+ for(var property in data) {
168
+ this.data[property] = data[property];
169
+ }
170
+ }
171
+
172
+ return this;
173
+ }
174
+ catch(error) {
175
+ alert(error.message);
176
+ }
177
+ });
178
+
179
+ /*
180
+ Method: add_test
181
+ Adds a test file to the tests array (beta).
182
+
183
+ Parameters:
184
+ test_file - File to add to the tests array
185
+
186
+ > MyModule.add_test('mytest.test.js');
187
+ */
188
+ NinjsModule.method('add_test', function(test_file) {
189
+ this.tests.push(test_file);
190
+ });
191
+
192
+ /*
193
+ Method: run_tests
194
+ Runs the test files in the test array. This method is automatically called by the execute method if run_tests === true
195
+ */
196
+ NinjsModule.method('run_tests', function() {
197
+ var test_template = [];
198
+ test_template.push('<div class="test-results" title="Test Results">');
199
+ test_template.push('<h1 id="qunit-header">' + this.name + ' module tests</h1>');
200
+ test_template.push('<h2 id="qunit-banner"></h2>');
201
+ test_template.push('<h2 id="qunit-userAgent"></h2>');
202
+ test_template.push('<ol id="qunit-tests"></ol>');
203
+ test_template.push('</div>');
204
+
205
+ $('body').append(test_template.join("\n"));
206
+
207
+ this.tests.each(function(test) {
208
+ $.getScript('tests/' + some + '.test.js', function() {
209
+ var test_results_dialog = $('.test-results');
210
+ var height = test_results_dialog.height() + 130;
211
+ var width = $(window).width() - 300;
212
+ var maxHeight = $(window).height() - 200;
213
+ try {
214
+ test_results_dialog.dialog({
215
+ width: width,
216
+ height: height,
217
+ maxHeight: maxHeight,
218
+ buttons: {
219
+ "Thanks buddy": function() {
220
+ test_results_dialog.dialog('close');
221
+ }
222
+ }
223
+ });
224
+ }
225
+ catch(error) {
226
+ alert("Test harness requires jQueryUI");
227
+ }
228
+ });
229
+ });
230
+ });