Api and options

Simpleview.extend(prototypeProperties, [staticProperties])

Used to define view types / constructor functions. Define prototype methods for view via object hash. Static properties are optional.


initialize(options)

Define initialize function in prototype properties if you need to do some logic on view startup. Will receive all arguments from constructor.


events(object | function)

Declare events with object hash or custom function in prototype properties.


            events: {
                'click .selector': 'handler',
                'click {{this.someVariable}}': 'handler', // variable will be injected
                'one:submit form': 'oneSubmit', // handler will run only once
                'resize window': 'onWindowResize',
                'keyup document': 'onDocumentKeyup'
            }
        

delegatedEvents: true | false

Events are delegated to view by default. If you want to bind them directly to elements (to avoid excessive bubbling on views with complex dom tree) set "delegatedEvents" to false.


addView(viewInstance)

Adds view instance to sub view registry. This binding enables effective cleanup of container views.


removeViews()

Removes all registered sub views.


$(selector)

Alias for this.$el.find(selector);


when(resources, [callbackDone, [callbackFail]]) {

Similar to $.when. Resources can be array of deferreds or single deferred. Callbacks are called with view instance as execution context.


trigger(eventName, [data])

Trigger custom event and optionally provide data to handler callback.


on(eventName, callback)

Subscribe to custom view events


off([eventName, [callback]])

Removes listeners to custom view events.


listenTo(publisher, eventName, callback)

Listen to other object events.


stopListening([publisher, [eventName, [callback]]])

Removes listeners to custom publisher events.


remove()

Removes view from DOM and does cleanup of all bound events.