Documentation

include MVC MVC.Animate MVC.Class MVC.Controller MVC.Controller.Action MVC.Controller.Action.Drag MVC.Controller.Action.Drop MVC.Controller.Action.EnterLeave MVC.Controller.Action.Event MVC.Controller.Action.Hover MVC.Controller.Action.Lasso MVC.Controller.Action.Selectable MVC.Controller.Action.Subscribe MVC.Controller.Comet MVC.Controller.Params MVC.Controller.Params.Drag MVC.Controller.Params.Drop MVC.Controller.Stateful MVC.Delegator MVC.Doc MVC.Element MVC.Event MVC.File MVC.History MVC.IO MVC.IO.Ajax MVC.IO.Comet MVC.IO.JsonP MVC.IO.WindowName MVC.IO.XDoc MVC.Model MVC.Model.Ajax MVC.Model.Cookie MVC.Model.JsonP MVC.Model.JsonRest MVC.Model.WindowName MVC.Model.XmlRest MVC.Native MVC.Native.Array MVC.Native.Date MVC.Native.Function MVC.Native.Number MVC.Native.Object MVC.Native.String MVC.Options MVC.Position MVC.Query MVC.Store MVC.SyntheticEvent MVC.Test MVC.Test.Assertions MVC.Test.Controller MVC.Test.Functional MVC.Test.Runner MVC.Test.Unit MVC.Timer MVC.Vector MVC.View MVC.View.Helpers OpenAjax

MVC.Controller.Stateful

Inherits: MVC.Controller
Controller.Stateful provides state for controller instances. Controller.Stateful is useful for creating self-contained widgets or when there are many instances of an object that has complex state. Read the fixedbox demo for good an example of using Controller.Stateful.

Example

The following is a a small piece of the SliderController.
 SliderController = MVC.Controller.Stateful('slider',{
   init : function(element, options){
     this.options = options ||{}
     this._super(MVC.$E(element))
   },
   '.slider dragstart' : function(params){
       params.horizontal()
   },
   '.slider dragging' : function(params){
     //check pos
     this.options.sliding(pos, params) //callback with position
   }
 })
You would create a new Slider like:
 new SliderController('element_id',{sliding: function(pos){console.log(pos)});

Naming

Naming works just similar to regular controllers. If the Controller's className is plural, it will insert an implicit .singular_name before this controller's event actions. If the controller is a singular name nothing is added to the delegation class name.

How Stateful works

New stateful instances create a new delegation listening point on the element passed into the base init function. As events happen on the element or child elements of the instance, they call back to the controller instance.

Static Methods

Prototype Methods

destroy

destroy() -> undefined
Removes all actions on this instance.

dispatch_closure

dispatch_closure(f_name) -> undefined
Used to call back to this instance
{Object} -

init

init(element) -> undefined
Called when aa new instance is created. you must provide
{HTMLElement} - the element this instance operates on.

query

query(selector) -> undefined
Queries from the current element.
{Object} -

respond

respond(respond) -> undefined
Can 'shut' down this controller, preventing it from responding to any event.
{Boolean} - true to respond to events, false to repond to nothing.