joosy 1.2.0.alpha.59 → 1.2.0.alpha.62
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -1
- data/.travis.yml +2 -1
- data/Gruntfile.coffee +50 -217
- data/bin/joosy +1 -1
- data/bower.json +1 -1
- data/build/joosy.js +5 -5
- data/{generators → lib/generators}/base.coffee +1 -1
- data/{generators → lib/generators}/command/command.coffee +1 -1
- data/{generators → lib/generators}/command/help.coffee +0 -0
- data/{generators → lib/generators}/layout.coffee +0 -0
- data/{generators → lib/generators}/page.coffee +0 -0
- data/{generators → lib/generators}/project.coffee +1 -1
- data/{generators → lib/generators}/project/base.coffee +0 -0
- data/{generators → lib/generators}/project/standalone.coffee +9 -4
- data/{generators → lib/generators}/templates/application/base/application.coffee +0 -0
- data/{generators → lib/generators}/templates/application/base/helpers/application.coffee +0 -0
- data/{generators → lib/generators}/templates/application/base/layouts/application.coffee +0 -0
- data/{generators → lib/generators}/templates/application/base/pages/application.coffee +0 -0
- data/{generators → lib/generators}/templates/application/base/pages/welcome/index.coffee +0 -0
- data/{generators → lib/generators}/templates/application/base/routes.coffee +0 -0
- data/{generators → lib/generators}/templates/application/base/templates/layouts/application.jst.hamlc +0 -0
- data/{generators → lib/generators}/templates/application/base/templates/pages/welcome/index.jst.hamlc +0 -0
- data/{generators → lib/generators}/templates/application/standalone/Gruntfile.coffee +11 -25
- data/{generators → lib/generators}/templates/application/standalone/Procfile +0 -0
- data/{generators → lib/generators}/templates/application/standalone/_gitignore +2 -2
- data/{generators/templates/application/standalone/source → lib/generators/templates/application/standalone/app}/haml/index.haml +0 -0
- data/{generators/templates/application/standalone/source → lib/generators/templates/application/standalone/app}/stylesheets/application.styl +0 -0
- data/{generators → lib/generators}/templates/application/standalone/bower.json +0 -0
- data/{generators → lib/generators}/templates/application/standalone/package.json +3 -0
- data/{generators → lib/generators}/templates/application/standalone/spec/application_spec.coffee +0 -0
- data/{generators → lib/generators}/templates/application/standalone/spec/helpers/environment.coffee +0 -0
- data/{generators → lib/generators}/templates/application/standalone/tasks/spec.coffee +0 -0
- data/{generators → lib/generators}/templates/layout/basic.coffee +0 -0
- data/{generators → lib/generators}/templates/layout/namespaced.coffee +0 -0
- data/{generators → lib/generators}/templates/page/basic.coffee +0 -0
- data/{generators → lib/generators}/templates/page/namespaced.coffee +0 -0
- data/{generators → lib/generators}/templates/widget/basic.coffee +0 -0
- data/{generators → lib/generators}/templates/widget/namespaced.coffee +0 -0
- data/{generators → lib/generators}/widget.coffee +0 -0
- data/lib/joosy.rb +2 -2
- data/lib/tasks/build.coffee +16 -0
- data/lib/tasks/doc.coffee +80 -0
- data/lib/tasks/publish.coffee +29 -0
- data/lib/tasks/testem.coffee +58 -0
- data/package.json +10 -15
- data/source/joosy/helpers/widgets.coffee +1 -1
- data/source/joosy/modules/events.coffee +1 -1
- data/source/joosy/router.coffee +2 -2
- data/source/joosy/templaters/jst.coffee +1 -1
- data/source/joosy/widget.coffee +2 -2
- data/spec/joosy/core/helpers/routes_spec.coffee +8 -2
- data/spec/joosy/core/router_spec.coffee +4 -4
- data/tasks/joosy.coffee +2 -0
- metadata +39 -42
- data/Gemfile +0 -6
- data/build/joosy/extensions/preloaders.js +0 -189
- data/source/joosy/extensions/preloaders/caching.coffee +0 -169
- data/source/joosy/extensions/preloaders/index.coffee +0 -1
- data/source/joosy/extensions/preloaders/inline.coffee +0 -56
- data/spec/joosy/extensions/preloaders/caching_spec.coffee +0 -36
- data/spec/joosy/extensions/preloaders/inline_spec.coffee +0 -16
@@ -184,11 +184,11 @@ describe "Joosy.Router", ->
|
|
184
184
|
|
185
185
|
it 'defines plain helper', ->
|
186
186
|
expect(Joosy.Helpers.Routes.rootPath()).toEqual '#'
|
187
|
-
expect(Joosy.Helpers.Routes.rootUrl()).toEqual "http
|
187
|
+
expect(Joosy.Helpers.Routes.rootUrl()).toEqual "http://#{location.host}#{pathname}#"
|
188
188
|
|
189
189
|
it 'defines namespaced parameterized helpers', ->
|
190
190
|
expect(Joosy.Helpers.Routes.sectionPagePath(id: 1)).toEqual '#section/page/1'
|
191
|
-
expect(Joosy.Helpers.Routes.sectionPageUrl(id: 1)).toEqual "http
|
191
|
+
expect(Joosy.Helpers.Routes.sectionPageUrl(id: 1)).toEqual "http://#{location.host}#{pathname}#section/page/1"
|
192
192
|
|
193
193
|
describe 'html5 based', ->
|
194
194
|
beforeEach ->
|
@@ -271,11 +271,11 @@ describe "Joosy.Router", ->
|
|
271
271
|
|
272
272
|
it 'defines plain helper', ->
|
273
273
|
expect(Joosy.Helpers.Routes.rootPath()).toEqual '/'
|
274
|
-
expect(Joosy.Helpers.Routes.rootUrl()).toEqual
|
274
|
+
expect(Joosy.Helpers.Routes.rootUrl()).toEqual "http://#{location.host}/"
|
275
275
|
|
276
276
|
it 'defines namespaced parameterized helpers', ->
|
277
277
|
expect(Joosy.Helpers.Routes.sectionPagePath(id: 1)).toEqual '/section/page/1'
|
278
|
-
expect(Joosy.Helpers.Routes.sectionPageUrl(id: 1)).toEqual
|
278
|
+
expect(Joosy.Helpers.Routes.sectionPageUrl(id: 1)).toEqual "http://#{location.host}/section/page/1"
|
279
279
|
|
280
280
|
describe 'linker', ->
|
281
281
|
it 'defines helper', ->
|
data/tasks/joosy.coffee
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joosy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0.alpha.
|
4
|
+
version: 1.2.0.alpha.62
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boris Staal
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-08-
|
13
|
+
date: 2013-08-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sprockets
|
@@ -49,57 +49,56 @@ files:
|
|
49
49
|
- .codoopts
|
50
50
|
- .gitignore
|
51
51
|
- .travis.yml
|
52
|
-
- Gemfile
|
53
52
|
- Gruntfile.coffee
|
54
53
|
- README.md
|
55
54
|
- bin/joosy
|
56
55
|
- bower.json
|
57
56
|
- build/joosy.js
|
58
|
-
- build/joosy/extensions/preloaders.js
|
59
57
|
- build/joosy/extensions/resources-form.js
|
60
58
|
- build/joosy/extensions/resources.js
|
61
|
-
- generators/base.coffee
|
62
|
-
- generators/command/command.coffee
|
63
|
-
- generators/command/help.coffee
|
64
|
-
- generators/layout.coffee
|
65
|
-
- generators/page.coffee
|
66
|
-
- generators/project.coffee
|
67
|
-
- generators/project/base.coffee
|
68
|
-
- generators/project/standalone.coffee
|
69
|
-
- generators/templates/application/base/application.coffee
|
70
|
-
- generators/templates/application/base/helpers/application.coffee
|
71
|
-
- generators/templates/application/base/layouts/application.coffee
|
72
|
-
- generators/templates/application/base/pages/application.coffee
|
73
|
-
- generators/templates/application/base/pages/welcome/index.coffee
|
74
|
-
- generators/templates/application/base/routes.coffee
|
75
|
-
- generators/templates/application/base/templates/layouts/application.jst.hamlc
|
76
|
-
- generators/templates/application/base/templates/pages/welcome/index.jst.hamlc
|
77
|
-
- generators/templates/application/standalone/Gruntfile.coffee
|
78
|
-
- generators/templates/application/standalone/Procfile
|
79
|
-
- generators/templates/application/standalone/_gitignore
|
80
|
-
- generators/templates/application/standalone/bower.json
|
81
|
-
- generators/templates/application/standalone/package.json
|
82
|
-
- generators/templates/application/standalone/source/haml/index.haml
|
83
|
-
- generators/templates/application/standalone/source/stylesheets/application.styl
|
84
|
-
- generators/templates/application/standalone/spec/application_spec.coffee
|
85
|
-
- generators/templates/application/standalone/spec/helpers/environment.coffee
|
86
|
-
- generators/templates/application/standalone/tasks/spec.coffee
|
87
|
-
- generators/templates/layout/basic.coffee
|
88
|
-
- generators/templates/layout/namespaced.coffee
|
89
|
-
- generators/templates/page/basic.coffee
|
90
|
-
- generators/templates/page/namespaced.coffee
|
91
|
-
- generators/templates/widget/basic.coffee
|
92
|
-
- generators/templates/widget/namespaced.coffee
|
93
|
-
- generators/widget.coffee
|
94
59
|
- joosy.gemspec
|
60
|
+
- lib/generators/base.coffee
|
61
|
+
- lib/generators/command/command.coffee
|
62
|
+
- lib/generators/command/help.coffee
|
63
|
+
- lib/generators/layout.coffee
|
64
|
+
- lib/generators/page.coffee
|
65
|
+
- lib/generators/project.coffee
|
66
|
+
- lib/generators/project/base.coffee
|
67
|
+
- lib/generators/project/standalone.coffee
|
68
|
+
- lib/generators/templates/application/base/application.coffee
|
69
|
+
- lib/generators/templates/application/base/helpers/application.coffee
|
70
|
+
- lib/generators/templates/application/base/layouts/application.coffee
|
71
|
+
- lib/generators/templates/application/base/pages/application.coffee
|
72
|
+
- lib/generators/templates/application/base/pages/welcome/index.coffee
|
73
|
+
- lib/generators/templates/application/base/routes.coffee
|
74
|
+
- lib/generators/templates/application/base/templates/layouts/application.jst.hamlc
|
75
|
+
- lib/generators/templates/application/base/templates/pages/welcome/index.jst.hamlc
|
76
|
+
- lib/generators/templates/application/standalone/Gruntfile.coffee
|
77
|
+
- lib/generators/templates/application/standalone/Procfile
|
78
|
+
- lib/generators/templates/application/standalone/_gitignore
|
79
|
+
- lib/generators/templates/application/standalone/app/haml/index.haml
|
80
|
+
- lib/generators/templates/application/standalone/app/stylesheets/application.styl
|
81
|
+
- lib/generators/templates/application/standalone/bower.json
|
82
|
+
- lib/generators/templates/application/standalone/package.json
|
83
|
+
- lib/generators/templates/application/standalone/spec/application_spec.coffee
|
84
|
+
- lib/generators/templates/application/standalone/spec/helpers/environment.coffee
|
85
|
+
- lib/generators/templates/application/standalone/tasks/spec.coffee
|
86
|
+
- lib/generators/templates/layout/basic.coffee
|
87
|
+
- lib/generators/templates/layout/namespaced.coffee
|
88
|
+
- lib/generators/templates/page/basic.coffee
|
89
|
+
- lib/generators/templates/page/namespaced.coffee
|
90
|
+
- lib/generators/templates/widget/basic.coffee
|
91
|
+
- lib/generators/templates/widget/namespaced.coffee
|
92
|
+
- lib/generators/widget.coffee
|
95
93
|
- lib/joosy.rb
|
94
|
+
- lib/tasks/build.coffee
|
95
|
+
- lib/tasks/doc.coffee
|
96
|
+
- lib/tasks/publish.coffee
|
97
|
+
- lib/tasks/testem.coffee
|
96
98
|
- package.json
|
97
99
|
- source/joosy.coffee
|
98
100
|
- source/joosy/application.coffee
|
99
101
|
- source/joosy/events/namespace.coffee
|
100
|
-
- source/joosy/extensions/preloaders/caching.coffee
|
101
|
-
- source/joosy/extensions/preloaders/index.coffee
|
102
|
-
- source/joosy/extensions/preloaders/inline.coffee
|
103
102
|
- source/joosy/extensions/resources-form/form.coffee
|
104
103
|
- source/joosy/extensions/resources-form/helpers/form.coffee
|
105
104
|
- source/joosy/extensions/resources-form/index.coffee
|
@@ -152,8 +151,6 @@ files:
|
|
152
151
|
- spec/joosy/environments/global_spec.coffee
|
153
152
|
- spec/joosy/extensions/form/form_spec.coffee
|
154
153
|
- spec/joosy/extensions/form/helpers/forms_spec.coffee
|
155
|
-
- spec/joosy/extensions/preloaders/caching_spec.coffee
|
156
|
-
- spec/joosy/extensions/preloaders/inline_spec.coffee
|
157
154
|
- spec/joosy/extensions/resources/base_spec.coffee
|
158
155
|
- spec/joosy/extensions/resources/collection_spec.coffee
|
159
156
|
- spec/joosy/extensions/resources/rest_collection_spec.coffee
|
data/Gemfile
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
(function() {
|
2
|
-
this.CachingPreloader = {
|
3
|
-
force: false,
|
4
|
-
prefix: "cache:",
|
5
|
-
counter: 0,
|
6
|
-
load: function(libraries, options) {
|
7
|
-
var i, key, lib, val, _i, _len, _ref, _ref1;
|
8
|
-
if (options == null) {
|
9
|
-
options = {};
|
10
|
-
}
|
11
|
-
for (key in options) {
|
12
|
-
val = options[key];
|
13
|
-
this[key] = val;
|
14
|
-
}
|
15
|
-
this.libraries = libraries.slice();
|
16
|
-
_ref = this.libraries;
|
17
|
-
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
18
|
-
lib = _ref[i];
|
19
|
-
this.libraries[i] = this.prefix + lib[0];
|
20
|
-
}
|
21
|
-
if (!this.force && this.check()) {
|
22
|
-
return this.restore();
|
23
|
-
} else {
|
24
|
-
if ((_ref1 = this.start) != null) {
|
25
|
-
_ref1.call(window);
|
26
|
-
}
|
27
|
-
this.clean();
|
28
|
-
return this.download(libraries);
|
29
|
-
}
|
30
|
-
},
|
31
|
-
check: function() {
|
32
|
-
var flag, i, name, _i, _len, _ref;
|
33
|
-
flag = true;
|
34
|
-
_ref = this.libraries;
|
35
|
-
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
36
|
-
name = _ref[i];
|
37
|
-
flag && (flag = window.localStorage.getItem(name) != null);
|
38
|
-
}
|
39
|
-
return flag;
|
40
|
-
},
|
41
|
-
escapeStr: function(str) {
|
42
|
-
return str.replace(new RegExp("\u0001", 'g'), "\\u0001").replace(new RegExp("\u000B", 'g'), "\\u000B");
|
43
|
-
},
|
44
|
-
restore: function() {
|
45
|
-
var i, name, _i, _len, _ref, _ref1;
|
46
|
-
_ref = this.libraries;
|
47
|
-
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
48
|
-
name = _ref[i];
|
49
|
-
window.evalGlobaly(window.localStorage.getItem(name));
|
50
|
-
}
|
51
|
-
return (_ref1 = this.complete) != null ? _ref1.call(window, true) : void 0;
|
52
|
-
},
|
53
|
-
download: function(libraries) {
|
54
|
-
var lib, size, url, _ref,
|
55
|
-
_this = this;
|
56
|
-
if (libraries.length > 0) {
|
57
|
-
this.counter += 1;
|
58
|
-
lib = libraries.shift();
|
59
|
-
url = lib[0];
|
60
|
-
size = lib[1];
|
61
|
-
return this.ajax(url, size, function(xhr) {
|
62
|
-
var code;
|
63
|
-
code = xhr.responseText;
|
64
|
-
if (window.navigator.appName === "Microsoft Internet Explorer") {
|
65
|
-
code = _this.escapeStr(code);
|
66
|
-
}
|
67
|
-
window.localStorage.setItem(_this.prefix + url, code);
|
68
|
-
window.evalGlobaly(xhr.responseText);
|
69
|
-
return _this.download(libraries);
|
70
|
-
});
|
71
|
-
} else {
|
72
|
-
return (_ref = this.complete) != null ? _ref.call(window) : void 0;
|
73
|
-
}
|
74
|
-
},
|
75
|
-
ajax: function(url, size, callback) {
|
76
|
-
var poller, x,
|
77
|
-
_this = this;
|
78
|
-
if (window.XMLHttpRequest) {
|
79
|
-
x = new XMLHttpRequest;
|
80
|
-
} else {
|
81
|
-
x = new ActiveXObject('Microsoft.XMLHTTP');
|
82
|
-
}
|
83
|
-
x.open('GET', url, 1);
|
84
|
-
x.onreadystatechange = function() {
|
85
|
-
if (x.readyState > 3) {
|
86
|
-
clearInterval(_this.interval);
|
87
|
-
return typeof callback === "function" ? callback(x) : void 0;
|
88
|
-
}
|
89
|
-
};
|
90
|
-
if (this.progress) {
|
91
|
-
poller = function() {
|
92
|
-
var e;
|
93
|
-
try {
|
94
|
-
return _this.progress.call(window, Math.round((x.responseText.length / size) * (_this.counter / _this.libraries.length) * 100));
|
95
|
-
} catch (_error) {
|
96
|
-
e = _error;
|
97
|
-
}
|
98
|
-
};
|
99
|
-
this.interval = setInterval(poller, 100);
|
100
|
-
}
|
101
|
-
return x.send();
|
102
|
-
},
|
103
|
-
clean: function() {
|
104
|
-
var find, i, key, _results;
|
105
|
-
i = 0;
|
106
|
-
find = function(arr, obj) {
|
107
|
-
var x, _i, _len;
|
108
|
-
for (_i = 0, _len = arr.length; _i < _len; _i++) {
|
109
|
-
x = arr[_i];
|
110
|
-
if (obj === x) {
|
111
|
-
return i;
|
112
|
-
}
|
113
|
-
}
|
114
|
-
return -1;
|
115
|
-
};
|
116
|
-
_results = [];
|
117
|
-
while (i < window.localStorage.length && (key = window.localStorage.key(i))) {
|
118
|
-
if (key.indexOf(this.prefix) === 0 && find(this.libraries, key) < 0) {
|
119
|
-
_results.push(window.localStorage.removeItem(key));
|
120
|
-
} else {
|
121
|
-
_results.push(i += 1);
|
122
|
-
}
|
123
|
-
}
|
124
|
-
return _results;
|
125
|
-
}
|
126
|
-
};
|
127
|
-
|
128
|
-
window.evalGlobaly = function(src) {
|
129
|
-
if (src.length === 0) {
|
130
|
-
return;
|
131
|
-
}
|
132
|
-
if (window.execScript) {
|
133
|
-
return window.execScript(src);
|
134
|
-
} else {
|
135
|
-
return window["eval"](src);
|
136
|
-
}
|
137
|
-
};
|
138
|
-
|
139
|
-
this.Preloader = this.CachingPreloader;
|
140
|
-
|
141
|
-
}).call(this);
|
142
|
-
(function() {
|
143
|
-
this.InlinePreloader = {
|
144
|
-
load: function(libraries, options) {
|
145
|
-
var key, val,
|
146
|
-
_this = this;
|
147
|
-
for (key in options) {
|
148
|
-
val = options[key];
|
149
|
-
this[key] = val;
|
150
|
-
}
|
151
|
-
if (typeof this.start === "function") {
|
152
|
-
this.start();
|
153
|
-
}
|
154
|
-
if (libraries.length > 0) {
|
155
|
-
return this.receive(libraries.shift()[0], function() {
|
156
|
-
return _this.load(libraries);
|
157
|
-
});
|
158
|
-
} else {
|
159
|
-
return typeof this.complete === "function" ? this.complete() : void 0;
|
160
|
-
}
|
161
|
-
},
|
162
|
-
receive: function(url, callback) {
|
163
|
-
var done, head, proceed, script;
|
164
|
-
head = document.getElementsByTagName("head")[0];
|
165
|
-
script = document.createElement("script");
|
166
|
-
script.src = url;
|
167
|
-
done = false;
|
168
|
-
proceed = function() {
|
169
|
-
if (!done && ((this.readyState == null) || this.readyState === "loaded" || this.readyState === "complete")) {
|
170
|
-
done = true;
|
171
|
-
if (typeof callback === "function") {
|
172
|
-
callback();
|
173
|
-
}
|
174
|
-
return script.onload = script.onreadystatechange = null;
|
175
|
-
}
|
176
|
-
};
|
177
|
-
script.onload = script.onreadystatechange = proceed;
|
178
|
-
head.appendChild(script);
|
179
|
-
return void 0;
|
180
|
-
}
|
181
|
-
};
|
182
|
-
|
183
|
-
this.Preloader = this.InlinePreloader;
|
184
|
-
|
185
|
-
}).call(this);
|
186
|
-
(function() {
|
187
|
-
|
188
|
-
|
189
|
-
}).call(this);
|
@@ -1,169 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Preloader for libraries with localStorage cache
|
3
|
-
#
|
4
|
-
# @note The `start` callback will only be called if loading required.
|
5
|
-
# While working with cache, `complete` is the only callback that will be triggered.
|
6
|
-
#
|
7
|
-
# @example Basic usage
|
8
|
-
# libraries = [['/test1.js', 100], ['/test2.js', 500]] #100, 500 - size in bytes
|
9
|
-
#
|
10
|
-
# CachingPreloader.load libraries,
|
11
|
-
# start: -> console.log 'preloading started'
|
12
|
-
# progress: (percent) -> console.log "#{percent}% loaded"
|
13
|
-
# complete: -> console.log 'preloading finished'
|
14
|
-
#
|
15
|
-
# @mixin
|
16
|
-
#
|
17
|
-
@CachingPreloader =
|
18
|
-
#
|
19
|
-
# If set to true, localStorage cache will be avoided
|
20
|
-
#
|
21
|
-
force: false
|
22
|
-
|
23
|
-
#
|
24
|
-
# Prefix for localStorage keys
|
25
|
-
#
|
26
|
-
prefix: "cache:"
|
27
|
-
|
28
|
-
#
|
29
|
-
# Number of libraries have been loaded (increases after lib was loaded)
|
30
|
-
#
|
31
|
-
counter: 0
|
32
|
-
|
33
|
-
#
|
34
|
-
# Loads (or takes from cache) set of libraries using xhr and caches them in localStorage
|
35
|
-
# See class description for example of usage
|
36
|
-
#
|
37
|
-
# @param [Array] 2-levels array of libraries URLs i.e. [['/test1.js', 10],['/test2.js', 20]]
|
38
|
-
# Second param of inner level is a size of script in bytes. Can be undefined.
|
39
|
-
# @param [Hash] Available options:
|
40
|
-
# * start: `() -> null` to call before load starts
|
41
|
-
# * progress: `(int percents) -> null` to call each 100ms of load in progress
|
42
|
-
# * complete: `() -> null` to call after load completes
|
43
|
-
#
|
44
|
-
load: (libraries, options={}) ->
|
45
|
-
@[key] = val for key, val of options
|
46
|
-
@libraries = libraries.slice()
|
47
|
-
|
48
|
-
for lib, i in @libraries
|
49
|
-
@libraries[i] = @prefix+lib[0]
|
50
|
-
|
51
|
-
if !@force && @check()
|
52
|
-
@restore()
|
53
|
-
else
|
54
|
-
@start?.call window
|
55
|
-
@clean()
|
56
|
-
@download libraries
|
57
|
-
|
58
|
-
#
|
59
|
-
# Checks if we can load libraries or have to download them over
|
60
|
-
#
|
61
|
-
check: ->
|
62
|
-
flag = true
|
63
|
-
for name, i in @libraries
|
64
|
-
flag &&= window.localStorage.getItem(name)?
|
65
|
-
flag
|
66
|
-
|
67
|
-
#
|
68
|
-
# Escapes non-printable terminal chars before storing to localStorage to prevent IE bug
|
69
|
-
#
|
70
|
-
# @param [String] String, that will be prepared for localStorage
|
71
|
-
#
|
72
|
-
escapeStr: (str) ->
|
73
|
-
str.replace(new RegExp("\u0001", 'g'), "\\u0001").replace(new RegExp("\u000B", 'g'), "\\u000B")
|
74
|
-
|
75
|
-
#
|
76
|
-
# Gets sources of scripts from localStorage and evals them
|
77
|
-
#
|
78
|
-
restore: ->
|
79
|
-
for name, i in @libraries
|
80
|
-
window.evalGlobaly window.localStorage.getItem name
|
81
|
-
@complete?.call window, true
|
82
|
-
|
83
|
-
#
|
84
|
-
# Loads set of libraries using xhr and caches them in localStorage
|
85
|
-
#
|
86
|
-
# @param [Array] 2-levels array of libraries URLs i.e. [['/test1.js', 100],['/test2.js', 500]]
|
87
|
-
# Second param of inner level is a size of script in bytes. Can be undefined.
|
88
|
-
#
|
89
|
-
download: (libraries) ->
|
90
|
-
if libraries.length > 0
|
91
|
-
@counter += 1
|
92
|
-
|
93
|
-
lib = libraries.shift()
|
94
|
-
url = lib[0]
|
95
|
-
size = lib[1]
|
96
|
-
|
97
|
-
@ajax url, size, (xhr) =>
|
98
|
-
code = xhr.responseText
|
99
|
-
if window.navigator.appName == "Microsoft Internet Explorer"
|
100
|
-
code = @escapeStr code
|
101
|
-
window.localStorage.setItem @prefix+url, code
|
102
|
-
window.evalGlobaly xhr.responseText
|
103
|
-
@download libraries
|
104
|
-
else
|
105
|
-
@complete?.call window
|
106
|
-
|
107
|
-
#
|
108
|
-
# Runs XHR request to get single script body
|
109
|
-
# Binds poller to call @progress each 100ms if possible (not IE *doh*)
|
110
|
-
#
|
111
|
-
# @param [String] URL to download from
|
112
|
-
# @param [Float] Expected size of download (to calculate percents)
|
113
|
-
# Size can not be taken from headers since we are supposed to get gziped content
|
114
|
-
# @param [Function] `(xhr) -> null` to call after script was loaded
|
115
|
-
#
|
116
|
-
ajax: (url, size, callback) ->
|
117
|
-
if window.XMLHttpRequest
|
118
|
-
x = new XMLHttpRequest
|
119
|
-
else
|
120
|
-
x = new ActiveXObject 'Microsoft.XMLHTTP'
|
121
|
-
|
122
|
-
x.open 'GET', url, 1
|
123
|
-
|
124
|
-
x.onreadystatechange = () =>
|
125
|
-
if x.readyState > 3
|
126
|
-
clearInterval @interval
|
127
|
-
callback? x
|
128
|
-
|
129
|
-
if @progress
|
130
|
-
poller = =>
|
131
|
-
try
|
132
|
-
@progress.call window, Math.round((x.responseText.length / size) * (@counter / @libraries.length) * 100)
|
133
|
-
catch e
|
134
|
-
# ... IE?
|
135
|
-
|
136
|
-
@interval = setInterval poller, 100
|
137
|
-
|
138
|
-
x.send()
|
139
|
-
|
140
|
-
#
|
141
|
-
# Searches through localStorage for outdated entries with our prefix and removes them
|
142
|
-
#
|
143
|
-
clean: ->
|
144
|
-
i = 0
|
145
|
-
|
146
|
-
find = (arr, obj) ->
|
147
|
-
(return i if obj == x) for x in arr
|
148
|
-
return -1
|
149
|
-
|
150
|
-
while i < window.localStorage.length && key = window.localStorage.key(i)
|
151
|
-
if key.indexOf(@prefix) == 0 && find(@libraries, key) < 0
|
152
|
-
window.localStorage.removeItem key
|
153
|
-
else
|
154
|
-
i += 1
|
155
|
-
|
156
|
-
#
|
157
|
-
# Evals source at a global scope
|
158
|
-
# Don't touch it! It should be window's property, or FF3.6 will execute scripts on preloader context.
|
159
|
-
#
|
160
|
-
# @param [String] JS source to execute
|
161
|
-
#
|
162
|
-
window.evalGlobaly = (src) ->
|
163
|
-
return if src.length == 0
|
164
|
-
if window.execScript
|
165
|
-
window.execScript src
|
166
|
-
else
|
167
|
-
window.eval src
|
168
|
-
|
169
|
-
@Preloader = @CachingPreloader
|