joosy 1.2.0.alpha.41 → 1.2.0.alpha.51

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Gruntfile.coffee +27 -7
  4. data/bin/joosy +1 -1
  5. data/bower.json +3 -2
  6. data/build/joosy/extensions/preloaders.js +189 -0
  7. data/build/joosy/extensions/resources-form.js +588 -0
  8. data/build/joosy/extensions/resources.js +673 -0
  9. data/build/joosy.js +2395 -0
  10. data/{src/joosy/generators → generators}/base.coffee +2 -2
  11. data/{src/joosy/generators → generators/command}/command.coffee +16 -3
  12. data/generators/command/help.coffee +38 -0
  13. data/{src/joosy/generators → generators}/layout.coffee +0 -0
  14. data/{src/joosy/generators → generators}/page.coffee +0 -0
  15. data/{src/joosy/generators → generators}/project/base.coffee +2 -4
  16. data/{src/joosy/generators → generators}/project/standalone.coffee +4 -3
  17. data/{src/joosy/generators → generators}/project.coffee +0 -0
  18. data/generators/templates/application/base/application.coffee +13 -0
  19. data/{templates → generators/templates}/application/base/helpers/application.coffee +0 -0
  20. data/{templates → generators/templates}/application/base/layouts/application.coffee +0 -0
  21. data/{templates → generators/templates}/application/base/pages/application.coffee +0 -0
  22. data/{templates → generators/templates}/application/base/pages/welcome/index.coffee +0 -0
  23. data/{templates → generators/templates}/application/base/routes.coffee +0 -0
  24. data/{templates → generators/templates}/application/base/templates/layouts/application.jst.hamlc +0 -0
  25. data/{templates → generators/templates}/application/base/templates/pages/welcome/index.jst.hamlc +0 -0
  26. data/{templates → generators/templates}/application/standalone/Gruntfile.coffee +1 -0
  27. data/{templates → generators/templates}/application/standalone/Procfile +0 -0
  28. data/{templates → generators/templates}/application/standalone/_gitignore +0 -0
  29. data/generators/templates/application/standalone/bower.json +17 -0
  30. data/{templates → generators/templates}/application/standalone/package.json +0 -0
  31. data/{templates → generators/templates}/application/standalone/source/haml/index.haml +0 -0
  32. data/{templates → generators/templates}/application/standalone/source/stylesheets/application.styl +0 -0
  33. data/{templates → generators/templates}/layout/basic.coffee +0 -0
  34. data/{templates → generators/templates}/layout/namespaced.coffee +0 -0
  35. data/{templates → generators/templates}/page/basic.coffee +0 -0
  36. data/{templates → generators/templates}/page/namespaced.coffee +0 -0
  37. data/{templates → generators/templates}/widget/basic.coffee +0 -0
  38. data/{templates → generators/templates}/widget/namespaced.coffee +0 -0
  39. data/{src/joosy/generators → generators}/widget.coffee +0 -0
  40. data/lib/joosy.rb +3 -3
  41. data/package.json +2 -3
  42. data/source/joosy/application.coffee +95 -0
  43. data/source/joosy/events/namespace.coffee +24 -0
  44. data/{src → source}/joosy/extensions/preloaders/caching.coffee +0 -0
  45. data/{src → source}/joosy/extensions/preloaders/index.coffee +0 -0
  46. data/{src → source}/joosy/extensions/preloaders/inline.coffee +0 -0
  47. data/{src → source}/joosy/extensions/resources/base.coffee +16 -8
  48. data/{src → source}/joosy/extensions/resources/collection.coffee +0 -0
  49. data/{src → source}/joosy/extensions/resources/index.coffee +0 -0
  50. data/{src → source}/joosy/extensions/resources/rest.coffee +0 -0
  51. data/{src → source}/joosy/extensions/resources/rest_collection.coffee +0 -0
  52. data/{src → source}/joosy/extensions/resources-form/form.coffee +18 -18
  53. data/{src → source}/joosy/extensions/resources-form/helpers/form.coffee +6 -6
  54. data/{src → source}/joosy/extensions/resources-form/index.coffee +0 -0
  55. data/source/joosy/helpers/routes.coffee +10 -0
  56. data/source/joosy/helpers/view.coffee +115 -0
  57. data/{src/joosy/core → source/joosy}/helpers/widgets.coffee +1 -1
  58. data/{src/joosy/core → source/joosy}/joosy.coffee +59 -19
  59. data/source/joosy/layout.coffee +73 -0
  60. data/{src/joosy/core → source/joosy}/module.coffee +7 -2
  61. data/{src/joosy/core/modules/container.coffee → source/joosy/modules/dom.coffee} +24 -17
  62. data/source/joosy/modules/events.coffee +156 -0
  63. data/source/joosy/modules/filters.coffee +67 -0
  64. data/{src/joosy/core → source/joosy}/modules/log.coffee +7 -3
  65. data/source/joosy/modules/page/scrolling.coffee +51 -0
  66. data/source/joosy/modules/page/title.coffee +18 -0
  67. data/{src/joosy/core → source/joosy}/modules/renderer.coffee +12 -13
  68. data/{src/joosy/core → source/joosy}/modules/time_manager.coffee +5 -1
  69. data/{src/joosy/core → source/joosy}/modules/widgets_manager.coffee +9 -5
  70. data/source/joosy/page.coffee +68 -0
  71. data/{src/joosy/core → source/joosy}/resources/watcher.coffee +5 -1
  72. data/source/joosy/router.coffee +305 -0
  73. data/{src/joosy/core → source/joosy}/templaters/jst.coffee +10 -7
  74. data/source/joosy/widget.coffee +385 -0
  75. data/source/joosy.coffee +1 -0
  76. data/{src/vendor → source}/metamorph.coffee +0 -0
  77. data/spec/helpers/matchers.coffee +8 -1
  78. data/spec/joosy/core/application_spec.coffee +121 -20
  79. data/spec/joosy/core/helpers/view_spec.coffee +3 -3
  80. data/spec/joosy/core/helpers/widgets_spec.coffee +3 -6
  81. data/spec/joosy/core/joosy_spec.coffee +0 -5
  82. data/spec/joosy/core/layout_spec.coffee +2 -28
  83. data/spec/joosy/core/modules/dom_spec.coffee +133 -0
  84. data/spec/joosy/core/modules/events_spec.coffee +16 -9
  85. data/spec/joosy/core/modules/filters_spec.coffee +232 -89
  86. data/spec/joosy/core/modules/log_spec.coffee +2 -2
  87. data/spec/joosy/core/modules/renderer_spec.coffee +8 -4
  88. data/spec/joosy/core/page_spec.coffee +2 -201
  89. data/spec/joosy/core/router_spec.coffee +295 -233
  90. data/spec/joosy/core/templaters/jst_spec.coffee +1 -1
  91. data/spec/joosy/core/widget_spec.coffee +373 -34
  92. data/spec/joosy/environments/amd_spec.coffee +38 -0
  93. data/spec/joosy/environments/global_spec.coffee +21 -0
  94. data/spec/joosy/extensions/form/form_spec.coffee +18 -18
  95. data/spec/joosy/extensions/form/helpers/forms_spec.coffee +1 -1
  96. data/spec/joosy/extensions/resources/base_spec.coffee +23 -11
  97. data/tasks/joosy.coffee +6 -9
  98. metadata +75 -69
  99. data/lib/extensions/preloaders.js +0 -193
  100. data/lib/extensions/resources-form.js +0 -592
  101. data/lib/extensions/resources.js +0 -675
  102. data/lib/joosy.js +0 -2199
  103. data/spec/joosy/core/modules/container_spec.coffee +0 -153
  104. data/spec/joosy/core/modules/widget_manager_spec.coffee +0 -96
  105. data/src/joosy/core/application.coffee +0 -59
  106. data/src/joosy/core/helpers/view.coffee +0 -52
  107. data/src/joosy/core/layout.coffee +0 -174
  108. data/src/joosy/core/modules/events.coffee +0 -188
  109. data/src/joosy/core/modules/filters.coffee +0 -42
  110. data/src/joosy/core/page.coffee +0 -383
  111. data/src/joosy/core/router.coffee +0 -313
  112. data/src/joosy/core/widget.coffee +0 -88
  113. data/src/joosy.coffee +0 -1
  114. data/templates/application/base/application.coffee +0 -9
  115. data/templates/application/standalone/bower.json +0 -7
@@ -1,188 +0,0 @@
1
- #= require joosy/core/joosy
2
-
3
- #
4
- # Basic events implementation
5
- #
6
- # @mixin
7
- #
8
- Joosy.Modules.Events =
9
-
10
- #
11
- # Waits for the list of given events to happen at least once. Then runs callback.
12
- #
13
- # @param [String|Array] events List of events to wait for separated by space
14
- # @param [Function] callback Action to run when all events were triggered at least once
15
- # @param [Hash] options Options
16
- #
17
- wait: (name, events, callback) ->
18
- @__oneShotEvents ||= {}
19
-
20
- # unnamed binding
21
- if Object.isFunction(events)
22
- callback = events
23
- events = name
24
- name = Object.keys(@__oneShotEvents).length.toString()
25
-
26
- @__oneShotEvents[name] = [@__splitEvents(events), callback]
27
- name
28
-
29
- #
30
- # Removes waiter action
31
- #
32
- # @param [Function] target Name of waiter to unbind
33
- #
34
- unwait: (target) ->
35
- delete @__oneShotEvents[target]
36
-
37
- #
38
- # Binds action to run each time any of given event was triggered
39
- #
40
- # @param [String|Array] events List of events separated by space
41
- # @param [Function] callback Action to run on trigger
42
- # @param [Hash] options Options
43
- #
44
- bind: (name, events, callback) ->
45
- @__boundEvents ||= {}
46
-
47
- # unnamed binding
48
- if Object.isFunction(events)
49
- callback = events
50
- events = name
51
- name = Object.keys(@__boundEvents).length.toString()
52
-
53
- @__boundEvents[name] = [@__splitEvents(events), callback]
54
- name
55
-
56
- #
57
- # Unbinds action from runing on trigger
58
- #
59
- # @param [Function] target Name of bind to unbind
60
- #
61
- unbind: (target) ->
62
- delete @__boundEvents[target]
63
-
64
- #
65
- # Triggers event for {bind} and {wait}
66
- #
67
- # @param [String] Name of event to trigger
68
- #
69
- trigger: (event, data...) ->
70
- Joosy.Modules.Log.debugAs @, "Event #{event} triggered"
71
-
72
- if @__oneShotEvents
73
- fire = []
74
- for name, [events, callback] of @__oneShotEvents
75
- events.remove event
76
- if events.length == 0
77
- fire.push name
78
- fire.each (name) =>
79
- callback = @__oneShotEvents[name][1]
80
- delete @__oneShotEvents[name]
81
- callback data...
82
-
83
- if @__boundEvents
84
- for name, [events, callback] of @__boundEvents
85
- if events.any event
86
- callback data...
87
-
88
- #
89
- # Runs set of callbacks finializing with result callback
90
- #
91
- # @example Basic usage
92
- # Joosy.synchronize (context) ->
93
- # contet.do (done) -> done()
94
- # contet.do (done) -> done()
95
- # content.after ->
96
- # console.log 'Success!'
97
- #
98
- # @param [Function] block Configuration block (see example)
99
- #
100
- synchronize: (block) ->
101
- context = new Joosy.Events.SynchronizationContext(@)
102
- block.call(@, context)
103
-
104
- if context.expectations.length == 0
105
- context.after.call(@)
106
- else
107
- @wait context.expectations, => context.after.call(@)
108
- context.actions.each (data) =>
109
- data[0].call @, =>
110
- @trigger data[1]
111
-
112
- __splitEvents: (events) ->
113
- if Object.isString events
114
- if events.isBlank()
115
- events = []
116
- else
117
- events = events.trim().split /\s+/
118
-
119
- unless Object.isArray(events) && events.length > 0
120
- throw new Error "#{Joosy.Module.__className @}> bind invalid events: #{events}"
121
-
122
- events
123
-
124
- #
125
- # Additional events helpers and tools
126
- #
127
- Joosy.namespace 'Joosy.Events', ->
128
- #
129
- # Events namespace
130
- #
131
- # Creates unified collection of bindings to a particular instance
132
- # that can be unbinded alltogether
133
- #
134
- # @example
135
- # namespace = Joosy.Events.Namespace(something)
136
- #
137
- # namespace.bind 'event1', ->
138
- # namespace.bind 'event2', ->
139
- # namespace.unbind() # unbinds both bindings
140
- #
141
- class @Namespace
142
- #
143
- # @param [Object] @parent Any instance that can trigger events
144
- #
145
- constructor: (@parent) ->
146
- @bindings = []
147
-
148
- bind: (args...) -> @bindings.push @parent.bind(args...)
149
- unbind: ->
150
- @parent.unbind b for b in @bindings
151
- @bindings = []
152
-
153
- #
154
- # Internal representation of {Joosy.Modules.Events.synchronize} context
155
- #
156
- # @see Joosy.Modules.Events.synchronize
157
- #
158
- class @SynchronizationContext
159
- @uid = 0
160
-
161
- constructor: (@parent) ->
162
- @expectations = []
163
- @actions = []
164
-
165
- #
166
- # Internal simple counter to separate given synchronization actions
167
- #
168
- uid: ->
169
- @constructor.uid += 1
170
-
171
- #
172
- # Registeres another async function that should be synchronized
173
- #
174
- # @param [Function] action `(Function) -> null` to call.
175
- # Should call given function to mark itself complete.
176
- #
177
- do: (action) ->
178
- event = "synchro-#{@uid()}"
179
- @expectations.push event
180
- @actions.push [action, event]
181
-
182
- #
183
- # Registers finalizer: the action that will be called when all do-functions
184
- # marked themselves as complete.
185
- #
186
- # @param [Function] after Function to call.
187
- #
188
- after: (@after) ->
@@ -1,42 +0,0 @@
1
- #= require joosy/core/joosy
2
-
3
- #
4
- # Filters registration routines
5
- #
6
- # @mixin
7
- #
8
- Joosy.Modules.Filters =
9
-
10
- #
11
- # Defines static registration routines
12
- #
13
- # @example Set of methods
14
- # class Test
15
- # @beforeLoad -> # supposed to run before load and control loading queue
16
- # @afterLoad -> # supposed to run after load to finalize loading
17
- # @afterUnload -> # supposed to run after unload to collect garbage
18
- #
19
- # # private
20
- #
21
- # @__runBeforeLoads() # Runs filters registered as beforeLoad
22
- # @__runAfterLoads() # Runs filters registered as afterLoad
23
- # @__runAfterUnloads() # Runs filters registered as afterUnload
24
- #
25
- included: ->
26
- ['beforeLoad', 'afterLoad', 'afterUnload'].each (filter) =>
27
- @[filter] = (callback) ->
28
- unless @::hasOwnProperty "__#{filter}s"
29
- @::["__#{filter}s"] = [].concat @.__super__["__#{filter}s"] || []
30
- @::["__#{filter}s"].push callback
31
-
32
-
33
- ['beforeLoad', 'afterLoad', 'afterUnload'].each (filter) =>
34
- camelized = filter.charAt(0).toUpperCase() + filter.slice(1);
35
-
36
- Joosy.Modules.Filters["__run#{camelized}s"] = (opts...) ->
37
- return true unless @["__#{filter}s"]
38
-
39
- @["__#{filter}s"].reduce (flag, func) =>
40
- func = @[func] unless Object.isFunction func
41
- flag && func.apply(@, opts) != false
42
- , true
@@ -1,383 +0,0 @@
1
- #= require joosy/core/joosy
2
- #= require joosy/core/modules/log
3
- #= require joosy/core/modules/events
4
- #= require joosy/core/modules/container
5
- #= require joosy/core/modules/renderer
6
- #= require joosy/core/modules/time_manager
7
- #= require joosy/core/modules/widgets_manager
8
- #= require joosy/core/modules/filters
9
-
10
- #
11
- # Base class for all of your Joosy Pages.
12
- # @see http://guides.joosy.ws/guides/blog/layouts-pages-and-routing.html
13
- #
14
- # @example Sample application page
15
- # class @RumbaPage extends Joosy.Layout
16
- # @view 'rumba'
17
- #
18
- # @include Joosy.Modules.Log
19
- # @include Joosy.Modules.Events
20
- # @include Joosy.Modules.Container
21
- # @include Joosy.Modules.Renderer
22
- # @include Joosy.Modules.TimeManager
23
- # @include Joosy.Modules.WidgetsManager
24
- # @include Joosy.Modules.Filters
25
- #
26
- class Joosy.Page extends Joosy.Module
27
- @include Joosy.Modules.Log
28
- @include Joosy.Modules.Events
29
- @include Joosy.Modules.Container
30
- @include Joosy.Modules.Renderer
31
- @include Joosy.Modules.TimeManager
32
- @include Joosy.Modules.WidgetsManager
33
- @include Joosy.Modules.Filters
34
-
35
- halted: false
36
-
37
- #
38
- # Default layout is no layout.
39
- #
40
- layout: false
41
-
42
- #
43
- # Previous page.
44
- #
45
- previous: false
46
-
47
- #
48
- # Route params.
49
- #
50
- params: false
51
-
52
- #
53
- # Prefetched page data.
54
- #
55
- data: false
56
- dataFetched: false
57
-
58
- #
59
- # Sets layout for current page
60
- #
61
- # @param [Class] layoutClass Layout to use
62
- #
63
- @layout: (layoutClass) ->
64
- @::__layoutClass = layoutClass
65
-
66
- #
67
- # Sets the method which will controll the painting preparation proccess.
68
- #
69
- # This method will be called right ater previous page {Joosy.Page.erase} and in parallel with
70
- # page data fetching so you can use it to initiate preloader.
71
- #
72
- # @note Given method will be called with `complete` function as parameter. As soon as your
73
- # preparations are done you should call that function.
74
- #
75
- # @example Sample before painter
76
- # @beforePaint (container, complete) ->
77
- # if !@data # checks if parallel fetching finished
78
- # $('preloader').slideDown -> complete()
79
- #
80
- #
81
- @beforePaint: (callback) ->
82
- @::__beforePaint = callback
83
-
84
- #
85
- # Sets the method which will controll the painting proccess.
86
- #
87
- # This method will be called after fetching, erasing and beforePaint is complete.
88
- # It should be used to setup appearance effects of page.
89
- #
90
- # @note Given method will be called with `complete` function as parameter. As soon as your
91
- # preparations are done you should call that function.
92
- #
93
- # @example Sample painter
94
- # @paint (container, complete) ->
95
- # @container.fadeIn -> complete()
96
- #
97
- @paint: (callback) ->
98
- @::__paint = callback
99
-
100
- @afterPaint: (callback) ->
101
- @::__afterPaint = callback
102
-
103
- #
104
- # Sets the method which will controll the erasing proccess.
105
- #
106
- # Use this method to setup hiding effect.
107
- #
108
- # @note Given method will be called with `complete` function as parameter. As soon as your
109
- # preparations are done you should call that function.
110
- #
111
- # @note This method will be caled _before_ unload routines so in theory you can
112
- # access page data from that. Think twice if you are doing it right though.
113
- #
114
- # @example Sample eraser
115
- # @erase (container, complete) ->
116
- # @container.fadeOut -> complete()
117
- #
118
- @erase: (callback) ->
119
- @::__erase = callback
120
-
121
- #
122
- # Sets the method which will controll the data fetching proccess.
123
- #
124
- # @note Given method will be called with `complete` function as parameter. As soon as your
125
- # preparations are done you should call that function.
126
- #
127
- # @example Basic usage
128
- # @fetch (complete) ->
129
- # $.get '/rumbas', (@data) => complete()
130
- #
131
- @fetch: (callback) ->
132
- @::__fetch = (complete) ->
133
- @data = {}
134
- callback.call this, =>
135
- @dataFetched = true
136
- complete()
137
-
138
- #
139
- # Sets the several separate methods that will fetch data in parallel.
140
- #
141
- # @note This will work through {Joosy.Modules.Events.synchronize}
142
- #
143
- # @example Basic usage
144
- # @fetchSynchronized (context) ->
145
- # context.do (done) ->
146
- # $.get '/rumbas', (data) =>
147
- # @data.rumbas = data
148
- # done()
149
- #
150
- # context.do (done) ->
151
- # $.get '/kutuzkas', (data) =>
152
- # @data.kutuzkas = data
153
- # done()
154
- #
155
- @fetchSynchronized: (callback) ->
156
- @::__fetch = (complete) ->
157
- @synchronize (context) ->
158
- context.after -> complete()
159
- callback.call(this, context)
160
-
161
- #
162
- # Sets the position where page will be scrolled to after load.
163
- #
164
- # @note If you use animated scroll joosy will atempt to temporarily fix the
165
- # height of your document while scrolling to prevent jump effect.
166
- #
167
- # @param [jQuery] element Element to scroll to
168
- # @param [Hash] options
169
- #
170
- # @option options [Integer] speed Sets the animation duration (500 is default)
171
- # @option options [Integer] margin Defines the margin from element position.
172
- # Can be negative.
173
- #
174
- @scroll: (element, options={}) ->
175
- @::__scrollElement = element
176
- @::__scrollSpeed = options.speed || 500
177
- @::__scrollMargin = options.margin || 0
178
-
179
- #
180
- # Scrolls page to stored positions
181
- #
182
- __performScrolling: ->
183
- scroll = $(@__extractSelector @__scrollElement).offset()?.top + @__scrollMargin
184
- Joosy.Modules.Log.debugAs @, "Scrolling to #{@__extractSelector @__scrollElement}"
185
- $('html, body').animate {scrollTop: scroll}, @__scrollSpeed, =>
186
- if @__scrollSpeed != 0
187
- @__releaseHeight()
188
-
189
- #
190
- # Sets the page HTML title.
191
- #
192
- # @note Title will be reverted on unload.
193
- #
194
- # @param [String] title Title to set.
195
- #
196
- @title: (title, separator=' / ') ->
197
- @afterLoad ->
198
- titleStr = if Object.isFunction(title) then title.apply(this) else title
199
- titleStr = titleStr.join(separator) if Object.isArray(titleStr)
200
- @__previousTitle = document.title
201
- document.title = titleStr
202
-
203
- @afterUnload ->
204
- document.title = @__previousTitle
205
-
206
- #
207
- # Constructor is very destructive (c), it calls bootstrap directly so use with caution.
208
- #
209
- # @params [Hash] params Route params
210
- # @params [Joosy.Page] previous Previous page to unload
211
- #
212
- constructor: (@params, @previous) ->
213
- @__layoutClass ||= ApplicationLayout
214
-
215
- unless @halted = !@__runBeforeLoads(@params, @previous)
216
- Joosy.Application.loading = true
217
-
218
- if !@previous?.layout?.uid? || @previous?.__layoutClass != @__layoutClass
219
- @__bootstrapLayout()
220
- else
221
- @__bootstrap()
222
-
223
- #
224
- # @see Joosy.Router.navigate
225
- #
226
- navigate: (args...) ->
227
- Joosy.Router.navigate(args...)
228
-
229
- #
230
- # This is required by {Joosy.Modules.Renderer}
231
- # Sets the base template dir to app_name/templates/pages
232
- #
233
- __renderSection: ->
234
- 'pages'
235
-
236
- #
237
- # Freezes the page height through $(html).
238
- #
239
- # Required to implement better {Joosy.Page.scroll} behavior.
240
- #
241
- __fixHeight: ->
242
- $('html').css 'min-height', $(document).height()
243
-
244
- #
245
- # Undo {#__fixHeight}
246
- #
247
- __releaseHeight: ->
248
- $('html').css 'min-height', ''
249
-
250
- #
251
- # Page bootstrap proccess
252
- #
253
- # * {Joosy.Modules.Container.__assignElements}
254
- # * {Joosy.Modules.Container.__delegateEvents}
255
- # * {Joosy.Modules.WidgetsManager.__setupWidgets}
256
- # * Scrolling
257
- #
258
- __load: ->
259
- @__assignElements()
260
- @__delegateEvents()
261
- @__setupWidgets()
262
- @__runAfterLoads @params, @previous
263
- @__performScrolling() if @__scrollElement
264
- Joosy.Application.loading = false
265
- Joosy.Router.trigger 'loaded', this
266
- @trigger 'loaded'
267
-
268
- Joosy.Modules.Log.debugAs @, "Page loaded"
269
-
270
- #
271
- # Page destruction proccess.
272
- #
273
- # * {Joosy.Modules.TimeManager.__clearTime}
274
- # * {Joosy.Modules.WidgetsManager.__unloadWidgets}
275
- # * {Joosy.Modules.Renderer.__removeMetamorphs}
276
- #
277
- __unload: ->
278
- @__clearTime()
279
- @__unloadWidgets()
280
- @__removeMetamorphs()
281
- @__runAfterUnloads @params, @previous
282
- delete @previous
283
-
284
- #
285
- # Proxies callback through possible async wrapper.
286
- #
287
- # If wrapper is defined, it will be called with given callback as one of parameters.
288
- # If wrapper is not defined callback will be called directly.
289
- #
290
- # @note Magic People Voodoo People
291
- #
292
- # @param [Object] entity Object possibly containing wrapper method
293
- # @param [String] receiver String name of wrapper method inside entity
294
- # @param [Hash] params Params to send to wrapper, callback will be
295
- # attached as the last of them.
296
- # @param [Function] callback Callback to run
297
- #
298
- __callSyncedThrough: (entity, receiver, params, callback) ->
299
- if entity?[receiver]?
300
- entity[receiver].apply entity, params.clone().add(callback)
301
- else
302
- callback()
303
-
304
- #
305
- # The single page (without layout reloading) bootstrap logic
306
- #
307
- # @example Hacky boot sequence description
308
- # previous::erase \
309
- # previous::unload \
310
- # beforePaint \
311
- # > paint
312
- # fetch /
313
- #
314
- __bootstrap: ->
315
- Joosy.Modules.Log.debugAs @, "Boostraping page"
316
- @layout = @previous.layout
317
-
318
- callbacksParams = [@layout.content()]
319
-
320
- if @__scrollElement && @__scrollSpeed != 0
321
- @__fixHeight()
322
-
323
- @wait "stageClear dataReceived", =>
324
- @previous?.__afterPaint?(callbacksParams)
325
- @__callSyncedThrough this, '__paint', callbacksParams, =>
326
- # Page HTML
327
- @swapContainer @layout.content(), @__renderDefault(@data || {})
328
- @container = @layout.content()
329
-
330
- # Loading
331
- @__load()
332
-
333
- @__callSyncedThrough @previous, '__erase', callbacksParams, =>
334
- @previous?.__unload()
335
- @__callSyncedThrough @, '__beforePaint', callbacksParams, =>
336
- @trigger 'stageClear'
337
-
338
- @__callSyncedThrough @, '__fetch', [], =>
339
- Joosy.Modules.Log.debugAs @, "Fetch complete"
340
- @trigger 'dataReceived'
341
-
342
- #
343
- # The page+layout bootstrap logic
344
- #
345
- # @example Hacky boot sequence description
346
- # previous::erase \
347
- # previous::unload \
348
- # beforePaint \
349
- # > paint
350
- # fetch /
351
- #
352
- __bootstrapLayout: ->
353
- Joosy.Modules.Log.debugAs @, "Boostraping page with layout"
354
- @layout = new @__layoutClass(@params)
355
-
356
- callbacksParams = [Joosy.Application.content(), this]
357
-
358
- if @__scrollElement && @__scrollSpeed != 0
359
- @__fixHeight()
360
-
361
- @wait "stageClear dataReceived", =>
362
- @__callSyncedThrough @layout, '__paint', callbacksParams, =>
363
- # Layout HTML
364
- @swapContainer Joosy.Application.content(), @layout.__renderDefault(@layout.data || {})
365
-
366
- # Page HTML
367
- @swapContainer @layout.content(), @__renderDefault(@data || {})
368
- @container = @layout.content()
369
-
370
- # Loading
371
- @layout.__load Joosy.Application.content()
372
- @__load()
373
-
374
- @__callSyncedThrough @previous?.layout, '__erase', callbacksParams, =>
375
- @previous?.layout?.__unload?()
376
- @previous?.__unload()
377
- @__callSyncedThrough @layout, '__beforePaint', callbacksParams, =>
378
- @trigger 'stageClear'
379
-
380
- @__callSyncedThrough @layout, '__fetch', [], =>
381
- @__callSyncedThrough @, '__fetch', [], =>
382
- Joosy.Modules.Log.debugAs @, "Fetch complete"
383
- @trigger 'dataReceived'