joosy 1.2.0.alpha.13 → 1.2.0.alpha.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bower.json +1 -1
- data/lib/joosy.js +27 -9
- data/package.json +1 -1
- data/spec/joosy/core/application_spec.coffee +2 -1
- data/spec/joosy/core/joosy_spec.coffee +1 -1
- data/spec/joosy/core/modules/log_spec.coffee +2 -2
- data/spec/joosy/core/router_spec.coffee +9 -9
- data/src/joosy/core/application.coffee +17 -3
- data/src/joosy/core/modules/log.coffee +2 -2
- data/src/joosy/core/router.coffee +1 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7efe3701ce2f216a6e1733e322573234cd19737
|
4
|
+
data.tar.gz: c41874a7bd7ce743e6f4c8232d5bad56acd4d8df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ac1bc38b42830cda852e9b46ff543d499d9057c7e290bc58b9d01b0995e5eb31604b05e8187f8dd87bbe37cf6de4dd659d95f4ba2baa29cc013a29cf2fbf1d7
|
7
|
+
data.tar.gz: 44265f5626c425a31c5ddcec40be293538a0b75e7d8d7f63a4b8ac92c116d3ee19d50befa8634c9c86a166b4457043d6cc6d747917b9549864ec726f23134d77
|
data/bower.json
CHANGED
data/lib/joosy.js
CHANGED
@@ -171,19 +171,24 @@ Joosy.Application = {
|
|
171
171
|
Controls: {},
|
172
172
|
loading: true,
|
173
173
|
identity: true,
|
174
|
-
debug: false,
|
175
174
|
debounceForms: false,
|
175
|
+
config: {
|
176
|
+
debug: false,
|
177
|
+
router: {
|
178
|
+
html5: false,
|
179
|
+
base: '/'
|
180
|
+
}
|
181
|
+
},
|
176
182
|
initialize: function(name, selector, options) {
|
177
|
-
var key, value;
|
178
183
|
this.name = name;
|
179
184
|
this.selector = selector;
|
180
185
|
if (options == null) {
|
181
186
|
options = {};
|
182
187
|
}
|
183
|
-
|
184
|
-
|
185
|
-
this[key] = value;
|
188
|
+
if (window.JoosyEnvironment != null) {
|
189
|
+
this.mergeConfig(window.JoosyEnvironment);
|
186
190
|
}
|
191
|
+
this.mergeConfig(options);
|
187
192
|
this.templater = new Joosy.Templaters.RailsJST(this.name);
|
188
193
|
Joosy.Router.__setupRoutes();
|
189
194
|
this.sandboxSelector = Joosy.uuid();
|
@@ -202,6 +207,19 @@ Joosy.Application = {
|
|
202
207
|
if (!attempt.halted) {
|
203
208
|
return this.page = attempt;
|
204
209
|
}
|
210
|
+
},
|
211
|
+
mergeConfig: function(options) {
|
212
|
+
var key, value, _results;
|
213
|
+
_results = [];
|
214
|
+
for (key in options) {
|
215
|
+
value = options[key];
|
216
|
+
if (Object.isObject(this.config[key])) {
|
217
|
+
_results.push(Object.merge(this.config[key], value));
|
218
|
+
} else {
|
219
|
+
_results.push(this.config[key] = value);
|
220
|
+
}
|
221
|
+
}
|
222
|
+
return _results;
|
205
223
|
}
|
206
224
|
};
|
207
225
|
|
@@ -324,7 +342,7 @@ Joosy.Modules.Log = {
|
|
324
342
|
debug: function() {
|
325
343
|
var args;
|
326
344
|
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
327
|
-
if (!Joosy.Application.debug) {
|
345
|
+
if (!Joosy.Application.config.debug) {
|
328
346
|
return;
|
329
347
|
}
|
330
348
|
return this.log.apply(this, args);
|
@@ -332,7 +350,7 @@ Joosy.Modules.Log = {
|
|
332
350
|
debugAs: function() {
|
333
351
|
var args, context, string;
|
334
352
|
context = arguments[0], string = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
335
|
-
if (!Joosy.Application.debug) {
|
353
|
+
if (!Joosy.Application.config.debug) {
|
336
354
|
return;
|
337
355
|
}
|
338
356
|
context = Joosy.Module.__className(context) || 'unknown context';
|
@@ -3303,9 +3321,9 @@ Joosy.Router = {
|
|
3303
3321
|
if (!history.pushState) {
|
3304
3322
|
this.__ignoreRequest = to;
|
3305
3323
|
location.hash = path;
|
3306
|
-
return setTimeout(function() {
|
3324
|
+
return setTimeout((function() {
|
3307
3325
|
return _this.__ignoreRequest = false;
|
3308
|
-
},
|
3326
|
+
}), 0);
|
3309
3327
|
} else {
|
3310
3328
|
return history[options.replaceState ? 'replaceState' : 'pushState']({}, '', '#' + path);
|
3311
3329
|
}
|
data/package.json
CHANGED
@@ -8,13 +8,14 @@ describe "Joosy.Application", ->
|
|
8
8
|
Joosy.Router.__setupRoutes.restore()
|
9
9
|
|
10
10
|
it "should initialize", ->
|
11
|
-
Joosy.Application.initialize 'app', '#application'
|
11
|
+
Joosy.Application.initialize 'app', '#application', router: {foo: 'bar'}
|
12
12
|
expect(Joosy.Application.page).toBeUndefined()
|
13
13
|
expect(Joosy.Application.selector).toEqual '#application'
|
14
14
|
expect(Joosy.Application.sandboxSelector).toMatch /#[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}/
|
15
15
|
expect($(Joosy.Application.sandboxSelector).length).toEqual 1
|
16
16
|
expect(Joosy.Router.__setupRoutes.callCount).toEqual 1
|
17
17
|
expect(Joosy.Application.name).toEqual 'app'
|
18
|
+
expect(Joosy.Application.config.router.foo).toEqual 'bar'
|
18
19
|
|
19
20
|
it "should set container", ->
|
20
21
|
expect(Joosy.Application.content()).toEqual $('#application')
|
@@ -9,7 +9,7 @@ describe "Joosy.Modules.Log", ->
|
|
9
9
|
@box.log 'message', 'appendix'
|
10
10
|
|
11
11
|
it "should log debug messages into console", ->
|
12
|
-
Joosy.Application.debug = true
|
12
|
+
Joosy.Application.config.debug = true
|
13
13
|
@box.debug 'debug message'
|
14
|
-
Joosy.Application.debug = false
|
14
|
+
Joosy.Application.config.debug = false
|
15
15
|
@box.debug 'unseen debug message'
|
@@ -7,20 +7,21 @@ describe "Joosy.Router", ->
|
|
7
7
|
section: sinon.spy()
|
8
8
|
wildcard: sinon.spy()
|
9
9
|
|
10
|
-
map =
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
'/
|
15
|
-
|
16
|
-
|
10
|
+
map =
|
11
|
+
Object.extended
|
12
|
+
'/': spies.root
|
13
|
+
'/page': TestPage
|
14
|
+
'/section':
|
15
|
+
'/page/:id': spies.section
|
16
|
+
'/page2/:more': TestPage
|
17
|
+
404: spies.wildcard
|
17
18
|
|
18
19
|
beforeEach ->
|
19
20
|
Joosy.Router.reset()
|
20
21
|
Joosy.Router.prefix = '!'
|
21
22
|
|
22
23
|
afterEach ->
|
23
|
-
$(window).
|
24
|
+
$(window).off 'hashchange'
|
24
25
|
|
25
26
|
it "should map", ->
|
26
27
|
Joosy.Router.map map
|
@@ -124,7 +125,6 @@ describe "Joosy.Router", ->
|
|
124
125
|
expect(location.hash).toEqual "#!test"
|
125
126
|
Joosy.Router.navigate ''
|
126
127
|
expect(location.hash).toEqual '#!'
|
127
|
-
location.hash = ''
|
128
128
|
|
129
129
|
it "should restrict urls", ->
|
130
130
|
sinon.stub Joosy.Router, '__respondRoute'
|
@@ -12,9 +12,14 @@ Joosy.Application =
|
|
12
12
|
|
13
13
|
loading: true
|
14
14
|
identity: true
|
15
|
-
debug: false
|
16
15
|
debounceForms: false
|
17
16
|
|
17
|
+
config:
|
18
|
+
debug: false
|
19
|
+
router:
|
20
|
+
html5: false
|
21
|
+
base: '/'
|
22
|
+
|
18
23
|
#
|
19
24
|
# Starts Joosy application by binding to element and bootstraping routes
|
20
25
|
#
|
@@ -23,7 +28,9 @@ Joosy.Application =
|
|
23
28
|
# @param [Object] options
|
24
29
|
#
|
25
30
|
initialize: (@name, @selector, options={}) ->
|
26
|
-
@
|
31
|
+
@mergeConfig(window.JoosyEnvironment) if window.JoosyEnvironment?
|
32
|
+
@mergeConfig(options)
|
33
|
+
|
27
34
|
@templater = new Joosy.Templaters.RailsJST @name
|
28
35
|
|
29
36
|
Joosy.Router.__setupRoutes()
|
@@ -52,4 +59,11 @@ Joosy.Application =
|
|
52
59
|
#
|
53
60
|
setCurrentPage: (page, params) ->
|
54
61
|
attempt = new page(params, @page)
|
55
|
-
@page = attempt unless attempt.halted
|
62
|
+
@page = attempt unless attempt.halted
|
63
|
+
|
64
|
+
mergeConfig: (options) ->
|
65
|
+
for key, value of options
|
66
|
+
if Object.isObject @config[key]
|
67
|
+
Object.merge @config[key], value
|
68
|
+
else
|
69
|
+
@config[key] = value
|
@@ -21,7 +21,7 @@ Joosy.Modules.Log =
|
|
21
21
|
# Runs `log` if debug is active
|
22
22
|
#
|
23
23
|
debug: (args...) ->
|
24
|
-
return unless Joosy.Application.debug
|
24
|
+
return unless Joosy.Application.config.debug
|
25
25
|
@log args...
|
26
26
|
|
27
27
|
#
|
@@ -31,6 +31,6 @@ Joosy.Modules.Log =
|
|
31
31
|
# @param [String] string Message to log
|
32
32
|
#
|
33
33
|
debugAs: (context, string, args...) ->
|
34
|
-
return unless Joosy.Application.debug
|
34
|
+
return unless Joosy.Application.config.debug
|
35
35
|
context = Joosy.Module.__className(context) || 'unknown context'
|
36
36
|
@debug "#{context}> #{string}", args...
|
@@ -98,9 +98,7 @@ Joosy.Router =
|
|
98
98
|
if !history.pushState
|
99
99
|
@__ignoreRequest = to
|
100
100
|
location.hash = path
|
101
|
-
setTimeout =>
|
102
|
-
@__ignoreRequest = false
|
103
|
-
, 2 # jQuery.hashchange checks hash changing every 1ms
|
101
|
+
setTimeout (=> @__ignoreRequest = false), 0
|
104
102
|
else
|
105
103
|
history[if options.replaceState then 'replaceState' else 'pushState'] {}, '', '#'+path
|
106
104
|
|