app/assets/javascripts/luca/core/view.coffee in luca-0.9.89 vs app/assets/javascripts/luca/core/view.coffee in luca-0.9.91

- old
+ new

@@ -134,15 +134,15 @@ # Luca.View.extend # bindMethods:["oneHandler","twoHandler"] # autoBindEventHandlers: false - # Supplying configuration to `@_events` will ensure that this configuration + # Supplying configuration to `@_inheritEvents` will ensure that this configuration # is present on views which extend from this view. In normal Backbone behavior # the `@events` property can be overridden by views which extend, and this isn't # always what you want from your component. - _events: undefined + _inheritEvents: undefined # Luca.View decorates Backbone.View with some patterns and conventions. view.publicMethods @@ -172,18 +172,18 @@ @setupHooks _( Luca.View::hooks.concat( @hooks ) ).uniq() Luca.concern.setup.call(@) - @delegateEvents() + @delegateEvents() unless _.isEmpty(@events) @trigger "after:initialize", @ _.bindAll(@, @bindMethods...) if @bindMethods?.legth > 0 - unless _.isEmpty(@_events) - for eventId, handler of @_events + unless _.isEmpty(@_inheritEvents) + for eventId, handler of @_inheritEvents @registerEvent(eventId, handler) debug: (args...)-> if @debugMode is true or window.LucaDebugMode is true @@ -196,19 +196,30 @@ Luca.ViewObserver ||= new Luca.Observer(type:"view") Luca.ViewObserver.relay @, arguments Backbone.View::trigger.apply @, arguments - + # Backbone.View.prototype.make is removed in 0.9.10. + # As we happen to rely on this little utility heavily, + # we add it to Luca.View + make: (tagName, attributes, content)-> + el = document.createElement(tagName); + if (attributes) + Backbone.$(el).attr(attributes) + if (content != null) + Backbone.$(el).html(content) + + el registerEvent: (selector, handler)-> @events ||= {} if _.isObject(selector) @events = _.extend(@events, selector) else - @events[selector] = handler + if _.isFunction(handler) || (_.isString(handler) && @[handler]?) + @events[selector] = handler @delegateEvents() view.privateMethods # Returns a reference to the class which this view is an instance of. @@ -237,9 +248,17 @@ # - before:render : beforeRender() # - after:render : afterRender() # - after:initialize : afterInitialize() # - first:activation : firstActivation() setupHooks: Luca.util.setupHooks + +# In order to support some Luca apps which rely +# on Backbone.View.make. +view.afterDefinition ()-> + if not Backbone.View::make? + Backbone.View::make = ()-> + console.log "Backbone.View::make has been removed from backbone. You should use Luca.View::make instead." + Luca.View::make view.register() Luca.View._originalExtend = Backbone.View.extend