modjs-architecture 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/Gemfile +9 -3
- data/Gemfile.lock +49 -13
- data/{README.rdoc → README.md} +6 -4
- data/Rakefile +25 -4
- data/VERSION +1 -1
- data/lib/modjs-architecture.rb +122 -0
- data/lib/modjs-architecture/core/application.js +29 -0
- data/lib/modjs-architecture/core/dom.js +84 -0
- data/lib/modjs-architecture/core/module.js +65 -0
- data/lib/modjs-architecture/extensions/events.js +84 -0
- data/lib/modjs-architecture/helpers/existence.js +62 -0
- data/lib/modjs-architecture/jasmine/MIT.LICENSE +20 -0
- data/lib/modjs-architecture/jasmine/index.html +50 -0
- data/lib/modjs-architecture/jasmine/jasmine-html.js +190 -0
- data/lib/modjs-architecture/jasmine/jasmine.css +166 -0
- data/lib/modjs-architecture/jasmine/jasmine.js +2476 -0
- data/lib/modjs-architecture/jasmine/jasmine_favicon.png +0 -0
- data/lib/modjs-architecture/lib/mod.js +320 -0
- data/lib/modjs-architecture/modjs.architecture +6 -0
- data/lib/modjs-architecture/src/mod.js +9 -0
- data/modjs-architecture.gemspec +92 -0
- data/spec/fixtures/myapp.architecture +8 -0
- data/spec/fixtures/myapp.js +322 -0
- data/spec/fixtures/test.js +1 -0
- data/spec/fixtures/test.module.js +1 -0
- data/spec/fixtures/update.architecture +8 -0
- data/spec/fixtures/update.js +329 -0
- data/spec/javascripts/application_spec.js +23 -0
- data/spec/javascripts/dom_spec.js +49 -0
- data/spec/javascripts/existence_spec.js +143 -0
- data/spec/javascripts/module_spec.js +76 -0
- data/spec/javascripts/support/jasmine.css +229 -0
- data/spec/javascripts/support/jasmine.yml +73 -0
- data/spec/javascripts/support/jasmine_config.rb +23 -0
- data/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/spec/modjs-architecture_spec.rb +97 -4
- data/spec/spec_helper.rb +39 -8
- metadata +61 -22
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -5,9 +5,15 @@ source "http://rubygems.org"
|
|
5
5
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
gem "architecture-js", "~> 0.1.11"
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem 'simplecov', :require => false
|
12
|
+
end
|
13
|
+
|
8
14
|
group :development do
|
9
|
-
gem "rspec", "~> 2.
|
15
|
+
gem "rspec", "~> 2.8.0"
|
10
16
|
gem "bundler", "~> 1.0.0"
|
11
|
-
gem "jeweler", "~> 1.
|
12
|
-
gem "
|
17
|
+
gem "jeweler", "~> 1.8.3"
|
18
|
+
gem "jasmine", "~> 1.1.2"
|
13
19
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,28 +1,64 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
architecture-js (0.1.11)
|
5
|
+
fssm
|
6
|
+
fssm (~> 0.2.8.1)
|
7
|
+
jsmin
|
8
|
+
jsmin (~> 1.0.1)
|
9
|
+
sprockets (= 1.0.2)
|
10
|
+
sprockets (= 1.0.2)
|
11
|
+
childprocess (0.3.0)
|
12
|
+
ffi (~> 1.0.6)
|
4
13
|
diff-lcs (1.1.3)
|
14
|
+
ffi (1.0.11)
|
15
|
+
fssm (0.2.8.1)
|
5
16
|
git (1.2.5)
|
6
|
-
|
7
|
-
|
17
|
+
jasmine (1.1.2)
|
18
|
+
jasmine-core (>= 1.1.0)
|
19
|
+
rack (>= 1.1)
|
20
|
+
rspec (>= 1.3.1)
|
21
|
+
selenium-webdriver (>= 0.1.3)
|
22
|
+
jasmine-core (1.1.0)
|
23
|
+
jeweler (1.8.3)
|
24
|
+
bundler (~> 1.0)
|
8
25
|
git (>= 1.2.5)
|
9
26
|
rake
|
27
|
+
rdoc
|
28
|
+
jsmin (1.0.1)
|
29
|
+
json (1.6.5)
|
30
|
+
multi_json (1.0.4)
|
31
|
+
rack (1.4.1)
|
10
32
|
rake (0.9.2.2)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
rspec-
|
15
|
-
rspec-
|
16
|
-
|
17
|
-
rspec-
|
33
|
+
rdoc (3.12)
|
34
|
+
json (~> 1.4)
|
35
|
+
rspec (2.8.0)
|
36
|
+
rspec-core (~> 2.8.0)
|
37
|
+
rspec-expectations (~> 2.8.0)
|
38
|
+
rspec-mocks (~> 2.8.0)
|
39
|
+
rspec-core (2.8.0)
|
40
|
+
rspec-expectations (2.8.0)
|
18
41
|
diff-lcs (~> 1.1.2)
|
19
|
-
rspec-mocks (2.
|
42
|
+
rspec-mocks (2.8.0)
|
43
|
+
rubyzip (0.9.5)
|
44
|
+
selenium-webdriver (2.18.0)
|
45
|
+
childprocess (>= 0.2.5)
|
46
|
+
ffi (~> 1.0.9)
|
47
|
+
multi_json (~> 1.0.4)
|
48
|
+
rubyzip
|
49
|
+
simplecov (0.5.4)
|
50
|
+
multi_json (~> 1.0.3)
|
51
|
+
simplecov-html (~> 0.5.3)
|
52
|
+
simplecov-html (0.5.3)
|
53
|
+
sprockets (1.0.2)
|
20
54
|
|
21
55
|
PLATFORMS
|
22
56
|
ruby
|
23
57
|
|
24
58
|
DEPENDENCIES
|
59
|
+
architecture-js (~> 0.1.11)
|
25
60
|
bundler (~> 1.0.0)
|
26
|
-
|
27
|
-
|
28
|
-
rspec (~> 2.
|
61
|
+
jasmine (~> 1.1.2)
|
62
|
+
jeweler (~> 1.8.3)
|
63
|
+
rspec (~> 2.8.0)
|
64
|
+
simplecov
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
# modjs-architecture [![Build Status](https://secure.travis-ci.org/daytonn/modjs-architecture.png)](http://travis-ci.org/daytonn/modjs-architecture)
|
2
2
|
|
3
|
-
|
3
|
+
##About
|
4
4
|
|
5
|
-
|
5
|
+
Mod.js is a Javascript framework built specifically for the [ArchitectureJS](https://github.com/daytonn/architecture-js "ArchitectureJS") engine although it can be used as a stand-alone framework.
|
6
|
+
|
7
|
+
###contributing to architecture.js
|
6
8
|
|
7
9
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
10
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
@@ -12,7 +14,7 @@ Description goes here.
|
|
12
14
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
15
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
16
|
|
15
|
-
|
17
|
+
##Copyright
|
16
18
|
|
17
19
|
Copyright (c) 2011 Dayton Nolan. See LICENSE.txt for
|
18
20
|
further details.
|
data/Rakefile
CHANGED
@@ -7,13 +7,15 @@ rescue Bundler::BundlerError => e
|
|
7
7
|
$stderr.puts "Run `bundle install` to install missing gems"
|
8
8
|
exit e.status_code
|
9
9
|
end
|
10
|
+
|
11
|
+
require 'rake/dsl_definition'
|
10
12
|
require 'rake'
|
11
13
|
|
12
14
|
require 'jeweler'
|
13
15
|
Jeweler::Tasks.new do |gem|
|
14
16
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
17
|
gem.name = "modjs-architecture"
|
16
|
-
gem.homepage = "http://github.com/daytonn/
|
18
|
+
gem.homepage = "http://github.com/daytonn/modjs-architecture"
|
17
19
|
gem.license = "MIT"
|
18
20
|
gem.summary = %Q{Mod.js is an a la carte javascript framework}
|
19
21
|
gem.description = %Q{Mod.js is a modular javascript library that provides a base application strucure to build large javascript applications. Mod.js is designed to work with architecture.js.}
|
@@ -21,8 +23,8 @@ Jeweler::Tasks.new do |gem|
|
|
21
23
|
gem.authors = ["Dayton Nolan"]
|
22
24
|
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
25
|
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
-
#
|
25
|
-
#
|
26
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
27
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
28
|
end
|
27
29
|
Jeweler::RubygemsDotOrgTasks.new
|
28
30
|
|
@@ -39,7 +41,7 @@ end
|
|
39
41
|
|
40
42
|
task :default => :spec
|
41
43
|
|
42
|
-
require '
|
44
|
+
require 'rdoc/task'
|
43
45
|
Rake::RDocTask.new do |rdoc|
|
44
46
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
47
|
|
@@ -48,3 +50,22 @@ Rake::RDocTask.new do |rdoc|
|
|
48
50
|
rdoc.rdoc_files.include('README*')
|
49
51
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
52
|
end
|
53
|
+
|
54
|
+
begin
|
55
|
+
require 'jasmine'
|
56
|
+
load 'jasmine/tasks/jasmine.rake'
|
57
|
+
rescue LoadError
|
58
|
+
task :jasmine do
|
59
|
+
abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
task :travis do
|
64
|
+
["rake jasmine:ci"].each do |cmd|
|
65
|
+
puts "Starting to run #{cmd}..."
|
66
|
+
system("export DISPLAY=:99.0 && bundle exec #{cmd}")
|
67
|
+
raise "#{cmd} failed!" unless $?.exitstatus == 0
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
task :default => 'travis'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.1.0
|
data/lib/modjs-architecture.rb
CHANGED
@@ -0,0 +1,122 @@
|
|
1
|
+
module ModJS
|
2
|
+
BASE_DIR = File.expand_path("../..", __FILE__)
|
3
|
+
LIB_DIR = "#{BASE_DIR}/lib/modjs-architecture/lib"
|
4
|
+
|
5
|
+
class Project < ArchitectureJS::Project
|
6
|
+
# this line adds the default framework to ArchitectureJS
|
7
|
+
ArchitectureJS::register_framework 'modjs', self
|
8
|
+
|
9
|
+
def initialize(config, root = nil)
|
10
|
+
raise "#{self.class}.new({ name: 'myapp' }, options): config[:name] is undefined" unless config[:name]
|
11
|
+
|
12
|
+
@config = {
|
13
|
+
framework: 'modjs',
|
14
|
+
src_dir: 'modules',
|
15
|
+
build_dir: 'application',
|
16
|
+
dependencies: [],
|
17
|
+
autoload: []
|
18
|
+
}
|
19
|
+
@config.merge! config unless config.nil?
|
20
|
+
|
21
|
+
super(@config, root)
|
22
|
+
@directories = %w'application elements lib models modules plugins spec'
|
23
|
+
end
|
24
|
+
|
25
|
+
def create
|
26
|
+
super
|
27
|
+
copy_modjs_core_to_lib
|
28
|
+
copy_spec_files
|
29
|
+
puts ArchitectureJS::Notification.added "#{@config[:build_dir]}/#{@config[:name]}.js created"
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_file_name(module_path)
|
33
|
+
module_file = module_path.split(/[\\\/]/).last
|
34
|
+
module_filename = module_file.gsub(/\.module\.js$/, '')
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_application_file
|
38
|
+
app_file = "#{@root}/#{@config[:build_dir]}/#{@config[:name]}.js"
|
39
|
+
FileUtils.cp "#{LIB_DIR}/mod.js", app_file
|
40
|
+
File.open(app_file, 'a') { |f| f.write("\nvar #{@config[:name]} = new Mod.Application('#{@config[:name]}');") }
|
41
|
+
end
|
42
|
+
|
43
|
+
def copy_modjs_core_to_lib
|
44
|
+
FileUtils.cp "#{LIB_DIR}/mod.js", "#{@root}/lib/"
|
45
|
+
end
|
46
|
+
|
47
|
+
def copy_spec_files
|
48
|
+
FileUtils.mkdir "#{@root}/spec/jasmine"
|
49
|
+
FileUtils.cp "#{ModJS::BASE_DIR}/spec/javascripts/application_spec.js", "#{@root}/spec/application_spec.js"
|
50
|
+
FileUtils.cp "#{ModJS::BASE_DIR}/spec/javascripts/dom_spec.js", "#{@root}/spec/dom_spec.js"
|
51
|
+
FileUtils.cp "#{ModJS::BASE_DIR}/spec/javascripts/existence_spec.js", "#{@root}/spec/existence_spec.js"
|
52
|
+
FileUtils.cp "#{ModJS::BASE_DIR}/spec/javascripts/module_spec.js", "#{@root}/spec/module_spec.js"
|
53
|
+
FileUtils.cp "#{ModJS::BASE_DIR}/lib/modjs-architecture/jasmine/jasmine-html.js", "#{@root}/spec/jasmine/"
|
54
|
+
FileUtils.cp "#{ModJS::BASE_DIR}/lib/modjs-architecture/jasmine/jasmine.css", "#{@root}/spec/jasmine/"
|
55
|
+
FileUtils.cp "#{ModJS::BASE_DIR}/lib/modjs-architecture/jasmine/jasmine.js", "#{@root}/spec/jasmine/"
|
56
|
+
FileUtils.cp "#{ModJS::BASE_DIR}/lib/modjs-architecture/jasmine/jasmine_favicon.png", "#{@root}/spec/jasmine/"
|
57
|
+
FileUtils.cp "#{ModJS::BASE_DIR}/lib/modjs-architecture/jasmine/MIT.LICENSE", "#{@root}/spec/jasmine/"
|
58
|
+
FileUtils.cp "#{ModJS::BASE_DIR}/lib/modjs-architecture/jasmine/index.html", "#{@root}/spec/jasmine/"
|
59
|
+
end
|
60
|
+
|
61
|
+
def update
|
62
|
+
read_config
|
63
|
+
update_application_file
|
64
|
+
super
|
65
|
+
end
|
66
|
+
|
67
|
+
def update_application_file
|
68
|
+
app_file = "#{@root}/#{@config[:build_dir]}/#{@config[:name]}.js"
|
69
|
+
|
70
|
+
File.open(app_file, "w+") do |file|
|
71
|
+
write_dependencies(file)
|
72
|
+
write_core(file)
|
73
|
+
write_autoload(file)
|
74
|
+
end
|
75
|
+
|
76
|
+
ArchitectureJS::Notification.log "#{app_file} updated"
|
77
|
+
compile_application_file app_file
|
78
|
+
end
|
79
|
+
|
80
|
+
def write_dependencies(file)
|
81
|
+
if @config[:dependencies]
|
82
|
+
@config[:dependencies].each do |dependency|
|
83
|
+
file << "/*---------- ModJS dependency #{dependency} ----------*/\n"
|
84
|
+
file << "//= require #{dependency}\n\n" if dependency.match(/^\<.+\>$/)
|
85
|
+
file << "//= require \"#{dependency}\"\n\n" if dependency.match(/^[^\<].+|[^\>]$/)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def write_core(file)
|
91
|
+
file << "/*---------- ModJS ../lib/mod.js ----------*/\n"
|
92
|
+
file << "//= require \"../lib/mod.js\"\n\n"
|
93
|
+
file << "var #{@config[:name]} = new Mod.Application('#{@config[:name]}');\n\n"
|
94
|
+
end
|
95
|
+
|
96
|
+
def write_autoload(file)
|
97
|
+
if @config[:autoload]
|
98
|
+
@config[:autoload].each do |autoload|
|
99
|
+
file << "/*---------- ModJS autoload #{autoload} ----------*/\n"
|
100
|
+
file << "//= require #{autoload}\n\n" if autoload.match(/^\<.+\>$/)
|
101
|
+
file << "//= require \"#{autoload}\"\n\n" if autoload.match(/^[^\<].+|[^\>]$/)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def compile_application_file(file)
|
107
|
+
sprockets = Sprockets::Secretary.new(
|
108
|
+
root: ModJS::BASE_DIR,
|
109
|
+
asset_root: File.expand_path(@config[:asset_root], @root),
|
110
|
+
load_path: ['repository'],
|
111
|
+
source_files: [file]
|
112
|
+
)
|
113
|
+
|
114
|
+
application_file = sprockets.concatenation
|
115
|
+
application_file.save_to file
|
116
|
+
sprockets.install_assets
|
117
|
+
rescue Exception => error
|
118
|
+
@errors = true
|
119
|
+
puts ModJS::Notification.error "Sprockets error: #{error.message}"
|
120
|
+
end
|
121
|
+
end # class Project
|
122
|
+
end # module ArchitectureJS
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Mod.Application = (function() {
|
2
|
+
|
3
|
+
function Application(name) {
|
4
|
+
if (is_undefined(name)) {
|
5
|
+
throw new Error("new Mod.Application(name): name is undefined");
|
6
|
+
}
|
7
|
+
|
8
|
+
this.name = name
|
9
|
+
};
|
10
|
+
|
11
|
+
// add_module is a factory function to attach modules to the application object
|
12
|
+
Application.prototype.add_module = function(name) {
|
13
|
+
if (is_undefined(name)) {
|
14
|
+
throw new Error("Mod.Application.add_module(name): name is undefined");
|
15
|
+
}
|
16
|
+
|
17
|
+
if (is_defined(this[name])) {
|
18
|
+
throw new Error("Mod.Application.add_module('" + name + "'): '" + name + "' already declared");
|
19
|
+
}
|
20
|
+
|
21
|
+
if (this.name === name) {
|
22
|
+
throw new Error("Mod.Application.add_module('" + name + "'): a module cannot have the same name as the application. It's bad idea. Do you really want to write " + name + "." + name + "? It's confusing.'");
|
23
|
+
}
|
24
|
+
|
25
|
+
return this[name] = new Mod.Module(name);
|
26
|
+
};
|
27
|
+
|
28
|
+
return Application;
|
29
|
+
})();
|
@@ -0,0 +1,84 @@
|
|
1
|
+
Mod.DOM = (function() {
|
2
|
+
|
3
|
+
var timer,
|
4
|
+
queue = [];
|
5
|
+
|
6
|
+
function DOM() {
|
7
|
+
this.cache = {};
|
8
|
+
this.is_ready = false;
|
9
|
+
}
|
10
|
+
|
11
|
+
DOM.prototype.add_event = function(element, type, fn, capture) {
|
12
|
+
if (is_undefined(capture)) {
|
13
|
+
capture = false;
|
14
|
+
}
|
15
|
+
|
16
|
+
if (is_string(element)) {
|
17
|
+
element = this.cache[element];
|
18
|
+
}
|
19
|
+
|
20
|
+
element.addEventListener(type, fn, capture);
|
21
|
+
};
|
22
|
+
|
23
|
+
DOM.prototype.remove_event = function(element, type, fn, capture) {
|
24
|
+
if (is_undefined(capture)) {
|
25
|
+
capture = false;
|
26
|
+
}
|
27
|
+
|
28
|
+
if (is_string(element)) {
|
29
|
+
element = this.cache[element];
|
30
|
+
}
|
31
|
+
|
32
|
+
element.removeEventListener(type, fn, capture);
|
33
|
+
};
|
34
|
+
|
35
|
+
DOM.prototype.call_when_ready = function(func) {
|
36
|
+
// if DOM is already loaded execute the function
|
37
|
+
if (this.is_ready) {
|
38
|
+
return func();
|
39
|
+
}
|
40
|
+
|
41
|
+
// if timer is ticking
|
42
|
+
if (timer) {
|
43
|
+
queue.push(func);
|
44
|
+
}
|
45
|
+
// this is the first in the queue
|
46
|
+
else {
|
47
|
+
// attach to the load event, just in case it finishes first.
|
48
|
+
this.add_event(window, 'load', this.execute_ready_queue);
|
49
|
+
queue.push(func);
|
50
|
+
timer = setInterval(this.execute_ready_queue, 13);
|
51
|
+
}
|
52
|
+
};
|
53
|
+
|
54
|
+
DOM.prototype.execute_ready_queue = function() {
|
55
|
+
if (this.is_ready) {
|
56
|
+
return false;
|
57
|
+
}
|
58
|
+
|
59
|
+
if (document && document.getElementsByTagName && document.getElementById && document.body) {
|
60
|
+
clearInterval(timer);
|
61
|
+
timer = null;
|
62
|
+
for(var i = 0, j = queue.length; i < j; i++) {
|
63
|
+
queue[i]();
|
64
|
+
}
|
65
|
+
|
66
|
+
queue = [];
|
67
|
+
this.is_ready = true;
|
68
|
+
}
|
69
|
+
};
|
70
|
+
|
71
|
+
DOM.prototype.add_elements = function(elements) {
|
72
|
+
for(var key in elements) {
|
73
|
+
if (elements.hasOwnProperty(key)) {
|
74
|
+
this.add_element(key, elements[key]);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
79
|
+
DOM.prototype.add_element = function(key, element) {
|
80
|
+
this.cache[key] = element;
|
81
|
+
};
|
82
|
+
|
83
|
+
return DOM;
|
84
|
+
})();
|
@@ -0,0 +1,65 @@
|
|
1
|
+
Mod.Module = (function() {
|
2
|
+
|
3
|
+
function Module(name) {
|
4
|
+
if (is_undefined(name)) {
|
5
|
+
throw new Error("Mod.Module(name): name is undefined");
|
6
|
+
}
|
7
|
+
|
8
|
+
this.dom = new Mod.DOM;
|
9
|
+
this.data = {};
|
10
|
+
this.name = name;
|
11
|
+
}
|
12
|
+
|
13
|
+
Module.prototype.actions = function() {};
|
14
|
+
|
15
|
+
Module.prototype.run = function() {
|
16
|
+
var mod = this;
|
17
|
+
this.dom.call_when_ready(function() {
|
18
|
+
mod.execute();
|
19
|
+
});
|
20
|
+
};
|
21
|
+
|
22
|
+
Module.prototype.execute = function() {
|
23
|
+
this.actions();
|
24
|
+
};
|
25
|
+
|
26
|
+
Module.prototype.elements = function(elements) {
|
27
|
+
if (is_undefined(elements)) {
|
28
|
+
return this.dom.cache;
|
29
|
+
}
|
30
|
+
|
31
|
+
// Look up cached element by string key
|
32
|
+
if (is_string(elements)) {
|
33
|
+
var name = elements;
|
34
|
+
return this.dom.cache[name];
|
35
|
+
}
|
36
|
+
// cache the DOM objects
|
37
|
+
else {
|
38
|
+
this.dom.add_elements(elements);
|
39
|
+
}
|
40
|
+
};
|
41
|
+
|
42
|
+
Module.prototype.set_data = function(key, value) {
|
43
|
+
if (is_undefined(key)) {
|
44
|
+
throw new Error(this.name + '.set_data(key, value): key is undefined');
|
45
|
+
}
|
46
|
+
|
47
|
+
if (is_typeof(String, key) && is_undefined(value)) {
|
48
|
+
throw new SyntaxError(this.name + 'Module.set_data(key, value): value is undefined');
|
49
|
+
}
|
50
|
+
|
51
|
+
if (is_typeof(String, key)) {
|
52
|
+
this.data[key] = value;
|
53
|
+
}
|
54
|
+
else if (is_typeof(Object, key)) {
|
55
|
+
var data = key;
|
56
|
+
for(var property in data) {
|
57
|
+
this.data[property] = data[property];
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
return this;
|
62
|
+
};
|
63
|
+
|
64
|
+
return Module;
|
65
|
+
})();
|