ninjs 0.13.7 → 0.13.8
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/.bundle/config +2 -0
- data/CNAME +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +36 -0
- data/LICENSE +29 -0
- data/README.md +348 -0
- data/VERSION +1 -1
- data/bin/ninjs +211 -0
- data/lib/ninjs.rb +10 -0
- data/lib/ninjs/command.rb +88 -0
- data/lib/ninjs/configuration.rb +82 -0
- data/lib/ninjs/dependencies.rb +16 -0
- data/lib/ninjs/generator.rb +57 -0
- data/lib/ninjs/helpers.rb +17 -0
- data/lib/ninjs/manifest.rb +9 -0
- data/lib/ninjs/notification.rb +37 -0
- data/lib/ninjs/project.rb +214 -0
- data/ninjs.gemspec +294 -5
- data/repository/jquery/1.1.4.js +2508 -0
- data/repository/jquery/1.2.6.js +32 -0
- data/repository/jquery/1.3.2.js +19 -0
- data/repository/jquery/1.4.2.js +154 -0
- data/repository/jquery/1.4.3.js +166 -0
- data/repository/jquery/1.4.4.js +167 -0
- data/repository/jquery/1.5.js +16 -0
- data/repository/jquery/fancybox/1.3.1.js +1079 -0
- data/repository/jquery/fancybox/assets/1.3.1/css/fancybox.css +363 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/blank.gif +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_close.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_loading.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_nav_left.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_nav_right.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_e.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_n.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_ne.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_nw.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_s.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_se.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_sw.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_shadow_w.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_title_left.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_title_main.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_title_over.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancy_title_right.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancybox-x.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancybox-y.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/fancybox.png +0 -0
- data/repository/jquery/fancybox/assets/1.3.1/images/fancybox/jquery.easing-1.3.pack.js +72 -0
- data/repository/jquery/fancybox/latest.js +1 -0
- data/repository/jquery/latest.js +1 -0
- data/repository/jquery/mobile/1.0a3.js +123 -0
- data/repository/jquery/mobile/1.0a3/assets/css/jquery.mobile.css +1652 -0
- data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/ajax-loader.png +0 -0
- data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/form-check-off.png +0 -0
- data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/form-check-on.png +0 -0
- data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/form-radio-off.png +0 -0
- data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/form-radio-on.png +0 -0
- data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icon-search-black.png +0 -0
- data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icons-18-black.png +0 -0
- data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icons-18-white.png +0 -0
- data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icons-36-black.png +0 -0
- data/repository/jquery/mobile/1.0a3/assets/images/jquerymobile/icons-36-white.png +0 -0
- data/repository/jquery/mobile/latest.js +1 -0
- data/repository/jquery/mousewheel/3.0.2.js +11 -0
- data/repository/jquery/mousewheel/latest.js +1 -0
- data/repository/jquery/ui/1.8.7.js +783 -0
- data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.accordion.css +19 -0
- data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.all.css +11 -0
- data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.autocomplete.css +53 -0
- data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.base.css +11 -0
- data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.button.css +38 -0
- data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.core.css +41 -0
- data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.datepicker.css +68 -0
- data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.dialog.css +21 -0
- data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.progressbar.css +11 -0
- data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.resizable.css +20 -0
- data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.selectable.css +10 -0
- data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.slider.css +24 -0
- data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.tabs.css +18 -0
- data/repository/jquery/ui/assets/1.8.7/css/jqueryui/jquery.ui.theme.css +252 -0
- data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-icons_222222_256x240.png +0 -0
- data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-icons_2e83ff_256x240.png +0 -0
- data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-icons_454545_256x240.png +0 -0
- data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-icons_888888_256x240.png +0 -0
- data/repository/jquery/ui/assets/1.8.7/images/jqueryui/ui-icons_cd0a0a_256x240.png +0 -0
- data/repository/jquery/ui/latest.js +1 -0
- data/repository/json2.js +482 -0
- data/repository/modernizr/1.5.js +28 -0
- data/repository/modernizr/latest.js +1 -0
- data/repository/ninjs/core/.core.pdoc.yaml +0 -0
- data/repository/ninjs/core/.existence.pdoc.yaml +12 -0
- data/repository/ninjs/core/.extend.pdoc.yaml +0 -0
- data/repository/ninjs/core/.nin.pdoc.yaml +0 -0
- data/repository/ninjs/core/application.js +47 -0
- data/repository/ninjs/core/existence.js +277 -0
- data/repository/ninjs/core/extend.js +77 -0
- data/repository/ninjs/core/module.js +135 -0
- data/repository/ninjs/core/nin.js +4 -0
- data/repository/ninjs/docs/Data/ClassHierarchy.nd +0 -0
- data/repository/ninjs/docs/Data/ConfigFileInfo.nd +0 -0
- data/repository/ninjs/docs/Data/FileInfo.nd +16 -0
- data/repository/ninjs/docs/Data/ImageFileInfo.nd +0 -0
- data/repository/ninjs/docs/Data/ImageReferenceTable.nd +0 -0
- data/repository/ninjs/docs/Data/IndexInfo.nd +0 -0
- data/repository/ninjs/docs/Data/PreviousMenuState.nd +0 -0
- data/repository/ninjs/docs/Data/PreviousSettings.nd +0 -0
- data/repository/ninjs/docs/Data/SymbolTable.nd +0 -0
- data/repository/ninjs/docs/Languages.txt +113 -0
- data/repository/ninjs/docs/Menu.txt +63 -0
- data/repository/ninjs/docs/Topics.txt +81 -0
- data/repository/ninjs/docs/files/core/application-js.html +44 -0
- data/repository/ninjs/docs/files/core/existence-js.html +60 -0
- data/repository/ninjs/docs/files/core/extend-js.html +55 -0
- data/repository/ninjs/docs/files/core/module-js.html +80 -0
- data/repository/ninjs/docs/files/core/nin-js.html +38 -0
- data/repository/ninjs/docs/index.html +1 -0
- data/repository/ninjs/docs/index/Classes.html +33 -0
- data/repository/ninjs/docs/index/Files.html +45 -0
- data/repository/ninjs/docs/index/Functions.html +65 -0
- data/repository/ninjs/docs/index/General.html +85 -0
- data/repository/ninjs/docs/index/Variables.html +45 -0
- data/repository/ninjs/docs/javascript/main.js +841 -0
- data/repository/ninjs/docs/javascript/prettify.js +1526 -0
- data/repository/ninjs/docs/javascript/searchdata.js +152 -0
- data/repository/ninjs/docs/search/ClassesN.html +20 -0
- data/repository/ninjs/docs/search/FilesA.html +20 -0
- data/repository/ninjs/docs/search/FilesE.html +20 -0
- data/repository/ninjs/docs/search/FilesM.html +20 -0
- data/repository/ninjs/docs/search/FilesN.html +20 -0
- data/repository/ninjs/docs/search/FunctionsA.html +20 -0
- data/repository/ninjs/docs/search/FunctionsC.html +20 -0
- data/repository/ninjs/docs/search/FunctionsE.html +20 -0
- data/repository/ninjs/docs/search/FunctionsI.html +20 -0
- data/repository/ninjs/docs/search/FunctionsM.html +20 -0
- data/repository/ninjs/docs/search/FunctionsR.html +20 -0
- data/repository/ninjs/docs/search/FunctionsS.html +20 -0
- data/repository/ninjs/docs/search/FunctionsSymbols.html +20 -0
- data/repository/ninjs/docs/search/FunctionsU.html +20 -0
- data/repository/ninjs/docs/search/GeneralA.html +20 -0
- data/repository/ninjs/docs/search/GeneralC.html +20 -0
- data/repository/ninjs/docs/search/GeneralD.html +20 -0
- data/repository/ninjs/docs/search/GeneralE.html +20 -0
- data/repository/ninjs/docs/search/GeneralF.html +20 -0
- data/repository/ninjs/docs/search/GeneralI.html +20 -0
- data/repository/ninjs/docs/search/GeneralM.html +20 -0
- data/repository/ninjs/docs/search/GeneralN.html +20 -0
- data/repository/ninjs/docs/search/GeneralR.html +20 -0
- data/repository/ninjs/docs/search/GeneralS.html +20 -0
- data/repository/ninjs/docs/search/GeneralSymbols.html +20 -0
- data/repository/ninjs/docs/search/GeneralT.html +20 -0
- data/repository/ninjs/docs/search/GeneralU.html +20 -0
- data/repository/ninjs/docs/search/GeneralV.html +20 -0
- data/repository/ninjs/docs/search/NoResults.html +15 -0
- data/repository/ninjs/docs/search/VariablesD.html +20 -0
- data/repository/ninjs/docs/search/VariablesN.html +20 -0
- data/repository/ninjs/docs/search/VariablesR.html +20 -0
- data/repository/ninjs/docs/search/VariablesT.html +20 -0
- data/repository/ninjs/docs/styles/main.css +828 -0
- data/repository/ninjs/extensions/jquery.elements.js +60 -0
- data/repository/ninjs/tests/index.html +21 -0
- data/repository/ninjs/tests/ninjs.test.js +188 -0
- data/repository/ninjs/tests/ninjs.utilities.test.js +137 -0
- data/repository/ninjs/tests/qunit/qunit.css +197 -0
- data/repository/ninjs/tests/qunit/qunit.js +1415 -0
- data/repository/ninjs/utilities/all.js +5 -0
- data/repository/ninjs/utilities/array.js +29 -0
- data/repository/ninjs/utilities/cookie.js +0 -0
- data/repository/ninjs/utilities/css.js +51 -0
- data/repository/ninjs/utilities/number.js +11 -0
- data/repository/ninjs/utilities/string.js +61 -0
- data/repository/nullconsole.js +7 -0
- data/repository/qunit/assets/css/qunit.css +196 -0
- data/repository/qunit/qunit.js +1374 -0
- data/repository/selectivizr/1.0.js +5 -0
- data/repository/selectivizr/latest.js +1 -0
- data/repository/syntaxhighlighter/all.js +11 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCore.css +226 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreDefault.css +328 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreDjango.css +331 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreEclipse.css +339 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreEmacs.css +324 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreFadeToGrey.css +328 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreMDUltra.css +324 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreMidnight.css +324 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shCoreRDark.css +324 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeDefault.css +117 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeDjango.css +120 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeEclipse.css +128 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeEmacs.css +113 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeFadeToGrey.css +117 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeMDUltra.css +113 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeMidnight.css +113 -0
- data/repository/syntaxhighlighter/assets/css/syntaxhighlighter/shThemeRDark.css +113 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCore.scss +216 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreDefault.scss +2 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreDjango.scss +2 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreEclipse.scss +2 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreEmacs.scss +2 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreFadeToGrey.scss +2 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreMDUltra.scss +2 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreMidnight.scss +2 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shCoreRDark.scss +2 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeDefault.scss +7 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeDjango.scss +36 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeEclipse.scss +48 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeEmacs.scss +32 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeFadeToGrey.scss +36 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeMDUltra.scss +32 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeMidnight.scss +32 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_shThemeRDark.scss +32 -0
- data/repository/syntaxhighlighter/assets/scss/syntaxhighlighter/_theme_template.scss +120 -0
- data/repository/syntaxhighlighter/shAutoloader.js +17 -0
- data/repository/syntaxhighlighter/shBrushAS3.js +59 -0
- data/repository/syntaxhighlighter/shBrushAppleScript.js +75 -0
- data/repository/syntaxhighlighter/shBrushBash.js +59 -0
- data/repository/syntaxhighlighter/shBrushCSharp.js +65 -0
- data/repository/syntaxhighlighter/shBrushColdFusion.js +100 -0
- data/repository/syntaxhighlighter/shBrushCpp.js +97 -0
- data/repository/syntaxhighlighter/shBrushCss.js +91 -0
- data/repository/syntaxhighlighter/shBrushDelphi.js +55 -0
- data/repository/syntaxhighlighter/shBrushDiff.js +41 -0
- data/repository/syntaxhighlighter/shBrushErlang.js +52 -0
- data/repository/syntaxhighlighter/shBrushGroovy.js +67 -0
- data/repository/syntaxhighlighter/shBrushJScript.js +52 -0
- data/repository/syntaxhighlighter/shBrushJava.js +57 -0
- data/repository/syntaxhighlighter/shBrushJavaFX.js +58 -0
- data/repository/syntaxhighlighter/shBrushPerl.js +72 -0
- data/repository/syntaxhighlighter/shBrushPhp.js +88 -0
- data/repository/syntaxhighlighter/shBrushPlain.js +33 -0
- data/repository/syntaxhighlighter/shBrushPowerShell.js +74 -0
- data/repository/syntaxhighlighter/shBrushPython.js +64 -0
- data/repository/syntaxhighlighter/shBrushRuby.js +55 -0
- data/repository/syntaxhighlighter/shBrushSass.js +94 -0
- data/repository/syntaxhighlighter/shBrushScala.js +51 -0
- data/repository/syntaxhighlighter/shBrushSql.js +66 -0
- data/repository/syntaxhighlighter/shBrushVb.js +56 -0
- data/repository/syntaxhighlighter/shBrushXml.js +69 -0
- data/repository/syntaxhighlighter/shCore.js +17 -0
- data/repository/syntaxhighlighter/shLegacy.js +17 -0
- data/spec/command_spec.rb +9 -0
- data/spec/configuration_spec.rb +70 -0
- data/spec/dependencies_spec.rb +27 -0
- data/spec/fixtures/autoload.js +3 -0
- data/spec/fixtures/changed.ninjs.conf +6 -0
- data/spec/fixtures/compressed.myapp.js +39 -0
- data/spec/fixtures/core.js +6 -0
- data/spec/fixtures/dependencies.js +3 -0
- data/spec/fixtures/foo.elements.js +3 -0
- data/spec/fixtures/foo.js +17 -0
- data/spec/fixtures/foo.model.js +3 -0
- data/spec/fixtures/foo.module.js +13 -0
- data/spec/fixtures/hello.elements.js +3 -0
- data/spec/fixtures/hello.js +17 -0
- data/spec/fixtures/hello.model.js +3 -0
- data/spec/fixtures/hello.module.js +13 -0
- data/spec/fixtures/myapp.initial.js +535 -0
- data/spec/fixtures/myapp.js +710 -0
- data/spec/fixtures/new.ninjs.conf +6 -0
- data/spec/fixtures/ninjs.conf +6 -0
- data/spec/generator_spec.rb +34 -0
- data/spec/helpers_spec.rb +11 -0
- data/spec/manifest_spec.rb +8 -0
- data/spec/ninjs_spec.rb +20 -0
- data/spec/notification_spec.rb +27 -0
- data/spec/project_spec.rb +239 -0
- data/spec/spec_helper.rb +29 -0
- metadata +294 -50
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
/* File: nin.js */
|
|
2
|
+
/* File: extend.js */
|
|
3
|
+
/* File: existence.js */
|
|
4
|
+
if (is_defined === undefined) {
|
|
5
|
+
/*
|
|
6
|
+
Function: is_defined
|
|
7
|
+
Checks if a variable is undefined. This is a convenience method to enhance clarity in your conditions.
|
|
8
|
+
|
|
9
|
+
Parameters:
|
|
10
|
+
suspect - suspect variable to test
|
|
11
|
+
|
|
12
|
+
Returns:
|
|
13
|
+
bool
|
|
14
|
+
|
|
15
|
+
See Also:
|
|
16
|
+
|
|
17
|
+
<is_undefined>
|
|
18
|
+
*/
|
|
19
|
+
var is_defined = function(suspect) {
|
|
20
|
+
return ((suspect === undefined) || (suspect === null)) ? false : true;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!is_defined(is_undefined)) {
|
|
25
|
+
/*
|
|
26
|
+
Function: is_undefined
|
|
27
|
+
Checks if a variable is defined. This is a convenience method to enhance clarity in your conditions.
|
|
28
|
+
|
|
29
|
+
Parameters:
|
|
30
|
+
suspect - suspect variable to test
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
bool
|
|
34
|
+
|
|
35
|
+
See Also:
|
|
36
|
+
|
|
37
|
+
<is_defined>
|
|
38
|
+
*/
|
|
39
|
+
var is_undefined = function(suspect) {
|
|
40
|
+
return (suspect === undefined) ? true : false;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (is_undefined(is_typeof)) {
|
|
45
|
+
/*
|
|
46
|
+
Function: is_typeof
|
|
47
|
+
Strict type checking by comparing constructors.
|
|
48
|
+
(Pro Javascript Techniques, John Resig, Apress p.24 Listing 2-8: Example of using the constructor property to determine the type of an object http://amzn.to/fTsDRg)
|
|
49
|
+
Parameters:
|
|
50
|
+
type - The type you expect (ie. String, Number, Array (note: without quotes): is_typeof(String, 'hello'): // true)
|
|
51
|
+
suspect - The suspect variable to check against type
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
bool
|
|
55
|
+
|
|
56
|
+
See Also:
|
|
57
|
+
<is_numeric>,
|
|
58
|
+
<is_string>,
|
|
59
|
+
<is_array>,
|
|
60
|
+
<is_number>,
|
|
61
|
+
<is_date>,
|
|
62
|
+
<is_bool>,
|
|
63
|
+
<is_regex>
|
|
64
|
+
*/
|
|
65
|
+
var is_typeof = function(type, suspect) {
|
|
66
|
+
if (is_undefined(type)) {
|
|
67
|
+
throw new SyntaxError("is_typeof(Type, suspect): type is undefined");
|
|
68
|
+
}
|
|
69
|
+
if (is_undefined(suspect)) {
|
|
70
|
+
throw new SyntaxError("is_typeof(Type, suspect): suspect is undefined");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return (suspect.constructor == type) ? true : false;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (is_undefined(is_numeric)) {
|
|
78
|
+
/*
|
|
79
|
+
Function: is_numeric
|
|
80
|
+
Determine if the suspect string represents a numeric value.
|
|
81
|
+
(JavaScript: The Good Parts, Douglas Crockford, O'Reilly p.69 Chapter 7: Regular Expressions An Example)
|
|
82
|
+
Parameters:
|
|
83
|
+
suspect - variable to check for numeric value
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
bool
|
|
87
|
+
|
|
88
|
+
See Also:
|
|
89
|
+
<is_number>
|
|
90
|
+
*/
|
|
91
|
+
var is_numeric = function(suspect) {
|
|
92
|
+
if(is_typeof(Number, suspect)) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
var pattern = /^-?\d+(?:\.\d*)?(?:e[+\-]?\d+)?$/i;
|
|
97
|
+
return pattern.test(suspect);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (is_undefined(is_string)) {
|
|
103
|
+
/*
|
|
104
|
+
Function: is_string
|
|
105
|
+
Determine the suspect is a String. This is a proxy method for is_typeof(String, suspect).
|
|
106
|
+
|
|
107
|
+
Parameters:
|
|
108
|
+
suspect - supect variable to test
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
bool
|
|
112
|
+
|
|
113
|
+
See Also:
|
|
114
|
+
<is_typeof>,
|
|
115
|
+
<is_numeric>,
|
|
116
|
+
<is_array>,
|
|
117
|
+
<is_number>,
|
|
118
|
+
<is_date>,
|
|
119
|
+
<is_bool>,
|
|
120
|
+
<is_regex>
|
|
121
|
+
*/
|
|
122
|
+
var is_string = function(suspect) {
|
|
123
|
+
return is_typeof(String, suspect);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (is_undefined(is_array)) {
|
|
128
|
+
/*
|
|
129
|
+
Function: is_array
|
|
130
|
+
Determine if the suspect is an Array. This is a proxy method for is_typeof(Array, suspect).
|
|
131
|
+
|
|
132
|
+
Parameters:
|
|
133
|
+
suspect - suspect variable to test
|
|
134
|
+
|
|
135
|
+
Returns:
|
|
136
|
+
bool
|
|
137
|
+
|
|
138
|
+
See Also:
|
|
139
|
+
<is_typeof>,
|
|
140
|
+
<is_numeric>,
|
|
141
|
+
<is_string>,
|
|
142
|
+
<is_number>,
|
|
143
|
+
<is_date>,
|
|
144
|
+
<is_bool>,
|
|
145
|
+
<is_regex>
|
|
146
|
+
*/
|
|
147
|
+
var is_array = function(suspect) {
|
|
148
|
+
return is_typeof(Array, suspect);
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (is_undefined(is_number)) {
|
|
153
|
+
/*
|
|
154
|
+
Function: is_number
|
|
155
|
+
Determines if the suspect is a Number. This is a proxy method for is_typeof(Number, suspect).
|
|
156
|
+
|
|
157
|
+
Parameters:
|
|
158
|
+
suspect - suspect variable to test
|
|
159
|
+
|
|
160
|
+
Returns:
|
|
161
|
+
bool
|
|
162
|
+
|
|
163
|
+
See Also:
|
|
164
|
+
<is_typeof>,
|
|
165
|
+
<is_numeric>,
|
|
166
|
+
<is_string>,
|
|
167
|
+
<is_array>,
|
|
168
|
+
<is_date>,
|
|
169
|
+
<is_bool>,
|
|
170
|
+
<is_regex>
|
|
171
|
+
*/
|
|
172
|
+
var is_number = function(suspect) {
|
|
173
|
+
return is_typeof(Number, suspect);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (is_undefined(is_date)) {
|
|
178
|
+
/*
|
|
179
|
+
Function: is_date
|
|
180
|
+
Determines if the suspect is a Date. This is a proxy method for is_typeof(Date, suspect).
|
|
181
|
+
|
|
182
|
+
Parameters:
|
|
183
|
+
suspect - suspect variable to test
|
|
184
|
+
|
|
185
|
+
Returns:
|
|
186
|
+
bool
|
|
187
|
+
|
|
188
|
+
See Also:
|
|
189
|
+
<is_typeof>,
|
|
190
|
+
<is_numeric>,
|
|
191
|
+
<is_string>,
|
|
192
|
+
<is_array>,
|
|
193
|
+
<is_number>,
|
|
194
|
+
<is_bool>,
|
|
195
|
+
<is_regex>
|
|
196
|
+
*/
|
|
197
|
+
var is_date = function(suspect) {
|
|
198
|
+
return is_typeof(Date, suspect);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (is_undefined(is_bool)) {
|
|
203
|
+
/*
|
|
204
|
+
Function: is_bool
|
|
205
|
+
Determines if the suspect is a Boolean. This is a proxy method for is_typeof(Boolean, suspect).
|
|
206
|
+
|
|
207
|
+
Parameters:
|
|
208
|
+
suspect - suspect variable to test
|
|
209
|
+
|
|
210
|
+
Returns:
|
|
211
|
+
bool
|
|
212
|
+
|
|
213
|
+
See Also:
|
|
214
|
+
<is_typeof>,
|
|
215
|
+
<is_numeric>,
|
|
216
|
+
<is_string>,
|
|
217
|
+
<is_array>,
|
|
218
|
+
<is_number>,
|
|
219
|
+
<is_regex>
|
|
220
|
+
*/
|
|
221
|
+
var is_bool = function(suspect) {
|
|
222
|
+
return is_typeof(Boolean, suspect);
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (is_undefined(is_regex)) {
|
|
227
|
+
/*
|
|
228
|
+
Function: is_regex
|
|
229
|
+
Determines if the suspect is a RegExp. This is a proxy method for is_typeof(RegExp, suspect).
|
|
230
|
+
|
|
231
|
+
Parameters:
|
|
232
|
+
suspect - suspect variable to test
|
|
233
|
+
|
|
234
|
+
Returns:
|
|
235
|
+
bool
|
|
236
|
+
|
|
237
|
+
See Also:
|
|
238
|
+
<is_typeof>,
|
|
239
|
+
<is_numeric>,
|
|
240
|
+
<is_string>,
|
|
241
|
+
<is_array>,
|
|
242
|
+
<is_number>,
|
|
243
|
+
<is_bool>
|
|
244
|
+
*/
|
|
245
|
+
var is_regex = function(suspect) {
|
|
246
|
+
return is_typeof(RegExp, suspect);
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
if (is_undefined(is_empty)) {
|
|
252
|
+
/*
|
|
253
|
+
Function: is_empty
|
|
254
|
+
Determined if the suspect's length is less than one.
|
|
255
|
+
|
|
256
|
+
Parameters:
|
|
257
|
+
suspect - suspect variable to test
|
|
258
|
+
|
|
259
|
+
Returns: bool
|
|
260
|
+
*/
|
|
261
|
+
var is_empty = function(suspect) {
|
|
262
|
+
return suspect.length === 0;
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (is_undefined(is_not_empty)) {
|
|
267
|
+
/*
|
|
268
|
+
Function: is_not_empty
|
|
269
|
+
Determined if the suspect's length is greater than one.
|
|
270
|
+
|
|
271
|
+
Parameters:
|
|
272
|
+
suspect - suspect variable to test
|
|
273
|
+
|
|
274
|
+
Returns: bool
|
|
275
|
+
*/
|
|
276
|
+
var is_not_empty = function(suspect) {
|
|
277
|
+
return suspect.length >= 1;
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (is_undefined(Function.prototype['method'])) {
|
|
282
|
+
/*
|
|
283
|
+
Function: method
|
|
284
|
+
Method to add a method to an object (ie. String.method('my_method', my_func); // 'hello'.my_method())
|
|
285
|
+
|
|
286
|
+
Parameters:
|
|
287
|
+
name - name of the method
|
|
288
|
+
func - function definition
|
|
289
|
+
|
|
290
|
+
Returns:
|
|
291
|
+
this (chainable)
|
|
292
|
+
|
|
293
|
+
> String.method('custom_method', function() {
|
|
294
|
+
> // define custom_method
|
|
295
|
+
> });
|
|
296
|
+
>
|
|
297
|
+
> "hello".custom_method();
|
|
298
|
+
*/
|
|
299
|
+
Function.prototype.method = function(name, func) {
|
|
300
|
+
if (is_undefined(name)) {
|
|
301
|
+
throw new SyntaxError("Object.method(name, func): name is undefined");
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (is_undefined(func)) {
|
|
305
|
+
throw new SyntaxError("Object.method(name, func): func is undefined");
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (is_undefined(this.prototype[name])) {
|
|
309
|
+
this.prototype[name] = func;
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (is_undefined(unless)) {
|
|
316
|
+
/*
|
|
317
|
+
Function: unless
|
|
318
|
+
Function to better express negative conditions (ie. if (!something))
|
|
319
|
+
|
|
320
|
+
Parameters:
|
|
321
|
+
expression - expression to be tested
|
|
322
|
+
callback - function to be executed unless expression is true (see how that works)
|
|
323
|
+
fallback - function to be executed if the expression is false (optional)
|
|
324
|
+
|
|
325
|
+
Returns:
|
|
326
|
+
undefined
|
|
327
|
+
|
|
328
|
+
> unless(test_expression === 'some condition',
|
|
329
|
+
> function() {
|
|
330
|
+
> alert('we do something');
|
|
331
|
+
> },
|
|
332
|
+
> function() {
|
|
333
|
+
> alert('we can do something if it meets the condition too');
|
|
334
|
+
> }
|
|
335
|
+
> );
|
|
336
|
+
*/
|
|
337
|
+
var unless = function(expression, callback, fallback) {
|
|
338
|
+
if (is_undefined(expression)) {
|
|
339
|
+
throw new SyntaxError("unless(expression, callback[, fallback]): expression is undefined");
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (is_undefined(callback)) {
|
|
343
|
+
throw new SyntaxError("unless(expression, callback[, fallback]): callback is undefined");
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (!expression) {
|
|
347
|
+
callback.call(this);
|
|
348
|
+
}
|
|
349
|
+
else if (is_defined(fallback)) {
|
|
350
|
+
fallback.call(this);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
var NinjsModule = function(name) {
|
|
355
|
+
this.dom = {};
|
|
356
|
+
this.data = {};
|
|
357
|
+
this.name = name;
|
|
358
|
+
this.run_tests = false;
|
|
359
|
+
this.tests = [];
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
NinjsModule.method('actions', function() {});
|
|
363
|
+
|
|
364
|
+
NinjsModule.method('run', function() {
|
|
365
|
+
this.call_on_ready(this.execute);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
NinjsModule.method('call_on_ready', function(callback) {
|
|
369
|
+
var timer;
|
|
370
|
+
var module = this;
|
|
371
|
+
|
|
372
|
+
function check_ready() {
|
|
373
|
+
timer = setInterval(is_ready, 13);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function is_ready() {
|
|
377
|
+
if (document && document.getElementsByTagName && document.getElementById && document.body) {
|
|
378
|
+
clearInterval(timer);
|
|
379
|
+
timer = null;
|
|
380
|
+
callback.call(module);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
check_ready();
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
NinjsModule.method('execute', function() {
|
|
388
|
+
if (this.run_tests) {
|
|
389
|
+
this._run_tests();
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
this.actions();
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
NinjsModule.method('elements', function(elements) {
|
|
396
|
+
if (is_undefined(elements)) {
|
|
397
|
+
if (is_typeof(Object, elements)) {
|
|
398
|
+
throw new SyntaxError("NinjsModule.elements(elements): elements is undefined");
|
|
399
|
+
}
|
|
400
|
+
else if (is_string(elements)) {
|
|
401
|
+
throw new SyntaxError("NinjsModule.elements(name): name is undefined");
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (is_string(elements)) {
|
|
406
|
+
var name = elements;
|
|
407
|
+
return is_defined(this.dom[name]) ? this.dom[name] : undefined;
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
this.call_on_ready(function() {
|
|
411
|
+
for(var key in elements) {
|
|
412
|
+
if (elements.hasOwnProperty(key)) {
|
|
413
|
+
this.dom[key] = elements[key];
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
NinjsModule.method('set_data', function(key, value) {
|
|
421
|
+
if (is_undefined(key)) {
|
|
422
|
+
throw new SyntaxError('NinjsModule.set_data(key, value): key is undefined');
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (is_typeof(String, key) && is_undefined(value)) {
|
|
426
|
+
throw new SyntaxError('NinjsModule.set_data(key, value): value is undefined');
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (is_typeof(String, key)) {
|
|
430
|
+
this.data[key] = value;
|
|
431
|
+
}
|
|
432
|
+
else if (is_typeof(Object, key)) {
|
|
433
|
+
var data = key;
|
|
434
|
+
for(var property in data) {
|
|
435
|
+
this.data[property] = data[property];
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return this;
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
NinjsModule.method('add_test', function(test_file) {
|
|
443
|
+
this.tests.push(test_file);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
NinjsModule.method('_run_tests', function() {
|
|
447
|
+
var test_template = [];
|
|
448
|
+
test_template.push('<div class="test-results" title="Test Results">');
|
|
449
|
+
test_template.push('<h1 id="qunit-header">' + this.name + ' module tests</h1>');
|
|
450
|
+
test_template.push('<h2 id="qunit-banner"></h2>');
|
|
451
|
+
test_template.push('<h2 id="qunit-userAgent"></h2>');
|
|
452
|
+
test_template.push('<ol id="qunit-tests"></ol>');
|
|
453
|
+
test_template.push('</div>');
|
|
454
|
+
|
|
455
|
+
var qunit_dependencies = '<script src="' + _.tests_path +'qunit/qunit.js"></script>';
|
|
456
|
+
$.getScript(_.tests_path + 'qunit/qunit.js');
|
|
457
|
+
var qunit_styles = '<link rel="stylesheet" href="' + _.tests_path + 'qunit/qunit.css">';
|
|
458
|
+
$('body').append(qunit_styles);
|
|
459
|
+
$('body').append(test_template.join("\n"));
|
|
460
|
+
|
|
461
|
+
this.tests.each(function(test) {
|
|
462
|
+
$.getScript(_.tests_path + test + '.test.js', function() {
|
|
463
|
+
var test_results_dialog = $('.test-results');
|
|
464
|
+
var height = $(window).height() - 200;
|
|
465
|
+
var width = $(window).width() - 300;
|
|
466
|
+
try {
|
|
467
|
+
test_results_dialog.dialog({
|
|
468
|
+
width: width,
|
|
469
|
+
height: height,
|
|
470
|
+
autoOpen: false,
|
|
471
|
+
buttons: {
|
|
472
|
+
"Thanks buddy": function() {
|
|
473
|
+
test_results_dialog.dialog('close');
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
var failed = $('.failed');
|
|
478
|
+
console.log(failed.html());
|
|
479
|
+
test_results_dialog.dialog('open');
|
|
480
|
+
}
|
|
481
|
+
catch(error) {
|
|
482
|
+
alert("Test harness requires jQueryUI");
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
/*
|
|
488
|
+
File: application.js
|
|
489
|
+
|
|
490
|
+
Class: NinjsApplication
|
|
491
|
+
An NinjsApplication object serves as your application's namespace and includes a utility to add modules to the application object.
|
|
492
|
+
|
|
493
|
+
See Also:
|
|
494
|
+
<NinjsModule>
|
|
495
|
+
*/
|
|
496
|
+
|
|
497
|
+
var NinjsApplication = function(base_url, tests_path) {
|
|
498
|
+
if(is_defined(tests_path)) {
|
|
499
|
+
this.tests_path = tests_path;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if(is_defined(base_url)) {
|
|
503
|
+
this.site_url = function(path) {
|
|
504
|
+
var path = path || '';
|
|
505
|
+
return base_url + path;
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
/*
|
|
511
|
+
Method: add_module
|
|
512
|
+
Adds a NinjsModule to the application.
|
|
513
|
+
|
|
514
|
+
Parameters:
|
|
515
|
+
name - the name of the module
|
|
516
|
+
|
|
517
|
+
> myapp.add_module('my_module');
|
|
518
|
+
*/
|
|
519
|
+
NinjsApplication.method('add_module', function(name) {
|
|
520
|
+
if (is_undefined(name)) {
|
|
521
|
+
throw new SyntaxError("NinjsApplication.add_module(name): name is undefined");
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (is_defined(this[name])) {
|
|
525
|
+
throw new SyntaxError("NinjsApplication.add_module(name): '" + name + "' already declared");
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (this.name === name) {
|
|
529
|
+
throw new SyntaxError("NinjsApplication.add_module(name): a module cannot have the same name as the application");
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
return this[name] = new NinjsModule(name);
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
var myapp = new NinjsApplication();
|