ninjs 0.13.8 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/bin/ninjs +2 -1
- data/lib/ninjs/command.rb +1 -1
- data/lib/ninjs/generator.rb +14 -10
- data/lib/ninjs/project.rb +7 -4
- data/ninjs.gemspec +20 -7
- data/repository/ninjs/core/application.js +24 -43
- data/repository/ninjs/core/dom.js +139 -0
- data/repository/ninjs/core/existence.js +121 -277
- data/repository/ninjs/core/extend.js +35 -77
- data/repository/ninjs/core/module.js +101 -116
- data/repository/ninjs/core/nin.js +7 -4
- data/repository/ninjs/tests/application.test.js +24 -0
- data/repository/ninjs/tests/array.utilities.test.js +55 -0
- data/repository/ninjs/tests/existence.test.js +64 -0
- data/repository/ninjs/tests/extension.test.js +38 -0
- data/repository/ninjs/tests/index.html +11 -5
- data/repository/ninjs/tests/module.test.js +75 -0
- data/repository/ninjs/tests/qspec.js +26 -0
- data/repository/ninjs/tests/{ninjs.utilities.test.js → string.utilities.test.js} +14 -66
- data/spec/cli_spec.rb +159 -0
- data/spec/command_spec.rb +226 -2
- data/spec/fixtures/compressed.myapp.js +40 -20
- data/spec/fixtures/myapp.initial.js +383 -488
- data/spec/fixtures/myapp.js +379 -484
- data/spec/fixtures/mymodule.alias.module.js +10 -0
- data/spec/fixtures/mymodule.dependencies.module.js +13 -0
- data/spec/fixtures/mymodule.elements.js +5 -0
- data/spec/fixtures/mymodule.model.js +3 -0
- data/spec/fixtures/mymodule.module.js +10 -0
- data/spec/fixtures/nin.js +428 -0
- data/spec/generator_spec.rb +58 -10
- data/spec/project_spec.rb +11 -7
- metadata +59 -9
- data/repository/ninjs/tests/ninjs.test.js +0 -188
- data/repository/ninjs/tests/qunit/qunit.css +0 -197
- data/repository/ninjs/tests/qunit/qunit.js +0 -1415
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.14.0
|
data/bin/ninjs
CHANGED
@@ -83,7 +83,7 @@ help = {
|
|
83
83
|
command = ARGV[0]
|
84
84
|
|
85
85
|
options = {
|
86
|
-
:alias =>
|
86
|
+
:alias => nil,
|
87
87
|
:elements => false,
|
88
88
|
:model => false,
|
89
89
|
:help => false,
|
@@ -171,6 +171,7 @@ case command
|
|
171
171
|
}
|
172
172
|
|
173
173
|
Ninjs::Command.generate({
|
174
|
+
:project => Ninjs::Project.new,
|
174
175
|
:type => type,
|
175
176
|
:name => name,
|
176
177
|
:alias => als,
|
data/lib/ninjs/command.rb
CHANGED
@@ -3,7 +3,7 @@ module Ninjs
|
|
3
3
|
def watch
|
4
4
|
require "fssm"
|
5
5
|
|
6
|
-
project_path = File.expand_path
|
6
|
+
project_path = File.expand_path Dir.getwd
|
7
7
|
raise "ninjs.conf was not located in #{project_path}" unless File.exists? "#{project_path}/ninjs.conf"
|
8
8
|
|
9
9
|
puts Ninjs::Notification.log "Ninjs are watching for changes. Press Ctrl-C to stop."
|
data/lib/ninjs/generator.rb
CHANGED
@@ -5,7 +5,7 @@ module Ninjs
|
|
5
5
|
|
6
6
|
def initialize(config)
|
7
7
|
@type = config[:type]
|
8
|
-
@project =
|
8
|
+
@project = config[:project]
|
9
9
|
@name = config[:name]
|
10
10
|
@module_name = config[:name].gsub(/^_/, '')
|
11
11
|
@alias = config[:alias].nil? ? false : true
|
@@ -21,14 +21,18 @@ module Ninjs
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def generate_module_file
|
24
|
+
module_content = Array.new
|
25
|
+
module_content << "(function(#{@app_name if @alias}) {\n"
|
26
|
+
module_content << "\tvar mod = #{@app_name}.add_module('#{@name}');\n\n"
|
27
|
+
module_content << %Q{\t//= require "../elements/#{@name.downcase}.elements"\n} if @dependencies[:elements] || @type === 'elements'
|
28
|
+
module_content << %Q{\t//= require "../models/#{@name.downcase}.model"\n\n} if @dependencies[:model] || @type === 'model'
|
29
|
+
module_content << "\t#{@app_name}.#{@module_name}.actions = function() {\n\t\t\n\t};\n\n"
|
30
|
+
module_content << "\t#{@app_name}.#{@module_name}.run();\n"
|
31
|
+
module_content << "\n})(#{@project.config.name if @alias});"
|
32
|
+
|
33
|
+
|
24
34
|
File.open "#{@project.root}/#{@dest}/#{@name}.module.js", "w" do |file|
|
25
|
-
file <<
|
26
|
-
file << "\tvar self = #{@app_name}.add_module('#{@name}');\n\n"
|
27
|
-
file << %Q(\t//= require "../elements/#{@name.downcase}.elements"\n\n) if @dependencies[:elements] || @type === 'elements'
|
28
|
-
file << %Q(\t//= require "../models/#{@name.downcase}.model"\n\n) if @dependencies[:model] || @type === 'model'
|
29
|
-
file << "\t#{@app_name}.#{@module_name}.actions = function() {\n\n\t};\n\n"
|
30
|
-
file << "\t#{@app_name}.#{@module_name}.run();\n"
|
31
|
-
file << "})(#{@project.config.name});" if @alias
|
35
|
+
file << module_content.join('')
|
32
36
|
puts Ninjs::Notification.added "created #{@name.downcase}.module.js"
|
33
37
|
end unless File.exists? "#{@project.root}/#{@dest}/#{@name}.module.js"
|
34
38
|
|
@@ -37,7 +41,7 @@ module Ninjs
|
|
37
41
|
|
38
42
|
def generate_elements_file
|
39
43
|
File.open("#{@project.root}/elements/#{@module_name}" + ".elements.js", "w") do |file|
|
40
|
-
file <<
|
44
|
+
file << %Q{\tmod.dom.ready(function() {\n\t\t#{@app_name}.#{@module_name}.elements({\n\t\t\t\n\t\t});\n\t});\n}
|
41
45
|
puts Ninjs::Notification.added "created #{@module_name}.elements.js"
|
42
46
|
end unless File.exists? "#{@project.root}/elements/#{@module_name}.elements.js"
|
43
47
|
|
@@ -46,7 +50,7 @@ module Ninjs
|
|
46
50
|
|
47
51
|
def generate_model_file
|
48
52
|
File.open "#{@project.root}/models/#{@module_name}.model.js", "w" do |file|
|
49
|
-
file <<
|
53
|
+
file << %Q{\t#{@app_name}.#{@module_name}.set_data({\n\t\t\n\t});\n}
|
50
54
|
puts Ninjs::Notification.added "created #{@module_name}.model.js"
|
51
55
|
end unless File.exists? "#{@project.root}/models/#{@module_name}.model.js"
|
52
56
|
|
data/lib/ninjs/project.rb
CHANGED
@@ -75,10 +75,13 @@ module Ninjs
|
|
75
75
|
|
76
76
|
def import_test_files
|
77
77
|
FileUtils.cp "#{Ninjs::BASE_DIR}/repository/ninjs/tests/index.html", "#{@root}/tests"
|
78
|
-
FileUtils.cp "#{Ninjs::BASE_DIR}/repository/ninjs/tests/
|
79
|
-
FileUtils.cp "#{Ninjs::BASE_DIR}/repository/ninjs/tests/
|
80
|
-
FileUtils.cp "#{Ninjs::BASE_DIR}/repository/ninjs/tests/
|
81
|
-
FileUtils.cp "#{Ninjs::BASE_DIR}/repository/ninjs/tests/
|
78
|
+
FileUtils.cp "#{Ninjs::BASE_DIR}/repository/ninjs/tests/application.test.js", "#{@root}/tests"
|
79
|
+
FileUtils.cp "#{Ninjs::BASE_DIR}/repository/ninjs/tests/array.utilities.test.js", "#{@root}/tests"
|
80
|
+
FileUtils.cp "#{Ninjs::BASE_DIR}/repository/ninjs/tests/existence.test.js", "#{@root}/tests"
|
81
|
+
FileUtils.cp "#{Ninjs::BASE_DIR}/repository/ninjs/tests/extension.test.js", "#{@root}/tests"
|
82
|
+
FileUtils.cp "#{Ninjs::BASE_DIR}/repository/ninjs/tests/module.test.js", "#{@root}/tests"
|
83
|
+
FileUtils.cp "#{Ninjs::BASE_DIR}/repository/ninjs/tests/qspec.js", "#{@root}/tests"
|
84
|
+
FileUtils.cp "#{Ninjs::BASE_DIR}/repository/ninjs/tests/string.utilities.test.js", "#{@root}/tests"
|
82
85
|
end
|
83
86
|
|
84
87
|
def update
|
data/ninjs.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ninjs}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.14.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dayton Nolan"]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-05}
|
13
13
|
s.default_executable = %q{ninjs}
|
14
14
|
s.description = %q{Ninjs is a ruby application and small javascript framework that helps you build clean, modular javascript applications. Ninjs encourages "Good Parts" best practices and the Crockford school Module pattern (http://www.crockford.com/). The ninjs command line application is an automatic compiler, written in ruby, and based on the Sprockets library (http://getsprockets.org/).}
|
15
15
|
s.email = %q{daytonn@gmail.com}
|
@@ -122,6 +122,7 @@ Gem::Specification.new do |s|
|
|
122
122
|
"repository/ninjs/core/.extend.pdoc.yaml",
|
123
123
|
"repository/ninjs/core/.nin.pdoc.yaml",
|
124
124
|
"repository/ninjs/core/application.js",
|
125
|
+
"repository/ninjs/core/dom.js",
|
125
126
|
"repository/ninjs/core/existence.js",
|
126
127
|
"repository/ninjs/core/extend.js",
|
127
128
|
"repository/ninjs/core/module.js",
|
@@ -187,11 +188,14 @@ Gem::Specification.new do |s|
|
|
187
188
|
"repository/ninjs/docs/search/VariablesT.html",
|
188
189
|
"repository/ninjs/docs/styles/main.css",
|
189
190
|
"repository/ninjs/extensions/jquery.elements.js",
|
191
|
+
"repository/ninjs/tests/application.test.js",
|
192
|
+
"repository/ninjs/tests/array.utilities.test.js",
|
193
|
+
"repository/ninjs/tests/existence.test.js",
|
194
|
+
"repository/ninjs/tests/extension.test.js",
|
190
195
|
"repository/ninjs/tests/index.html",
|
191
|
-
"repository/ninjs/tests/
|
192
|
-
"repository/ninjs/tests/
|
193
|
-
"repository/ninjs/tests/
|
194
|
-
"repository/ninjs/tests/qunit/qunit.js",
|
196
|
+
"repository/ninjs/tests/module.test.js",
|
197
|
+
"repository/ninjs/tests/qspec.js",
|
198
|
+
"repository/ninjs/tests/string.utilities.test.js",
|
195
199
|
"repository/ninjs/utilities/all.js",
|
196
200
|
"repository/ninjs/utilities/array.js",
|
197
201
|
"repository/ninjs/utilities/cookie.js",
|
@@ -267,6 +271,7 @@ Gem::Specification.new do |s|
|
|
267
271
|
"repository/syntaxhighlighter/shBrushXml.js",
|
268
272
|
"repository/syntaxhighlighter/shCore.js",
|
269
273
|
"repository/syntaxhighlighter/shLegacy.js",
|
274
|
+
"spec/cli_spec.rb",
|
270
275
|
"spec/command_spec.rb",
|
271
276
|
"spec/configuration_spec.rb",
|
272
277
|
"spec/dependencies_spec.rb",
|
@@ -285,7 +290,13 @@ Gem::Specification.new do |s|
|
|
285
290
|
"spec/fixtures/hello.module.js",
|
286
291
|
"spec/fixtures/myapp.initial.js",
|
287
292
|
"spec/fixtures/myapp.js",
|
293
|
+
"spec/fixtures/mymodule.alias.module.js",
|
294
|
+
"spec/fixtures/mymodule.dependencies.module.js",
|
295
|
+
"spec/fixtures/mymodule.elements.js",
|
296
|
+
"spec/fixtures/mymodule.model.js",
|
297
|
+
"spec/fixtures/mymodule.module.js",
|
288
298
|
"spec/fixtures/new.ninjs.conf",
|
299
|
+
"spec/fixtures/nin.js",
|
289
300
|
"spec/fixtures/ninjs.conf",
|
290
301
|
"spec/generator_spec.rb",
|
291
302
|
"spec/helpers_spec.rb",
|
@@ -299,9 +310,10 @@ Gem::Specification.new do |s|
|
|
299
310
|
s.licenses = ["MIT"]
|
300
311
|
s.require_paths = ["lib"]
|
301
312
|
s.rubyforge_project = %q{nowarning}
|
302
|
-
s.rubygems_version = %q{1.
|
313
|
+
s.rubygems_version = %q{1.3.7}
|
303
314
|
s.summary = %q{ninjs is a command line application to help you write clean, modular javascript applications.}
|
304
315
|
s.test_files = [
|
316
|
+
"spec/cli_spec.rb",
|
305
317
|
"spec/command_spec.rb",
|
306
318
|
"spec/configuration_spec.rb",
|
307
319
|
"spec/dependencies_spec.rb",
|
@@ -315,6 +327,7 @@ Gem::Specification.new do |s|
|
|
315
327
|
]
|
316
328
|
|
317
329
|
if s.respond_to? :specification_version then
|
330
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
318
331
|
s.specification_version = 3
|
319
332
|
|
320
333
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
@@ -1,47 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
An NinjsApplication object serves as your application's namespace and includes a utility to add modules to the application object.
|
1
|
+
window.NinjsApplication = function(base_url, tests_path) {
|
2
|
+
if(is_defined(tests_path)) {
|
3
|
+
this.tests_path = tests_path;
|
4
|
+
}
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
if(is_defined(base_url)) {
|
7
|
+
this.site_url = function(path) {
|
8
|
+
var path = path || '';
|
9
|
+
return base_url + path;
|
10
|
+
};
|
11
|
+
}
|
12
|
+
};
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
if(is_defined(base_url)) {
|
17
|
-
this.site_url = function(path) {
|
18
|
-
var path = path || '';
|
19
|
-
return base_url + path;
|
20
|
-
};
|
21
|
-
}
|
22
|
-
};
|
14
|
+
NinjsApplication.method('add_module', function(name) {
|
15
|
+
if (is_undefined(name)) {
|
16
|
+
throw new SyntaxError("NinjsApplication.add_module(name): name is undefined");
|
17
|
+
}
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
Parameters:
|
29
|
-
name - the name of the module
|
30
|
-
|
31
|
-
> myapp.add_module('my_module');
|
32
|
-
*/
|
33
|
-
NinjsApplication.method('add_module', function(name) {
|
34
|
-
if (is_undefined(name)) {
|
35
|
-
throw new SyntaxError("NinjsApplication.add_module(name): name is undefined");
|
36
|
-
}
|
19
|
+
if (is_defined(this[name])) {
|
20
|
+
throw new SyntaxError("NinjsApplication.add_module(name): '" + name + "' already declared");
|
21
|
+
}
|
37
22
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
}
|
45
|
-
|
46
|
-
return this[name] = new NinjsModule(name);
|
47
|
-
});
|
23
|
+
if (this.name === name) {
|
24
|
+
throw new SyntaxError("NinjsApplication.add_module(name): a module cannot have the same name as the application");
|
25
|
+
}
|
26
|
+
|
27
|
+
return this[name] = new NinjsModule(name);
|
28
|
+
});
|
@@ -0,0 +1,139 @@
|
|
1
|
+
var userAgent = navigator.userAgent;
|
2
|
+
var browser = {
|
3
|
+
agent: userAgent,
|
4
|
+
mozilla: (/mozilla/.test(userAgent.toLowerCase())) && (!/(compatible|webkit)/.test(userAgent.toLowerCase())),
|
5
|
+
webkit: /webkit/.test(userAgent.toLowerCase()),
|
6
|
+
firefox: /firefox/.test(userAgent.toLowerCase()),
|
7
|
+
chrome: /webkit/.test(userAgent.toLowerCase()),
|
8
|
+
safari: /safari/.test(userAgent.toLowerCase()),
|
9
|
+
opera: /opera/.test(userAgent.toLowerCase()),
|
10
|
+
msie: (/msie/.test(userAgent.toLowerCase())) && (!/opera/.test( userAgent.toLowerCase() ))
|
11
|
+
};
|
12
|
+
|
13
|
+
var readyBound = false;
|
14
|
+
var isReady = false;
|
15
|
+
var readyList = [];
|
16
|
+
|
17
|
+
function domReady() {
|
18
|
+
if (!isReady) {
|
19
|
+
isReady = true;
|
20
|
+
if (readyList) {
|
21
|
+
for(var fn = 0; fn < readyList.length; fn++) {
|
22
|
+
readyList[fn].call(window, []);
|
23
|
+
}
|
24
|
+
readyList = [];
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
// From Simon Willison. A safe way to fire onload w/o screwing up everyone else.
|
30
|
+
function addLoadEvent(func) {
|
31
|
+
var oldonload = window.onload;
|
32
|
+
if (typeof window.onload != 'function') {
|
33
|
+
window.onload = func;
|
34
|
+
} else {
|
35
|
+
window.onload = function() {
|
36
|
+
if (oldonload) {
|
37
|
+
oldonload();
|
38
|
+
}
|
39
|
+
func();
|
40
|
+
}
|
41
|
+
}
|
42
|
+
};
|
43
|
+
|
44
|
+
// does the heavy work of working through the browsers idiosyncracies (let's call them that) to hook onload.
|
45
|
+
function bindReady() {
|
46
|
+
if (readyBound) {
|
47
|
+
return;
|
48
|
+
}
|
49
|
+
|
50
|
+
readyBound = true;
|
51
|
+
|
52
|
+
// Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
|
53
|
+
if (document.addEventListener && !browser.opera) {
|
54
|
+
// Use the handy event callback
|
55
|
+
document.addEventListener("DOMContentLoaded", domReady, false);
|
56
|
+
}
|
57
|
+
|
58
|
+
// If IE is used and is not in a frame
|
59
|
+
// Continually check to see if the document is ready
|
60
|
+
if (browser.msie && window == top) (function(){
|
61
|
+
if (isReady) return;
|
62
|
+
try {
|
63
|
+
// If IE is used, use the trick by Diego Perini
|
64
|
+
// http://javascript.nwbox.com/IEContentLoaded/
|
65
|
+
document.documentElement.doScroll("left");
|
66
|
+
} catch(error) {
|
67
|
+
setTimeout(arguments.callee, 0);
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
// and execute any waiting functions
|
71
|
+
domReady();
|
72
|
+
})();
|
73
|
+
|
74
|
+
if (browser.opera) {
|
75
|
+
document.addEventListener( "DOMContentLoaded", function () {
|
76
|
+
if (isReady) return;
|
77
|
+
for (var i = 0; i < document.styleSheets.length; i++)
|
78
|
+
if (document.styleSheets[i].disabled) {
|
79
|
+
setTimeout( arguments.callee, 0 );
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
// and execute any waiting functions
|
83
|
+
domReady();
|
84
|
+
}, false);
|
85
|
+
}
|
86
|
+
|
87
|
+
if (browser.safari) {
|
88
|
+
var numStyles;
|
89
|
+
(function(){
|
90
|
+
if (isReady) return;
|
91
|
+
if (document.readyState != "loaded" && document.readyState != "complete") {
|
92
|
+
setTimeout( arguments.callee, 0 );
|
93
|
+
return;
|
94
|
+
}
|
95
|
+
if (numStyles === undefined) {
|
96
|
+
var links = document.getElementsByTagName("link");
|
97
|
+
for (var i=0; i < links.length; i++) {
|
98
|
+
if (links[i].getAttribute('rel') == 'stylesheet') {
|
99
|
+
numStyles++;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
var styles = document.getElementsByTagName("style");
|
103
|
+
numStyles += styles.length;
|
104
|
+
}
|
105
|
+
if (document.styleSheets.length != numStyles) {
|
106
|
+
setTimeout( arguments.callee, 0 );
|
107
|
+
return;
|
108
|
+
}
|
109
|
+
|
110
|
+
// and execute any waiting functions
|
111
|
+
domReady();
|
112
|
+
})();
|
113
|
+
}
|
114
|
+
|
115
|
+
// A fallback to window.onload, that will always work
|
116
|
+
addLoadEvent(domReady);
|
117
|
+
};
|
118
|
+
|
119
|
+
window.NinjsDOM = function() {
|
120
|
+
this.cached_selectors = {};
|
121
|
+
};
|
122
|
+
|
123
|
+
// This is the public function that people can use to hook up ready.
|
124
|
+
NinjsDOM.method('ready', function(fn, args) {
|
125
|
+
// Attach the listeners
|
126
|
+
bindReady();
|
127
|
+
|
128
|
+
// If the DOM is already ready
|
129
|
+
if (isReady) {
|
130
|
+
// Execute the function immediately
|
131
|
+
fn.call(window, []);
|
132
|
+
}
|
133
|
+
else {
|
134
|
+
// Add the function to the wait list
|
135
|
+
readyList.push( function() { return fn.call(window, []); } );
|
136
|
+
}
|
137
|
+
});
|
138
|
+
|
139
|
+
bindReady();
|
@@ -1,277 +1,121 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
}
|
73
|
-
|
74
|
-
|
75
|
-
if (is_undefined(
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
};
|
123
|
-
}
|
124
|
-
|
125
|
-
if (is_undefined(is_array)) {
|
126
|
-
/*
|
127
|
-
Function: is_array
|
128
|
-
Determine if the suspect is an Array. This is a proxy method for is_typeof(Array, suspect).
|
129
|
-
|
130
|
-
Parameters:
|
131
|
-
suspect - suspect variable to test
|
132
|
-
|
133
|
-
Returns:
|
134
|
-
bool
|
135
|
-
|
136
|
-
See Also:
|
137
|
-
<is_typeof>,
|
138
|
-
<is_numeric>,
|
139
|
-
<is_string>,
|
140
|
-
<is_number>,
|
141
|
-
<is_date>,
|
142
|
-
<is_bool>,
|
143
|
-
<is_regex>
|
144
|
-
*/
|
145
|
-
var is_array = function(suspect) {
|
146
|
-
return is_typeof(Array, suspect);
|
147
|
-
};
|
148
|
-
}
|
149
|
-
|
150
|
-
if (is_undefined(is_number)) {
|
151
|
-
/*
|
152
|
-
Function: is_number
|
153
|
-
Determines if the suspect is a Number. This is a proxy method for is_typeof(Number, suspect).
|
154
|
-
|
155
|
-
Parameters:
|
156
|
-
suspect - suspect variable to test
|
157
|
-
|
158
|
-
Returns:
|
159
|
-
bool
|
160
|
-
|
161
|
-
See Also:
|
162
|
-
<is_typeof>,
|
163
|
-
<is_numeric>,
|
164
|
-
<is_string>,
|
165
|
-
<is_array>,
|
166
|
-
<is_date>,
|
167
|
-
<is_bool>,
|
168
|
-
<is_regex>
|
169
|
-
*/
|
170
|
-
var is_number = function(suspect) {
|
171
|
-
return is_typeof(Number, suspect);
|
172
|
-
};
|
173
|
-
}
|
174
|
-
|
175
|
-
if (is_undefined(is_date)) {
|
176
|
-
/*
|
177
|
-
Function: is_date
|
178
|
-
Determines if the suspect is a Date. This is a proxy method for is_typeof(Date, suspect).
|
179
|
-
|
180
|
-
Parameters:
|
181
|
-
suspect - suspect variable to test
|
182
|
-
|
183
|
-
Returns:
|
184
|
-
bool
|
185
|
-
|
186
|
-
See Also:
|
187
|
-
<is_typeof>,
|
188
|
-
<is_numeric>,
|
189
|
-
<is_string>,
|
190
|
-
<is_array>,
|
191
|
-
<is_number>,
|
192
|
-
<is_bool>,
|
193
|
-
<is_regex>
|
194
|
-
*/
|
195
|
-
var is_date = function(suspect) {
|
196
|
-
return is_typeof(Date, suspect);
|
197
|
-
};
|
198
|
-
}
|
199
|
-
|
200
|
-
if (is_undefined(is_bool)) {
|
201
|
-
/*
|
202
|
-
Function: is_bool
|
203
|
-
Determines if the suspect is a Boolean. This is a proxy method for is_typeof(Boolean, suspect).
|
204
|
-
|
205
|
-
Parameters:
|
206
|
-
suspect - suspect variable to test
|
207
|
-
|
208
|
-
Returns:
|
209
|
-
bool
|
210
|
-
|
211
|
-
See Also:
|
212
|
-
<is_typeof>,
|
213
|
-
<is_numeric>,
|
214
|
-
<is_string>,
|
215
|
-
<is_array>,
|
216
|
-
<is_number>,
|
217
|
-
<is_regex>
|
218
|
-
*/
|
219
|
-
var is_bool = function(suspect) {
|
220
|
-
return is_typeof(Boolean, suspect);
|
221
|
-
};
|
222
|
-
}
|
223
|
-
|
224
|
-
if (is_undefined(is_regex)) {
|
225
|
-
/*
|
226
|
-
Function: is_regex
|
227
|
-
Determines if the suspect is a RegExp. This is a proxy method for is_typeof(RegExp, suspect).
|
228
|
-
|
229
|
-
Parameters:
|
230
|
-
suspect - suspect variable to test
|
231
|
-
|
232
|
-
Returns:
|
233
|
-
bool
|
234
|
-
|
235
|
-
See Also:
|
236
|
-
<is_typeof>,
|
237
|
-
<is_numeric>,
|
238
|
-
<is_string>,
|
239
|
-
<is_array>,
|
240
|
-
<is_number>,
|
241
|
-
<is_bool>
|
242
|
-
*/
|
243
|
-
var is_regex = function(suspect) {
|
244
|
-
return is_typeof(RegExp, suspect);
|
245
|
-
};
|
246
|
-
}
|
247
|
-
|
248
|
-
|
249
|
-
if (is_undefined(is_empty)) {
|
250
|
-
/*
|
251
|
-
Function: is_empty
|
252
|
-
Determined if the suspect's length is less than one.
|
253
|
-
|
254
|
-
Parameters:
|
255
|
-
suspect - suspect variable to test
|
256
|
-
|
257
|
-
Returns: bool
|
258
|
-
*/
|
259
|
-
var is_empty = function(suspect) {
|
260
|
-
return suspect.length === 0;
|
261
|
-
};
|
262
|
-
}
|
263
|
-
|
264
|
-
if (is_undefined(is_not_empty)) {
|
265
|
-
/*
|
266
|
-
Function: is_not_empty
|
267
|
-
Determined if the suspect's length is greater than one.
|
268
|
-
|
269
|
-
Parameters:
|
270
|
-
suspect - suspect variable to test
|
271
|
-
|
272
|
-
Returns: bool
|
273
|
-
*/
|
274
|
-
var is_not_empty = function(suspect) {
|
275
|
-
return suspect.length >= 1;
|
276
|
-
};
|
277
|
-
}
|
1
|
+
if (window.is_defined === undefined) {
|
2
|
+
window.is_defined = function(suspect) {
|
3
|
+
return ((suspect === undefined) || (suspect === null)) ? false : true;
|
4
|
+
};
|
5
|
+
}
|
6
|
+
|
7
|
+
if (!is_defined(window.is_undefined)) {
|
8
|
+
window.is_undefined = function(suspect) {
|
9
|
+
return (suspect === undefined) ? true : false;
|
10
|
+
};
|
11
|
+
}
|
12
|
+
|
13
|
+
if (is_undefined(window.is_typeof)) {
|
14
|
+
window.is_typeof = function(type, suspect) {
|
15
|
+
if (is_undefined(type)) {
|
16
|
+
throw new SyntaxError("is_typeof(Type, suspect): type is undefined");
|
17
|
+
}
|
18
|
+
if (is_undefined(suspect)) {
|
19
|
+
throw new SyntaxError("is_typeof(Type, suspect): suspect is undefined");
|
20
|
+
}
|
21
|
+
|
22
|
+
return (suspect.constructor == type) ? true : false;
|
23
|
+
};
|
24
|
+
}
|
25
|
+
|
26
|
+
if (is_undefined(window.is_numeric)) {
|
27
|
+
window.is_numeric = function(suspect) {
|
28
|
+
if(is_typeof(Number, suspect)) {
|
29
|
+
return true;
|
30
|
+
}
|
31
|
+
else {
|
32
|
+
var pattern = /^-?\d+(?:\.\d*)?(?:e[+\-]?\d+)?$/i;
|
33
|
+
return pattern.test(suspect);
|
34
|
+
}
|
35
|
+
};
|
36
|
+
}
|
37
|
+
|
38
|
+
if (is_undefined(window.is_string)) {
|
39
|
+
window.is_string = function(suspect) {
|
40
|
+
return is_typeof(String, suspect);
|
41
|
+
};
|
42
|
+
}
|
43
|
+
|
44
|
+
if (is_undefined(window.is_array)) {
|
45
|
+
window.is_array = function(suspect) {
|
46
|
+
return is_typeof(Array, suspect);
|
47
|
+
};
|
48
|
+
}
|
49
|
+
|
50
|
+
if (is_undefined(window.is_number)) {
|
51
|
+
window.is_number = function(suspect) {
|
52
|
+
return is_typeof(Number, suspect);
|
53
|
+
};
|
54
|
+
}
|
55
|
+
|
56
|
+
if (is_undefined(window.is_date)) {
|
57
|
+
window.is_date = function(suspect) {
|
58
|
+
return is_typeof(Date, suspect);
|
59
|
+
};
|
60
|
+
}
|
61
|
+
|
62
|
+
if (is_undefined(window.is_bool)) {
|
63
|
+
window.is_bool = function(suspect) {
|
64
|
+
return is_typeof(Boolean, suspect);
|
65
|
+
};
|
66
|
+
}
|
67
|
+
|
68
|
+
if (is_undefined(window.is_regex)) {
|
69
|
+
window.is_regex = function(suspect) {
|
70
|
+
return is_typeof(RegExp, suspect);
|
71
|
+
};
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
if (is_undefined(window.is_empty)) {
|
76
|
+
window.is_empty = function(suspect) {
|
77
|
+
return suspect.length === 0;
|
78
|
+
};
|
79
|
+
}
|
80
|
+
|
81
|
+
if (is_undefined(window.is_not_empty)) {
|
82
|
+
window.is_not_empty = function(suspect) {
|
83
|
+
return suspect.length >= 1;
|
84
|
+
};
|
85
|
+
}
|
86
|
+
|
87
|
+
if (is_undefined(Function.prototype['method'])) {
|
88
|
+
Function.prototype.method = function(name, func) {
|
89
|
+
if (is_undefined(name)) {
|
90
|
+
throw new SyntaxError("Object.method(name, func): name is undefined");
|
91
|
+
}
|
92
|
+
|
93
|
+
if (is_undefined(func)) {
|
94
|
+
throw new SyntaxError("Object.method(name, func): func is undefined");
|
95
|
+
}
|
96
|
+
|
97
|
+
if (is_undefined(this.prototype[name])) {
|
98
|
+
this.prototype[name] = func;
|
99
|
+
return this;
|
100
|
+
}
|
101
|
+
};
|
102
|
+
}
|
103
|
+
|
104
|
+
if (is_undefined(window.unless)) {
|
105
|
+
window.unless = function(expression, callback, fallback) {
|
106
|
+
if (is_undefined(expression)) {
|
107
|
+
throw new SyntaxError("unless(expression, callback[, fallback]): expression is undefined");
|
108
|
+
}
|
109
|
+
|
110
|
+
if (is_undefined(callback)) {
|
111
|
+
throw new SyntaxError("unless(expression, callback[, fallback]): callback is undefined");
|
112
|
+
}
|
113
|
+
|
114
|
+
if (!expression) {
|
115
|
+
callback.call(this);
|
116
|
+
}
|
117
|
+
else if (is_defined(fallback)) {
|
118
|
+
fallback.call(this);
|
119
|
+
}
|
120
|
+
};
|
121
|
+
}
|