bigpipe-rails 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +160 -0
- data/Guardfile +21 -0
- data/LICENSE.txt +20 -0
- data/README.md +0 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/assets/bigpipe.coffee +150 -0
- data/assets/bigpipe.js +164 -0
- data/bigpipe-rails.gemspec +153 -0
- data/lib/bigpipe_rails/helper.rb +36 -0
- data/lib/bigpipe_rails.rb +13 -0
- data/lib/engines.rb +16 -0
- data/qunit/.DS_Store +0 -0
- data/qunit/qunit.css +227 -0
- data/qunit/qunit.js +1450 -0
- data/qunit/tests.html +302 -0
- data/spec/dummy_app/.gitignore +5 -0
- data/spec/dummy_app/Gemfile +19 -0
- data/spec/dummy_app/Gemfile.lock +143 -0
- data/spec/dummy_app/README +261 -0
- data/spec/dummy_app/Rakefile +7 -0
- data/spec/dummy_app/app/assets/images/rails.png +0 -0
- data/spec/dummy_app/app/assets/javascripts/application.js +5 -0
- data/spec/dummy_app/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy_app/app/controllers/application_controller.rb +3 -0
- data/spec/dummy_app/app/controllers/test_controller.rb +8 -0
- data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
- data/spec/dummy_app/app/mailers/.gitkeep +0 -0
- data/spec/dummy_app/app/models/.gitkeep +0 -0
- data/spec/dummy_app/app/views/layouts/application.html.erb +18 -0
- data/spec/dummy_app/app/views/test/test.html.erb +3 -0
- data/spec/dummy_app/app/views/test/test_with_exception.html.erb +7 -0
- data/spec/dummy_app/config/application.rb +47 -0
- data/spec/dummy_app/config/boot.rb +6 -0
- data/spec/dummy_app/config/database.yml +25 -0
- data/spec/dummy_app/config/environment.rb +5 -0
- data/spec/dummy_app/config/environments/development.rb +27 -0
- data/spec/dummy_app/config/environments/production.rb +54 -0
- data/spec/dummy_app/config/environments/test.rb +39 -0
- data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy_app/config/initializers/inflections.rb +10 -0
- data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
- data/spec/dummy_app/config/initializers/secret_token.rb +7 -0
- data/spec/dummy_app/config/initializers/session_store.rb +8 -0
- data/spec/dummy_app/config/initializers/wrap_parameters.rb +12 -0
- data/spec/dummy_app/config/locales/en.yml +5 -0
- data/spec/dummy_app/config/routes.rb +62 -0
- data/spec/dummy_app/config/unicorn.rb +1 -0
- data/spec/dummy_app/config.ru +4 -0
- data/spec/dummy_app/db/seeds.rb +7 -0
- data/spec/dummy_app/lib/tasks/.gitkeep +0 -0
- data/spec/dummy_app/log/.gitkeep +0 -0
- data/spec/dummy_app/public/404.html +26 -0
- data/spec/dummy_app/public/422.html +26 -0
- data/spec/dummy_app/public/500.html +26 -0
- data/spec/dummy_app/public/favicon.ico +0 -0
- data/spec/dummy_app/public/index.html +241 -0
- data/spec/dummy_app/public/javascripts/bigpipe.js +164 -0
- data/spec/dummy_app/public/robots.txt +5 -0
- data/spec/dummy_app/script/rails +6 -0
- data/spec/dummy_app/spec/spec_helper.rb +26 -0
- data/spec/dummy_app/test/fixtures/.gitkeep +0 -0
- data/spec/dummy_app/test/functional/.gitkeep +0 -0
- data/spec/dummy_app/test/integration/.gitkeep +0 -0
- data/spec/dummy_app/test/integration/testabc_test.rb +9 -0
- data/spec/dummy_app/test/performance/browsing_test.rb +12 -0
- data/spec/dummy_app/test/test_helper.rb +13 -0
- data/spec/dummy_app/test/unit/.gitkeep +0 -0
- data/spec/dummy_app/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/dummy_app/vendor/plugins/.gitkeep +0 -0
- data/spec/lib/bigpipe_rails_spec.rb +18 -0
- data/spec/requests/bigpipe_request_spec.rb +21 -0
- data/spec/spec_helper.rb +28 -0
- metadata +277 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "rails", "3.1.0.rc4"
|
4
|
+
|
5
|
+
# Add dependencies to develop your gem here.
|
6
|
+
# Include everything needed to run rake, tests, features, etc.
|
7
|
+
group :development, :test do
|
8
|
+
gem "sqlite3"
|
9
|
+
gem "rspec-rails"
|
10
|
+
gem "bundler"
|
11
|
+
gem "jeweler"
|
12
|
+
gem "guard-rspec"
|
13
|
+
gem "guard-coffeescript"
|
14
|
+
gem "ruby-debug19", :require => "ruby-debug"
|
15
|
+
gem 'mocha'
|
16
|
+
gem 'unicorn'
|
17
|
+
gem 'factory_girl_rails'
|
18
|
+
gem 'rails3-generators'
|
19
|
+
gem 'growl'
|
20
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (3.1.0.rc4)
|
5
|
+
actionpack (= 3.1.0.rc4)
|
6
|
+
mail (~> 2.3.0)
|
7
|
+
actionpack (3.1.0.rc4)
|
8
|
+
activemodel (= 3.1.0.rc4)
|
9
|
+
activesupport (= 3.1.0.rc4)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
i18n (~> 0.6)
|
13
|
+
rack (~> 1.3.0)
|
14
|
+
rack-cache (~> 1.0.1)
|
15
|
+
rack-mount (~> 0.8.1)
|
16
|
+
rack-test (~> 0.6.0)
|
17
|
+
sprockets (~> 2.0.0.beta.10)
|
18
|
+
tzinfo (~> 0.3.27)
|
19
|
+
activemodel (3.1.0.rc4)
|
20
|
+
activesupport (= 3.1.0.rc4)
|
21
|
+
bcrypt-ruby (~> 2.1.4)
|
22
|
+
builder (~> 3.0.0)
|
23
|
+
i18n (~> 0.6)
|
24
|
+
activerecord (3.1.0.rc4)
|
25
|
+
activemodel (= 3.1.0.rc4)
|
26
|
+
activesupport (= 3.1.0.rc4)
|
27
|
+
arel (~> 2.1.1)
|
28
|
+
tzinfo (~> 0.3.27)
|
29
|
+
activeresource (3.1.0.rc4)
|
30
|
+
activemodel (= 3.1.0.rc4)
|
31
|
+
activesupport (= 3.1.0.rc4)
|
32
|
+
activesupport (3.1.0.rc4)
|
33
|
+
multi_json (~> 1.0)
|
34
|
+
archive-tar-minitar (0.5.2)
|
35
|
+
arel (2.1.3)
|
36
|
+
bcrypt-ruby (2.1.4)
|
37
|
+
builder (3.0.0)
|
38
|
+
coffee-script (2.2.0)
|
39
|
+
coffee-script-source
|
40
|
+
execjs
|
41
|
+
coffee-script-source (1.1.1)
|
42
|
+
columnize (0.3.4)
|
43
|
+
diff-lcs (1.1.2)
|
44
|
+
erubis (2.7.0)
|
45
|
+
execjs (1.2.0)
|
46
|
+
multi_json (~> 1.0)
|
47
|
+
factory_girl (2.0.1)
|
48
|
+
factory_girl_rails (1.1.0)
|
49
|
+
factory_girl (~> 2.0.0)
|
50
|
+
railties (>= 3.0.0)
|
51
|
+
git (1.2.5)
|
52
|
+
growl (1.0.3)
|
53
|
+
guard (0.5.1)
|
54
|
+
thor (~> 0.14.6)
|
55
|
+
guard-coffeescript (0.3.1)
|
56
|
+
coffee-script (>= 2.2.0)
|
57
|
+
guard (>= 0.4)
|
58
|
+
guard-rspec (0.4.0)
|
59
|
+
guard (>= 0.4.0)
|
60
|
+
hike (1.2.0)
|
61
|
+
i18n (0.6.0)
|
62
|
+
jeweler (1.6.4)
|
63
|
+
bundler (~> 1.0)
|
64
|
+
git (>= 1.2.5)
|
65
|
+
rake
|
66
|
+
kgio (2.6.0)
|
67
|
+
linecache19 (0.5.12)
|
68
|
+
ruby_core_source (>= 0.1.4)
|
69
|
+
mail (2.3.0)
|
70
|
+
i18n (>= 0.4.0)
|
71
|
+
mime-types (~> 1.16)
|
72
|
+
treetop (~> 1.4.8)
|
73
|
+
mime-types (1.16)
|
74
|
+
mocha (0.9.12)
|
75
|
+
multi_json (1.0.3)
|
76
|
+
polyglot (0.3.1)
|
77
|
+
rack (1.3.1)
|
78
|
+
rack-cache (1.0.2)
|
79
|
+
rack (>= 0.4)
|
80
|
+
rack-mount (0.8.1)
|
81
|
+
rack (>= 1.0.0)
|
82
|
+
rack-ssl (1.3.2)
|
83
|
+
rack
|
84
|
+
rack-test (0.6.0)
|
85
|
+
rack (>= 1.0)
|
86
|
+
rails (3.1.0.rc4)
|
87
|
+
actionmailer (= 3.1.0.rc4)
|
88
|
+
actionpack (= 3.1.0.rc4)
|
89
|
+
activerecord (= 3.1.0.rc4)
|
90
|
+
activeresource (= 3.1.0.rc4)
|
91
|
+
activesupport (= 3.1.0.rc4)
|
92
|
+
bundler (~> 1.0)
|
93
|
+
railties (= 3.1.0.rc4)
|
94
|
+
rails3-generators (0.17.4)
|
95
|
+
railties (>= 3.0.0)
|
96
|
+
railties (3.1.0.rc4)
|
97
|
+
actionpack (= 3.1.0.rc4)
|
98
|
+
activesupport (= 3.1.0.rc4)
|
99
|
+
rack-ssl (~> 1.3.2)
|
100
|
+
rake (>= 0.8.7)
|
101
|
+
rdoc (~> 3.4)
|
102
|
+
thor (~> 0.14.6)
|
103
|
+
raindrops (0.7.0)
|
104
|
+
rake (0.9.2)
|
105
|
+
rdoc (3.8)
|
106
|
+
rspec (2.6.0)
|
107
|
+
rspec-core (~> 2.6.0)
|
108
|
+
rspec-expectations (~> 2.6.0)
|
109
|
+
rspec-mocks (~> 2.6.0)
|
110
|
+
rspec-core (2.6.4)
|
111
|
+
rspec-expectations (2.6.0)
|
112
|
+
diff-lcs (~> 1.1.2)
|
113
|
+
rspec-mocks (2.6.0)
|
114
|
+
rspec-rails (2.6.1)
|
115
|
+
actionpack (~> 3.0)
|
116
|
+
activesupport (~> 3.0)
|
117
|
+
railties (~> 3.0)
|
118
|
+
rspec (~> 2.6.0)
|
119
|
+
ruby-debug-base19 (0.11.25)
|
120
|
+
columnize (>= 0.3.1)
|
121
|
+
linecache19 (>= 0.5.11)
|
122
|
+
ruby_core_source (>= 0.1.4)
|
123
|
+
ruby-debug19 (0.11.6)
|
124
|
+
columnize (>= 0.3.1)
|
125
|
+
linecache19 (>= 0.5.11)
|
126
|
+
ruby-debug-base19 (>= 0.11.19)
|
127
|
+
ruby_core_source (0.1.5)
|
128
|
+
archive-tar-minitar (>= 0.5.2)
|
129
|
+
sprockets (2.0.0.beta.10)
|
130
|
+
hike (~> 1.0)
|
131
|
+
rack (~> 1.0)
|
132
|
+
tilt (!= 1.3.0, ~> 1.1)
|
133
|
+
sqlite3 (1.3.3)
|
134
|
+
thor (0.14.6)
|
135
|
+
tilt (1.3.2)
|
136
|
+
treetop (1.4.9)
|
137
|
+
polyglot (>= 0.3.1)
|
138
|
+
tzinfo (0.3.29)
|
139
|
+
unicorn (4.0.1)
|
140
|
+
kgio (~> 2.4)
|
141
|
+
rack
|
142
|
+
raindrops (~> 0.6)
|
143
|
+
|
144
|
+
PLATFORMS
|
145
|
+
ruby
|
146
|
+
|
147
|
+
DEPENDENCIES
|
148
|
+
bundler
|
149
|
+
factory_girl_rails
|
150
|
+
growl
|
151
|
+
guard-coffeescript
|
152
|
+
guard-rspec
|
153
|
+
jeweler
|
154
|
+
mocha
|
155
|
+
rails (= 3.1.0.rc4)
|
156
|
+
rails3-generators
|
157
|
+
rspec-rails
|
158
|
+
ruby-debug19
|
159
|
+
sqlite3
|
160
|
+
unicorn
|
data/Guardfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^spec/.+_spec\.rb$})
|
11
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('spec/spec_helper.rb') { "spec" }
|
15
|
+
watch('config/routes.rb') { "spec/routing" }
|
16
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
17
|
+
# Capybara request specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
19
|
+
end
|
20
|
+
|
21
|
+
guard 'coffeescript', :input => 'assets'
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Dan Langevin
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
File without changes
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= bigpipe_rails
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to bigpipe_rails
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* 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
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Dan Langevin. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "bigpipe-rails"
|
18
|
+
gem.homepage = "http://github.com/dlangevin/bigpipe-rails"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Rails Engines Plugin to provide BigPipe functionality}
|
21
|
+
gem.description = %Q{Takes advantage of context switching and provides in Rails 3.1}
|
22
|
+
gem.email = "dan.langevin@gmail.com"
|
23
|
+
gem.authors = ["Dan Langevin"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "bigpipe_rails #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# Bigpipe - singleton/factory for PageletResources and Pagelets
|
2
|
+
class Bigpipe
|
3
|
+
# set up our instance variables to hold the CSS/JS PageletResources
|
4
|
+
constructor : ()->
|
5
|
+
@css = {}
|
6
|
+
@js = {}
|
7
|
+
@pagelets = []
|
8
|
+
|
9
|
+
# add a Pagelet to the stack, the Pagelet takes care of its own loading
|
10
|
+
add_pagelet : (data)=>
|
11
|
+
@pagelets.push(new Pagelet(data))
|
12
|
+
|
13
|
+
# some Pagelets will need the same css/js before initializing, make sure that
|
14
|
+
# we only load each resource once
|
15
|
+
get_resource : (file, type)=>
|
16
|
+
if type == "css"
|
17
|
+
@css[file] ?= new CssResource(file)
|
18
|
+
return @css[file]
|
19
|
+
else if type == "js"
|
20
|
+
@js[file] ?= new JsResource(file)
|
21
|
+
return @js[file]
|
22
|
+
|
23
|
+
# Load a resource
|
24
|
+
# Loading has 3 phases
|
25
|
+
# 0 - not on the page
|
26
|
+
# 1 - on the page but not finished loading
|
27
|
+
# 2 - loaded
|
28
|
+
class PageletResource
|
29
|
+
# get the file name and set load_phase to 0 (not started)
|
30
|
+
constructor : (file_name)->
|
31
|
+
@load_phase = 0
|
32
|
+
@file_name = file_name
|
33
|
+
# if load_phase is 2, we have completed loading
|
34
|
+
loaded : ()->
|
35
|
+
@load_phase == 2
|
36
|
+
# only call this once, we set load phase to 1 when the element is created
|
37
|
+
# and add a listener to the element's 'ready' callback to set it to 2
|
38
|
+
load : ()->
|
39
|
+
return if @load_phase > 0
|
40
|
+
@load_phase = 1
|
41
|
+
# handled in the subclass
|
42
|
+
this.create_element()
|
43
|
+
@el.ready(()=>
|
44
|
+
this.load_phase = 2
|
45
|
+
)
|
46
|
+
this
|
47
|
+
|
48
|
+
# concrete implementation for CSS
|
49
|
+
class CssResource extends PageletResource
|
50
|
+
create_element : ()->
|
51
|
+
@el = $j(document.createElement('link'))
|
52
|
+
@el.attr('rel', 'stylesheet').attr('href', "#{@file_name}.css")
|
53
|
+
@el
|
54
|
+
|
55
|
+
# concrete implementation for JS
|
56
|
+
class JsResource extends PageletResource
|
57
|
+
create_element : ()->
|
58
|
+
@el = $j(document.createElement('script'))
|
59
|
+
@el.attr('type', 'text/javascript').attr('src', "#{@file_name}.js")
|
60
|
+
@el
|
61
|
+
|
62
|
+
# a Pagelet is a composed of a container element, some HTML content and resources
|
63
|
+
# the order is as follows
|
64
|
+
# 1 - initialize Pagelet giving it the paths of its resources, its container, its content and any callbacks
|
65
|
+
# 2 - load all of the CSS, checking back every 20ms to see if the loading is complete
|
66
|
+
# 3 - put the HTML on the page
|
67
|
+
# 4 - load all of the JS, checking back every 20ms to see if the loading is complete
|
68
|
+
# 5 - call the on_load callback
|
69
|
+
class Pagelet
|
70
|
+
# constructor data
|
71
|
+
# - container - jQuery selector of the container to populate
|
72
|
+
# - content - HTML content to put in the container
|
73
|
+
# - css - Array of css files to load
|
74
|
+
# - js - Array of js files to load
|
75
|
+
# - append - Option to append the content to the container rather than replace its HTML
|
76
|
+
constructor : (data)->
|
77
|
+
@container = data.container
|
78
|
+
@content = data.content
|
79
|
+
@append = data.append || false
|
80
|
+
@css_resources = []
|
81
|
+
@js_resources = []
|
82
|
+
@on_load = data.on_load ? ()->
|
83
|
+
this.init_resources(data)
|
84
|
+
this.load_css()
|
85
|
+
# use Bigpipe's factory method to find or create the js and css resources
|
86
|
+
init_resources : (data)->
|
87
|
+
$j.each((data['css'] || []),(i, file)=>
|
88
|
+
this.css_resources.push(window.Bigpipe.get_resource(file, 'css'))
|
89
|
+
)
|
90
|
+
$j.each((data['js'] || []),(i, file)=>
|
91
|
+
this.js_resources.push(window.Bigpipe.get_resource(file, 'js'))
|
92
|
+
)
|
93
|
+
# first phase - load the css files
|
94
|
+
load_css : ()->
|
95
|
+
this.add_css()
|
96
|
+
# keep trying every 20ms til the loading of the CSS is complete
|
97
|
+
# TODO: this will lock up a browser if the CSS is never found - make sure to take care of that
|
98
|
+
unless this.css_loaded()
|
99
|
+
setTimeout(()=>
|
100
|
+
this.load_css()
|
101
|
+
, 20)
|
102
|
+
else
|
103
|
+
# once we've loaded the CSS, we move on to the HTML and JS
|
104
|
+
this.add_html()
|
105
|
+
this.load_js()
|
106
|
+
|
107
|
+
# final phase - load the js
|
108
|
+
# TODO: maybe make this before the HTML and use on_load to initialize
|
109
|
+
# listeners?
|
110
|
+
load_js : ()->
|
111
|
+
this.add_js()
|
112
|
+
unless this.js_loaded()
|
113
|
+
setTimeout(()=>
|
114
|
+
this.load_js()
|
115
|
+
,20)
|
116
|
+
else
|
117
|
+
this.on_load()
|
118
|
+
# check to seee if all of the css resources are loaded
|
119
|
+
css_loaded : ()->
|
120
|
+
loaded = true
|
121
|
+
$j.each(@css_resources, (i, resource)->
|
122
|
+
loaded = (loaded && resource.loaded())
|
123
|
+
)
|
124
|
+
return loaded
|
125
|
+
# check to see if all of the js resources are loaded
|
126
|
+
js_loaded : ()->
|
127
|
+
loaded = true
|
128
|
+
$j.each(@js_resources, (i, resource)->
|
129
|
+
loaded = (loaded && resource.loaded())
|
130
|
+
)
|
131
|
+
return loaded
|
132
|
+
# add and load a js resource
|
133
|
+
add_js : ()->
|
134
|
+
$j.each(@js_resources, (i, resource)->
|
135
|
+
resource.load()
|
136
|
+
)
|
137
|
+
# add and load a css resource
|
138
|
+
add_css : ()->
|
139
|
+
$j.each(@css_resources, (i, resource)->
|
140
|
+
resource.load()
|
141
|
+
)
|
142
|
+
# add htmlt to the container - replacing or appending as appropriate
|
143
|
+
add_html : ()->
|
144
|
+
unless @append
|
145
|
+
$j(@container).html(@content)
|
146
|
+
else
|
147
|
+
$j(@container).append(@content)
|
148
|
+
|
149
|
+
this.$j = jQuery.noConflict()
|
150
|
+
this.Bigpipe = new Bigpipe()
|