joosy 0.1.0.RC2 → 0.1.0.RC3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/.codoopts +5 -0
  2. data/.gitignore +2 -0
  3. data/Gemfile.lock +4 -2
  4. data/README.md +10 -4
  5. data/app/assets/javascripts/joosy/core/application.js.coffee +3 -1
  6. data/app/assets/javascripts/joosy/core/form.js.coffee +69 -42
  7. data/app/assets/javascripts/joosy/core/helpers/view.js.coffee +30 -0
  8. data/app/assets/javascripts/joosy/core/joosy.js.coffee +125 -66
  9. data/app/assets/javascripts/joosy/core/layout.js.coffee +106 -1
  10. data/app/assets/javascripts/joosy/core/modules/container.js.coffee +41 -0
  11. data/app/assets/javascripts/joosy/core/modules/events.js.coffee +88 -1
  12. data/app/assets/javascripts/joosy/core/modules/filters.js.coffee +24 -0
  13. data/app/assets/javascripts/joosy/core/modules/log.js.coffee +18 -0
  14. data/app/assets/javascripts/joosy/core/modules/module.js.coffee +53 -1
  15. data/app/assets/javascripts/joosy/core/modules/renderer.js.coffee +22 -6
  16. data/app/assets/javascripts/joosy/core/modules/time_manager.js.coffee +21 -0
  17. data/app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +26 -0
  18. data/app/assets/javascripts/joosy/core/page.js.coffee +225 -16
  19. data/app/assets/javascripts/joosy/core/preloader.js.coffee +8 -0
  20. data/app/assets/javascripts/joosy/core/resource/collection.js.coffee +52 -15
  21. data/app/assets/javascripts/joosy/core/resource/generic.js.coffee +78 -50
  22. data/app/assets/javascripts/joosy/core/resource/rest.js.coffee +39 -41
  23. data/app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +36 -27
  24. data/app/assets/javascripts/joosy/core/router.js.coffee +95 -19
  25. data/app/assets/javascripts/joosy/core/widget.js.coffee +42 -1
  26. data/app/assets/javascripts/joosy/preloaders/caching.js.coffee +39 -24
  27. data/app/assets/javascripts/joosy/preloaders/inline.js.coffee +9 -7
  28. data/app/helpers/joosy/sprockets_helper.rb +4 -1
  29. data/lib/joosy/rails/version.rb +1 -1
  30. data/spec/javascripts/joosy/core/application_spec.js.coffee +3 -3
  31. data/spec/javascripts/joosy/core/resource/rest_spec.js.coffee +0 -2
  32. data/spec/javascripts/joosy/core/router_spec.js.coffee +24 -24
  33. data/vendor/assets/javascripts/jquery.form.js +978 -963
  34. data/vendor/assets/javascripts/sugar.js +1 -1
  35. metadata +20 -20
  36. data/app/assets/javascripts/joosy/core/helpers.js.coffee +0 -16
  37. data/vendor/assets/javascripts/base64.js +0 -135
@@ -8,6 +8,14 @@
8
8
  #= require joosy/core/modules/widgets_manager
9
9
  #= require joosy/core/modules/filters
10
10
 
11
+ #
12
+ # Base class for all of your Joosy Layouts.
13
+ # @see http://guides.joosy.ws/guides/layouts-pages-and-routing.html
14
+ #
15
+ # @example Sample application layout
16
+ # class @ApplicationLayout extends Joosy.Layout
17
+ # @view 'application'
18
+ #
11
19
  class Joosy.Layout extends Joosy.Module
12
20
  @include Joosy.Modules.Log
13
21
  @include Joosy.Modules.Events
@@ -19,39 +27,136 @@ class Joosy.Layout extends Joosy.Module
19
27
 
20
28
  @view 'default'
21
29
 
30
+ #
31
+ # Sets the method which will controll the painting preparation proccess.
32
+ #
33
+ # This method will be called right ater previous layout {Joosy.Layout.erase} and in parallel with
34
+ # layout data fetching so you can use it to initiate preloader.
35
+ #
36
+ # @note Given method will be called with `complete` function as parameter. As soon as your
37
+ # preparations are done you should call that function.
38
+ #
39
+ # @example Sample before painter
40
+ # @beforePaint (complete) ->
41
+ # if !@data # checks if parallel fetching finished
42
+ # $('preloader').slideDown -> complete()
43
+ #
44
+ #
22
45
  @beforePaint: (callback) ->
23
46
  @::__beforePaint = callback
47
+
48
+ #
49
+ # Sets the method which will controll the painting proccess.
50
+ #
51
+ # This method will be called after fetching, erasing and beforePaint is complete.
52
+ # It should be used to setup appearance effects of layout.
53
+ #
54
+ # @note Given method will be called with `complete` function as parameter. As soon as your
55
+ # preparations are done you should call that function.
56
+ #
57
+ # @example Sample painter
58
+ # @paint (complete) ->
59
+ # @container.fadeIn -> complete()
60
+ #
24
61
  @paint: (callback) ->
25
62
  @::__paint = callback
63
+
64
+ #
65
+ # Sets the method which will controll the erasing proccess.
66
+ #
67
+ # Use this method to setup hiding effect.
68
+ #
69
+ # @note Given method will be called with `complete` function as parameter. As soon as your
70
+ # preparations are done you should call that function.
71
+ #
72
+ # @note This method will be caled _before_ unload routines so in theory you can
73
+ # access layout data from that. Think twice if you are doing it right though.
74
+ #
75
+ # @example Sample eraser
76
+ # @erase (complete) ->
77
+ # @container.fadeOut -> complete()
78
+ #
26
79
  @erase: (callback) ->
27
80
  @::__erase = callback
28
-
81
+
82
+ #
83
+ # Sets the method which will controll the data fetching proccess.
84
+ #
85
+ # @note Given method will be called with `complete` function as parameter. As soon as your
86
+ # preparations are done you should call that function.
87
+ #
88
+ # @note You are strongly encouraged to NOT fetch anything with Layout!
89
+ # Use {Joosy.Page.fetch}
90
+ #
91
+ # @example Basic usage
92
+ # @fetch (complete) ->
93
+ # $.get '/rumbas', (@data) => complete()
94
+ #
29
95
  @fetch: (callback) ->
30
96
  @::__fetch = callback
31
97
 
98
+ #
99
+ # Defaults to `false` to ease beforePaint state check.
100
+ #
32
101
  data: false
33
102
 
103
+ #
104
+ # @param [Hash] params List of route params
105
+ #
34
106
  constructor: (@params) ->
35
107
 
108
+ #
109
+ # @see Joosy.Router#navigate
110
+ #
36
111
  navigate: (args...) ->
37
112
  Joosy.Router.navigate(args...)
38
113
 
114
+ #
115
+ # This is required by {Joosy.Modules.Renderer}
116
+ # Sets the base template dir to app_name/templates/layouts
117
+ #
39
118
  __renderSection: ->
40
119
  'layouts'
41
120
 
121
+ #
122
+ # Layout bootstrap proccess.
123
+ #
124
+ # * {Joosy.Modules.Container#refreshElements}
125
+ # * {Joosy.Modules.Container#__delegateEvents}
126
+ # * {Joosy.Modules.WidgetsManager#__setupWidgets}
127
+ # * {Joosy.Modules.Filters#__runAfterLoads}
128
+ #
42
129
  __load: (@container) ->
43
130
  @refreshElements()
44
131
  @__delegateEvents()
45
132
  @__setupWidgets()
46
133
  @__runAfterLoads()
47
134
 
135
+ #
136
+ # Layout destruction proccess.
137
+ #
138
+ # * {Joosy.Modules.TimeManager#__clearTime}
139
+ # * {Joosy.Modules.WidgetsManager#__unloadWidgets}
140
+ # * {Joosy.Modules.Renderer#__removeMetamorphs}
141
+ # * {Joosy.Modules.Filters#__runAfterUnloads}
142
+ #
48
143
  __unload: ->
49
144
  @__clearTime()
50
145
  @__unloadWidgets()
146
+ @__removeMetamorphs()
51
147
  @__runAfterUnloads()
52
148
 
149
+ #
150
+ # @todo Rename this shit already. We are not going to release having function that marks
151
+ # element with UUID called `yield`.
152
+ #
53
153
  yield: ->
54
154
  @uuid = Joosy.uuid()
55
155
 
156
+ #
157
+ # Gets layout element.
158
+ #
159
+ # @return [jQuery]
160
+ #
56
161
  content: ->
57
162
  $("##{@uuid}")
@@ -1,3 +1,10 @@
1
+ #
2
+ # DOM container handling, DOM elements and DOM events bindings
3
+ #
4
+ # @note Requires implementor to contain DOM node at @container propert
5
+ #
6
+ # @module
7
+ #
1
8
  Joosy.Modules.Container =
2
9
  events: false
3
10
  elements: false
@@ -7,16 +14,33 @@ Joosy.Modules.Container =
7
14
  $: (selector) ->
8
15
  $(selector, @container)
9
16
 
17
+ #
18
+ # Rebinds selectors defined in 'elements' hash to object properties
19
+ #
20
+ # @example Sample elements
21
+ # elements:
22
+ # foo: '.foo'
23
+ # bar: '.bar'
24
+ #
10
25
  refreshElements: ->
11
26
  @__collectElements().each (key, value) =>
12
27
  # TODO: Check for possible collisions?
13
28
  @[key] = @$(value)
14
29
 
30
+ #
31
+ # Fills container with given data removing all events
32
+ #
33
+ # @param [jQuery] container jQuery entity of container to update
34
+ # @param [String] data HTML to inject
35
+ #
15
36
  swapContainer: (container, data) ->
16
37
  container.unbind().off()
17
38
  container.html data
18
39
  container
19
40
 
41
+ #
42
+ # Gathers 'elements' from current and super classes
43
+ #
20
44
  __collectElements: ->
21
45
  elements = Object.extended @elements || {}
22
46
 
@@ -26,6 +50,9 @@ Joosy.Modules.Container =
26
50
 
27
51
  elements
28
52
 
53
+ #
54
+ # Gathers 'events' from current and super classes
55
+ #
29
56
  __collectEvents: ->
30
57
  events = Object.extended @events || {}
31
58
 
@@ -35,12 +62,26 @@ Joosy.Modules.Container =
35
62
 
36
63
  events
37
64
 
65
+ #
66
+ # Converts '$...' notation to selector from 'elements'
67
+ #
68
+ # @param [String] selector Selector to convert
69
+ #
38
70
  __extractSelector: (selector) ->
39
71
  if r = selector.match /\$([A-z]+)/
40
72
  selector = @__collectElements()[r[1]]
41
73
 
42
74
  selector
43
75
 
76
+ #
77
+ # Bings events defined in 'events' to container
78
+ #
79
+ # @example Sample events
80
+ # events:
81
+ # 'click': -> # this will raise on container click
82
+ # 'click .foo': -> # this will raise on .foo click
83
+ # 'click $foo': -> #this will search for selector of foo element
84
+ #
44
85
  __delegateEvents: ->
45
86
  module = this
46
87
  events = @__collectEvents()
@@ -1,22 +1,50 @@
1
+ #
2
+ # Basic events implementation
3
+ #
4
+ # @module
5
+ #
1
6
  Joosy.Modules.Events =
7
+
8
+ #
9
+ # Waits for the list of given events to happen at least once. Then runs callback.
10
+ #
11
+ # @param [String] events List of events to wait for separated by space
12
+ # @param [Function] callback Action to run when all events were triggered at least once
13
+ #
2
14
  wait: (events, callback) ->
3
- events = events.split /\s+/
15
+ events = events.split /\s+/ if Object.isString events
4
16
 
5
17
  @__oneShotEvents ||= []
6
18
  @__oneShotEvents.push [events, callback]
7
19
 
20
+ #
21
+ # Binds action to run each time any of given even was triggered
22
+ #
23
+ # @param [String] events List of events separated by space
24
+ # @param [Function] callback Action to run on trigger
25
+ #
8
26
  bind: (events, callback) ->
9
27
  events = events.split /\s+/
10
28
 
11
29
  @__boundEvents ||= []
12
30
  @__boundEvents.push [events, callback]
13
31
 
32
+ #
33
+ # Unbinds action from runing on trigger
34
+ #
35
+ # @param [Function] target Action to unbind
36
+ #
14
37
  unbind: (target) ->
15
38
  for [events, callback], index in @__boundEvents
16
39
  if callback == target
17
40
  @__boundEvents.splice index, 1
18
41
  return
19
42
 
43
+ #
44
+ # Triggers event for {bind} and {wait}
45
+ #
46
+ # @param [String] Name of event to trigger
47
+ #
20
48
  trigger: (event) ->
21
49
  Joosy.Modules.Log.debugAs @, "Event #{event} triggered"
22
50
  if @__oneShotEvents
@@ -34,3 +62,62 @@ Joosy.Modules.Events =
34
62
  for [events, callback] in @__boundEvents
35
63
  if events.has event
36
64
  callback()
65
+
66
+ #
67
+ # Runs set of callbacks finializing with result callback
68
+ #
69
+ # @example Basic usage
70
+ # Joosy.Events.synchronize (context) ->
71
+ # contet.do (done) -> done()
72
+ # contet.do (done) -> done()
73
+ # content.after ->
74
+ # console.log 'Success!'
75
+ #
76
+ # @param [Function] block Configuration block (see example)
77
+ #
78
+ synchronize: (block) ->
79
+ context = new Joosy.Modules.Events.SynchronizationContext(this)
80
+ block.call(this, context)
81
+
82
+ @wait context.expectations, => context.after.call(this)
83
+
84
+ context.actions.each (data) =>
85
+ data[0].call this, =>
86
+ @trigger data[1]
87
+
88
+ #
89
+ # Internal representation of {Joosy.Modules.Events#synchronize} context
90
+ #
91
+ # @see Joosy.Modules.Events#synchronize
92
+ #
93
+ class Joosy.Modules.Events.SynchronizationContext
94
+ @uid = 0
95
+
96
+ constructor: (@parent) ->
97
+ @expectations = []
98
+ @actions = []
99
+
100
+ #
101
+ # Internal simple counter to separate given synchronization actions
102
+ #
103
+ uid: ->
104
+ @constructor.uid += 1
105
+
106
+ #
107
+ # Registeres another async function that should be synchronized
108
+ #
109
+ # @param [Function] action `(Function) -> null` to call.
110
+ # Should call given function to mark itself complete.
111
+ #
112
+ do: (action) ->
113
+ event = "synchro-#{@uid()}"
114
+ @expectations.push event
115
+ @actions.push [action, event]
116
+
117
+ #
118
+ # Registers finalizer: the action that will be called when all do-functions
119
+ # marked themselves as complete.
120
+ #
121
+ # @param [Function] after Function to call.
122
+ #
123
+ after: (@after) ->
@@ -1,4 +1,19 @@
1
+ #
2
+ # Filters registration routines
3
+ #
4
+ # @module
5
+ #
1
6
  Joosy.Modules.Filters =
7
+
8
+ #
9
+ # Defines static registration routines
10
+ #
11
+ # @example Set of methods
12
+ # class Test
13
+ # @beforeLoad -> # supposed to run before load and control loading queue
14
+ # @afterLoad -> # supposed to run after load to finalize loading
15
+ # @afterUnload -> # supposed to run after unload to collect garbage
16
+ #
2
17
  included: ->
3
18
  @beforeLoad = (callback) ->
4
19
  unless @::hasOwnProperty '__beforeLoads'
@@ -15,6 +30,9 @@ Joosy.Modules.Filters =
15
30
  @::__afterUnloads = [].concat @.__super__.__afterUnloads || []
16
31
  @::__afterUnloads.push callback
17
32
 
33
+ #
34
+ # Runs filters registered as beforeLoad
35
+ #
18
36
  __runBeforeLoads: (opts...) ->
19
37
  unless @__beforeLoads?.length > 0
20
38
  return true
@@ -28,6 +46,9 @@ Joosy.Modules.Filters =
28
46
 
29
47
  return flag
30
48
 
49
+ #
50
+ # Runs filters registered as afterLoad
51
+ #
31
52
  __runAfterLoads: (opts...) ->
32
53
  if @__afterLoads?.length > 0
33
54
  for filter in @__afterLoads
@@ -35,6 +56,9 @@ Joosy.Modules.Filters =
35
56
  filter = @[filter]
36
57
  filter.apply @, opts
37
58
 
59
+ #
60
+ # Runs filters registered as afterUnload
61
+ #
38
62
  __runAfterUnloads: (opts...) ->
39
63
  if @__afterUnloads?.length > 0
40
64
  for filter in @__afterUnloads
@@ -1,4 +1,13 @@
1
+ #
2
+ # Wrappers for console.log
3
+ #
4
+ # @module
5
+ #
1
6
  Joosy.Modules.Log =
7
+
8
+ #
9
+ # Checks if console is available and proxies given arguments directly to `console.log`
10
+ #
2
11
  log: (args...) ->
3
12
  return unless console?
4
13
 
@@ -8,10 +17,19 @@ Joosy.Modules.Log =
8
17
  else
9
18
  console.log args.first()
10
19
 
20
+ #
21
+ # Runs `log` if debug is active
22
+ #
11
23
  debug: (args...) ->
12
24
  return unless Joosy.debug
13
25
  @log args...
14
26
 
27
+ #
28
+ # Logs given message wrapping it with description of given object (class name)
29
+ #
30
+ # @param [Object] context The class required to be described in log message
31
+ # @param [String] string Message to log
32
+ #
15
33
  debugAs: (context, string, args...) ->
16
34
  return unless Joosy.debug
17
35
  context = Joosy.Module.__className(context) || 'unknown context'
@@ -1,9 +1,30 @@
1
1
  moduleKeywords = ['included', 'extended']
2
2
 
3
+ #
4
+ # Base Joosy class extending Coffee class with module-like injections
5
+ # and other tiny stuff.
6
+ #
3
7
  class Joosy.Module
8
+ #
9
+ # Sets the default namespace for all Joosy descendants.
10
+ # This is used in {Joosy.namespace} magic.
11
+ #
4
12
  @__namespace__: []
5
13
 
6
- @__className = (klass) ->
14
+ #
15
+ # Gets Object/Class class name.
16
+ #
17
+ # @note Never use this to make some magical auto-suggestions!!!
18
+ # Remember: minifcation will rename your classes. Therefore it
19
+ # is only intended for development debugging purposes.
20
+ #
21
+ # @note Go @jashkenas Go! Give us https://github.com/jashkenas/coffee-script/issues/2052.
22
+ # Please go vote for this feature if you are reading this. It will
23
+ # give us ability to eleminate a lot of boilerplate for you.
24
+ #
25
+ # @return [String]
26
+ #
27
+ @__className: (klass) ->
7
28
  unless Object.isFunction(klass)
8
29
  klass = klass.constructor
9
30
 
@@ -12,6 +33,14 @@ class Joosy.Module
12
33
  else
13
34
  klass.toString().replace /^function ([a-zA-Z]+)\([\s\S]+/, '$1'
14
35
 
36
+ #
37
+ # Determines if class A has class B in its ancestors.
38
+ #
39
+ # @param [Class] what Class to check againt
40
+ # @param [Class] klass Possible ancestor to search for
41
+ #
42
+ # @return [Boolean]
43
+ #
15
44
  @hasAncestor: (what, klass) ->
16
45
  unless what? && klass?
17
46
  return false
@@ -25,6 +54,19 @@ class Joosy.Module
25
54
 
26
55
  false
27
56
 
57
+ #
58
+ # Simple and fast shallow merge implementation.
59
+ #
60
+ # This is here due to: https://github.com/andrewplummer/Sugar/issues/100.
61
+ # This bug was closed and we got some performance but this implementation is
62
+ # still like 10x fater for basic tasks.
63
+ #
64
+ # @param [Object] destination Object to extend
65
+ # @param [Object] source Source of new properties
66
+ # @param [Boolean] unsafe Determines if we should rewrite destination properties
67
+ #
68
+ # @return [Object] The new and mighty destination Object
69
+ #
28
70
  @merge: (destination, source, unsafe=true) ->
29
71
  for key, value of source
30
72
  if source.hasOwnProperty(key)
@@ -32,6 +74,11 @@ class Joosy.Module
32
74
  destination[key] = value
33
75
  destination
34
76
 
77
+ #
78
+ # Mixes given object as dynamic methods
79
+ #
80
+ # @param [Object] object Module object
81
+ #
35
82
  @include: (object) ->
36
83
  unless object
37
84
  throw new Error 'include(object) requires obj'
@@ -43,6 +90,11 @@ class Joosy.Module
43
90
  object.included?.apply this
44
91
  null
45
92
 
93
+ #
94
+ # Mixes given object as static methods
95
+ #
96
+ # @param [Object] object Module object
97
+ #
46
98
  @extend: (object) ->
47
99
  unless object
48
100
  throw new Error 'extend(object) requires object'
@@ -1,13 +1,28 @@
1
1
  #= require_tree ../templaters
2
2
  #= require metamorph
3
3
 
4
+ #
5
+ # Core DOM rendering mechanics
6
+ #
7
+ # @module
8
+ # @todo Describe this scary thing o_O
9
+ #
4
10
  Joosy.Modules.Renderer =
5
11
 
12
+ #
13
+ # Default behavior for non-set renderer (empty template?)
14
+ #
6
15
  __renderer: ->
7
16
  throw new Error "#{Joosy.Module.__className @constructor} does not have an attached template"
8
17
 
9
18
  __helpers: null
10
19
 
20
+ #
21
+ # Defines class-level helpers: @view and @helpers
22
+ #
23
+ # View (@view): Sets the curent template by specifying its name or lambda
24
+ # Helpers (@helpers): Lists set of helpers' namespaces to include
25
+ #
11
26
  included: ->
12
27
  @view = (template, options={}) ->
13
28
  if Object.isFunction template
@@ -77,6 +92,7 @@ Joosy.Modules.Renderer =
77
92
  stack = @__renderingStackChildFor parentStackPointer
78
93
 
79
94
  stack.template = template
95
+ stack.locals = locals
80
96
 
81
97
  isResource = Joosy.Module.hasAncestor locals.constructor, Joosy.Resource.Generic
82
98
  isCollection = Joosy.Module.hasAncestor locals.constructor, Joosy.Resource.Collection
@@ -91,11 +107,6 @@ Joosy.Modules.Renderer =
91
107
 
92
108
  if !Object.isObject(locals) && !isResource && !isCollection
93
109
  throw new Error "#{Joosy.Module.__className @}> locals (maybe @data?) not in: dumb hash, Resource, Collection"
94
-
95
- if isResource
96
- stack.locals = locals.e
97
- else
98
- stack.locals = locals
99
110
 
100
111
  renderers =
101
112
  render: (template, locals={}) =>
@@ -105,7 +116,12 @@ Joosy.Modules.Renderer =
105
116
 
106
117
  context = =>
107
118
  data = {}
108
- Joosy.Module.merge data, stack.locals
119
+
120
+ if isResource
121
+ Joosy.Module.merge data, stack.locals.e
122
+ else
123
+ Joosy.Module.merge data, stack.locals
124
+
109
125
  Joosy.Module.merge data, @__instantiateHelpers(), false
110
126
  Joosy.Module.merge data, renderers
111
127
  data
@@ -1,4 +1,16 @@
1
+ #
2
+ # Comfortable and clever wrappers for timeouts management
3
+ #
4
+ # @module
5
+ #
1
6
  Joosy.Modules.TimeManager =
7
+
8
+ #
9
+ # Registeres timeout for current object
10
+ #
11
+ # @param [Integer] timeout Miliseconds to wait
12
+ # @param [Function] action Action to run on timeout
13
+ #
2
14
  setTimeout: (timeout, action) ->
3
15
  @__timeouts ||= []
4
16
 
@@ -7,6 +19,12 @@ Joosy.Modules.TimeManager =
7
19
 
8
20
  timer
9
21
 
22
+ #
23
+ # Registeres interval for current object
24
+ #
25
+ # @param [Integer] delay Miliseconds between runs
26
+ # @param [Function] action Action to run
27
+ #
10
28
  setInterval: (delay, action) ->
11
29
  @__intervals ||= []
12
30
 
@@ -15,6 +33,9 @@ Joosy.Modules.TimeManager =
15
33
 
16
34
  timer
17
35
 
36
+ #
37
+ # Drops all registered timeouts and intervals for this object
38
+ #
18
39
  __clearTime: ->
19
40
  if @__intervals
20
41
  for entry in @__intervals
@@ -1,4 +1,16 @@
1
+ #
2
+ # Widgets management routines
3
+ #
4
+ # @module
5
+ #
1
6
  Joosy.Modules.WidgetsManager =
7
+
8
+ #
9
+ # Registeres and runs widget inside specified container
10
+ #
11
+ # @param [DOM] container jQuery or direct dom node object
12
+ # @param [Joosy.Widget] widget Class or object of Joosy.Widget to register
13
+ #
2
14
  registerWidget: (container, widget) ->
3
15
  if Joosy.Module.hasAncestor widget, Joosy.Widget
4
16
  widget = new widget()
@@ -8,11 +20,19 @@ Joosy.Modules.WidgetsManager =
8
20
 
9
21
  widget
10
22
 
23
+ #
24
+ # Unregisteres and destroys widget
25
+ #
26
+ # @param [Joosy.Widget] widget Object of Joosy.Widget to unregister
27
+ #
11
28
  unregisterWidget: (widget) ->
12
29
  widget.__unload()
13
30
 
14
31
  @__activeWidgets.splice @__activeWidgets.indexOf(widget), 1
15
32
 
33
+ #
34
+ # Gathers widgets definitions from current and super classes
35
+ #
16
36
  __collectWidgets: ->
17
37
  widgets = Object.extended @widgets || {}
18
38
 
@@ -22,6 +42,9 @@ Joosy.Modules.WidgetsManager =
22
42
 
23
43
  widgets
24
44
 
45
+ #
46
+ # Intialize all widgets for current object
47
+ #
25
48
  __setupWidgets: ->
26
49
  widgets = @__collectWidgets()
27
50
  registered = Object.extended()
@@ -52,6 +75,9 @@ Joosy.Modules.WidgetsManager =
52
75
  value.each (widget, count) =>
53
76
  Joosy.Modules.Log.debugAs @, "Widget #{widget} registered at '#{selector}'. Elements: #{count}"
54
77
 
78
+ #
79
+ # Unregister all widgets for current object
80
+ #
55
81
  __unloadWidgets: ->
56
82
  if @__activeWidgets
57
83
  for widget in @__activeWidgets