app/assets/javascripts/joosy/core/modules/container.js.coffee in joosy-0.1.0.RC1 vs app/assets/javascripts/joosy/core/modules/container.js.coffee in joosy-0.1.0.RC2
- old
+ new
@@ -2,58 +2,62 @@
events: false
elements: false
eventSplitter: /^(\S+)\s*(.*)$/
- $: (selector) -> $(selector, @container)
+ $: (selector) ->
+ $(selector, @container)
refreshElements: ->
@__collectElements().each (key, value) =>
+ # TODO: Check for possible collisions?
@[key] = @$(value)
swapContainer: (container, data) ->
- realContainer = container.clone().html(data)
- container.replaceWith realContainer
- realContainer
+ container.unbind().off()
+ container.html data
+ container
__collectElements: ->
- elements = Object.extended(@elements || {})
+ elements = Object.extended @elements || {}
klass = this
while klass = klass.constructor.__super__
- elements.merge(klass.elements, false)
+ Joosy.Module.merge elements, klass.elements, false
elements
__collectEvents: ->
- events = Object.extended(@events || {})
+ events = Object.extended @events || {}
klass = this
while klass = klass.constructor.__super__
- events.merge(klass.events, false)
+ Joosy.Module.merge events, klass.events, false
events
__extractSelector: (selector) ->
- if r = selector.match(/\$([A-z]+)/)
+ if r = selector.match /\$([A-z]+)/
selector = @__collectElements()[r[1]]
selector
__delegateEvents: ->
module = this
events = @__collectEvents()
events.each (key, method) =>
- method = @[method] unless typeof(method) == 'function'
- callback = (event) -> method.call(module, this, event)
+ unless Object.isFunction method
+ method = @[method]
+ callback = (event) ->
+ method.call module, this, event
- match = key.match(@eventSplitter)
+ match = key.match @eventSplitter
eventName = match[1]
- selector = @__extractSelector(match[2])
+ selector = @__extractSelector match[2]
if selector == ""
- @container.bind(eventName, callback)
+ @container.bind eventName, callback
Joosy.Modules.Log.debugAs @, "#{eventName} binded on container"
else
- @container.on(eventName, selector, callback)
+ @container.on eventName, selector, callback
Joosy.Modules.Log.debugAs @, "#{eventName} binded on #{selector}"